add support for generic lv2 command running
This commit is contained in:
parent
9c6387973f
commit
f9c1851734
2 changed files with 64 additions and 13 deletions
|
@ -51,7 +51,7 @@ pub const CommandType = enum {
|
|||
Rotate,
|
||||
};
|
||||
|
||||
pub const Type = enum {
|
||||
pub const NewCommandType = enum {
|
||||
/// "LV2 Commands" are commands that receive split, index, and then receive
|
||||
/// any f64 arguments.
|
||||
lv2_command,
|
||||
|
@ -151,6 +151,9 @@ pub const NewCommand = struct {
|
|||
|
||||
pub const Amp = struct {
|
||||
pub const base_tag = Tag.amp;
|
||||
pub const command_type = NewCommandType.lv2_command;
|
||||
pub const lv2_url = "http://lv2plug.in/plugins/eg-amp";
|
||||
|
||||
base: NewCommand,
|
||||
split: usize,
|
||||
index: usize,
|
||||
|
@ -159,6 +162,9 @@ pub const NewCommand = struct {
|
|||
|
||||
pub const RFlanger = struct {
|
||||
pub const base_tag = Tag.rflanger;
|
||||
pub const command_type = NewCommandType.lv2_command;
|
||||
pub const lv2_url = "http://plugin.org.uk/swh-plugins/retroFlange";
|
||||
|
||||
base: NewCommand,
|
||||
split: usize,
|
||||
index: usize,
|
||||
|
|
|
@ -374,6 +374,38 @@ pub const Runner = struct {
|
|||
try image.runPlugin("http://calf.sourceforge.net/plugins/VintageDelay", pos, params);
|
||||
}
|
||||
|
||||
fn executeLV2Command(self: *@This(), command: var) !void {
|
||||
const pos = plugin.Position{
|
||||
.split = command.split,
|
||||
.index = command.index,
|
||||
};
|
||||
|
||||
var params = ParamList.init(self.allocator);
|
||||
defer params.deinit();
|
||||
|
||||
const typ = @TypeOf(command);
|
||||
|
||||
inline for (@typeInfo(typ).Struct.fields) |cmd_field| {
|
||||
// ignore fields that can't be symbols for lv2 execution
|
||||
comptime {
|
||||
if (std.mem.eql(u8, cmd_field.name, "base") or
|
||||
std.mem.eql(u8, cmd_field.name, "split") or
|
||||
std.mem.eql(u8, cmd_field.name, "index"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
try params.append(plugin.Param{
|
||||
.sym = cmd_field.name,
|
||||
.value = @field(command, cmd_field.name),
|
||||
});
|
||||
}
|
||||
|
||||
var image = try self.getImage();
|
||||
try image.runPlugin(typ.lv2_url, pos, params);
|
||||
}
|
||||
|
||||
fn newRunCommandSingle(
|
||||
self: *@This(),
|
||||
cmd: lang.NewCommand,
|
||||
|
@ -381,15 +413,36 @@ pub const Runner = struct {
|
|||
) !void {
|
||||
comptime const typ = lang.NewCommand.tagToType(tag);
|
||||
const command = cmd.cast(typ).?;
|
||||
std.debug.warn("{} {}\n", .{ command.path.ptr, command.path.len });
|
||||
inline for (@typeInfo(typ).Struct.decls) |decl| {
|
||||
comptime {
|
||||
if (!std.mem.eql(u8, decl.name, "command_type")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
std.debug.warn("{}\n", .{command});
|
||||
const ctype = typ.command_type;
|
||||
switch (ctype) {
|
||||
.lv2_command => try self.executeLV2Command(command.*),
|
||||
else => @panic("TODO support command type"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn newRunCommand(self: *@This(), cmd: lang.NewCommand) !void {
|
||||
// .load => try self.newRunCommandSingle(cmd, .load),
|
||||
switch (cmd.tag) {
|
||||
.load => try self.newRunCommandSingle(cmd, .load),
|
||||
else => @panic("TODO"),
|
||||
.load => {
|
||||
const command = cmd.cast(lang.NewCommand.Load).?;
|
||||
try self.loadCmd(command.path);
|
||||
},
|
||||
.quicksave => {
|
||||
try self.quicksaveCmd();
|
||||
},
|
||||
.amp => try self.newRunCommandSingle(cmd, .amp),
|
||||
else => {
|
||||
std.debug.warn("TODO support {}\n", .{@tagName(cmd.tag)});
|
||||
@panic("TODO support tag");
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -796,14 +849,6 @@ pub const Runner = struct {
|
|||
) !void {
|
||||
for (cmds.items) |cmd| {
|
||||
cmd.print();
|
||||
|
||||
switch (cmd.tag) {
|
||||
.load => {
|
||||
const proper_cmd = cmd.cast(lang.NewCommand.Load).?;
|
||||
std.debug.warn("got load! {}\n", .{proper_cmd});
|
||||
},
|
||||
else => @panic("TODO"),
|
||||
}
|
||||
try self.newRunCommand(cmd.*);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue