Compare commits
3 commits
b238517b33
...
b0525f2386
Author | SHA1 | Date | |
---|---|---|---|
b0525f2386 | |||
54919110a5 | |||
76b353e593 |
1 changed files with 44 additions and 110 deletions
154
src/runner.zig
154
src/runner.zig
|
@ -190,16 +190,14 @@ pub const Runner = struct {
|
||||||
_ = try proc.spawnAndWait();
|
_ = try proc.spawnAndWait();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rotateCmd(
|
fn rotateCmd(self: *Runner, cmd: lang.Command) !void {
|
||||||
self: *Runner,
|
const rotate_cmd = cmd.cast(lang.Command.Rotate).?;
|
||||||
deg: f32,
|
|
||||||
bgfill: []const u8,
|
|
||||||
) !void {
|
|
||||||
var image = try self.getImage();
|
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);
|
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 {
|
fn executeLV2Command(self: *@This(), command: var) !void {
|
||||||
|
@ -224,7 +222,7 @@ pub const Runner = struct {
|
||||||
try image.runPlugin(typ.lv2_url, pos, params);
|
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{
|
const pos = plugin.Position{
|
||||||
.split = command.split,
|
.split = command.split,
|
||||||
.index = command.index,
|
.index = command.index,
|
||||||
|
@ -234,7 +232,7 @@ pub const Runner = struct {
|
||||||
try image.runCustomPlugin(@TypeOf(command).plugin_type, pos, command.parameters);
|
try image.runCustomPlugin(@TypeOf(command).plugin_type, pos, command.parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn newRunCommandSingle(
|
fn runSingleCommand(
|
||||||
self: *@This(),
|
self: *@This(),
|
||||||
cmd: lang.Command,
|
cmd: lang.Command,
|
||||||
comptime tag: lang.Command.Tag,
|
comptime tag: lang.Command.Tag,
|
||||||
|
@ -251,55 +249,54 @@ pub const Runner = struct {
|
||||||
const ctype = typ.command_type;
|
const ctype = typ.command_type;
|
||||||
switch (ctype) {
|
switch (ctype) {
|
||||||
.lv2_command => try self.executeLV2Command(command.*),
|
.lv2_command => try self.executeLV2Command(command.*),
|
||||||
.custom_command => try self.executePlugin(command.*),
|
.custom_command => try self.executeCustomCommand(command.*),
|
||||||
else => @panic("TODO support command type"),
|
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) {
|
switch (cmd.tag) {
|
||||||
.load => {
|
.load => {
|
||||||
const command = cmd.cast(lang.Command.Load).?;
|
const command = cmd.cast(lang.Command.Load).?;
|
||||||
try self.loadCmd(command.path);
|
try self.loadCmd(command.path);
|
||||||
},
|
},
|
||||||
.quicksave => {
|
.quicksave => try self.quicksaveCmd(),
|
||||||
try self.quicksaveCmd();
|
.rotate => try self.rotateCmd(cmd),
|
||||||
},
|
|
||||||
.amp => try self.newRunCommandSingle(cmd, .amp),
|
|
||||||
|
|
||||||
.rflanger => try self.newRunCommandSingle(cmd, .rflanger),
|
.amp => try self.runSingleCommand(cmd, .amp),
|
||||||
.eq => try self.newRunCommandSingle(cmd, .eq),
|
.rflanger => try self.runSingleCommand(cmd, .rflanger),
|
||||||
.phaser => try self.newRunCommandSingle(cmd, .phaser),
|
.eq => try self.runSingleCommand(cmd, .eq),
|
||||||
.mbeq => try self.newRunCommandSingle(cmd, .mbeq),
|
.phaser => try self.runSingleCommand(cmd, .phaser),
|
||||||
.chorus => try self.newRunCommandSingle(cmd, .chorus),
|
.mbeq => try self.runSingleCommand(cmd, .mbeq),
|
||||||
.pitchscaler => try self.newRunCommandSingle(cmd, .pitchscaler),
|
.chorus => try self.runSingleCommand(cmd, .chorus),
|
||||||
.reverb => try self.newRunCommandSingle(cmd, .reverb),
|
.pitchscaler => try self.runSingleCommand(cmd, .pitchscaler),
|
||||||
.highpass => try self.newRunCommandSingle(cmd, .highpass),
|
.reverb => try self.runSingleCommand(cmd, .reverb),
|
||||||
.delay => try self.newRunCommandSingle(cmd, .delay),
|
.highpass => try self.runSingleCommand(cmd, .highpass),
|
||||||
.vinyl => try self.newRunCommandSingle(cmd, .vinyl),
|
.delay => try self.runSingleCommand(cmd, .delay),
|
||||||
.revdelay => try self.newRunCommandSingle(cmd, .revdelay),
|
.vinyl => try self.runSingleCommand(cmd, .vinyl),
|
||||||
.gate => try self.newRunCommandSingle(cmd, .gate),
|
.revdelay => try self.runSingleCommand(cmd, .revdelay),
|
||||||
.detune => try self.newRunCommandSingle(cmd, .detune),
|
.gate => try self.runSingleCommand(cmd, .gate),
|
||||||
.overdrive => try self.newRunCommandSingle(cmd, .overdrive),
|
.detune => try self.runSingleCommand(cmd, .detune),
|
||||||
.degrade => try self.newRunCommandSingle(cmd, .degrade),
|
.overdrive => try self.runSingleCommand(cmd, .overdrive),
|
||||||
.repsycho => try self.newRunCommandSingle(cmd, .repsycho),
|
.degrade => try self.runSingleCommand(cmd, .degrade),
|
||||||
.talkbox => try self.newRunCommandSingle(cmd, .talkbox),
|
.repsycho => try self.runSingleCommand(cmd, .repsycho),
|
||||||
.dyncomp => try self.newRunCommandSingle(cmd, .dyncomp),
|
.talkbox => try self.runSingleCommand(cmd, .talkbox),
|
||||||
.thruzero => try self.newRunCommandSingle(cmd, .thruzero),
|
.dyncomp => try self.runSingleCommand(cmd, .dyncomp),
|
||||||
.foverdrive => try self.newRunCommandSingle(cmd, .foverdrive),
|
.thruzero => try self.runSingleCommand(cmd, .thruzero),
|
||||||
.gverb => try self.newRunCommandSingle(cmd, .gverb),
|
.foverdrive => try self.runSingleCommand(cmd, .foverdrive),
|
||||||
.invert => try self.newRunCommandSingle(cmd, .invert),
|
.gverb => try self.runSingleCommand(cmd, .gverb),
|
||||||
.tapedelay => try self.newRunCommandSingle(cmd, .tapedelay),
|
.invert => try self.runSingleCommand(cmd, .invert),
|
||||||
.moddelay => try self.newRunCommandSingle(cmd, .moddelay),
|
.tapedelay => try self.runSingleCommand(cmd, .tapedelay),
|
||||||
.multichorus => try self.newRunCommandSingle(cmd, .multichorus),
|
.moddelay => try self.runSingleCommand(cmd, .moddelay),
|
||||||
.saturator => try self.newRunCommandSingle(cmd, .saturator),
|
.multichorus => try self.runSingleCommand(cmd, .multichorus),
|
||||||
.vintagedelay => try self.newRunCommandSingle(cmd, .vintagedelay),
|
.saturator => try self.runSingleCommand(cmd, .saturator),
|
||||||
|
.vintagedelay => try self.runSingleCommand(cmd, .vintagedelay),
|
||||||
|
|
||||||
.noise => try self.newRunCommandSingle(cmd, .noise),
|
.noise => try self.runSingleCommand(cmd, .noise),
|
||||||
.wildnoise => try self.newRunCommandSingle(cmd, .wildnoise),
|
.wildnoise => try self.runSingleCommand(cmd, .wildnoise),
|
||||||
.write => try self.newRunCommandSingle(cmd, .write),
|
.write => try self.runSingleCommand(cmd, .write),
|
||||||
.embed => try self.newRunCommandSingle(cmd, .embed),
|
.embed => try self.runSingleCommand(cmd, .embed),
|
||||||
|
|
||||||
else => {
|
else => {
|
||||||
std.debug.warn("TODO support {}\n", .{@tagName(cmd.tag)});
|
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.
|
/// Run a list of commands.
|
||||||
pub fn runCommands(
|
pub fn runCommands(
|
||||||
self: *Runner,
|
self: *Runner,
|
||||||
|
@ -378,7 +312,7 @@ pub const Runner = struct {
|
||||||
) !void {
|
) !void {
|
||||||
for (cmds.items) |cmd| {
|
for (cmds.items) |cmd| {
|
||||||
cmd.print();
|
cmd.print();
|
||||||
try self.newRunCommand(cmd.*);
|
try self.runCommand(cmd.*);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue