Compare commits
No commits in common. "e669b74ffb0b5444f2b77dc157c536bb524d5c8d" and "7543ecafaa38e4ef7ba8d063162cc48a35fa34ac" have entirely different histories.
e669b74ffb
...
7543ecafaa
1 changed files with 17 additions and 86 deletions
101
src/lang.zig
101
src/lang.zig
|
@ -31,23 +31,6 @@ fn LV2Command(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn CustomCommand(
|
|
||||||
comptime tag: Command.tag,
|
|
||||||
comptime plugin: type,
|
|
||||||
comptime parameters: type,
|
|
||||||
) type {
|
|
||||||
return struct {
|
|
||||||
pub const base_tag = tag;
|
|
||||||
pub const command_type = CommandType.plugin_command;
|
|
||||||
pub const plugin_type = plugin;
|
|
||||||
|
|
||||||
base: Command,
|
|
||||||
split: usize,
|
|
||||||
index: usize,
|
|
||||||
parameters: LV2Parameters,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const Command = struct {
|
pub const Command = struct {
|
||||||
tag: Tag,
|
tag: Tag,
|
||||||
|
|
||||||
|
@ -130,13 +113,6 @@ pub const Command = struct {
|
||||||
.saturator => Saturator,
|
.saturator => Saturator,
|
||||||
.vintagedelay => Vintagedelay,
|
.vintagedelay => Vintagedelay,
|
||||||
|
|
||||||
.noise => Noise,
|
|
||||||
.wildnoise => Wildnoise,
|
|
||||||
.write => Write,
|
|
||||||
.embed => Embed,
|
|
||||||
|
|
||||||
.rotate => Rotate,
|
|
||||||
|
|
||||||
else => @panic("TODO"),
|
else => @panic("TODO"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -170,37 +146,8 @@ pub const Command = struct {
|
||||||
|
|
||||||
pub const RunQS = struct {
|
pub const RunQS = struct {
|
||||||
pub const base_tag = Tag.runqs;
|
pub const base_tag = Tag.runqs;
|
||||||
base: Command,
|
|
||||||
program: []const u8,
|
program: []const u8,
|
||||||
};
|
|
||||||
|
|
||||||
pub const Noise = CustomCommand(Tag.noise, custom.RandomNoise, struct {
|
|
||||||
seed: f32,
|
|
||||||
fill_bytes: f32,
|
|
||||||
});
|
|
||||||
|
|
||||||
pub const Wildnoise = CustomCommand(Tag.wildnoise, custom.WildNoise, struct {
|
|
||||||
seed: f32,
|
|
||||||
fill_bytes: f32,
|
|
||||||
});
|
|
||||||
|
|
||||||
pub const Write = CustomCommand(Tag.write, custom.Write, struct {
|
|
||||||
data: f32,
|
|
||||||
});
|
|
||||||
|
|
||||||
pub const Embed = struct {
|
|
||||||
pub const base_tag = Tag.embed;
|
|
||||||
base: Command,
|
base: Command,
|
||||||
split: usize,
|
|
||||||
index: usize,
|
|
||||||
path: []const u8,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub const Rotate = struct {
|
|
||||||
pub const base_tag = Tag.rotate;
|
|
||||||
base: Command,
|
|
||||||
deg: f32,
|
|
||||||
bgfill: []const u8,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Amp = LV2Command(
|
pub const Amp = LV2Command(
|
||||||
|
@ -415,14 +362,9 @@ pub const Command = struct {
|
||||||
t4d: f32,
|
t4d: f32,
|
||||||
t4a_db: f32,
|
t4a_db: f32,
|
||||||
});
|
});
|
||||||
|
pub const Moddelay = LV2Command(.moddelay, "http://plugin.org.uk/swh-plugins/modDelay", struct {
|
||||||
pub const Moddelay = LV2Command(
|
|
||||||
.moddelay,
|
|
||||||
"http://plugin.org.uk/swh-plugins/modDelay",
|
|
||||||
struct {
|
|
||||||
base: f32,
|
base: f32,
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
pub const Multichorus = LV2Command(.multichorus, "http://calf.sourceforge.net/plugins/MultiChorus", struct {
|
pub const Multichorus = LV2Command(.multichorus, "http://calf.sourceforge.net/plugins/MultiChorus", struct {
|
||||||
min_delay: f32,
|
min_delay: f32,
|
||||||
|
@ -506,7 +448,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;
|
||||||
|
@ -529,34 +471,23 @@ pub const Lang = struct {
|
||||||
// arguments...
|
// arguments...
|
||||||
|
|
||||||
if (is_lv2_command) {
|
if (is_lv2_command) {
|
||||||
const split = tok_it.next();
|
cmd.split = try std.fmt.parseInt(usize, tok_it.next().?, 10);
|
||||||
if (split == null) {
|
cmd.index = try std.fmt.parseInt(usize, tok_it.next().?, 10);
|
||||||
self.doError("Expected split parameter, got EOL", .{});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const index = tok_it.next();
|
|
||||||
if (index == null) {
|
|
||||||
self.doError("Expected index parameter, got EOL", .{});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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| {
|
inline for (@typeInfo(@TypeOf(cmd.parameters)).Struct.fields) |cmd_field| {
|
||||||
const maybe_arg = tok_it.next();
|
const arg = tok_it.next().?;
|
||||||
if (maybe_arg == null) {
|
const argument_value = switch (cmd_field.field_type) {
|
||||||
self.doError("Expected parameter for {}, got nothing", .{cmd_field.name});
|
f32 => try std.fmt.parseFloat(f32, arg),
|
||||||
return;
|
else => @compileError("LV2 parameter struct can only have f32 fields"),
|
||||||
}
|
};
|
||||||
|
|
||||||
const arg = maybe_arg.?;
|
std.debug.warn("parsing {}, arg of type {} => {}\n", .{
|
||||||
if (cmd_field.field_type != f32)
|
@typeName(command_struct),
|
||||||
@compileError("LV2 parameter struct can only have f32 fields");
|
@typeName(@TypeOf(argument_value)),
|
||||||
|
argument_value,
|
||||||
|
});
|
||||||
|
|
||||||
@field(cmd.parameters, cmd_field.name) = try std.fmt.parseFloat(f32, arg);
|
@field(cmd.parameters, cmd_field.name) = argument_value;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
inline for (@typeInfo(command_struct).Struct.fields) |cmd_field| {
|
inline for (@typeInfo(command_struct).Struct.fields) |cmd_field| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue