add lv2 parameter validation
This commit is contained in:
parent
8ce844ceed
commit
d9358ed794
1 changed files with 10 additions and 8 deletions
18
src/lang.zig
18
src/lang.zig
|
@ -453,7 +453,7 @@ pub const Lang = struct {
|
|||
self.line = 0;
|
||||
}
|
||||
fn doError(self: *Lang, comptime fmt: []const u8, args: var) void {
|
||||
std.debug.warn("error at line {}: ", .{self.line});
|
||||
std.debug.warn("ERROR! at line {}: ", .{self.line});
|
||||
std.debug.warn(fmt, args);
|
||||
std.debug.warn("\n", .{});
|
||||
self.has_error = true;
|
||||
|
@ -491,19 +491,21 @@ 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 arg = tok_it.next().?;
|
||||
const maybe_arg = tok_it.next();
|
||||
if (maybe_arg == null) {
|
||||
self.doError("Expected parameter for {}, got nothing", .{cmd_field.name});
|
||||
return;
|
||||
}
|
||||
|
||||
const arg = maybe_arg.?;
|
||||
|
||||
const argument_value = switch (cmd_field.field_type) {
|
||||
f32 => try std.fmt.parseFloat(f32, arg),
|
||||
else => @compileError("LV2 parameter struct can only have f32 fields"),
|
||||
};
|
||||
|
||||
std.debug.warn("parsing {}, arg of type {} => {}\n", .{
|
||||
@typeName(command_struct),
|
||||
@typeName(@TypeOf(argument_value)),
|
||||
argument_value,
|
||||
});
|
||||
|
||||
@field(cmd.parameters, cmd_field.name) = argument_value;
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue