From f973d6807daa3d34cb1d14c47b3010419962d61b Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 22:35:16 -0300 Subject: [PATCH] add basics of printing under new command structure --- src/printer.zig | 66 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/src/printer.zig b/src/printer.zig index b7592db..73a0e8a 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -1,12 +1,74 @@ const langs = @import("lang.zig"); +pub fn printCommand(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 = typ.command_type; + switch (ctype) { + .lv2_command => try printLV2Command(casted), + .custom_command => try printCustomCommand(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}); - for (cmd.args.items) |arg| { - try stream.print(" {}", .{arg}); + switch (cmd.tag) { + .load => { + const load = command.cast(langs.Command.Load).?; + try stream.print("{}", .{load.path}); + }, + .quicksave => {}, + .rotate => { + const rotate = command.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), + + .noise => try printCommand(cmd, .noise), + .wildnoise => try printCommand(cmd, .wildnoise), + .write => try printCommand(cmd, .write), + .embed => try printCommand(cmd, .embed), + + else => @compileError("unhandled command"), } _ = try stream.write(";\n");