From 176bbd446add2fb305050b20b43cf998ebee6e99 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 8 Jul 2019 22:40:52 -0300 Subject: [PATCH] add draft impl for ampCmd --- examples/middle_echo.scri | 3 ++- src/lang.zig | 10 ++++++++++ src/plugin.zig | 17 +++++++++++++++++ src/runner.zig | 30 +++++++++++++++++++++++++++++- 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/plugin.zig diff --git a/examples/middle_echo.scri b/examples/middle_echo.scri index 18e29f6..627c63a 100644 --- a/examples/middle_echo.scri +++ b/examples/middle_echo.scri @@ -1,3 +1,4 @@ load :0; -echo 3 0 1 0.2; +amp 10 1; +# echo 3 0 1 0.2; quicksave; diff --git a/src/lang.zig b/src/lang.zig index 8b91e8f..8ee0d9e 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -19,6 +19,16 @@ pub const Command = struct { pub fn print(self: *const Command) void { std.debug.warn("cmd:{}\n", self.command); } + + pub fn intArgAt(self: *const Command, idx: usize) !i32 { + var arg = self.args.at(idx); + return try std.fmt.parseInt(i32, arg, 10); + } + + pub fn floatArgAt(self: *const Command, idx: usize) !f32 { + var arg = self.args.at(idx); + return try std.fmt.parseFloat(f32, arg); + } }; pub const CommandList = std.ArrayList(*Command); diff --git a/src/plugin.zig b/src/plugin.zig new file mode 100644 index 0000000..4241df4 --- /dev/null +++ b/src/plugin.zig @@ -0,0 +1,17 @@ +const std = @import("std"); + +/// Control port +pub const Param = struct { + /// Port symbol + sym: []const u8, + + /// Control value + value: f32, +}; + +pub const ParamList = std.ArrayList(Param); + +pub const Position = struct { + split: usize, + index: usize, +}; diff --git a/src/runner.zig b/src/runner.zig index 90ccd08..740394e 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -1,6 +1,7 @@ const std = @import("std"); const lang = @import("lang.zig"); const images = @import("image.zig"); +const plugin = @import("plugin.zig"); const Image = images.Image; @@ -70,6 +71,8 @@ pub const Runner = struct { return RunError.NoBMP; } + // TODO, copy load_path into a temporary file, then use that + // file to work on things. self.image = try Image.open(self.allocator, load_path); } @@ -135,6 +138,24 @@ pub const Runner = struct { std.debug.warn("out path: {}\n", out_path); } + /// Run the http://lv2plug.in/plugins/eg-amp plugin over the file. + fn ampCmd(self: *Runner, split: i32, index: i32, gain: f32) !void { + var param = try self.allocator.create(plugin.Param); + defer self.allocator.destroy(param); + + param.* = Param{ .sym = "gain", .value = gain }; + + var params = plugin.ParamList.init(self.allocator); + defer params.deinit(); + + // TODO impl this + try image.runPlugin( + "http://lv2plug.in/plugins/eg-amp", + plugin.Position{ .split = split, .index = index }, + params, + ); + } + fn runCommand(self: *Runner, cmd: *lang.Command) !void { return switch (cmd.command) { .Noop => {}, @@ -143,8 +164,15 @@ pub const Runner = struct { try self.loadCmd(path); break :blk; }, - .Quicksave => try self.quicksaveCmd(), + + // .Amp => blk: { + // const split = try cmd.intArgAt(0); + // const index = try cmd.intArgAt(1); + // const gain = try cmd.floatArgAt(2); + // try self.ampCmd(split, index, gain); + // } + else => blk: { std.debug.warn("Unknown command: {}\n", cmd.command); break :blk RunError.UnknownCommand;