diff --git a/src/lang.zig b/src/lang.zig index 03a6c52..a455a1f 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -31,23 +31,6 @@ fn LV2Command( }; } -fn CustomCommand( - comptime tag: Command.tag, - comptime plugin: type, - comptime parameters: type, -) type { - return struct { - pub const base_tag = tag; - pub const command_type = CommandType.plugin_command; - pub const plugin_type = plugin; - - base: Command, - split: usize, - index: usize, - parameters: LV2Parameters, - }; -} - pub const Command = struct { tag: Tag, @@ -130,13 +113,6 @@ pub const Command = struct { .saturator => Saturator, .vintagedelay => Vintagedelay, - .noise => Noise, - .wildnoise => Wildnoise, - .write => Write, - .embed => Embed, - - .rotate => Rotate, - else => @panic("TODO"), }; } @@ -170,37 +146,8 @@ pub const Command = struct { pub const RunQS = struct { pub const base_tag = Tag.runqs; - base: Command, program: []const u8, - }; - - pub const Noise = CustomCommand(Tag.noise, custom.RandomNoise, struct { - seed: f32, - fill_bytes: f32, - }); - - pub const Wildnoise = CustomCommand(Tag.wildnoise, custom.WildNoise, struct { - seed: f32, - fill_bytes: f32, - }); - - pub const Write = CustomCommand(Tag.write, custom.Write, struct { - data: f32, - }); - - pub const Embed = struct { - pub const base_tag = Tag.embed; base: Command, - split: usize, - index: usize, - path: []const u8, - }; - - pub const Rotate = struct { - pub const base_tag = Tag.rotate; - base: Command, - deg: f32, - bgfill: []const u8, }; pub const Amp = LV2Command( @@ -415,14 +362,9 @@ pub const Command = struct { t4d: f32, t4a_db: f32, }); - - pub const Moddelay = LV2Command( - .moddelay, - "http://plugin.org.uk/swh-plugins/modDelay", - struct { - base: f32, - }, - ); + pub const Moddelay = LV2Command(.moddelay, "http://plugin.org.uk/swh-plugins/modDelay", struct { + base: f32, + }); pub const Multichorus = LV2Command(.multichorus, "http://calf.sourceforge.net/plugins/MultiChorus", struct { min_delay: f32, @@ -506,7 +448,7 @@ pub const Lang = struct { self.line = 0; } fn doError(self: *Lang, comptime fmt: []const u8, args: var) void { - std.debug.warn("ERROR! at line {}: ", .{self.line}); + std.debug.warn("error at line {}: ", .{self.line}); std.debug.warn(fmt, args); std.debug.warn("\n", .{}); self.has_error = true; @@ -529,34 +471,23 @@ pub const Lang = struct { // arguments... if (is_lv2_command) { - const split = tok_it.next(); - if (split == null) { - self.doError("Expected split parameter, got EOL", .{}); - return; - } + cmd.split = try std.fmt.parseInt(usize, tok_it.next().?, 10); + cmd.index = try std.fmt.parseInt(usize, tok_it.next().?, 10); - const index = tok_it.next(); - if (index == null) { - self.doError("Expected index parameter, got EOL", .{}); - return; - } - - cmd.split = try std.fmt.parseInt(usize, split.?, 10); - cmd.index = try std.fmt.parseInt(usize, index.?, 10); - - // All parameters for LV2 plugins are f32. inline for (@typeInfo(@TypeOf(cmd.parameters)).Struct.fields) |cmd_field| { - const maybe_arg = tok_it.next(); - if (maybe_arg == null) { - self.doError("Expected parameter for {}, got nothing", .{cmd_field.name}); - return; - } + const arg = tok_it.next().?; + const argument_value = switch (cmd_field.field_type) { + f32 => try std.fmt.parseFloat(f32, arg), + else => @compileError("LV2 parameter struct can only have f32 fields"), + }; - const arg = maybe_arg.?; - if (cmd_field.field_type != f32) - @compileError("LV2 parameter struct can only have f32 fields"); + std.debug.warn("parsing {}, arg of type {} => {}\n", .{ + @typeName(command_struct), + @typeName(@TypeOf(argument_value)), + argument_value, + }); - @field(cmd.parameters, cmd_field.name) = try std.fmt.parseFloat(f32, arg); + @field(cmd.parameters, cmd_field.name) = argument_value; } } else { inline for (@typeInfo(command_struct).Struct.fields) |cmd_field| {