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

View File

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