add main command struct and make fillKeywords mostly-comptime

This commit is contained in:
Luna 2020-05-30 16:57:00 -03:00
parent e462b4e9d6
commit d86e9efe43

View file

@ -51,6 +51,37 @@ pub const CommandType = enum {
Rotate, Rotate,
}; };
pub const Type = enum {
/// "LV2 Commands" are commands that receive split, index, and then receive
/// any f64 arguments.
lv2_command,
};
pub const NewCommand = struct {
pub const Noop = struct {};
pub const Load = struct {
path: []const u8,
};
pub const Quicksave = struct {};
pub const RunQS = struct {
program: []const u8,
};
pub const Amp = struct {
pub const base_type = Type.lv2_command;
gain: f64
};
pub const RFlanger = struct {
pub const base_type = Type.lv2_command;
delay_depth_avg: f64,
law_freq: f64,
};
};
pub const Command = struct { pub const Command = struct {
command: CommandType, command: CommandType,
args: ArgList, args: ArgList,
@ -182,48 +213,18 @@ pub const Lang = struct {
} }
fn fillKeywords(self: *Lang) !void { fn fillKeywords(self: *Lang) !void {
_ = try self.keywords.put("noop", .Noop); inline for (@typeInfo(NewCommand).Struct.decls) |cmd_struct_decl| {
_ = try self.keywords.put("load", .Load); const struct_name = cmd_struct_decl.name;
_ = try self.keywords.put("quicksave", .Quicksave);
_ = try self.keywords.put("runqs", .RunQS);
_ = try self.keywords.put("amp", .Amp); comptime var lowered_command_name = [_]u8{0} ** struct_name.len;
_ = try self.keywords.put("rflanger", .RFlanger); comptime {
_ = try self.keywords.put("eq", .Eq); for (struct_name) |c, i| {
_ = try self.keywords.put("mbeq", .Mbeq); lowered_command_name[i] = std.ascii.toLower(c);
_ = try self.keywords.put("phaser", .Phaser); }
_ = try self.keywords.put("chorus", .Chorus); }
_ = try self.keywords.put("pitchscaler", .PitchScaler);
_ = try self.keywords.put("reverb", .Reverb);
_ = try self.keywords.put("highpass", .Highpass);
_ = try self.keywords.put("delay", .Delay);
_ = try self.keywords.put("vinyl", .Vinyl);
_ = try self.keywords.put("revdelay", .RevDelay);
_ = try self.keywords.put("gate", .Gate);
_ = try self.keywords.put("detune", .Detune);
_ = try self.keywords.put("overdrive", .Overdrive);
_ = try self.keywords.put("talkbox", .TalkBox);
_ = try self.keywords.put("thruzero", .ThruZero);
_ = try self.keywords.put("foverdrive", .Foverdrive);
_ = try self.keywords.put("gverb", .Gverb);
_ = try self.keywords.put("invert", .Invert);
_ = try self.keywords.put("tapedelay", .TapeDelay);
_ = try self.keywords.put("moddelay", .ModDelay);
_ = try self.keywords.put("multichorus", .MultiChorus);
_ = try self.keywords.put("saturator", .Saturator);
_ = try self.keywords.put("vintagedelay", .VintageDelay);
// custom implementations (not lv2) _ = try self.keywords.put(&lowered_command_name, @field(CommandType, struct_name));
_ = try self.keywords.put("noise", .Noise); }
_ = try self.keywords.put("wildnoise", .WildNoise);
_ = try self.keywords.put("write", .Write);
_ = try self.keywords.put("embed", .Embed);
_ = try self.keywords.put("degrade", .Degrade);
_ = try self.keywords.put("repsycho", .RePsycho);
_ = try self.keywords.put("dyncomp", .RePsycho);
// even more custom
_ = try self.keywords.put("rotate", .Rotate);
} }
pub fn getCommand(self: *Lang, stmt: []const u8) ?CommandType { pub fn getCommand(self: *Lang, stmt: []const u8) ?CommandType {