add draft impl for ampCmd

This commit is contained in:
Luna 2019-07-08 22:40:52 -03:00
parent 276100c556
commit 176bbd446a
4 changed files with 58 additions and 2 deletions

View File

@ -1,3 +1,4 @@
load :0;
echo 3 0 1 0.2;
amp 10 1;
# echo 3 0 1 0.2;
quicksave;

View File

@ -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);

17
src/plugin.zig Normal file
View File

@ -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,
};

View File

@ -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;