From 8677e977ee4e10dd4baa01d65aa45816fd62e682 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 9 Jul 2019 23:04:05 -0300 Subject: [PATCH] add file "saving" to quicksave cmd --- examples/middle_echo.scri | 2 +- src/image.zig | 17 ++++++++++++++++- src/runner.zig | 12 ++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/examples/middle_echo.scri b/examples/middle_echo.scri index 45bc8d1..be4e7cf 100644 --- a/examples/middle_echo.scri +++ b/examples/middle_echo.scri @@ -1,4 +1,4 @@ load :0; -amp 3 1 10; +amp 3 1 20; # echo 3 0 1 0.2; quicksave; diff --git a/src/image.zig b/src/image.zig index 0b53d09..179ac45 100644 --- a/src/image.zig +++ b/src/image.zig @@ -109,9 +109,16 @@ fn mkSfInfo() c.SF_INFO { pub const Image = struct { allocator: *std.mem.Allocator, + + /// Pointer to the underlying libsndfile's SNDFILE struct. sndfile: *c.SNDFILE, + + /// The original image file path. path: []const u8, + /// Represents the current path being worked on. + curpath: []const u8, + /// Open a BMP file. pub fn open(allocator: *std.mem.Allocator, path: []const u8) !*Image { var in_fmt = mkSfInfo(); @@ -123,6 +130,7 @@ pub const Image = struct { .allocator = allocator, .sndfile = sndfile, .path = path, + .curpath = path, }; return image; @@ -251,6 +259,13 @@ pub const Image = struct { } } - _ = c.sf_close(out_file); + _ = c.sf_close(self.sndfile); + self.sndfile = out_file; + self.curpath = tmpnam; + } + + pub fn saveTo(self: *Image, out_path: []const u8) !void { + std.debug.warn("saved to '{}'\n", out_path); + try std.fs.copyFile(self.curpath, out_path); } }; diff --git a/src/runner.zig b/src/runner.zig index f704ea1..076bdbd 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -136,8 +136,16 @@ pub const Runner = struct { } } - const out_path = try std.fmt.allocPrint(self.allocator, "{}_g{}{}", starts_with, max + 1, extension); - std.debug.warn("out path: {}\n", out_path); + const out_path = try std.fmt.allocPrint( + self.allocator, + "{}/{}{}{}", + dirname, + starts_with, + max + 1, + extension, + ); + + try image.saveTo(out_path); } /// Run the http://lv2plug.in/plugins/eg-amp plugin over the file.