Compare commits
No commits in common. "b0525f23862d98900799be4d0c1c031eb3a5ff9b" and "b238517b3399ed634f15b9206782bb565ef0d8d5" have entirely different histories.
b0525f2386
...
b238517b33
1 changed files with 110 additions and 44 deletions
154
src/runner.zig
154
src/runner.zig
|
@ -190,14 +190,16 @@ pub const Runner = struct {
|
||||||
_ = try proc.spawnAndWait();
|
_ = try proc.spawnAndWait();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rotateCmd(self: *Runner, cmd: lang.Command) !void {
|
fn rotateCmd(
|
||||||
const rotate_cmd = cmd.cast(lang.Command.Rotate).?;
|
self: *Runner,
|
||||||
|
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, rotate_cmd.bgfill);
|
var c_bgfill = try std.cstr.addNullByte(self.allocator, bgfill);
|
||||||
defer self.allocator.free(c_bgfill);
|
defer self.allocator.free(c_bgfill);
|
||||||
|
|
||||||
try magick.runRotate(image, rotate_cmd.deg, c_bgfill);
|
try magick.runRotate(image, deg, c_bgfill);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn executeLV2Command(self: *@This(), command: var) !void {
|
fn executeLV2Command(self: *@This(), command: var) !void {
|
||||||
|
@ -222,7 +224,7 @@ pub const Runner = struct {
|
||||||
try image.runPlugin(typ.lv2_url, pos, params);
|
try image.runPlugin(typ.lv2_url, pos, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn executeCustomCommand(self: *@This(), command: var) !void {
|
fn executePlugin(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,
|
||||||
|
@ -232,7 +234,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 runSingleCommand(
|
fn newRunCommandSingle(
|
||||||
self: *@This(),
|
self: *@This(),
|
||||||
cmd: lang.Command,
|
cmd: lang.Command,
|
||||||
comptime tag: lang.Command.Tag,
|
comptime tag: lang.Command.Tag,
|
||||||
|
@ -249,54 +251,55 @@ 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.executeCustomCommand(command.*),
|
.custom_command => try self.executePlugin(command.*),
|
||||||
else => @panic("TODO support command type"),
|
else => @panic("TODO support command type"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn runCommand(self: *@This(), cmd: lang.Command) !void {
|
fn newRunCommand(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 => try self.quicksaveCmd(),
|
.quicksave => {
|
||||||
.rotate => try self.rotateCmd(cmd),
|
try self.quicksaveCmd();
|
||||||
|
},
|
||||||
|
.amp => try self.newRunCommandSingle(cmd, .amp),
|
||||||
|
|
||||||
.amp => try self.runSingleCommand(cmd, .amp),
|
.rflanger => try self.newRunCommandSingle(cmd, .rflanger),
|
||||||
.rflanger => try self.runSingleCommand(cmd, .rflanger),
|
.eq => try self.newRunCommandSingle(cmd, .eq),
|
||||||
.eq => try self.runSingleCommand(cmd, .eq),
|
.phaser => try self.newRunCommandSingle(cmd, .phaser),
|
||||||
.phaser => try self.runSingleCommand(cmd, .phaser),
|
.mbeq => try self.newRunCommandSingle(cmd, .mbeq),
|
||||||
.mbeq => try self.runSingleCommand(cmd, .mbeq),
|
.chorus => try self.newRunCommandSingle(cmd, .chorus),
|
||||||
.chorus => try self.runSingleCommand(cmd, .chorus),
|
.pitchscaler => try self.newRunCommandSingle(cmd, .pitchscaler),
|
||||||
.pitchscaler => try self.runSingleCommand(cmd, .pitchscaler),
|
.reverb => try self.newRunCommandSingle(cmd, .reverb),
|
||||||
.reverb => try self.runSingleCommand(cmd, .reverb),
|
.highpass => try self.newRunCommandSingle(cmd, .highpass),
|
||||||
.highpass => try self.runSingleCommand(cmd, .highpass),
|
.delay => try self.newRunCommandSingle(cmd, .delay),
|
||||||
.delay => try self.runSingleCommand(cmd, .delay),
|
.vinyl => try self.newRunCommandSingle(cmd, .vinyl),
|
||||||
.vinyl => try self.runSingleCommand(cmd, .vinyl),
|
.revdelay => try self.newRunCommandSingle(cmd, .revdelay),
|
||||||
.revdelay => try self.runSingleCommand(cmd, .revdelay),
|
.gate => try self.newRunCommandSingle(cmd, .gate),
|
||||||
.gate => try self.runSingleCommand(cmd, .gate),
|
.detune => try self.newRunCommandSingle(cmd, .detune),
|
||||||
.detune => try self.runSingleCommand(cmd, .detune),
|
.overdrive => try self.newRunCommandSingle(cmd, .overdrive),
|
||||||
.overdrive => try self.runSingleCommand(cmd, .overdrive),
|
.degrade => try self.newRunCommandSingle(cmd, .degrade),
|
||||||
.degrade => try self.runSingleCommand(cmd, .degrade),
|
.repsycho => try self.newRunCommandSingle(cmd, .repsycho),
|
||||||
.repsycho => try self.runSingleCommand(cmd, .repsycho),
|
.talkbox => try self.newRunCommandSingle(cmd, .talkbox),
|
||||||
.talkbox => try self.runSingleCommand(cmd, .talkbox),
|
.dyncomp => try self.newRunCommandSingle(cmd, .dyncomp),
|
||||||
.dyncomp => try self.runSingleCommand(cmd, .dyncomp),
|
.thruzero => try self.newRunCommandSingle(cmd, .thruzero),
|
||||||
.thruzero => try self.runSingleCommand(cmd, .thruzero),
|
.foverdrive => try self.newRunCommandSingle(cmd, .foverdrive),
|
||||||
.foverdrive => try self.runSingleCommand(cmd, .foverdrive),
|
.gverb => try self.newRunCommandSingle(cmd, .gverb),
|
||||||
.gverb => try self.runSingleCommand(cmd, .gverb),
|
.invert => try self.newRunCommandSingle(cmd, .invert),
|
||||||
.invert => try self.runSingleCommand(cmd, .invert),
|
.tapedelay => try self.newRunCommandSingle(cmd, .tapedelay),
|
||||||
.tapedelay => try self.runSingleCommand(cmd, .tapedelay),
|
.moddelay => try self.newRunCommandSingle(cmd, .moddelay),
|
||||||
.moddelay => try self.runSingleCommand(cmd, .moddelay),
|
.multichorus => try self.newRunCommandSingle(cmd, .multichorus),
|
||||||
.multichorus => try self.runSingleCommand(cmd, .multichorus),
|
.saturator => try self.newRunCommandSingle(cmd, .saturator),
|
||||||
.saturator => try self.runSingleCommand(cmd, .saturator),
|
.vintagedelay => try self.newRunCommandSingle(cmd, .vintagedelay),
|
||||||
.vintagedelay => try self.runSingleCommand(cmd, .vintagedelay),
|
|
||||||
|
|
||||||
.noise => try self.runSingleCommand(cmd, .noise),
|
.noise => try self.newRunCommandSingle(cmd, .noise),
|
||||||
.wildnoise => try self.runSingleCommand(cmd, .wildnoise),
|
.wildnoise => try self.newRunCommandSingle(cmd, .wildnoise),
|
||||||
.write => try self.runSingleCommand(cmd, .write),
|
.write => try self.newRunCommandSingle(cmd, .write),
|
||||||
.embed => try self.runSingleCommand(cmd, .embed),
|
.embed => try self.newRunCommandSingle(cmd, .embed),
|
||||||
|
|
||||||
else => {
|
else => {
|
||||||
std.debug.warn("TODO support {}\n", .{@tagName(cmd.tag)});
|
std.debug.warn("TODO support {}\n", .{@tagName(cmd.tag)});
|
||||||
|
@ -304,6 +307,69 @@ 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,
|
||||||
|
@ -312,7 +378,7 @@ pub const Runner = struct {
|
||||||
) !void {
|
) !void {
|
||||||
for (cmds.items) |cmd| {
|
for (cmds.items) |cmd| {
|
||||||
cmd.print();
|
cmd.print();
|
||||||
try self.runCommand(cmd.*);
|
try self.newRunCommand(cmd.*);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue