Compare commits

...

5 commits

4 changed files with 79 additions and 29 deletions

View file

@ -159,7 +159,7 @@ pub const Command = struct {
pub const Load = struct {
pub const base_tag = Tag.load;
base: Command,
path: []const u8,
path: []u8,
};
pub const Quicksave = struct {
@ -566,6 +566,7 @@ pub const Lang = struct {
usize => try std.fmt.parseInt(usize, arg, 10),
i32 => try std.fmt.parseInt(i32, arg, 10),
f32 => try std.fmt.parseFloat(f32, arg),
[]u8 => try self.allocator.dupe(u8, arg),
[]const u8 => try self.allocator.dupe(u8, arg),
else => @compileError("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."),
};

View file

@ -57,13 +57,16 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
} else {
// if there isn't any commands on the file, we load our default
// 'load :0' command
var loadargs = langs.ArgList.init(allocator);
try loadargs.append(":0");
try cmds.append(langs.Command{
.command = .Load,
.args = loadargs,
});
// TODO: deliberate memleak here. we only allocate this
// command once, for the start of the file, so.
var load_cmd = try allocator.create(langs.Command.Load);
std.mem.copy(u8, load_cmd.path, ":0");
load_cmd.base.tag = langs.Command.Tag.load;
// taking address is fine, because load_cmd lives in the lifetime
// of the allocator.
try cmds.append(&load_cmd.base);
}
if (file_read_opt) |file_read| {
@ -185,8 +188,7 @@ pub fn main() !void {
const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path or 'repl'"));
if (std.mem.eql(u8, scri_path, "repl")) {
@panic("TODO bring repl back");
// return try doRepl(allocator, &args_it);
return try doRepl(allocator, &args_it);
}
var file = try std.fs.cwd().openFile(scri_path, .{});

View file

@ -1,12 +1,72 @@
const langs = @import("lang.zig");
pub fn printCommand(cmd: langs.Command, comptime tag: langs.Command.Tag) !void {
const CommandStruct = langs.Command.tagToType(tag);
const casted = cmd.cast(CommandStruct).?;
// TODO move this to Tag method?
const is_typed = switch (tag) {
.noop, .load, .quicksave, .runqs, .rotate => false,
else => true,
};
const ctype = typ.command_type;
switch (ctype) {
.lv2_command => try printLV2Command(casted),
.custom_command => try printCustomCommand(casted),
else => @panic("TODO support command type"),
}
}
pub fn printList(list: langs.CommandList, stream: var) !void {
for (list.items) |cmd| {
const command = @tagName(cmd.tag);
try stream.print("{}", .{command});
for (cmd.args.items) |arg| {
try stream.print(" {}", .{arg});
switch (cmd.tag) {
.load => {
const load = command.cast(langs.Command.Load).?;
try stream.print("{}", .{load.path});
},
.quicksave => {},
.rotate => {
const rotate = command.cast(langs.Command.Rotate).?;
try stream.print("{} {}", .{ rotate.deg, rotate.bgfill });
},
.amp => try printCommand(cmd, .amp),
.rflanger => try printCommand(cmd, .rflanger),
.eq => try printCommand(cmd, .eq),
.phaser => try printCommand(cmd, .phaser),
.mbeq => try printCommand(cmd, .mbeq),
.chorus => try printCommand(cmd, .chorus),
.pitchscaler => try printCommand(cmd, .pitchscaler),
.reverb => try printCommand(cmd, .reverb),
.highpass => try printCommand(cmd, .highpass),
.delay => try printCommand(cmd, .delay),
.vinyl => try printCommand(cmd, .vinyl),
.revdelay => try printCommand(cmd, .revdelay),
.gate => try printCommand(cmd, .gate),
.detune => try printCommand(cmd, .detune),
.overdrive => try printCommand(cmd, .overdrive),
.degrade => try printCommand(cmd, .degrade),
.repsycho => try printCommand(cmd, .repsycho),
.talkbox => try printCommand(cmd, .talkbox),
.dyncomp => try printCommand(cmd, .dyncomp),
.thruzero => try printCommand(cmd, .thruzero),
.foverdrive => try printCommand(cmd, .foverdrive),
.gverb => try printCommand(cmd, .gverb),
.invert => try printCommand(cmd, .invert),
.tapedelay => try printCommand(cmd, .tapedelay),
.moddelay => try printCommand(cmd, .moddelay),
.multichorus => try printCommand(cmd, .multichorus),
.saturator => try printCommand(cmd, .saturator),
.vintagedelay => try printCommand(cmd, .vintagedelay),
.noise => try printCommand(cmd, .noise),
.wildnoise => try printCommand(cmd, .wildnoise),
.write => try printCommand(cmd, .write),
.embed => try printCommand(cmd, .embed),
}
_ = try stream.write(";\n");

View file

@ -239,19 +239,11 @@ pub const Runner = struct {
) !void {
comptime const typ = lang.Command.tagToType(tag);
const command = cmd.cast(typ).?;
inline for (@typeInfo(typ).Struct.decls) |decl| {
comptime {
if (!std.mem.eql(u8, decl.name, "command_type")) {
continue;
}
}
const ctype = typ.command_type;
switch (ctype) {
.lv2_command => try self.executeLV2Command(command.*),
.custom_command => try self.executeCustomCommand(command.*),
else => @panic("TODO support command type"),
}
const ctype = typ.command_type;
switch (ctype) {
.lv2_command => try self.executeLV2Command(command.*),
.custom_command => try self.executeCustomCommand(command.*),
else => @panic("TODO support command type"),
}
}
@ -297,11 +289,6 @@ pub const Runner = struct {
.wildnoise => try self.runSingleCommand(cmd, .wildnoise),
.write => try self.runSingleCommand(cmd, .write),
.embed => try self.runSingleCommand(cmd, .embed),
else => {
std.debug.warn("TODO support {}\n", .{@tagName(cmd.tag)});
@panic("TODO support tag");
},
}
}
/// Run a list of commands.