YO35U3UA6BUXJFNGGOFZ3NL5AWPANX7JSJUXZLPJ3CXEBBBBOCPAC
// Override logging with host logging if available
pub const std_options = struct {
pub fn logFn(
comptime message_level: std.log.Level,
comptime scope: @TypeOf(.enum_literal),
comptime format: []const u8,
args: anytype,
) void {
// Try using every plugin's self hook to get host logging
// if they all are not available, default to defaultLog
if (gmsynth.maybe_self) |self| {
if (gmsynth.logFn(self, message_level, scope, format, args)) {
return;
} else |err| {
std.debug.print("Failed to use gmsynth.logFn: {}\n", .{err});
}
}
std.log.defaultLog(message_level, scope, format, args);
}
};
host_latency: *const clap.clap_host_latency_t,
host_log: *const clap.clap_host_log_t,
host_thread_check: *const clap.clap_host_thread_check_t,
host_state: *const clap.clap_host_state_t,
// Host extensions
host_latency: ?*const clap.clap_host_latency_t,
host_log: ?*const clap.clap_host_log_t,
host_thread_check: ?*const clap.clap_host_thread_check_t,
host_state: ?*const clap.clap_host_state_t,
p.plugin.activate = null;
p.plugin.deactivate = null;
p.plugin.start_processing = null;
p.plugin.stop_processing = null;
p.plugin.reset = null;
p.plugin.process = null;
p.plugin.activate = gmsynth_activate;
p.plugin.deactivate = gmsynth_deactivate;
p.plugin.start_processing = gmsynth_start_processing;
p.plugin.stop_processing = gmsynth_stop_processing;
p.plugin.reset = gmsynth_reset;
p.plugin.process = gmsynth_process;
}
// Used for Zig-side code. Plugin code should retrieve
// self using get_self
pub var maybe_self: ?*GmSynth = null;
pub fn logFn(
self: *GmSynth,
comptime message_level: std.log.Level,
comptime scope: @Type(.EnumLiteral),
comptime format: []const u8,
args: anytype,
) !void {
const clap_level = switch (message_level) {
.debug => clap.CLAP_LOG_DEBUG,
.info => clap.CLAP_LOG_INFO,
.warn => clap.CLAP_LOG_WARNING,
.err => clap.CLAP_LOG_ERROR,
};
const level_txt = comptime message_level.asText();
const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
var text = std.ArrayList(u8).init(shared.allocator);
defer text.deinit();
const writer = text.writer();
std.fmt.format(writer, "plugin " ++ level_txt ++ prefix2 ++ format, args) catch return;
const out = try text.toOwnedSliceSentinel(0);
defer shared.allocator.free(out);
if (self.host_log) |host_log| {
host_log.log.?(self.host, clap_level, out);
} else {
return error.NoHostLogExtension;
}
}
fn get_host_extension(comptime T: type, host: *const clap.clap_host, ext: [*:0]const u8) ?*const T {
// we expect host to have get_extension be not-null
return @ptrCast(?*const T, @alignCast(@alignOf(T), host.get_extension.?(host, ext)));
var plug = @ptrCast(*GmSynth, @alignCast(@alignOf(GmSynth), cplug.plugin_data));
_ = plug;
var plug = get_self(cplug);
// Fetch host extensions
plug.host_log = get_host_extension(clap.clap_host_log_t, plug.host, &clap.CLAP_EXT_LOG);
// Hook self
maybe_self = plug;
Logger.debug("Initialized GM Synth version {s}", .{desc.version});
}
fn gmsynth_activate(
plugin: ?*const clap.clap_plugin,
sample_rate: f64,
min_frames_count: u32,
max_frames_count: u32,
) callconv(.C) bool {
_ = max_frames_count;
_ = min_frames_count;
_ = sample_rate;
_ = plugin;
return true;
}
fn gmsynth_deactivate(plugin: ?*const clap.clap_plugin) callconv(.C) void {
_ = plugin;
}
fn gmsynth_start_processing(plugin: ?*const clap.clap_plugin) callconv(.C) bool {
_ = plugin;
return true;
}
fn gmsynth_stop_processing(plugin: ?*const clap.clap_plugin) callconv(.C) void {
_ = plugin;
}
fn gmsynth_reset(plugin: ?*const clap.clap_plugin) callconv(.C) void {
_ = plugin;
}
fn gmsynth_process(plugin: ?*const clap.clap_plugin, process: ?*const clap.clap_process_t) callconv(.C) clap.clap_process_status {
_ = process;
if (plugin) |cplug| {
var plug = get_self(cplug);
_ = plug;
}
return clap.CLAP_PROCESS_CONTINUE;
fn gmsynth_on_main_thread(plugin: ?*const clap.clap_plugin) callconv(.C) void {
if (plugin) |cplug| {
var plug = get_self(cplug);
_ = plug;
Logger.info("Main thread stuff", .{});
}
}