Compare commits
5 commits
9801e303c0
...
36937a5fde
Author | SHA1 | Date | |
---|---|---|---|
36937a5fde | |||
72379e63ee | |||
690ab89cfd | |||
30da41293a | |||
89afa8af10 |
4 changed files with 28 additions and 40 deletions
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
24
src/lang.zig
24
src/lang.zig
|
@ -178,13 +178,13 @@ pub const Command = struct {
|
|||
};
|
||||
|
||||
pub const Noise = CustomCommand(Tag.noise, custom.RandomNoise, struct {
|
||||
seed: f32,
|
||||
fill_bytes: f32,
|
||||
seed: u64,
|
||||
fill_bytes: usize,
|
||||
});
|
||||
|
||||
pub const Wildnoise = CustomCommand(Tag.wildnoise, custom.WildNoise, struct {
|
||||
seed: f32,
|
||||
fill_bytes: f32,
|
||||
seed: u64,
|
||||
fill_bytes: usize,
|
||||
});
|
||||
|
||||
pub const Write = CustomCommand(Tag.write, custom.Write, struct {
|
||||
|
@ -521,7 +521,7 @@ pub const Lang = struct {
|
|||
var cmd = try self.allocator.create(command_struct);
|
||||
const is_lv2_command = switch (command_struct.base_tag) {
|
||||
.noop, .load, .quicksave, .runqs, .rotate => false,
|
||||
else => command_struct.command_type == .lv2_command,
|
||||
else => true,
|
||||
};
|
||||
|
||||
// TODO: crash when no arguments are left but we still need
|
||||
|
@ -543,7 +543,6 @@ pub const Lang = struct {
|
|||
cmd.split = try std.fmt.parseInt(usize, split.?, 10);
|
||||
cmd.index = try std.fmt.parseInt(usize, index.?, 10);
|
||||
|
||||
// All parameters for LV2 plugins are f32.
|
||||
inline for (@typeInfo(@TypeOf(cmd.parameters)).Struct.fields) |cmd_field| {
|
||||
const maybe_arg = tok_it.next();
|
||||
if (maybe_arg == null) {
|
||||
|
@ -552,10 +551,15 @@ pub const Lang = struct {
|
|||
}
|
||||
|
||||
const arg = maybe_arg.?;
|
||||
if (cmd_field.field_type != f32)
|
||||
@compileError("LV2 parameter struct can only have f32 fields");
|
||||
const arg_value = switch (cmd_field.field_type) {
|
||||
f32 => try std.fmt.parseFloat(f32, arg),
|
||||
u64 => try std.fmt.parseInt(u64, arg, 10),
|
||||
usize => try std.fmt.parseInt(usize, arg, 10),
|
||||
[]const u8 => try self.allocator.dupe(u8, arg),
|
||||
else => @compileError("parameter struct has unsupported type " ++ @typeName(cmd_field.field_type)),
|
||||
};
|
||||
|
||||
@field(cmd.parameters, cmd_field.name) = try std.fmt.parseFloat(f32, arg);
|
||||
@field(cmd.parameters, cmd_field.name) = arg_value;
|
||||
}
|
||||
} else {
|
||||
inline for (@typeInfo(command_struct).Struct.fields) |cmd_field| {
|
||||
|
@ -570,7 +574,7 @@ pub const Lang = struct {
|
|||
i32 => try std.fmt.parseInt(i32, arg, 10),
|
||||
f32 => try std.fmt.parseFloat(f32, arg),
|
||||
[]const u8 => try self.allocator.dupe(u8, arg),
|
||||
else => @panic("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."),
|
||||
else => @compileError("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."),
|
||||
};
|
||||
|
||||
std.debug.warn("parsing {}, arg of type {} => {}\n", .{
|
||||
|
|
|
@ -230,18 +230,8 @@ pub const Runner = struct {
|
|||
.index = command.index,
|
||||
};
|
||||
|
||||
var params = ParamMap.init(self.allocator);
|
||||
defer params.deinit();
|
||||
|
||||
inline for (@typeInfo(@TypeOf(command.parameters)).Struct.fields) |cmd_field| {
|
||||
_ = try params.put(
|
||||
cmd_field.name,
|
||||
@field(command.parameters, cmd_field.name),
|
||||
);
|
||||
}
|
||||
|
||||
var image = try self.getImage();
|
||||
try image.runCustomPlugin(@TypeOf(command).plugin_type, pos, ¶ms);
|
||||
try image.runCustomPlugin(@TypeOf(command).plugin_type, pos, command.parameters);
|
||||
}
|
||||
|
||||
fn newRunCommandSingle(
|
||||
|
|
Loading…
Reference in a new issue