2020-06-02 02:58:56 +00:00
|
|
|
const std = @import("std");
|
2019-09-10 14:45:04 +00:00
|
|
|
const langs = @import("lang.zig");
|
|
|
|
|
2020-06-02 01:45:35 +00:00
|
|
|
fn printCommandWithParams(stream: var, command: var) !void {
|
|
|
|
const Parameters = @TypeOf(command.parameters);
|
2020-06-02 19:00:54 +00:00
|
|
|
try stream.print(" {} {}", .{ command.split, command.index });
|
2020-06-02 01:45:35 +00:00
|
|
|
inline for (@typeInfo(Parameters).Struct.fields) |field| {
|
2020-06-02 02:58:56 +00:00
|
|
|
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)});
|
|
|
|
}
|
2020-06-02 01:45:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn printCommand(stream: var, cmd: *langs.Command, comptime tag: langs.Command.Tag) !void {
|
2020-06-02 01:35:16 +00:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2020-06-02 01:45:35 +00:00
|
|
|
const ctype = CommandStruct.command_type;
|
2020-06-02 01:35:16 +00:00
|
|
|
switch (ctype) {
|
2020-06-02 01:45:35 +00:00
|
|
|
.lv2_command => try printCommandWithParams(stream, casted),
|
|
|
|
.custom_command => try printCommandWithParams(stream, casted),
|
2020-06-02 01:35:16 +00:00
|
|
|
else => @panic("TODO support command type"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-10 14:45:04 +00:00
|
|
|
pub fn printList(list: langs.CommandList, stream: var) !void {
|
2020-05-12 20:26:33 +00:00
|
|
|
for (list.items) |cmd| {
|
2020-06-02 01:14:12 +00:00
|
|
|
const command = @tagName(cmd.tag);
|
2020-01-15 01:31:20 +00:00
|
|
|
try stream.print("{}", .{command});
|
2019-09-10 14:45:04 +00:00
|
|
|
|
2020-06-02 01:35:16 +00:00
|
|
|
switch (cmd.tag) {
|
|
|
|
.load => {
|
2020-06-02 01:45:35 +00:00
|
|
|
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});
|
2020-06-02 01:35:16 +00:00
|
|
|
},
|
2020-06-02 01:45:35 +00:00
|
|
|
.noop, .quicksave => {},
|
2020-06-02 01:35:16 +00:00
|
|
|
.rotate => {
|
2020-06-02 01:45:35 +00:00
|
|
|
const rotate = cmd.cast(langs.Command.Rotate).?;
|
2020-06-02 02:58:56 +00:00
|
|
|
try stream.print(" {d} {}", .{ rotate.deg, rotate.bgfill });
|
2020-06-02 01:35:16 +00:00
|
|
|
},
|
|
|
|
|
2020-06-02 01:45:35 +00:00
|
|
|
.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),
|
2020-06-02 01:35:16 +00:00
|
|
|
|
2020-06-02 01:45:35 +00:00
|
|
|
.noise => try printCommand(stream, cmd, .noise),
|
|
|
|
.wildnoise => try printCommand(stream, cmd, .wildnoise),
|
|
|
|
.write => try printCommand(stream, cmd, .write),
|
|
|
|
.embed => try printCommand(stream, cmd, .embed),
|
2019-09-10 14:45:04 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 19:35:58 +00:00
|
|
|
_ = try stream.write(";\n");
|
2019-09-10 14:45:04 +00:00
|
|
|
}
|
|
|
|
}
|