add setting of parameters to the ports

- fix ampCmd's param pass
This commit is contained in:
Luna 2019-07-09 13:55:52 -03:00
parent bbf34f1133
commit 05fe41d8b4
3 changed files with 38 additions and 17 deletions

View file

@ -1,12 +1,6 @@
const std = @import("std");
const lv2 = @import("lv2_helpers.zig");
const c = @cImport({
@cInclude("sndfile.h");
@cInclude("lilv/lilv.h");
@cInclude("lv2/core/lv2.h");
});
const c = lv2.c;
const plugins = @import("plugin.zig");
@ -14,6 +8,7 @@ pub const ImageError = error{
OpenFail,
InvalidPlugin,
UnknownPlugin,
InvalidSymbol,
};
/// Low level integration function with libsndfile.
@ -103,13 +98,41 @@ pub const Image = struct {
pos: plugins.Position,
params: plugins.ParamList,
) !void {
var context = try plugins.makeContext(self.allocator, plugin_uri);
std.debug.warn("world: {}\n", context.world);
std.debug.warn("plugin: {}\n", context.plugin);
var ctx = try plugins.makeContext(self.allocator, plugin_uri);
std.debug.warn("\tworld: {}\n", ctx.world);
std.debug.warn("\tplugin: {}\n", ctx.plugin);
var ports = try lv2.setupPorts(&context);
for (ports) |port| {
std.debug.warn("port: {}\n", port.*);
var ports = try lv2.setupPorts(&ctx);
if (ctx.n_audio_in != 1) {
std.debug.warn("plugin <{}> does not accept mono input.\n", plugin_uri);
return ImageError.InvalidPlugin;
}
// now, for each param for the plugin, we find its port, and set
// the value for the port there.
var it = params.iterator();
while (it.next()) |param| {
var sym_cstr = try std.cstr.addNullByte(self.allocator, param.sym);
defer self.allocator.free(sym_cstr);
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");
return ImageError.InvalidSymbol;
};
c.lilv_node_free(sym);
var idx = c.lilv_port_get_index(ctx.plugin, port);
std.debug.warn(
"sym={}, idx={} to val={}\n",
param.sym,
idx,
param.value,
);
ports[idx].value = param.value;
}
}
};

View file

@ -2,6 +2,7 @@ const std = @import("std");
const plugin = @import("plugin.zig");
pub const c = @cImport({
@cInclude("sndfile.h");
@cInclude("lilv/lilv.h");
@cInclude("lv2/core/lv2.h");
});

View file

@ -143,12 +143,9 @@ pub const Runner = struct {
/// Run the http://lv2plug.in/plugins/eg-amp plugin over the file.
fn ampCmd(self: *Runner, split: usize, index: usize, gain: f32) !void {
var image = try self.getImage();
var param = try self.allocator.create(plugin.Param);
defer self.allocator.destroy(param);
param.* = plugin.Param{ .sym = "gain", .value = gain };
var params = plugin.ParamList.init(self.allocator);
try params.append(plugin.Param{ .sym = "gain", .value = gain });
defer params.deinit();
try image.runPlugin(