add lv2 parameter validation

This commit is contained in:
Luna 2020-05-31 21:25:25 -03:00
parent 8ce844ceed
commit d9358ed794

View file

@ -453,7 +453,7 @@ pub const Lang = struct {
self.line = 0; self.line = 0;
} }
fn doError(self: *Lang, comptime fmt: []const u8, args: var) void { 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(fmt, args);
std.debug.warn("\n", .{}); std.debug.warn("\n", .{});
self.has_error = true; self.has_error = true;
@ -491,19 +491,21 @@ 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 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) { const argument_value = switch (cmd_field.field_type) {
f32 => try std.fmt.parseFloat(f32, arg), f32 => try std.fmt.parseFloat(f32, arg),
else => @compileError("LV2 parameter struct can only have f32 fields"), 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; @field(cmd.parameters, cmd_field.name) = argument_value;
} }
} else { } else {