Use comptime for fully declarative LV2 and Custom commands #14
1 changed files with 52 additions and 41 deletions
|
@ -1,6 +1,13 @@
|
||||||
const langs = @import("lang.zig");
|
const langs = @import("lang.zig");
|
||||||
|
|
||||||
pub fn printCommand(cmd: langs.Command, comptime tag: langs.Command.Tag) !void {
|
fn printCommandWithParams(stream: var, command: var) !void {
|
||||||
|
const Parameters = @TypeOf(command.parameters);
|
||||||
|
inline for (@typeInfo(Parameters).Struct.fields) |field| {
|
||||||
|
try stream.print(" {}", .{@field(command.parameters, field.name)});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn printCommand(stream: var, cmd: *langs.Command, comptime tag: langs.Command.Tag) !void {
|
||||||
const CommandStruct = langs.Command.tagToType(tag);
|
const CommandStruct = langs.Command.tagToType(tag);
|
||||||
const casted = cmd.cast(CommandStruct).?;
|
const casted = cmd.cast(CommandStruct).?;
|
||||||
|
|
||||||
|
@ -10,10 +17,10 @@ pub fn printCommand(cmd: langs.Command, comptime tag: langs.Command.Tag) !void {
|
||||||
else => true,
|
else => true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const ctype = typ.command_type;
|
const ctype = CommandStruct.command_type;
|
||||||
switch (ctype) {
|
switch (ctype) {
|
||||||
.lv2_command => try printLV2Command(casted),
|
.lv2_command => try printCommandWithParams(stream, casted),
|
||||||
.custom_command => try printCustomCommand(casted),
|
.custom_command => try printCommandWithParams(stream, casted),
|
||||||
else => @panic("TODO support command type"),
|
else => @panic("TODO support command type"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,48 +32,52 @@ pub fn printList(list: langs.CommandList, stream: var) !void {
|
||||||
|
|
||||||
switch (cmd.tag) {
|
switch (cmd.tag) {
|
||||||
.load => {
|
.load => {
|
||||||
const load = command.cast(langs.Command.Load).?;
|
const load = cmd.cast(langs.Command.Load).?;
|
||||||
try stream.print(" {}", .{load.path});
|
try stream.print(" {}", .{load.path});
|
||||||
},
|
},
|
||||||
.quicksave => {},
|
.runqs => {
|
||||||
|
const runqs = cmd.cast(langs.Command.RunQS).?;
|
||||||
|
try stream.print(" {}", .{runqs.program});
|
||||||
|
},
|
||||||
|
.noop, .quicksave => {},
|
||||||
.rotate => {
|
.rotate => {
|
||||||
const rotate = command.cast(langs.Command.Rotate).?;
|
const rotate = cmd.cast(langs.Command.Rotate).?;
|
||||||
try stream.print(" {} {}", .{ rotate.deg, rotate.bgfill });
|
try stream.print(" {} {}", .{ rotate.deg, rotate.bgfill });
|
||||||
},
|
},
|
||||||
|
|
||||||
.amp => try printCommand(cmd, .amp),
|
.amp => try printCommand(stream, cmd, .amp),
|
||||||
.rflanger => try printCommand(cmd, .rflanger),
|
.rflanger => try printCommand(stream, cmd, .rflanger),
|
||||||
.eq => try printCommand(cmd, .eq),
|
.eq => try printCommand(stream, cmd, .eq),
|
||||||
.phaser => try printCommand(cmd, .phaser),
|
.phaser => try printCommand(stream, cmd, .phaser),
|
||||||
.mbeq => try printCommand(cmd, .mbeq),
|
.mbeq => try printCommand(stream, cmd, .mbeq),
|
||||||
.chorus => try printCommand(cmd, .chorus),
|
.chorus => try printCommand(stream, cmd, .chorus),
|
||||||
.pitchscaler => try printCommand(cmd, .pitchscaler),
|
.pitchscaler => try printCommand(stream, cmd, .pitchscaler),
|
||||||
.reverb => try printCommand(cmd, .reverb),
|
.reverb => try printCommand(stream, cmd, .reverb),
|
||||||
.highpass => try printCommand(cmd, .highpass),
|
.highpass => try printCommand(stream, cmd, .highpass),
|
||||||
.delay => try printCommand(cmd, .delay),
|
.delay => try printCommand(stream, cmd, .delay),
|
||||||
.vinyl => try printCommand(cmd, .vinyl),
|
.vinyl => try printCommand(stream, cmd, .vinyl),
|
||||||
.revdelay => try printCommand(cmd, .revdelay),
|
.revdelay => try printCommand(stream, cmd, .revdelay),
|
||||||
.gate => try printCommand(cmd, .gate),
|
.gate => try printCommand(stream, cmd, .gate),
|
||||||
.detune => try printCommand(cmd, .detune),
|
.detune => try printCommand(stream, cmd, .detune),
|
||||||
.overdrive => try printCommand(cmd, .overdrive),
|
.overdrive => try printCommand(stream, cmd, .overdrive),
|
||||||
.degrade => try printCommand(cmd, .degrade),
|
.degrade => try printCommand(stream, cmd, .degrade),
|
||||||
.repsycho => try printCommand(cmd, .repsycho),
|
.repsycho => try printCommand(stream, cmd, .repsycho),
|
||||||
.talkbox => try printCommand(cmd, .talkbox),
|
.talkbox => try printCommand(stream, cmd, .talkbox),
|
||||||
.dyncomp => try printCommand(cmd, .dyncomp),
|
.dyncomp => try printCommand(stream, cmd, .dyncomp),
|
||||||
.thruzero => try printCommand(cmd, .thruzero),
|
.thruzero => try printCommand(stream, cmd, .thruzero),
|
||||||
.foverdrive => try printCommand(cmd, .foverdrive),
|
.foverdrive => try printCommand(stream, cmd, .foverdrive),
|
||||||
.gverb => try printCommand(cmd, .gverb),
|
.gverb => try printCommand(stream, cmd, .gverb),
|
||||||
.invert => try printCommand(cmd, .invert),
|
.invert => try printCommand(stream, cmd, .invert),
|
||||||
.tapedelay => try printCommand(cmd, .tapedelay),
|
.tapedelay => try printCommand(stream, cmd, .tapedelay),
|
||||||
.moddelay => try printCommand(cmd, .moddelay),
|
.moddelay => try printCommand(stream, cmd, .moddelay),
|
||||||
.multichorus => try printCommand(cmd, .multichorus),
|
.multichorus => try printCommand(stream, cmd, .multichorus),
|
||||||
.saturator => try printCommand(cmd, .saturator),
|
.saturator => try printCommand(stream, cmd, .saturator),
|
||||||
.vintagedelay => try printCommand(cmd, .vintagedelay),
|
.vintagedelay => try printCommand(stream, cmd, .vintagedelay),
|
||||||
|
|
||||||
.noise => try printCommand(cmd, .noise),
|
.noise => try printCommand(stream, cmd, .noise),
|
||||||
.wildnoise => try printCommand(cmd, .wildnoise),
|
.wildnoise => try printCommand(stream, cmd, .wildnoise),
|
||||||
.write => try printCommand(cmd, .write),
|
.write => try printCommand(stream, cmd, .write),
|
||||||
.embed => try printCommand(cmd, .embed),
|
.embed => try printCommand(stream, cmd, .embed),
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = try stream.write(";\n");
|
_ = try stream.write(";\n");
|
||||||
|
|
Loading…
Reference in a new issue