HFVSTXMSKTTDRFWUUDP7QOHEI773WZ2VMLAWVCOAJXNI2FVS2MEQC var gpa = std.heap.GeneralPurposeAllocator(.{.stack_trace_frames = 1024,
// We don't use the thread-safe mode (yet), because// we aren't on the thread pool, and audio thread *must*// not allocate. We might move to thread pool, so we would need// .thread_safe = true,pub var gpa = std.heap.GeneralPurposeAllocator(.{.stack_trace_frames = 4,
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});}
switch (gmsynth.plugin_state) {.inited => |*self| {if (gmsynth.logFn(self, message_level, scope, format, args)) {return;} else |err| {std.debug.print("Failed to use gmsynth.logFn: {}\n", .{err});}},else => {},
};pub const GmSynth = struct {// CLAP plugin structplugin: clap.clap_plugin_t,host: *const clap.clap_host_t,// Host extensionshost_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,// Our actual datalatency: u32,
fn create(host: *const clap.clap_host_t) shared.PluginError!*clap.clap_plugin_t {var p = try shared.allocator.create(GmSynth);p.host = host;p.plugin.desc = &desc;p.plugin.plugin_data = p;p.plugin.init = gmsynth_init;p.plugin.destroy = gmsynth_destroy;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;p.plugin.get_extension = gmsynth_get_extension;p.plugin.on_main_thread = gmsynth_on_main_thread;return &p.plugin;}
}}const clap_plugin = clap.clap_plugin_t{.desc = &desc,.plugin_data = &plugin_state,.init = gmsynth_init,.destroy = gmsynth_destroy,.activate = gmsynth_activate,.deactivate = gmsynth_deactivate,.start_processing = gmsynth_start_processing,.stop_processing = gmsynth_stop_processing,.reset = gmsynth_reset,.process = gmsynth_process,.get_extension = gmsynth_get_extension,.on_main_thread = gmsynth_on_main_thread,};fn create(host: *const clap.clap_host_t) !*const clap.clap_plugin_t {switch (plugin_state) {.ready, .uninited => {plugin_state = .{ .uninited = host };},.inited => |plug| {std.log.err("attempted to create inited plugin", .{});return plug.plugin;},
pub fn get_self(plugin: *const clap.clap_plugin) *GmSynth {return @ptrCast(*GmSynth, @alignCast(@alignOf(GmSynth), plugin.plugin_data));
pub fn get_state(plugin: *const clap.clap_plugin) *PlugData {return @ptrCast(*PlugData, @alignCast(@alignOf(PlugData), plugin.plugin_data));
// Fetch host extensionsplug.host_log = get_host_extension(clap.clap_host_log_t, plug.host, &clap.CLAP_EXT_LOG);
switch (get_state(cplug).*) {PlugData.ready, PlugData.inited => {return false;},PlugData.uninited => |host| {// Fetch host extensionsconst host_data = GmSynth.HostData{.host = host,.host_log = get_host_extension(clap.clap_host_log_t, host, &clap.CLAP_EXT_LOG),.host_thread_check = get_host_extension(clap.clap_host_thread_check_t, host, &clap.CLAP_EXT_THREAD_CHECK),.host_latency = null,.host_state = null,};
fn gmsynth_process(plugin: ?*const clap.clap_plugin, process: ?*const clap.clap_process_t) callconv(.C) clap.clap_process_status {_ = process;
fn gmsynth_process(plugin: ?*const clap.clap_plugin, maybe_process: ?*const clap.clap_process_t) callconv(.C) clap.clap_process_status {
var plug = get_self(cplug);_ = plug;
switch (get_state(cplug).*) {PlugData.ready, PlugData.uninited => {// Misbehavior: calling process on non-initedreturn clap.CLAP_PROCESS_ERROR;},PlugData.inited => |*plug| {if (maybe_process) |process| {return plug.plugin_process(process);}},}
// This is where we store plugin stuffconst std = @import("std");const clap = @import("../clap.zig");pub const Logger = std.log.scoped(.gmsynth);pub const HostData = struct {host: *const clap.clap_host_t,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,pub fn assert_main_thread(self: *const HostData) !void {if (self.host_thread_check) |thread_check| {if (!thread_check.is_main_thread.?(self.host)) {return error.NotMainThread;}}}pub fn assert_audio_thread(self: *const HostData) !void {if (self.host_thread_check) |thread_check| {if (!thread_check.is_audio_thread.?(self.host)) {return error.NotMainThread;}}}};// allocatorallocator: std.mem.Allocator,// CLAP plugin structplugin: *const clap.clap_plugin_t,host_data: HostData,// Our actual datalatency: u32,test_alloc: []u8,const Self = @This();pub fn init(allocator: std.mem.Allocator, host_data: HostData, plugin: *const clap.clap_plugin_t) !Self {// How to use the allocatorvar test_alloc = try allocator.alloc(u8, 256);errdefer allocator.free(test_alloc);std.mem.set(u8, test_alloc, 0xde);return .{.host_data = host_data,.latency = 0,.test_alloc = test_alloc,.plugin = plugin,.allocator = allocator,};}pub fn deinit(self: *Self) void {self.allocator.free(self.test_alloc);}pub fn on_main_thread(self: *const Self) void {_ = self;// TODO Run main thread callbacks here.Logger.info("Main thread stuff", .{});}pub fn plugin_process(self: *Self, process: *const clap.clap_process_t) clap.clap_process_status {_ = self;_ = process;return clap.CLAP_PROCESS_SLEEP;}
const std = @import("std");const clap = @import("../clap.zig");const shared = @import("../shared.zig");const gmsynth = @import("../gmsynth.zig");pub const ext = clap.clap_plugin_gui_t{.is_api_supported = is_api_supported,.get_preferred_api = null,.create = null,.destroy = null,.set_scale = null,.get_size = null,.can_resize = null,.get_resize_hints = null,.adjust_size = null,.set_size = null,.set_parent = null,.set_transient = null,.suggest_title = null,.show = null,.hide = null,};fn is_api_supported(plugin: ?*const clap.clap_plugin_t,api: ?[*:0]const u8,is_floating: bool,) callconv(.C) bool {_ = is_floating;_ = plugin;std.log.info("{?s}", .{api});return false;}