Use comptime for fully declarative LV2 and Custom commands #14
2 changed files with 14 additions and 15 deletions
18
src/lang.zig
18
src/lang.zig
|
@ -15,7 +15,7 @@ pub const CommandType = enum {
|
|||
};
|
||||
|
||||
fn LV2Command(
|
||||
comptime tag: NewCommand.Tag,
|
||||
comptime tag: Command.Tag,
|
||||
comptime plugin_url: []const u8,
|
||||
comptime LV2Parameters: type,
|
||||
) type {
|
||||
|
@ -24,14 +24,14 @@ fn LV2Command(
|
|||
pub const command_type = CommandType.lv2_command;
|
||||
pub const lv2_url = plugin_url;
|
||||
|
||||
base: NewCommand,
|
||||
base: Command,
|
||||
split: usize,
|
||||
index: usize,
|
||||
parameters: LV2Parameters,
|
||||
};
|
||||
}
|
||||
|
||||
pub const NewCommand = struct {
|
||||
pub const Command = struct {
|
||||
tag: Tag,
|
||||
|
||||
pub const Tag = enum {
|
||||
|
@ -130,24 +130,24 @@ pub const NewCommand = struct {
|
|||
|
||||
pub const Noop = struct {
|
||||
pub const base_tag = Tag.noop;
|
||||
base: NewCommand,
|
||||
base: Command,
|
||||
};
|
||||
|
||||
pub const Load = struct {
|
||||
pub const base_tag = Tag.load;
|
||||
base: NewCommand,
|
||||
base: Command,
|
||||
path: []const u8,
|
||||
};
|
||||
|
||||
pub const Quicksave = struct {
|
||||
pub const base_tag = Tag.quicksave;
|
||||
base: NewCommand,
|
||||
base: Command,
|
||||
};
|
||||
|
||||
pub const RunQS = struct {
|
||||
pub const base_tag = Tag.runqs;
|
||||
program: []const u8,
|
||||
base: NewCommand,
|
||||
base: Command,
|
||||
};
|
||||
|
||||
pub const Amp = LV2Command(
|
||||
|
@ -183,7 +183,7 @@ pub const NewCommand = struct {
|
|||
);
|
||||
};
|
||||
|
||||
pub const CommandList = std.ArrayList(*NewCommand);
|
||||
pub const CommandList = std.ArrayList(*Command);
|
||||
pub const ArgList = std.ArrayList([]const u8);
|
||||
|
||||
pub const KeywordMap = std.StringHashMap(CommandType);
|
||||
|
@ -306,7 +306,7 @@ pub const Lang = struct {
|
|||
|
||||
var found: bool = false;
|
||||
|
||||
inline for (@typeInfo(NewCommand).Struct.decls) |cmd_struct_decl| {
|
||||
inline for (@typeInfo(Command).Struct.decls) |cmd_struct_decl| {
|
||||
switch (cmd_struct_decl.data) {
|
||||
.Type => |typ| switch (@typeInfo(typ)) {
|
||||
.Struct => {},
|
||||
|
|
|
@ -398,10 +398,10 @@ pub const Runner = struct {
|
|||
|
||||
fn newRunCommandSingle(
|
||||
self: *@This(),
|
||||
cmd: lang.NewCommand,
|
||||
comptime tag: lang.NewCommand.Tag,
|
||||
cmd: lang.Command,
|
||||
comptime tag: lang.Command.Tag,
|
||||
) !void {
|
||||
comptime const typ = lang.NewCommand.tagToType(tag);
|
||||
comptime const typ = lang.Command.tagToType(tag);
|
||||
const command = cmd.cast(typ).?;
|
||||
inline for (@typeInfo(typ).Struct.decls) |decl| {
|
||||
comptime {
|
||||
|
@ -418,11 +418,10 @@ pub const Runner = struct {
|
|||
}
|
||||
}
|
||||
|
||||
fn newRunCommand(self: *@This(), cmd: lang.NewCommand) !void {
|
||||
// .load => try self.newRunCommandSingle(cmd, .load),
|
||||
fn newRunCommand(self: *@This(), cmd: lang.Command) !void {
|
||||
switch (cmd.tag) {
|
||||
.load => {
|
||||
const command = cmd.cast(lang.NewCommand.Load).?;
|
||||
const command = cmd.cast(lang.Command.Load).?;
|
||||
try self.loadCmd(command.path);
|
||||
},
|
||||
.quicksave => {
|
||||
|
|
Loading…
Reference in a new issue