fix some clones, finish list of commands for printer

This commit is contained in:
Luna 2019-09-10 22:00:07 -03:00
parent 84d582cfd1
commit 49cc7221b0
4 changed files with 34 additions and 8 deletions

View file

@ -152,7 +152,7 @@ pub const Image = struct {
var in_fmt = mkSfInfo();
// clone sndfile
var sndfile = try sopen(self.allocator, self.curpath, c.SFM_READ, &in_fmt);
var image = try allocator.create(Image);
var image = try self.allocator.create(Image);
std.debug.assert(in_fmt.frames > i64(0));
std.debug.assert(in_fmt.seekable == i32(1));

View file

@ -9,9 +9,8 @@ test "scritcher" {
}
fn wrapInCmdList(allocator: *std.mem.Allocator, cmd: langs.Command) !langs.CommandList {
var cmds = try langs.CommandList.init(allocator);
var cmds = langs.CommandList.init(allocator);
try cmds.append(cmd);
return cmds;
}
@ -33,7 +32,6 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
var loadargs = langs.ArgList.init(allocator);
defer loadargs.deinit();
try loadargs.append(":1");
var cmds = try wrapInCmdList(allocator, langs.Command{
@ -63,6 +61,12 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
// run the load command
try runner.runCommands(cmds, true);
var runqs_args = langs.ArgList.init(allocator);
defer runqs_args.deinit();
// TODO change the runqs command to something given in an env var
try runqs_args.append("ristretto");
while (true) {
lang.reset();
try stdout.print("> ");
@ -104,6 +108,11 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void {
var runner_clone = try runner.clone();
defer runner_clone.deinit();
try cmds_parsed.append(langs.Command{
.command = .RunQS,
.args = runqs_args,
});
try runner_clone.runCommands(cmds_parsed, true);
}
}

View file

@ -8,8 +8,24 @@ pub fn printList(list: langs.CommandList, stream: var) !void {
.Quicksave => "quicksave",
.RunQS => "runqs",
// TODO rest of commands
else => unreachable,
.Amp => "amp",
.RFlanger => "rflanger",
.Eq => "eq",
.Phaser => "phaser",
.Mbeq => "mbeq",
.Chorus => "chorus",
.PitchScaler => "pitchscaler",
.Reverb => "reverb",
.Highpass => "highpass",
.Delay => "delay",
.Vinyl => "vinyl",
.RevDelay => "revdelay",
.Noise => "noise",
.WildNoise => "wildnoise",
.Write => "write",
.Rotate => "rotate",
};
try stream.print("{}", command);

View file

@ -33,8 +33,9 @@ pub const Runner = struct {
}
}
pub fn clone(self: *Runner) *Runner {
return Runner{ .allocator = allocator, .image = try image.clone() };
pub fn clone(self: *Runner) !Runner {
var cloned_image = if (self.image) |image| try image.clone() else null;
return Runner{ .allocator = self.allocator, .image = cloned_image };
}
fn resolveArg(self: *Runner, load_path: []const u8) ![]const u8 {