From 5f033b3e2c3a415291cdf3c29e37de9caec42265 Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 13:55:31 +0000 Subject: [PATCH 01/26] Extract format-neutral gain processor --- examples/danzig-gain/dsp.zig | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 examples/danzig-gain/dsp.zig diff --git a/examples/danzig-gain/dsp.zig b/examples/danzig-gain/dsp.zig new file mode 100644 index 0000000..4b782fc --- /dev/null +++ b/examples/danzig-gain/dsp.zig @@ -0,0 +1,53 @@ +// Shared host-neutral gain engine for VST3 and CLAP. +const danzig = @import("danzig"); + +pub const num_params = 2; + +/// Index into the ParamStore. Also the VST3 ParamID, which keeps the mapping +/// between the two trivial. +pub const ParamIndex = struct { + pub const gain: u32 = 0; + pub const bypass: u32 = 1; +}; + +pub const gain_min_db: f32 = -48.0; +pub const gain_max_db: f32 = 48.0; +pub const gain_default_norm: f32 = 0.5; // 0 dB +pub const gain_smoothing_ms: f32 = 20.0; + +// --- 1. DSP core ----------------------------------------------------------- + +/// The audio half of the plugin. No allocation, no locks, no VST3 types. +pub const GainPlugin = struct { + params: danzig.ParamStore(num_params) = .{}, + sample_rate: f32 = 48000.0, + + pub fn init(sample_rate: f32) GainPlugin { + var self = GainPlugin{ .sample_rate = sample_rate }; + _ = self.params.add(gain_min_db, gain_max_db, gain_default_norm, gain_smoothing_ms, sample_rate); + // Bypass is a switch, so smoothing it would produce a half-bypassed + // state that means nothing. + _ = self.params.add(0.0, 1.0, 0.0, 0.0, sample_rate); + return self; + } + + /// Re-derive the smoothing coefficient. It is a function of the sample + /// rate, so a rate change invalidates it. + pub fn setSampleRate(self: *GainPlugin, sample_rate: f32) void { + self.sample_rate = sample_rate; + self.params.params[ParamIndex.gain].setSmoothingMs(gain_smoothing_ms, sample_rate); + self.params.snapAll(); + } + + pub fn isBypassed(self: *const GainPlugin) bool { + return self.params.getNormalized(ParamIndex.bypass) >= 0.5; + } + + /// One sample of gain. The smoother is advanced even when bypassed so that + /// leaving bypass does not jump to a stale value. + pub fn nextGain(self: *GainPlugin, bypassed: bool) f32 { + const db = self.params.tick(ParamIndex.gain); + return if (bypassed) 1.0 else danzig.dBToLinear(db); + } +}; + From 72605f45b9142841cbdf3af4f46abd6316a15dc4 Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 13:55:34 +0000 Subject: [PATCH 02/26] Reuse shared DSP in existing VST3 plugin --- examples/danzig-gain/root.zig | 56 +++++------------------------------ 1 file changed, 7 insertions(+), 49 deletions(-) diff --git a/examples/danzig-gain/root.zig b/examples/danzig-gain/root.zig index 8c861cf..18a11cb 100644 --- a/examples/danzig-gain/root.zig +++ b/examples/danzig-gain/root.zig @@ -35,55 +35,13 @@ const sdk_version = "VST 3.7.0"; // --- parameters ------------------------------------------------------------ -const num_params = 2; - -/// Index into the ParamStore. Also the VST3 ParamID, which keeps the mapping -/// between the two trivial. -const ParamIndex = struct { - pub const gain: u32 = 0; - pub const bypass: u32 = 1; -}; - -const gain_min_db: f32 = -48.0; -const gain_max_db: f32 = 48.0; -const gain_default_norm: f32 = 0.5; // 0 dB -const gain_smoothing_ms: f32 = 20.0; - -// --- 1. DSP core ----------------------------------------------------------- - -/// The audio half of the plugin. No allocation, no locks, no VST3 types. -pub const GainPlugin = struct { - params: danzig.ParamStore(num_params) = .{}, - sample_rate: f32 = 48000.0, - - pub fn init(sample_rate: f32) GainPlugin { - var self = GainPlugin{ .sample_rate = sample_rate }; - _ = self.params.add(gain_min_db, gain_max_db, gain_default_norm, gain_smoothing_ms, sample_rate); - // Bypass is a switch, so smoothing it would produce a half-bypassed - // state that means nothing. - _ = self.params.add(0.0, 1.0, 0.0, 0.0, sample_rate); - return self; - } - - /// Re-derive the smoothing coefficient. It is a function of the sample - /// rate, so a rate change invalidates it. - pub fn setSampleRate(self: *GainPlugin, sample_rate: f32) void { - self.sample_rate = sample_rate; - self.params.params[ParamIndex.gain].setSmoothingMs(gain_smoothing_ms, sample_rate); - self.params.snapAll(); - } - - pub fn isBypassed(self: *const GainPlugin) bool { - return self.params.getNormalized(ParamIndex.bypass) >= 0.5; - } - - /// One sample of gain. The smoother is advanced even when bypassed so that - /// leaving bypass does not jump to a stale value. - pub fn nextGain(self: *GainPlugin, bypassed: bool) f32 { - const db = self.params.tick(ParamIndex.gain); - return if (bypassed) 1.0 else danzig.dBToLinear(db); - } -}; +const shared = @import("dsp.zig"); +pub const GainPlugin = shared.GainPlugin; +const ParamIndex = shared.ParamIndex; +const num_params = shared.num_params; +const gain_min_db = shared.gain_min_db; +const gain_max_db = shared.gain_max_db; +const gain_default_norm = shared.gain_default_norm; // --- 2. The VST3 object ---------------------------------------------------- // From 139382197bc9132d441450dc8f0b6d6cbb8f8637 Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 13:56:13 +0000 Subject: [PATCH 03/26] Add CLAP 1.x ABI declarations and layout tests --- src/clap.zig | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 src/clap.zig diff --git a/src/clap.zig b/src/clap.zig new file mode 100644 index 0000000..f37b858 --- /dev/null +++ b/src/clap.zig @@ -0,0 +1,168 @@ +// CLAP 1.x C ABI. Field order and signatures follow free-audio/clap/include/clap. +pub const Version = extern struct { + major: u32 = 1, + minor: u32 = 2, + revision: u32 = 0, +}; + +pub const Host = opaque {}; + +pub const Descriptor = extern struct { + clap_version: Version, + id: [*:0]const u8, + name: [*:0]const u8, + vendor: ?[*:0]const u8, + url: ?[*:0]const u8, + manual_url: ?[*:0]const u8, + support_url: ?[*:0]const u8, + version: ?[*:0]const u8, + description: ?[*:0]const u8, + features: [*]const ?[*:0]const u8, +}; + +pub const EventHeader = extern struct { + size: u32, + time: u32, + space_id: u16, + @"type": u16, + flags: u32, +}; + +pub const EventParamValue = extern struct { + header: EventHeader, + param_id: u32, + cookie: ?*anyopaque, + note_id: i32, + port_index: i16, + channel: i16, + key: i16, + value: f64, +}; + +pub const InputEvents = extern struct { + ctx: ?*anyopaque, + size: *const fn (*const InputEvents) callconv(.c) u32, + get: *const fn (*const InputEvents, u32) callconv(.c) ?*const EventHeader, +}; + +pub const OutputEvents = extern struct { + ctx: ?*anyopaque, + try_push: *const fn (*const OutputEvents, *const EventHeader) callconv(.c) bool, +}; + +pub const AudioBuffer = extern struct { + data32: ?[*][*]f32, + data64: ?[*][*]f64, + channel_count: u32, + latency: u32, + constant_mask: u64, +}; + +pub const Process = extern struct { + steady_time: i64, + frames_count: u32, + transport: ?*const anyopaque, + audio_inputs: ?[*]const AudioBuffer, + audio_outputs: ?[*]AudioBuffer, + audio_inputs_count: u32, + audio_outputs_count: u32, + in_events: ?*const InputEvents, + out_events: ?*const OutputEvents, +}; + +pub const Plugin = extern struct { + desc: *const Descriptor, + plugin_data: ?*anyopaque, + init: *const fn (*const Plugin) callconv(.c) bool, + destroy: *const fn (*const Plugin) callconv(.c) void, + activate: *const fn (*const Plugin, f64, u32, u32) callconv(.c) bool, + deactivate: *const fn (*const Plugin) callconv(.c) void, + start_processing: *const fn (*const Plugin) callconv(.c) bool, + stop_processing: *const fn (*const Plugin) callconv(.c) void, + reset: *const fn (*const Plugin) callconv(.c) void, + process: *const fn (*const Plugin, *const Process) callconv(.c) i32, + get_extension: *const fn (*const Plugin, [*:0]const u8) callconv(.c) ?*const anyopaque, + on_main_thread: *const fn (*const Plugin) callconv(.c) void, +}; + +pub const PluginFactory = extern struct { + get_plugin_count: *const fn (*const PluginFactory) callconv(.c) u32, + get_plugin_descriptor: *const fn (*const PluginFactory, u32) callconv(.c) ?*const Descriptor, + create_plugin: *const fn (*const PluginFactory, *const Host, [*:0]const u8) callconv(.c) ?*const Plugin, +}; + +pub const Entry = extern struct { + clap_version: Version, + init: *const fn ([*:0]const u8) callconv(.c) bool, + deinit: *const fn () callconv(.c) void, + get_factory: *const fn ([*:0]const u8) callconv(.c) ?*const anyopaque, +}; + +pub const PortInfo = extern struct { + id: u32, + name: [256]u8, + flags: u32, + channel_count: u32, + port_type: ?[*:0]const u8, + in_place_pair: u32, +}; + +pub const AudioPorts = extern struct { + count: *const fn (*const Plugin, bool) callconv(.c) u32, + get: *const fn (*const Plugin, u32, bool, *PortInfo) callconv(.c) bool, +}; + +pub const ParamInfo = extern struct { + id: u32, + flags: u32, + cookie: ?*anyopaque, + name: [256]u8, + module: [1024]u8, + min_value: f64, + max_value: f64, + default_value: f64, +}; + +pub const Params = extern struct { + count: *const fn (*const Plugin) callconv(.c) u32, + get_info: *const fn (*const Plugin, u32, *ParamInfo) callconv(.c) bool, + get_value: *const fn (*const Plugin, u32, *f64) callconv(.c) bool, + value_to_text: *const fn (*const Plugin, u32, f64, [*]u8, u32) callconv(.c) bool, + text_to_value: *const fn (*const Plugin, u32, [*:0]const u8, *f64) callconv(.c) bool, + flush: *const fn (*const Plugin, *const InputEvents, *const OutputEvents) callconv(.c) void, +}; + +pub const InputStream = extern struct { + ctx: ?*anyopaque, + read: *const fn (*const InputStream, *anyopaque, u64) callconv(.c) i64, +}; + +pub const OutputStream = extern struct { + ctx: ?*anyopaque, + write: *const fn (*const OutputStream, *const anyopaque, u64) callconv(.c) i64, +}; + +pub const State = extern struct { + save: *const fn (*const Plugin, *const OutputStream) callconv(.c) bool, + load: *const fn (*const Plugin, *const InputStream) callconv(.c) bool, +}; + +pub const event_param_value: u16 = 5; +pub const process_error: i32 = 0; +pub const process_continue: i32 = 1; +pub const param_automatable: u32 = 1 << 5; +pub const param_stepped: u32 = 1 << 0; +pub const param_bypass: u32 = 1 << 4; +pub const audio_port_main: u32 = 1; +pub const invalid_id: u32 = 0xffffffff; + +test "CLAP ABI structure sizes" { + const std = @import("std"); + try std.testing.expectEqual(@as(usize, 12), @sizeOf(Version)); + try std.testing.expectEqual(@as(usize, 16), @sizeOf(EventHeader)); + if (@sizeOf(usize) == 8) { + try std.testing.expectEqual(@as(usize, 56), @sizeOf(EventParamValue)); + try std.testing.expectEqual(@as(usize, 40), @sizeOf(AudioBuffer)); + try std.testing.expectEqual(@as(usize, 104), @sizeOf(Plugin)); + } +} From 7dae6db97d00ef4d95fb2481515eb69731099d39 Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 13:58:08 +0000 Subject: [PATCH 04/26] Implement loadable CLAP gain plugin with audio, automation, parameters and state --- examples/danzig-gain-clap/root.zig | 337 +++++++++++++++++++++++++++++ 1 file changed, 337 insertions(+) create mode 100644 examples/danzig-gain-clap/root.zig diff --git a/examples/danzig-gain-clap/root.zig b/examples/danzig-gain-clap/root.zig new file mode 100644 index 0000000..a3a380c --- /dev/null +++ b/examples/danzig-gain-clap/root.zig @@ -0,0 +1,337 @@ +// Danzig Gain CLAP adapter. DSP and parameter storage are shared with the VST3 example. +const std = @import("std"); +const clap = @import("danzig").clap; +const core = @import("../danzig-gain/dsp.zig"); + +const plugin_id = "dev.superelectric.danzig.gain"; +const features = [_]?[*:0]const u8{ "audio-effect", "stereo", null }; +const descriptor = clap.Descriptor{ + .clap_version = .{}, + .id = plugin_id, + .name = "Danzig Gain", + .vendor = "Superelectric", + .url = "https://superelectric.dev", + .manual_url = null, + .support_url = null, + .version = "0.1.0", + .description = "Stereo gain with smoothed automation and bypass", + .features = features[0..].ptr, +}; + +const Instance = struct { + plugin: clap.Plugin, + dsp: core.GainPlugin, + active: bool = false, + processing: bool = false, +}; + +fn instance(plugin: *const clap.Plugin) *Instance { + return @ptrCast(@alignCast(plugin.plugin_data.?)); +} + +fn pluginInit(plugin: *const clap.Plugin) callconv(.c) bool { + _ = plugin; + return true; +} + +fn pluginDestroy(plugin: *const clap.Plugin) callconv(.c) void { + std.heap.page_allocator.destroy(instance(plugin)); +} + +fn pluginActivate(plugin: *const clap.Plugin, sample_rate: f64, min_frames: u32, max_frames: u32) callconv(.c) bool { + if (!std.math.isFinite(sample_rate) or sample_rate <= 0 or max_frames == 0 or min_frames > max_frames) return false; + const self = instance(plugin); + self.dsp.setSampleRate(@floatCast(sample_rate)); + self.active = true; + return true; +} + +fn pluginDeactivate(plugin: *const clap.Plugin) callconv(.c) void { + const self = instance(plugin); + self.processing = false; + self.active = false; +} + +fn startProcessing(plugin: *const clap.Plugin) callconv(.c) bool { + const self = instance(plugin); + if (!self.active) return false; + self.processing = true; + return true; +} + +fn stopProcessing(plugin: *const clap.Plugin) callconv(.c) void { + instance(plugin).processing = false; +} + +fn reset(plugin: *const clap.Plugin) callconv(.c) void { + instance(plugin).dsp.params.snapAll(); +} + +fn plainValue(self: *const Instance, id: u32) ?f64 { + if (id >= core.num_params) return null; + const norm = self.dsp.params.getNormalized(id); + return if (id == core.ParamIndex.gain) + @as(f64, norm) * 96.0 - 48.0 + else if (norm >= 0.5) @as(f64, 1.0) else @as(f64, 0.0); +} + +fn setPlain(self: *Instance, id: u32, value: f64) void { + if (!std.math.isFinite(value)) return; + switch (id) { + core.ParamIndex.gain => self.dsp.params.setNormalized(id, @floatCast(std.math.clamp((value + 48.0) / 96.0, 0.0, 1.0))), + core.ParamIndex.bypass => self.dsp.params.setNormalized(id, if (value >= 0.5) 1.0 else 0.0), + else => {}, + } +} + +fn applyEvent(self: *Instance, header: *const clap.EventHeader) void { + if (header.space_id != 0 or header.@"type" != clap.event_param_value or header.size < @sizeOf(clap.EventParamValue)) return; + const event: *const clap.EventParamValue = @ptrCast(@alignCast(header)); + // Per-note modulation is deliberately not advertised by this effect. + if (event.note_id != -1 or event.port_index != -1 or event.channel != -1 or event.key != -1) return; + setPlain(self, event.param_id, event.value); +} + +fn flushEvents(self: *Instance, events: ?*const clap.InputEvents) void { + const list = events orelse return; + for (0..list.size(list)) |i| { + if (list.get(list, @intCast(i))) |header| applyEvent(self, header); + } +} + +fn processAudio(plugin: *const clap.Plugin, process: *const clap.Process) callconv(.c) i32 { + const self = instance(plugin); + if (!self.processing or process.audio_outputs_count != 1 or process.audio_inputs_count != 1) return clap.process_error; + const inputs = process.audio_inputs orelse return clap.process_error; + const outputs = process.audio_outputs orelse return clap.process_error; + const input = &inputs[0]; + const output = &outputs[0]; + const in_data = input.data32 orelse return clap.process_error; + const out_data = output.data32 orelse return clap.process_error; + if (input.channel_count != 2 or output.channel_count != 2) return clap.process_error; + + const events = process.in_events; + const count: u32 = if (events) |list| list.size(list) else 0; + var next: u32 = 0; + var frame: u32 = 0; + while (frame < process.frames_count) : (frame += 1) { + while (next < count) { + const header = events.?.get(events.?, next) orelse { + next += 1; + continue; + }; + if (header.time > frame) break; + applyEvent(self, header); + next += 1; + } + const gain = self.dsp.nextGain(self.dsp.isBypassed()); + for (0..2) |channel| { + const constant = (input.constant_mask & (@as(u64, 1) << @intCast(channel))) != 0; + const source_frame: usize = if (constant) 0 else frame; + out_data[channel][frame] = in_data[channel][source_frame] * gain; + } + } + // Zero-frame process() is allowed to carry automation. + while (next < count) : (next += 1) { + if (events.?.get(events.?, next)) |header| applyEvent(self, header); + } + output.constant_mask = 0; + return clap.process_continue; +} + +fn getExtension(_: *const clap.Plugin, id: [*:0]const u8) callconv(.c) ?*const anyopaque { + const name = std.mem.span(id); + if (std.mem.eql(u8, name, "clap.audio-ports")) return @ptrCast(&audio_ports); + if (std.mem.eql(u8, name, "clap.params")) return @ptrCast(¶ms); + if (std.mem.eql(u8, name, "clap.state")) return @ptrCast(&state); + return null; +} + +fn onMainThread(_: *const clap.Plugin) callconv(.c) void {} + +fn portCount(_: *const clap.Plugin, _: bool) callconv(.c) u32 { + return 1; +} + +fn getPort(_: *const clap.Plugin, index: u32, is_input: bool, info: *clap.PortInfo) callconv(.c) bool { + if (index != 0) return false; + info.* = std.mem.zeroes(clap.PortInfo); + info.id = 0; + info.flags = clap.audio_port_main; + info.channel_count = 2; + info.port_type = "stereo"; + info.in_place_pair = 0; + const name = if (is_input) "Stereo In" else "Stereo Out"; + @memcpy(info.name[0..name.len], name); + return true; +} + +const audio_ports = clap.AudioPorts{ .count = portCount, .get = getPort }; + +fn paramCount(_: *const clap.Plugin) callconv(.c) u32 { + return core.num_params; +} + +fn paramInfo(_: *const clap.Plugin, index: u32, info: *clap.ParamInfo) callconv(.c) bool { + if (index >= core.num_params) return false; + info.* = std.mem.zeroes(clap.ParamInfo); + info.id = index; + info.flags = clap.param_automatable; + if (index == core.ParamIndex.gain) { + @memcpy(info.name[0..4], "Gain"); + info.min_value = -48.0; + info.max_value = 48.0; + info.default_value = 0.0; + } else { + @memcpy(info.name[0..6], "Bypass"); + info.flags |= clap.param_stepped | clap.param_bypass; + info.min_value = 0.0; + info.max_value = 1.0; + info.default_value = 0.0; + } + return true; +} + +fn paramGetValue(plugin: *const clap.Plugin, id: u32, out: *f64) callconv(.c) bool { + out.* = plainValue(instance(plugin), id) orelse return false; + return true; +} + +fn paramValueToText(_: *const clap.Plugin, id: u32, value: f64, buffer: [*]u8, capacity: u32) callconv(.c) bool { + if (id >= core.num_params or capacity < 2) return false; + const slice = buffer[0..capacity]; + if (id == core.ParamIndex.bypass) { + const word = if (value >= 0.5) "On" else "Off"; + if (word.len + 1 > slice.len) return false; + @memcpy(slice[0..word.len], word); + slice[word.len] = 0; + return true; + } + const formatted = std.fmt.bufPrint(slice[0 .. slice.len - 1], "{d} dB", .{value}) catch return false; + slice[formatted.len] = 0; + return true; +} + +fn paramTextToValue(_: *const clap.Plugin, id: u32, text: [*:0]const u8, out: *f64) callconv(.c) bool { + if (id >= core.num_params) return false; + const raw = std.mem.trim(u8, std.mem.span(text), " \t"); + if (id == core.ParamIndex.bypass) { + if (std.ascii.eqlIgnoreCase(raw, "On")) { out.* = 1; return true; } + if (std.ascii.eqlIgnoreCase(raw, "Off")) { out.* = 0; return true; } + } + const number = if (std.mem.endsWith(u8, raw, "dB")) std.mem.trim(u8, raw[0 .. raw.len - 2], " \t") else raw; + const value = std.fmt.parseFloat(f64, number) catch return false; + if (!std.math.isFinite(value)) return false; + out.* = value; + return true; +} + +fn paramFlush(plugin: *const clap.Plugin, inputs: *const clap.InputEvents, _: *const clap.OutputEvents) callconv(.c) void { + flushEvents(instance(plugin), inputs); +} + +const params = clap.Params{ + .count = paramCount, + .get_info = paramInfo, + .get_value = paramGetValue, + .value_to_text = paramValueToText, + .text_to_value = paramTextToValue, + .flush = paramFlush, +}; + +// Versioned, little-endian state: "DZG1", gain bits, bypass bits. +fn stateSave(plugin: *const clap.Plugin, stream: *const clap.OutputStream) callconv(.c) bool { + const self = instance(plugin); + var bytes = [_]u8{ 'D', 'Z', 'G', '1' } ++ [_]u8{0} ** 8; + for (0..core.num_params) |i| { + const bits: u32 = @bitCast(self.dsp.params.getNormalized(@intCast(i))); + for (0..4) |byte| { + bytes[4 + i * 4 + byte] = @truncate(bits >> @intCast(byte * 8)); + } + } + var done: usize = 0; + while (done < bytes.len) { + const n = stream.write(stream, @ptrCast(&bytes[done]), @intCast(bytes.len - done)); + if (n <= 0 or @as(u64, @intCast(n)) > bytes.len - done) return false; + done += @intCast(n); + } + return true; +} + +fn stateLoad(plugin: *const clap.Plugin, stream: *const clap.InputStream) callconv(.c) bool { + var bytes: [12]u8 = undefined; + var done: usize = 0; + while (done < bytes.len) { + const n = stream.read(stream, @ptrCast(&bytes[done]), @intCast(bytes.len - done)); + if (n <= 0 or @as(u64, @intCast(n)) > bytes.len - done) return false; + done += @intCast(n); + } + if (!std.mem.eql(u8, bytes[0..4], "DZG1")) return false; + var values: [2]f32 = undefined; + for (0..2) |i| { + var bits: u32 = 0; + for (0..4) |byte| bits |= @as(u32, bytes[4 + i * 4 + byte]) << @intCast(byte * 8); + values[i] = @bitCast(bits); + if (!std.math.isFinite(values[i]) or values[i] < 0 or values[i] > 1) return false; + } + const self = instance(plugin); + for (0..2) |i| self.dsp.params.setNormalized(@intCast(i), values[i]); + return true; +} + +const state = clap.State{ .save = stateSave, .load = stateLoad }; + +fn factoryCount(_: *const clap.PluginFactory) callconv(.c) u32 { + return 1; +} + +fn factoryDescriptor(_: *const clap.PluginFactory, index: u32) callconv(.c) ?*const clap.Descriptor { + return if (index == 0) &descriptor else null; +} + +fn factoryCreate(_: *const clap.PluginFactory, _: *const clap.Host, id: [*:0]const u8) callconv(.c) ?*const clap.Plugin { + if (!std.mem.eql(u8, std.mem.span(id), plugin_id)) return null; + const self = std.heap.page_allocator.create(Instance) catch return null; + self.* = .{ + .dsp = core.GainPlugin.init(48000), + .plugin = .{ + .desc = &descriptor, + .plugin_data = self, + .init = pluginInit, + .destroy = pluginDestroy, + .activate = pluginActivate, + .deactivate = pluginDeactivate, + .start_processing = startProcessing, + .stop_processing = stopProcessing, + .reset = reset, + .process = processAudio, + .get_extension = getExtension, + .on_main_thread = onMainThread, + }, + }; + return &self.plugin; +} + +const factory = clap.PluginFactory{ + .get_plugin_count = factoryCount, + .get_plugin_descriptor = factoryDescriptor, + .create_plugin = factoryCreate, +}; + +fn entryInit(_: [*:0]const u8) callconv(.c) bool { + return true; +} + +fn entryDeinit() callconv(.c) void {} + +fn entryGetFactory(id: [*:0]const u8) callconv(.c) ?*const anyopaque { + if (std.mem.eql(u8, std.mem.span(id), "clap.plugin-factory")) return @ptrCast(&factory); + return null; +} + +pub export var clap_entry: clap.Entry = .{ + .clap_version = .{}, + .init = entryInit, + .deinit = entryDeinit, + .get_factory = entryGetFactory, +}; From 336a99817549af7ce8071e17554f9e883574471a Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 13:59:25 +0000 Subject: [PATCH 05/26] Expose CLAP interface in public module --- src/root.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/root.zig b/src/root.zig index 1d69a58..4beacfa 100644 --- a/src/root.zig +++ b/src/root.zig @@ -1,6 +1,7 @@ // Danzig VST3 Library Root pub const vst3 = @import("vst3.zig"); +pub const clap = @import("clap.zig"); pub const plugin = @import("plugin.zig"); pub const audio = @import("audio.zig"); pub const params = @import("params.zig"); From e8262186c85481d3511f883aaa6dda0979f3c301 Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 13:59:27 +0000 Subject: [PATCH 06/26] Correct CLAP ABI test sizes --- src/clap.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clap.zig b/src/clap.zig index f37b858..b1a120a 100644 --- a/src/clap.zig +++ b/src/clap.zig @@ -162,7 +162,7 @@ test "CLAP ABI structure sizes" { try std.testing.expectEqual(@as(usize, 16), @sizeOf(EventHeader)); if (@sizeOf(usize) == 8) { try std.testing.expectEqual(@as(usize, 56), @sizeOf(EventParamValue)); - try std.testing.expectEqual(@as(usize, 40), @sizeOf(AudioBuffer)); - try std.testing.expectEqual(@as(usize, 104), @sizeOf(Plugin)); + try std.testing.expectEqual(@as(usize, 32), @sizeOf(AudioBuffer)); + try std.testing.expectEqual(@as(usize, 96), @sizeOf(Plugin)); } } From df25770e2d0cdbfd691f45aa2678b36dd85a9a85 Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 13:59:33 +0000 Subject: [PATCH 07/26] Build native CLAP and universal macOS bundle --- build.zig | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/build.zig b/build.zig index c8e8266..2f7d73f 100644 --- a/build.zig +++ b/build.zig @@ -38,6 +38,19 @@ pub fn build(b: *std.Build) void { // Install to zig-out/lib/ b.installArtifact(danzig_gain); + // Native CLAP dynamic library. macOS bundle packaging is a separate step. + const danzig_clap = b.addLibrary(.{ + .name = "DanzigGainCLAP", + .root_module = b.createModule(.{ + .root_source_file = b.path("examples/danzig-gain-clap/root.zig"), + .target = target, + .optimize = optimize, + }), + .linkage = .dynamic, + }); + danzig_clap.root_module.addImport("danzig", danzig_module); + b.installArtifact(danzig_clap); + // Integration harness. Links the plugin itself so it can call the exported // GetPluginFactory entry point and drive it through the raw VST3 C ABI. const danzig_test = b.addExecutable(.{ @@ -131,6 +144,7 @@ pub fn build(b: *std.Build) void { // because it doubles compile work and only applies to macOS. if (target.result.os.tag == .macos) { addVst3Bundle(b, optimize, danzig_module); + addClapBundle(b, optimize, danzig_module); } // --- GUI example (macOS) ------------------------------------------------- @@ -313,3 +327,78 @@ fn infoPlist(b: *std.Build) []const u8 { ; return b.fmt(template, .{ VERSION, VERSION }); } + + +/// Build a universal macOS CLAP bundle containing the same DSP used by VST3. +fn addClapBundle( + b: *std.Build, + optimize: std.builtin.OptimizeMode, + danzig_module: *std.Build.Module, +) void { + const arches = [_]std.Target.Cpu.Arch{ .aarch64, .x86_64 }; + const suffixes = [_][]const u8{ "arm64", "x86" }; + const lipo = b.addSystemCommand(&.{ "lipo", "-create" }); + + inline for (arches, suffixes) |arch, suffix| { + const arch_target = b.resolveTargetQuery(.{ .cpu_arch = arch, .os_tag = .macos }); + const plugin = b.addLibrary(.{ + .name = "DanzigGainCLAP_" ++ suffix, + .root_module = b.createModule(.{ + .root_source_file = b.path("examples/danzig-gain-clap/root.zig"), + .target = arch_target, + .optimize = optimize, + }), + .linkage = .dynamic, + }); + plugin.root_module.addImport("danzig", danzig_module); + lipo.addArtifactArg(plugin); + } + + lipo.addArg("-output"); + const universal = lipo.addOutputFileArg("DanzigGain"); + const bundle = b.addWriteFiles(); + _ = bundle.add("Contents/Info.plist", clapInfoPlist(b)); + _ = bundle.add("Contents/PkgInfo", "BNDL????"); + _ = bundle.addCopyFile(universal, "Contents/MacOS/DanzigGain"); + + const package = b.addInstallDirectory(.{ + .source_dir = bundle.getDirectory(), + .install_dir = .prefix, + .install_subdir = "DanzigGain.clap", + }); + const clap_step = b.step("clap", "Build the universal macOS CLAP plugin"); + clap_step.dependOn(&package.step); + + const install = b.addSystemCommand(&.{ + "sh", "-c", + "mkdir -p \"$HOME/Library/Audio/Plug-Ins/CLAP\" && rm -rf \"$HOME/Library/Audio/Plug-Ins/CLAP/DanzigGain.clap\" && cp -R \"$1\" \"$HOME/Library/Audio/Plug-Ins/CLAP/DanzigGain.clap\"", + "sh", + }); + install.addDirectoryArg(bundle.getDirectory()); + const install_step = b.step("install-clap", "Install CLAP to ~/Library/Audio/Plug-Ins/CLAP/"); + install_step.dependOn(&install.step); +} + +fn clapInfoPlist(b: *std.Build) []const u8 { + const template = + \\ + \\ + \\ + \\ + \\ CFBundleExecutable + \\ DanzigGain + \\ CFBundleIdentifier + \\ dev.superelectric.danzig.gain.clap + \\ CFBundleName + \\ DanzigGain + \\ CFBundlePackageType + \\ BNDL + \\ CFBundleVersion + \\ {s} + \\ CFBundleShortVersionString + \\ {s} + \\ + \\ + ; + return b.fmt(template, .{ VERSION, VERSION }); +} From c836faa8d01af499f8d9feaff80b16c5f1fceae2 Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 14:01:27 +0000 Subject: [PATCH 08/26] Exercise CLAP loading, audio processing and sample-timed automation --- examples/danzig-clap-test/root.zig | 114 +++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 examples/danzig-clap-test/root.zig diff --git a/examples/danzig-clap-test/root.zig b/examples/danzig-clap-test/root.zig new file mode 100644 index 0000000..c4300a3 --- /dev/null +++ b/examples/danzig-clap-test/root.zig @@ -0,0 +1,114 @@ +// Black-box CLAP ABI smoke test: factory, parameters, state extension, audio, automation. +const std = @import("std"); +const clap = @import("danzig").clap; +extern var clap_entry: clap.Entry; + +const automation = clap.EventParamValue{ + .header = .{ + .size = @sizeOf(clap.EventParamValue), + .time = 0, + .space_id = 0, + .@"type" = clap.event_param_value, + .flags = 0, + }, + .param_id = 0, + .cookie = null, + .note_id = -1, + .port_index = -1, + .channel = -1, + .key = -1, + .value = -6.0, +}; + +fn eventCount(_: *const clap.InputEvents) callconv(.c) u32 { + return 1; +} + +fn eventGet(_: *const clap.InputEvents, index: u32) callconv(.c) ?*const clap.EventHeader { + return if (index == 0) &automation.header else null; +} + +const in_events = clap.InputEvents{ + .ctx = null, + .size = eventCount, + .get = eventGet, +}; + +pub fn main() !void { + const testing = std.testing; + try testing.expect(clap_entry.init("DanzigGain.clap")); + defer clap_entry.deinit(); + + const raw = clap_entry.get_factory("clap.plugin-factory") orelse return error.FactoryNotFound; + const factory: *const clap.PluginFactory = @ptrCast(@alignCast(raw)); + try testing.expectEqual(@as(u32, 1), factory.get_plugin_count(factory)); + const desc = factory.get_plugin_descriptor(factory, 0) orelse return error.MissingDescriptor; + try testing.expectEqualStrings("Danzig Gain", std.mem.span(desc.name)); + try testing.expect(factory.get_plugin_descriptor(factory, 1) == null); + + // The example CLAP adapter never dereferences the host pointer. + var host_storage: u8 = 0; + const host: *const clap.Host = @ptrCast(&host_storage); + const plugin = factory.create_plugin(factory, host, desc.id) orelse return error.CannotCreate; + defer plugin.destroy(plugin); + try testing.expect(plugin.init(plugin)); + + const params_raw = plugin.get_extension(plugin, "clap.params") orelse return error.ParamsMissing; + const params: *const clap.Params = @ptrCast(@alignCast(params_raw)); + try testing.expectEqual(@as(u32, 2), params.count(plugin)); + var info: clap.ParamInfo = undefined; + try testing.expect(params.get_info(plugin, 1, &info)); + try testing.expect((info.flags & clap.param_bypass) != 0); + + const ports_raw = plugin.get_extension(plugin, "clap.audio-ports") orelse return error.PortsMissing; + const ports: *const clap.AudioPorts = @ptrCast(@alignCast(ports_raw)); + try testing.expectEqual(@as(u32, 1), ports.count(plugin, true)); + var port_info: clap.PortInfo = undefined; + try testing.expect(ports.get(plugin, 0, false, &port_info)); + try testing.expectEqual(@as(u32, 2), port_info.channel_count); + + try testing.expect(plugin.activate(plugin, 48000.0, 1, 512)); + defer plugin.deactivate(plugin); + try testing.expect(plugin.start_processing(plugin)); + defer plugin.stop_processing(plugin); + + var left_in = [_]f32{1.0} ** 32; + var right_in = [_]f32{0.5} ** 32; + var left_out = [_]f32{0.0} ** 32; + var right_out = [_]f32{0.0} ** 32; + var inputs = [_][*]f32{ &left_in, &right_in }; + var outputs = [_][*]f32{ &left_out, &right_out }; + var input_bus = [_]clap.AudioBuffer{.{ + .data32 = &inputs, + .data64 = null, + .channel_count = 2, + .latency = 0, + .constant_mask = 0, + }}; + var output_bus = [_]clap.AudioBuffer{.{ + .data32 = &outputs, + .data64 = null, + .channel_count = 2, + .latency = 0, + .constant_mask = 0, + }}; + const block = clap.Process{ + .steady_time = 0, + .frames_count = 32, + .transport = null, + .audio_inputs = &input_bus, + .audio_outputs = &output_bus, + .audio_inputs_count = 1, + .audio_outputs_count = 1, + .in_events = &in_events, + .out_events = null, + }; + try testing.expectEqual(clap.process_continue, plugin.process(plugin, &block)); + try testing.expect(left_out[0] < 1.0); + try testing.expect(left_out[31] < left_out[0]); + try testing.expectApproxEqAbs(left_out[31] * 0.5, right_out[31], 0.0001); + + var value: f64 = 0; + try testing.expect(params.get_value(plugin, 0, &value)); + try testing.expectApproxEqAbs(@as(f64, -6.0), value, 0.0001); +} From 2866900ee2550aac1ecde1d8d2045d00f69f8ec8 Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 14:01:47 +0000 Subject: [PATCH 09/26] Add CLAP ABI integration harness to build and tests --- build.zig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/build.zig b/build.zig index 2f7d73f..525905c 100644 --- a/build.zig +++ b/build.zig @@ -51,6 +51,22 @@ pub fn build(b: *std.Build) void { danzig_clap.root_module.addImport("danzig", danzig_module); b.installArtifact(danzig_clap); + // Execute the CLAP factory and DSP through the exported C ABI. + const clap_test = b.addExecutable(.{ + .name = "danzig_clap_test", + .root_module = b.createModule(.{ + .root_source_file = b.path("examples/danzig-clap-test/root.zig"), + .target = target, + .optimize = optimize, + }), + }); + clap_test.root_module.addImport("danzig", danzig_module); + clap_test.root_module.linkLibrary(danzig_clap); + b.installArtifact(clap_test); + const run_clap_test = b.addRunArtifact(clap_test); + const clap_test_step = b.step("test-clap", "Run CLAP ABI integration tests"); + clap_test_step.dependOn(&run_clap_test.step); + // Integration harness. Links the plugin itself so it can call the exported // GetPluginFactory entry point and drive it through the raw VST3 C ABI. const danzig_test = b.addExecutable(.{ @@ -183,6 +199,7 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", "Run tests"); test_step.dependOn(&run_unit_tests.step); test_step.dependOn(&run_test.step); + test_step.dependOn(&run_clap_test.step); } /// Build DanzigGain for both macOS architectures, merge them into one From b3b58cf39e3f0de1f7f1aa602cb4531c843e5806 Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 14:01:50 +0000 Subject: [PATCH 10/26] Verify CLAP integration and macOS packaging in CI --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 532ba87..6e1cabb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,3 +39,6 @@ jobs: # Drives the built plugin through the raw VST3 C ABI. - name: Test run: zig build test + + - name: Package CLAP + run: zig build clap From 1745da9a55b20f8224a9c150dd709d9bffcc5481 Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 14:01:53 +0000 Subject: [PATCH 11/26] Distribute format adapter scripts with Zig package --- build.zig.zon | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.zig.zon b/build.zig.zon index d684d23..e39b09d 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -18,6 +18,8 @@ "build.zig.zon", "src", "examples", + "wrappers", + "scripts", "ui", }, } From 491483972bf84841ba197973a3edee7c74f7e0b9 Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 14:03:47 +0000 Subject: [PATCH 12/26] Provide effect-typed AUv2 and optional AAX wrapper targets --- wrappers/CMakeLists.txt | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 wrappers/CMakeLists.txt diff --git a/wrappers/CMakeLists.txt b/wrappers/CMakeLists.txt new file mode 100644 index 0000000..8fcee46 --- /dev/null +++ b/wrappers/CMakeLists.txt @@ -0,0 +1,47 @@ +cmake_minimum_required(VERSION 3.21) +project(DanzigFormatWrappers LANGUAGES C CXX) + +if (NOT APPLE) + message(FATAL_ERROR "This wrapper project builds AUv2 on macOS. AAX Windows builds can use clap-wrapper directly.") +endif() + +if (NOT DEFINED CLAP_WRAPPER_SOURCE OR NOT EXISTS "${CLAP_WRAPPER_SOURCE}/CMakeLists.txt") + message(FATAL_ERROR "Set CLAP_WRAPPER_SOURCE to a checkout of free-audio/clap-wrapper") +endif() + +if (NOT DEFINED DANZIG_CLAP_BUNDLE OR NOT EXISTS "${DANZIG_CLAP_BUNDLE}") + message(FATAL_ERROR "Set DANZIG_CLAP_BUNDLE to the built DanzigGain.clap bundle (zig build clap)") +endif() + +set(CLAP_WRAPPER_OUTPUT_NAME "DanzigGain" CACHE STRING "CLAP wrapper output" FORCE) +set(CLAP_WRAPPER_COPY_AFTER_BUILD OFF CACHE BOOL "Install wrappers automatically" FORCE) +add_subdirectory("${CLAP_WRAPPER_SOURCE}" "${CMAKE_CURRENT_BINARY_DIR}/clap-wrapper") + +add_library(danzig_gain_auv2 MODULE) +target_add_auv2_wrapper( + TARGET danzig_gain_auv2 + OUTPUT_NAME "DanzigGain" + BUNDLE_IDENTIFIER "dev.superelectric.danzig.gain.auv2" + BUNDLE_VERSION "0.1.0" + PREFER_CMAKE_AUV2_CONFIGURATION TRUE + MANUFACTURER_NAME "Superelectric" + MANUFACTURER_CODE "SuEl" + SUBTYPE_CODE "DzGn" + INSTRUMENT_TYPE "aufx" + MACOS_EMBEDDED_CLAP_LOCATION "${DANZIG_CLAP_BUNDLE}" +) + +option(DANZIG_BUILD_AAX "Build the AAX wrapper with the licensed Avid SDK" OFF) +if (DANZIG_BUILD_AAX) + if (NOT DEFINED AAX_SDK_ROOT OR NOT EXISTS "${AAX_SDK_ROOT}/Interfaces/AAX_Exports.cpp") + message(FATAL_ERROR "Set AAX_SDK_ROOT to an installed Avid AAX SDK checkout") + endif() + add_library(danzig_gain_aax MODULE) + target_add_aax_wrapper( + TARGET danzig_gain_aax + OUTPUT_NAME "DanzigGain" + BUNDLE_IDENTIFIER "dev.superelectric.danzig.gain.aax" + BUNDLE_VERSION "0.1.0" + MACOS_EMBEDDED_CLAP_LOCATION "${DANZIG_CLAP_BUNDLE}" + ) +endif() From daa63bb253e0a1e892db0369ca00d51bfde73807 Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 14:04:03 +0000 Subject: [PATCH 13/26] Add AUv2/AAX CMake build helper with SDK gates --- scripts/build-wrappers.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 scripts/build-wrappers.sh diff --git a/scripts/build-wrappers.sh b/scripts/build-wrappers.sh new file mode 100644 index 0000000..f37870e --- /dev/null +++ b/scripts/build-wrappers.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +: "${CLAP_WRAPPER_SOURCE:?Set CLAP_WRAPPER_SOURCE to the free-audio/clap-wrapper source directory}" +: "${CLAP_SDK_ROOT:?Set CLAP_SDK_ROOT to the free-audio/clap source directory}" +: "${AUDIOUNIT_SDK_ROOT:?Set AUDIOUNIT_SDK_ROOT to the Apple AudioUnitSDK source directory}" + +if [[ "$(uname -s)" != "Darwin" ]]; then + echo "AUv2 wrapper builds require macOS" >&2 + exit 1 +fi + +cd "$ROOT" +zig build clap + +BUILD_AAX=OFF +if [[ "${DANZIG_BUILD_AAX:-OFF}" == "ON" ]]; then + : "${AAX_SDK_ROOT:?Set AAX_SDK_ROOT to the licensed Avid SDK when DANZIG_BUILD_AAX=ON}" + BUILD_AAX=ON +fi + +cmake -S "$ROOT/wrappers" -B "$ROOT/zig-out/format-wrappers" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCLAP_WRAPPER_SOURCE="$CLAP_WRAPPER_SOURCE" \ + -DCLAP_SDK_ROOT="$CLAP_SDK_ROOT" \ + -DAUDIOUNIT_SDK_ROOT="$AUDIOUNIT_SDK_ROOT" \ + -DAAX_SDK_ROOT="${AAX_SDK_ROOT:-}" \ + -DDANZIG_CLAP_BUNDLE="$ROOT/zig-out/DanzigGain.clap" \ + -DDANZIG_BUILD_AAX="$BUILD_AAX" +cmake --build "$ROOT/zig-out/format-wrappers" --config Release --parallel From d111a095b627a787c338627d0a594ca3e6e638a6 Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 14:04:41 +0000 Subject: [PATCH 14/26] Document CLAP, AUv2 and AAX build and validation paths --- docs/FORMATS.md | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 docs/FORMATS.md diff --git a/docs/FORMATS.md b/docs/FORMATS.md new file mode 100644 index 0000000..6c0f266 --- /dev/null +++ b/docs/FORMATS.md @@ -0,0 +1,78 @@ +# Plugin formats + +Danzig's DSP is host-neutral Zig. The VST3 and CLAP adapters share +`examples/danzig-gain/dsp.zig`; the CLAP ABI declarations live in +`src/clap.zig`. The CLAP example implements its factory, stereo ports, gain and +bypass parameters, sample-timed automation and state persistence. Hosts provide +generic parameter controls; no custom CLAP editor is claimed. + +## CLAP + +Build and test the CLAP adapter on a supported target with `zig build` and +`zig build test-clap`. On macOS, package and install the universal bundle: + +```sh +zig build clap +zig build test-clap +zig build install-clap +``` + +The bundle is `zig-out/DanzigGain.clap`. Install it to +`~/Library/Audio/Plug-Ins/CLAP` or `/Library/Audio/Plug-Ins/CLAP` on macOS. +The plugin identifier is `dev.superelectric.danzig.gain`, which must remain +stable across releases. Before shipping, validate using clap-validator and +a real host such as REAPER. + +## Audio Unit v2 + +AUv2 is produced by [clap-wrapper](https://github.com/free-audio/clap-wrapper), +which hosts the CLAP implementation rather than duplicating the audio/parameter +protocol. The wrapper registers as an **effect** (`aufx`), not an instrument +(`aumu`), with subtype `DzGn` and manufacturer code `SuEl`. + +On macOS, install Zig, CMake and Xcode command-line tools, then clone +[free-audio/clap](https://github.com/free-audio/clap), +[free-audio/clap-wrapper](https://github.com/free-audio/clap-wrapper), and +[apple/AudioUnitSDK](https://github.com/apple/AudioUnitSDK). + +```sh +export CLAP_WRAPPER_SOURCE="$HOME/src/clap-wrapper" +export CLAP_SDK_ROOT="$HOME/src/clap" +export AUDIOUNIT_SDK_ROOT="$HOME/src/AudioUnitSDK" +bash scripts/build-wrappers.sh +``` + +The `DanzigGain.component` bundle is produced under `zig-out/format-wrappers`. +Copy it into `~/Library/Audio/Plug-Ins/Components/`, sign as appropriate +and run `auval -v aufx DzGn SuEl` after registration. The AUv2 build requires +external SDKs and is intentionally not part of `zig build`. + +## AAX + +The same clap-wrapper project supports an optional AAX target, using Avid's +separately licensed AAX SDK. On macOS, set `AAX_SDK_ROOT` and opt in: + +```sh +export DANZIG_BUILD_AAX=ON +export AAX_SDK_ROOT="$HOME/src/aax" +bash scripts/build-wrappers.sh +``` + +This can produce a `DanzigGain.aaxplugin` wrapper if the SDK and toolchain +support it. It is **not** automatically a Pro Tools-loadable release: Avid +developer terms, Avid/PACE signing, and validation in Pro Tools are still +required. Pro Tools testing also needs an iLok account. No AAX SDK sources +or signing credentials are committed to the repository. + +## Verification matrix + +| Format | Build | Verification | +|---|---|---| +| VST3 | `zig build vst3` | Existing VST3 C ABI harness | +| CLAP | `zig build clap` | CLAP factory, parameters and processing harness | +| AUv2 | `bash scripts/build-wrappers.sh` | Requires AudioUnitSDK, macOS and `auval` | +| AAX | `DANZIG_BUILD_AAX=ON bash scripts/build-wrappers.sh` | Requires Avid SDK, signing and Pro Tools | + +These external wrappers are not a claim of independent native Zig AU or AAX +implementations. Danzig and clap-wrapper are MIT licensed; Apple AudioUnitSDK +and Avid AAX SDK have independent licences and redistribution requirements. From 6b56fe269e9749f5c86d3b55b823f46f986cb189 Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 14:05:05 +0000 Subject: [PATCH 15/26] Expose new CLAP, AU and AAX format support in README --- README.md | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3b903a6..e900ed7 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,12 @@ [![CI](https://github.com/godofecht/danzig/actions/workflows/ci.yml/badge.svg)](https://github.com/godofecht/danzig/actions/workflows/ci.yml) [![Zig](https://img.shields.io/badge/zig-0.14.1%20%7C%200.15.2%20%7C%200.16.0-f7a41d)](https://ziglang.org/) -A VST3 plugin framework in pure Zig. No JUCE, no Steinberg SDK, no C++ in the -core. `src/vst3.zig` implements the VST3 C ABI directly as `extern struct`s of +A VST3 and CLAP plugin framework in pure Zig. No JUCE, no Steinberg SDK, no C++ in the +core. AUv2 and AAX builds are available through optional external CLAP wrappers. `src/vst3.zig` implements the VST3 C ABI directly as `extern struct`s of `callconv(.c)` function pointers, which is what a C++ vtable is at the machine level. -**[Read the guide: docs/WIKI.md](docs/WIKI.md)** +**[Read the guide: docs/WIKI.md](docs/WIKI.md)** | **[Plugin formats: CLAP / AU / AAX](docs/FORMATS.md)** ## Setup @@ -27,8 +27,11 @@ By hand: ```bash zig build # Build Summary: 29/29 steps succeeded zig build test --summary all # Build Summary: 9/9 steps succeeded; 35/35 tests passed -zig build vst3 # universal arm64 + x86_64 bundle in zig-out/ +zig build vst3 # universal arm64 + x86_64 VST3 bundle in zig-out/ +zig build clap # universal arm64 + x86_64 CLAP bundle +zig build test-clap # CLAP factory and processing integration test zig build install-vst3 # copy it to ~/Library/Audio/Plug-Ins/VST3/ +zig build install-clap # copy it to ~/Library/Audio/Plug-Ins/CLAP/ ``` Then: @@ -54,6 +57,7 @@ Architectures in the fat file: zig-out/DanzigGain.vst3/Contents/MacOS/DanzigGain | File | Contents | |---|---| +| `clap.zig` | The CLAP 1.x C ABI, plugin lifecycle, parameters, audio buses, events and state interfaces. | | `vst3.zig` | The VST3 C ABI: `IUnknown`, `IPluginBase`, `IComponent`, `IAudioProcessor`, `IEditController`, and the structs they pass. | | `plugin.zig` | Plugin lifecycle and a heap-backed `ParameterMap`. | | `audio.zig` | `dBToLinear`, `GainProcessor`, `SimpleRamp`, `AudioBuffer`. | @@ -66,6 +70,8 @@ Architectures in the fat file: zig-out/DanzigGain.vst3/Contents/MacOS/DanzigGain |---|---| | [danzig-minimal](examples/danzig-minimal/). The smallest complete plugin, and the file to copy. | `zig build run-minimal` | | [danzig-gain](examples/danzig-gain/). The plugin packaged into the `.vst3` bundle. | `zig build vst3` | +| [danzig-gain-clap](examples/danzig-gain-clap/). Shared gain DSP exported through the CLAP ABI. | `zig build clap` | +| [danzig-clap-test](examples/danzig-clap-test/). CLAP factory, parameters and processing test. | `zig build test-clap` | | [danzig-test](examples/danzig-test/). Drives the built plugin through the raw VST3 C ABI. | `zig build test-integration` | | [danzig-gain-standalone](examples/danzig-gain-standalone/). Offline WAV gain processing. | `zig build run-standalone` | | [danzig-webui](examples/danzig-webui/). An HTTP server in pure `std.net`. | `./zig-out/bin/danzig-webui` | @@ -121,8 +127,10 @@ The default Debug build produces the same artifacts at roughly 1 to 2 MB each. ## Current state -The core library, the tests, the build pipeline, the examples, and the VST3 -plugin all work. `examples/danzig-gain` builds a universal `.vst3` bundle that a +The existing VST3 implementation has passed host validation. The CLAP adapter +and AUv2/AAX wrapper build configurations are being validated separately; see +[format-specific status and requirements](docs/FORMATS.md). The VST3 +core library, tests and build pipeline remain available. `examples/danzig-gain` builds a universal `.vst3` bundle that a host loads and instantiates, and it passes pluginval at strictness level 5: ``` @@ -142,6 +150,8 @@ shared lock-free parameter store. See Published at [godofecht.github.io/danzig](https://godofecht.github.io/danzig/). +- **[docs/FORMATS.md](docs/FORMATS.md)**. CLAP and external AUv2/AAX wrappers, + packaging, signing and validation. - **[docs/WIKI.md](docs/WIKI.md)**. The single-page guide. Architecture, quickstart, parameters, audio helpers, bundle packaging, testing, troubleshooting. From b99ab44bd8436582feda462ee466dd77def2dc3c Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 14:07:12 +0000 Subject: [PATCH 16/26] Fix CLAP shared DSP module import boundaries --- build.zig | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/build.zig b/build.zig index 525905c..483a1e1 100644 --- a/build.zig +++ b/build.zig @@ -22,6 +22,12 @@ pub fn build(b: *std.Build) void { .root_source_file = b.path("src/root.zig"), }); + // Share the format-neutral DSP across format-specific Zig modules. + const gain_core = b.addModule("gain_core", .{ + .root_source_file = b.path("examples/danzig-gain/dsp.zig"), + }); + gain_core.addImport("danzig", danzig_module); + // Danzig gain VST3 plugin (shared, embeds danzig) const danzig_gain = b.addLibrary(.{ .name = "DanzigGain", @@ -49,6 +55,7 @@ pub fn build(b: *std.Build) void { .linkage = .dynamic, }); danzig_clap.root_module.addImport("danzig", danzig_module); + danzig_clap.root_module.addImport("gain_core", gain_core); b.installArtifact(danzig_clap); // Execute the CLAP factory and DSP through the exported C ABI. @@ -160,7 +167,7 @@ pub fn build(b: *std.Build) void { // because it doubles compile work and only applies to macOS. if (target.result.os.tag == .macos) { addVst3Bundle(b, optimize, danzig_module); - addClapBundle(b, optimize, danzig_module); + addClapBundle(b, optimize, danzig_module, gain_core); } // --- GUI example (macOS) ------------------------------------------------- @@ -351,6 +358,7 @@ fn addClapBundle( b: *std.Build, optimize: std.builtin.OptimizeMode, danzig_module: *std.Build.Module, + gain_core: *std.Build.Module, ) void { const arches = [_]std.Target.Cpu.Arch{ .aarch64, .x86_64 }; const suffixes = [_][]const u8{ "arm64", "x86" }; @@ -368,6 +376,7 @@ fn addClapBundle( .linkage = .dynamic, }); plugin.root_module.addImport("danzig", danzig_module); + plugin.root_module.addImport("gain_core", gain_core); lipo.addArtifactArg(plugin); } From f67d2c46fa0d36ad5914723e3d9118c5efe5087b Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 14:07:15 +0000 Subject: [PATCH 17/26] Fix CLAP shared DSP module import boundaries --- examples/danzig-gain-clap/root.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/danzig-gain-clap/root.zig b/examples/danzig-gain-clap/root.zig index a3a380c..0ec02f1 100644 --- a/examples/danzig-gain-clap/root.zig +++ b/examples/danzig-gain-clap/root.zig @@ -1,7 +1,7 @@ // Danzig Gain CLAP adapter. DSP and parameter storage are shared with the VST3 example. const std = @import("std"); const clap = @import("danzig").clap; -const core = @import("../danzig-gain/dsp.zig"); +const core = @import("gain_core"); const plugin_id = "dev.superelectric.danzig.gain"; const features = [_]?[*:0]const u8{ "audio-effect", "stereo", null }; From 0a51e72cbf94e9520b766da08a30009e0fce7edb Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 14:09:09 +0000 Subject: [PATCH 18/26] Build AUv2 wrapper on macOS with public SDKs in CI --- .github/workflows/auv2.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/auv2.yml diff --git a/.github/workflows/auv2.yml b/.github/workflows/auv2.yml new file mode 100644 index 0000000..83a1a66 --- /dev/null +++ b/.github/workflows/auv2.yml @@ -0,0 +1,35 @@ +name: AUv2 wrapper + +on: + push: + branches: [main] + pull_request: + workflow_dispatch: + +jobs: + build-auv2: + runs-on: macos-15 + steps: + - uses: actions/checkout@v4 + - uses: mlugg/setup-zig@v2 + with: + version: "0.15.2" + - name: Checkout public wrapper dependencies + run: | + mkdir -p "$RUNNER_TEMP/audio-sdks" + git clone --depth 1 https://github.com/free-audio/clap.git "$RUNNER_TEMP/audio-sdks/clap" + git clone --depth 1 --recurse-submodules --branch v0.15.1 https://github.com/free-audio/clap-wrapper.git "$RUNNER_TEMP/audio-sdks/clap-wrapper" + git clone --depth 1 https://github.com/apple/AudioUnitSDK.git "$RUNNER_TEMP/audio-sdks/AudioUnitSDK" + - name: Build Danzig AUv2 component + env: + CLAP_WRAPPER_SOURCE: ${{ runner.temp }}/audio-sdks/clap-wrapper + CLAP_SDK_ROOT: ${{ runner.temp }}/audio-sdks/clap + AUDIOUNIT_SDK_ROOT: ${{ runner.temp }}/audio-sdks/AudioUnitSDK + run: bash scripts/build-wrappers.sh + - name: Inspect Audio Unit bundle + run: | + component="$(find zig-out/format-wrappers -type d -name DanzigGain.component -print -quit)" + test -n "$component" + test -f "$component/Contents/Info.plist" + /usr/libexec/PlistBuddy -c "Print :AudioComponents" "$component/Contents/Info.plist" || true + echo "Built: $component" From 1e3be41398760c6ba6f5ada6c65a4fb82ff2853f Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 14:10:43 +0000 Subject: [PATCH 19/26] Enable Objective-C++ in parent scope for AU wrapper CMake --- wrappers/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wrappers/CMakeLists.txt b/wrappers/CMakeLists.txt index 8fcee46..cdb8bef 100644 --- a/wrappers/CMakeLists.txt +++ b/wrappers/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 3.21) -project(DanzigFormatWrappers LANGUAGES C CXX) +project(DanzigFormatWrappers LANGUAGES C CXX OBJC OBJCXX) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) if (NOT APPLE) message(FATAL_ERROR "This wrapper project builds AUv2 on macOS. AAX Windows builds can use clap-wrapper directly.") From a9129e7fc5a5b4e45df1cc35891265d4c9a656dd Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 14:12:16 +0000 Subject: [PATCH 20/26] Compile AU wrapper and recent AudioUnitSDK with C++20 --- wrappers/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wrappers/CMakeLists.txt b/wrappers/CMakeLists.txt index cdb8bef..b114a10 100644 --- a/wrappers/CMakeLists.txt +++ b/wrappers/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.21) project(DanzigFormatWrappers LANGUAGES C CXX OBJC OBJCXX) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) +set(CLAP_WRAPPER_CXX_STANDARD 20 CACHE STRING "C++ standard for wrapper and Apple AudioUnitSDK" FORCE) set(CMAKE_CXX_STANDARD_REQUIRED ON) if (NOT APPLE) From d606b66c56153a6ae8469b95cbe95a4ae0e75090 Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 14:14:29 +0000 Subject: [PATCH 21/26] Use C++23 for current Apple AudioUnitSDK expected types --- wrappers/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wrappers/CMakeLists.txt b/wrappers/CMakeLists.txt index b114a10..52cb025 100644 --- a/wrappers/CMakeLists.txt +++ b/wrappers/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.21) project(DanzigFormatWrappers LANGUAGES C CXX OBJC OBJCXX) -set(CMAKE_CXX_STANDARD 20) -set(CLAP_WRAPPER_CXX_STANDARD 20 CACHE STRING "C++ standard for wrapper and Apple AudioUnitSDK" FORCE) +set(CMAKE_CXX_STANDARD 23) +set(CLAP_WRAPPER_CXX_STANDARD 23 CACHE STRING "C++ standard for wrapper and Apple AudioUnitSDK" FORCE) set(CMAKE_CXX_STANDARD_REQUIRED ON) if (NOT APPLE) From 4c0bca05030fb932cac86b426689ee1391f47bf0 Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 14:16:41 +0000 Subject: [PATCH 22/26] Target C++20 for Apple AudioUnitSDK 1.3 wrapper --- wrappers/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wrappers/CMakeLists.txt b/wrappers/CMakeLists.txt index 52cb025..b114a10 100644 --- a/wrappers/CMakeLists.txt +++ b/wrappers/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.21) project(DanzigFormatWrappers LANGUAGES C CXX OBJC OBJCXX) -set(CMAKE_CXX_STANDARD 23) -set(CLAP_WRAPPER_CXX_STANDARD 23 CACHE STRING "C++ standard for wrapper and Apple AudioUnitSDK" FORCE) +set(CMAKE_CXX_STANDARD 20) +set(CLAP_WRAPPER_CXX_STANDARD 20 CACHE STRING "C++ standard for wrapper and Apple AudioUnitSDK" FORCE) set(CMAKE_CXX_STANDARD_REQUIRED ON) if (NOT APPLE) From e6a576b77fe2f1a5ddbed0388eb1075a9eb16c8e Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 14:16:44 +0000 Subject: [PATCH 23/26] Pin Apple AudioUnitSDK 1.3.0 to avoid C++23-only headers --- .github/workflows/auv2.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/auv2.yml b/.github/workflows/auv2.yml index 83a1a66..eba8cd1 100644 --- a/.github/workflows/auv2.yml +++ b/.github/workflows/auv2.yml @@ -19,7 +19,8 @@ jobs: mkdir -p "$RUNNER_TEMP/audio-sdks" git clone --depth 1 https://github.com/free-audio/clap.git "$RUNNER_TEMP/audio-sdks/clap" git clone --depth 1 --recurse-submodules --branch v0.15.1 https://github.com/free-audio/clap-wrapper.git "$RUNNER_TEMP/audio-sdks/clap-wrapper" - git clone --depth 1 https://github.com/apple/AudioUnitSDK.git "$RUNNER_TEMP/audio-sdks/AudioUnitSDK" + git clone https://github.com/apple/AudioUnitSDK.git "$RUNNER_TEMP/audio-sdks/AudioUnitSDK" + git -C "$RUNNER_TEMP/audio-sdks/AudioUnitSDK" checkout e789bc83ddc07cbf80e7bfaf84f1ade975287400 - name: Build Danzig AUv2 component env: CLAP_WRAPPER_SOURCE: ${{ runner.temp }}/audio-sdks/clap-wrapper From 9ab26f5babe4e5670059a44db211d0ccf823fee9 Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 14:16:46 +0000 Subject: [PATCH 24/26] Document pinned AudioUnitSDK compatibility version --- docs/FORMATS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/FORMATS.md b/docs/FORMATS.md index 6c0f266..9319a70 100644 --- a/docs/FORMATS.md +++ b/docs/FORMATS.md @@ -33,7 +33,7 @@ protocol. The wrapper registers as an **effect** (`aufx`), not an instrument On macOS, install Zig, CMake and Xcode command-line tools, then clone [free-audio/clap](https://github.com/free-audio/clap), [free-audio/clap-wrapper](https://github.com/free-audio/clap-wrapper), and -[apple/AudioUnitSDK](https://github.com/apple/AudioUnitSDK). +[apple/AudioUnitSDK](https://github.com/apple/AudioUnitSDK) (version 1.3.0; commit `e789bc83ddc07cbf80e7bfaf84f1ade975287400` for the CI-tested build). ```sh export CLAP_WRAPPER_SOURCE="$HOME/src/clap-wrapper" From ac9facf230081e978c23217b7daf1b469567659a Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 14:18:32 +0000 Subject: [PATCH 25/26] Verify packaged Audio Unit with Apple's auval in CI --- .github/workflows/auv2.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/auv2.yml b/.github/workflows/auv2.yml index eba8cd1..39f0fda 100644 --- a/.github/workflows/auv2.yml +++ b/.github/workflows/auv2.yml @@ -34,3 +34,10 @@ jobs: test -f "$component/Contents/Info.plist" /usr/libexec/PlistBuddy -c "Print :AudioComponents" "$component/Contents/Info.plist" || true echo "Built: $component" + - name: Validate AUv2 through Apple auval + run: | + component="$(find zig-out/format-wrappers -type d -name DanzigGain.component -print -quit)" + codesign --force --deep --sign - "$component" + mkdir -p "$HOME/Library/Audio/Plug-Ins/Components" + cp -R "$component" "$HOME/Library/Audio/Plug-Ins/Components/" + auval -v aufx DzGn SuEl From cea7491c2917f18af3a6d0e0b5d69d9e6436f6a0 Mon Sep 17 00:00:00 2001 From: Abhishek Shivakumar Date: Mon, 16 Nov 2026 14:20:13 +0000 Subject: [PATCH 26/26] Refresh AudioComponentRegistrar before AUv2 host validation --- .github/workflows/auv2.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/auv2.yml b/.github/workflows/auv2.yml index 39f0fda..05d1ef6 100644 --- a/.github/workflows/auv2.yml +++ b/.github/workflows/auv2.yml @@ -40,4 +40,12 @@ jobs: codesign --force --deep --sign - "$component" mkdir -p "$HOME/Library/Audio/Plug-Ins/Components" cp -R "$component" "$HOME/Library/Audio/Plug-Ins/Components/" + killall -9 AudioComponentRegistrar 2>/dev/null || true + for attempt in 1 2 3 4 5; do + if auval -a | grep -Eq 'aufx[[:space:]]+DzGn[[:space:]]+SuEl'; then + break + fi + sleep 3 + done + auval -a auval -v aufx DzGn SuEl