fix cimport not doing deref
This commit is contained in:
parent
58aea2755e
commit
f7a16447f4
1 changed files with 63 additions and 27 deletions
86
src/main.zig
86
src/main.zig
|
@ -53,6 +53,30 @@ const Param = struct {
|
||||||
value: f32,
|
value: f32,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub fn lilv_instance_connect_port(
|
||||||
|
instance: [*c]c.LilvInstance,
|
||||||
|
port_index: u32,
|
||||||
|
data_location: ?*c_void,
|
||||||
|
) void {
|
||||||
|
instance.?.*.lv2_descriptor.?.*.connect_port.?(instance.?.*.lv2_handle, port_index, data_location);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn lilv_instance_activate(instance: [*c]c.LilvInstance) void {
|
||||||
|
if (instance.?.*.lv2_descriptor.?.*.activate != null) {
|
||||||
|
instance.?.*.lv2_descriptor.?.*.activate.?(instance.?.*.lv2_handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn lilv_instance_run(instance: [*c]c.LilvInstance, sample_count: u32) void {
|
||||||
|
instance.?.*.lv2_descriptor.?.*.run.?(instance.?.*.lv2_handle, sample_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn lilv_instance_deactivate(instance: [*c]c.LilvInstance) void {
|
||||||
|
if (instance.?.*.lv2_descriptor.?.*.deactivate != null) {
|
||||||
|
instance.?.*.lv2_descriptor.?.*.deactivate.?(instance.?.*.lv2_handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const ParamList = std.ArrayList(Param);
|
const ParamList = std.ArrayList(Param);
|
||||||
|
|
||||||
const PortType = enum {
|
const PortType = enum {
|
||||||
|
@ -74,14 +98,15 @@ const Port = struct {
|
||||||
const LV2Apply = struct {
|
const LV2Apply = struct {
|
||||||
allocator: *std.mem.Allocator,
|
allocator: *std.mem.Allocator,
|
||||||
|
|
||||||
world: *c.LilvWorld = undefined,
|
world: ?*c.LilvWorld = null,
|
||||||
plugin: *const c.LilvPlugin = undefined,
|
plugin: ?*const c.LilvPlugin = null,
|
||||||
instance: *c.LilvInstance = undefined,
|
instance: ?*c.LilvInstance = null,
|
||||||
in_path: []u8 = undefined,
|
|
||||||
out_path: []u8 = undefined,
|
|
||||||
|
|
||||||
in_file: *c.SNDFILE = undefined,
|
in_path: ?[]u8 = undefined,
|
||||||
out_file: *c.SNDFILE = undefined,
|
out_path: ?[]u8 = undefined,
|
||||||
|
|
||||||
|
in_file: ?*c.SNDFILE = null,
|
||||||
|
out_file: ?*c.SNDFILE = null,
|
||||||
|
|
||||||
n_params: u32,
|
n_params: u32,
|
||||||
|
|
||||||
|
@ -96,8 +121,12 @@ const LV2Apply = struct {
|
||||||
sclose(self.in_path, self.in_file);
|
sclose(self.in_path, self.in_file);
|
||||||
sclose(self.out_path, self.out_file);
|
sclose(self.out_path, self.out_file);
|
||||||
|
|
||||||
|
if (self.instance) |instance| {
|
||||||
c.lilv_instance_free(self.instance);
|
c.lilv_instance_free(self.instance);
|
||||||
|
}
|
||||||
|
if (self.world) |world| {
|
||||||
c.lilv_world_free(self.world);
|
c.lilv_world_free(self.world);
|
||||||
|
}
|
||||||
|
|
||||||
self.allocator.free(self.ports);
|
self.allocator.free(self.ports);
|
||||||
self.params.deinit();
|
self.params.deinit();
|
||||||
|
@ -172,7 +201,10 @@ const LV2Apply = struct {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fn sopen(path: []const u8, mode: i32, fmt: *c.SF_INFO) ?*c.SNDFILE {
|
fn sopen(path_opt: ?[]const u8, mode: i32, fmt: *c.SF_INFO) ?*c.SNDFILE {
|
||||||
|
if (path_opt == null) return null;
|
||||||
|
|
||||||
|
var path = path_opt.?;
|
||||||
var file = c.sf_open(path.ptr, mode, fmt);
|
var file = c.sf_open(path.ptr, mode, fmt);
|
||||||
const st: i32 = c.sf_error(file);
|
const st: i32 = c.sf_error(file);
|
||||||
|
|
||||||
|
@ -184,7 +216,12 @@ fn sopen(path: []const u8, mode: i32, fmt: *c.SF_INFO) ?*c.SNDFILE {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sclose(path: []const u8, file: *c.SNDFILE) void {
|
fn sclose(path_opt: ?[]const u8, file_opt: ?*c.SNDFILE) void {
|
||||||
|
if (path_opt == null) return;
|
||||||
|
if (file_opt == null) return;
|
||||||
|
var path = path_opt.?;
|
||||||
|
var file = file_opt.?;
|
||||||
|
|
||||||
var st: i32 = c.sf_close(file);
|
var st: i32 = c.sf_close(file);
|
||||||
if (st != 0) {
|
if (st != 0) {
|
||||||
std.debug.warn(
|
std.debug.warn(
|
||||||
|
@ -198,7 +235,9 @@ fn sclose(path: []const u8, file: *c.SNDFILE) void {
|
||||||
///Read a single frame from a file into an interleaved buffer.
|
///Read a single frame from a file into an interleaved buffer.
|
||||||
///If more channels are required than are available in the file, the remaining
|
///If more channels are required than are available in the file, the remaining
|
||||||
///channels are distributed in a round-robin fashion (LRLRL).
|
///channels are distributed in a round-robin fashion (LRLRL).
|
||||||
fn sread(file: *c.SNDFILE, file_chans: c_int, buf: []f32) bool {
|
fn sread(file_opt: ?*c.SNDFILE, file_chans: c_int, buf: []f32) bool {
|
||||||
|
var file = file_opt.?;
|
||||||
|
|
||||||
const n_read: c.sf_count_t = c.sf_readf_float(file, buf.ptr, 1);
|
const n_read: c.sf_count_t = c.sf_readf_float(file, buf.ptr, 1);
|
||||||
const buf_chans = @intCast(c_int, buf.len);
|
const buf_chans = @intCast(c_int, buf.len);
|
||||||
|
|
||||||
|
@ -221,17 +260,14 @@ fn print_version() !void {
|
||||||
fn print_usage() !void {
|
fn print_usage() !void {
|
||||||
const stdout_file = try std.io.getStdOut();
|
const stdout_file = try std.io.getStdOut();
|
||||||
try stdout_file.write("Usage: lv2apply [OPTION]... PLUGIN_URI\n");
|
try stdout_file.write("Usage: lv2apply [OPTION]... PLUGIN_URI\n");
|
||||||
try stdout_file.write(" -i IN_FILE Input file\n");
|
try stdout_file.write("\t-i IN_FILE Input file\n");
|
||||||
try stdout_file.write(" -o OUT_FILE Output file\n");
|
try stdout_file.write("\t-o OUT_FILE Output file\n");
|
||||||
try stdout_file.write(" -o OUT_FILE Output file\n");
|
try stdout_file.write("\t-c SYM VAL Control value\n");
|
||||||
try stdout_file.write("-c SYM VAL Control value\n");
|
try stdout_file.write("\t--help print help\n");
|
||||||
try stdout_file.write("--help print help\n");
|
try stdout_file.write("\t--version display version\n");
|
||||||
try stdout_file.write("--version display version\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
std.debug.warn("awoo.\n");
|
|
||||||
|
|
||||||
var arena = std.heap.ArenaAllocator.init(std.heap.c_allocator);
|
var arena = std.heap.ArenaAllocator.init(std.heap.c_allocator);
|
||||||
const allocator = &arena.allocator;
|
const allocator = &arena.allocator;
|
||||||
|
|
||||||
|
@ -388,17 +424,17 @@ pub fn main() !void {
|
||||||
var p = @intCast(u32, p_idx);
|
var p = @intCast(u32, p_idx);
|
||||||
|
|
||||||
if (ptype == .Control) {
|
if (ptype == .Control) {
|
||||||
c.lilv_instance_connect_port(self.instance, p, &port.value);
|
lilv_instance_connect_port(self.instance, p, &port.value);
|
||||||
} else if (ptype == .Audio) {
|
} else if (ptype == .Audio) {
|
||||||
if (port.is_input) {
|
if (port.is_input) {
|
||||||
c.lilv_instance_connect_port(self.instance, p, &in_buf[i]);
|
lilv_instance_connect_port(self.instance, p, &in_buf[i]);
|
||||||
i += 1;
|
i += 1;
|
||||||
} else {
|
} else {
|
||||||
c.lilv_instance_connect_port(self.instance, p, &in_buf[o]);
|
lilv_instance_connect_port(self.instance, p, &in_buf[o]);
|
||||||
o += 1;
|
o += 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.lilv_instance_connect_port(self.instance, p, null);
|
lilv_instance_connect_port(self.instance, p, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,7 +443,7 @@ pub fn main() !void {
|
||||||
// read/write from/to sndfile.
|
// read/write from/to sndfile.
|
||||||
std.debug.warn("almost there!\n");
|
std.debug.warn("almost there!\n");
|
||||||
|
|
||||||
c.lilv_instance_activate(self.instance);
|
lilv_instance_activate(self.instance);
|
||||||
|
|
||||||
const START = 2 * 44100;
|
const START = 2 * 44100;
|
||||||
// for the first START frames, copy from in to out
|
// for the first START frames, copy from in to out
|
||||||
|
@ -423,13 +459,13 @@ pub fn main() !void {
|
||||||
std.debug.warn("{} seeked frames\n", seeked);
|
std.debug.warn("{} seeked frames\n", seeked);
|
||||||
|
|
||||||
while (sread(self.in_file, in_fmt.channels, in_buf)) {
|
while (sread(self.in_file, in_fmt.channels, in_buf)) {
|
||||||
c.lilv_instance_run(self.instance, 1);
|
lilv_instance_run(self.instance, 1);
|
||||||
if (c.sf_writef_float(self.out_file, out_buf.ptr, 1) != 1) {
|
if (c.sf_writef_float(self.out_file, out_buf.ptr, 1) != 1) {
|
||||||
std.debug.warn("failed to write to output file\n");
|
std.debug.warn("failed to write to output file\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.lilv_instance_deactivate(self.instance);
|
lilv_instance_deactivate(self.instance);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue