diff --git a/doc/README.md b/doc/README.md index fe22674..746b6f1 100644 --- a/doc/README.md +++ b/doc/README.md @@ -60,6 +60,15 @@ Parameters: - `fb`: Feedback, -1..1, default 0 - `spread`: Spread (octaves), 0..2, default 1 +## `mbeq split index band_1 band_2 band_3 band_4 band_5 band_6 band_7 band_8 band_9 band_10 band_11 band_12 band_13 band_14 band_15` + +In respective order, the band arugments represent the: +50Hz, 100Hz, 156Hz, 220Hz, 311Hz, 440Hz, 622Hz, 880Hz 1250Hz, 1750Hz, 2500Hz, +3500Hz, 5000Hz, 10000Hz and 20000Hz frequencies. + +All of them represent the band's gain in dB. The range is -70 to +30dB, +default is 0. + ## TODO `echo split index delay` Run an echo filter on the given loaded file. diff --git a/examples/mbeq.scri b/examples/mbeq.scri new file mode 100644 index 0000000..9afbee1 --- /dev/null +++ b/examples/mbeq.scri @@ -0,0 +1,3 @@ +load :0; +mbeq 3 1 1 4 0.2 2.1; +quicksave; diff --git a/src/lang.zig b/src/lang.zig index dc7010c..2ad9e9f 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -17,6 +17,7 @@ pub const CommandType = enum { RFlanger, Eq, Phaser, + Mbeq, }; pub const Command = struct { @@ -59,6 +60,28 @@ pub const Command = struct { var arg = try self.argAt(idx); return try std.fmt.parseFloat(f32, arg); } + + pub fn floatArgMany( + self: *const Command, + allocator: *std.mem.Allocator, + start_index: usize, + elements: usize, + default: f32, + ) ![]const f32 { + var i: usize = start_index; + var arr = std.ArrayList(f32).init(allocator); + + while (i < elements) : (i += 1) { + var value: f32 = self.floatArgAt(i) catch |err| blk: { + std.debug.warn("\tdoing default on arg {}\n", i); + break :blk default; + }; + + try arr.append(value); + } + + return arr.toSliceConst(); + } }; pub const CommandList = std.ArrayList(*Command); @@ -86,6 +109,7 @@ pub const Lang = struct { _ = try self.keywords.put("amp", .Amp); _ = try self.keywords.put("rflanger", .RFlanger); _ = try self.keywords.put("eq", .Eq); + _ = try self.keywords.put("mbeq", .Mbeq); _ = try self.keywords.put("phaser", .Phaser); } diff --git a/src/runner.zig b/src/runner.zig index 0299838..ab0cefd 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -231,6 +231,23 @@ pub const Runner = struct { try image.runPlugin("http://plugin.org.uk/swh-plugins/lfoPhaser", position, params); } + fn mbeqCmd( + self: *Runner, + position: plugin.Position, + bands: []const f32, + ) !void { + var image = try self.getImage(); + var params = plugin.ParamList.init(self.allocator); + defer params.deinit(); + + for (bands) |band_value, idx| { + var sym = try std.fmt.allocPrint(self.allocator, "band_{}", idx + 1); + try appendParam(¶ms, sym, band_value); + } + + try image.runPlugin("http://plugin.org.uk/swh-plugins/mbeq", position, params); + } + fn runCommand(self: *Runner, cmd: *lang.Command) !void { return switch (cmd.command) { .Noop => {}, @@ -278,6 +295,12 @@ pub const Runner = struct { try self.phaserCmd(pos, lfo_rate, lfo_depth, fb, spread); }, + .Mbeq => blk: { + const pos = try cmd.consumePosition(); + const bands = try cmd.floatArgMany(self.allocator, 2, 15, f32(0)); + try self.mbeqCmd(pos, bands); + }, + else => blk: { std.debug.warn("Unknown command: {}\n", cmd.command); break :blk RunError.UnknownCommand;