fix ports, fix c-str for params

This commit is contained in:
Luna 2019-07-07 15:54:38 -03:00
parent bd00f61977
commit f222c5e34f

View file

@ -90,7 +90,7 @@ const PortType = enum {
/// Runtime port information. /// Runtime port information.
const Port = struct { const Port = struct {
lilv_port: *const c.LilvPort, lilv_port: ?*const c.LilvPort,
ptype: PortType, ptype: PortType,
index: u32, index: u32,
value: f32, value: f32,
@ -146,6 +146,20 @@ const LV2Apply = struct {
self.ports = try self.allocator.realloc(self.ports, n_ports); self.ports = try self.allocator.realloc(self.ports, n_ports);
for (self.ports) |port_ptr, idx| {
var port = try self.allocator.create(Port);
port.* = Port{
.lilv_port = null,
.ptype = .Control,
.index = f32(0),
.value = f32(0),
.is_input = false,
.optional = false,
};
self.ports[idx] = port;
}
var values: []f32 = try self.allocator.alloc(f32, n_ports); var values: []f32 = try self.allocator.alloc(f32, n_ports);
defer self.allocator.free(values); defer self.allocator.free(values);
@ -176,10 +190,12 @@ const LV2Apply = struct {
var i: u32 = 0; var i: u32 = 0;
while (i < n_ports) : (i += 1) { while (i < n_ports) : (i += 1) {
var port: *Port = self.ports[i]; var port: *Port = self.ports[i];
const lport = c.lilv_plugin_get_port_by_index(self.plugin, i).?; const lport = c.lilv_plugin_get_port_by_index(self.plugin, i).?;
port.lilv_port = lport; port.lilv_port = lport;
port.index = i; port.index = i;
if (std.math.isNan(values[i])) { if (std.math.isNan(values[i])) {
port.value = f32(0); port.value = f32(0);
} else { } else {
@ -387,13 +403,13 @@ pub fn main() !void {
var it = self.params.iterator(); var it = self.params.iterator();
while (it.next()) |param| { while (it.next()) |param| {
var sym = c.lilv_new_string(self.world, param.sym.ptr); var param_sym = try self.makeCStr(param.sym);
const port = c.lilv_plugin_get_port_by_symbol(self.plugin, sym); var sym = c.lilv_new_string(self.world, param_sym.ptr);
const port = c.lilv_plugin_get_port_by_symbol(self.plugin, sym).?;
c.lilv_node_free(sym); c.lilv_node_free(sym);
std.debug.warn("param control: set {} to {}\n", param.sym, param.value); var idx = c.lilv_port_get_index(self.plugin, port);
self.ports[idx].value = param.value;
self.ports[c.lilv_port_get_index(self.plugin, port)].value = param.value;
} }
var out_fmt = c.SF_INFO{ var out_fmt = c.SF_INFO{