add support for plugin command types

This commit is contained in:
Luna 2020-05-31 21:47:31 -03:00
parent 1fac8c7312
commit 1c1e525b1d

View file

@ -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");