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
1 changed files with 22 additions and 6 deletions

View File

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