Compare commits
No commits in common. "36937a5fdeee43e0b64e35059274f0b21e68a649" and "9801e303c0fbeaf8617a1cccd8b90f934c8777cd" have entirely different histories.
36937a5fde
...
9801e303c0
4 changed files with 40 additions and 28 deletions
|
@ -16,12 +16,15 @@ pub const RandomNoise = struct {
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
allocator: *std.mem.Allocator,
|
allocator: *std.mem.Allocator,
|
||||||
params: var,
|
params: *plugins.ParamMap,
|
||||||
) ?RandomNoise {
|
) ?RandomNoise {
|
||||||
var r = std.rand.DefaultPrng.init(params.seed);
|
const seed = @floatToInt(u64, params.get("seed").?.value);
|
||||||
|
const fillbytes = @floatToInt(usize, params.get("fill_bytes").?.value);
|
||||||
|
|
||||||
if (params.fill_bytes > 0) {
|
var r = std.rand.DefaultPrng.init(seed);
|
||||||
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);
|
||||||
|
@ -64,12 +67,15 @@ pub const WildNoise = struct {
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
allocator: *std.mem.Allocator,
|
allocator: *std.mem.Allocator,
|
||||||
params: var,
|
params: *plugins.ParamMap,
|
||||||
) ?WildNoise {
|
) ?WildNoise {
|
||||||
var r = std.rand.DefaultPrng.init(params.seed);
|
const seed = @floatToInt(u64, params.get("seed").?.value);
|
||||||
|
const fillbytes = @floatToInt(usize, params.get("fill_bytes").?.value);
|
||||||
|
|
||||||
if (params.fill_bytes > 0) {
|
var r = std.rand.DefaultPrng.init(seed);
|
||||||
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));
|
||||||
|
@ -112,10 +118,10 @@ pub const Write = struct {
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
allocator: *std.mem.Allocator,
|
allocator: *std.mem.Allocator,
|
||||||
params: var,
|
params: *plugins.ParamMap,
|
||||||
) Write {
|
) Write {
|
||||||
return Write{
|
return Write{
|
||||||
.data = params.data,
|
.data = params.get("data").?.value,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,10 +139,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: var) @This() {
|
pub fn init(allocator: *std.mem.Allocator, params: *plugins.ParmaMap) @This() {
|
||||||
return Embed{
|
return Embed{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.filepath = params.path,
|
.filepath = params.get("path").?.value,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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: var,
|
extra: *ParamMap,
|
||||||
) !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) {
|
||||||
|
|
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 {
|
pub const Noise = CustomCommand(Tag.noise, custom.RandomNoise, struct {
|
||||||
seed: u64,
|
seed: f32,
|
||||||
fill_bytes: usize,
|
fill_bytes: f32,
|
||||||
});
|
});
|
||||||
|
|
||||||
pub const Wildnoise = CustomCommand(Tag.wildnoise, custom.WildNoise, struct {
|
pub const Wildnoise = CustomCommand(Tag.wildnoise, custom.WildNoise, struct {
|
||||||
seed: u64,
|
seed: f32,
|
||||||
fill_bytes: usize,
|
fill_bytes: f32,
|
||||||
});
|
});
|
||||||
|
|
||||||
pub const Write = CustomCommand(Tag.write, custom.Write, struct {
|
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);
|
var cmd = try self.allocator.create(command_struct);
|
||||||
const is_lv2_command = switch (command_struct.base_tag) {
|
const is_lv2_command = switch (command_struct.base_tag) {
|
||||||
.noop, .load, .quicksave, .runqs, .rotate => false,
|
.noop, .load, .quicksave, .runqs, .rotate => false,
|
||||||
else => true,
|
else => command_struct.command_type == .lv2_command,
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: crash when no arguments are left but we still need
|
// TODO: crash when no arguments are left but we still need
|
||||||
|
@ -543,6 +543,7 @@ pub const Lang = struct {
|
||||||
cmd.split = try std.fmt.parseInt(usize, split.?, 10);
|
cmd.split = try std.fmt.parseInt(usize, split.?, 10);
|
||||||
cmd.index = try std.fmt.parseInt(usize, index.?, 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| {
|
inline for (@typeInfo(@TypeOf(cmd.parameters)).Struct.fields) |cmd_field| {
|
||||||
const maybe_arg = tok_it.next();
|
const maybe_arg = tok_it.next();
|
||||||
if (maybe_arg == null) {
|
if (maybe_arg == null) {
|
||||||
|
@ -551,15 +552,10 @@ pub const Lang = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
const arg = maybe_arg.?;
|
const arg = maybe_arg.?;
|
||||||
const arg_value = switch (cmd_field.field_type) {
|
if (cmd_field.field_type != f32)
|
||||||
f32 => try std.fmt.parseFloat(f32, arg),
|
@compileError("LV2 parameter struct can only have f32 fields");
|
||||||
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) = arg_value;
|
@field(cmd.parameters, cmd_field.name) = try std.fmt.parseFloat(f32, arg);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
inline for (@typeInfo(command_struct).Struct.fields) |cmd_field| {
|
inline for (@typeInfo(command_struct).Struct.fields) |cmd_field| {
|
||||||
|
@ -574,7 +570,7 @@ pub const Lang = struct {
|
||||||
i32 => try std.fmt.parseInt(i32, arg, 10),
|
i32 => try std.fmt.parseInt(i32, arg, 10),
|
||||||
f32 => try std.fmt.parseFloat(f32, arg),
|
f32 => try std.fmt.parseFloat(f32, arg),
|
||||||
[]const u8 => try self.allocator.dupe(u8, arg),
|
[]const u8 => try self.allocator.dupe(u8, arg),
|
||||||
else => @compileError("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."),
|
else => @panic("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."),
|
||||||
};
|
};
|
||||||
|
|
||||||
std.debug.warn("parsing {}, arg of type {} => {}\n", .{
|
std.debug.warn("parsing {}, arg of type {} => {}\n", .{
|
||||||
|
|
|
@ -230,8 +230,18 @@ pub const Runner = struct {
|
||||||
.index = command.index,
|
.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();
|
var image = try self.getImage();
|
||||||
try image.runCustomPlugin(@TypeOf(command).plugin_type, pos, command.parameters);
|
try image.runCustomPlugin(@TypeOf(command).plugin_type, pos, ¶ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn newRunCommandSingle(
|
fn newRunCommandSingle(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue