make internal ports a slice of Port structs

This commit is contained in:
Luna 2019-08-14 22:35:22 -03:00
parent 1d86abff5b
commit cfec45eb6c
3 changed files with 9 additions and 10 deletions

View file

@ -285,7 +285,7 @@ pub const Image = struct {
idx, idx,
param.value, param.value,
); );
ports[idx].value = param.value; (&ports[idx]).value = param.value;
} }
// now we need to generate a temporary file and put the output of // now we need to generate a temporary file and put the output of

View file

@ -59,14 +59,14 @@ pub const Port = struct {
/// Setup ports for a given plugin. Gives an array to pointers of Port structs. /// Setup ports for a given plugin. Gives an array to pointers of Port structs.
/// This setup is required so we link the plugin to the ports later on, and /// This setup is required so we link the plugin to the ports later on, and
/// also link our buffers, and control values. /// also link our buffers, and control values.
pub fn setupPorts(ctx: *plugin.Context) ![]*Port { pub fn setupPorts(ctx: *plugin.Context) ![]Port {
var world = ctx.world; var world = ctx.world;
const n_ports: u32 = c.lilv_plugin_get_num_ports(ctx.plugin); const n_ports: u32 = c.lilv_plugin_get_num_ports(ctx.plugin);
var ports = try ctx.allocator.alloc(*Port, n_ports); var ports = try ctx.allocator.alloc(Port, n_ports);
for (ports) |port_ptr, idx| { for (ports) |_, idx| {
var port = try ctx.allocator.create(Port); var port: *Port = &ports[idx];
port.* = Port{ port.* = Port{
.lilv_port = null, .lilv_port = null,
.ptype = .Control, .ptype = .Control,
@ -75,8 +75,6 @@ pub fn setupPorts(ctx: *plugin.Context) ![]*Port {
.is_input = false, .is_input = false,
.optional = false, .optional = false,
}; };
ports[idx] = port;
} }
var values: []f32 = try ctx.allocator.alloc(f32, n_ports); var values: []f32 = try ctx.allocator.alloc(f32, n_ports);
@ -100,7 +98,7 @@ pub fn setupPorts(ctx: *plugin.Context) ![]*Port {
var i: u32 = 0; var i: u32 = 0;
while (i < n_ports) : (i += 1) { while (i < n_ports) : (i += 1) {
var port: *Port = ports[i]; var port: *Port = &ports[i];
const lport = c.lilv_plugin_get_port_by_index(ctx.plugin, i).?; const lport = c.lilv_plugin_get_port_by_index(ctx.plugin, i).?;

View file

@ -112,15 +112,16 @@ pub const RunContext = struct {
self.buffers.deinit(); self.buffers.deinit();
} }
pub fn connectPorts(self: *RunContext, ports: []*lv2.Port) void { pub fn connectPorts(self: *RunContext, ports: []lv2.Port) void {
var i: usize = 0; var i: usize = 0;
var o: usize = 0; var o: usize = 0;
var in_buf = self.buffers.in; var in_buf = self.buffers.in;
var out_buf = self.buffers.out; var out_buf = self.buffers.out;
for (ports) |port, p_idx| { for (ports) |_, p_idx| {
var p = @intCast(u32, p_idx); var p = @intCast(u32, p_idx);
var port: *lv2.Port = &ports[p_idx];
switch (port.ptype) { switch (port.ptype) {
.Control => lv2.lilv_instance_connect_port(self.instance, p, &port.value), .Control => lv2.lilv_instance_connect_port(self.instance, p, &port.value),