Use comptime for fully declarative LV2 and Custom commands #14

Merged
luna merged 69 commits from declarative-commands into master 2020-06-02 21:37:47 +00:00
2 changed files with 13 additions and 19 deletions
Showing only changes of commit 89afa8af10 - Show all commits

View file

@ -16,15 +16,12 @@ pub const RandomNoise = struct {
pub fn init(
allocator: *std.mem.Allocator,
params: *plugins.ParamMap,
params: var,
) ?RandomNoise {
const seed = @floatToInt(u64, params.get("seed").?.value);
const fillbytes = @floatToInt(usize, params.get("fill_bytes").?.value);
var r = std.rand.DefaultPrng.init(params.seed);
var r = std.rand.DefaultPrng.init(seed);
if (fillbytes > 0) {
var rand_buf = allocator.alloc(f32, fillbytes) catch return null;
if (params.fill_bytes > 0) {
var rand_buf = allocator.alloc(f32, params.fill_bytes) catch return null;
for (rand_buf) |_, idx| {
rand_buf[idx] = r.random.float(f32);
@ -67,15 +64,12 @@ pub const WildNoise = struct {
pub fn init(
allocator: *std.mem.Allocator,
params: *plugins.ParamMap,
params: var,
) ?WildNoise {
const seed = @floatToInt(u64, params.get("seed").?.value);
const fillbytes = @floatToInt(usize, params.get("fill_bytes").?.value);
var r = std.rand.DefaultPrng.init(params.seed);
var r = std.rand.DefaultPrng.init(seed);
if (fillbytes > 0) {
var rand_buf = allocator.alloc(f32, fillbytes) catch return null;
if (params.fill_bytes > 0) {
var rand_buf = allocator.alloc(f32, params.fill_bytes) catch return null;
for (rand_buf) |_, idx| {
rand_buf[idx] = @intToFloat(f32, r.random.int(u1));
@ -118,10 +112,10 @@ pub const Write = struct {
pub fn init(
allocator: *std.mem.Allocator,
params: *plugins.ParamMap,
params: var,
) Write {
return Write{
.data = params.get("data").?.value,
.data = params.data,
};
}
@ -139,10 +133,10 @@ pub const Embed = struct {
sndfile: *c.SNDFILE = undefined,
buf: []f32 = undefined,
pub fn init(allocator: *std.mem.Allocator, params: *plugins.ParmaMap) @This() {
pub fn init(allocator: *std.mem.Allocator, params: var) @This() {
return Embed{
.allocator = allocator,
.filepath = params.get("path").?.value,
.filepath = params.path,
};
}

View file

@ -422,7 +422,7 @@ pub const Image = struct {
self: *Image,
comptime Plugin: type,
position: plugins.Position,
extra: *ParamMap,
extra: var,
) !void {
var plugin_opt: ?Plugin = Plugin.init(self.allocator, extra);
if (plugin_opt == null) {