Compare commits
7 commits
b0ddb35ae9
...
cfec45eb6c
Author | SHA1 | Date | |
---|---|---|---|
cfec45eb6c | |||
1d86abff5b | |||
a33db9f060 | |||
e142285a32 | |||
f8d8ed067d | |||
0ad1c88274 | |||
b66070c4e4 |
7 changed files with 37 additions and 23 deletions
|
@ -9,7 +9,8 @@ const RunBuffers = plugins.RunBuffers;
|
||||||
|
|
||||||
pub const RandomNoise = struct {
|
pub const RandomNoise = struct {
|
||||||
r: std.rand.DefaultPrng,
|
r: std.rand.DefaultPrng,
|
||||||
rand_buf: ?[]f32,
|
rand_buf: ?[]f32 = null,
|
||||||
|
allocator: ?*std.mem.Allocator = null,
|
||||||
cnt: usize = 0,
|
cnt: usize = 0,
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
|
@ -30,16 +31,22 @@ pub const RandomNoise = struct {
|
||||||
|
|
||||||
return RandomNoise{
|
return RandomNoise{
|
||||||
.r = r,
|
.r = r,
|
||||||
|
.allocator = allocator,
|
||||||
.rand_buf = rand_buf,
|
.rand_buf = rand_buf,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return RandomNoise{
|
return RandomNoise{
|
||||||
.r = r,
|
.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 {
|
pub fn run(self: *RandomNoise, bufs: *RunBuffers) void {
|
||||||
if (self.rand_buf) |rand_buf| {
|
if (self.rand_buf) |rand_buf| {
|
||||||
if (self.cnt >= rand_buf.len) self.cnt = 0;
|
if (self.cnt >= rand_buf.len) self.cnt = 0;
|
||||||
|
@ -53,7 +60,8 @@ pub const RandomNoise = struct {
|
||||||
|
|
||||||
pub const WildNoise = struct {
|
pub const WildNoise = struct {
|
||||||
r: std.rand.DefaultPrng,
|
r: std.rand.DefaultPrng,
|
||||||
rand_buf: ?[]f32,
|
rand_buf: ?[]f32 = null,
|
||||||
|
allocator: ?*std.mem.Allocator = null,
|
||||||
cnt: usize = 0,
|
cnt: usize = 0,
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
|
@ -79,11 +87,16 @@ pub const WildNoise = struct {
|
||||||
} else {
|
} else {
|
||||||
return WildNoise{
|
return WildNoise{
|
||||||
.r = r,
|
.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 {
|
pub fn run(self: *WildNoise, bufs: *RunBuffers) void {
|
||||||
if (self.rand_buf) |rand_buf| {
|
if (self.rand_buf) |rand_buf| {
|
||||||
if (self.cnt >= rand_buf.len) self.cnt = 0;
|
if (self.cnt >= rand_buf.len) self.cnt = 0;
|
||||||
|
@ -107,12 +120,13 @@ pub const Write = struct {
|
||||||
params: *plugins.ParamMap,
|
params: *plugins.ParamMap,
|
||||||
) Write {
|
) Write {
|
||||||
const data = params.get("data").?;
|
const data = params.get("data").?;
|
||||||
|
|
||||||
return Write{
|
return Write{
|
||||||
.data = data.value,
|
.data = data.value,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn deinit(self: *Write) void {}
|
||||||
|
|
||||||
pub fn run(self: *Write, bufs: *RunBuffers) void {
|
pub fn run(self: *Write, bufs: *RunBuffers) void {
|
||||||
bufs.out[0] = self.data;
|
bufs.out[0] = self.data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,7 @@ fn sf_tell(file: *c.SNDFILE) i64 {
|
||||||
return -frames;
|
return -frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Caller owns the returned memory.
|
||||||
pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 {
|
pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 {
|
||||||
const template_start = "/temp/temp_";
|
const template_start = "/temp/temp_";
|
||||||
const template = "/tmp/temp_XXXXXXXXXXX";
|
const template = "/tmp/temp_XXXXXXXXXXX";
|
||||||
|
@ -284,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
|
||||||
|
@ -375,6 +376,7 @@ pub const Image = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var plugin = plugin_opt.?;
|
var plugin = plugin_opt.?;
|
||||||
|
defer plugin.deinit();
|
||||||
|
|
||||||
// the code here is a copypaste of runPlugin() without the specific
|
// the code here is a copypaste of runPlugin() without the specific
|
||||||
// lilv things.
|
// lilv things.
|
||||||
|
|
|
@ -332,7 +332,7 @@ pub const Lang = struct {
|
||||||
stmt = std.mem.trimLeft(u8, stmt, "\n");
|
stmt = std.mem.trimLeft(u8, stmt, "\n");
|
||||||
|
|
||||||
if (stmt.len == 0) continue;
|
if (stmt.len == 0) continue;
|
||||||
if (stmt[0] == '#') continue;
|
if (std.mem.startsWith(u8, stmt, "#")) continue;
|
||||||
|
|
||||||
// TODO better tokenizer instead of just tokenize(" ");
|
// TODO better tokenizer instead of just tokenize(" ");
|
||||||
var tok_it = std.mem.tokenize(stmt, " ");
|
var tok_it = std.mem.tokenize(stmt, " ");
|
||||||
|
|
|
@ -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).?;
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,7 @@ test "scritcher" {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
var arena = std.heap.ArenaAllocator.init(std.heap.c_allocator);
|
const allocator = std.heap.direct_allocator;
|
||||||
defer arena.deinit();
|
|
||||||
|
|
||||||
const allocator = &arena.allocator;
|
|
||||||
|
|
||||||
var lang = langs.Lang.init(allocator);
|
var lang = langs.Lang.init(allocator);
|
||||||
defer lang.deinit();
|
defer lang.deinit();
|
||||||
|
@ -21,9 +18,7 @@ pub fn main() !void {
|
||||||
|
|
||||||
var args_it = std.process.args();
|
var args_it = std.process.args();
|
||||||
|
|
||||||
const exe_name = try (args_it.next(allocator) orelse @panic("expected exe name"));
|
_ = try (args_it.next(allocator) orelse @panic("expected exe name"));
|
||||||
|
|
||||||
// args[1] is the path to scri file
|
|
||||||
const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path"));
|
const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path"));
|
||||||
|
|
||||||
var file = try std.fs.File.openRead(scri_path);
|
var file = try std.fs.File.openRead(scri_path);
|
||||||
|
|
|
@ -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),
|
||||||
|
@ -141,6 +142,7 @@ pub const RunContext = struct {
|
||||||
|
|
||||||
pub fn makeContext(allocator: *std.mem.Allocator, plugin_uri: []const u8) !Context {
|
pub fn makeContext(allocator: *std.mem.Allocator, plugin_uri: []const u8) !Context {
|
||||||
const cstr_plugin_uri = try std.cstr.addNullByte(allocator, plugin_uri);
|
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().?;
|
var world: *c.LilvWorld = c.lilv_world_new().?;
|
||||||
errdefer c.lilv_world_free(world);
|
errdefer c.lilv_world_free(world);
|
||||||
|
|
|
@ -115,6 +115,7 @@ pub const Runner = struct {
|
||||||
"{}_g",
|
"{}_g",
|
||||||
basename[0..period_idx],
|
basename[0..period_idx],
|
||||||
);
|
);
|
||||||
|
defer self.allocator.free(starts_with);
|
||||||
|
|
||||||
var max: usize = 0;
|
var max: usize = 0;
|
||||||
|
|
||||||
|
@ -328,6 +329,8 @@ pub const Runner = struct {
|
||||||
.Mbeq => blk: {
|
.Mbeq => blk: {
|
||||||
const pos = try cmd.consumePosition();
|
const pos = try cmd.consumePosition();
|
||||||
const bands = try cmd.floatArgMany(self.allocator, 2, 15, f32(0));
|
const bands = try cmd.floatArgMany(self.allocator, 2, 15, f32(0));
|
||||||
|
defer self.allocator.free(bands);
|
||||||
|
|
||||||
try self.mbeqCmd(pos, bands);
|
try self.mbeqCmd(pos, bands);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue