add eq command
This commit is contained in:
parent
c534721e88
commit
9a5d4f14e5
4 changed files with 50 additions and 2 deletions
4
examples/eq.scri
Normal file
4
examples/eq.scri
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
load :0;
|
||||||
|
eq 3 1 2 -0.3 0.7;
|
||||||
|
eq 10 3 3 -0.9 2;
|
||||||
|
quicksave;
|
|
@ -187,7 +187,7 @@ pub const Image = struct {
|
||||||
|
|
||||||
var sym = c.lilv_new_string(ctx.world, sym_cstr.ptr);
|
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: {
|
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;
|
return ImageError.InvalidSymbol;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
14
src/lang.zig
14
src/lang.zig
|
@ -1,5 +1,7 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
|
const plugin = @import("plugin.zig");
|
||||||
|
|
||||||
pub const ParseError = error{
|
pub const ParseError = error{
|
||||||
NoCommandGiven,
|
NoCommandGiven,
|
||||||
UnknownCommand,
|
UnknownCommand,
|
||||||
|
@ -9,9 +11,11 @@ pub const ParseError = error{
|
||||||
pub const CommandType = enum {
|
pub const CommandType = enum {
|
||||||
Noop,
|
Noop,
|
||||||
Load,
|
Load,
|
||||||
|
Quicksave,
|
||||||
|
|
||||||
Amp,
|
Amp,
|
||||||
RFlanger,
|
RFlanger,
|
||||||
Quicksave,
|
Eq,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Command = struct {
|
pub const Command = struct {
|
||||||
|
@ -38,6 +42,13 @@ pub const Command = struct {
|
||||||
return try std.fmt.parseInt(usize, arg, 10);
|
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 {
|
pub fn intArgAt(self: *const Command, idx: usize) !i32 {
|
||||||
var arg = try self.argAt(idx);
|
var arg = try self.argAt(idx);
|
||||||
return try std.fmt.parseInt(i32, arg, 10);
|
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("amp", .Amp);
|
||||||
_ = try self.keywords.put("rflanger", .RFlanger);
|
_ = try self.keywords.put("rflanger", .RFlanger);
|
||||||
|
_ = try self.keywords.put("eq", .Eq);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(self: *Lang, data: []const u8) !CommandList {
|
pub fn parse(self: *Lang, data: []const u8) !CommandList {
|
||||||
|
|
|
@ -11,6 +11,10 @@ pub const RunError = error{
|
||||||
ImageRequired,
|
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 {
|
pub const Runner = struct {
|
||||||
allocator: *std.mem.Allocator,
|
allocator: *std.mem.Allocator,
|
||||||
image: ?*Image = null,
|
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(¶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 runCommand(self: *Runner, cmd: *lang.Command) !void {
|
fn runCommand(self: *Runner, cmd: *lang.Command) !void {
|
||||||
return switch (cmd.command) {
|
return switch (cmd.command) {
|
||||||
.Noop => {},
|
.Noop => {},
|
||||||
|
@ -215,6 +237,16 @@ pub const Runner = struct {
|
||||||
try self.rFlangerCmd(split, index, delay_depth_avg, law_freq);
|
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: {
|
else => blk: {
|
||||||
std.debug.warn("Unknown command: {}\n", cmd.command);
|
std.debug.warn("Unknown command: {}\n", cmd.command);
|
||||||
break :blk RunError.UnknownCommand;
|
break :blk RunError.UnknownCommand;
|
||||||
|
|
Loading…
Reference in a new issue