diff --git a/doc/README.md b/doc/README.md index fe22674..5895910 100644 --- a/doc/README.md +++ b/doc/README.md @@ -23,8 +23,6 @@ where in the file you want the plugin to be ran. so, if you did `plugin 3 1...`, it would split the file in 3, then get the part that is of index 1 (starting at 0). -**Keep in mind parts start from the bottom of the file.** - ## `load path_or_arg` Load a file into memory. The file MUST end with the bmp extension (and so MUST @@ -36,29 +34,7 @@ Run the eg-amp plugin over the given slice of the file. ## `rflanger split index delay_depth_avg law_freq` -Run the Retro Flanger script from the SWH plugins. - - - `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. - -`lo`, `mid`, and `hi` are the respective dB gains for each frequency range. - -All three ranges accept gains from -70dB to +6dB. -Default is 0 for all (no action taken). - -## `phaser split index lfo_rate lfo_depth fb spread` - -Run the LFO Phaser plugin from the SWH plugins. - -Parameters: - - `lfo_rate`: LFO Rate (Hz), 0..100, default 25 - - `lfo_depth`: LFO depth, 0..1, default 0.25 - - `fb`: Feedback, -1..1, default 0 - - `spread`: Spread (octaves), 0..2, default 1 +Runs the Retro Flanger script from the SWH plugins. ## TODO `echo split index delay` diff --git a/examples/eq.scri b/examples/eq.scri deleted file mode 100644 index 08ac2b4..0000000 --- a/examples/eq.scri +++ /dev/null @@ -1,4 +0,0 @@ -load :0; -eq 3 1 2 -0.3 0.7; -eq 10 3 3 -0.9 2; -quicksave; diff --git a/examples/phaser.scri b/examples/phaser.scri deleted file mode 100644 index 9e8f2ce..0000000 --- a/examples/phaser.scri +++ /dev/null @@ -1,3 +0,0 @@ -load :0; -phaser 3 1 25 0.25 0 1; -quicksave; diff --git a/src/image.zig b/src/image.zig index c11e3fd..06bc739 100644 --- a/src/image.zig +++ b/src/image.zig @@ -187,7 +187,7 @@ pub const Image = struct { var sym = c.lilv_new_string(ctx.world, sym_cstr.ptr); const port = c.lilv_plugin_get_port_by_symbol(ctx.plugin, sym) orelse blk: { - std.debug.warn("assert fail: symbol {} not found on port\n", param.sym); + std.debug.warn("assert fail: symbol not found on port"); return ImageError.InvalidSymbol; }; diff --git a/src/lang.zig b/src/lang.zig index dc7010c..f3c9c71 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -1,7 +1,5 @@ const std = @import("std"); -const plugin = @import("plugin.zig"); - pub const ParseError = error{ NoCommandGiven, UnknownCommand, @@ -11,12 +9,9 @@ pub const ParseError = error{ pub const CommandType = enum { Noop, Load, - Quicksave, - Amp, RFlanger, - Eq, - Phaser, + Quicksave, }; pub const Command = struct { @@ -43,13 +38,6 @@ pub const Command = struct { return try std.fmt.parseInt(usize, arg, 10); } - pub fn consumePosition(self: *const Command) !plugin.Position { - return plugin.Position{ - .split = try self.usizeArgAt(0), - .index = try self.usizeArgAt(1), - }; - } - pub fn intArgAt(self: *const Command, idx: usize) !i32 { var arg = try self.argAt(idx); return try std.fmt.parseInt(i32, arg, 10); @@ -64,34 +52,33 @@ pub const Command = struct { pub const CommandList = std.ArrayList(*Command); pub const ArgList = std.ArrayList([]const u8); -pub const PluginKeywords = [_]CommandType{ .Amp, .RFlanger }; -pub const KeywordMap = std.AutoHashMap([]const u8, CommandType); +pub fn commandToCmdType(command: []const u8) ParseError!CommandType { + // TODO make a hashmap for those + if (std.mem.eql(u8, command, "noop")) { + return CommandType.Noop; + } else if (std.mem.eql(u8, command, "load")) { + return CommandType.Load; + } else if (std.mem.eql(u8, command, "amp")) { + return CommandType.Amp; + } else if (std.mem.eql(u8, command, "rflanger")) { + return CommandType.RFlanger; + } else if (std.mem.eql(u8, command, "quicksave")) { + return CommandType.Quicksave; + } else { + std.debug.warn("Unknown command: '{}'\n", command); + return ParseError.UnknownCommand; + } +} pub const Lang = struct { allocator: *std.mem.Allocator, - keywords: KeywordMap, pub fn init(allocator: *std.mem.Allocator) Lang { - return Lang{ - .allocator = allocator, - .keywords = KeywordMap.init(allocator), - }; - } - - fn fillKeywords(self: *Lang) !void { - _ = try self.keywords.put("noop", .Noop); - _ = try self.keywords.put("load", .Load); - _ = try self.keywords.put("quicksave", .Quicksave); - - _ = try self.keywords.put("amp", .Amp); - _ = try self.keywords.put("rflanger", .RFlanger); - _ = try self.keywords.put("eq", .Eq); - _ = try self.keywords.put("phaser", .Phaser); + return Lang{ .allocator = allocator }; } pub fn parse(self: *Lang, data: []const u8) !CommandList { var splitted_it = std.mem.separate(data, ";"); - try self.fillKeywords(); var cmds = CommandList.init(self.allocator); while (splitted_it.next()) |stmt_orig| { @@ -106,17 +93,9 @@ pub const Lang = struct { var cmd_opt = tok_it.next(); if (cmd_opt == null) return ParseError.NoCommandGiven; + var command = cmd_opt.?; - - var kv_opt = self.keywords.get(command); - var ctype: CommandType = undefined; - if (kv_opt) |kv| { - ctype = kv.value; - } else { - std.debug.warn("Unknown command: '{}'\n", command); - return ParseError.UnknownCommand; - } - + var ctype = try commandToCmdType(command); var args = ArgList.init(self.allocator); while (tok_it.next()) |arg| { diff --git a/src/runner.zig b/src/runner.zig index 0299838..baeedfe 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -11,10 +11,6 @@ pub const RunError = error{ 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 { allocator: *std.mem.Allocator, image: ?*Image = null, @@ -193,44 +189,6 @@ pub const Runner = struct { ); } - fn eqCmd( - self: *Runner, - position: plugin.Position, - lo: f32, - mid: f32, - high: f32, - ) !void { - 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); - } - - fn phaserCmd( - self: *Runner, - position: plugin.Position, - lfo_rate: f32, - lfo_depth: f32, - fb: f32, - spread: f32, - ) !void { - 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); - } - fn runCommand(self: *Runner, cmd: *lang.Command) !void { return switch (cmd.command) { .Noop => {}, @@ -257,27 +215,6 @@ pub const Runner = struct { try self.rFlangerCmd(split, index, delay_depth_avg, law_freq); }, - .Eq => blk: { - const pos = try cmd.consumePosition(); - - const lo = try cmd.floatArgAt(2); - const mid = try cmd.floatArgAt(3); - const high = try cmd.floatArgAt(4); - - try self.eqCmd(pos, lo, mid, high); - }, - - .Phaser => blk: { - const pos = try cmd.consumePosition(); - - const lfo_rate = try cmd.floatArgAt(2); - const lfo_depth = try cmd.floatArgAt(3); - const fb = try cmd.floatArgAt(4); - const spread = try cmd.floatArgAt(5); - - try self.phaserCmd(pos, lfo_rate, lfo_depth, fb, spread); - }, - else => blk: { std.debug.warn("Unknown command: {}\n", cmd.command); break :blk RunError.UnknownCommand;