convert from ParamMap to ducktyped param struct

This commit is contained in:
Luna 2020-05-31 22:27:11 -03:00
parent 9801e303c0
commit 89afa8af10
2 changed files with 13 additions and 19 deletions

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) {