Compare commits

..

7 commits

7 changed files with 37 additions and 23 deletions

View file

@ -9,7 +9,8 @@ const RunBuffers = plugins.RunBuffers;
pub const RandomNoise = struct {
r: std.rand.DefaultPrng,
rand_buf: ?[]f32,
rand_buf: ?[]f32 = null,
allocator: ?*std.mem.Allocator = null,
cnt: usize = 0,
pub fn init(
@ -30,16 +31,22 @@ pub const RandomNoise = struct {
return RandomNoise{
.r = r,
.allocator = allocator,
.rand_buf = rand_buf,
};
} else {
return RandomNoise{
.r = r,
.rand_buf = null,
};
}
}
pub fn deinit(self: *RandomNoise) void {
if (self.allocator == null) return;
if (self.rand_buf == null) return;
self.allocator.?.free(self.rand_buf.?);
}
pub fn run(self: *RandomNoise, bufs: *RunBuffers) void {
if (self.rand_buf) |rand_buf| {
if (self.cnt >= rand_buf.len) self.cnt = 0;
@ -53,7 +60,8 @@ pub const RandomNoise = struct {
pub const WildNoise = struct {
r: std.rand.DefaultPrng,
rand_buf: ?[]f32,
rand_buf: ?[]f32 = null,
allocator: ?*std.mem.Allocator = null,
cnt: usize = 0,
pub fn init(
@ -79,11 +87,16 @@ pub const WildNoise = struct {
} else {
return WildNoise{
.r = r,
.rand_buf = null,
};
}
}
pub fn deinit(self: *WildNoise) void {
if (self.allocator == null) return;
if (self.rand_buf == null) return;
self.allocator.?.free(self.rand_buf.?);
}
pub fn run(self: *WildNoise, bufs: *RunBuffers) void {
if (self.rand_buf) |rand_buf| {
if (self.cnt >= rand_buf.len) self.cnt = 0;
@ -107,12 +120,13 @@ pub const Write = struct {
params: *plugins.ParamMap,
) Write {
const data = params.get("data").?;
return Write{
.data = data.value,
};
}
pub fn deinit(self: *Write) void {}
pub fn run(self: *Write, bufs: *RunBuffers) void {
bufs.out[0] = self.data;
}

View file

@ -69,6 +69,7 @@ fn sf_tell(file: *c.SNDFILE) i64 {
return -frames;
}
/// Caller owns the returned memory.
pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 {
const template_start = "/temp/temp_";
const template = "/tmp/temp_XXXXXXXXXXX";
@ -284,7 +285,7 @@ pub const Image = struct {
idx,
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
@ -375,6 +376,7 @@ pub const Image = struct {
}
var plugin = plugin_opt.?;
defer plugin.deinit();
// the code here is a copypaste of runPlugin() without the specific
// lilv things.

View file

@ -332,7 +332,7 @@ pub const Lang = struct {
stmt = std.mem.trimLeft(u8, stmt, "\n");
if (stmt.len == 0) continue;
if (stmt[0] == '#') continue;
if (std.mem.startsWith(u8, stmt, "#")) continue;
// TODO better tokenizer instead of just tokenize(" ");
var tok_it = std.mem.tokenize(stmt, " ");

View file

@ -59,14 +59,14 @@ pub const Port = struct {
/// 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
/// 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;
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| {
var port = try ctx.allocator.create(Port);
for (ports) |_, idx| {
var port: *Port = &ports[idx];
port.* = Port{
.lilv_port = null,
.ptype = .Control,
@ -75,8 +75,6 @@ pub fn setupPorts(ctx: *plugin.Context) ![]*Port {
.is_input = false,
.optional = false,
};
ports[idx] = port;
}
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;
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).?;

View file

@ -8,10 +8,7 @@ test "scritcher" {
}
pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.c_allocator);
defer arena.deinit();
const allocator = &arena.allocator;
const allocator = std.heap.direct_allocator;
var lang = langs.Lang.init(allocator);
defer lang.deinit();
@ -21,9 +18,7 @@ pub fn main() !void {
var args_it = std.process.args();
const exe_name = try (args_it.next(allocator) orelse @panic("expected exe name"));
// args[1] is the path to scri file
_ = try (args_it.next(allocator) orelse @panic("expected exe name"));
const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path"));
var file = try std.fs.File.openRead(scri_path);

View file

@ -112,15 +112,16 @@ pub const RunContext = struct {
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 o: usize = 0;
var in_buf = self.buffers.in;
var out_buf = self.buffers.out;
for (ports) |port, p_idx| {
for (ports) |_, p_idx| {
var p = @intCast(u32, p_idx);
var port: *lv2.Port = &ports[p_idx];
switch (port.ptype) {
.Control => lv2.lilv_instance_connect_port(self.instance, p, &port.value),
@ -141,6 +142,7 @@ pub const RunContext = struct {
pub fn makeContext(allocator: *std.mem.Allocator, plugin_uri: []const u8) !Context {
const cstr_plugin_uri = try std.cstr.addNullByte(allocator, plugin_uri);
defer allocator.free(cstr_plugin_uri);
var world: *c.LilvWorld = c.lilv_world_new().?;
errdefer c.lilv_world_free(world);

View file

@ -115,6 +115,7 @@ pub const Runner = struct {
"{}_g",
basename[0..period_idx],
);
defer self.allocator.free(starts_with);
var max: usize = 0;
@ -328,6 +329,8 @@ pub const Runner = struct {
.Mbeq => blk: {
const pos = try cmd.consumePosition();
const bands = try cmd.floatArgMany(self.allocator, 2, 15, f32(0));
defer self.allocator.free(bands);
try self.mbeqCmd(pos, bands);
},