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");
|
||||
|
||||
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 casted = cmd.cast(CommandStruct).?;
|
||||
|
||||
|
@ -10,10 +17,10 @@ pub fn printCommand(cmd: langs.Command, comptime tag: langs.Command.Tag) !void {
|
|||
else => true,
|
||||
};
|
||||
|
||||
const ctype = typ.command_type;
|
||||
const ctype = CommandStruct.command_type;
|
||||
switch (ctype) {
|
||||
.lv2_command => try printLV2Command(casted),
|
||||
.custom_command => try printCustomCommand(casted),
|
||||
.lv2_command => try printCommandWithParams(stream, casted),
|
||||
.custom_command => try printCommandWithParams(stream, casted),
|
||||
else => @panic("TODO support command type"),
|
||||
}
|
||||
}
|
||||
|
@ -25,48 +32,52 @@ pub fn printList(list: langs.CommandList, stream: var) !void {
|
|||
|
||||
switch (cmd.tag) {
|
||||
.load => {
|
||||
const load = command.cast(langs.Command.Load).?;
|
||||
try stream.print("{}", .{load.path});
|
||||
const load = cmd.cast(langs.Command.Load).?;
|
||||
try stream.print(" {}", .{load.path});
|
||||
},
|
||||
.quicksave => {},
|
||||
.runqs => {
|
||||
const runqs = cmd.cast(langs.Command.RunQS).?;
|
||||
try stream.print(" {}", .{runqs.program});
|
||||
},
|
||||
.noop, .quicksave => {},
|
||||
.rotate => {
|
||||
const rotate = command.cast(langs.Command.Rotate).?;
|
||||
try stream.print("{} {}", .{ rotate.deg, rotate.bgfill });
|
||||
const rotate = cmd.cast(langs.Command.Rotate).?;
|
||||
try stream.print(" {} {}", .{ rotate.deg, rotate.bgfill });
|
||||
},
|
||||
|
||||
.amp => try printCommand(cmd, .amp),
|
||||
.rflanger => try printCommand(cmd, .rflanger),
|
||||
.eq => try printCommand(cmd, .eq),
|
||||
.phaser => try printCommand(cmd, .phaser),
|
||||
.mbeq => try printCommand(cmd, .mbeq),
|
||||
.chorus => try printCommand(cmd, .chorus),
|
||||
.pitchscaler => try printCommand(cmd, .pitchscaler),
|
||||
.reverb => try printCommand(cmd, .reverb),
|
||||
.highpass => try printCommand(cmd, .highpass),
|
||||
.delay => try printCommand(cmd, .delay),
|
||||
.vinyl => try printCommand(cmd, .vinyl),
|
||||
.revdelay => try printCommand(cmd, .revdelay),
|
||||
.gate => try printCommand(cmd, .gate),
|
||||
.detune => try printCommand(cmd, .detune),
|
||||
.overdrive => try printCommand(cmd, .overdrive),
|
||||
.degrade => try printCommand(cmd, .degrade),
|
||||
.repsycho => try printCommand(cmd, .repsycho),
|
||||
.talkbox => try printCommand(cmd, .talkbox),
|
||||
.dyncomp => try printCommand(cmd, .dyncomp),
|
||||
.thruzero => try printCommand(cmd, .thruzero),
|
||||
.foverdrive => try printCommand(cmd, .foverdrive),
|
||||
.gverb => try printCommand(cmd, .gverb),
|
||||
.invert => try printCommand(cmd, .invert),
|
||||
.tapedelay => try printCommand(cmd, .tapedelay),
|
||||
.moddelay => try printCommand(cmd, .moddelay),
|
||||
.multichorus => try printCommand(cmd, .multichorus),
|
||||
.saturator => try printCommand(cmd, .saturator),
|
||||
.vintagedelay => try printCommand(cmd, .vintagedelay),
|
||||
.amp => try printCommand(stream, cmd, .amp),
|
||||
.rflanger => try printCommand(stream, cmd, .rflanger),
|
||||
.eq => try printCommand(stream, cmd, .eq),
|
||||
.phaser => try printCommand(stream, cmd, .phaser),
|
||||
.mbeq => try printCommand(stream, cmd, .mbeq),
|
||||
.chorus => try printCommand(stream, cmd, .chorus),
|
||||
.pitchscaler => try printCommand(stream, cmd, .pitchscaler),
|
||||
.reverb => try printCommand(stream, cmd, .reverb),
|
||||
.highpass => try printCommand(stream, cmd, .highpass),
|
||||
.delay => try printCommand(stream, cmd, .delay),
|
||||
.vinyl => try printCommand(stream, cmd, .vinyl),
|
||||
.revdelay => try printCommand(stream, cmd, .revdelay),
|
||||
.gate => try printCommand(stream, cmd, .gate),
|
||||
.detune => try printCommand(stream, cmd, .detune),
|
||||
.overdrive => try printCommand(stream, cmd, .overdrive),
|
||||
.degrade => try printCommand(stream, cmd, .degrade),
|
||||
.repsycho => try printCommand(stream, cmd, .repsycho),
|
||||
.talkbox => try printCommand(stream, cmd, .talkbox),
|
||||
.dyncomp => try printCommand(stream, cmd, .dyncomp),
|
||||
.thruzero => try printCommand(stream, cmd, .thruzero),
|
||||
.foverdrive => try printCommand(stream, cmd, .foverdrive),
|
||||
.gverb => try printCommand(stream, cmd, .gverb),
|
||||
.invert => try printCommand(stream, cmd, .invert),
|
||||
.tapedelay => try printCommand(stream, cmd, .tapedelay),
|
||||
.moddelay => try printCommand(stream, cmd, .moddelay),
|
||||
.multichorus => try printCommand(stream, cmd, .multichorus),
|
||||
.saturator => try printCommand(stream, cmd, .saturator),
|
||||
.vintagedelay => try printCommand(stream, cmd, .vintagedelay),
|
||||
|
||||
.noise => try printCommand(cmd, .noise),
|
||||
.wildnoise => try printCommand(cmd, .wildnoise),
|
||||
.write => try printCommand(cmd, .write),
|
||||
.embed => try printCommand(cmd, .embed),
|
||||
.noise => try printCommand(stream, cmd, .noise),
|
||||
.wildnoise => try printCommand(stream, cmd, .wildnoise),
|
||||
.write => try printCommand(stream, cmd, .write),
|
||||
.embed => try printCommand(stream, cmd, .embed),
|
||||
}
|
||||
|
||||
_ = try stream.write(";\n");
|
||||
|
|
Loading…
Reference in a new issue