refactor command functions
This commit is contained in:
parent
5fb0f9c066
commit
f9898b2f11
2 changed files with 35 additions and 94 deletions
|
@ -1,3 +1,3 @@
|
||||||
load :0;
|
load :0;
|
||||||
chorus 3 1 3 10 0.5 1 9 0;
|
chorus 3 1 3 10 0.01 0.1 2 0;
|
||||||
quicksave;
|
quicksave;
|
||||||
|
|
127
src/runner.zig
127
src/runner.zig
|
@ -3,6 +3,9 @@ const lang = @import("lang.zig");
|
||||||
const images = @import("image.zig");
|
const images = @import("image.zig");
|
||||||
const plugin = @import("plugin.zig");
|
const plugin = @import("plugin.zig");
|
||||||
|
|
||||||
|
const Position = plugin.Position;
|
||||||
|
const ParamList = plugin.ParamList;
|
||||||
|
|
||||||
const Image = images.Image;
|
const Image = images.Image;
|
||||||
|
|
||||||
pub const RunError = error{
|
pub const RunError = error{
|
||||||
|
@ -11,10 +14,6 @@ pub const RunError = error{
|
||||||
ImageRequired,
|
ImageRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn appendParam(params: *plugin.ParamList, sym: []const u8, value: f32) !void {
|
|
||||||
try params.append(plugin.Param{ .sym = sym, .value = value });
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const Runner = struct {
|
pub const Runner = struct {
|
||||||
allocator: *std.mem.Allocator,
|
allocator: *std.mem.Allocator,
|
||||||
image: ?*Image = null,
|
image: ?*Image = null,
|
||||||
|
@ -154,95 +153,41 @@ pub const Runner = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run the http://lv2plug.in/plugins/eg-amp plugin over the file.
|
/// Run the http://lv2plug.in/plugins/eg-amp plugin over the file.
|
||||||
fn ampCmd(self: *Runner, split: usize, index: usize, gain: f32) !void {
|
fn ampCmd(self: *Runner, pos: Position, params: ParamList) !void {
|
||||||
var image = try self.getImage();
|
var image = try self.getImage();
|
||||||
|
try image.runPlugin("http://lv2plug.in/plugins/eg-amp", pos, params);
|
||||||
var params = plugin.ParamList.init(self.allocator);
|
|
||||||
defer params.deinit();
|
|
||||||
|
|
||||||
try params.append(plugin.Param{ .sym = "gain", .value = gain });
|
|
||||||
|
|
||||||
// TODO if we could detect that the next command is a quicksave then
|
|
||||||
// we don't need the temporary file in runPlugin and instead we
|
|
||||||
// dump it all on the output image for it.
|
|
||||||
try image.runPlugin(
|
|
||||||
"http://lv2plug.in/plugins/eg-amp",
|
|
||||||
plugin.Position{ .split = split, .index = index },
|
|
||||||
params,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rFlangerCmd(
|
fn rFlangerCmd(self: *Runner, pos: Position, params: ParamList) !void {
|
||||||
self: *Runner,
|
|
||||||
split: usize,
|
|
||||||
index: usize,
|
|
||||||
delay_depth_avg: f32,
|
|
||||||
law_freq: f32,
|
|
||||||
) !void {
|
|
||||||
var image = try self.getImage();
|
var image = try self.getImage();
|
||||||
var params = plugin.ParamList.init(self.allocator);
|
try image.runPlugin("http://plugin.org.uk/swh-plugins/retroFlange", pos, params);
|
||||||
defer params.deinit();
|
|
||||||
|
|
||||||
try params.append(plugin.Param{ .sym = "delay_depth_avg", .value = delay_depth_avg });
|
|
||||||
try params.append(plugin.Param{ .sym = "law_freq", .value = law_freq });
|
|
||||||
|
|
||||||
try image.runPlugin(
|
|
||||||
"http://plugin.org.uk/swh-plugins/retroFlange",
|
|
||||||
plugin.Position{ .split = split, .index = index },
|
|
||||||
params,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eqCmd(
|
fn eqCmd(self: *Runner, position: Position, params: ParamList) !void {
|
||||||
self: *Runner,
|
|
||||||
position: plugin.Position,
|
|
||||||
lo: f32,
|
|
||||||
mid: f32,
|
|
||||||
high: f32,
|
|
||||||
) !void {
|
|
||||||
var image = try self.getImage();
|
var image = try self.getImage();
|
||||||
var params = plugin.ParamList.init(self.allocator);
|
|
||||||
defer params.deinit();
|
|
||||||
|
|
||||||
try appendParam(¶ms, "lo", lo);
|
|
||||||
try appendParam(¶ms, "mid", mid);
|
|
||||||
try appendParam(¶ms, "hi", high);
|
|
||||||
|
|
||||||
try image.runPlugin("http://plugin.org.uk/swh-plugins/dj_eq_mono", position, params);
|
try image.runPlugin("http://plugin.org.uk/swh-plugins/dj_eq_mono", position, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn phaserCmd(
|
fn phaserCmd(self: *Runner, position: Position, params: ParamList) !void {
|
||||||
self: *Runner,
|
|
||||||
position: plugin.Position,
|
|
||||||
lfo_rate: f32,
|
|
||||||
lfo_depth: f32,
|
|
||||||
fb: f32,
|
|
||||||
spread: f32,
|
|
||||||
) !void {
|
|
||||||
var image = try self.getImage();
|
var image = try self.getImage();
|
||||||
var params = plugin.ParamList.init(self.allocator);
|
|
||||||
defer params.deinit();
|
|
||||||
|
|
||||||
try appendParam(¶ms, "lfo_rate", lfo_rate);
|
|
||||||
try appendParam(¶ms, "lfo_depth", lfo_depth);
|
|
||||||
try appendParam(¶ms, "fb", fb);
|
|
||||||
try appendParam(¶ms, "spread", spread);
|
|
||||||
|
|
||||||
try image.runPlugin("http://plugin.org.uk/swh-plugins/lfoPhaser", position, params);
|
try image.runPlugin("http://plugin.org.uk/swh-plugins/lfoPhaser", position, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mbeqCmd(
|
fn mbeqCmd(
|
||||||
self: *Runner,
|
self: *Runner,
|
||||||
position: plugin.Position,
|
position: Position,
|
||||||
bands: []const f32,
|
bands: []const f32,
|
||||||
) !void {
|
) !void {
|
||||||
var image = try self.getImage();
|
var image = try self.getImage();
|
||||||
var params = plugin.ParamList.init(self.allocator);
|
var params = ParamList.init(self.allocator);
|
||||||
defer params.deinit();
|
defer params.deinit();
|
||||||
|
|
||||||
for (bands) |band_value, idx| {
|
for (bands) |band_value, idx| {
|
||||||
var sym = try std.fmt.allocPrint(self.allocator, "band_{}", idx + 1);
|
var sym = try std.fmt.allocPrint(self.allocator, "band_{}", idx + 1);
|
||||||
try appendParam(¶ms, sym, band_value);
|
try params.append(plugin.Param{
|
||||||
|
.sym = sym,
|
||||||
|
.value = band_value,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
try image.runPlugin("http://plugin.org.uk/swh-plugins/mbeq", position, params);
|
try image.runPlugin("http://plugin.org.uk/swh-plugins/mbeq", position, params);
|
||||||
|
@ -250,15 +195,15 @@ pub const Runner = struct {
|
||||||
|
|
||||||
fn chorusCmd(
|
fn chorusCmd(
|
||||||
self: *Runner,
|
self: *Runner,
|
||||||
pos: plugin.Position,
|
pos: Position,
|
||||||
params: plugin.ParamList,
|
params: ParamList,
|
||||||
) !void {
|
) !void {
|
||||||
var image = try self.getImage();
|
var image = try self.getImage();
|
||||||
try image.runPlugin("http://plugin.org.uk/swh-plugins/multivoiceChorus", pos, params);
|
try image.runPlugin("http://plugin.org.uk/swh-plugins/multivoiceChorus", pos, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn runCommand(self: *Runner, cmd: *lang.Command) !void {
|
fn runCommand(self: *Runner, cmd: *lang.Command) !void {
|
||||||
var params = plugin.ParamList.init(self.allocator);
|
var params = ParamList.init(self.allocator);
|
||||||
defer params.deinit();
|
defer params.deinit();
|
||||||
|
|
||||||
return switch (cmd.command) {
|
return switch (cmd.command) {
|
||||||
|
@ -271,40 +216,36 @@ pub const Runner = struct {
|
||||||
.Quicksave => try self.quicksaveCmd(),
|
.Quicksave => try self.quicksaveCmd(),
|
||||||
|
|
||||||
.Amp => blk: {
|
.Amp => blk: {
|
||||||
const split = try cmd.usizeArgAt(0);
|
const pos = try cmd.consumePosition();
|
||||||
const index = try cmd.usizeArgAt(1);
|
try cmd.appendParam(¶ms, "gain", 2);
|
||||||
const gain = try cmd.floatArgAt(2);
|
try self.ampCmd(pos, params);
|
||||||
try self.ampCmd(split, index, gain);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
.RFlanger => blk: {
|
.RFlanger => blk: {
|
||||||
const split = try cmd.usizeArgAt(0);
|
const pos = try cmd.consumePosition();
|
||||||
const index = try cmd.usizeArgAt(1);
|
try cmd.appendParam(¶ms, "delay_depth_avg", 2);
|
||||||
const delay_depth_avg = try cmd.floatArgAt(2);
|
try cmd.appendParam(¶ms, "law_freq", 3);
|
||||||
const law_freq = try cmd.floatArgAt(3);
|
try self.rFlangerCmd(pos, params);
|
||||||
|
|
||||||
try self.rFlangerCmd(split, index, delay_depth_avg, law_freq);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
.Eq => blk: {
|
.Eq => blk: {
|
||||||
const pos = try cmd.consumePosition();
|
const pos = try cmd.consumePosition();
|
||||||
|
try cmd.appendParam(¶ms, "lo", 2);
|
||||||
|
try cmd.appendParam(¶ms, "mid", 3);
|
||||||
|
try cmd.appendParam(¶ms, "hi", 4);
|
||||||
|
|
||||||
const lo = try cmd.floatArgAt(2);
|
try self.eqCmd(pos, params);
|
||||||
const mid = try cmd.floatArgAt(3);
|
|
||||||
const high = try cmd.floatArgAt(4);
|
|
||||||
|
|
||||||
try self.eqCmd(pos, lo, mid, high);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
.Phaser => blk: {
|
.Phaser => blk: {
|
||||||
const pos = try cmd.consumePosition();
|
const pos = try cmd.consumePosition();
|
||||||
|
|
||||||
const lfo_rate = try cmd.floatArgAt(2);
|
try cmd.appendParam(¶ms, "lfo_rate", 2);
|
||||||
const lfo_depth = try cmd.floatArgAt(3);
|
try cmd.appendParam(¶ms, "lfo_depth", 3);
|
||||||
const fb = try cmd.floatArgAt(4);
|
try cmd.appendParam(¶ms, "fb", 4);
|
||||||
const spread = try cmd.floatArgAt(5);
|
try cmd.appendParam(¶ms, "spread", 5);
|
||||||
|
|
||||||
try self.phaserCmd(pos, lfo_rate, lfo_depth, fb, spread);
|
try self.phaserCmd(pos, params);
|
||||||
},
|
},
|
||||||
|
|
||||||
.Mbeq => blk: {
|
.Mbeq => blk: {
|
||||||
|
|
Loading…
Reference in a new issue