91 lines
4 KiB
Zig
91 lines
4 KiB
Zig
const std = @import("std");
|
|
const langs = @import("lang.zig");
|
|
|
|
fn printCommandWithParams(stream: var, command: var) !void {
|
|
const Parameters = @TypeOf(command.parameters);
|
|
try stream.print(" {} {}", .{ command.split, command.index });
|
|
inline for (@typeInfo(Parameters).Struct.fields) |field| {
|
|
if (field.field_type == f32 or field.field_type == f64) {
|
|
try stream.print(" {d}", .{@field(command.parameters, field.name)});
|
|
} else {
|
|
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).?;
|
|
|
|
// TODO move this to Tag method?
|
|
const is_typed = switch (tag) {
|
|
.noop, .load, .quicksave, .runqs, .rotate => false,
|
|
else => true,
|
|
};
|
|
|
|
const ctype = CommandStruct.command_type;
|
|
switch (ctype) {
|
|
.lv2_command => try printCommandWithParams(stream, casted),
|
|
.custom_command => try printCommandWithParams(stream, casted),
|
|
else => @panic("TODO support command type"),
|
|
}
|
|
}
|
|
|
|
pub fn printList(list: langs.CommandList, stream: var) !void {
|
|
for (list.items) |cmd| {
|
|
const command = @tagName(cmd.tag);
|
|
try stream.print("{}", .{command});
|
|
|
|
switch (cmd.tag) {
|
|
.load => {
|
|
const load = cmd.cast(langs.Command.Load).?;
|
|
try stream.print(" {}", .{load.path});
|
|
},
|
|
.runqs => {
|
|
const runqs = cmd.cast(langs.Command.RunQS).?;
|
|
try stream.print(" {}", .{runqs.program});
|
|
},
|
|
.noop, .quicksave => {},
|
|
.rotate => {
|
|
const rotate = cmd.cast(langs.Command.Rotate).?;
|
|
try stream.print(" {d} {}", .{ rotate.deg, rotate.bgfill });
|
|
},
|
|
|
|
.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(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");
|
|
}
|
|
}
|