Compare commits

..

3 commits

View file

@ -190,16 +190,14 @@ pub const Runner = struct {
_ = try proc.spawnAndWait();
}
fn rotateCmd(
self: *Runner,
deg: f32,
bgfill: []const u8,
) !void {
fn rotateCmd(self: *Runner, cmd: lang.Command) !void {
const rotate_cmd = cmd.cast(lang.Command.Rotate).?;
var image = try self.getImage();
var c_bgfill = try std.cstr.addNullByte(self.allocator, bgfill);
var c_bgfill = try std.cstr.addNullByte(self.allocator, rotate_cmd.bgfill);
defer self.allocator.free(c_bgfill);
try magick.runRotate(image, deg, c_bgfill);
try magick.runRotate(image, rotate_cmd.deg, c_bgfill);
}
fn executeLV2Command(self: *@This(), command: var) !void {
@ -224,7 +222,7 @@ pub const Runner = struct {
try image.runPlugin(typ.lv2_url, pos, params);
}
fn executePlugin(self: *@This(), command: var) !void {
fn executeCustomCommand(self: *@This(), command: var) !void {
const pos = plugin.Position{
.split = command.split,
.index = command.index,
@ -234,7 +232,7 @@ pub const Runner = struct {
try image.runCustomPlugin(@TypeOf(command).plugin_type, pos, command.parameters);
}
fn newRunCommandSingle(
fn runSingleCommand(
self: *@This(),
cmd: lang.Command,
comptime tag: lang.Command.Tag,
@ -251,55 +249,54 @@ pub const Runner = struct {
const ctype = typ.command_type;
switch (ctype) {
.lv2_command => try self.executeLV2Command(command.*),
.custom_command => try self.executePlugin(command.*),
.custom_command => try self.executeCustomCommand(command.*),
else => @panic("TODO support command type"),
}
}
}
fn newRunCommand(self: *@This(), cmd: lang.Command) !void {
fn runCommand(self: *@This(), cmd: lang.Command) !void {
switch (cmd.tag) {
.load => {
const command = cmd.cast(lang.Command.Load).?;
try self.loadCmd(command.path);
},
.quicksave => {
try self.quicksaveCmd();
},
.amp => try self.newRunCommandSingle(cmd, .amp),
.quicksave => try self.quicksaveCmd(),
.rotate => try self.rotateCmd(cmd),
.rflanger => try self.newRunCommandSingle(cmd, .rflanger),
.eq => try self.newRunCommandSingle(cmd, .eq),
.phaser => try self.newRunCommandSingle(cmd, .phaser),
.mbeq => try self.newRunCommandSingle(cmd, .mbeq),
.chorus => try self.newRunCommandSingle(cmd, .chorus),
.pitchscaler => try self.newRunCommandSingle(cmd, .pitchscaler),
.reverb => try self.newRunCommandSingle(cmd, .reverb),
.highpass => try self.newRunCommandSingle(cmd, .highpass),
.delay => try self.newRunCommandSingle(cmd, .delay),
.vinyl => try self.newRunCommandSingle(cmd, .vinyl),
.revdelay => try self.newRunCommandSingle(cmd, .revdelay),
.gate => try self.newRunCommandSingle(cmd, .gate),
.detune => try self.newRunCommandSingle(cmd, .detune),
.overdrive => try self.newRunCommandSingle(cmd, .overdrive),
.degrade => try self.newRunCommandSingle(cmd, .degrade),
.repsycho => try self.newRunCommandSingle(cmd, .repsycho),
.talkbox => try self.newRunCommandSingle(cmd, .talkbox),
.dyncomp => try self.newRunCommandSingle(cmd, .dyncomp),
.thruzero => try self.newRunCommandSingle(cmd, .thruzero),
.foverdrive => try self.newRunCommandSingle(cmd, .foverdrive),
.gverb => try self.newRunCommandSingle(cmd, .gverb),
.invert => try self.newRunCommandSingle(cmd, .invert),
.tapedelay => try self.newRunCommandSingle(cmd, .tapedelay),
.moddelay => try self.newRunCommandSingle(cmd, .moddelay),
.multichorus => try self.newRunCommandSingle(cmd, .multichorus),
.saturator => try self.newRunCommandSingle(cmd, .saturator),
.vintagedelay => try self.newRunCommandSingle(cmd, .vintagedelay),
.amp => try self.runSingleCommand(cmd, .amp),
.rflanger => try self.runSingleCommand(cmd, .rflanger),
.eq => try self.runSingleCommand(cmd, .eq),
.phaser => try self.runSingleCommand(cmd, .phaser),
.mbeq => try self.runSingleCommand(cmd, .mbeq),
.chorus => try self.runSingleCommand(cmd, .chorus),
.pitchscaler => try self.runSingleCommand(cmd, .pitchscaler),
.reverb => try self.runSingleCommand(cmd, .reverb),
.highpass => try self.runSingleCommand(cmd, .highpass),
.delay => try self.runSingleCommand(cmd, .delay),
.vinyl => try self.runSingleCommand(cmd, .vinyl),
.revdelay => try self.runSingleCommand(cmd, .revdelay),
.gate => try self.runSingleCommand(cmd, .gate),
.detune => try self.runSingleCommand(cmd, .detune),
.overdrive => try self.runSingleCommand(cmd, .overdrive),
.degrade => try self.runSingleCommand(cmd, .degrade),
.repsycho => try self.runSingleCommand(cmd, .repsycho),
.talkbox => try self.runSingleCommand(cmd, .talkbox),
.dyncomp => try self.runSingleCommand(cmd, .dyncomp),
.thruzero => try self.runSingleCommand(cmd, .thruzero),
.foverdrive => try self.runSingleCommand(cmd, .foverdrive),
.gverb => try self.runSingleCommand(cmd, .gverb),
.invert => try self.runSingleCommand(cmd, .invert),
.tapedelay => try self.runSingleCommand(cmd, .tapedelay),
.moddelay => try self.runSingleCommand(cmd, .moddelay),
.multichorus => try self.runSingleCommand(cmd, .multichorus),
.saturator => try self.runSingleCommand(cmd, .saturator),
.vintagedelay => try self.runSingleCommand(cmd, .vintagedelay),
.noise => try self.newRunCommandSingle(cmd, .noise),
.wildnoise => try self.newRunCommandSingle(cmd, .wildnoise),
.write => try self.newRunCommandSingle(cmd, .write),
.embed => try self.newRunCommandSingle(cmd, .embed),
.noise => try self.runSingleCommand(cmd, .noise),
.wildnoise => try self.runSingleCommand(cmd, .wildnoise),
.write => try self.runSingleCommand(cmd, .write),
.embed => try self.runSingleCommand(cmd, .embed),
else => {
std.debug.warn("TODO support {}\n", .{@tagName(cmd.tag)});
@ -307,69 +304,6 @@ pub const Runner = struct {
},
}
}
fn runCommand(self: *Runner, cmd: *lang.Command) !void {
var params = ParamList.init(self.allocator);
defer params.deinit();
var map = ParamMap.init(self.allocator);
defer map.deinit();
return switch (cmd.command) {
.Noop => {},
.Load => blk: {
var path = cmd.args.items[0];
try self.loadCmd(path);
// TODO is this needed?
break :blk;
},
.Quicksave => try self.quicksaveCmd(),
.RunQS => try self.runQSCmd(cmd.args.items[0]),
.Noise => blk: {
const pos = try cmd.consumePosition();
try cmd.appendParamMap(&map, "seed");
try cmd.appendParamMap(&map, "fill_bytes");
try self.noiseCmd(pos, &map);
},
.WildNoise => blk: {
const pos = try cmd.consumePosition();
try cmd.appendParamMap(&map, "seed");
try cmd.appendParamMap(&map, "fill_bytes");
try self.wildNoiseCmd(pos, &map);
},
.Write => blk: {
const pos = try cmd.consumePosition();
try cmd.appendParamMap(&map, "data");
try self.writeCmd(pos, &map);
},
.Embed => blk: {
const pos = try cmd.consumePosition();
const path = cmd.args.items[2];
try self.embedCmd(pos, path);
},
.Rotate => blk: {
const deg = try cmd.floatArgAt(0);
const bgfill = try cmd.argAt(1);
try self.rotateCmd(deg, bgfill);
},
else => blk: {
std.debug.warn("Unsupported command: {}\n", .{cmd.command});
break :blk RunError.UnknownCommand;
},
};
}
/// Run a list of commands.
pub fn runCommands(
self: *Runner,
@ -378,7 +312,7 @@ pub const Runner = struct {
) !void {
for (cmds.items) |cmd| {
cmd.print();
try self.newRunCommand(cmd.*);
try self.runCommand(cmd.*);
}
}
};