diff --git a/doc/README.md b/doc/README.md index 8330e43..3620102 100644 --- a/doc/README.md +++ b/doc/README.md @@ -38,17 +38,13 @@ Run the eg-amp plugin over the given slice of the file. Run the Retro Flanger script from the SWH plugins. -Parameters: - - `delay_depth_avg`: Average stall (ms), 0..10, default 2.5 - - `law_freq`: Flange frequency (Hz), 0.5..8, default 1 + - `delay_depth_avg` is for the `Average stall (ms)` parameter of the plugin. + - `law_freq` is for the `Flange frequency` parameter of the plugin. ## `eq split index lo mid hi` Run the DJ EQ plugin from the SWH plugins. -Parameters: - - `lo`: Low range - `lo`, `mid`, and `hi` are the respective dB gains for each frequency range. All three ranges accept gains from -70dB to +6dB. diff --git a/src/custom.zig b/src/custom.zig index 2fc5a09..df9f331 100644 --- a/src/custom.zig +++ b/src/custom.zig @@ -95,10 +95,6 @@ pub const WildNoise = struct { } }; -/// Write any float to the image. -/// Keep in mind that the bit representation of the float will clash with -/// the format of BMP pixel data, which means writing 0 everywhere won't give -/// you the black color. pub const Write = struct { data: f32, diff --git a/src/image.zig b/src/image.zig index e031c5a..8686e12 100644 --- a/src/image.zig +++ b/src/image.zig @@ -243,22 +243,17 @@ pub const Image = struct { position: plugins.Position, params: plugins.ParamList, ) !void { - var timer = try std.time.Timer.start(); - var ctx = try plugins.makeContext(self.allocator, plugin_uri); defer ctx.deinit(); var ports = try lv2.setupPorts(&ctx); if (ctx.n_audio_in > 2) { - std.debug.warn("plugin <{}> has more than two inputs.\n", plugin_uri); + std.debug.warn("plugin <{}> accepts more than two channels.\n", plugin_uri); return ImageError.InvalidPlugin; } - if (ctx.n_audio_out > 2) { - std.debug.warn("plugin <{}> has more than two outputs.\n", plugin_uri); - return ImageError.InvalidPlugin; - } + // TODO check n_audio_out > 2 // now, for each param for the plugin, we find its port, and set // the value for the port there. @@ -352,9 +347,6 @@ pub const Image = struct { _ = c.sf_close(self.sndfile); try self.reopen(tmpnam); - - var time_taken = timer.read(); - std.debug.warn("\ttook {d:.2}ms running plugin\n", time_taken / std.time.millisecond); } pub fn saveTo(self: *Image, out_path: []const u8) !void { diff --git a/src/lang.zig b/src/lang.zig index 9dc588a..55dd9b2 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -169,66 +169,6 @@ pub const Lang = struct { _ = try self.keywords.put("rotate", .Rotate); } - // TODO remove this once AutoHashMap is fixed. - pub fn getCommand(self: *Lang, stmt: []const u8) ?CommandType { - const commands = [_][]const u8{ - "noop", - "load", - "quicksave", - "runqs", - "amp", - "rflanger", - "eq", - "phaser", - "mbeq", - "chorus", - "pitchscaler", - "reverb", - "highpass", - "delay", - "vinyl", - "revdelay", - "noise", - "wildnoise", - "write", - "rotate", - }; - - const command_types = [_]CommandType{ - .Noop, - .Load, - .Quicksave, - .RunQS, - - .Amp, - .RFlanger, - .Eq, - .Phaser, - .Mbeq, - .Chorus, - .PitchScaler, - .Reverb, - .Highpass, - .Delay, - .Vinyl, - .RevDelay, - - .Noise, - .WildNoise, - .Write, - - .Rotate, - }; - - std.debug.assert(commands.len == command_types.len); - - for (commands) |command, idx| { - if (std.mem.eql(u8, stmt, command)) return command_types[idx]; - } - - return null; - } - pub fn parse(self: *Lang, data: []const u8) !CommandList { var splitted_it = std.mem.separate(data, ";"); try self.fillKeywords(); @@ -248,12 +188,12 @@ pub const Lang = struct { if (cmd_opt == null) return ParseError.NoCommandGiven; var command = cmd_opt.?; - var ctype_opt = self.getCommand(command); + var kv_opt = self.keywords.get(command); var ctype: CommandType = undefined; - if (ctype_opt) |ctype_val| { - ctype = ctype_val; + if (kv_opt) |kv| { + ctype = kv.value; } else { - std.debug.warn("Unknown command: '{}' ({})\n", command, command.len); + std.debug.warn("Unknown command: '{}'\n", command); return ParseError.UnknownCommand; } diff --git a/src/plugin.zig b/src/plugin.zig index 4612523..7794c9e 100644 --- a/src/plugin.zig +++ b/src/plugin.zig @@ -99,6 +99,12 @@ pub const RunContext = struct { return ImageError.InstantiateFail; } + // we allocate []f32 with size 2 to account for stereo plugins, however + // we only use &in_buf[0] and &out_buf[0], and don't use the + // (supposedly) right side of neither input or output. + var in_buf = try allocator.alloc(f32, 2); + std.mem.secureZero(f32, in_buf); + return RunContext{ .buffers = try RunBuffers.init(allocator), .instance = instance.?,