add eq command

This commit is contained in:
Luna 2019-07-10 16:06:44 -03:00
parent c534721e88
commit 9a5d4f14e5
4 changed files with 50 additions and 2 deletions

4
examples/eq.scri Normal file
View file

@ -0,0 +1,4 @@
load :0;
eq 3 1 2 -0.3 0.7;
eq 10 3 3 -0.9 2;
quicksave;

View file

@ -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");
std.debug.warn("assert fail: symbol {} not found on port\n", param.sym);
return ImageError.InvalidSymbol;
};

View file

@ -1,5 +1,7 @@
const std = @import("std");
const plugin = @import("plugin.zig");
pub const ParseError = error{
NoCommandGiven,
UnknownCommand,
@ -9,9 +11,11 @@ pub const ParseError = error{
pub const CommandType = enum {
Noop,
Load,
Quicksave,
Amp,
RFlanger,
Quicksave,
Eq,
};
pub const Command = struct {
@ -38,6 +42,13 @@ 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);
@ -73,6 +84,7 @@ pub const Lang = struct {
_ = try self.keywords.put("amp", .Amp);
_ = try self.keywords.put("rflanger", .RFlanger);
_ = try self.keywords.put("eq", .Eq);
}
pub fn parse(self: *Lang, data: []const u8) !CommandList {

View file

@ -11,6 +11,10 @@ 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,
@ -189,6 +193,24 @@ 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(&params, "lo", lo);
try appendParam(&params, "mid", mid);
try appendParam(&params, "hi", high);
try image.runPlugin("http://plugin.org.uk/swh-plugins/dj_eq_mono", position, params);
}
fn runCommand(self: *Runner, cmd: *lang.Command) !void {
return switch (cmd.command) {
.Noop => {},
@ -215,6 +237,16 @@ 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);
},
else => blk: {
std.debug.warn("Unknown command: {}\n", cmd.command);
break :blk RunError.UnknownCommand;