From 1c1e525b1daf6cc32d5c62901bca4eb59414908f Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 21:47:31 -0300 Subject: [PATCH] add support for plugin command types --- src/runner.zig | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/runner.zig b/src/runner.zig index e65bac0..a1bed65 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -190,26 +190,6 @@ pub const Runner = struct { _ = try proc.spawnAndWait(); } - fn noiseCmd(self: *Runner, pos: Position, map: *ParamMap) !void { - var image = try self.getImage(); - try image.runCustomPlugin(custom.RandomNoise, pos, *ParamMap, map); - } - - fn wildNoiseCmd(self: *Runner, pos: Position, map: *ParamMap) !void { - var image = try self.getImage(); - try image.runCustomPlugin(custom.WildNoise, pos, *ParamMap, map); - } - - fn writeCmd(self: *Runner, pos: Position, map: *ParamMap) !void { - var image = try self.getImage(); - try image.runCustomPlugin(custom.Write, pos, *ParamMap, map); - } - - fn embedCmd(self: *Runner, pos: Position, path: []const u8) !void { - var image = try self.getImage(); - try image.runCustomPlugin(custom.Embed, pos, []const u8, path); - } - fn rotateCmd( self: *Runner, deg: f32, @@ -244,6 +224,26 @@ pub const Runner = struct { try image.runPlugin(typ.lv2_url, pos, params); } + fn executePlugin(self: *@This(), command: var) !void { + const pos = plugin.Position{ + .split = command.split, + .index = command.index, + }; + + var params = ParamMap.init(self.allocator); + defer params.deinit(); + + inline for (@typeInfo(@TypeOf(command.parameters)).Struct.fields) |cmd_field| { + try params.put( + cmd_field.name, + @field(command.parameters, cmd_field.name), + ); + } + + var image = try self.getImage(); + try image.runCustomPlugin(typ.plugin_type, pos, map); + } + fn newRunCommandSingle( self: *@This(), cmd: lang.Command, @@ -261,6 +261,7 @@ pub const Runner = struct { const ctype = typ.command_type; switch (ctype) { .lv2_command => try self.executeLV2Command(command.*), + .plugin_command => try self.executePlugin(command.*), else => @panic("TODO support command type"), } } @@ -305,6 +306,8 @@ pub const Runner = struct { .saturator => try self.newRunCommandSingle(cmd, .saturator), .vintagedelay => try self.newRunCommandSingle(cmd, .vintagedelay), + .noise, .wildnoise, .write, .embed => |tag| try self.newRunCommandSingle(cmd, tag), + else => { std.debug.warn("TODO support {}\n", .{@tagName(cmd.tag)}); @panic("TODO support tag");