From f2db15b9116ac036a3b167aa674b33f3956665ce Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 3 Sep 2019 12:30:49 -0300 Subject: [PATCH 001/182] comment out uneeded bug reproduction instructions --- src/lang.zig | 14 +++++++------- src/main.zig | 9 +++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 7c66fa4..26ed175 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -360,15 +360,15 @@ pub const Lang = struct { // construct final Command based on command var cmd_ptr = try self.allocator.create(Command); - errdefer self.allocator.destroy(cmd_ptr); + //errdefer self.allocator.destroy(cmd_ptr); - cmd_ptr.* = Command{ .command = ctype, .args = args }; - self.validateCommand(cmd_ptr) catch |err| { - self.doError("Unknown command '{}' (length {})", command, command.len); - continue; - }; + //cmd_ptr.* = Command{ .command = ctype, .args = args }; + //self.validateCommand(cmd_ptr) catch |err| { + // self.doError("Unknown command '{}' (length {})", command, command.len); + // continue; + //}; - try cmds.append(cmd_ptr); + //try cmds.append(cmd_ptr); } if (self.has_error) return ParseError.ParseFail; diff --git a/src/main.zig b/src/main.zig index 156855e..d5cd92d 100644 --- a/src/main.zig +++ b/src/main.zig @@ -13,9 +13,6 @@ pub fn main() !void { var lang = langs.Lang.init(allocator); defer lang.deinit(); - var runner = runners.Runner.init(allocator); - defer runner.deinit(); - var args_it = std.process.args(); _ = try (args_it.next(allocator) orelse @panic("expected exe name")); @@ -34,5 +31,9 @@ pub fn main() !void { var cmds = try lang.parse(data); defer cmds.deinit(); - try runner.runCommands(cmds, true); + // not needed for bug reproduction + //var runner = runners.Runner.init(allocator); + //defer runner.deinit(); + + //try runner.runCommands(cmds, true); } From b3bb56279a9dbd72592ee974d128ae440c0cbb8c Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 3 Sep 2019 12:45:17 -0300 Subject: [PATCH 002/182] remove usage of command pointers for most things this serves as a workaround for the compiler bugs found on zig trunk - use std.StringHashMap --- src/lang.zig | 51 +++++++++++++++++++++++--------------------------- src/plugin.zig | 2 +- src/runner.zig | 9 ++++++--- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 7c66fa4..3af632c 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -41,11 +41,11 @@ pub const Command = struct { args: ArgList, cur_idx: usize = 0, - pub fn print(self: *const Command) void { + pub fn print(self: Command) void { std.debug.warn("cmd:{}\n", self.command); } - pub fn argAt(self: *const Command, idx: usize) ![]const u8 { + pub fn argAt(self: Command, idx: usize) ![]const u8 { const args = self.args.toSliceConst(); if (idx > (args.len - 1)) { @@ -56,7 +56,7 @@ pub const Command = struct { return args[idx]; } - pub fn usizeArgAt(self: *const Command, idx: usize) !usize { + pub fn usizeArgAt(self: Command, idx: usize) !usize { var arg = try self.argAt(idx); return try std.fmt.parseInt(usize, arg, 10); } @@ -69,18 +69,18 @@ pub const Command = struct { }; } - pub fn intArgAt(self: *const Command, idx: usize) !i32 { + pub fn intArgAt(self: Command, idx: usize) !i32 { var arg = try self.argAt(idx); return try std.fmt.parseInt(i32, arg, 10); } - pub fn floatArgAt(self: *const Command, idx: usize) !f32 { + pub fn floatArgAt(self: Command, idx: usize) !f32 { var arg = try self.argAt(idx); return try std.fmt.parseFloat(f32, arg); } pub fn floatArgMany( - self: *const Command, + self: Command, allocator: *std.mem.Allocator, start_index: usize, elements: usize, @@ -124,25 +124,23 @@ pub const Command = struct { self.cur_idx += 1; _ = try map.put(symbol, val); } + + pub fn copy(self: Command, allocator: *std.mem.Allocator) !*Command { + var cmd = try allocator.create(Command); + cmd.* = Command{ + .command = self.command, + .args = self.args, + .cur_idx = self.cur_idx, + }; + + return cmd; + } }; -pub const CommandList = std.ArrayList(*Command); +pub const CommandList = std.ArrayList(Command); pub const ArgList = std.ArrayList([]const u8); -fn eqlu8(a: []const u8, b: []const u8) bool { - return std.mem.eql(u8, a, b); -} - -fn hashu8(key: []const u8) u32 { - var hasher = std.hash.Wyhash.init(0); - for (key) |value| { - std.hash.autoHash(&hasher, value); - } - - return @truncate(u32, hasher.final()); -} - -pub const KeywordMap = std.HashMap([]const u8, CommandType, hashu8, eqlu8); +pub const KeywordMap = std.StringHashMap(CommandType); pub const Lang = struct { allocator: *std.mem.Allocator, @@ -290,7 +288,7 @@ pub const Lang = struct { } } - fn validateCommand(self: *Lang, cmd: *Command) !void { + fn validateCommand(self: *Lang, cmd: Command) !void { switch (cmd.command) { .Quicksave, .Noop => {}, .Load, .RunQS => try self.expectSingle(cmd.args), @@ -359,16 +357,13 @@ pub const Lang = struct { } // construct final Command based on command - var cmd_ptr = try self.allocator.create(Command); - errdefer self.allocator.destroy(cmd_ptr); - - cmd_ptr.* = Command{ .command = ctype, .args = args }; - self.validateCommand(cmd_ptr) catch |err| { + var cmd = Command{ .command = ctype, .args = args }; + self.validateCommand(cmd) catch |err| { self.doError("Unknown command '{}' (length {})", command, command.len); continue; }; - try cmds.append(cmd_ptr); + try cmds.append(cmd); } if (self.has_error) return ParseError.ParseFail; diff --git a/src/plugin.zig b/src/plugin.zig index daf8023..03b72cc 100644 --- a/src/plugin.zig +++ b/src/plugin.zig @@ -16,7 +16,7 @@ pub const Param = struct { /// List of parameters to be set to control ports. pub const ParamList = std.ArrayList(Param); -pub const ParamMap = std.AutoHashMap([]const u8, f32); +pub const ParamMap = std.StringHashMap(f32); /// Represents an absolute position in the image. pub const SeekPos = struct { diff --git a/src/runner.zig b/src/runner.zig index 625c1f1..a348f22 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -464,10 +464,13 @@ pub const Runner = struct { cmds: lang.CommandList, debug_flag: bool, ) !void { - var it = cmds.iterator(); + for (cmds.toSlice()) |const_cmd| { + if (debug_flag) const_cmd.print(); + + // copy the command so we own its memory + var cmd = try const_cmd.copy(self.allocator); + defer self.allocator.destroy(cmd); - while (it.next()) |cmd| { - if (debug_flag) cmd.print(); try self.runCommand(cmd); } } From 7e8023a383ea7a3aced344a4e7aa40ba65f5cfc9 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 8 Sep 2019 11:55:17 -0300 Subject: [PATCH 003/182] add validation of bmp magic bytes --- src/bmp_valid.zig | 26 ++++++++++++++++++++++++++ src/image.zig | 19 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/bmp_valid.zig diff --git a/src/bmp_valid.zig b/src/bmp_valid.zig new file mode 100644 index 0000000..81c6759 --- /dev/null +++ b/src/bmp_valid.zig @@ -0,0 +1,26 @@ +const std = @import("std"); + +pub const BMPValidError = error{InvalidMagic}; + +const VALID_MAGICS = [_][]const u8{ + "BM", + "BA", + + "CI", + "CP", + "IC", + "PT", +}; + +pub fn magicValid(magic: []const u8) !void { + var valid = false; + + for (VALID_MAGICS) |valid_magic| { + if (std.mem.eql(u8, magic, valid_magic)) valid = true; + } + + if (!valid) { + std.debug.warn("\tINVALID HEADER: '{}'\n", magic); + return BMPValidError.InvalidMagic; + } +} diff --git a/src/image.zig b/src/image.zig index 16e682f..3e38903 100644 --- a/src/image.zig +++ b/src/image.zig @@ -2,6 +2,7 @@ const std = @import("std"); const lv2 = @import("lv2_helpers.zig"); const c = lv2.c; const custom = @import("custom.zig"); +const bmp = @import("bmp_valid.zig"); const plugins = @import("plugin.zig"); @@ -235,6 +236,22 @@ pub const Image = struct { std.debug.warn("\timage: reopened on '{}'\n", self.curpath); } + pub fn checkValid(self: *Image) !void { + var file = try std.fs.File.openRead(self.path); + defer file.close(); + + // main bmp header: + // 2 bytes for magic header + // 4 bytes for size in bytes + // 2 bytes ? + // 2 bytes ? + // 4 bytes for pixel array offset + var magic = [2]u8{ 0, 0 }; + _ = try file.read(&magic); + + try bmp.magicValid(&magic); + } + /// Run a plugin over the image. /// This setups a new lilv world/plugin among other things. /// The internal SNDFILE pointer is modified to point to the output of the @@ -354,6 +371,7 @@ pub const Image = struct { _ = c.sf_close(self.sndfile); try self.reopen(tmpnam); + try self.checkValid(); var time_taken = timer.read(); std.debug.warn("\ttook {d:.2}ms running plugin\n", time_taken / std.time.millisecond); @@ -441,5 +459,6 @@ pub const Image = struct { // reopen the file as SFM_READ so we can run plugin chains etc try self.reopen(tmpnam); + try self.checkValid(); } }; From fc8dcf4583a42716e904f5c89e083b6ffceac78e Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 8 Sep 2019 17:06:19 -0300 Subject: [PATCH 004/182] add doRepl func --- src/main.zig | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/main.zig b/src/main.zig index 156855e..4211446 100644 --- a/src/main.zig +++ b/src/main.zig @@ -7,6 +7,29 @@ test "scritcher" { _ = @import("runner.zig"); } +pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { + const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path")); + + // the thing here is that 'load :0' would load the scri_path, since we + // now have a 'repl' argument right before it. to counteract that, the + // initial repl buffer contains 'load :1' instead. + + var buf = langs.CommandList.init(allocator); + defer buf.deinit(); + + var loadargs = langs.ArgList.init(allocator); + defer loadargs.deinit(); + + try loadargs.append(":1"); + + try buf.append(langs.Command{ + .command = .Load, + .args = loadargs, + }); + + // TODO the rest +} + pub fn main() !void { const allocator = std.heap.direct_allocator; @@ -18,9 +41,15 @@ pub fn main() !void { var args_it = std.process.args(); + // TODO print help + _ = try (args_it.next(allocator) orelse @panic("expected exe name")); const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path")); + if (std.mem.eql(u8, scri_path, "repl")) { + return try doRepl(allocator, &args_it); + } + var file = try std.fs.File.openRead(scri_path); defer file.close(); From 34d3b12c56a6d49a9cd30e344769af2c6e5f0d7a Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 8 Sep 2019 17:27:59 -0300 Subject: [PATCH 005/182] add basic main loop --- src/main.zig | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main.zig b/src/main.zig index 4211446..fe3ce9a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -14,20 +14,35 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { // now have a 'repl' argument right before it. to counteract that, the // initial repl buffer contains 'load :1' instead. - var buf = langs.CommandList.init(allocator); - defer buf.deinit(); + var cmds = langs.CommandList.init(allocator); + defer cmds.deinit(); var loadargs = langs.ArgList.init(allocator); defer loadargs.deinit(); try loadargs.append(":1"); - try buf.append(langs.Command{ + try cmds.append(langs.Command{ .command = .Load, .args = loadargs, }); - // TODO the rest + // TODO start a runner and keep it hot + + while (true) { + try stdout.print("> "); + + var buffer = try std.Buffer.init(allocator, ""[0..]); + var line = std.io.readLine(&buffer) catch |err| { + if (err == error.EndOfStream) return; + return err; + }; + + // TODO parse the line through langs.parse, then add the command to cmds + + // TODO save the line to scri_file? or should we have a special `push` + // to do so? + } } pub fn main() !void { From 736277db049fdffb6f8d3eddfde1bcd4c77fbc48 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 8 Sep 2019 23:28:09 -0300 Subject: [PATCH 006/182] add parsing of given repl line --- src/lang.zig | 12 +++++------- src/main.zig | 12 +++++++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 3af632c..fe31d11 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -3,10 +3,8 @@ const std = @import("std"); const plugin = @import("plugin.zig"); pub const ParseError = error{ - NoCommandGiven, - UnknownCommand, + OutOfMemory, ArgRequired, - FloatParseFail, ParseFail, }; @@ -261,7 +259,7 @@ pub const Lang = struct { fn expectAny(self: *Lang, count: usize, args: ArgList) !void { if (args.len != count) { - std.debug.warn("expected {} arguments, found {}\n", count, args.len); + self.doError("expected {} arguments, found {}", count, args.len); return error.ArgRequired; } } @@ -274,7 +272,7 @@ pub const Lang = struct { var i: usize = 0; if (args.len != count) { - std.debug.warn("expected {} arguments, found {}\n", count, args.len); + self.doError("expected {} arguments, found {}", count, args.len); return error.ArgRequired; } @@ -319,7 +317,7 @@ pub const Lang = struct { self.has_error = true; } - pub fn parse(self: *Lang, data: []const u8) !CommandList { + pub fn parse(self: *Lang, data: []const u8) ParseError!CommandList { var splitted_it = std.mem.separate(data, ";"); try self.fillKeywords(); var cmds = CommandList.init(self.allocator); @@ -359,7 +357,7 @@ pub const Lang = struct { // construct final Command based on command var cmd = Command{ .command = ctype, .args = args }; self.validateCommand(cmd) catch |err| { - self.doError("Unknown command '{}' (length {})", command, command.len); + //self.doError("error validating command '{}': {}", command, err); continue; }; diff --git a/src/main.zig b/src/main.zig index fe3ce9a..1ac9680 100644 --- a/src/main.zig +++ b/src/main.zig @@ -8,6 +8,9 @@ test "scritcher" { } pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { + var stdout_file = try std.io.getStdOut(); + const stdout = &stdout_file.outStream().stream; + const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path")); // the thing here is that 'load :0' would load the scri_path, since we @@ -29,6 +32,9 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { // TODO start a runner and keep it hot + var lang = langs.Lang.init(allocator); + defer lang.deinit(); + while (true) { try stdout.print("> "); @@ -38,7 +44,11 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { return err; }; - // TODO parse the line through langs.parse, then add the command to cmds + var cmds_parsed = lang.parse(line) catch |err| { + std.debug.warn("repl: error while parsing: {}\n", err); + continue; + }; + try cmds.append(cmds_parsed.at(0)); // TODO save the line to scri_file? or should we have a special `push` // to do so? From 8b67ccc1bfc0944720d3ffc0cc583658f1c07a04 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 10 Sep 2019 11:45:04 -0300 Subject: [PATCH 007/182] add printing of commands to any stream --- src/main.zig | 4 ++++ src/printer.zig | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/printer.zig diff --git a/src/main.zig b/src/main.zig index 1ac9680..5c414a8 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,6 +1,7 @@ const std = @import("std"); const langs = @import("lang.zig"); const runners = @import("runner.zig"); +const printer = @import("printer.zig"); test "scritcher" { _ = @import("lang.zig"); @@ -52,6 +53,9 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { // TODO save the line to scri_file? or should we have a special `push` // to do so? + + // note this is debug + try printer.printList(cmds, stdout); } } diff --git a/src/printer.zig b/src/printer.zig new file mode 100644 index 0000000..29aeb9b --- /dev/null +++ b/src/printer.zig @@ -0,0 +1,23 @@ +const langs = @import("lang.zig"); + +pub fn printList(list: langs.CommandList, stream: var) !void { + for (list.toSlice()) |cmd| { + var command = switch (cmd.command) { + .Noop => "noop", + .Load => "load", + .Quicksave => "quicksave", + .RunQS => "runqs", + + // TODO rest of commands + else => unreachable, + }; + + try stream.print("{}", command); + + for (cmd.args.toSlice()) |arg| { + try stream.print(" {}", arg); + } + + try stream.write(";\n"); + } +} From c90590e3b53f4953569dec8a128a02f4cd7c31b7 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 10 Sep 2019 12:12:10 -0300 Subject: [PATCH 008/182] add Lang.reset, open scri_file and write current commands to it --- src/lang.zig | 5 +++++ src/main.zig | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index fe31d11..9724dfb 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -158,6 +158,11 @@ pub const Lang = struct { self.keywords.deinit(); } + pub fn reset(self: *Lang) void { + self.has_error = false; + self.line = 0; + } + fn fillKeywords(self: *Lang) !void { _ = try self.keywords.put("noop", .Noop); _ = try self.keywords.put("load", .Load); diff --git a/src/main.zig b/src/main.zig index 5c414a8..c0af701 100644 --- a/src/main.zig +++ b/src/main.zig @@ -14,6 +14,12 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path")); + var file = try std.fs.File.openWrite(scri_path); + defer file.close(); + + var out = file.outStream(); + var stream = &out.stream; + // the thing here is that 'load :0' would load the scri_path, since we // now have a 'repl' argument right before it. to counteract that, the // initial repl buffer contains 'load :1' instead. @@ -41,7 +47,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { var buffer = try std.Buffer.init(allocator, ""[0..]); var line = std.io.readLine(&buffer) catch |err| { - if (err == error.EndOfStream) return; + if (err == error.EndOfStream) break; return err; }; @@ -51,11 +57,13 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { }; try cmds.append(cmds_parsed.at(0)); + lang.reset(); + // TODO save the line to scri_file? or should we have a special `push` // to do so? - // note this is debug - try printer.printList(cmds, stdout); + try file.seekTo(0); + try printer.printList(cmds, stream); } } From 058bf8deb90c21c3d318df79af173a2b527de439 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 10 Sep 2019 14:51:41 -0300 Subject: [PATCH 009/182] add push and list commands --- src/main.zig | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main.zig b/src/main.zig index c0af701..1c7acaf 100644 --- a/src/main.zig +++ b/src/main.zig @@ -43,6 +43,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { defer lang.deinit(); while (true) { + lang.reset(); try stdout.print("> "); var buffer = try std.Buffer.init(allocator, ""[0..]); @@ -51,19 +52,20 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { return err; }; + if (std.mem.eql(u8, line, "push")) { + try file.seekTo(0); + try printer.printList(cmds, stream); + continue; + } else if (std.mem.eql(u8, line, "list")) { + try printer.printList(cmds, stream); + continue; + } + var cmds_parsed = lang.parse(line) catch |err| { std.debug.warn("repl: error while parsing: {}\n", err); continue; }; try cmds.append(cmds_parsed.at(0)); - - lang.reset(); - - // TODO save the line to scri_file? or should we have a special `push` - // to do so? - - try file.seekTo(0); - try printer.printList(cmds, stream); } } From 88a73e64d81910a7ffb10c5be45f218041b18978 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 10 Sep 2019 15:44:10 -0300 Subject: [PATCH 010/182] better repl logic --- src/main.zig | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main.zig b/src/main.zig index 1c7acaf..671ed3f 100644 --- a/src/main.zig +++ b/src/main.zig @@ -39,9 +39,15 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { // TODO start a runner and keep it hot + // we keep + // - a CommandList with the full commands we have right now + // - a Command with the current last typed successful command + var lang = langs.Lang.init(allocator); defer lang.deinit(); + var current: langs.Command = undefined; + while (true) { lang.reset(); try stdout.print("> "); @@ -53,10 +59,13 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { }; if (std.mem.eql(u8, line, "push")) { - try file.seekTo(0); - try printer.printList(cmds, stream); + try cmds.append(current); continue; } else if (std.mem.eql(u8, line, "list")) { + try printer.printList(cmds, stdout); + continue; + } else if (std.mem.eql(u8, line, "save")) { + try file.seekTo(0); try printer.printList(cmds, stream); continue; } @@ -65,7 +74,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { std.debug.warn("repl: error while parsing: {}\n", err); continue; }; - try cmds.append(cmds_parsed.at(0)); + current = cmds_parsed.at(0); } } From 67c42e39d479811195e81265a938ad78d0d48989 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 10 Sep 2019 21:31:23 -0300 Subject: [PATCH 011/182] add cloning of Runner and Image + basic Runner REPL logic --- src/image.zig | 21 ++++++++++++++++++++- src/main.zig | 34 +++++++++++++++++++++++++++++----- src/runner.zig | 4 ++++ 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/image.zig b/src/image.zig index 3e38903..1942f87 100644 --- a/src/image.zig +++ b/src/image.zig @@ -131,7 +131,6 @@ pub const Image = struct { /// Open a BMP image for later. pub fn open(allocator: *std.mem.Allocator, path: []const u8) !*Image { var in_fmt = mkSfInfo(); - var sndfile = try sopen(allocator, path, c.SFM_READ, &in_fmt); var image = try allocator.create(Image); @@ -149,6 +148,26 @@ pub const Image = struct { return image; } + pub fn clone(self: *Image) !*Image { + var in_fmt = mkSfInfo(); + // clone sndfile + var sndfile = try sopen(self.allocator, self.path, c.SFM_READ, &in_fmt); + var image = try allocator.create(Image); + + std.debug.assert(in_fmt.frames > i64(0)); + std.debug.assert(in_fmt.seekable == i32(1)); + + image.* = Image{ + .allocator = self.allocator, + .sndfile = sndfile, + .path = self.path, + .curpath = self.curpath, + .frames = @intCast(usize, in_fmt.frames), + }; + + return image; + } + pub fn close(self: *Image) void { //self.allocator.free(self.path); //self.allocator.free(self.curpath); diff --git a/src/main.zig b/src/main.zig index 671ed3f..be83ad6 100644 --- a/src/main.zig +++ b/src/main.zig @@ -8,6 +8,13 @@ test "scritcher" { _ = @import("runner.zig"); } +fn wrapInCmdList(allocator: *std.mem.Allocator, cmd: langs.Command) !langs.CommandList { + var cmds = try langs.CommandList.init(allocator); + try cmds.append(cmd); + + return cmds; +} + pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { var stdout_file = try std.io.getStdOut(); const stdout = &stdout_file.outStream().stream; @@ -24,30 +31,38 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { // now have a 'repl' argument right before it. to counteract that, the // initial repl buffer contains 'load :1' instead. - var cmds = langs.CommandList.init(allocator); - defer cmds.deinit(); - var loadargs = langs.ArgList.init(allocator); defer loadargs.deinit(); try loadargs.append(":1"); - try cmds.append(langs.Command{ + var cmds = try wrapInCmdList(allocator, langs.Command{ .command = .Load, .args = loadargs, }); - // TODO start a runner and keep it hot + defer cmds.deinit(); // we keep // - a CommandList with the full commands we have right now // - a Command with the current last typed successful command + // - one runner that contains the current full state of the image + // as if the current cmds was ran over it (TODO better wording) + // - one runner that gets copied from the original on every new + // command the user issues + var lang = langs.Lang.init(allocator); defer lang.deinit(); var current: langs.Command = undefined; + var runner = runners.Runner.init(allocator); + defer runner.deinit(); + + // run the load command + try runner.runCommands(cmds, true); + while (true) { lang.reset(); try stdout.print("> "); @@ -60,6 +75,10 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { if (std.mem.eql(u8, line, "push")) { try cmds.append(current); + var cmds_wrapped = try wrapInCmdList(allocator, current); + defer cmds_wrapped.deinit(); + + try runner.runCommands(cmds_wrapped, true); continue; } else if (std.mem.eql(u8, line, "list")) { try printer.printList(cmds, stdout); @@ -75,6 +94,11 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { continue; }; current = cmds_parsed.at(0); + + var runner_clone = try runner.clone(); + defer runner_clone.deinit(); + + try runner_clone.runCommands(cmds_parsed, true); } } diff --git a/src/runner.zig b/src/runner.zig index a348f22..909a9b2 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -33,6 +33,10 @@ pub const Runner = struct { } } + pub fn clone(self: *Runner) *Runner { + return Runner{ .allocator = allocator, .image = try image.clone() }; + } + fn resolveArg(self: *Runner, load_path: []const u8) ![]const u8 { if (load_path[0] == ':') { // parse the index from 1 to end From 84d582cfd1c2a582cbad2800da5c0a1397899e04 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 10 Sep 2019 21:35:22 -0300 Subject: [PATCH 012/182] image: open curpath instead of path when cloning --- src/image.zig | 2 +- src/main.zig | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/image.zig b/src/image.zig index 1942f87..fdad5ca 100644 --- a/src/image.zig +++ b/src/image.zig @@ -151,7 +151,7 @@ pub const Image = struct { pub fn clone(self: *Image) !*Image { var in_fmt = mkSfInfo(); // clone sndfile - var sndfile = try sopen(self.allocator, self.path, c.SFM_READ, &in_fmt); + var sndfile = try sopen(self.allocator, self.curpath, c.SFM_READ, &in_fmt); var image = try allocator.create(Image); std.debug.assert(in_fmt.frames > i64(0)); diff --git a/src/main.zig b/src/main.zig index be83ad6..011256d 100644 --- a/src/main.zig +++ b/src/main.zig @@ -75,10 +75,13 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { if (std.mem.eql(u8, line, "push")) { try cmds.append(current); + + // run the current added command to main cmds list + // with the main parent runner var cmds_wrapped = try wrapInCmdList(allocator, current); defer cmds_wrapped.deinit(); - try runner.runCommands(cmds_wrapped, true); + continue; } else if (std.mem.eql(u8, line, "list")) { try printer.printList(cmds, stdout); @@ -95,6 +98,9 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { }; current = cmds_parsed.at(0); + // by cloning the parent runner, we can iteratively write + // whatever command we want and only commit the good results + // back to the parent runner var runner_clone = try runner.clone(); defer runner_clone.deinit(); From 49cc7221b032c7b604bba300db3e9047e81495e0 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 10 Sep 2019 22:00:07 -0300 Subject: [PATCH 013/182] fix some clones, finish list of commands for printer --- src/image.zig | 2 +- src/main.zig | 15 ++++++++++++--- src/printer.zig | 20 ++++++++++++++++++-- src/runner.zig | 5 +++-- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/image.zig b/src/image.zig index fdad5ca..0e9c775 100644 --- a/src/image.zig +++ b/src/image.zig @@ -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)); diff --git a/src/main.zig b/src/main.zig index 011256d..be034f9 100644 --- a/src/main.zig +++ b/src/main.zig @@ -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); } } diff --git a/src/printer.zig b/src/printer.zig index 29aeb9b..2a30f8e 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -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); diff --git a/src/runner.zig b/src/runner.zig index 909a9b2..a010325 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -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 { From 66a73565023498b2bae0d6920d3083fc311f25c0 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 10 Sep 2019 22:08:35 -0300 Subject: [PATCH 014/182] runner: add newline to runqs message --- src/runner.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runner.zig b/src/runner.zig index a010325..072e38b 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -178,7 +178,7 @@ pub const Runner = struct { ); defer proc.deinit(); - std.debug.warn("running '{} {}'", program, out_path); + std.debug.warn("running '{} {}'\n", program, out_path); _ = try proc.spawnAndWait(); } From 52950f9a6fadf01754dd1538d76557b39fc602b4 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 10 Sep 2019 22:27:35 -0300 Subject: [PATCH 015/182] README: add repl instructions --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 31e1e17..584f6ff 100644 --- a/README.md +++ b/README.md @@ -41,3 +41,16 @@ scritcher examples/noise.scri blah.bmp // blah_g1.bmp, the second saves to blah_g2.bmp, etc. $your_image_viewer blah_g1.bmp ``` + +# using the repl + +using repl works via `scritcher repl scri_file.scri input_image.bmp` + +you type commands as you'd write the specific scritcher commands +(`doc/README.md`), with three repl-specific ones: + - `push`, to push the last written command to the queue + - `save`, to write the queue to the given `scri_file.scri` file + - `list`, to print the current contents of the queue + +this allows for quicker iteration of commands, as you can type a command, tweak +its arguments, and when satisfied, `push` it, and work on the next one, etc. From 0e323f66310e82c906fd2f0a7f3d015ac0883360 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 29 Sep 2019 23:57:24 -0300 Subject: [PATCH 016/182] repl tweaks --- build.zig | 5 ++--- src/main.zig | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.zig b/build.zig index eebcb55..f4bb0fb 100644 --- a/build.zig +++ b/build.zig @@ -2,12 +2,11 @@ const builds = @import("std").build; const Builder = @import("std").build.Builder; fn setupLinks(step: *builds.LibExeObjStep) void { + step.linkSystemLibrary("c"); + step.linkSystemLibrary("lilv-0"); step.linkSystemLibrary("sndfile"); - // TODO 2.30 glibc - step.linkSystemLibrary("c"); - step.linkSystemLibrary("GraphicsMagickWand"); step.linkSystemLibrary("GraphicsMagick"); diff --git a/src/main.zig b/src/main.zig index be034f9..503f1b3 100644 --- a/src/main.zig +++ b/src/main.zig @@ -65,7 +65,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { defer runqs_args.deinit(); // TODO change the runqs command to something given in an env var - try runqs_args.append("ristretto"); + try runqs_args.append("feh"); while (true) { lang.reset(); @@ -114,6 +114,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { }); try runner_clone.runCommands(cmds_parsed, true); + try stdout.write("\n"); } } From f8814ca94d109e8a1306327fa89c834f5187610b Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 5 Oct 2019 21:42:16 -0300 Subject: [PATCH 017/182] add assertions about seek state and seek position --- src/image.zig | 39 ++++++++++++++++++++++++++++----------- src/main.zig | 2 +- src/plugin.zig | 1 + 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/image.zig b/src/image.zig index 0e9c775..2b2a38a 100644 --- a/src/image.zig +++ b/src/image.zig @@ -45,6 +45,15 @@ fn sopen( return ImageError.OpenFail; } + const frames_on_end = c.sf_seek(file, 0, c.SEEK_END); + _ = c.sf_seek(file, 0, c.SEEK_SET); + std.testing.expectEqual(fmt.frames, frames_on_end); + + const frames_on_end_by_end = c.sf_seek(file, frames_on_end, c.SEEK_SET); + std.testing.expectEqual(frames_on_end, frames_on_end_by_end); + + std.debug.warn("frames on end: {}, frame on end (2): {}\n", frames_on_end, frames_on_end_by_end); + return file.?; } @@ -52,22 +61,20 @@ fn swrite(file: *c.SNDFILE, buf: [*]f32, frames: i64) !void { const count = c.sf_writef_float(file, buf, frames); if (count != frames) { - std.debug.warn("Wanted to read {}, got {}\n", frames, count); + std.debug.warn("Wanted to write {}, got {}\n", frames, count); return ImageError.WriteFail; } } fn sseek(file: *c.SNDFILE, offset: usize) void { - const frames = c.sf_seek(file, @intCast(i64, offset), c.SEEK_SET); - if (frames != @intCast(i64, offset)) { - std.debug.warn("failed to seek to {}\n", offset); - } -} + const offset_i64 = @intCast(i64, offset); + const frames = c.sf_seek(file, offset_i64, c.SEEK_SET); + const frames_current = c.sf_seek(file, 0, c.SEEK_CUR); + std.testing.expectEqual(frames, frames_current); -fn sf_tell(file: *c.SNDFILE) i64 { - var frames = c.sf_seek(file, 0, c.SEEK_CUR); - std.debug.warn("\t\t{} frames\n", frames); - return -frames; + if (frames != offset_i64) { + std.debug.warn("failed to seek to {} (seeked {} frames, offset_i64={})\n", offset, frames, offset_i64); + } } /// Caller owns the returned memory. @@ -132,6 +139,7 @@ pub const Image = struct { pub fn open(allocator: *std.mem.Allocator, path: []const u8) !*Image { var in_fmt = mkSfInfo(); var sndfile = try sopen(allocator, path, c.SFM_READ, &in_fmt); + var image = try allocator.create(Image); std.debug.assert(in_fmt.frames > i64(0)); @@ -152,6 +160,8 @@ pub const Image = struct { var in_fmt = mkSfInfo(); // clone sndfile var sndfile = try sopen(self.allocator, self.curpath, c.SFM_READ, &in_fmt); + std.testing.expectEqual(self.frames, @intCast(usize, in_fmt.frames)); + var image = try self.allocator.create(Image); std.debug.assert(in_fmt.frames > i64(0)); @@ -249,10 +259,17 @@ pub const Image = struct { var in_fmt = mkSfInfo(); self.sndfile = try sopen(self.allocator, path, c.SFM_READ, &in_fmt); + std.testing.expectEqual(self.frames, @intCast(usize, in_fmt.frames)); + self.curpath = path; self.frames = @intCast(usize, in_fmt.frames); - std.debug.warn("\timage: reopened on '{}'\n", self.curpath); + std.debug.warn( + "\timage: reopened on '{}' (frames={}, fmt.frames={})\n", + self.curpath, + self.frames, + in_fmt.frames, + ); } pub fn checkValid(self: *Image) !void { diff --git a/src/main.zig b/src/main.zig index 503f1b3..3df73fc 100644 --- a/src/main.zig +++ b/src/main.zig @@ -65,7 +65,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { defer runqs_args.deinit(); // TODO change the runqs command to something given in an env var - try runqs_args.append("feh"); + try runqs_args.append("ristretto"); while (true) { lang.reset(); diff --git a/src/plugin.zig b/src/plugin.zig index 03b72cc..861b452 100644 --- a/src/plugin.zig +++ b/src/plugin.zig @@ -34,6 +34,7 @@ pub const Position = struct { index: usize, pub fn seekPos(self: Position, total_size: usize) SeekPos { + std.debug.assert(self.index <= self.split); var tot = total_size / self.split; return SeekPos{ From 8c5f42b3db59a2e8f9e03593883a4206bafa8e25 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 5 Oct 2019 21:44:44 -0300 Subject: [PATCH 018/182] add quit/q commands to repl --- src/main.zig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main.zig b/src/main.zig index 3df73fc..d8702d4 100644 --- a/src/main.zig +++ b/src/main.zig @@ -94,6 +94,9 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { try file.seekTo(0); try printer.printList(cmds, stream); continue; + } else if (std.mem.eql(u8, line, "quit") or std.mem.eql(u8, line, "q")) { + std.debug.warn("leaving\n"); + break; } var cmds_parsed = lang.parse(line) catch |err| { From cb689c3adefafb67404c7064d8b476dc9506a8c8 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 6 Oct 2019 10:53:09 -0300 Subject: [PATCH 019/182] repl: use readline --- build.zig | 1 + src/main.zig | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/build.zig b/build.zig index f4bb0fb..622961e 100644 --- a/build.zig +++ b/build.zig @@ -6,6 +6,7 @@ fn setupLinks(step: *builds.LibExeObjStep) void { step.linkSystemLibrary("lilv-0"); step.linkSystemLibrary("sndfile"); + step.linkSystemLibrary("readline"); step.linkSystemLibrary("GraphicsMagickWand"); step.linkSystemLibrary("GraphicsMagick"); diff --git a/src/main.zig b/src/main.zig index d8702d4..a54a7c5 100644 --- a/src/main.zig +++ b/src/main.zig @@ -8,6 +8,14 @@ test "scritcher" { _ = @import("runner.zig"); } +const readline = @cImport({ + @cInclude("stdio.h"); + @cInclude("stdlib.h"); + + @cInclude("readline/readline.h"); + @cInclude("readline/history.h"); +}); + fn wrapInCmdList(allocator: *std.mem.Allocator, cmd: langs.Command) !langs.CommandList { var cmds = langs.CommandList.init(allocator); try cmds.append(cmd); @@ -69,13 +77,13 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { while (true) { lang.reset(); - try stdout.print("> "); - var buffer = try std.Buffer.init(allocator, ""[0..]); - var line = std.io.readLine(&buffer) catch |err| { - if (err == error.EndOfStream) break; - return err; - }; + var rd_line = readline.readline(c"> "); + if (rd_line == null) break; + readline.add_history(rd_line); + defer std.heap.c_allocator.destroy(rd_line); + + var line = rd_line[0..std.mem.len(u8, rd_line)]; if (std.mem.eql(u8, line, "push")) { try cmds.append(current); From 66b262beb290a212e20aa4e175eb35527c325814 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 6 Oct 2019 14:39:15 -0300 Subject: [PATCH 020/182] repl: open file as read and append to cmds before open as write closes #7 --- src/main.zig | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/main.zig b/src/main.zig index a54a7c5..502c52b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -28,12 +28,6 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path")); - var file = try std.fs.File.openWrite(scri_path); - defer file.close(); - - var out = file.outStream(); - var stream = &out.stream; - // the thing here is that 'load :0' would load the scri_path, since we // now have a 'repl' argument right before it. to counteract that, the // initial repl buffer contains 'load :1' instead. @@ -49,6 +43,37 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { defer cmds.deinit(); + // if the scri file already had commands, we add them up on the cmd list + var file_read = try std.fs.openReead(scri_path); + const total_bytes = try file_read.getEndPos(); + + if (total_bytes > 0) { + var scri_existing = try allocator.alloc(u8, total_bytes); + defer allocator.free(scri_existing); + + _ = try file.read(slice); + file_read.close(); + + var existing_cmds = try lang.parse(scri_existing); + defer existing_cmds.deinit(); + + // copy the existing command list into the repl's command list + var it = existing_cmds.iterator(); + while (it.next()) |existing_cmd| { + try cmds.append(existing_cmd); + } + } + + var file = try std.fs.File.openWrite(scri_path); + defer file.close(); + + var out = file.outStream(); + var stream = &out.stream; + + // since we opened the file for writing, it becomes empty, so, to ensure + // we don't fuck up later on, we print cmds before starting the repl + try printer.printList(cmds, stream); + // we keep // - a CommandList with the full commands we have right now // - a Command with the current last typed successful command @@ -99,6 +124,8 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { try printer.printList(cmds, stdout); continue; } else if (std.mem.eql(u8, line, "save")) { + // seek to 0 instead of appending the new command + // NOTE appending single command might be faster try file.seekTo(0); try printer.printList(cmds, stream); continue; From 80036c4c0d4c5dd351b4ecf7aca65a21a7c13dd7 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 6 Oct 2019 15:07:30 -0300 Subject: [PATCH 021/182] fix other things related to reading scri file on repl --- src/lang.zig | 1 + src/main.zig | 44 +++++++++++++++++++++++--------------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 9724dfb..a75193b 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -140,6 +140,7 @@ pub const ArgList = std.ArrayList([]const u8); pub const KeywordMap = std.StringHashMap(CommandType); +/// A parser. pub const Lang = struct { allocator: *std.mem.Allocator, keywords: KeywordMap, diff --git a/src/main.zig b/src/main.zig index 502c52b..9e333f5 100644 --- a/src/main.zig +++ b/src/main.zig @@ -25,45 +25,49 @@ fn wrapInCmdList(allocator: *std.mem.Allocator, cmd: langs.Command) !langs.Comma pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { var stdout_file = try std.io.getStdOut(); const stdout = &stdout_file.outStream().stream; - const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path")); + var file_read = try std.fs.File.openRead(scri_path); + const total_bytes = try file_read.getEndPos(); + // the thing here is that 'load :0' would load the scri_path, since we // now have a 'repl' argument right before it. to counteract that, the // initial repl buffer contains 'load :1' instead. - var loadargs = langs.ArgList.init(allocator); - defer loadargs.deinit(); - try loadargs.append(":1"); - - var cmds = try wrapInCmdList(allocator, langs.Command{ - .command = .Load, - .args = loadargs, - }); + // TODO load should -1 the index if its on repl + var cmds = langs.CommandList.init(allocator); defer cmds.deinit(); - // if the scri file already had commands, we add them up on the cmd list - var file_read = try std.fs.openReead(scri_path); - const total_bytes = try file_read.getEndPos(); + var lang = langs.Lang.init(allocator); + defer lang.deinit(); if (total_bytes > 0) { + // those MUST BE long lived, we can't defer them here var scri_existing = try allocator.alloc(u8, total_bytes); - defer allocator.free(scri_existing); - - _ = try file.read(slice); - file_read.close(); - + _ = try file_read.read(scri_existing); var existing_cmds = try lang.parse(scri_existing); - defer existing_cmds.deinit(); // copy the existing command list into the repl's command list var it = existing_cmds.iterator(); while (it.next()) |existing_cmd| { try cmds.append(existing_cmd); } + } else { + // if there isn't any commands on the file, we load our default + // 'load :1' command + var loadargs = langs.ArgList.init(allocator); + // defer loadargs.deinit(); + try loadargs.append(":1"); + + try cmds.append(langs.Command{ + .command = .Load, + .args = loadargs, + }); } + file_read.close(); + var file = try std.fs.File.openWrite(scri_path); defer file.close(); @@ -72,6 +76,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { // since we opened the file for writing, it becomes empty, so, to ensure // we don't fuck up later on, we print cmds before starting the repl + try printer.printList(cmds, stdout); try printer.printList(cmds, stream); // we keep @@ -83,9 +88,6 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { // - one runner that gets copied from the original on every new // command the user issues - var lang = langs.Lang.init(allocator); - defer lang.deinit(); - var current: langs.Command = undefined; var runner = runners.Runner.init(allocator); From 7cf16f9ffa202ea68b669f27b7d8214cbff06bb5 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 6 Oct 2019 15:12:19 -0300 Subject: [PATCH 022/182] deinit existing_cmds (not long lived) --- src/main.zig | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main.zig b/src/main.zig index 9e333f5..7a05be3 100644 --- a/src/main.zig +++ b/src/main.zig @@ -30,12 +30,6 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { var file_read = try std.fs.File.openRead(scri_path); const total_bytes = try file_read.getEndPos(); - // the thing here is that 'load :0' would load the scri_path, since we - // now have a 'repl' argument right before it. to counteract that, the - // initial repl buffer contains 'load :1' instead. - - // TODO load should -1 the index if its on repl - var cmds = langs.CommandList.init(allocator); defer cmds.deinit(); @@ -43,10 +37,15 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { defer lang.deinit(); if (total_bytes > 0) { - // those MUST BE long lived, we can't defer them here + // this MUST BE long lived (a reference to it is kept inside + // existing_cmds, and then passed along to cmds), + // we can't defer them here var scri_existing = try allocator.alloc(u8, total_bytes); _ = try file_read.read(scri_existing); + + // we can defer this because we copy the Command structs back to cmds var existing_cmds = try lang.parse(scri_existing); + defer existing_cmds.deinit(); // copy the existing command list into the repl's command list var it = existing_cmds.iterator(); @@ -56,8 +55,9 @@ 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 :1' command + + // TODO load should +1 the index if its on repl var loadargs = langs.ArgList.init(allocator); - // defer loadargs.deinit(); try loadargs.append(":1"); try cmds.append(langs.Command{ From c05be26dbdbb4e887a5f65cec5e35e6f4e6b843a Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 6 Oct 2019 15:16:41 -0300 Subject: [PATCH 023/182] runner: ignore one arg when its in repl closes #8 --- src/main.zig | 10 ++++------ src/runner.zig | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main.zig b/src/main.zig index 7a05be3..c8ff9cd 100644 --- a/src/main.zig +++ b/src/main.zig @@ -54,11 +54,9 @@ 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 :1' command - - // TODO load should +1 the index if its on repl + // 'load :0' command var loadargs = langs.ArgList.init(allocator); - try loadargs.append(":1"); + try loadargs.append(":0"); try cmds.append(langs.Command{ .command = .Load, @@ -90,7 +88,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { var current: langs.Command = undefined; - var runner = runners.Runner.init(allocator); + var runner = runners.Runner.init(allocator, true); defer runner.deinit(); // run the load command @@ -164,7 +162,7 @@ pub fn main() !void { var lang = langs.Lang.init(allocator); defer lang.deinit(); - var runner = runners.Runner.init(allocator); + var runner = runners.Runner.init(allocator, false); defer runner.deinit(); var args_it = std.process.args(); diff --git a/src/runner.zig b/src/runner.zig index 072e38b..ede7b3b 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -19,11 +19,17 @@ pub const RunError = error{ pub const Runner = struct { allocator: *std.mem.Allocator, + + /// The currently opened image in the runner image: ?*Image = null, - pub fn init(allocator: *std.mem.Allocator) Runner { + /// If the runner is in REPL mode + repl: bool = false, + + pub fn init(allocator: *std.mem.Allocator, repl: bool) Runner { return Runner{ .allocator = allocator, + .repl = repl, }; } @@ -41,7 +47,11 @@ pub const Runner = struct { fn resolveArg(self: *Runner, load_path: []const u8) ![]const u8 { if (load_path[0] == ':') { // parse the index from 1 to end - const index = try std.fmt.parseInt(usize, load_path[1..], 10); + var index = try std.fmt.parseInt(usize, load_path[1..], 10); + + // don't care about the 'repl' being prepended when we're in repl + if (self.repl) index += 1; + var args_it = std.process.args(); _ = args_it.skip(); From a18809eb5b1c0c21e0db82d6c05ec239f66491a6 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 20 Oct 2019 11:37:11 -0300 Subject: [PATCH 024/182] repl: handle when original file doesn't exist --- src/main.zig | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main.zig b/src/main.zig index c8ff9cd..5778385 100644 --- a/src/main.zig +++ b/src/main.zig @@ -27,8 +27,11 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { const stdout = &stdout_file.outStream().stream; const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path")); - var file_read = try std.fs.File.openRead(scri_path); - const total_bytes = try file_read.getEndPos(); + var file_read_opt: ?std.fs.File = std.fs.File.openRead(scri_path) catch |err| blk: { + if (err == error.FileNotFound) break :blk null; + return err; + }; + const total_bytes = if (file_read_opt) |file_read| try file_read.getEndPos() else 0; var cmds = langs.CommandList.init(allocator); defer cmds.deinit(); @@ -41,7 +44,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { // existing_cmds, and then passed along to cmds), // we can't defer them here var scri_existing = try allocator.alloc(u8, total_bytes); - _ = try file_read.read(scri_existing); + _ = try file_read_opt.?.read(scri_existing); // we can defer this because we copy the Command structs back to cmds var existing_cmds = try lang.parse(scri_existing); @@ -64,7 +67,9 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { }); } - file_read.close(); + if (file_read_opt) |file_read| { + file_read.close(); + } var file = try std.fs.File.openWrite(scri_path); defer file.close(); From cdca993048aea437b31d98f82a2d2c221cc659ef Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 20 Oct 2019 11:59:15 -0300 Subject: [PATCH 025/182] remove 'use-after-free' --- src/main.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.zig b/src/main.zig index 5778385..af21328 100644 --- a/src/main.zig +++ b/src/main.zig @@ -111,7 +111,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { var rd_line = readline.readline(c"> "); if (rd_line == null) break; readline.add_history(rd_line); - defer std.heap.c_allocator.destroy(rd_line); + //defer std.heap.c_allocator.destroy(rd_line); var line = rd_line[0..std.mem.len(u8, rd_line)]; From ecc9546de2671d5e70af4865f1a8b9903dcbb025 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 20 Oct 2019 13:08:54 -0300 Subject: [PATCH 026/182] add readline to readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 584f6ff..c289de8 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ glitch art "framework", ???????? language??? something? - zig at https://ziglang.org - libc, lilv and libsndfile - graphicsmagick for the `rotate` command + - readline (for repl) ## plugin depedencies (only required at runtime): - lv2 default plugins (most specifically the eg-amp plugin, From c75db195236bfc3c5249ca495214a6aad05034cd Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 20 Oct 2019 13:12:49 -0300 Subject: [PATCH 027/182] repl: ignore comments closes #10 --- src/main.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.zig b/src/main.zig index af21328..b8a70a1 100644 --- a/src/main.zig +++ b/src/main.zig @@ -137,6 +137,8 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { } else if (std.mem.eql(u8, line, "quit") or std.mem.eql(u8, line, "q")) { std.debug.warn("leaving\n"); break; + } else if (std.mem.startsWith(u8, line, "#")) { + continue; } var cmds_parsed = lang.parse(line) catch |err| { From bb501d9c1ecf2e6d267ff6107eccde864e8b48de Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 20 Oct 2019 13:13:32 -0300 Subject: [PATCH 028/182] repl: add output when leaving from c-d --- src/main.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main.zig b/src/main.zig index b8a70a1..66f9cce 100644 --- a/src/main.zig +++ b/src/main.zig @@ -109,7 +109,10 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { lang.reset(); var rd_line = readline.readline(c"> "); - if (rd_line == null) break; + if (rd_line == null) { + std.debug.warn("leaving from eof\n"); + break; + } readline.add_history(rd_line); //defer std.heap.c_allocator.destroy(rd_line); From 005d68572332b968a36ed6f5edc8538210764ff0 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 20 Oct 2019 13:17:23 -0300 Subject: [PATCH 029/182] doc: remove unused parameters part of eq command --- doc/README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/doc/README.md b/doc/README.md index 8330e43..34ef5d7 100644 --- a/doc/README.md +++ b/doc/README.md @@ -46,9 +46,6 @@ Parameters: Run the DJ EQ plugin from the SWH plugins. -Parameters: - - `lo`: Low range - `lo`, `mid`, and `hi` are the respective dB gains for each frequency range. All three ranges accept gains from -70dB to +6dB. From 87bab879ed60db02d6c7db4673c1920e15ac9e40 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 22 Oct 2019 17:08:19 -0300 Subject: [PATCH 030/182] add embed cmd --- src/lang.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lang.zig b/src/lang.zig index a75193b..d926d77 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -30,6 +30,7 @@ pub const CommandType = enum { Noise, WildNoise, Write, + Embed, Rotate, }; @@ -187,6 +188,7 @@ pub const Lang = struct { _ = try self.keywords.put("noise", .Noise); _ = try self.keywords.put("wildnoise", .WildNoise); _ = try self.keywords.put("write", .Write); + _ = try self.keywords.put("embed", .Embed); // even more custom _ = try self.keywords.put("rotate", .Rotate); From 2e273900581139ee11604c6ca6c4cf3f67e4f33c Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 22 Oct 2019 18:16:15 -0300 Subject: [PATCH 031/182] add the rest for embed command - allow any extra param as a generic to custom plugin init --- src/custom.zig | 42 ++++++++++++++++++++++++++++++++++++++++++ src/image.zig | 19 +++++++++++++------ src/lang.zig | 3 +++ src/printer.zig | 1 + src/runner.zig | 19 ++++++++++++++++--- 5 files changed, 75 insertions(+), 9 deletions(-) diff --git a/src/custom.zig b/src/custom.zig index 3f57a4b..7d3eb23 100644 --- a/src/custom.zig +++ b/src/custom.zig @@ -2,6 +2,7 @@ const std = @import("std"); const lv2 = @import("lv2_helpers.zig"); const plugins = @import("plugin.zig"); +const image = @import("image.zig"); const c = lv2.c; @@ -131,3 +132,44 @@ pub const Write = struct { bufs.out[0] = self.data; } }; + +pub const Embed = struct { + allocator: *std.mem.Allocator, + filepath: []const u8, + + sndfile: *c.SNDFILE = undefined, + + // TODO add its own read buffers from snd file + + pub fn init(allocator: *std.mem.Allocator, filepath: []const u8) @This() { + return Embed{ + .allocator = allocator, + .filepath = filepath, + }; + } + + pub fn setup(self: *@This()) !void { + var in_fmt = c.SF_INFO{ + .frames = c_int(0), + .samplerate = c_int(0), + .channels = c_int(0), + .format = c_int(0), + .sections = c_int(0), + .seekable = c_int(0), + }; + self.sndfile = try image.sopen( + self.allocator, + self.filepath, + c.SFM_READ, + &in_fmt, + ); + + // TODO allocate 1 or 2 in read buffer, but only use 1 + } + + pub fn deinit(self: *@This()) void {} + + pub fn run(self: *@This(), bufs: *RunBuffers) void { + bufs.out[0] = 0; + } +}; diff --git a/src/image.zig b/src/image.zig index 2b2a38a..3badd58 100644 --- a/src/image.zig +++ b/src/image.zig @@ -1,7 +1,6 @@ const std = @import("std"); const lv2 = @import("lv2_helpers.zig"); const c = lv2.c; -const custom = @import("custom.zig"); const bmp = @import("bmp_valid.zig"); const plugins = @import("plugin.zig"); @@ -23,7 +22,7 @@ pub const ImageError = error{ }; /// Low level integration function with libsndfile. -fn sopen( +pub fn sopen( allocator: *std.mem.Allocator, path: []const u8, mode: i32, @@ -57,7 +56,7 @@ fn sopen( return file.?; } -fn swrite(file: *c.SNDFILE, buf: [*]f32, frames: i64) !void { +pub fn swrite(file: *c.SNDFILE, buf: [*]f32, frames: i64) !void { const count = c.sf_writef_float(file, buf, frames); if (count != frames) { @@ -109,7 +108,7 @@ pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 { return error.TempGenFail; } -fn mkSfInfo() c.SF_INFO { +pub fn mkSfInfo() c.SF_INFO { return c.SF_INFO{ .frames = c_int(0), .samplerate = c_int(44100), @@ -422,9 +421,10 @@ pub const Image = struct { self: *Image, comptime Plugin: type, position: plugins.Position, - params: *plugins.ParamMap, + comptime ExtraType: type, + extra: ExtraType, ) !void { - var plugin_opt: ?Plugin = Plugin.init(self.allocator, params); + var plugin_opt: ?Plugin = Plugin.init(self.allocator, extra); if (plugin_opt == null) { return ImageError.PluginLoadFail; } @@ -432,6 +432,13 @@ pub const Image = struct { var plugin = plugin_opt.?; defer plugin.deinit(); + const decls = comptime std.meta.declarations(Plugin); + inline for (decls) |decl| { + if (comptime std.mem.eql(u8, decl.name, "setup")) { + try plugin.setup(); + } + } + // the code here is a copypaste of runPlugin() without the specific // lilv things. var tmpnam = try temporaryName(self.allocator); diff --git a/src/lang.zig b/src/lang.zig index d926d77..02dbf3b 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -227,6 +227,7 @@ pub const Lang = struct { "noise", "wildnoise", "write", + "embed", "rotate", }; @@ -252,6 +253,7 @@ pub const Lang = struct { .Noise, .WildNoise, .Write, + .Embed, .Rotate, }; @@ -314,6 +316,7 @@ pub const Lang = struct { .WildNoise => try self.expectFloat(4, cmd.args), .Write => try self.expectFloat(3, cmd.args), .Rotate => try self.expectAny(2, cmd.args), + .Embed => try self.expectAny(3, cmd.args), else => std.debug.warn("WARN unchecked command {}\n", cmd.command), } } diff --git a/src/printer.zig b/src/printer.zig index 2a30f8e..f198579 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -24,6 +24,7 @@ pub fn printList(list: langs.CommandList, stream: var) !void { .Noise => "noise", .WildNoise => "wildnoise", .Write => "write", + .Embed => "embed", .Rotate => "rotate", }; diff --git a/src/runner.zig b/src/runner.zig index ede7b3b..5ae666c 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -266,17 +266,22 @@ pub const Runner = struct { fn noiseCmd(self: *Runner, pos: Position, map: *ParamMap) !void { var image = try self.getImage(); - try image.runCustomPlugin(custom.RandomNoise, pos, map); + try image.runCustomPlugin(custom.RandomNoise, pos, *ParamMap, map); } fn wildNoiseCmd(self: *Runner, pos: Position, map: *ParamMap) !void { var image = try self.getImage(); - try image.runCustomPlugin(custom.WildNoise, pos, map); + try image.runCustomPlugin(custom.WildNoise, pos, *ParamMap, map); } fn writeCmd(self: *Runner, pos: Position, map: *ParamMap) !void { var image = try self.getImage(); - try image.runCustomPlugin(custom.Write, pos, map); + try image.runCustomPlugin(custom.Write, pos, *ParamMap, map); + } + + fn embedCmd(self: *Runner, pos: Position, path: []const u8) !void { + var image = try self.getImage(); + try image.runCustomPlugin(custom.Embed, pos, []const u8, path); } fn rotateCmd( @@ -303,6 +308,8 @@ pub const Runner = struct { .Load => blk: { var path = cmd.args.at(0); try self.loadCmd(path); + + // TODO is this needed? break :blk; }, .Quicksave => try self.quicksaveCmd(), @@ -460,6 +467,12 @@ pub const Runner = struct { try self.writeCmd(pos, &map); }, + .Embed => blk: { + const pos = try cmd.consumePosition(); + const path = cmd.args.at(2); + try self.embedCmd(pos, path); + }, + .Rotate => blk: { const deg = try cmd.floatArgAt(0); const bgfill = try cmd.argAt(1); From 612421f7b6ff34223a41a19abef4d6a1fb2b6cd8 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 22 Oct 2019 18:23:05 -0300 Subject: [PATCH 032/182] add embed code --- src/custom.zig | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/custom.zig b/src/custom.zig index 7d3eb23..4c8c611 100644 --- a/src/custom.zig +++ b/src/custom.zig @@ -138,8 +138,7 @@ pub const Embed = struct { filepath: []const u8, sndfile: *c.SNDFILE = undefined, - - // TODO add its own read buffers from snd file + buf: []f32 = undefined, pub fn init(allocator: *std.mem.Allocator, filepath: []const u8) @This() { return Embed{ @@ -157,6 +156,7 @@ pub const Embed = struct { .sections = c_int(0), .seekable = c_int(0), }; + self.sndfile = try image.sopen( self.allocator, self.filepath, @@ -164,12 +164,29 @@ pub const Embed = struct { &in_fmt, ); - // TODO allocate 1 or 2 in read buffer, but only use 1 + self.buf = try self.allocator.alloc(f32, @intCast(usize, in_fmt.channels)); } pub fn deinit(self: *@This()) void {} pub fn run(self: *@This(), bufs: *RunBuffers) void { - bufs.out[0] = 0; + const read_bytes = c.sf_readf_float(self.sndfile, self.buf.ptr, 1); + + if (read_bytes == 0) { + std.debug.warn("WARN! reached EOF for embed\n"); + return; + } + + if (read_bytes < 0) { + const st: i32 = c.sf_error(self.sndfile); + std.debug.warn( + "Failed to read {} ({})\n", + self.filepath, + c.sf_error_number(st), + ); + return; + } + + bufs.out[0] = bufs.in[0] + self.buf[0]; } }; From 2d64eaa3efd14f71d07b381550df9c0b09f8106a Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 22 Oct 2019 18:30:55 -0300 Subject: [PATCH 033/182] add embed example script --- .gitignore | 1 + examples/embed.scri | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 examples/embed.scri diff --git a/.gitignore b/.gitignore index 3cef7be..3fa9744 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ zig-cache/ +*.mp3 diff --git a/examples/embed.scri b/examples/embed.scri new file mode 100644 index 0000000..d9c7efa --- /dev/null +++ b/examples/embed.scri @@ -0,0 +1,3 @@ +load :0; +embed 3 1 ./file.mp3 +quicksave; From 6e66850d905c3aaf646d8add316c78e591183f59 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 22 Oct 2019 18:57:36 -0300 Subject: [PATCH 034/182] use sf_open_fd --- examples/embed.scri | 2 +- src/image.zig | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/embed.scri b/examples/embed.scri index d9c7efa..eb26536 100644 --- a/examples/embed.scri +++ b/examples/embed.scri @@ -1,3 +1,3 @@ load :0; -embed 3 1 ./file.mp3 +embed 3 1 file.mp3 quicksave; diff --git a/src/image.zig b/src/image.zig index 3badd58..4b275f9 100644 --- a/src/image.zig +++ b/src/image.zig @@ -31,14 +31,17 @@ pub fn sopen( var cstr_path = try std.cstr.addNullByte(allocator, path); defer allocator.free(cstr_path); - var file = c.sf_open(cstr_path.ptr, mode, fmt); + var fs_file = try std.fs.File.openRead(path); + + var file = c.sf_open_fd(fs_file.handle, mode, fmt, 1); const st: i32 = c.sf_error(file); if (st != 0) { + var msg = c.sf_error_number(st); std.debug.warn( "Failed to open {} ({})\n", path, - c.sf_error_number(st), + msg[0..std.mem.len(u8, msg)], ); return ImageError.OpenFail; From 1c6ef1d4d5fcc6798ea5539de1517306cbf6e054 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 22 Oct 2019 19:08:38 -0300 Subject: [PATCH 035/182] Revert "use sf_open_fd" This reverts commit 6e66850d905c3aaf646d8add316c78e591183f59. --- examples/embed.scri | 2 +- src/image.zig | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/examples/embed.scri b/examples/embed.scri index eb26536..d9c7efa 100644 --- a/examples/embed.scri +++ b/examples/embed.scri @@ -1,3 +1,3 @@ load :0; -embed 3 1 file.mp3 +embed 3 1 ./file.mp3 quicksave; diff --git a/src/image.zig b/src/image.zig index 4b275f9..3badd58 100644 --- a/src/image.zig +++ b/src/image.zig @@ -31,17 +31,14 @@ pub fn sopen( var cstr_path = try std.cstr.addNullByte(allocator, path); defer allocator.free(cstr_path); - var fs_file = try std.fs.File.openRead(path); - - var file = c.sf_open_fd(fs_file.handle, mode, fmt, 1); + var file = c.sf_open(cstr_path.ptr, mode, fmt); const st: i32 = c.sf_error(file); if (st != 0) { - var msg = c.sf_error_number(st); std.debug.warn( "Failed to open {} ({})\n", path, - msg[0..std.mem.len(u8, msg)], + c.sf_error_number(st), ); return ImageError.OpenFail; From c8b5327634a94a42c76d25b14c5221751755c91b Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 22 Oct 2019 19:09:05 -0300 Subject: [PATCH 036/182] libsndfile cant open mp3s --- .gitignore | 1 + examples/embed.scri | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3fa9744..b43912f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ zig-cache/ *.mp3 +*.wav diff --git a/examples/embed.scri b/examples/embed.scri index d9c7efa..b78f7c9 100644 --- a/examples/embed.scri +++ b/examples/embed.scri @@ -1,3 +1,3 @@ load :0; -embed 3 1 ./file.mp3 +embed 3 1 ./file.wav; quicksave; From 430677fc07655e190bcea7951bd11075b2911445 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 22 Oct 2019 19:16:09 -0300 Subject: [PATCH 037/182] enhance embed custom plugin - seek to 0 on setup - ignore and copy original bytes if we reached end of audio file --- src/custom.zig | 4 +++- src/image.zig | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/custom.zig b/src/custom.zig index 4c8c611..0727113 100644 --- a/src/custom.zig +++ b/src/custom.zig @@ -164,6 +164,8 @@ pub const Embed = struct { &in_fmt, ); + image.sseek(self.sndfile, 0); + self.buf = try self.allocator.alloc(f32, @intCast(usize, in_fmt.channels)); } @@ -173,7 +175,7 @@ pub const Embed = struct { const read_bytes = c.sf_readf_float(self.sndfile, self.buf.ptr, 1); if (read_bytes == 0) { - std.debug.warn("WARN! reached EOF for embed\n"); + bufs.out[0] = bufs.in[0]; return; } diff --git a/src/image.zig b/src/image.zig index 3badd58..9748bc9 100644 --- a/src/image.zig +++ b/src/image.zig @@ -65,7 +65,7 @@ pub fn swrite(file: *c.SNDFILE, buf: [*]f32, frames: i64) !void { } } -fn sseek(file: *c.SNDFILE, offset: usize) void { +pub fn sseek(file: *c.SNDFILE, offset: usize) void { const offset_i64 = @intCast(i64, offset); const frames = c.sf_seek(file, offset_i64, c.SEEK_SET); const frames_current = c.sf_seek(file, 0, c.SEEK_CUR); From 1c17b714a73bae91374de1848d36de8c356ed51e Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 25 Oct 2019 07:09:39 -0300 Subject: [PATCH 038/182] doc: add embed cmd --- doc/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/README.md b/doc/README.md index 34ef5d7..c342bef 100644 --- a/doc/README.md +++ b/doc/README.md @@ -166,6 +166,11 @@ Rotate the image by `deg` degrees, filling the resulting triangles with `bgfill` `bgfill` is a hex string, e.g `#000000`. +## `embed split index path_to_file` + +embed an audio file in the given image. the file is opened with libsndfile, +which means some formats, like mp3, will not be opened. + ## `quicksave` Save the file on the same directory of the file specified by `load`, but From 91de05d3b1e0e8e3ecf743b3eebf3709520484ae Mon Sep 17 00:00:00 2001 From: Luna Date: Thu, 31 Oct 2019 19:02:36 -0300 Subject: [PATCH 039/182] runner: fix for latest zig --- src/runner.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/runner.zig b/src/runner.zig index 5ae666c..800fd69 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -117,7 +117,7 @@ pub const Runner = struct { const basename = std.fs.path.basename(image.path); const dirname = std.fs.path.dirname(image.path).?; - var dir = try std.fs.Dir.open(self.allocator, dirname); + var dir = try std.fs.Dir.open(dirname); defer dir.close(); const period_idx = std.mem.lastIndexOf(u8, basename, ".").?; @@ -134,7 +134,9 @@ pub const Runner = struct { var max: usize = 0; - while (try dir.next()) |entry| { + var it = dir.iterate(); + + while (try it.next()) |entry| { switch (entry.kind) { .File => blk: { if (!std.mem.startsWith(u8, entry.name, starts_with)) break :blk {}; From fb0516a1db7834362c7a9b90b378718624451af1 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 1 Nov 2019 21:43:45 -0300 Subject: [PATCH 040/182] allow ppm files as inputs - only run bmp.magicValid when path ends in bmp - remove uneeced header size constants --- src/image.zig | 6 ++---- src/runner.zig | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/image.zig b/src/image.zig index 9748bc9..c9a436c 100644 --- a/src/image.zig +++ b/src/image.zig @@ -5,9 +5,6 @@ const bmp = @import("bmp_valid.zig"); const plugins = @import("plugin.zig"); -/// Approximate size of the BMP header, in bytes. -pub const BMPHeaderSize: usize = 82000; - /// Buffer size for main image copying. pub const BufferSize: usize = 300000; @@ -284,7 +281,8 @@ pub const Image = struct { var magic = [2]u8{ 0, 0 }; _ = try file.read(&magic); - try bmp.magicValid(&magic); + if (std.mem.endsWith(u8, self.path, ".bmp")) + try bmp.magicValid(&magic); } /// Run a plugin over the image. diff --git a/src/runner.zig b/src/runner.zig index 800fd69..8169393 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -89,7 +89,7 @@ pub const Runner = struct { // before loading the file into scritcher. for example, you can start // krita/gimp and make it export a bmp and while in the program you can // apply filters, etc. - if (!std.mem.endsWith(u8, load_path, ".bmp")) { + if (!std.mem.endsWith(u8, load_path, ".bmp") and !std.mem.endsWith(u8, load_path, ".ppm")) { std.debug.warn("Only BMP files are allowed to be loaded.\n"); return RunError.NoBMP; } From a411659d6b0b523a4b948684a555db8c991ae4ce Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 1 Nov 2019 22:29:14 -0300 Subject: [PATCH 041/182] add exampels/rflanger.scri --- examples/rflanger.scri | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 examples/rflanger.scri diff --git a/examples/rflanger.scri b/examples/rflanger.scri new file mode 100644 index 0000000..f1fe18d --- /dev/null +++ b/examples/rflanger.scri @@ -0,0 +1,3 @@ +load :0; +rflanger 3 1 2.5 1; +quicksave; From c57c40db61a897c2de9f6c99299556d10ef86abf Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 10 Nov 2019 13:37:59 -0300 Subject: [PATCH 042/182] use at-as builtin --- src/custom.zig | 12 ++++++------ src/image.zig | 24 ++++++++++++------------ src/lv2_helpers.zig | 6 +++--- src/plugin.zig | 2 +- src/runner.zig | 2 +- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/custom.zig b/src/custom.zig index 0727113..b748ac5 100644 --- a/src/custom.zig +++ b/src/custom.zig @@ -149,12 +149,12 @@ pub const Embed = struct { pub fn setup(self: *@This()) !void { var in_fmt = c.SF_INFO{ - .frames = c_int(0), - .samplerate = c_int(0), - .channels = c_int(0), - .format = c_int(0), - .sections = c_int(0), - .seekable = c_int(0), + .frames = @as(c_int, 0), + .samplerate = @as(c_int, 0), + .channels = @as(c_int, 0), + .format = @as(c_int, 0), + .sections = @as(c_int, 0), + .seekable = @as(c_int, 0), }; self.sndfile = try image.sopen( diff --git a/src/image.zig b/src/image.zig index c9a436c..3e521fb 100644 --- a/src/image.zig +++ b/src/image.zig @@ -90,7 +90,7 @@ pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 { // generate a random uppercase letter, that is, 65 + random number. for (fill) |_, f_idx| { var idx = @intCast(u8, r.random.uintLessThan(u5, 24)); - var letter = u8(65) + idx; + var letter = @as(u8, 65) + idx; fill[f_idx] = letter; } @@ -107,12 +107,12 @@ pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 { pub fn mkSfInfo() c.SF_INFO { return c.SF_INFO{ - .frames = c_int(0), - .samplerate = c_int(44100), - .channels = c_int(1), + .frames = @as(c_int, 0), + .samplerate = @as(c_int, 44100), + .channels = @as(c_int, 1), .format = c.SF_FORMAT_ULAW | c.SF_FORMAT_RAW | c.SF_ENDIAN_BIG, - .sections = c_int(0), - .seekable = c_int(0), + .sections = @as(c_int, 0), + .seekable = @as(c_int, 0), }; } @@ -138,8 +138,8 @@ pub const Image = struct { var image = try allocator.create(Image); - std.debug.assert(in_fmt.frames > i64(0)); - std.debug.assert(in_fmt.seekable == i32(1)); + std.debug.assert(in_fmt.frames > @as(i64, 0)); + std.debug.assert(in_fmt.seekable == @as(i32, 1)); image.* = Image{ .allocator = allocator, @@ -160,8 +160,8 @@ pub const Image = struct { var image = try self.allocator.create(Image); - std.debug.assert(in_fmt.frames > i64(0)); - std.debug.assert(in_fmt.seekable == i32(1)); + std.debug.assert(in_fmt.frames > @as(i64, 0)); + std.debug.assert(in_fmt.seekable == @as(i32, 1)); image.* = Image{ .allocator = self.allocator, @@ -367,7 +367,7 @@ pub const Image = struct { // pre-plugin copy, merged with bmp header copy try self.copyBytes( out_file, - usize(0), + @as(usize, 0), seek_pos.start, ); @@ -462,7 +462,7 @@ pub const Image = struct { // pre-plugin copy, merged with bmp header copy try self.copyBytes( out_file, - usize(0), + @as(usize, 0), seek_pos.start, ); diff --git a/src/lv2_helpers.zig b/src/lv2_helpers.zig index d9a89f5..825ea19 100644 --- a/src/lv2_helpers.zig +++ b/src/lv2_helpers.zig @@ -70,8 +70,8 @@ pub fn setupPorts(ctx: *plugin.Context) ![]Port { port.* = Port{ .lilv_port = null, .ptype = .Control, - .index = f32(0), - .value = f32(0), + .index = @as(f32, 0), + .value = @as(f32, 0), .is_input = false, .optional = false, }; @@ -106,7 +106,7 @@ pub fn setupPorts(ctx: *plugin.Context) ![]Port { port.index = i; if (std.math.isNan(values[i])) { - port.value = f32(0); + port.value = @as(f32, 0); } else { port.value = values[i]; } diff --git a/src/plugin.zig b/src/plugin.zig index 861b452..ebc7f03 100644 --- a/src/plugin.zig +++ b/src/plugin.zig @@ -95,7 +95,7 @@ pub const RunContext = struct { allocator: *std.mem.Allocator, plugin: *const c.LilvPlugin, ) !RunContext { - var instance = c.lilv_plugin_instantiate(plugin, f64(44100), null); + var instance = c.lilv_plugin_instantiate(plugin, @as(f64, 44100), null); errdefer c.lilv_instance_free(instance); if (instance == null) { diff --git a/src/runner.zig b/src/runner.zig index 8169393..869f0f5 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -352,7 +352,7 @@ pub const Runner = struct { .Mbeq => blk: { const pos = try cmd.consumePosition(); - const bands = try cmd.floatArgMany(self.allocator, 2, 15, f32(0)); + const bands = try cmd.floatArgMany(self.allocator, 2, 15, @as(f32, 0)); defer self.allocator.free(bands); try self.mbeqCmd(pos, bands); From 46d576fc13e23f27f193a12a5cb65343f4ca3420 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 10 Nov 2019 13:46:48 -0300 Subject: [PATCH 043/182] image: remove expectEqual check (caused problems for rotate) --- src/image.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/image.zig b/src/image.zig index 3e521fb..d8b4dd3 100644 --- a/src/image.zig +++ b/src/image.zig @@ -255,7 +255,7 @@ pub const Image = struct { var in_fmt = mkSfInfo(); self.sndfile = try sopen(self.allocator, path, c.SFM_READ, &in_fmt); - std.testing.expectEqual(self.frames, @intCast(usize, in_fmt.frames)); + // std.testing.expectEqual(self.frames, @intCast(usize, in_fmt.frames)); self.curpath = path; self.frames = @intCast(usize, in_fmt.frames); From 09471e564a93e927ccc9cd6e8b286d1b27ef9801 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 2 Dec 2019 20:13:19 -0300 Subject: [PATCH 044/182] allow args to be deinited on error, fix argAt --- src/lang.zig | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 02dbf3b..8063329 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -45,13 +45,14 @@ pub const Command = struct { } pub fn argAt(self: Command, idx: usize) ![]const u8 { - const args = self.args.toSliceConst(); + std.debug.warn("{} {}", idx, self.args.len); - if (idx > (args.len - 1)) { + if (idx > (self.args.len - 1)) { std.debug.warn("Expected argument at index {}\n", idx); return ParseError.ArgRequired; } + const args = self.args.toSliceConst(); return args[idx]; } @@ -361,6 +362,8 @@ pub const Lang = struct { } var args = ArgList.init(self.allocator); + errdefer args.deinit(); + while (tok_it.next()) |arg| { try args.append(arg); } From a10416e56f712ac39759baa5742e4117c47d4c19 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 8 Dec 2019 12:14:31 -0300 Subject: [PATCH 045/182] fixes for latest zig --- src/magick_wand.zig | 218 ++++++++++++++++++++++---------------------- src/main.zig | 4 +- src/runner.zig | 4 +- 3 files changed, 113 insertions(+), 113 deletions(-) diff --git a/src/magick_wand.zig b/src/magick_wand.zig index 426dc06..63c9437 100644 --- a/src/magick_wand.zig +++ b/src/magick_wand.zig @@ -3459,32 +3459,32 @@ pub const __GNUC_VA_LIST = 1; pub const __BIGGEST_ALIGNMENT__ = 16; pub const EXIT_SUCCESS = 0; pub const _IO_USER_LOCK = 32768; -pub const __INT64_FMTd__ = c"ld"; +pub const __INT64_FMTd__ = "ld"; pub const __STDC_VERSION__ = c_long(201112); pub const __SIZEOF_FLOAT__ = 4; pub const MagickSignature = c_ulong(2880220587); -pub const __INT_LEAST32_FMTi__ = c"i"; +pub const __INT_LEAST32_FMTi__ = "i"; pub const MagickLibInterfaceOldest = 3; -pub const __INT_LEAST8_FMTi__ = c"hhi"; +pub const __INT_LEAST8_FMTi__ = "hhi"; pub const __LDBL_EPSILON__ = 0.000000; pub const __LZCNT__ = 1; pub const MaxTextExtent = 2053; pub const __STDC_UTF_32__ = 1; -pub const __INT_LEAST32_FMTd__ = c"d"; +pub const __INT_LEAST32_FMTd__ = "d"; pub const __INVPCID__ = 1; pub const __SIG_ATOMIC_WIDTH__ = 32; -pub const __FD_ZERO_STOS = c"stosq"; -pub const __UINT_FAST64_FMTX__ = c"lX"; +pub const __FD_ZERO_STOS = "stosq"; +pub const __UINT_FAST64_FMTX__ = "lX"; pub const __GCC_ATOMIC_LLONG_LOCK_FREE = 2; pub const DrawGetException = MagickDrawGetException; -pub const __clang_version__ = c"8.0.0 (tags/RELEASE_800/final)"; -pub const __UINT_LEAST8_FMTo__ = c"hho"; +pub const __clang_version__ = "8.0.0 (tags/RELEASE_800/final)"; +pub const __UINT_LEAST8_FMTo__ = "hho"; pub const __SIZEOF_DOUBLE__ = 8; -pub const __INTMAX_FMTd__ = c"ld"; +pub const __INTMAX_FMTd__ = "ld"; pub const __HAVE_DISTINCT_FLOAT16 = __HAVE_FLOAT16; pub const __CLANG_ATOMIC_CHAR_LOCK_FREE = 2; pub const LITTLE_ENDIAN = __LITTLE_ENDIAN; -pub const __INT_LEAST16_FMTi__ = c"hi"; +pub const __INT_LEAST16_FMTi__ = "hi"; pub const __GCC_ATOMIC_SHORT_LOCK_FREE = 2; pub const MAGICK_OFF_F = MAGICK_INT64_F; pub const _STDLIB_H = 1; @@ -3494,7 +3494,7 @@ pub const __MMX__ = 1; pub const __HAVE_FLOAT64 = 1; pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 = 1; pub const BYTE_ORDER = __BYTE_ORDER; -pub const __SIZE_FMTX__ = c"lX"; +pub const __SIZE_FMTX__ = "lX"; pub const __ID_T_TYPE = __U32_TYPE; pub const _THREAD_SHARED_TYPES_H = 1; pub const MinBlobExtent = c_long(32768); @@ -3510,20 +3510,20 @@ pub const __STDC_IEC_559_COMPLEX__ = 1; pub const __USE_MISC = 1; pub const __FSBLKCNT64_T_TYPE = __UQUAD_TYPE; pub const __SIZEOF_PTHREAD_ATTR_T = 56; -pub const __PTRDIFF_FMTd__ = c"ld"; +pub const __PTRDIFF_FMTd__ = "ld"; pub const __DBL_MIN_EXP__ = -1021; -pub const MAGICK_UINT32_F = c""; +pub const MAGICK_UINT32_F = ""; pub const __lldiv_t_defined = 1; pub const __HAVE_FLOAT32X = 1; pub const __FLT_EVAL_METHOD__ = 0; pub const __USECONDS_T_TYPE = __U32_TYPE; pub const __SSE_MATH__ = 1; pub const __PID_T_TYPE = __S32_TYPE; -pub const __UINT_FAST8_FMTo__ = c"hho"; +pub const __UINT_FAST8_FMTo__ = "hho"; pub const __UINT_LEAST64_MAX__ = c_ulong(18446744073709551615); pub const SignatureSize = 64; pub const _ALLOCA_H = 1; -pub const __UINT_LEAST64_FMTx__ = c"lx"; +pub const __UINT_LEAST64_FMTx__ = "lx"; pub const __INT8_MAX__ = 127; pub const __NLINK_T_TYPE = __SYSCALL_ULONG_TYPE; pub const __DBL_HAS_DENORM__ = 1; @@ -3535,7 +3535,7 @@ pub const __DBL_DECIMAL_DIG__ = 17; pub const __XSAVEC__ = 1; pub const __SIZEOF_SHORT__ = 2; pub const ____FILE_defined = 1; -pub const __UINT16_FMTX__ = c"hX"; +pub const __UINT16_FMTX__ = "hX"; pub const __UINT_FAST16_MAX__ = 65535; pub const __PTHREAD_MUTEX_HAVE_PREV = 1; pub const __timeval_defined = 1; @@ -3561,7 +3561,7 @@ pub const __LONG_MAX__ = c_long(9223372036854775807); pub const __STDC_HOSTED__ = 1; pub const __pic__ = 2; pub const __PTRDIFF_WIDTH__ = 64; -pub const __INT_FAST16_FMTi__ = c"hi"; +pub const __INT_FAST16_FMTi__ = "hi"; pub const __INT_LEAST32_TYPE__ = int; pub const __SCHAR_MAX__ = 127; pub const __USE_POSIX2 = 1; @@ -3590,7 +3590,7 @@ pub const __SIG_ATOMIC_MAX__ = 2147483647; pub const __struct_FILE_defined = 1; pub const _IO_EOF_SEEN = 16; pub const __USE_ATFILE = 1; -pub const __UINT64_FMTX__ = c"lX"; +pub const __UINT64_FMTX__ = "lX"; pub const __WALL = 1073741824; pub const __UINT64_MAX__ = c_ulong(18446744073709551615); pub const __DBL_MANT_DIG__ = 53; @@ -3599,34 +3599,34 @@ pub const _____fpos_t_defined = 1; pub const __INT_LEAST32_MAX__ = 2147483647; pub const __DBL_DIG__ = 15; pub const __GLIBC_USE_DEPRECATED_SCANF = 0; -pub const MagickLogFilename = c"log.mgk"; +pub const MagickLogFilename = "log.mgk"; pub const __ATOMIC_ACQUIRE = 2; pub const __OPENCL_MEMORY_SCOPE_WORK_GROUP = 1; pub const __USE_ISOC95 = 1; pub const __FLT16_HAS_DENORM__ = 1; pub const __UID_T_TYPE = __U32_TYPE; -pub const __UINT_FAST16_FMTu__ = c"hu"; -pub const __INTPTR_FMTi__ = c"li"; -pub const __UINT_FAST8_FMTX__ = c"hhX"; +pub const __UINT_FAST16_FMTu__ = "hu"; +pub const __INTPTR_FMTi__ = "li"; +pub const __UINT_FAST8_FMTX__ = "hhX"; pub const __LITTLE_ENDIAN__ = 1; pub const __SSE__ = 1; pub const __FLT_HAS_QUIET_NAN__ = 1; pub const __SIZEOF_SIZE_T__ = 8; -pub const __UINT_LEAST16_FMTo__ = c"ho"; -pub const __UINT8_FMTo__ = c"hho"; +pub const __UINT_LEAST16_FMTo__ = "ho"; +pub const __UINT8_FMTo__ = "hho"; pub const MagickSizeType = magick_int64_t; pub const __HAVE_FLOAT32 = 1; -pub const __UINT_LEAST16_FMTx__ = c"hx"; +pub const __UINT_LEAST16_FMTx__ = "hx"; pub const __CLANG_ATOMIC_WCHAR_T_LOCK_FREE = 2; pub const MagickFalse = 0; -pub const __UINT_FAST16_FMTX__ = c"hX"; -pub const __UINT_FAST32_FMTx__ = c"x"; -pub const __VERSION__ = c"4.2.1 Compatible Clang 8.0.0 (tags/RELEASE_800/final)"; -pub const MagickQuantumDepth = c"Q16"; +pub const __UINT_FAST16_FMTX__ = "hX"; +pub const __UINT_FAST32_FMTx__ = "x"; +pub const __VERSION__ = "4.2.1 Compatible Clang 8.0.0 (tags/RELEASE_800/final)"; +pub const MagickQuantumDepth = "Q16"; pub const __UINTPTR_MAX__ = c_ulong(18446744073709551615); -pub const __UINT_FAST8_FMTu__ = c"hhu"; -pub const __UINT_LEAST8_FMTu__ = c"hhu"; -pub const __UINT_LEAST64_FMTo__ = c"lo"; +pub const __UINT_FAST8_FMTu__ = "hhu"; +pub const __UINT_LEAST8_FMTu__ = "hhu"; +pub const __UINT_LEAST64_FMTo__ = "lo"; pub const __clockid_t_defined = 1; pub const __UINT_LEAST8_MAX__ = 255; pub const OpaqueOpacity = c_ulong(0); @@ -3649,22 +3649,22 @@ pub const __code_model_small_ = 1; pub const linux = 1; pub const __SIZEOF_WINT_T__ = 4; pub const DestroyDrawingWand = MagickDestroyDrawingWand; -pub const __UINTMAX_FMTo__ = c"lo"; +pub const __UINTMAX_FMTo__ = "lo"; pub const __FLT_DIG__ = 6; -pub const __UINT_LEAST8_FMTX__ = c"hhX"; +pub const __UINT_LEAST8_FMTX__ = "hhX"; pub const __INT16_MAX__ = 32767; pub const __HAVE_FLOAT64X = 1; -pub const MagickReleaseDate = c"2019-06-15"; +pub const MagickReleaseDate = "2019-06-15"; pub const __HAVE_FLOAT16 = 0; pub const __WINT_UNSIGNED__ = 1; pub const __FLT_MAX_10_EXP__ = 38; -pub const MAGICK_UINTPTR_F = c"l"; +pub const MAGICK_UINTPTR_F = "l"; pub const _FEATURES_H = 1; pub const __CLANG_ATOMIC_POINTER_LOCK_FREE = 2; -pub const __UINTPTR_FMTX__ = c"lX"; -pub const __UINT_LEAST16_FMTu__ = c"hu"; +pub const __UINTPTR_FMTX__ = "lX"; +pub const __UINT_LEAST16_FMTu__ = "hu"; pub const __WINT_WIDTH__ = 32; -pub const MagickChangeDate = c"20190615"; +pub const MagickChangeDate = "20190615"; pub const __F16C__ = 1; pub const AreaResource = UndefinedResource; pub const __SHRT_MAX__ = 32767; @@ -3675,7 +3675,7 @@ pub const __POINTER_WIDTH__ = 64; pub const __PTRDIFF_MAX__ = c_long(9223372036854775807); pub const __tune_corei7__ = 1; pub const __FLT16_DIG__ = 3; -pub const __INT32_FMTd__ = c"d"; +pub const __INT32_FMTd__ = "d"; pub const __DBL_MIN__ = 0.000000; pub const __SIZEOF_LONG__ = 8; pub const __S32_TYPE = int; @@ -3686,7 +3686,7 @@ pub const __INT_FAST32_TYPE__ = int; pub const __TIME64_T_TYPE = __TIME_T_TYPE; pub const __W_CONTINUED = 65535; pub const __NO_INLINE__ = 1; -pub const __UINT_FAST32_FMTX__ = c"X"; +pub const __UINT_FAST32_FMTX__ = "X"; pub const _POSIX_SOURCE = 1; pub const __LITTLE_ENDIAN = 1234; pub const __HAVE_FLOAT128 = 0; @@ -3694,7 +3694,7 @@ pub const __gnu_linux__ = 1; pub const __INT_FAST32_MAX__ = 2147483647; pub const _BITS_PTHREADTYPES_COMMON_H = 1; pub const __corei7__ = 1; -pub const __UINTMAX_FMTu__ = c"lu"; +pub const __UINTMAX_FMTu__ = "lu"; pub const __BMI__ = 1; pub const __FILE_defined = 1; pub const CloneDrawingWand = MagickCloneDrawingWand; @@ -3714,7 +3714,7 @@ pub const _STRUCT_TIMESPEC = 1; pub const _BITS_STDINT_INTN_H = 1; pub const __FLT16_DECIMAL_DIG__ = 5; pub const __PRAGMA_REDEFINE_EXTNAME = 1; -pub const __INT_FAST8_FMTd__ = c"hhd"; +pub const __INT_FAST8_FMTd__ = "hhd"; pub const __KEY_T_TYPE = __S32_TYPE; pub const SEEK_SET = 0; pub const __INT32_TYPE__ = int; @@ -3723,14 +3723,14 @@ pub const __CPU_MASK_TYPE = __SYSCALL_ULONG_TYPE; pub const MagickFail = 0; pub const FOPEN_MAX = 16; pub const MAGICK_OPTIMIZE_FUNC = opt; -pub const MAGICK_INT64_F = c"l"; +pub const MAGICK_INT64_F = "l"; pub const __UINTMAX_WIDTH__ = 64; -pub const MAGICK_SSIZE_T_F = c"l"; +pub const MAGICK_SSIZE_T_F = "l"; pub const __PTHREAD_MUTEX_USE_UNION = 0; pub const __FLT_MIN__ = 0.000000; -pub const __INT64_FMTi__ = c"li"; -pub const __UINT_FAST64_FMTu__ = c"lu"; -pub const __INT8_FMTd__ = c"hhd"; +pub const __INT64_FMTi__ = "li"; +pub const __UINT_FAST64_FMTu__ = "lu"; +pub const __INT8_FMTd__ = "hhd"; pub const MagickLibVersion = 2301952; pub const __INT_FAST16_TYPE__ = short; pub const YCbCrColorspace = Rec601YCbCrColorspace; @@ -3739,38 +3739,38 @@ pub const __FLT_MAX_EXP__ = 128; pub const __XSAVE__ = 1; pub const __DBL_MAX_10_EXP__ = 308; pub const __LDBL_MIN__ = 0.000000; -pub const __INT_FAST64_FMTi__ = c"li"; -pub const __INT_LEAST8_FMTd__ = c"hhd"; +pub const __INT_FAST64_FMTi__ = "li"; +pub const __INT_LEAST8_FMTd__ = "hhd"; pub const __CLANG_ATOMIC_LLONG_LOCK_FREE = 2; pub const __FSFILCNT64_T_TYPE = __UQUAD_TYPE; pub const MAGICK_RANDOM_MAX = 4294967295; -pub const __UINT_LEAST32_FMTX__ = c"X"; +pub const __UINT_LEAST32_FMTX__ = "X"; pub const __PIC__ = 2; pub const __GID_T_TYPE = __U32_TYPE; -pub const MagickLibVersionText = c"1.3.32"; +pub const MagickLibVersionText = "1.3.32"; pub const __UINTMAX_MAX__ = c_ulong(18446744073709551615); -pub const __UINT_FAST16_FMTo__ = c"ho"; +pub const __UINT_FAST16_FMTo__ = "ho"; pub const _DEFAULT_SOURCE = 1; pub const __FD_SETSIZE = 1024; pub const __LDBL_DECIMAL_DIG__ = 21; -pub const __UINT_LEAST64_FMTX__ = c"lX"; +pub const __UINT_LEAST64_FMTX__ = "lX"; pub const __clang_minor__ = 0; pub const __LDBL_REDIR_DECL = name; pub const __OFF64_T_TYPE = __SQUAD_TYPE; pub const __SIZEOF_FLOAT128__ = 16; pub const __CLOCKID_T_TYPE = __S32_TYPE; -pub const __UINT_FAST64_FMTo__ = c"lo"; -pub const __SIZE_FMTx__ = c"lx"; +pub const __UINT_FAST64_FMTo__ = "lo"; +pub const __SIZE_FMTx__ = "lx"; pub const __DBL_MAX__ = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878; pub const __DBL_EPSILON__ = 0.000000; -pub const __UINT64_FMTx__ = c"lx"; -pub const MAGICK_UINTMAX_F = c"l"; -pub const P_tmpdir = c"/tmp"; +pub const __UINT64_FMTx__ = "lx"; +pub const MAGICK_UINTMAX_F = "l"; +pub const P_tmpdir = "/tmp"; pub const __BLKCNT_T_TYPE = __SYSCALL_SLONG_TYPE; pub const __CHAR_BIT__ = 8; pub const __WCOREFLAG = 128; pub const SEEK_END = 2; -pub const __INT16_FMTi__ = c"hi"; +pub const __INT16_FMTi__ = "hi"; pub const __SLONG32_TYPE = int; pub const SEEK_CUR = 1; pub const _DEBUG = 1; @@ -3778,14 +3778,14 @@ pub const __GNUC_MINOR__ = 2; pub const __restrict_arr = __restrict; pub const __UINT_FAST32_MAX__ = c_uint(4294967295); pub const __RLIM_T_MATCHES_RLIM64_T = 1; -pub const __UINT8_FMTX__ = c"hhX"; +pub const __UINT8_FMTX__ = "hhX"; pub const NFDBITS = __NFDBITS; pub const __FLT_EPSILON__ = 0.000000; pub const __UINTPTR_WIDTH__ = 64; pub const MAGICK_PIXELS_BGRA = 1; pub const __llvm__ = 1; pub const __UINT_FAST64_MAX__ = c_ulong(18446744073709551615); -pub const __INT_FAST32_FMTi__ = c"i"; +pub const __INT_FAST32_FMTi__ = "i"; pub const __WNOTHREAD = 536870912; pub const __time_t_defined = 1; pub const __FLT_HAS_INFINITY__ = 1; @@ -3794,18 +3794,18 @@ pub const __DADDR_T_TYPE = __S32_TYPE; pub const __AES__ = 1; pub const NULL = if (@typeId(@typeOf(0)) == @import("builtin").TypeId.Pointer) @ptrCast([*c]void, 0) else if (@typeId(@typeOf(0)) == @import("builtin").TypeId.Int) @intToPtr([*c]void, 0) else ([*c]void)(0); pub const __OFF_T_TYPE = __SYSCALL_SLONG_TYPE; -pub const __UINT8_FMTx__ = c"hhx"; +pub const __UINT8_FMTx__ = "hhx"; pub const __INTMAX_C_SUFFIX__ = L; pub const __ORDER_LITTLE_ENDIAN__ = 1234; pub const __time64_t = __time_t; pub const MagickRationalType = double; pub const DrawClearException = MagickDrawClearException; pub const __GCC_ATOMIC_CHAR16_T_LOCK_FREE = 2; -pub const __INT16_FMTd__ = c"hd"; -pub const __UINT32_FMTX__ = c"X"; +pub const __INT16_FMTd__ = "hd"; +pub const __UINT32_FMTX__ = "X"; pub const __SUSECONDS_T_TYPE = __SYSCALL_SLONG_TYPE; pub const HasX11 = 1; -pub const MAGICK_INT32_F = c""; +pub const MAGICK_INT32_F = ""; pub const __PTHREAD_MUTEX_NUSERS_AFTER_KIND = 0; pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 = 1; pub const MagickPass = 1; @@ -3821,25 +3821,25 @@ pub const EXIT_FAILURE = 1; pub const __USE_POSIX = 1; pub const __BIT_TYPES_DEFINED__ = 1; pub const TransparentOpacity = MaxRGB; -pub const __SIZE_FMTo__ = c"lo"; +pub const __SIZE_FMTo__ = "lo"; pub const __DBL_HAS_QUIET_NAN__ = 1; pub const __PDP_ENDIAN = 3412; -pub const __INT_FAST8_FMTi__ = c"hhi"; -pub const __UINT_LEAST32_FMTo__ = c"o"; +pub const __INT_FAST8_FMTi__ = "hhi"; +pub const __UINT_LEAST32_FMTo__ = "o"; pub const __STDC_UTF_16__ = 1; pub const __UINT_LEAST32_MAX__ = c_uint(4294967295); pub const __ATOMIC_RELEASE = 3; -pub const __UINT_FAST16_FMTx__ = c"hx"; +pub const __UINT_FAST16_FMTx__ = "hx"; pub const __UINTMAX_C_SUFFIX__ = UL; pub const __FLT_MIN_EXP__ = -125; pub const __SIZEOF_LONG_DOUBLE__ = 16; -pub const __UINT_LEAST64_FMTu__ = c"lu"; +pub const __UINT_LEAST64_FMTu__ = "lu"; pub const __ldiv_t_defined = 1; pub const __GCC_ATOMIC_LONG_LOCK_FREE = 2; pub const __ORDER_PDP_ENDIAN__ = 3412; pub const __SIZEOF_PTHREAD_BARRIER_T = 32; pub const __GLIBC_USE_IEC_60559_FUNCS_EXT = 0; -pub const __INT_FAST64_FMTd__ = c"ld"; +pub const __INT_FAST64_FMTd__ = "ld"; pub const FILENAME_MAX = 4096; pub const ExtendedUnsignedIntegralType = magick_uint64_t; pub const __CLANG_ATOMIC_LONG_LOCK_FREE = 2; @@ -3848,16 +3848,16 @@ pub const __INT16_TYPE__ = short; pub const __SSE2_MATH__ = 1; pub const __FLT_MANT_DIG__ = 24; pub const __GLIBC_USE_IEC_60559_TYPES_EXT = 0; -pub const __UINT_FAST64_FMTx__ = c"lx"; +pub const __UINT_FAST64_FMTx__ = "lx"; pub const __STDC__ = 1; pub const __HAVE_FLOAT64X_LONG_DOUBLE = 1; pub const __INT_FAST8_MAX__ = 127; -pub const __INTPTR_FMTd__ = c"ld"; +pub const __INTPTR_FMTd__ = "ld"; pub const __GNUC_PATCHLEVEL__ = 1; pub const __SIZE_WIDTH__ = 64; -pub const __UINT_LEAST8_FMTx__ = c"hhx"; +pub const __UINT_LEAST8_FMTx__ = "hhx"; pub const __MPX__ = 1; -pub const __INT_LEAST64_FMTi__ = c"li"; +pub const __INT_LEAST64_FMTi__ = "li"; pub const __HAVE_DISTINCT_FLOAT64 = 0; pub const __SSE4_2__ = 1; pub const __STDC_IEC_559__ = 1; @@ -3866,15 +3866,15 @@ pub const __INT_FAST16_MAX__ = 32767; pub const __USE_ISOC99 = 1; pub const __INTPTR_MAX__ = c_long(9223372036854775807); pub const __CLANG_ATOMIC_CHAR16_T_LOCK_FREE = 2; -pub const __UINT64_FMTu__ = c"lu"; +pub const __UINT64_FMTu__ = "lu"; pub const __have_pthread_attr_t = 1; pub const __BYTE_ORDER__ = __ORDER_LITTLE_ENDIAN__; pub const __SSE2__ = 1; pub const MaxMapDouble = 65535.000000; -pub const MAGICK_UINT64_F = c"l"; +pub const MAGICK_UINT64_F = "l"; pub const __INT_MAX__ = 2147483647; pub const __BLKSIZE_T_TYPE = __SYSCALL_SLONG_TYPE; -pub const __INTMAX_FMTi__ = c"li"; +pub const __INTMAX_FMTi__ = "li"; pub const __DBL_DENORM_MIN__ = 0.000000; pub const __clang_major__ = 8; pub const __FLT16_MANT_DIG__ = 11; @@ -3884,7 +3884,7 @@ pub const MaxRGBDouble = 65535.000000; pub const _POSIX_C_SOURCE = c_long(200809); pub const __FLT_DENORM_MIN__ = 0.000000; pub const __DBL_MAX_EXP__ = 1024; -pub const __INT8_FMTi__ = c"hhi"; +pub const __INT8_FMTi__ = "hhi"; pub const L_tmpnam = 20; pub const __BIG_ENDIAN = 4321; pub const __UINT_LEAST16_MAX__ = 65535; @@ -3898,17 +3898,17 @@ pub const __UINT_FAST8_MAX__ = 255; pub const __DBL_MIN_10_EXP__ = -307; pub const __GLIBC_USE_LIB_EXT2 = 0; pub const __SIZEOF_PTHREAD_MUTEX_T = 40; -pub const __UINT8_FMTu__ = c"hhu"; +pub const __UINT8_FMTu__ = "hhu"; pub const __OFF_T_MATCHES_OFF64_T = 1; pub const __RLIM64_T_TYPE = __UQUAD_TYPE; pub const __HAVE_FLOAT128X = 0; pub const __INT_FAST64_MAX__ = c_long(9223372036854775807); pub const __SSE3__ = 1; -pub const __UINT16_FMTu__ = c"hu"; +pub const __UINT16_FMTu__ = "hu"; pub const __ATOMIC_SEQ_CST = 5; -pub const __SIZE_FMTu__ = c"lu"; +pub const __SIZE_FMTu__ = "lu"; pub const __LDBL_MIN_EXP__ = -16381; -pub const __UINT_FAST32_FMTu__ = c"u"; +pub const __UINT_FAST32_FMTu__ = "u"; pub const DrawAllocateWand = MagickDrawAllocateWand; pub const __SSP_STRONG__ = 2; pub const __BYTE_ORDER = __LITTLE_ENDIAN; @@ -3925,12 +3925,12 @@ pub const __PCLMUL__ = 1; pub const __UINT8_MAX__ = 255; pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 = 1; pub const _IOLBF = 1; -pub const __UINT32_FMTx__ = c"x"; -pub const __UINT16_FMTo__ = c"ho"; +pub const __UINT32_FMTx__ = "x"; +pub const __UINT16_FMTo__ = "ho"; pub const __POPCNT__ = 1; pub const __OPENCL_MEMORY_SCOPE_DEVICE = 2; pub const __SIZEOF_PTHREAD_CONDATTR_T = 4; -pub const __UINT32_FMTu__ = c"u"; +pub const __UINT32_FMTu__ = "u"; pub const WNOHANG = 1; pub const __SIZEOF_PTHREAD_COND_T = 48; pub const __SIZEOF_POINTER__ = 8; @@ -3939,10 +3939,10 @@ pub const __SIZE_MAX__ = c_ulong(18446744073709551615); pub const __unix = 1; pub const _BITS_UINTN_IDENTITY_H = 1; pub const __GLIBC_USE_IEC_60559_BFP_EXT = 0; -pub const MagickPackageName = c"GraphicsMagick"; -pub const __INT_FAST16_FMTd__ = c"hd"; +pub const MagickPackageName = "GraphicsMagick"; +pub const __INT_FAST16_FMTd__ = "hd"; pub const unix = 1; -pub const __UINT_LEAST32_FMTu__ = c"u"; +pub const __UINT_LEAST32_FMTu__ = "u"; pub const __FLT_MAX__ = 340282346999999984391321947108527833088.000000; pub const __corei7 = 1; pub const BUFSIZ = 8192; @@ -3954,21 +3954,21 @@ pub const __unix__ = 1; pub const __x86_64__ = 1; pub const __LDBL_HAS_INFINITY__ = 1; pub const __WORDSIZE_TIME64_COMPAT32 = 1; -pub const __UINTMAX_FMTx__ = c"lx"; +pub const __UINTMAX_FMTx__ = "lx"; pub const __UINT64_C_SUFFIX__ = UL; pub const __GNU_LIBRARY__ = 6; pub const __INT_LEAST16_MAX__ = 32767; pub const __FLT_MIN_10_EXP__ = -37; pub const __clock_t_defined = 1; -pub const __UINT32_FMTo__ = c"o"; -pub const __UINTPTR_FMTo__ = c"lo"; +pub const __UINT32_FMTo__ = "o"; +pub const __UINTPTR_FMTo__ = "lo"; pub const _SYS_SELECT_H = 1; pub const MaxColormapSize = c_uint(65536); -pub const __INT_LEAST16_FMTd__ = c"hd"; -pub const __UINTPTR_FMTx__ = c"lx"; +pub const __INT_LEAST16_FMTd__ = "hd"; +pub const __UINTPTR_FMTx__ = "lx"; pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 = 1; pub const _IONBF = 2; -pub const __INT_LEAST64_FMTd__ = c"ld"; +pub const __INT_LEAST64_FMTd__ = "ld"; pub const _SYS_TYPES_H = 1; pub const __INT_LEAST16_TYPE__ = short; pub const __attribute_alloc_size__ = params; @@ -3988,24 +3988,24 @@ pub const __ADX__ = 1; pub const __LDBL_MAX_10_EXP__ = 4932; pub const L_ctermid = 9; pub const __SIZEOF_INT128__ = 16; -pub const __UINT_FAST8_FMTx__ = c"hhx"; +pub const __UINT_FAST8_FMTx__ = "hhx"; pub const __SIZEOF_PTHREAD_RWLOCK_T = 56; pub const __glibc_c99_flexarr_available = 1; pub const __linux = 1; pub const __sigset_t_defined = 1; -pub const __UINT16_FMTx__ = c"hx"; +pub const __UINT16_FMTx__ = "hx"; pub const MaxTreeDepth = 8; -pub const __UINTPTR_FMTu__ = c"lu"; -pub const __UINT_LEAST16_FMTX__ = c"hX"; +pub const __UINTPTR_FMTu__ = "lu"; +pub const __UINT_LEAST16_FMTX__ = "hX"; pub const __SIZEOF_PTHREAD_MUTEXATTR_T = 4; pub const __CLFLUSHOPT__ = 1; pub const __amd64__ = 1; -pub const __UINT_FAST32_FMTo__ = c"o"; +pub const __UINT_FAST32_FMTo__ = "o"; pub const __linux__ = 1; pub const __clang__ = 1; pub const __LP64__ = 1; pub const __SYSCALL_WORDSIZE = 64; -pub const __PTRDIFF_FMTi__ = c"li"; +pub const __PTRDIFF_FMTi__ = "li"; pub const __SSE4_1__ = 1; pub const __LDBL_DIG__ = 18; pub const __GCC_ATOMIC_CHAR32_T_LOCK_FREE = 2; @@ -4014,8 +4014,8 @@ pub const DefaultResizeFilter = LanczosFilter; pub const WCONTINUED = 8; pub const ReplaceCompositeOp = CopyCompositeOp; pub const __XSAVEOPT__ = 1; -pub const __UINT64_FMTo__ = c"lo"; -pub const __INT_FAST32_FMTd__ = c"d"; +pub const __UINT64_FMTo__ = "lo"; +pub const __INT_FAST32_FMTd__ = "d"; pub const __HAVE_DISTINCT_FLOAT128X = __HAVE_FLOAT128X; pub const _BITS_PTHREADTYPES_ARCH_H = 1; pub const BIG_ENDIAN = __BIG_ENDIAN; @@ -4031,25 +4031,25 @@ pub const __GLIBC__ = 2; pub const WUNTRACED = 2; pub const DefaultThumbnailFilter = BoxFilter; pub const __INTMAX_MAX__ = c_long(9223372036854775807); -pub const __UINT_LEAST32_FMTx__ = c"x"; +pub const __UINT_LEAST32_FMTx__ = "x"; pub const __WORDSIZE = 64; pub const MagickUnsignedType = magick_uint64_t; pub const __WCHAR_MAX__ = 2147483647; pub const __INT64_MAX__ = c_long(9223372036854775807); pub const WSTOPPED = 2; -pub const MAGICK_SIZE_T_F = c"l"; +pub const MAGICK_SIZE_T_F = "l"; pub const __CLANG_ATOMIC_CHAR32_T_LOCK_FREE = 2; -pub const MagickCopyright = c"Copyright (C) 2002-2019 GraphicsMagick Group.\nAdditional copyrights and licenses apply to this software.\nSee http://www.GraphicsMagick.org/www/Copyright.html for details."; +pub const MagickCopyright = "Copyright (C) 2002-2019 GraphicsMagick Group.\nAdditional copyrights and licenses apply to this software.\nSee http://www.GraphicsMagick.org/www/Copyright.html for details."; pub const __INT_LEAST64_MAX__ = c_long(9223372036854775807); pub const WNOWAIT = 16777216; -pub const __UINTMAX_FMTX__ = c"lX"; +pub const __UINTMAX_FMTX__ = "lX"; pub const __OPENCL_MEMORY_SCOPE_WORK_ITEM = 0; pub const __FLT_HAS_DENORM__ = 1; pub const __DECIMAL_DIG__ = __LDBL_DECIMAL_DIG__; pub const __SYSCALL_SLONG_TYPE = __SLONGWORD_TYPE; pub const __WCLONE = 2147483648; pub const __DEV_T_TYPE = __UQUAD_TYPE; -pub const __INT32_FMTi__ = c"i"; +pub const __INT32_FMTi__ = "i"; pub const __DBL_HAS_INFINITY__ = 1; pub const QuantumDepth = 16; pub const __FINITE_MATH_ONLY__ = 0; diff --git a/src/main.zig b/src/main.zig index 66f9cce..2642ddc 100644 --- a/src/main.zig +++ b/src/main.zig @@ -23,7 +23,7 @@ fn wrapInCmdList(allocator: *std.mem.Allocator, cmd: langs.Command) !langs.Comma } pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { - var stdout_file = try std.io.getStdOut(); + var stdout_file = std.io.getStdOut(); const stdout = &stdout_file.outStream().stream; const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path")); @@ -108,7 +108,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { while (true) { lang.reset(); - var rd_line = readline.readline(c"> "); + var rd_line = readline.readline("> "); if (rd_line == null) { std.debug.warn("leaving from eof\n"); break; diff --git a/src/runner.zig b/src/runner.zig index 869f0f5..0252d4b 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -72,7 +72,7 @@ pub const Runner = struct { const path = try self.resolveArg(path_or_argidx); const resolved_path = try std.fs.path.resolve( self.allocator, - [_][]const u8{path}, + &[_][]const u8{path}, ); return resolved_path; @@ -185,7 +185,7 @@ pub const Runner = struct { try image.saveTo(out_path); var proc = try std.ChildProcess.init( - [_][]const u8{ program, out_path }, + &[_][]const u8{ program, out_path }, self.allocator, ); defer proc.deinit(); From 182d368363a975e94e4d02f7032b9ba923677362 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 14 Jan 2020 22:31:20 -0300 Subject: [PATCH 046/182] fix for latest zig --- src/bmp_valid.zig | 2 +- src/custom.zig | 5 ++-- src/image.zig | 56 ++++++++++++++++++++------------------------- src/lang.zig | 26 ++++++++++----------- src/lv2_helpers.zig | 4 ++-- src/magick.zig | 6 ++--- src/main.zig | 9 ++++---- src/plugin.zig | 4 ++-- src/printer.zig | 4 ++-- src/runner.zig | 24 ++++++++----------- 10 files changed, 64 insertions(+), 76 deletions(-) diff --git a/src/bmp_valid.zig b/src/bmp_valid.zig index 81c6759..c4f9438 100644 --- a/src/bmp_valid.zig +++ b/src/bmp_valid.zig @@ -20,7 +20,7 @@ pub fn magicValid(magic: []const u8) !void { } if (!valid) { - std.debug.warn("\tINVALID HEADER: '{}'\n", magic); + std.debug.warn("\tINVALID HEADER: '{}'\n", .{magic}); return BMPValidError.InvalidMagic; } } diff --git a/src/custom.zig b/src/custom.zig index b748ac5..f346fa0 100644 --- a/src/custom.zig +++ b/src/custom.zig @@ -181,11 +181,10 @@ pub const Embed = struct { if (read_bytes < 0) { const st: i32 = c.sf_error(self.sndfile); - std.debug.warn( - "Failed to read {} ({})\n", + std.debug.warn("Failed to read {} ({})\n", .{ self.filepath, c.sf_error_number(st), - ); + }); return; } diff --git a/src/image.zig b/src/image.zig index d8b4dd3..ad48f61 100644 --- a/src/image.zig +++ b/src/image.zig @@ -32,11 +32,10 @@ pub fn sopen( const st: i32 = c.sf_error(file); if (st != 0) { - std.debug.warn( - "Failed to open {} ({})\n", + std.debug.warn("Failed to open {} ({})\n", .{ path, c.sf_error_number(st), - ); + }); return ImageError.OpenFail; } @@ -48,7 +47,7 @@ pub fn sopen( const frames_on_end_by_end = c.sf_seek(file, frames_on_end, c.SEEK_SET); std.testing.expectEqual(frames_on_end, frames_on_end_by_end); - std.debug.warn("frames on end: {}, frame on end (2): {}\n", frames_on_end, frames_on_end_by_end); + std.debug.warn("frames on end: {}, frame on end (2): {}\n", .{ frames_on_end, frames_on_end_by_end }); return file.?; } @@ -57,7 +56,7 @@ pub fn swrite(file: *c.SNDFILE, buf: [*]f32, frames: i64) !void { const count = c.sf_writef_float(file, buf, frames); if (count != frames) { - std.debug.warn("Wanted to write {}, got {}\n", frames, count); + std.debug.warn("Wanted to write {}, got {}\n", .{ frames, count }); return ImageError.WriteFail; } } @@ -69,7 +68,7 @@ pub fn sseek(file: *c.SNDFILE, offset: usize) void { std.testing.expectEqual(frames, frames_current); if (frames != offset_i64) { - std.debug.warn("failed to seek to {} (seeked {} frames, offset_i64={})\n", offset, frames, offset_i64); + std.debug.warn("failed to seek to {} (seeked {} frames, offset_i64={})\n", .{ offset, frames, offset_i64 }); } } @@ -180,11 +179,10 @@ pub const Image = struct { var st: i32 = c.sf_close(self.sndfile); if (st != 0) { - std.debug.warn( - "Failed to close {} ({})\n", + std.debug.warn("Failed to close {} ({})\n", .{ self.path, c.sf_error_number(st), - ); + }); } } @@ -221,7 +219,7 @@ pub const Image = struct { sseek(out_file, start); while (i <= end) : (i += buf.len) { - std.debug.warn("\t\ti={}, buf.len={}, end={}\n", i, buf.len, end); + std.debug.warn("\t\ti={}, buf.len={}, end={}\n", .{ i, buf.len, end }); sseek(self.sndfile, i); sseek(out_file, i); @@ -247,7 +245,7 @@ pub const Image = struct { fn getSeekPos(self: *Image, position: plugins.Position) plugins.SeekPos { const file_end = self.frames; var seek_pos = position.seekPos(file_end); - std.debug.warn("\tstart {} end {}\n", seek_pos.start, seek_pos.end); + std.debug.warn("\tstart {} end {}\n", .{ seek_pos.start, seek_pos.end }); return seek_pos; } @@ -260,12 +258,11 @@ pub const Image = struct { self.curpath = path; self.frames = @intCast(usize, in_fmt.frames); - std.debug.warn( - "\timage: reopened on '{}' (frames={}, fmt.frames={})\n", + std.debug.warn("\timage: reopened on '{}' (frames={}, fmt.frames={})\n", .{ self.curpath, self.frames, in_fmt.frames, - ); + }); } pub fn checkValid(self: *Image) !void { @@ -303,45 +300,42 @@ pub const Image = struct { var ports = try lv2.setupPorts(&ctx); if (ctx.n_audio_in > 2) { - std.debug.warn("plugin <{}> has more than two inputs.\n", plugin_uri); + std.debug.warn("plugin <{}> has more than two inputs.\n", .{plugin_uri}); return ImageError.InvalidPlugin; } if (ctx.n_audio_out > 2) { - std.debug.warn("plugin <{}> has more than two outputs.\n", plugin_uri); + std.debug.warn("plugin <{}> has more than two outputs.\n", .{plugin_uri}); return ImageError.InvalidPlugin; } // now, for each param for the plugin, we find its port, and set // the value for the port there. - var it = params.iterator(); - - while (it.next()) |param| { + for (params.toSlice()) |param| { var sym_cstr = try std.cstr.addNullByte(self.allocator, param.sym); defer self.allocator.free(sym_cstr); var sym = c.lilv_new_string(ctx.world, sym_cstr.ptr); const port = c.lilv_plugin_get_port_by_symbol(ctx.plugin, sym) orelse blk: { - std.debug.warn("assert fail: symbol {} not found on port\n", param.sym); + std.debug.warn("assert fail: symbol {} not found on port\n", .{param.sym}); return ImageError.InvalidSymbol; }; c.lilv_node_free(sym); var idx = c.lilv_port_get_index(ctx.plugin, port); - std.debug.warn( - "\tset sym={}, idx={} to val={}\n", + std.debug.warn("\tset sym={}, idx={} to val={}\n", .{ param.sym, idx, param.value, - ); + }); (&ports[idx]).value = param.value; } // now we need to generate a temporary file and put the output of // running the plugin on that file var tmpnam = try temporaryName(self.allocator); - std.debug.warn("\trunning plugin from '{}' to '{}'\n", self.curpath, tmpnam); + std.debug.warn("\trunning plugin from '{}' to '{}'\n", .{ self.curpath, tmpnam }); var out_fmt = mkSfInfo(); var out_file = try sopen(self.allocator, tmpnam, c.SFM_WRITE, &out_fmt); @@ -374,7 +368,7 @@ pub const Image = struct { sseek(self.sndfile, seek_pos.start); var i: usize = seek_pos.start; - std.debug.warn("\tseek pos start: {} end: {}\n", seek_pos.start, seek_pos.end); + std.debug.warn("\tseek pos start: {} end: {}\n", .{ seek_pos.start, seek_pos.end }); var inbuf = rctx.buffers.in; var outbuf = rctx.buffers.out; @@ -382,7 +376,7 @@ pub const Image = struct { while (i <= seek_pos.end) : (i += 1) { const read_bytes = c.sf_readf_float(self.sndfile, inbuf.ptr, 1); if (read_bytes == 0) { - std.debug.warn("WARN! reached EOF at idx={}\n", i); + std.debug.warn("WARN! reached EOF at idx={}\n", .{i}); break; } @@ -407,11 +401,11 @@ pub const Image = struct { try self.checkValid(); var time_taken = timer.read(); - std.debug.warn("\ttook {d:.2}ms running plugin\n", time_taken / std.time.millisecond); + std.debug.warn("\ttook {d:.2}ms running plugin\n", .{time_taken / std.time.millisecond}); } pub fn saveTo(self: *Image, out_path: []const u8) !void { - std.debug.warn("\timg: copy from '{}' to '{}'\n", self.curpath, out_path); + std.debug.warn("\timg: copy from '{}' to '{}'\n", .{ self.curpath, out_path }); try std.fs.copyFile(self.curpath, out_path); } @@ -440,7 +434,7 @@ pub const Image = struct { // the code here is a copypaste of runPlugin() without the specific // lilv things. var tmpnam = try temporaryName(self.allocator); - std.debug.warn("\trunning CUSTOM plugin from '{}' to '{}'\n", self.curpath, tmpnam); + std.debug.warn("\trunning CUSTOM plugin from '{}' to '{}'\n", .{ self.curpath, tmpnam }); var out_fmt = mkSfInfo(); var out_file = try sopen(self.allocator, tmpnam, c.SFM_WRITE, &out_fmt); @@ -469,7 +463,7 @@ pub const Image = struct { sseek(self.sndfile, seek_pos.start); var i: usize = seek_pos.start; - std.debug.warn("\tseek pos start: {} end: {}\n", seek_pos.start, seek_pos.end); + std.debug.warn("\tseek pos start: {} end: {}\n", .{ seek_pos.start, seek_pos.end }); var inbuf = bufs.in; var outbuf = bufs.out; @@ -477,7 +471,7 @@ pub const Image = struct { while (i <= seek_pos.end) : (i += 1) { const read_bytes = c.sf_readf_float(self.sndfile, bufs.in.ptr, 1); if (read_bytes == 0) { - std.debug.warn("WARN! reached EOF at idx={}\n", i); + std.debug.warn("WARN! reached EOF at idx={}\n", .{i}); break; } diff --git a/src/lang.zig b/src/lang.zig index 8063329..a50f738 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -41,14 +41,14 @@ pub const Command = struct { cur_idx: usize = 0, pub fn print(self: Command) void { - std.debug.warn("cmd:{}\n", self.command); + std.debug.warn("cmd:{}\n", .{self.command}); } pub fn argAt(self: Command, idx: usize) ![]const u8 { - std.debug.warn("{} {}", idx, self.args.len); + std.debug.warn("{} {}", .{ idx, self.args.len }); if (idx > (self.args.len - 1)) { - std.debug.warn("Expected argument at index {}\n", idx); + std.debug.warn("Expected argument at index {}\n", .{idx}); return ParseError.ArgRequired; } @@ -91,7 +91,7 @@ pub const Command = struct { while (i < elements) : (i += 1) { var value: f32 = self.floatArgAt(i) catch |err| blk: { - std.debug.warn("\tdoing default on arg {}\n", i); + std.debug.warn("\tdoing default on arg {}\n", .{i}); break :blk default; }; @@ -270,7 +270,7 @@ pub const Lang = struct { fn expectAny(self: *Lang, count: usize, args: ArgList) !void { if (args.len != count) { - self.doError("expected {} arguments, found {}", count, args.len); + self.doError("expected {} arguments, found {}", .{ count, args.len }); return error.ArgRequired; } } @@ -283,7 +283,7 @@ pub const Lang = struct { var i: usize = 0; if (args.len != count) { - self.doError("expected {} arguments, found {}", count, args.len); + self.doError("expected {} arguments, found {}", .{ count, args.len }); return error.ArgRequired; } @@ -291,7 +291,7 @@ pub const Lang = struct { var arg = args.at(i); _ = std.fmt.parseFloat(f32, arg) catch |err| { - std.debug.warn("failed to parse f32: {}\n", err); + std.debug.warn("failed to parse f32: {}\n", .{err}); return error.FloatParseFail; }; } @@ -318,14 +318,14 @@ pub const Lang = struct { .Write => try self.expectFloat(3, cmd.args), .Rotate => try self.expectAny(2, cmd.args), .Embed => try self.expectAny(3, cmd.args), - else => std.debug.warn("WARN unchecked command {}\n", cmd.command), + else => std.debug.warn("WARN unchecked command {}\n", .{cmd.command}), } } - fn doError(self: *Lang, comptime fmt: []const u8, args: ...) void { - std.debug.warn("error at line {}: ", self.line); + fn doError(self: *Lang, comptime fmt: []const u8, args: var) void { + std.debug.warn("error at line {}: ", .{self.line}); std.debug.warn(fmt, args); - std.debug.warn("\n"); + std.debug.warn("\n", .{}); self.has_error = true; } @@ -347,7 +347,7 @@ pub const Lang = struct { var cmd_opt = tok_it.next(); if (cmd_opt == null) { - self.doError("No command given"); + self.doError("No command given", .{}); continue; } var command = cmd_opt.?; @@ -357,7 +357,7 @@ pub const Lang = struct { if (ctype_opt) |ctype_val| { ctype = ctype_val; } else { - self.doError("Unknown command '{}' ({})", command, command.len); + self.doError("Unknown command '{}' ({})", .{ command, command.len }); continue; } diff --git a/src/lv2_helpers.zig b/src/lv2_helpers.zig index 825ea19..abc9c8f 100644 --- a/src/lv2_helpers.zig +++ b/src/lv2_helpers.zig @@ -116,7 +116,7 @@ pub fn setupPorts(ctx: *plugin.Context) ![]Port { if (c.lilv_port_is_a(ctx.plugin, lport, lv2_InputPort)) { port.is_input = true; } else if (!c.lilv_port_is_a(ctx.plugin, lport, lv2_OutputPort) and !port.optional) { - std.debug.warn("Port {} is neither input or output\n", i); + std.debug.warn("Port {} is neither input or output\n", .{i}); return error.UnassignedIOPort; } @@ -132,7 +132,7 @@ pub fn setupPorts(ctx: *plugin.Context) ![]Port { ctx.n_audio_out += 1; } } else if (!port.optional) { - std.debug.warn("Port {} has unsupported type\n", i); + std.debug.warn("Port {} has unsupported type\n", .{i}); return error.UnsupportedPortType; } } diff --git a/src/magick.zig b/src/magick.zig index fbaeef7..e7b582a 100644 --- a/src/magick.zig +++ b/src/magick.zig @@ -37,7 +37,7 @@ fn magickLoad(image: *Image) !MagickContext { var curpath = try std.cstr.addNullByte(image.allocator, image.curpath); defer image.allocator.free(curpath); - std.debug.warn("loading '{}'\n", curpath); + std.debug.warn("loading '{}'\n", .{curpath}); if (mc.MagickReadImage(mctx.wand, curpath.ptr) != 1) return error.MagickReadFail; @@ -52,12 +52,12 @@ fn magickSave(image: *Image, wand: *mc.MagickWand) !void { var c_tmpnam = try std.cstr.addNullByte(allocator, tmpnam); defer allocator.free(c_tmpnam); - std.debug.warn("\tmagick: saving to '{}'..", c_tmpnam); + std.debug.warn("\tmagick: saving to '{}'..", .{c_tmpnam}); if (mc.MagickWriteImage(wand, c_tmpnam.ptr) != 1) return error.MagickWriteFail; - std.debug.warn("OK\n"); + std.debug.warn("OK\n", .{}); try image.reopen(tmpnam); } diff --git a/src/main.zig b/src/main.zig index 2642ddc..1235607 100644 --- a/src/main.zig +++ b/src/main.zig @@ -51,8 +51,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { defer existing_cmds.deinit(); // copy the existing command list into the repl's command list - var it = existing_cmds.iterator(); - while (it.next()) |existing_cmd| { + for (existing_cmds.toSlice()) |existing_cmd| { try cmds.append(existing_cmd); } } else { @@ -110,7 +109,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { var rd_line = readline.readline("> "); if (rd_line == null) { - std.debug.warn("leaving from eof\n"); + std.debug.warn("leaving from eof\n", .{}); break; } readline.add_history(rd_line); @@ -138,14 +137,14 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { try printer.printList(cmds, stream); continue; } else if (std.mem.eql(u8, line, "quit") or std.mem.eql(u8, line, "q")) { - std.debug.warn("leaving\n"); + std.debug.warn("leaving\n", .{}); break; } else if (std.mem.startsWith(u8, line, "#")) { continue; } var cmds_parsed = lang.parse(line) catch |err| { - std.debug.warn("repl: error while parsing: {}\n", err); + std.debug.warn("repl: error while parsing: {}\n", .{err}); continue; }; current = cmds_parsed.at(0); diff --git a/src/plugin.zig b/src/plugin.zig index ebc7f03..6c98336 100644 --- a/src/plugin.zig +++ b/src/plugin.zig @@ -151,7 +151,7 @@ pub fn makeContext(allocator: *std.mem.Allocator, plugin_uri: []const u8) !Conte c.lilv_world_load_all(world); var uri: *c.LilvNode = c.lilv_new_uri(world, cstr_plugin_uri.ptr) orelse blk: { - std.debug.warn("Invalid plugin URI <{}>\n", plugin_uri); + std.debug.warn("Invalid plugin URI <{}>\n", .{plugin_uri}); return ImageError.InvalidPlugin; }; defer c.lilv_node_free(uri); @@ -159,7 +159,7 @@ pub fn makeContext(allocator: *std.mem.Allocator, plugin_uri: []const u8) !Conte const plugins: *const c.LilvPlugins = c.lilv_world_get_all_plugins(world); var plugin: *const c.LilvPlugin = c.lilv_plugins_get_by_uri(plugins, uri) orelse blk: { - std.debug.warn("Plugin <{}> not found\n", plugin_uri); + std.debug.warn("Plugin <{}> not found\n", .{plugin_uri}); return ImageError.UnknownPlugin; }; diff --git a/src/printer.zig b/src/printer.zig index f198579..a543325 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -29,10 +29,10 @@ pub fn printList(list: langs.CommandList, stream: var) !void { .Rotate => "rotate", }; - try stream.print("{}", command); + try stream.print("{}", .{command}); for (cmd.args.toSlice()) |arg| { - try stream.print(" {}", arg); + try stream.print(" {}", .{arg}); } try stream.write(";\n"); diff --git a/src/runner.zig b/src/runner.zig index 0252d4b..33cacb2 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -80,7 +80,7 @@ pub const Runner = struct { fn loadCmd(self: *Runner, path_or_argidx: []const u8) !void { var load_path = try self.resolveArgPath(path_or_argidx); - std.debug.warn("\tload path: {}\n", load_path); + std.debug.warn("\tload path: {}\n", .{load_path}); // we could use ImageMagick to convert from X to BMP // but i can't find an easy way to do things in memory. @@ -90,7 +90,7 @@ pub const Runner = struct { // krita/gimp and make it export a bmp and while in the program you can // apply filters, etc. if (!std.mem.endsWith(u8, load_path, ".bmp") and !std.mem.endsWith(u8, load_path, ".ppm")) { - std.debug.warn("Only BMP files are allowed to be loaded.\n"); + std.debug.warn("Only BMP files are allowed to be loaded.\n", .{}); return RunError.NoBMP; } @@ -104,7 +104,7 @@ pub const Runner = struct { if (self.image) |image| { return image; } else { - std.debug.warn("image is required!\n"); + std.debug.warn("image is required!\n", .{}); return RunError.ImageRequired; } } @@ -125,11 +125,9 @@ pub const Runner = struct { // starts_with would be "x_g", we want to find all files in the directory // that start with that name. - const starts_with = try std.fmt.allocPrint( - self.allocator, - "{}_g", + const starts_with = try std.fmt.allocPrint(self.allocator, "{}_g", .{ basename[0..period_idx], - ); + }); defer self.allocator.free(starts_with); var max: usize = 0; @@ -161,14 +159,12 @@ pub const Runner = struct { } } - const out_path = try std.fmt.allocPrint( - self.allocator, - "{}/{}{}{}", + const out_path = try std.fmt.allocPrint(self.allocator, "{}/{}{}{}", .{ dirname, starts_with, max + 1, extension, - ); + }); return out_path; } @@ -190,7 +186,7 @@ pub const Runner = struct { ); defer proc.deinit(); - std.debug.warn("running '{} {}'\n", program, out_path); + std.debug.warn("running '{} {}'\n", .{ program, out_path }); _ = try proc.spawnAndWait(); } @@ -221,7 +217,7 @@ pub const Runner = struct { defer params.deinit(); for (bands) |band_value, idx| { - var sym = try std.fmt.allocPrint(self.allocator, "band_{}", idx + 1); + var sym = try std.fmt.allocPrint(self.allocator, "band_{}", .{idx + 1}); try params.append(plugin.Param{ .sym = sym, .value = band_value, @@ -482,7 +478,7 @@ pub const Runner = struct { }, else => blk: { - std.debug.warn("Unsupported command: {}\n", cmd.command); + std.debug.warn("Unsupported command: {}\n", .{cmd.command}); break :blk RunError.UnknownCommand; }, }; From 9a6caa2453238ac3983b1541d20a3140deb252a4 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 25 Jan 2020 17:47:20 -0300 Subject: [PATCH 047/182] add gate cmd --- doc/README.md | 9 +++++++++ examples/gate.scri | 5 +++++ src/lang.zig | 2 ++ src/printer.zig | 1 + src/runner.zig | 16 ++++++++++++++++ 5 files changed, 33 insertions(+) create mode 100644 examples/gate.scri diff --git a/doc/README.md b/doc/README.md index c342bef..74a1445 100644 --- a/doc/README.md +++ b/doc/README.md @@ -178,3 +178,12 @@ with a suffix on the filename (before extension). Doing consecutive `quicksave`s will not overwrite any files, the suffixes will just be different. + +## `gate split index switch threshold attack hold decay gaterange` + + - switch (bool): 0..1, default 0 + - threshold (dB): -70..12, default -70 + - attack (ms): 0.1..500, default 30 + - hold (ms): 5..3000, default 500 + - decay (ms): 5..4000, default 1000 + - gaterange (dB): -90..-20, default -90 diff --git a/examples/gate.scri b/examples/gate.scri new file mode 100644 index 0000000..9269932 --- /dev/null +++ b/examples/gate.scri @@ -0,0 +1,5 @@ +load :0; +gate 5 1 0 1 100 500 1000 -50; +gate 5 2 1 1 100 500 1000 -50; +gate 5 3 1 1 150 1000 1000 -50; +quicksave; diff --git a/src/lang.zig b/src/lang.zig index a50f738..07e5fb1 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -26,6 +26,7 @@ pub const CommandType = enum { Delay, Vinyl, RevDelay, + Gate, Noise, WildNoise, @@ -184,6 +185,7 @@ pub const Lang = struct { _ = try self.keywords.put("delay", .Delay); _ = try self.keywords.put("vinyl", .Vinyl); _ = try self.keywords.put("revdelay", .RevDelay); + _ = try self.keywords.put("gate", .Gate); // custom implementations (not lv2) _ = try self.keywords.put("noise", .Noise); diff --git a/src/printer.zig b/src/printer.zig index a543325..faa863a 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -20,6 +20,7 @@ pub fn printList(list: langs.CommandList, stream: var) !void { .Delay => "delay", .Vinyl => "vinyl", .RevDelay => "revdelay", + .Gate => "gate", .Noise => "noise", .WildNoise => "wildnoise", diff --git a/src/runner.zig b/src/runner.zig index 33cacb2..44c9fb4 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -294,6 +294,11 @@ pub const Runner = struct { try magick.runRotate(image, deg, c_bgfill); } + fn gateCmd(self: *Runner, pos: Position, params: ParamList) !void { + var image = try self.getImage(); + try image.runPlugin("http://hippie.lt/lv2/gate", pos, params); + } + fn runCommand(self: *Runner, cmd: *lang.Command) !void { var params = ParamList.init(self.allocator); defer params.deinit(); @@ -477,6 +482,17 @@ pub const Runner = struct { try self.rotateCmd(deg, bgfill); }, + .Gate => { + const pos = try cmd.consumePosition(); + try cmd.appendParam(¶ms, "switch"); + try cmd.appendParam(¶ms, "threshold"); + try cmd.appendParam(¶ms, "attack"); + try cmd.appendParam(¶ms, "hold"); + try cmd.appendParam(¶ms, "decay"); + try cmd.appendParam(¶ms, "gaterange"); + try self.gateCmd(pos, params); + }, + else => blk: { std.debug.warn("Unsupported command: {}\n", .{cmd.command}); break :blk RunError.UnknownCommand; From 7c4dead5cf534e5628aef337409a974d7bdd228a Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 25 Jan 2020 18:52:45 -0300 Subject: [PATCH 048/182] add many experimental plugins --- README.md | 1 + doc/README.md | 58 ++++++++++++++++++++++++++++++++ examples/degrade.scri | 5 +++ examples/detune.scri | 3 ++ examples/gate.scri | 4 +-- examples/overdrive.scri | 5 +++ examples/repsycho.scri | 8 +++++ examples/talkbox.scri | 3 ++ src/lang.zig | 10 ++++++ src/printer.zig | 5 +++ src/runner.zig | 73 +++++++++++++++++++++++++++++++++++++++++ 11 files changed, 172 insertions(+), 3 deletions(-) create mode 100644 examples/degrade.scri create mode 100644 examples/detune.scri create mode 100644 examples/overdrive.scri create mode 100644 examples/repsycho.scri create mode 100644 examples/talkbox.scri diff --git a/README.md b/README.md index c289de8..d8e5ef9 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ glitch art "framework", ???????? language??? something? will likely be there by default) - the SWH plugins ( https://github.com/swh/lv2 ) - the Invada Studio plugins ( https://launchpad.net/invada-studio/ ) + - abGate plugin ```bash # build and install diff --git a/doc/README.md b/doc/README.md index 74a1445..bb312ee 100644 --- a/doc/README.md +++ b/doc/README.md @@ -181,9 +181,67 @@ just be different. ## `gate split index switch threshold attack hold decay gaterange` +**TODO:** find good parameters + - switch (bool): 0..1, default 0 - threshold (dB): -70..12, default -70 - attack (ms): 0.1..500, default 30 - hold (ms): 5..3000, default 500 - decay (ms): 5..4000, default 1000 - gaterange (dB): -90..-20, default -90 + +## `detune split index detune mix output latency` + +> A low-quality stereo pitch shifter for the sort of chorus and detune effects found on multi-effects hardware. + + - detune (cents, left channel is lowered in pitch, right channel is raised): 0..1, default 0.2 + - mix (wet/dry mix): 0..1, default 0.9 + - output (level trim): 0..1, default 0.5 + - latency (trade-off between latency and low-freq response): 0..1, default 0.5 + +other presets: + - stereo detune: 0.2 0.9 0.5 0.5 + - out of tune: 0.8 0.7 0.5 0.5 + + +## `overdrive split index drive muffle output` + +> Possible uses include adding body to drum loops, fuzz guitar, and that 'standing outside a nightclub' sound. This plug does not simulate valve distortion, and any attempt to process organ sounds through it will be extremely unrewarding! + + - drive (amount of distortion): 0..1, default 0 + - muffle (gentle low-pass filter): 0..1, default 0 + - output (level trim): 0..1, default 0.5 + +## `degrade split index headroom quant rate post_filt non_lin output` + +> Sample quality reduction + +**NOTE:** finding the right parameters is HARD for this plugin. + + - headroom (peak clipping threshold): 0..1, default 0.8 + - quant (bit depth, typically 8 or below for "telephone" quality): 0..1, default 0.5 + - rate (sample rate): 0..1, default 0.65 + - post_filt (low-pass filter to muffle the distortion): 0..1, default 0.9 + - non_lin (additional harmonic distortion "thickening"): 0..1, default 0.58 + - output: 0..1, default 0.5 + +## `repsycho split index tune fine decay thresh hold mix quality` + +**NOTE:** HARD to find good parameters + + - tune (coarse tune, semitones): 0..1, default 1 + - fine (fine tune, cents): 0..1, default 1 + - decay (adjust envelope of each trunk, a fast decay can be useful while setting up): 0..1, default 0.5 + - thresh (trigger level to divide the input into chunks): 0..1, default 0.6 + - hold (minimum chunk length): 0..1, default 0.45 + - mix (mix original signal with output): 0..1, default 1 + - quality (quality, bool. the high=1 setting uses smoother pitch-shifting and allows stereo): 0..1, default 0 + +## `talkbox split index wet dry carrier quality` + +> High resolution vocoder + + - wet: 0..1, default 0.5 + - dry: 0..1, default 0 + - carrier: 0..1, default 0 + - quality: 0..1, default 1 diff --git a/examples/degrade.scri b/examples/degrade.scri new file mode 100644 index 0000000..ccd1a2c --- /dev/null +++ b/examples/degrade.scri @@ -0,0 +1,5 @@ +load :0; +degrade 5 1 0.8 0.5 0.65 0.9 0.58 0.5; +degrade 5 2 0.1 1 0.65 0.5 0.5 0.4; +degrade 5 3 0.1 1 0.65 0.9 0.58 0.5; +quicksave; diff --git a/examples/detune.scri b/examples/detune.scri new file mode 100644 index 0000000..269e80d --- /dev/null +++ b/examples/detune.scri @@ -0,0 +1,3 @@ +load :0; +detune 3 1 0.2 0.9 0.5 0.5; +quicksave; diff --git a/examples/gate.scri b/examples/gate.scri index 9269932..7299d00 100644 --- a/examples/gate.scri +++ b/examples/gate.scri @@ -1,5 +1,3 @@ load :0; -gate 5 1 0 1 100 500 1000 -50; -gate 5 2 1 1 100 500 1000 -50; -gate 5 3 1 1 150 1000 1000 -50; +gate 3 1 0 -70 30 500 1000 -90; quicksave; diff --git a/examples/overdrive.scri b/examples/overdrive.scri new file mode 100644 index 0000000..585f8ad --- /dev/null +++ b/examples/overdrive.scri @@ -0,0 +1,5 @@ +load :0; +overdrive 5 1 0.5 0 0.4; +overdrive 5 2 0.6 0.2 0.3; +overdrive 5 3 0.7 0.3 0.2; +quicksave; diff --git a/examples/repsycho.scri b/examples/repsycho.scri new file mode 100644 index 0000000..757c728 --- /dev/null +++ b/examples/repsycho.scri @@ -0,0 +1,8 @@ +load :0; +repsycho 8 1 1 1 0.5 0.6 0.45 1 0; +repsycho 8 2 1 1 1 0.6 0.45 1 0; +repsycho 8 3 1 1 0.5 0.8 0.45 1 0; +repsycho 8 4 1 1 0.5 0.6 0.1 1 0; +repsycho 8 5 1 1 0.5 0.6 0.45 0.5 0; +repsycho 8 6 1 1 0.5 0.6 0.45 1 1; +quicksave; diff --git a/examples/talkbox.scri b/examples/talkbox.scri new file mode 100644 index 0000000..2f3c386 --- /dev/null +++ b/examples/talkbox.scri @@ -0,0 +1,3 @@ +load :0; +talkbox 3 1 0.5 0 0 1; +quicksave; diff --git a/src/lang.zig b/src/lang.zig index 07e5fb1..1ade59c 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -27,6 +27,11 @@ pub const CommandType = enum { Vinyl, RevDelay, Gate, + Detune, + Overdrive, + Degrade, + RePsycho, + TalkBox, Noise, WildNoise, @@ -186,12 +191,17 @@ pub const Lang = struct { _ = 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); // custom implementations (not lv2) _ = 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); // even more custom _ = try self.keywords.put("rotate", .Rotate); diff --git a/src/printer.zig b/src/printer.zig index faa863a..d685979 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -21,6 +21,11 @@ pub fn printList(list: langs.CommandList, stream: var) !void { .Vinyl => "vinyl", .RevDelay => "revdelay", .Gate => "gate", + .Detune => "detune", + .Overdrive => "overdrive", + .Degrade => "Degrade", + .RePsycho => "repsycho", + .TalkBox => "talkbox", .Noise => "noise", .WildNoise => "wildnoise", diff --git a/src/runner.zig b/src/runner.zig index 44c9fb4..86f6e06 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -299,6 +299,31 @@ pub const Runner = struct { try image.runPlugin("http://hippie.lt/lv2/gate", pos, params); } + fn detuneCmd(self: *Runner, pos: Position, params: ParamList) !void { + var image = try self.getImage(); + try image.runPlugin("http://drobilla.net/plugins/mda/Detune", pos, params); + } + + fn overdriveCmd(self: *Runner, pos: Position, params: ParamList) !void { + var image = try self.getImage(); + try image.runPlugin("http://drobilla.net/plugins/mda/Overdrive", pos, params); + } + + fn degradeCmd(self: *Runner, pos: Position, params: ParamList) !void { + var image = try self.getImage(); + try image.runPlugin("http://drobilla.net/plugins/mda/Degrade", pos, params); + } + + fn repsychoCmd(self: *Runner, pos: Position, params: ParamList) !void { + var image = try self.getImage(); + try image.runPlugin("http://drobilla.net/plugins/mda/RePsycho", pos, params); + } + + fn talkboxCmd(self: *Runner, pos: Position, params: ParamList) !void { + var image = try self.getImage(); + try image.runPlugin("http://drobilla.net/plugins/mda/TalkBox", pos, params); + } + fn runCommand(self: *Runner, cmd: *lang.Command) !void { var params = ParamList.init(self.allocator); defer params.deinit(); @@ -493,6 +518,54 @@ pub const Runner = struct { try self.gateCmd(pos, params); }, + .Detune => { + const pos = try cmd.consumePosition(); + try cmd.appendParam(¶ms, "detune"); + try cmd.appendParam(¶ms, "mix"); + try cmd.appendParam(¶ms, "output"); + try cmd.appendParam(¶ms, "latency"); + try self.detuneCmd(pos, params); + }, + + .Overdrive => { + const pos = try cmd.consumePosition(); + try cmd.appendParam(¶ms, "drive"); + try cmd.appendParam(¶ms, "muffle"); + try cmd.appendParam(¶ms, "output"); + try self.overdriveCmd(pos, params); + }, + + .Degrade => { + const pos = try cmd.consumePosition(); + try cmd.appendParam(¶ms, "headroom"); + try cmd.appendParam(¶ms, "quant"); + try cmd.appendParam(¶ms, "rate"); + try cmd.appendParam(¶ms, "post_filt"); + try cmd.appendParam(¶ms, "non_lin"); + try cmd.appendParam(¶ms, "output"); + try self.degradeCmd(pos, params); + }, + + .RePsycho => { + const pos = try cmd.consumePosition(); + try cmd.appendParam(¶ms, "tune"); + try cmd.appendParam(¶ms, "fine"); + try cmd.appendParam(¶ms, "decay"); + try cmd.appendParam(¶ms, "thresh"); + try cmd.appendParam(¶ms, "hold"); + try cmd.appendParam(¶ms, "mix"); + try cmd.appendParam(¶ms, "quality"); + try self.repsychoCmd(pos, params); + }, + + .TalkBox => { + const pos = try cmd.consumePosition(); + try cmd.appendParam(¶ms, "wet"); + try cmd.appendParam(¶ms, "dry"); + try cmd.appendParam(¶ms, "carrier"); + try cmd.appendParam(¶ms, "quality"); + try self.talkboxCmd(pos, params); + }, else => blk: { std.debug.warn("Unsupported command: {}\n", .{cmd.command}); break :blk RunError.UnknownCommand; From 7dae50b030fef9b08473c9253855d54056cbd4bf Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 25 Jan 2020 18:53:29 -0300 Subject: [PATCH 049/182] README: add note about MDA dep --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d8e5ef9..6abf427 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ glitch art "framework", ???????? language??? something? - the SWH plugins ( https://github.com/swh/lv2 ) - the Invada Studio plugins ( https://launchpad.net/invada-studio/ ) - abGate plugin + - MDA plugins ```bash # build and install From 5a0e6934e774e9b636c1cfe79043de1bf2aeb384 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 25 Jan 2020 22:45:37 -0300 Subject: [PATCH 050/182] add dyncomp cmd --- doc/README.md | 13 +++++++++++++ examples/degrade.scri | 9 ++++++--- src/lang.zig | 2 ++ src/printer.zig | 1 + src/runner.zig | 21 +++++++++++++++++++++ 5 files changed, 43 insertions(+), 3 deletions(-) diff --git a/doc/README.md b/doc/README.md index bb312ee..40d9976 100644 --- a/doc/README.md +++ b/doc/README.md @@ -245,3 +245,16 @@ other presets: - dry: 0..1, default 0 - carrier: 0..1, default 0 - quality: 0..1, default 1 + +## `dyncomp split index enable hold inputgain threshold ratio attack release gain_min gain_max rms` + + - enable (bool): 0..1, default 1 + - hold (bool): 0..1, default 0 + - inputgain (dB): -10..30, default 0 + - threshold (dB): -50..-10, default -30 + - ratio (???): 0..1, default 0 + - attack (seconds): 0.001..0.1, default 0.01 + - release (seconds): 0.03..3.0, default 0.3 + - gain\_min (dB): -20..40 + - gain\_max (dB): -20..40 + - rms (signal level, dB): -80..10 diff --git a/examples/degrade.scri b/examples/degrade.scri index ccd1a2c..09c04c0 100644 --- a/examples/degrade.scri +++ b/examples/degrade.scri @@ -1,5 +1,8 @@ load :0; -degrade 5 1 0.8 0.5 0.65 0.9 0.58 0.5; -degrade 5 2 0.1 1 0.65 0.5 0.5 0.4; -degrade 5 3 0.1 1 0.65 0.9 0.58 0.5; +degrade 8 1 0.8 0.5 0.65 0.9 0.58 0.5; +degrade 8 2 0.1 1 0.65 0.5 0.5 0.4; +degrade 8 3 0.1 1 0.65 0.9 0.58 0.5; +degrade 8 4 0 1 1 0 0 1; +degrade 8 5 0 1 1 0 0 0; +degrade 8 6 0 0 0 0 0 0; quicksave; diff --git a/src/lang.zig b/src/lang.zig index 1ade59c..02ce56a 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -32,6 +32,7 @@ pub const CommandType = enum { Degrade, RePsycho, TalkBox, + DynComp, Noise, WildNoise, @@ -202,6 +203,7 @@ pub const Lang = struct { _ = 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); diff --git a/src/printer.zig b/src/printer.zig index d685979..3d7a72b 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -26,6 +26,7 @@ pub fn printList(list: langs.CommandList, stream: var) !void { .Degrade => "Degrade", .RePsycho => "repsycho", .TalkBox => "talkbox", + .DynComp => "dyncomp", .Noise => "noise", .WildNoise => "wildnoise", diff --git a/src/runner.zig b/src/runner.zig index 86f6e06..34c77a1 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -324,6 +324,11 @@ pub const Runner = struct { try image.runPlugin("http://drobilla.net/plugins/mda/TalkBox", pos, params); } + fn dynCompCmd(self: *Runner, pos: Position, params: ParamList) !void { + var image = try self.getImage(); + try image.runPlugin("http://gareus.org/oss/lv2/darc#mono", pos, params); + } + fn runCommand(self: *Runner, cmd: *lang.Command) !void { var params = ParamList.init(self.allocator); defer params.deinit(); @@ -566,6 +571,22 @@ pub const Runner = struct { try cmd.appendParam(¶ms, "quality"); try self.talkboxCmd(pos, params); }, + + .DynComp => { + const pos = try cmd.consumePosition(); + try cmd.appendParam(¶ms, "enable"); + try cmd.appendParam(¶ms, "hold"); + try cmd.appendParam(¶ms, "inputgain"); + try cmd.appendParam(¶ms, "threshold"); + try cmd.appendParam(¶ms, "ratio"); + try cmd.appendParam(¶ms, "attack"); + try cmd.appendParam(¶ms, "release"); + try cmd.appendParam(¶ms, "gain_min"); + try cmd.appendParam(¶ms, "gain_max"); + try cmd.appendParam(¶ms, "rms"); + try self.dynCompCmd(pos, params); + }, + else => blk: { std.debug.warn("Unsupported command: {}\n", .{cmd.command}); break :blk RunError.UnknownCommand; From 519eb51206036098d8e63e62735b003efccaa0a5 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 25 Jan 2020 22:46:00 -0300 Subject: [PATCH 051/182] remove heap allocation for RunBuffers --- src/image.zig | 27 ++++++++++++++++----------- src/plugin.zig | 46 ++++++++++++++++------------------------------ 2 files changed, 32 insertions(+), 41 deletions(-) diff --git a/src/image.zig b/src/image.zig index ad48f61..9541070 100644 --- a/src/image.zig +++ b/src/image.zig @@ -370,18 +370,25 @@ pub const Image = struct { var i: usize = seek_pos.start; std.debug.warn("\tseek pos start: {} end: {}\n", .{ seek_pos.start, seek_pos.end }); - var inbuf = rctx.buffers.in; - var outbuf = rctx.buffers.out; + var inbuf = &rctx.buffers.in; + var outbuf = &rctx.buffers.out; while (i <= seek_pos.end) : (i += 1) { - const read_bytes = c.sf_readf_float(self.sndfile, inbuf.ptr, 1); + inbuf[0] = 0; + inbuf[1] = 0; + + const read_bytes = c.sf_readf_float(self.sndfile, inbuf, 1); if (read_bytes == 0) { std.debug.warn("WARN! reached EOF at idx={}\n", .{i}); break; } + // trick plugins into having correct stereo signal from + // my mono input + inbuf[1] = inbuf[0]; + lv2.lilv_instance_run(rctx.instance, 1); - try swrite(out_file, outbuf.ptr, 1); + try swrite(out_file, outbuf, 1); } sseek(self.sndfile, seek_pos.end); @@ -439,9 +446,7 @@ pub const Image = struct { var out_fmt = mkSfInfo(); var out_file = try sopen(self.allocator, tmpnam, c.SFM_WRITE, &out_fmt); - var bufs = try plugins.RunBuffers.init(self.allocator); - defer bufs.deinit(); - + var bufs = plugins.RunBuffers{}; const seek_pos = self.getSeekPos(position); // make sure we start from 0 @@ -465,18 +470,18 @@ pub const Image = struct { var i: usize = seek_pos.start; std.debug.warn("\tseek pos start: {} end: {}\n", .{ seek_pos.start, seek_pos.end }); - var inbuf = bufs.in; - var outbuf = bufs.out; + var inbuf = &bufs.in; + var outbuf = &bufs.out; while (i <= seek_pos.end) : (i += 1) { - const read_bytes = c.sf_readf_float(self.sndfile, bufs.in.ptr, 1); + const read_bytes = c.sf_readf_float(self.sndfile, inbuf, 1); if (read_bytes == 0) { std.debug.warn("WARN! reached EOF at idx={}\n", .{i}); break; } plugin.run(&bufs); - try swrite(out_file, bufs.out.ptr, 1); + try swrite(out_file, outbuf, 1); } sseek(self.sndfile, seek_pos.end); diff --git a/src/plugin.zig b/src/plugin.zig index 6c98336..b979833 100644 --- a/src/plugin.zig +++ b/src/plugin.zig @@ -61,29 +61,11 @@ pub const Context = struct { /// Specific run context for non-plugins. pub const RunBuffers = struct { - allocator: *std.mem.Allocator, - - in: []f32, - out: []f32, - - pub fn init(allocator: *std.mem.Allocator) !RunBuffers { - // we allocate []f32 with size 2 to account for stereo plugins, however - // we only use &in_buf[0] and &out_buf[0], and don't use the - // (supposedly) right side of neither input or output. - var in_buf = try allocator.alloc(f32, 2); - std.mem.secureZero(f32, in_buf); - - return RunBuffers{ - .allocator = allocator, - .in = in_buf, - .out = try allocator.alloc(f32, 2), - }; - } - - pub fn deinit(self: *RunBuffers) void { - self.allocator.free(self.in); - self.allocator.free(self.out); - } + // we use [2]f32 to account for stereo plugins, however + // we only use in_buf[0] and out_buf[0], and don't use the + // (supposedly) right side of neither input or output. + in: [2]f32 = [_]f32{0} ** 2, + out: [2]f32 = [_]f32{0} ** 2, }; /// Represents the specific run context of plugin instantation. @@ -103,23 +85,19 @@ pub const RunContext = struct { } return RunContext{ - .buffers = try RunBuffers.init(allocator), + .buffers = RunBuffers{}, .instance = instance.?, }; } pub fn deinit(self: *RunContext) void { c.lilv_instance_free(self.instance); - self.buffers.deinit(); } pub fn connectPorts(self: *RunContext, ports: []lv2.Port) void { var i: usize = 0; var o: usize = 0; - var in_buf = self.buffers.in; - var out_buf = self.buffers.out; - for (ports) |_, p_idx| { var p = @intCast(u32, p_idx); var port: *lv2.Port = &ports[p_idx]; @@ -128,10 +106,18 @@ pub const RunContext = struct { .Control => lv2.lilv_instance_connect_port(self.instance, p, &port.value), .Audio => blk: { if (port.is_input) { - lv2.lilv_instance_connect_port(self.instance, p, &in_buf[i]); + lv2.lilv_instance_connect_port( + self.instance, + p, + &self.buffers.in[i], + ); i += 1; } else { - lv2.lilv_instance_connect_port(self.instance, p, &out_buf[o]); + lv2.lilv_instance_connect_port( + self.instance, + p, + &self.buffers.out[o], + ); o += 1; } }, From 046e43a68c5d3b83ec3803ee293927a1aefedc4b Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 25 Jan 2020 22:46:15 -0300 Subject: [PATCH 052/182] add dyncomp example file --- examples/dyncomp.scri | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 examples/dyncomp.scri diff --git a/examples/dyncomp.scri b/examples/dyncomp.scri new file mode 100644 index 0000000..d1d9e7b --- /dev/null +++ b/examples/dyncomp.scri @@ -0,0 +1,3 @@ +load :0; +dyncomp 3 1 1 0 0 -30 0 0.01 0.3 0 0 0; +quicksave; From fa8740e0db8b55affbace3fb62a82f4f7493139d Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 25 Jan 2020 23:32:24 -0300 Subject: [PATCH 053/182] add thruzero command --- doc/README.md | 11 +++++++++++ examples/thruzero.scri | 3 +++ src/lang.zig | 2 ++ src/printer.zig | 1 + src/runner.zig | 14 ++++++++++++++ 5 files changed, 31 insertions(+) create mode 100644 examples/thruzero.scri diff --git a/doc/README.md b/doc/README.md index 40d9976..5611dc3 100644 --- a/doc/README.md +++ b/doc/README.md @@ -258,3 +258,14 @@ other presets: - gain\_min (dB): -20..40 - gain\_max (dB): -20..40 - rms (signal level, dB): -80..10 + +## `thruzero split index + +> Tape flanger and ADT + +> This plug simulates tape-flanging, where two copies of a signal cancel out completely as the tapes pass each other. It can also be used for other "modulated delay" effects such as phasing and simple chorusing. + + - rate (modulation rate, set to minimum for static comb filtering): 0..1, default 0.3 + - mix (wet/dry mix, set to 50% for complete cancelling): 0..1, default 0.47 + - feedback (add positive or negative feedback for harsher or "ringing" sound): 0..1, default 0.3 + - depth_mod (modulation depth, set to less than 100% to limit build up of low frequencies with feedback): 0..1, default 1 diff --git a/examples/thruzero.scri b/examples/thruzero.scri new file mode 100644 index 0000000..99b4899 --- /dev/null +++ b/examples/thruzero.scri @@ -0,0 +1,3 @@ +load :0; +thruzero 3 1 0.3 0.47 0.3 1; +quicksave; diff --git a/src/lang.zig b/src/lang.zig index 02ce56a..67cbfcc 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -33,6 +33,7 @@ pub const CommandType = enum { RePsycho, TalkBox, DynComp, + ThruZero, Noise, WildNoise, @@ -195,6 +196,7 @@ pub const Lang = struct { _ = try self.keywords.put("detune", .Detune); _ = try self.keywords.put("overdrive", .Overdrive); _ = try self.keywords.put("talkbox", .TalkBox); + _ = try self.keywords.put("thruzero", .ThruZero); // custom implementations (not lv2) _ = try self.keywords.put("noise", .Noise); diff --git a/src/printer.zig b/src/printer.zig index 3d7a72b..b02f226 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -27,6 +27,7 @@ pub fn printList(list: langs.CommandList, stream: var) !void { .RePsycho => "repsycho", .TalkBox => "talkbox", .DynComp => "dyncomp", + .ThruZero => "thruzero", .Noise => "noise", .WildNoise => "wildnoise", diff --git a/src/runner.zig b/src/runner.zig index 34c77a1..ab02cd5 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -329,6 +329,11 @@ pub const Runner = struct { try image.runPlugin("http://gareus.org/oss/lv2/darc#mono", pos, params); } + fn thruZeroCmd(self: *Runner, pos: Position, params: ParamList) !void { + var image = try self.getImage(); + try image.runPlugin("http://drobilla.net/plugins/mda/ThruZero", pos, params); + } + fn runCommand(self: *Runner, cmd: *lang.Command) !void { var params = ParamList.init(self.allocator); defer params.deinit(); @@ -587,6 +592,15 @@ pub const Runner = struct { try self.dynCompCmd(pos, params); }, + .ThruZero => { + const pos = try cmd.consumePosition(); + try cmd.appendParam(¶ms, "rate"); + try cmd.appendParam(¶ms, "mix"); + try cmd.appendParam(¶ms, "feedback"); + try cmd.appendParam(¶ms, "depth_mod"); + try self.thruZeroCmd(pos, params); + }, + else => blk: { std.debug.warn("Unsupported command: {}\n", .{cmd.command}); break :blk RunError.UnknownCommand; From c73b7440a6e6de83f9615f864819c71396beea7d Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 25 Jan 2020 23:52:22 -0300 Subject: [PATCH 054/182] add foverdrive cmd - lang: remove oldGetCommand --- doc/README.md | 11 +++++-- examples/foverdrive.scri | 3 ++ src/lang.zig | 65 ++-------------------------------------- src/printer.zig | 1 + src/runner.zig | 11 +++++++ 5 files changed, 26 insertions(+), 65 deletions(-) create mode 100644 examples/foverdrive.scri diff --git a/doc/README.md b/doc/README.md index 5611dc3..b8f3a0a 100644 --- a/doc/README.md +++ b/doc/README.md @@ -23,7 +23,8 @@ where in the file you want the plugin to be ran. so, if you did `plugin 3 1...`, it would split the file in 3, then get the part that is of index 1 (starting at 0). -**Keep in mind parts start from the bottom of the file.** +**Keep in mind parts can start from either top or bottom of the image, +it depends of the file format** ## `load path_or_arg` @@ -259,7 +260,7 @@ other presets: - gain\_max (dB): -20..40 - rms (signal level, dB): -80..10 -## `thruzero split index +## `thruzero split index rate mix feedback depth_mod` > Tape flanger and ADT @@ -269,3 +270,9 @@ other presets: - mix (wet/dry mix, set to 50% for complete cancelling): 0..1, default 0.47 - feedback (add positive or negative feedback for harsher or "ringing" sound): 0..1, default 0.3 - depth_mod (modulation depth, set to less than 100% to limit build up of low frequencies with feedback): 0..1, default 1 + +## `foverdrive split index drive` + +Fast Overdrive from SWH plugins. + + - drive: 1..3, default 1 diff --git a/examples/foverdrive.scri b/examples/foverdrive.scri new file mode 100644 index 0000000..a4ac785 --- /dev/null +++ b/examples/foverdrive.scri @@ -0,0 +1,3 @@ +load :0; +foverdrive 3 1 100; +quicksave; diff --git a/src/lang.zig b/src/lang.zig index 67cbfcc..a0b1c9d 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -34,6 +34,7 @@ pub const CommandType = enum { TalkBox, DynComp, ThruZero, + Foverdrive, Noise, WildNoise, @@ -197,6 +198,7 @@ pub const Lang = struct { _ = try self.keywords.put("overdrive", .Overdrive); _ = try self.keywords.put("talkbox", .TalkBox); _ = try self.keywords.put("thruzero", .ThruZero); + _ = try self.keywords.put("foverdrive", .Foverdrive); // custom implementations (not lv2) _ = try self.keywords.put("noise", .Noise); @@ -221,69 +223,6 @@ pub const Lang = struct { } } - // NOTE this is fallback since std.AutoHashMap does not follow - // pointers anymore (in master). - fn oldGetCommand(self: *Lang, stmt: []const u8) ?CommandType { - const commands = [_][]const u8{ - "noop", - "load", - "quicksave", - "runqs", - "amp", - "rflanger", - "eq", - "phaser", - "mbeq", - "chorus", - "pitchscaler", - "reverb", - "highpass", - "delay", - "vinyl", - "revdelay", - "noise", - "wildnoise", - "write", - "embed", - "rotate", - }; - - const command_types = [_]CommandType{ - .Noop, - .Load, - .Quicksave, - .RunQS, - - .Amp, - .RFlanger, - .Eq, - .Phaser, - .Mbeq, - .Chorus, - .PitchScaler, - .Reverb, - .Highpass, - .Delay, - .Vinyl, - .RevDelay, - - .Noise, - .WildNoise, - .Write, - .Embed, - - .Rotate, - }; - - std.debug.assert(commands.len == command_types.len); - - for (commands) |command, idx| { - if (std.mem.eql(u8, stmt, command)) return command_types[idx]; - } - - return null; - } - fn expectAny(self: *Lang, count: usize, args: ArgList) !void { if (args.len != count) { self.doError("expected {} arguments, found {}", .{ count, args.len }); diff --git a/src/printer.zig b/src/printer.zig index b02f226..0ef6f5a 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -28,6 +28,7 @@ pub fn printList(list: langs.CommandList, stream: var) !void { .TalkBox => "talkbox", .DynComp => "dyncomp", .ThruZero => "thruzero", + .Foverdrive => "foverdrive", .Noise => "noise", .WildNoise => "wildnoise", diff --git a/src/runner.zig b/src/runner.zig index ab02cd5..e48220a 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -329,6 +329,11 @@ pub const Runner = struct { try image.runPlugin("http://gareus.org/oss/lv2/darc#mono", pos, params); } + fn foverdriveCmd(self: *Runner, pos: Position, params: ParamList) !void { + var image = try self.getImage(); + try image.runPlugin("http://plugin.org.uk/swh-plugins/foverdrive", pos, params); + } + fn thruZeroCmd(self: *Runner, pos: Position, params: ParamList) !void { var image = try self.getImage(); try image.runPlugin("http://drobilla.net/plugins/mda/ThruZero", pos, params); @@ -601,6 +606,12 @@ pub const Runner = struct { try self.thruZeroCmd(pos, params); }, + .Foverdrive => { + const pos = try cmd.consumePosition(); + try cmd.appendParam(¶ms, "drive"); + try self.foverdriveCmd(pos, params); + }, + else => blk: { std.debug.warn("Unsupported command: {}\n", .{cmd.command}); break :blk RunError.UnknownCommand; From 299a39fc27084c52bb780b02babe42fa9d105892 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 26 Jan 2020 00:03:15 -0300 Subject: [PATCH 055/182] add gverb cmd --- doc/README.md | 12 ++++++++++++ examples/gverb.scri | 3 +++ src/lang.zig | 2 ++ src/printer.zig | 1 + src/runner.zig | 17 +++++++++++++++++ 5 files changed, 35 insertions(+) create mode 100644 examples/gverb.scri diff --git a/doc/README.md b/doc/README.md index b8f3a0a..b3cc13c 100644 --- a/doc/README.md +++ b/doc/README.md @@ -276,3 +276,15 @@ other presets: Fast Overdrive from SWH plugins. - drive: 1..3, default 1 + +## `gverb split index roomsize revtime damping drylevel earlylevel taillevel` + +GVerb algorithm from SWH plugins. + + - roomsize (meters): 1..300, default 75.75 + - revtime (reverb time, seconds): 0.1..30, default 7.575 + - damping: 0..1, default 0.5 + - inputbandwidth: 0..1, default 0.75 + - drylevel (dB): -70..0, default 0 + - earlylevel (dB): -70..0, default 0 + - taillevel (dB): -70..0, default -17.5 diff --git a/examples/gverb.scri b/examples/gverb.scri new file mode 100644 index 0000000..f9aced0 --- /dev/null +++ b/examples/gverb.scri @@ -0,0 +1,3 @@ +load :0; +gverb 3 1 75.75 7.575 0.5 0.75 0 0 -17.5; +quicksave; diff --git a/src/lang.zig b/src/lang.zig index a0b1c9d..60bf549 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -35,6 +35,7 @@ pub const CommandType = enum { DynComp, ThruZero, Foverdrive, + Gverb, Noise, WildNoise, @@ -199,6 +200,7 @@ pub const Lang = struct { _ = try self.keywords.put("talkbox", .TalkBox); _ = try self.keywords.put("thruzero", .ThruZero); _ = try self.keywords.put("foverdrive", .Foverdrive); + _ = try self.keywords.put("gverb", .Gverb); // custom implementations (not lv2) _ = try self.keywords.put("noise", .Noise); diff --git a/src/printer.zig b/src/printer.zig index 0ef6f5a..1fb6c68 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -29,6 +29,7 @@ pub fn printList(list: langs.CommandList, stream: var) !void { .DynComp => "dyncomp", .ThruZero => "thruzero", .Foverdrive => "foverdrive", + .Gverb => "gverb", .Noise => "noise", .WildNoise => "wildnoise", diff --git a/src/runner.zig b/src/runner.zig index e48220a..451dac5 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -339,6 +339,11 @@ pub const Runner = struct { try image.runPlugin("http://drobilla.net/plugins/mda/ThruZero", pos, params); } + fn gverbCmd(self: *Runner, pos: Position, params: ParamList) !void { + var image = try self.getImage(); + try image.runPlugin("http://plugin.org.uk/swh-plugins/gverb", pos, params); + } + fn runCommand(self: *Runner, cmd: *lang.Command) !void { var params = ParamList.init(self.allocator); defer params.deinit(); @@ -612,6 +617,18 @@ pub const Runner = struct { try self.foverdriveCmd(pos, params); }, + .Gverb => { + const pos = try cmd.consumePosition(); + try cmd.appendParam(¶ms, "roomsize"); + try cmd.appendParam(¶ms, "revtime"); + try cmd.appendParam(¶ms, "damping"); + try cmd.appendParam(¶ms, "inputbandwidth"); + try cmd.appendParam(¶ms, "drylevel"); + try cmd.appendParam(¶ms, "earlylevel"); + try cmd.appendParam(¶ms, "taillevel"); + try self.gverbCmd(pos, params); + }, + else => blk: { std.debug.warn("Unsupported command: {}\n", .{cmd.command}); break :blk RunError.UnknownCommand; From 8c3c5a3ac2dce74b7bbd8c40427ab23ce65bd504 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 26 Jan 2020 00:13:53 -0300 Subject: [PATCH 056/182] add invert cmd --- doc/README.md | 4 ++++ examples/invert.scri | 3 +++ src/lang.zig | 2 ++ src/printer.zig | 1 + src/runner.zig | 10 ++++++++++ 5 files changed, 20 insertions(+) create mode 100644 examples/invert.scri diff --git a/doc/README.md b/doc/README.md index b3cc13c..cc77cd1 100644 --- a/doc/README.md +++ b/doc/README.md @@ -288,3 +288,7 @@ GVerb algorithm from SWH plugins. - drylevel (dB): -70..0, default 0 - earlylevel (dB): -70..0, default 0 - taillevel (dB): -70..0, default -17.5 + +## `invert split index` + +> A utility plugin that inverts the signal, also (wrongly) known as a 180 degree phase shift. diff --git a/examples/invert.scri b/examples/invert.scri new file mode 100644 index 0000000..bd7b695 --- /dev/null +++ b/examples/invert.scri @@ -0,0 +1,3 @@ +load :0; +invert 3 1; +quicksave; diff --git a/src/lang.zig b/src/lang.zig index 60bf549..2b022dd 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -36,6 +36,7 @@ pub const CommandType = enum { ThruZero, Foverdrive, Gverb, + Invert, Noise, WildNoise, @@ -201,6 +202,7 @@ pub const Lang = struct { _ = try self.keywords.put("thruzero", .ThruZero); _ = try self.keywords.put("foverdrive", .Foverdrive); _ = try self.keywords.put("gverb", .Gverb); + _ = try self.keywords.put("invert", .Invert); // custom implementations (not lv2) _ = try self.keywords.put("noise", .Noise); diff --git a/src/printer.zig b/src/printer.zig index 1fb6c68..0d75ea4 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -30,6 +30,7 @@ pub fn printList(list: langs.CommandList, stream: var) !void { .ThruZero => "thruzero", .Foverdrive => "foverdrive", .Gverb => "gverb", + .Invert => "invert", .Noise => "noise", .WildNoise => "wildnoise", diff --git a/src/runner.zig b/src/runner.zig index 451dac5..dd6d49e 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -344,6 +344,11 @@ pub const Runner = struct { try image.runPlugin("http://plugin.org.uk/swh-plugins/gverb", pos, params); } + fn invertCmd(self: *Runner, pos: Position, params: ParamList) !void { + var image = try self.getImage(); + try image.runPlugin("http://plugin.org.uk/swh-plugins/inv", pos, params); + } + fn runCommand(self: *Runner, cmd: *lang.Command) !void { var params = ParamList.init(self.allocator); defer params.deinit(); @@ -629,6 +634,11 @@ pub const Runner = struct { try self.gverbCmd(pos, params); }, + .Invert => { + const pos = try cmd.consumePosition(); + try self.gverbCmd(pos, params); + }, + else => blk: { std.debug.warn("Unsupported command: {}\n", .{cmd.command}); break :blk RunError.UnknownCommand; From a0a75579dd0c335346dec7d9597529c18035b220 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 26 Jan 2020 00:28:59 -0300 Subject: [PATCH 057/182] add tapedelay cmd (broken) --- doc/README.md | 19 +++++++++++++++++++ examples/tapedelay.scri | 3 +++ src/lang.zig | 2 ++ src/printer.zig | 1 + src/runner.zig | 25 +++++++++++++++++++++++++ 5 files changed, 50 insertions(+) create mode 100644 examples/tapedelay.scri diff --git a/doc/README.md b/doc/README.md index cc77cd1..4ce663a 100644 --- a/doc/README.md +++ b/doc/README.md @@ -292,3 +292,22 @@ GVerb algorithm from SWH plugins. ## `invert split index` > A utility plugin that inverts the signal, also (wrongly) known as a 180 degree phase shift. + +## `tapedelay split index` + +**TODO:** gives 0 output + +> Correctly models the tape motion and some of the smear effect, there is no simulation fo the head saturation yet, as I don't have a good model of it. When I get one I will add it. + +> The way the tape accelerates and decelerates gives a nicer delay effect for many purposes. + + - speed (inches/sec, 1=normal): 0..10, default 1 + - da\_db (dry level, dB): -90..0, default -90 + - t1d (tap 1 distance, inches): 0..4, default 0 + - t1a\_db (tap 1 level, dB): -90..0, default 0 + - t2d (tap 2 distance, inches): 0..4, default 1 + - t2a\_db (tap 2 level, dB): -90..0, default -90 + - t3d (tap 3 distance, inches): 0..4, default 2 + - t3a\_db (tap 3 level, dB): -90..0, default -90 + - t4d (tap 4 distance, inches): 0..4, default 3 + - t4a\_db (tap 4 level, dB): -90..0, default -90 diff --git a/examples/tapedelay.scri b/examples/tapedelay.scri new file mode 100644 index 0000000..4b5d8c0 --- /dev/null +++ b/examples/tapedelay.scri @@ -0,0 +1,3 @@ +load :0; +tapedelay 3 1 1 -90 0 0 1 -90 2 -90 3 -90; +quicksave; diff --git a/src/lang.zig b/src/lang.zig index 2b022dd..dd91bd6 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -37,6 +37,7 @@ pub const CommandType = enum { Foverdrive, Gverb, Invert, + TapeDelay, Noise, WildNoise, @@ -203,6 +204,7 @@ pub const Lang = struct { _ = try self.keywords.put("foverdrive", .Foverdrive); _ = try self.keywords.put("gverb", .Gverb); _ = try self.keywords.put("invert", .Invert); + _ = try self.keywords.put("tapedelay", .TapeDelay); // custom implementations (not lv2) _ = try self.keywords.put("noise", .Noise); diff --git a/src/printer.zig b/src/printer.zig index 0d75ea4..8491328 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -31,6 +31,7 @@ pub fn printList(list: langs.CommandList, stream: var) !void { .Foverdrive => "foverdrive", .Gverb => "gverb", .Invert => "invert", + .TapeDelay => "tapedelay", .Noise => "noise", .WildNoise => "wildnoise", diff --git a/src/runner.zig b/src/runner.zig index dd6d49e..7bc870d 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -349,6 +349,11 @@ pub const Runner = struct { try image.runPlugin("http://plugin.org.uk/swh-plugins/inv", pos, params); } + fn tapedelayCmd(self: *Runner, pos: Position, params: ParamList) !void { + var image = try self.getImage(); + try image.runPlugin("http://plugin.org.uk/swh-plugins/tapeDelay", pos, params); + } + fn runCommand(self: *Runner, cmd: *lang.Command) !void { var params = ParamList.init(self.allocator); defer params.deinit(); @@ -639,6 +644,26 @@ pub const Runner = struct { try self.gverbCmd(pos, params); }, + .TapeDelay => { + const pos = try cmd.consumePosition(); + try cmd.appendParam(¶ms, "speed"); + try cmd.appendParam(¶ms, "da_db"); + + try cmd.appendParam(¶ms, "t1d"); + try cmd.appendParam(¶ms, "t1a_db"); + + try cmd.appendParam(¶ms, "t2d"); + try cmd.appendParam(¶ms, "t2a_db"); + + try cmd.appendParam(¶ms, "t3d"); + try cmd.appendParam(¶ms, "t3a_db"); + + try cmd.appendParam(¶ms, "t4d"); + try cmd.appendParam(¶ms, "t4a_db"); + + try self.tapedelayCmd(pos, params); + }, + else => blk: { std.debug.warn("Unsupported command: {}\n", .{cmd.command}); break :blk RunError.UnknownCommand; From 127ea389fd1f2a2572b74ef8247d53f8a49ea26a Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 26 Jan 2020 02:05:43 -0300 Subject: [PATCH 058/182] add moddelay cmd --- doc/README.md | 8 +++++++- examples/moddelay.scri | 3 +++ src/lang.zig | 2 ++ src/printer.zig | 1 + src/runner.zig | 11 +++++++++++ 5 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 examples/moddelay.scri diff --git a/doc/README.md b/doc/README.md index 4ce663a..d0509c0 100644 --- a/doc/README.md +++ b/doc/README.md @@ -293,7 +293,7 @@ GVerb algorithm from SWH plugins. > A utility plugin that inverts the signal, also (wrongly) known as a 180 degree phase shift. -## `tapedelay split index` +## `tapedelay split index speed da_db t1d t1a_db...` **TODO:** gives 0 output @@ -311,3 +311,9 @@ GVerb algorithm from SWH plugins. - t3a\_db (tap 3 level, dB): -90..0, default -90 - t4d (tap 4 distance, inches): 0..4, default 3 - t4a\_db (tap 4 level, dB): -90..0, default -90 + +## `moddelay split index` + +> A delay whose tap can be modulated at audio rate. + + - base (base delay, seconds): 0..1, default 1 diff --git a/examples/moddelay.scri b/examples/moddelay.scri new file mode 100644 index 0000000..202cafb --- /dev/null +++ b/examples/moddelay.scri @@ -0,0 +1,3 @@ +load :0; +moddelay 3 1 1; +quicksave; diff --git a/src/lang.zig b/src/lang.zig index dd91bd6..ae3e8cd 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -38,6 +38,7 @@ pub const CommandType = enum { Gverb, Invert, TapeDelay, + ModDelay, Noise, WildNoise, @@ -205,6 +206,7 @@ pub const Lang = struct { _ = try self.keywords.put("gverb", .Gverb); _ = try self.keywords.put("invert", .Invert); _ = try self.keywords.put("tapedelay", .TapeDelay); + _ = try self.keywords.put("moddelay", .ModDelay); // custom implementations (not lv2) _ = try self.keywords.put("noise", .Noise); diff --git a/src/printer.zig b/src/printer.zig index 8491328..6dfc508 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -32,6 +32,7 @@ pub fn printList(list: langs.CommandList, stream: var) !void { .Gverb => "gverb", .Invert => "invert", .TapeDelay => "tapedelay", + .ModDelay => "moddelay", .Noise => "noise", .WildNoise => "wildnoise", diff --git a/src/runner.zig b/src/runner.zig index 7bc870d..3a9a007 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -354,6 +354,11 @@ pub const Runner = struct { try image.runPlugin("http://plugin.org.uk/swh-plugins/tapeDelay", pos, params); } + fn moddelayCmd(self: *Runner, pos: Position, params: ParamList) !void { + var image = try self.getImage(); + try image.runPlugin("http://plugin.org.uk/swh-plugins/modDelay", pos, params); + } + fn runCommand(self: *Runner, cmd: *lang.Command) !void { var params = ParamList.init(self.allocator); defer params.deinit(); @@ -664,6 +669,12 @@ pub const Runner = struct { try self.tapedelayCmd(pos, params); }, + .ModDelay => { + const pos = try cmd.consumePosition(); + try cmd.appendParam(¶ms, "base"); + try self.moddelayCmd(pos, params); + }, + else => blk: { std.debug.warn("Unsupported command: {}\n", .{cmd.command}); break :blk RunError.UnknownCommand; From bc8ab986898a16068180f44206e08d6f17402e90 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 26 Jan 2020 14:03:01 -0300 Subject: [PATCH 059/182] add multichorus cmd --- README.md | 1 + doc/README.md | 22 +++++++++++++++++++++- examples/multichorus.scri | 3 +++ src/lang.zig | 2 ++ src/printer.zig | 1 + src/runner.zig | 25 +++++++++++++++++++++++++ 6 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 examples/multichorus.scri diff --git a/README.md b/README.md index 6abf427..dba4162 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ glitch art "framework", ???????? language??? something? - the Invada Studio plugins ( https://launchpad.net/invada-studio/ ) - abGate plugin - MDA plugins + - Calf plugins ```bash # build and install diff --git a/doc/README.md b/doc/README.md index d0509c0..8ae3743 100644 --- a/doc/README.md +++ b/doc/README.md @@ -312,8 +312,28 @@ GVerb algorithm from SWH plugins. - t4d (tap 4 distance, inches): 0..4, default 3 - t4a\_db (tap 4 level, dB): -90..0, default -90 -## `moddelay split index` +## `moddelay split index base` > A delay whose tap can be modulated at audio rate. - base (base delay, seconds): 0..1, default 1 + +## `multichorus split index min_delay mod_depth mod_rate stereo voices vphase amount dry freq freq2 q overlap level_in level_out lfo` + +Calf Multi Chorus + + - `min_delay` (ms): 0.1..10, default 5 + - `mod_depth` (ms): 0.1..10, default 6 + - `mod_rate` (hz): 0.1..20, default 0.1 + - `stereo` (degrees): 0..360, default 180 + - `voices`: 1..8, default 4 + - `vphase` (inter-voice phase, degrees): 0..360, default 64 + - `amount`: 0..4, default 0.5 + - `dry`: 0..4, default 0.5 + - `freq` (center frq 1, hz): 10..20000, default 100 + - `freq2` (center frq 2, hz): 10..20000, default 5000 + - `q` (???): 0.125..8, default 0.125 + - `overlap`: 0..1, default 0.75 + - `level_in` (Input Gain): 0.0156250..64, default 1 + - `level_out` (Output Gain): 0.0156250..64, default 1 + - `lfo` (toggle): 0..1, default 1 diff --git a/examples/multichorus.scri b/examples/multichorus.scri new file mode 100644 index 0000000..2355d16 --- /dev/null +++ b/examples/multichorus.scri @@ -0,0 +1,3 @@ +load :0; +multichorus 3 1 5 6 0.1 180 4 64 0.5 0.5 100 5000 0.125 0.75 1 1 1; +quicksave; diff --git a/src/lang.zig b/src/lang.zig index ae3e8cd..b652617 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -39,6 +39,7 @@ pub const CommandType = enum { Invert, TapeDelay, ModDelay, + MultiChorus, Noise, WildNoise, @@ -207,6 +208,7 @@ pub const Lang = struct { _ = try self.keywords.put("invert", .Invert); _ = try self.keywords.put("tapedelay", .TapeDelay); _ = try self.keywords.put("moddelay", .ModDelay); + _ = try self.keywords.put("multichorus", .MultiChorus); // custom implementations (not lv2) _ = try self.keywords.put("noise", .Noise); diff --git a/src/printer.zig b/src/printer.zig index 6dfc508..08734b3 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -33,6 +33,7 @@ pub fn printList(list: langs.CommandList, stream: var) !void { .Invert => "invert", .TapeDelay => "tapedelay", .ModDelay => "moddelay", + .MultiChorus => "multichorus", .Noise => "noise", .WildNoise => "wildnoise", diff --git a/src/runner.zig b/src/runner.zig index 3a9a007..5856d7d 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -359,6 +359,11 @@ pub const Runner = struct { try image.runPlugin("http://plugin.org.uk/swh-plugins/modDelay", pos, params); } + fn multichorusCmd(self: *Runner, pos: Position, params: ParamList) !void { + var image = try self.getImage(); + try image.runPlugin("http://calf.sourceforge.net/plugins/MultiChorus", pos, params); + } + fn runCommand(self: *Runner, cmd: *lang.Command) !void { var params = ParamList.init(self.allocator); defer params.deinit(); @@ -675,6 +680,26 @@ pub const Runner = struct { try self.moddelayCmd(pos, params); }, + .MultiChorus => { + const pos = try cmd.consumePosition(); + try cmd.appendParam(¶ms, "min_delay"); + try cmd.appendParam(¶ms, "mod_depth"); + try cmd.appendParam(¶ms, "mod_rate"); + try cmd.appendParam(¶ms, "stereo"); + try cmd.appendParam(¶ms, "voices"); + try cmd.appendParam(¶ms, "vphase"); + try cmd.appendParam(¶ms, "amount"); + try cmd.appendParam(¶ms, "dry"); + try cmd.appendParam(¶ms, "freq"); + try cmd.appendParam(¶ms, "freq2"); + try cmd.appendParam(¶ms, "q"); + try cmd.appendParam(¶ms, "overlap"); + try cmd.appendParam(¶ms, "level_in"); + try cmd.appendParam(¶ms, "level_out"); + try cmd.appendParam(¶ms, "lfo"); + try self.multichorusCmd(pos, params); + }, + else => blk: { std.debug.warn("Unsupported command: {}\n", .{cmd.command}); break :blk RunError.UnknownCommand; From 08d9923e756eff418c92f94efc5baaa8accb55ca Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 26 Jan 2020 14:50:50 -0300 Subject: [PATCH 060/182] add saturator, vintagedelay cmd --- doc/README.md | 40 ++++++++++++++++++++++++ examples/saturator.scri | 3 ++ examples/vintagedelay.scri | 3 ++ src/lang.zig | 4 +++ src/printer.zig | 2 ++ src/runner.zig | 62 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 114 insertions(+) create mode 100644 examples/saturator.scri create mode 100644 examples/vintagedelay.scri diff --git a/doc/README.md b/doc/README.md index 8ae3743..c02ebda 100644 --- a/doc/README.md +++ b/doc/README.md @@ -337,3 +337,43 @@ Calf Multi Chorus - `level_in` (Input Gain): 0.0156250..64, default 1 - `level_out` (Output Gain): 0.0156250..64, default 1 - `lfo` (toggle): 0..1, default 1 + +## `saturator split index bypass level_in level_out mix drive blend lp_pre_freq hp_pre_fre lp_post_freq hp_post_freq p_freq p_level p_q pre post` + + - `bypass` (toggle): 0..1, default 0 + - `level_in` (Input Gain): 0.0156250..64, default 1 + - `level_out` (Output Gain): 0.0156250..64, default 1 + - `mix`: 0..1, default 1 + - `drive` (saturation, coef): 0.1..10, default 5 + - `blend` (coef): -10..10, default 10 + - `lp_pre_freq` (lowpass, hz): 10..20000, default 20000 + - `hp_pre_freq` (highpass, hz): 10..20000, default 10 + - `lp_post_freq` (lowpass, hz): 10..20000, default 20000 + - `hp_post_freq` (highpass, hz): 10..20000, default 10 + - `p_freq` (Tone, hz): 80..8000, default 2000 + - `p_level` (Amount): 0.0625..16, default 1 + - `p_q` (???, coef): 0.1..10, default 1 + - `pre` (Activate Pre, toggle): 0..1, default 0 + - `post` (Activate Post, toggle): 0..1, default 0 + +## `vintagedelay split index ...` + + - `level_in` (Input Gain): 0.0156250..64, default 1 + - `level_out` (Output Gain): 0.0156250..64, default 1 + - `subdiv` (int): 1..16, default 4 + - `time_l` (int): 1..16, default 3 + - `time_r` (int): 1..16, default 5 + - `feedback`: 0..1, default 0.5 + - `amount` (Wet): 0..4, default 0.25 + - `mix_mode` (enum): Stereo=0, Ping-Pong=1, L then R=2, R then L=3, default 1 + - `medium` (enum): Plain=0, Tape=1, Old Tape=2, default 1 + - `dry` (dry): 0..4, default 1 + - `width` (stereo width, strict): -1..1, default 1 + - `fragmentation` (enum): Repeating=0, Pattern=1, default 0 + - `pbeats` (Pattern Beats, int): 1..8, default 4 + - `pfrag` (Pattern Fragmentation, int): 1..8, default 4 + - `timing` (enum): BPM=0, ms=1, Hz=2, Sync=3, default 0 + - `bpm`: 30..300, default 120 + - `ms` (int): 10..2000, default 500 + - `hz`: 0.01..100, default 2 + - `bpm_host` (strict): 1..300, default 120 diff --git a/examples/saturator.scri b/examples/saturator.scri new file mode 100644 index 0000000..864c27a --- /dev/null +++ b/examples/saturator.scri @@ -0,0 +1,3 @@ +load :0; +saturator 3 1 0 1 1 1 5 10 20000 10 20000 10 2000 1 1 0 0; +quicksave; diff --git a/examples/vintagedelay.scri b/examples/vintagedelay.scri new file mode 100644 index 0000000..156638a --- /dev/null +++ b/examples/vintagedelay.scri @@ -0,0 +1,3 @@ +load :0; +vintagedelay 3 1 1 1 4 3 5 0.5 0.25 1 1 1 1 0 4 4 0 120 500 2 120; +quicksave; diff --git a/src/lang.zig b/src/lang.zig index b652617..45b806c 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -40,6 +40,8 @@ pub const CommandType = enum { TapeDelay, ModDelay, MultiChorus, + Saturator, + VintageDelay, Noise, WildNoise, @@ -209,6 +211,8 @@ pub const Lang = struct { _ = 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("noise", .Noise); diff --git a/src/printer.zig b/src/printer.zig index 08734b3..3cbcd72 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -34,6 +34,8 @@ pub fn printList(list: langs.CommandList, stream: var) !void { .TapeDelay => "tapedelay", .ModDelay => "moddelay", .MultiChorus => "multichorus", + .Saturator => "saturator", + .VintageDelay => "vintagedelay", .Noise => "noise", .WildNoise => "wildnoise", diff --git a/src/runner.zig b/src/runner.zig index 5856d7d..b3c4ed6 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -364,6 +364,16 @@ pub const Runner = struct { try image.runPlugin("http://calf.sourceforge.net/plugins/MultiChorus", pos, params); } + fn saturatorCmd(self: *Runner, pos: Position, params: ParamList) !void { + var image = try self.getImage(); + try image.runPlugin("http://calf.sourceforge.net/plugins/Saturator", pos, params); + } + + fn vintagedelayCmd(self: *Runner, pos: Position, params: ParamList) !void { + var image = try self.getImage(); + try image.runPlugin("http://calf.sourceforge.net/plugins/VintageDelay", pos, params); + } + fn runCommand(self: *Runner, cmd: *lang.Command) !void { var params = ParamList.init(self.allocator); defer params.deinit(); @@ -700,6 +710,58 @@ pub const Runner = struct { try self.multichorusCmd(pos, params); }, + .Saturator => { + const pos = try cmd.consumePosition(); + + try cmd.appendParam(¶ms, "bypass"); + try cmd.appendParam(¶ms, "level_in"); + try cmd.appendParam(¶ms, "level_out"); + try cmd.appendParam(¶ms, "mix"); + try cmd.appendParam(¶ms, "drive"); + try cmd.appendParam(¶ms, "blend"); + try cmd.appendParam(¶ms, "lp_pre_freq"); + try cmd.appendParam(¶ms, "hp_pre_freq"); + try cmd.appendParam(¶ms, "lp_post_freq"); + try cmd.appendParam(¶ms, "hp_post_freq"); + try cmd.appendParam(¶ms, "p_freq"); + try cmd.appendParam(¶ms, "p_level"); + try cmd.appendParam(¶ms, "p_q"); + try cmd.appendParam(¶ms, "pre"); + try cmd.appendParam(¶ms, "post"); + try self.saturatorCmd(pos, params); + }, + + .VintageDelay => { + const pos = try cmd.consumePosition(); + const PARAMS = [_][]const u8{ + "level_in", + "level_out", + "subdiv", + "time_l", + "time_r", + "feedback", + "amount", + "mix_mode", + "medium", + "dry", + "width", + "fragmentation", + "pbeats", + "pfrag", + "timing", + "bpm", + "ms", + "hz", + "bpm_host", + }; + + inline for (PARAMS) |param| { + try cmd.appendParam(¶ms, param); + } + + try self.vintagedelayCmd(pos, params); + }, + else => blk: { std.debug.warn("Unsupported command: {}\n", .{cmd.command}); break :blk RunError.UnknownCommand; From 2c0716e11d5c4499b1d07024073cb43661a54351 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 26 Jan 2020 15:45:09 -0300 Subject: [PATCH 061/182] move pitch.scri => pitchscaler.scri --- examples/{pitch.scri => pitchscaler.scri} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{pitch.scri => pitchscaler.scri} (100%) diff --git a/examples/pitch.scri b/examples/pitchscaler.scri similarity index 100% rename from examples/pitch.scri rename to examples/pitchscaler.scri From fe7e3477624847cf15b472acaa497e9cd684ff17 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 8 Feb 2020 01:40:35 -0300 Subject: [PATCH 062/182] fix mbeq example --- examples/mbeq.scri | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/mbeq.scri b/examples/mbeq.scri index 9afbee1..de0eef4 100644 --- a/examples/mbeq.scri +++ b/examples/mbeq.scri @@ -1,3 +1,3 @@ load :0; -mbeq 3 1 1 4 0.2 2.1; +mbeq 3 1 0 0 0 0.3 0 0 7 0 0 0 0 0 0.1 0 0; quicksave; From 8261d202bd0b351e3dae904015d319a97451b471 Mon Sep 17 00:00:00 2001 From: Luna Date: Thu, 26 Mar 2020 16:35:58 -0300 Subject: [PATCH 063/182] multiple fixes for latest zig --- src/image.zig | 7 ++++--- src/main.zig | 17 ++++++++++------- src/printer.zig | 2 +- src/runner.zig | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/image.zig b/src/image.zig index 9541070..e3599be 100644 --- a/src/image.zig +++ b/src/image.zig @@ -94,7 +94,8 @@ pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 { } // if we fail to access it, we assume it doesn't exist and return it. - std.fs.File.access(nam) catch |err| { + + _ = std.fs.cwd().openFile(nam, .{ .read = true, .write = false }) catch |err| { if (err == error.FileNotFound) { return nam; } @@ -266,7 +267,7 @@ pub const Image = struct { } pub fn checkValid(self: *Image) !void { - var file = try std.fs.File.openRead(self.path); + var file = try std.fs.cwd().openFile(self.path, .{ .read = true }); defer file.close(); // main bmp header: @@ -413,7 +414,7 @@ pub const Image = struct { pub fn saveTo(self: *Image, out_path: []const u8) !void { std.debug.warn("\timg: copy from '{}' to '{}'\n", .{ self.curpath, out_path }); - try std.fs.copyFile(self.curpath, out_path); + try std.fs.copyFileAbsolute(self.curpath, out_path, .{}); } pub fn runCustomPlugin( diff --git a/src/main.zig b/src/main.zig index 1235607..4571910 100644 --- a/src/main.zig +++ b/src/main.zig @@ -24,10 +24,10 @@ fn wrapInCmdList(allocator: *std.mem.Allocator, cmd: langs.Command) !langs.Comma pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { var stdout_file = std.io.getStdOut(); - const stdout = &stdout_file.outStream().stream; + const stdout = &stdout_file.outStream(); const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path")); - var file_read_opt: ?std.fs.File = std.fs.File.openRead(scri_path) catch |err| blk: { + var file_read_opt: ?std.fs.File = std.fs.cwd().openFile(scri_path, .{}) catch |err| blk: { if (err == error.FileNotFound) break :blk null; return err; }; @@ -70,11 +70,14 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { file_read.close(); } - var file = try std.fs.File.openWrite(scri_path); + var file = try std.fs.cwd().openFile(scri_path, .{ + .write = true, + .read = false, + }); defer file.close(); var out = file.outStream(); - var stream = &out.stream; + var stream = &out; // since we opened the file for writing, it becomes empty, so, to ensure // we don't fuck up later on, we print cmds before starting the repl @@ -115,7 +118,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { readline.add_history(rd_line); //defer std.heap.c_allocator.destroy(rd_line); - var line = rd_line[0..std.mem.len(u8, rd_line)]; + var line = rd_line[0..std.mem.len(rd_line)]; if (std.mem.eql(u8, line, "push")) { try cmds.append(current); @@ -161,7 +164,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { }); try runner_clone.runCommands(cmds_parsed, true); - try stdout.write("\n"); + _ = try stdout.write("\n"); } } @@ -185,7 +188,7 @@ pub fn main() !void { return try doRepl(allocator, &args_it); } - var file = try std.fs.File.openRead(scri_path); + var file = try std.fs.cwd().openFile(scri_path, .{}); defer file.close(); // sadly, we read it all into memory. such is life diff --git a/src/printer.zig b/src/printer.zig index 3cbcd72..940c7b3 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -51,6 +51,6 @@ pub fn printList(list: langs.CommandList, stream: var) !void { try stream.print(" {}", .{arg}); } - try stream.write(";\n"); + _ = try stream.write(";\n"); } } diff --git a/src/runner.zig b/src/runner.zig index b3c4ed6..aa0a069 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -117,7 +117,7 @@ pub const Runner = struct { const basename = std.fs.path.basename(image.path); const dirname = std.fs.path.dirname(image.path).?; - var dir = try std.fs.Dir.open(dirname); + var dir = try std.fs.cwd().openDir(dirname, .{ .iterate = true }); defer dir.close(); const period_idx = std.mem.lastIndexOf(u8, basename, ".").?; From 8bb09f1573c57a8ac4fdcecabd67515f489e4bd3 Mon Sep 17 00:00:00 2001 From: Luna Date: Thu, 9 Apr 2020 23:51:33 -0300 Subject: [PATCH 064/182] fixes for latest zig - arraylist breaking changes - mem.separate => mem.split - heap.page_allocator --- src/lang.zig | 17 ++++++++--------- src/main.zig | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 45b806c..864940d 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -61,15 +61,14 @@ pub const Command = struct { } pub fn argAt(self: Command, idx: usize) ![]const u8 { - std.debug.warn("{} {}", .{ idx, self.args.len }); + std.debug.warn("{} {}", .{ idx, self.args.items.len }); - if (idx > (self.args.len - 1)) { + if (idx > (self.args.items.len - 1)) { std.debug.warn("Expected argument at index {}\n", .{idx}); return ParseError.ArgRequired; } - const args = self.args.toSliceConst(); - return args[idx]; + return self.args.items[idx]; } pub fn usizeArgAt(self: Command, idx: usize) !usize { @@ -238,8 +237,8 @@ pub const Lang = struct { } fn expectAny(self: *Lang, count: usize, args: ArgList) !void { - if (args.len != count) { - self.doError("expected {} arguments, found {}", .{ count, args.len }); + if (args.items.len != count) { + self.doError("expected {} arguments, found {}", .{ count, args.items.len }); return error.ArgRequired; } } @@ -251,8 +250,8 @@ pub const Lang = struct { fn expectFloat(self: *Lang, count: usize, args: ArgList) !void { var i: usize = 0; - if (args.len != count) { - self.doError("expected {} arguments, found {}", .{ count, args.len }); + if (args.items.len != count) { + self.doError("expected {} arguments, found {}", .{ count, args.items.len }); return error.ArgRequired; } @@ -299,7 +298,7 @@ pub const Lang = struct { } pub fn parse(self: *Lang, data: []const u8) ParseError!CommandList { - var splitted_it = std.mem.separate(data, ";"); + var splitted_it = std.mem.split(data, ";"); try self.fillKeywords(); var cmds = CommandList.init(self.allocator); diff --git a/src/main.zig b/src/main.zig index 4571910..3b4fe82 100644 --- a/src/main.zig +++ b/src/main.zig @@ -169,7 +169,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { } pub fn main() !void { - const allocator = std.heap.direct_allocator; + const allocator = std.heap.page_allocator; var lang = langs.Lang.init(allocator); defer lang.deinit(); From 9614b96c71712ce1c21dde5b76b1bc3cd662e6c1 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 10 Apr 2020 00:01:23 -0300 Subject: [PATCH 065/182] Add SCRITCHER_RUNNER env var Closes #13 --- src/main.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.zig b/src/main.zig index 3b4fe82..0857fdc 100644 --- a/src/main.zig +++ b/src/main.zig @@ -104,8 +104,8 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { 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"); + const wanted_runner: []const u8 = std.os.getenv("SCRITCHER_RUNNER") orelse "ristretto"; + try runqs_args.append(wanted_runner); while (true) { lang.reset(); From 043556e798e83f7967dc594f1e6159a94000c165 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 10 Apr 2020 00:20:46 -0300 Subject: [PATCH 066/182] Update README on new env var --- README.md | 13 ++++++++++--- src/main.zig | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index dba4162..7d4da76 100644 --- a/README.md +++ b/README.md @@ -51,10 +51,17 @@ $your_image_viewer blah_g1.bmp using repl works via `scritcher repl scri_file.scri input_image.bmp` you type commands as you'd write the specific scritcher commands -(`doc/README.md`), with three repl-specific ones: +(`doc/README.md`), with four repl-specific ones (semicolons do not apply): - `push`, to push the last written command to the queue - `save`, to write the queue to the given `scri_file.scri` file - `list`, to print the current contents of the queue + - `quit`, to exit -this allows for quicker iteration of commands, as you can type a command, tweak -its arguments, and when satisfied, `push` it, and work on the next one, etc. +After a non-REPL command, such as an effect, the program pointed by +`SCRITCHER_RUNNER` will run as argument to the `runqs` command. By default, +the program run will be `ristretto` (as it is my preffered image viewer, +considering it was able to handle when some images went broke) + +this allows for quicker iteration of commands, as you can type a command, see +the image changes as fast as possible, tweak its arguments, +and when satisfied, `push` it, and work on the next command, etc. diff --git a/src/main.zig b/src/main.zig index 0857fdc..510c2d8 100644 --- a/src/main.zig +++ b/src/main.zig @@ -182,7 +182,7 @@ pub fn main() !void { // TODO print help _ = try (args_it.next(allocator) orelse @panic("expected exe name")); - const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path")); + const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path or 'repl'")); if (std.mem.eql(u8, scri_path, "repl")) { return try doRepl(allocator, &args_it); From 0c2cd5638e938539d781e252d2d5dcc76ba679e5 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 12 May 2020 17:26:33 -0300 Subject: [PATCH 067/182] update because of arraylist api changes --- src/image.zig | 2 +- src/lang.zig | 5 ++--- src/main.zig | 2 +- src/printer.zig | 4 ++-- src/runner.zig | 8 ++++---- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/image.zig b/src/image.zig index e3599be..704213d 100644 --- a/src/image.zig +++ b/src/image.zig @@ -312,7 +312,7 @@ pub const Image = struct { // now, for each param for the plugin, we find its port, and set // the value for the port there. - for (params.toSlice()) |param| { + for (params.items) |param| { var sym_cstr = try std.cstr.addNullByte(self.allocator, param.sym); defer self.allocator.free(sym_cstr); diff --git a/src/lang.zig b/src/lang.zig index 864940d..848cf9a 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -113,7 +113,7 @@ pub const Command = struct { try arr.append(value); } - return arr.toSliceConst(); + return arr.items; } pub fn appendParam( @@ -256,8 +256,7 @@ pub const Lang = struct { } while (i < count) : (i += 1) { - var arg = args.at(i); - + var arg = args.items[i]; _ = std.fmt.parseFloat(f32, arg) catch |err| { std.debug.warn("failed to parse f32: {}\n", .{err}); return error.FloatParseFail; diff --git a/src/main.zig b/src/main.zig index 510c2d8..2b8da57 100644 --- a/src/main.zig +++ b/src/main.zig @@ -51,7 +51,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { defer existing_cmds.deinit(); // copy the existing command list into the repl's command list - for (existing_cmds.toSlice()) |existing_cmd| { + for (existing_cmds.items) |existing_cmd| { try cmds.append(existing_cmd); } } else { diff --git a/src/printer.zig b/src/printer.zig index 940c7b3..ea91ec2 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -1,7 +1,7 @@ const langs = @import("lang.zig"); pub fn printList(list: langs.CommandList, stream: var) !void { - for (list.toSlice()) |cmd| { + for (list.items) |cmd| { var command = switch (cmd.command) { .Noop => "noop", .Load => "load", @@ -47,7 +47,7 @@ pub fn printList(list: langs.CommandList, stream: var) !void { try stream.print("{}", .{command}); - for (cmd.args.toSlice()) |arg| { + for (cmd.args.items) |arg| { try stream.print(" {}", .{arg}); } diff --git a/src/runner.zig b/src/runner.zig index aa0a069..6276954 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -384,14 +384,14 @@ pub const Runner = struct { return switch (cmd.command) { .Noop => {}, .Load => blk: { - var path = cmd.args.at(0); + var path = cmd.args.items[0]; try self.loadCmd(path); // TODO is this needed? break :blk; }, .Quicksave => try self.quicksaveCmd(), - .RunQS => try self.runQSCmd(cmd.args.at(0)), + .RunQS => try self.runQSCmd(cmd.args.items[0]), .Amp => blk: { const pos = try cmd.consumePosition(); @@ -547,7 +547,7 @@ pub const Runner = struct { .Embed => blk: { const pos = try cmd.consumePosition(); - const path = cmd.args.at(2); + const path = cmd.args.items[2]; try self.embedCmd(pos, path); }, @@ -775,7 +775,7 @@ pub const Runner = struct { cmds: lang.CommandList, debug_flag: bool, ) !void { - for (cmds.toSlice()) |const_cmd| { + for (cmds.items) |const_cmd| { if (debug_flag) const_cmd.print(); // copy the command so we own its memory From 3de84b5a236f85a710bd06e406e397457d33c590 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 12 May 2020 17:48:15 -0300 Subject: [PATCH 068/182] finish arraylist updates --- src/lang.zig | 8 ++++---- src/main.zig | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 848cf9a..34c5004 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -359,7 +359,7 @@ test "noop" { defer cmds.deinit(); std.testing.expectEqual(cmds.len, 1); - std.testing.expectEqual(cmds.at(0).command, .Noop); + std.testing.expectEqual(cmds.items[0].command, .Noop); } test "load, phaser, quicksave" { @@ -376,7 +376,7 @@ test "load, phaser, quicksave" { defer cmds.deinit(); std.testing.expectEqual(cmds.len, 3); - std.testing.expectEqual(cmds.at(0).command, .Load); - std.testing.expectEqual(cmds.at(1).command, .Phaser); - std.testing.expectEqual(cmds.at(2).command, .Quicksave); + std.testing.expectEqual(cmds.items[0].command, .Load); + std.testing.expectEqual(cmds.items[1].command, .Phaser); + std.testing.expectEqual(cmds.items[2].command, .Quicksave); } diff --git a/src/main.zig b/src/main.zig index 2b8da57..04bcf2d 100644 --- a/src/main.zig +++ b/src/main.zig @@ -150,7 +150,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { std.debug.warn("repl: error while parsing: {}\n", .{err}); continue; }; - current = cmds_parsed.at(0); + current = cmds_parsed.items[0]; // by cloning the parent runner, we can iteratively write // whatever command we want and only commit the good results From c8f949fe96f0a909ec835d3e0fd9515919fb989e Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 12 May 2020 17:48:20 -0300 Subject: [PATCH 069/182] remove embedded magick_wand in favor of cimport --- src/magick.zig | 4 +- src/magick_wand.zig | 4124 ------------------------------------------- 2 files changed, 3 insertions(+), 4125 deletions(-) delete mode 100644 src/magick_wand.zig diff --git a/src/magick.zig b/src/magick.zig index e7b582a..33ba882 100644 --- a/src/magick.zig +++ b/src/magick.zig @@ -4,7 +4,9 @@ const images = @import("image.zig"); const Image = images.Image; -const mc = @import("magick_wand.zig"); +const mc = @cImport({ + @cInclude("wand/magick_wand.h"); +}); pub const MagickContext = struct { wand: *mc.MagickWand, diff --git a/src/magick_wand.zig b/src/magick_wand.zig deleted file mode 100644 index 63c9437..0000000 --- a/src/magick_wand.zig +++ /dev/null @@ -1,4124 +0,0 @@ -pub const struct___va_list_tag = extern struct { - gp_offset: c_uint, - fp_offset: c_uint, - overflow_arg_area: ?*c_void, - reg_save_area: ?*c_void, -}; -pub const __builtin_va_list = [1]struct___va_list_tag; -pub const va_list = __builtin_va_list; -pub const __gnuc_va_list = __builtin_va_list; -pub const __u_char = u8; -pub const __u_short = c_ushort; -pub const __u_int = c_uint; -pub const __u_long = c_ulong; -pub const __int8_t = i8; -pub const __uint8_t = u8; -pub const __int16_t = c_short; -pub const __uint16_t = c_ushort; -pub const __int32_t = c_int; -pub const __uint32_t = c_uint; -pub const __int64_t = c_long; -pub const __uint64_t = c_ulong; -pub const __int_least8_t = __int8_t; -pub const __uint_least8_t = __uint8_t; -pub const __int_least16_t = __int16_t; -pub const __uint_least16_t = __uint16_t; -pub const __int_least32_t = __int32_t; -pub const __uint_least32_t = __uint32_t; -pub const __int_least64_t = __int64_t; -pub const __uint_least64_t = __uint64_t; -pub const __quad_t = c_long; -pub const __u_quad_t = c_ulong; -pub const __intmax_t = c_long; -pub const __uintmax_t = c_ulong; -pub const __dev_t = c_ulong; -pub const __uid_t = c_uint; -pub const __gid_t = c_uint; -pub const __ino_t = c_ulong; -pub const __ino64_t = c_ulong; -pub const __mode_t = c_uint; -pub const __nlink_t = c_ulong; -pub const __off_t = c_long; -pub const __off64_t = c_long; -pub const __pid_t = c_int; -pub const __fsid_t = extern struct { - __val: [2]c_int, -}; -pub const __clock_t = c_long; -pub const __rlim_t = c_ulong; -pub const __rlim64_t = c_ulong; -pub const __id_t = c_uint; -pub const __time_t = c_long; -pub const __useconds_t = c_uint; -pub const __suseconds_t = c_long; -pub const __daddr_t = c_int; -pub const __key_t = c_int; -pub const __clockid_t = c_int; -pub const __timer_t = ?*c_void; -pub const __blksize_t = c_long; -pub const __blkcnt_t = c_long; -pub const __blkcnt64_t = c_long; -pub const __fsblkcnt_t = c_ulong; -pub const __fsblkcnt64_t = c_ulong; -pub const __fsfilcnt_t = c_ulong; -pub const __fsfilcnt64_t = c_ulong; -pub const __fsword_t = c_long; -pub const __ssize_t = c_long; -pub const __syscall_slong_t = c_long; -pub const __syscall_ulong_t = c_ulong; -pub const __loff_t = __off64_t; -pub const __caddr_t = [*c]u8; -pub const __intptr_t = c_long; -pub const __socklen_t = c_uint; -pub const __sig_atomic_t = c_int; -pub const __mbstate_t = extern struct { - __count: c_int, - __value: extern union { - __wch: c_uint, - __wchb: [4]u8, - }, -}; -pub const struct__G_fpos_t = extern struct { - __pos: __off_t, - __state: __mbstate_t, -}; -pub const __fpos_t = struct__G_fpos_t; -pub const struct__G_fpos64_t = extern struct { - __pos: __off64_t, - __state: __mbstate_t, -}; -pub const __fpos64_t = struct__G_fpos64_t; -pub const struct__IO_marker = @OpaqueType(); -pub const _IO_lock_t = c_void; -pub const struct__IO_codecvt = @OpaqueType(); -pub const struct__IO_wide_data = @OpaqueType(); -pub const struct__IO_FILE = extern struct { - _flags: c_int, - _IO_read_ptr: [*c]u8, - _IO_read_end: [*c]u8, - _IO_read_base: [*c]u8, - _IO_write_base: [*c]u8, - _IO_write_ptr: [*c]u8, - _IO_write_end: [*c]u8, - _IO_buf_base: [*c]u8, - _IO_buf_end: [*c]u8, - _IO_save_base: [*c]u8, - _IO_backup_base: [*c]u8, - _IO_save_end: [*c]u8, - _markers: ?*struct__IO_marker, - _chain: [*c]struct__IO_FILE, - _fileno: c_int, - _flags2: c_int, - _old_offset: __off_t, - _cur_column: c_ushort, - _vtable_offset: i8, - _shortbuf: [1]u8, - _lock: ?*_IO_lock_t, - _offset: __off64_t, - _codecvt: ?*struct__IO_codecvt, - _wide_data: ?*struct__IO_wide_data, - _freeres_list: [*c]struct__IO_FILE, - _freeres_buf: ?*c_void, - __pad5: usize, - _mode: c_int, - _unused2: [20]u8, -}; -pub const __FILE = struct__IO_FILE; -pub const FILE = struct__IO_FILE; -pub const off_t = __off_t; -pub const fpos_t = __fpos_t; -pub extern var stdin: [*c]FILE; -pub extern var stdout: [*c]FILE; -pub extern var stderr: [*c]FILE; -pub extern fn remove(__filename: [*c]const u8) c_int; -pub extern fn rename(__old: [*c]const u8, __new: [*c]const u8) c_int; -pub extern fn renameat(__oldfd: c_int, __old: [*c]const u8, __newfd: c_int, __new: [*c]const u8) c_int; -pub extern fn tmpfile() [*c]FILE; -pub extern fn tmpnam(__s: [*c]u8) [*c]u8; -pub extern fn tmpnam_r(__s: [*c]u8) [*c]u8; -pub extern fn tempnam(__dir: [*c]const u8, __pfx: [*c]const u8) [*c]u8; -pub extern fn fclose(__stream: [*c]FILE) c_int; -pub extern fn fflush(__stream: [*c]FILE) c_int; -pub extern fn fflush_unlocked(__stream: [*c]FILE) c_int; -pub extern fn fopen(__filename: [*c]const u8, __modes: [*c]const u8) [*c]FILE; -pub extern fn freopen(noalias __filename: [*c]const u8, noalias __modes: [*c]const u8, noalias __stream: [*c]FILE) [*c]FILE; -pub extern fn fdopen(__fd: c_int, __modes: [*c]const u8) [*c]FILE; -pub extern fn fmemopen(__s: ?*c_void, __len: usize, __modes: [*c]const u8) [*c]FILE; -pub extern fn open_memstream(__bufloc: [*c]([*c]u8), __sizeloc: [*c]usize) [*c]FILE; -pub extern fn setbuf(noalias __stream: [*c]FILE, noalias __buf: [*c]u8) void; -pub extern fn setvbuf(noalias __stream: [*c]FILE, noalias __buf: [*c]u8, __modes: c_int, __n: usize) c_int; -pub extern fn setbuffer(noalias __stream: [*c]FILE, noalias __buf: [*c]u8, __size: usize) void; -pub extern fn setlinebuf(__stream: [*c]FILE) void; -pub extern fn fprintf(__stream: [*c]FILE, __format: [*c]const u8, ...) c_int; -pub extern fn printf(__format: [*c]const u8, ...) c_int; -pub extern fn sprintf(__s: [*c]u8, __format: [*c]const u8, ...) c_int; -pub extern fn vfprintf(__s: [*c]FILE, __format: [*c]const u8, __arg: [*c]struct___va_list_tag) c_int; -pub extern fn vprintf(__format: [*c]const u8, __arg: [*c]struct___va_list_tag) c_int; -pub extern fn vsprintf(__s: [*c]u8, __format: [*c]const u8, __arg: [*c]struct___va_list_tag) c_int; -pub extern fn snprintf(__s: [*c]u8, __maxlen: c_ulong, __format: [*c]const u8, ...) c_int; -pub extern fn vsnprintf(__s: [*c]u8, __maxlen: c_ulong, __format: [*c]const u8, __arg: [*c]struct___va_list_tag) c_int; -pub extern fn vdprintf(__fd: c_int, noalias __fmt: [*c]const u8, __arg: [*c]struct___va_list_tag) c_int; -pub extern fn dprintf(__fd: c_int, noalias __fmt: [*c]const u8, ...) c_int; -pub extern fn fscanf(noalias __stream: [*c]FILE, noalias __format: [*c]const u8, ...) c_int; -pub extern fn scanf(noalias __format: [*c]const u8, ...) c_int; -pub extern fn sscanf(noalias __s: [*c]const u8, noalias __format: [*c]const u8, ...) c_int; -pub extern fn vfscanf(noalias __s: [*c]FILE, noalias __format: [*c]const u8, __arg: [*c]struct___va_list_tag) c_int; -pub extern fn vscanf(noalias __format: [*c]const u8, __arg: [*c]struct___va_list_tag) c_int; -pub extern fn vsscanf(noalias __s: [*c]const u8, noalias __format: [*c]const u8, __arg: [*c]struct___va_list_tag) c_int; -pub extern fn fgetc(__stream: [*c]FILE) c_int; -pub extern fn getc(__stream: [*c]FILE) c_int; -pub extern fn getchar() c_int; -pub extern fn getc_unlocked(__stream: [*c]FILE) c_int; -pub extern fn getchar_unlocked() c_int; -pub extern fn fgetc_unlocked(__stream: [*c]FILE) c_int; -pub extern fn fputc(__c: c_int, __stream: [*c]FILE) c_int; -pub extern fn putc(__c: c_int, __stream: [*c]FILE) c_int; -pub extern fn putchar(__c: c_int) c_int; -pub extern fn fputc_unlocked(__c: c_int, __stream: [*c]FILE) c_int; -pub extern fn putc_unlocked(__c: c_int, __stream: [*c]FILE) c_int; -pub extern fn putchar_unlocked(__c: c_int) c_int; -pub extern fn getw(__stream: [*c]FILE) c_int; -pub extern fn putw(__w: c_int, __stream: [*c]FILE) c_int; -pub extern fn fgets(noalias __s: [*c]u8, __n: c_int, noalias __stream: [*c]FILE) [*c]u8; -pub extern fn __getdelim(noalias __lineptr: [*c]([*c]u8), noalias __n: [*c]usize, __delimiter: c_int, noalias __stream: [*c]FILE) __ssize_t; -pub extern fn getdelim(noalias __lineptr: [*c]([*c]u8), noalias __n: [*c]usize, __delimiter: c_int, noalias __stream: [*c]FILE) __ssize_t; -pub extern fn getline(noalias __lineptr: [*c]([*c]u8), noalias __n: [*c]usize, noalias __stream: [*c]FILE) __ssize_t; -pub extern fn fputs(noalias __s: [*c]const u8, noalias __stream: [*c]FILE) c_int; -pub extern fn puts(__s: [*c]const u8) c_int; -pub extern fn ungetc(__c: c_int, __stream: [*c]FILE) c_int; -pub extern fn fread(__ptr: ?*c_void, __size: c_ulong, __n: c_ulong, __stream: [*c]FILE) c_ulong; -pub extern fn fwrite(__ptr: ?*const c_void, __size: c_ulong, __n: c_ulong, __s: [*c]FILE) c_ulong; -pub extern fn fread_unlocked(noalias __ptr: ?*c_void, __size: usize, __n: usize, noalias __stream: [*c]FILE) usize; -pub extern fn fwrite_unlocked(noalias __ptr: ?*const c_void, __size: usize, __n: usize, noalias __stream: [*c]FILE) usize; -pub extern fn fseek(__stream: [*c]FILE, __off: c_long, __whence: c_int) c_int; -pub extern fn ftell(__stream: [*c]FILE) c_long; -pub extern fn rewind(__stream: [*c]FILE) void; -pub extern fn fseeko(__stream: [*c]FILE, __off: __off_t, __whence: c_int) c_int; -pub extern fn ftello(__stream: [*c]FILE) __off_t; -pub extern fn fgetpos(noalias __stream: [*c]FILE, noalias __pos: [*c]fpos_t) c_int; -pub extern fn fsetpos(__stream: [*c]FILE, __pos: [*c]const fpos_t) c_int; -pub extern fn clearerr(__stream: [*c]FILE) void; -pub extern fn feof(__stream: [*c]FILE) c_int; -pub extern fn ferror(__stream: [*c]FILE) c_int; -pub extern fn clearerr_unlocked(__stream: [*c]FILE) void; -pub extern fn feof_unlocked(__stream: [*c]FILE) c_int; -pub extern fn ferror_unlocked(__stream: [*c]FILE) c_int; -pub extern fn perror(__s: [*c]const u8) void; -pub extern var sys_nerr: c_int; -pub extern const sys_errlist: [*c]const ([*c]const u8); -pub extern fn fileno(__stream: [*c]FILE) c_int; -pub extern fn fileno_unlocked(__stream: [*c]FILE) c_int; -pub extern fn popen(__command: [*c]const u8, __modes: [*c]const u8) [*c]FILE; -pub extern fn pclose(__stream: [*c]FILE) c_int; -pub extern fn ctermid(__s: [*c]u8) [*c]u8; -pub extern fn flockfile(__stream: [*c]FILE) void; -pub extern fn ftrylockfile(__stream: [*c]FILE) c_int; -pub extern fn funlockfile(__stream: [*c]FILE) void; -pub extern fn __uflow(arg0: [*c]FILE) c_int; -pub extern fn __overflow(arg0: [*c]FILE, arg1: c_int) c_int; -pub const wchar_t = c_int; -pub const _Float32 = f32; -pub const _Float64 = f64; -pub const _Float32x = f64; -pub const _Float64x = c_longdouble; -pub const div_t = extern struct { - quot: c_int, - rem: c_int, -}; -pub const ldiv_t = extern struct { - quot: c_long, - rem: c_long, -}; -pub const lldiv_t = extern struct { - quot: c_longlong, - rem: c_longlong, -}; -pub extern fn __ctype_get_mb_cur_max() usize; -pub extern fn atof(__nptr: [*c]const u8) f64; -pub extern fn atoi(__nptr: [*c]const u8) c_int; -pub extern fn atol(__nptr: [*c]const u8) c_long; -pub extern fn atoll(__nptr: [*c]const u8) c_longlong; -pub extern fn strtod(__nptr: [*c]const u8, __endptr: [*c]([*c]u8)) f64; -pub extern fn strtof(__nptr: [*c]const u8, __endptr: [*c]([*c]u8)) f32; -pub extern fn strtold(__nptr: [*c]const u8, __endptr: [*c]([*c]u8)) c_longdouble; -pub extern fn strtol(__nptr: [*c]const u8, __endptr: [*c]([*c]u8), __base: c_int) c_long; -pub extern fn strtoul(__nptr: [*c]const u8, __endptr: [*c]([*c]u8), __base: c_int) c_ulong; -pub extern fn strtoq(noalias __nptr: [*c]const u8, noalias __endptr: [*c]([*c]u8), __base: c_int) c_longlong; -pub extern fn strtouq(noalias __nptr: [*c]const u8, noalias __endptr: [*c]([*c]u8), __base: c_int) c_ulonglong; -pub extern fn strtoll(__nptr: [*c]const u8, __endptr: [*c]([*c]u8), __base: c_int) c_longlong; -pub extern fn strtoull(__nptr: [*c]const u8, __endptr: [*c]([*c]u8), __base: c_int) c_ulonglong; -pub extern fn l64a(__n: c_long) [*c]u8; -pub extern fn a64l(__s: [*c]const u8) c_long; -pub const u_char = __u_char; -pub const u_short = __u_short; -pub const u_int = __u_int; -pub const u_long = __u_long; -pub const quad_t = __quad_t; -pub const u_quad_t = __u_quad_t; -pub const fsid_t = __fsid_t; -pub const loff_t = __loff_t; -pub const ino_t = __ino_t; -pub const dev_t = __dev_t; -pub const gid_t = __gid_t; -pub const mode_t = __mode_t; -pub const nlink_t = __nlink_t; -pub const uid_t = __uid_t; -pub const pid_t = __pid_t; -pub const id_t = __id_t; -pub const daddr_t = __daddr_t; -pub const caddr_t = __caddr_t; -pub const key_t = __key_t; -pub const clock_t = __clock_t; -pub const clockid_t = __clockid_t; -pub const time_t = __time_t; -pub const timer_t = __timer_t; -pub const ulong = c_ulong; -pub const ushort = c_ushort; -pub const uint = c_uint; -pub const u_int8_t = u8; -pub const u_int16_t = c_ushort; -pub const u_int32_t = c_uint; -pub const u_int64_t = c_ulong; -pub const register_t = c_long; -pub fn __bswap_16(__bsx: __uint16_t) __uint16_t { - return __uint16_t(((c_int(__bsx) >> @import("std").math.Log2Int(c_int)(8)) & 255) | ((c_int(__bsx) & 255) << @import("std").math.Log2Int(c_int)(8))); -} -pub fn __bswap_32(__bsx: __uint32_t) __uint32_t { - return ((((__bsx & 4278190080) >> @import("std").math.Log2Int(c_uint)(24)) | ((__bsx & 16711680) >> @import("std").math.Log2Int(c_uint)(8))) | ((__bsx & 65280) << @import("std").math.Log2Int(c_uint)(8))) | ((__bsx & 255) << @import("std").math.Log2Int(c_uint)(24)); -} -pub fn __bswap_64(__bsx: __uint64_t) __uint64_t { - return __uint64_t(((((((((c_ulonglong(__bsx) & 18374686479671623680) >> @import("std").math.Log2Int(c_ulonglong)(56)) | ((c_ulonglong(__bsx) & 71776119061217280) >> @import("std").math.Log2Int(c_ulonglong)(40))) | ((c_ulonglong(__bsx) & 280375465082880) >> @import("std").math.Log2Int(c_ulonglong)(24))) | ((c_ulonglong(__bsx) & 1095216660480) >> @import("std").math.Log2Int(c_ulonglong)(8))) | ((c_ulonglong(__bsx) & 4278190080) << @import("std").math.Log2Int(c_ulonglong)(8))) | ((c_ulonglong(__bsx) & 16711680) << @import("std").math.Log2Int(c_ulonglong)(24))) | ((c_ulonglong(__bsx) & 65280) << @import("std").math.Log2Int(c_ulonglong)(40))) | ((c_ulonglong(__bsx) & 255) << @import("std").math.Log2Int(c_ulonglong)(56))); -} -pub fn __uint16_identity(__x: __uint16_t) __uint16_t { - return __x; -} -pub fn __uint32_identity(__x: __uint32_t) __uint32_t { - return __x; -} -pub fn __uint64_identity(__x: __uint64_t) __uint64_t { - return __x; -} -pub const __sigset_t = extern struct { - __val: [16]c_ulong, -}; -pub const sigset_t = __sigset_t; -pub const struct_timeval = extern struct { - tv_sec: __time_t, - tv_usec: __suseconds_t, -}; -pub const struct_timespec = extern struct { - tv_sec: __time_t, - tv_nsec: __syscall_slong_t, -}; -pub const suseconds_t = __suseconds_t; -pub const __fd_mask = c_long; -pub const fd_set = extern struct { - __fds_bits: [16]__fd_mask, -}; -pub const fd_mask = __fd_mask; -pub extern fn select(__nfds: c_int, noalias __readfds: [*c]fd_set, noalias __writefds: [*c]fd_set, noalias __exceptfds: [*c]fd_set, noalias __timeout: [*c]struct_timeval) c_int; -pub extern fn pselect(__nfds: c_int, noalias __readfds: [*c]fd_set, noalias __writefds: [*c]fd_set, noalias __exceptfds: [*c]fd_set, noalias __timeout: [*c]const struct_timespec, noalias __sigmask: [*c]const __sigset_t) c_int; -pub const blksize_t = __blksize_t; -pub const blkcnt_t = __blkcnt_t; -pub const fsblkcnt_t = __fsblkcnt_t; -pub const fsfilcnt_t = __fsfilcnt_t; -pub const struct___pthread_rwlock_arch_t = extern struct { - __readers: c_uint, - __writers: c_uint, - __wrphase_futex: c_uint, - __writers_futex: c_uint, - __pad3: c_uint, - __pad4: c_uint, - __cur_writer: c_int, - __shared: c_int, - __rwelision: i8, - __pad1: [7]u8, - __pad2: c_ulong, - __flags: c_uint, -}; -pub const struct___pthread_internal_list = extern struct { - __prev: [*c]struct___pthread_internal_list, - __next: [*c]struct___pthread_internal_list, -}; -pub const __pthread_list_t = struct___pthread_internal_list; -pub const struct___pthread_mutex_s = extern struct { - __lock: c_int, - __count: c_uint, - __owner: c_int, - __nusers: c_uint, - __kind: c_int, - __spins: c_short, - __elision: c_short, - __list: __pthread_list_t, -}; -pub const struct___pthread_cond_s = extern struct { - @"": extern union { - __wseq: c_ulonglong, - __wseq32: extern struct { - __low: c_uint, - __high: c_uint, - }, - }, - @"": extern union { - __g1_start: c_ulonglong, - __g1_start32: extern struct { - __low: c_uint, - __high: c_uint, - }, - }, - __g_refs: [2]c_uint, - __g_size: [2]c_uint, - __g1_orig_size: c_uint, - __wrefs: c_uint, - __g_signals: [2]c_uint, -}; -pub const pthread_t = c_ulong; -pub const pthread_mutexattr_t = extern union { - __size: [4]u8, - __align: c_int, -}; -pub const pthread_condattr_t = extern union { - __size: [4]u8, - __align: c_int, -}; -pub const pthread_key_t = c_uint; -pub const pthread_once_t = c_int; -pub const union_pthread_attr_t = extern union { - __size: [56]u8, - __align: c_long, -}; -pub const pthread_attr_t = union_pthread_attr_t; -pub const pthread_mutex_t = extern union { - __data: struct___pthread_mutex_s, - __size: [40]u8, - __align: c_long, -}; -pub const pthread_cond_t = extern union { - __data: struct___pthread_cond_s, - __size: [48]u8, - __align: c_longlong, -}; -pub const pthread_rwlock_t = extern union { - __data: struct___pthread_rwlock_arch_t, - __size: [56]u8, - __align: c_long, -}; -pub const pthread_rwlockattr_t = extern union { - __size: [8]u8, - __align: c_long, -}; -pub const pthread_spinlock_t = c_int; -pub const pthread_barrier_t = extern union { - __size: [32]u8, - __align: c_long, -}; -pub const pthread_barrierattr_t = extern union { - __size: [4]u8, - __align: c_int, -}; -pub extern fn random() c_long; -pub extern fn srandom(__seed: c_uint) void; -pub extern fn initstate(__seed: c_uint, __statebuf: [*c]u8, __statelen: usize) [*c]u8; -pub extern fn setstate(__statebuf: [*c]u8) [*c]u8; -pub const struct_random_data = extern struct { - fptr: [*c]i32, - rptr: [*c]i32, - state: [*c]i32, - rand_type: c_int, - rand_deg: c_int, - rand_sep: c_int, - end_ptr: [*c]i32, -}; -pub extern fn random_r(noalias __buf: [*c]struct_random_data, noalias __result: [*c]i32) c_int; -pub extern fn srandom_r(__seed: c_uint, __buf: [*c]struct_random_data) c_int; -pub extern fn initstate_r(__seed: c_uint, noalias __statebuf: [*c]u8, __statelen: usize, noalias __buf: [*c]struct_random_data) c_int; -pub extern fn setstate_r(noalias __statebuf: [*c]u8, noalias __buf: [*c]struct_random_data) c_int; -pub extern fn rand() c_int; -pub extern fn srand(__seed: c_uint) void; -pub extern fn rand_r(__seed: [*c]c_uint) c_int; -pub extern fn drand48() f64; -pub extern fn erand48(__xsubi: [*c]c_ushort) f64; -pub extern fn lrand48() c_long; -pub extern fn nrand48(__xsubi: [*c]c_ushort) c_long; -pub extern fn mrand48() c_long; -pub extern fn jrand48(__xsubi: [*c]c_ushort) c_long; -pub extern fn srand48(__seedval: c_long) void; -pub extern fn seed48(__seed16v: [*c]c_ushort) [*c]c_ushort; -pub extern fn lcong48(__param: [*c]c_ushort) void; -pub const struct_drand48_data = extern struct { - __x: [3]c_ushort, - __old_x: [3]c_ushort, - __c: c_ushort, - __init: c_ushort, - __a: c_ulonglong, -}; -pub extern fn drand48_r(noalias __buffer: [*c]struct_drand48_data, noalias __result: [*c]f64) c_int; -pub extern fn erand48_r(__xsubi: [*c]c_ushort, noalias __buffer: [*c]struct_drand48_data, noalias __result: [*c]f64) c_int; -pub extern fn lrand48_r(noalias __buffer: [*c]struct_drand48_data, noalias __result: [*c]c_long) c_int; -pub extern fn nrand48_r(__xsubi: [*c]c_ushort, noalias __buffer: [*c]struct_drand48_data, noalias __result: [*c]c_long) c_int; -pub extern fn mrand48_r(noalias __buffer: [*c]struct_drand48_data, noalias __result: [*c]c_long) c_int; -pub extern fn jrand48_r(__xsubi: [*c]c_ushort, noalias __buffer: [*c]struct_drand48_data, noalias __result: [*c]c_long) c_int; -pub extern fn srand48_r(__seedval: c_long, __buffer: [*c]struct_drand48_data) c_int; -pub extern fn seed48_r(__seed16v: [*c]c_ushort, __buffer: [*c]struct_drand48_data) c_int; -pub extern fn lcong48_r(__param: [*c]c_ushort, __buffer: [*c]struct_drand48_data) c_int; -pub extern fn malloc(__size: c_ulong) ?*c_void; -pub extern fn calloc(__nmemb: c_ulong, __size: c_ulong) ?*c_void; -pub extern fn realloc(__ptr: ?*c_void, __size: c_ulong) ?*c_void; -pub extern fn reallocarray(__ptr: ?*c_void, __nmemb: usize, __size: usize) ?*c_void; -pub extern fn free(__ptr: ?*c_void) void; -pub extern fn alloca(__size: c_ulong) ?*c_void; -pub extern fn valloc(__size: usize) ?*c_void; -pub extern fn posix_memalign(__memptr: [*c](?*c_void), __alignment: usize, __size: usize) c_int; -pub extern fn aligned_alloc(__alignment: usize, __size: usize) ?*c_void; -pub extern fn abort() noreturn; -pub extern fn atexit(__func: ?extern fn () void) c_int; -pub extern fn at_quick_exit(__func: ?extern fn () void) c_int; -pub extern fn on_exit(__func: ?extern fn (c_int, ?*c_void) void, __arg: ?*c_void) c_int; -pub extern fn exit(__status: c_int) noreturn; -pub extern fn quick_exit(__status: c_int) noreturn; -pub extern fn _Exit(__status: c_int) noreturn; -pub extern fn getenv(__name: [*c]const u8) [*c]u8; -pub extern fn putenv(__string: [*c]u8) c_int; -pub extern fn setenv(__name: [*c]const u8, __value: [*c]const u8, __replace: c_int) c_int; -pub extern fn unsetenv(__name: [*c]const u8) c_int; -pub extern fn clearenv() c_int; -pub extern fn mktemp(__template: [*c]u8) [*c]u8; -pub extern fn mkstemp(__template: [*c]u8) c_int; -pub extern fn mkstemps(__template: [*c]u8, __suffixlen: c_int) c_int; -pub extern fn mkdtemp(__template: [*c]u8) [*c]u8; -pub extern fn system(__command: [*c]const u8) c_int; -pub extern fn realpath(noalias __name: [*c]const u8, noalias __resolved: [*c]u8) [*c]u8; -pub const __compar_fn_t = ?extern fn (?*const c_void, ?*const c_void) c_int; -pub extern fn bsearch(__key: ?*const c_void, __base: ?*const c_void, __nmemb: usize, __size: usize, __compar: __compar_fn_t) ?*c_void; -pub extern fn qsort(__base: ?*c_void, __nmemb: usize, __size: usize, __compar: __compar_fn_t) void; -pub extern fn abs(__x: c_int) c_int; -pub extern fn labs(__x: c_long) c_long; -pub extern fn llabs(__x: c_longlong) c_longlong; -pub extern fn div(__numer: c_int, __denom: c_int) div_t; -pub extern fn ldiv(__numer: c_long, __denom: c_long) ldiv_t; -pub extern fn lldiv(__numer: c_longlong, __denom: c_longlong) lldiv_t; -pub extern fn ecvt(__value: f64, __ndigit: c_int, noalias __decpt: [*c]c_int, noalias __sign: [*c]c_int) [*c]u8; -pub extern fn fcvt(__value: f64, __ndigit: c_int, noalias __decpt: [*c]c_int, noalias __sign: [*c]c_int) [*c]u8; -pub extern fn gcvt(__value: f64, __ndigit: c_int, __buf: [*c]u8) [*c]u8; -pub extern fn qecvt(__value: c_longdouble, __ndigit: c_int, noalias __decpt: [*c]c_int, noalias __sign: [*c]c_int) [*c]u8; -pub extern fn qfcvt(__value: c_longdouble, __ndigit: c_int, noalias __decpt: [*c]c_int, noalias __sign: [*c]c_int) [*c]u8; -pub extern fn qgcvt(__value: c_longdouble, __ndigit: c_int, __buf: [*c]u8) [*c]u8; -pub extern fn ecvt_r(__value: f64, __ndigit: c_int, noalias __decpt: [*c]c_int, noalias __sign: [*c]c_int, noalias __buf: [*c]u8, __len: usize) c_int; -pub extern fn fcvt_r(__value: f64, __ndigit: c_int, noalias __decpt: [*c]c_int, noalias __sign: [*c]c_int, noalias __buf: [*c]u8, __len: usize) c_int; -pub extern fn qecvt_r(__value: c_longdouble, __ndigit: c_int, noalias __decpt: [*c]c_int, noalias __sign: [*c]c_int, noalias __buf: [*c]u8, __len: usize) c_int; -pub extern fn qfcvt_r(__value: c_longdouble, __ndigit: c_int, noalias __decpt: [*c]c_int, noalias __sign: [*c]c_int, noalias __buf: [*c]u8, __len: usize) c_int; -pub extern fn mblen(__s: [*c]const u8, __n: usize) c_int; -pub extern fn mbtowc(noalias __pwc: [*c]wchar_t, noalias __s: [*c]const u8, __n: usize) c_int; -pub extern fn wctomb(__s: [*c]u8, __wchar: wchar_t) c_int; -pub extern fn mbstowcs(noalias __pwcs: [*c]wchar_t, noalias __s: [*c]const u8, __n: usize) usize; -pub extern fn wcstombs(noalias __s: [*c]u8, noalias __pwcs: [*c]const wchar_t, __n: usize) usize; -pub extern fn rpmatch(__response: [*c]const u8) c_int; -pub extern fn getsubopt(noalias __optionp: [*c]([*c]u8), noalias __tokens: [*c]const ([*c]u8), noalias __valuep: [*c]([*c]u8)) c_int; -pub extern fn getloadavg(__loadavg: [*c]f64, __nelem: c_int) c_int; -pub const magick_int8_t = i8; -pub const magick_uint8_t = u8; -pub const magick_int16_t = c_short; -pub const magick_uint16_t = c_ushort; -pub const magick_int32_t = c_int; -pub const magick_uint32_t = c_uint; -pub const magick_int64_t = c_long; -pub const magick_uint64_t = c_ulong; -pub const magick_uintmax_t = c_ulong; -pub const magick_uintptr_t = c_ulong; -pub const magick_off_t = magick_int64_t; -pub const UndefinedClass = 0; -pub const DirectClass = 1; -pub const PseudoClass = 2; -pub const ClassType = extern enum { - UndefinedClass = 0, - DirectClass = 1, - PseudoClass = 2, -}; -pub const UndefinedColorspace = 0; -pub const RGBColorspace = 1; -pub const GRAYColorspace = 2; -pub const TransparentColorspace = 3; -pub const OHTAColorspace = 4; -pub const XYZColorspace = 5; -pub const YCCColorspace = 6; -pub const YIQColorspace = 7; -pub const YPbPrColorspace = 8; -pub const YUVColorspace = 9; -pub const CMYKColorspace = 10; -pub const sRGBColorspace = 11; -pub const HSLColorspace = 12; -pub const HWBColorspace = 13; -pub const LABColorspace = 14; -pub const CineonLogRGBColorspace = 15; -pub const Rec601LumaColorspace = 16; -pub const Rec601YCbCrColorspace = 17; -pub const Rec709LumaColorspace = 18; -pub const Rec709YCbCrColorspace = 19; -pub const ColorspaceType = extern enum { - UndefinedColorspace = 0, - RGBColorspace = 1, - GRAYColorspace = 2, - TransparentColorspace = 3, - OHTAColorspace = 4, - XYZColorspace = 5, - YCCColorspace = 6, - YIQColorspace = 7, - YPbPrColorspace = 8, - YUVColorspace = 9, - CMYKColorspace = 10, - sRGBColorspace = 11, - HSLColorspace = 12, - HWBColorspace = 13, - LABColorspace = 14, - CineonLogRGBColorspace = 15, - Rec601LumaColorspace = 16, - Rec601YCbCrColorspace = 17, - Rec709LumaColorspace = 18, - Rec709YCbCrColorspace = 19, -}; -pub const UndefinedCompression = 0; -pub const NoCompression = 1; -pub const BZipCompression = 2; -pub const FaxCompression = 3; -pub const Group3Compression = 3; -pub const Group4Compression = 4; -pub const JPEGCompression = 5; -pub const LosslessJPEGCompression = 6; -pub const LZWCompression = 7; -pub const RLECompression = 8; -pub const ZipCompression = 9; -pub const LZMACompression = 10; -pub const JPEG2000Compression = 11; -pub const JBIG1Compression = 12; -pub const JBIG2Compression = 13; -pub const ZSTDCompression = 14; -pub const WebPCompression = 15; -pub const CompressionType = extern enum { - UndefinedCompression = 0, - NoCompression = 1, - BZipCompression = 2, - FaxCompression = 3, - Group4Compression = 4, - JPEGCompression = 5, - LosslessJPEGCompression = 6, - LZWCompression = 7, - RLECompression = 8, - ZipCompression = 9, - LZMACompression = 10, - JPEG2000Compression = 11, - JBIG1Compression = 12, - JBIG2Compression = 13, - ZSTDCompression = 14, - WebPCompression = 15, - pub const Group3Compression = @This().FaxCompression; -}; -pub const Quantum = c_ushort; -pub const struct__PixelPacket = extern struct { - blue: Quantum, - green: Quantum, - red: Quantum, - opacity: Quantum, -}; -pub const PixelPacket = struct__PixelPacket; -pub const struct__PrimaryInfo = extern struct { - x: f64, - y: f64, - z: f64, -}; -pub const PrimaryInfo = struct__PrimaryInfo; -pub const struct__ChromaticityInfo = extern struct { - red_primary: PrimaryInfo, - green_primary: PrimaryInfo, - blue_primary: PrimaryInfo, - white_point: PrimaryInfo, -}; -pub const ChromaticityInfo = struct__ChromaticityInfo; -pub const UndefinedOrientation = 0; -pub const TopLeftOrientation = 1; -pub const TopRightOrientation = 2; -pub const BottomRightOrientation = 3; -pub const BottomLeftOrientation = 4; -pub const LeftTopOrientation = 5; -pub const RightTopOrientation = 6; -pub const RightBottomOrientation = 7; -pub const LeftBottomOrientation = 8; -pub const OrientationType = extern enum { - UndefinedOrientation = 0, - TopLeftOrientation = 1, - TopRightOrientation = 2, - BottomRightOrientation = 3, - BottomLeftOrientation = 4, - LeftTopOrientation = 5, - RightTopOrientation = 6, - RightBottomOrientation = 7, - LeftBottomOrientation = 8, -}; -pub const UndefinedIntent = 0; -pub const SaturationIntent = 1; -pub const PerceptualIntent = 2; -pub const AbsoluteIntent = 3; -pub const RelativeIntent = 4; -pub const RenderingIntent = extern enum { - UndefinedIntent = 0, - SaturationIntent = 1, - PerceptualIntent = 2, - AbsoluteIntent = 3, - RelativeIntent = 4, -}; -pub const UndefinedResolution = 0; -pub const PixelsPerInchResolution = 1; -pub const PixelsPerCentimeterResolution = 2; -pub const ResolutionType = extern enum { - UndefinedResolution = 0, - PixelsPerInchResolution = 1, - PixelsPerCentimeterResolution = 2, -}; -pub const struct__RectangleInfo = extern struct { - width: c_ulong, - height: c_ulong, - x: c_long, - y: c_long, -}; -pub const RectangleInfo = struct__RectangleInfo; -pub const UndefinedFilter = 0; -pub const PointFilter = 1; -pub const BoxFilter = 2; -pub const TriangleFilter = 3; -pub const HermiteFilter = 4; -pub const HanningFilter = 5; -pub const HammingFilter = 6; -pub const BlackmanFilter = 7; -pub const GaussianFilter = 8; -pub const QuadraticFilter = 9; -pub const CubicFilter = 10; -pub const CatromFilter = 11; -pub const MitchellFilter = 12; -pub const LanczosFilter = 13; -pub const BesselFilter = 14; -pub const SincFilter = 15; -pub const FilterTypes = extern enum { - UndefinedFilter = 0, - PointFilter = 1, - BoxFilter = 2, - TriangleFilter = 3, - HermiteFilter = 4, - HanningFilter = 5, - HammingFilter = 6, - BlackmanFilter = 7, - GaussianFilter = 8, - QuadraticFilter = 9, - CubicFilter = 10, - CatromFilter = 11, - MitchellFilter = 12, - LanczosFilter = 13, - BesselFilter = 14, - SincFilter = 15, -}; -pub const UndefinedInterlace = 0; -pub const NoInterlace = 1; -pub const LineInterlace = 2; -pub const PlaneInterlace = 3; -pub const PartitionInterlace = 4; -pub const InterlaceType = extern enum { - UndefinedInterlace = 0, - NoInterlace = 1, - LineInterlace = 2, - PlaneInterlace = 3, - PartitionInterlace = 4, -}; -pub const UndefinedEndian = 0; -pub const LSBEndian = 1; -pub const MSBEndian = 2; -pub const NativeEndian = 3; -pub const EndianType = extern enum { - UndefinedEndian = 0, - LSBEndian = 1, - MSBEndian = 2, - NativeEndian = 3, -}; -pub const ForgetGravity = 0; -pub const NorthWestGravity = 1; -pub const NorthGravity = 2; -pub const NorthEastGravity = 3; -pub const WestGravity = 4; -pub const CenterGravity = 5; -pub const EastGravity = 6; -pub const SouthWestGravity = 7; -pub const SouthGravity = 8; -pub const SouthEastGravity = 9; -pub const StaticGravity = 10; -pub const GravityType = extern enum { - ForgetGravity = 0, - NorthWestGravity = 1, - NorthGravity = 2, - NorthEastGravity = 3, - WestGravity = 4, - CenterGravity = 5, - EastGravity = 6, - SouthWestGravity = 7, - SouthGravity = 8, - SouthEastGravity = 9, - StaticGravity = 10, -}; -pub const UndefinedCompositeOp = 0; -pub const OverCompositeOp = 1; -pub const InCompositeOp = 2; -pub const OutCompositeOp = 3; -pub const AtopCompositeOp = 4; -pub const XorCompositeOp = 5; -pub const PlusCompositeOp = 6; -pub const MinusCompositeOp = 7; -pub const AddCompositeOp = 8; -pub const SubtractCompositeOp = 9; -pub const DifferenceCompositeOp = 10; -pub const MultiplyCompositeOp = 11; -pub const BumpmapCompositeOp = 12; -pub const CopyCompositeOp = 13; -pub const CopyRedCompositeOp = 14; -pub const CopyGreenCompositeOp = 15; -pub const CopyBlueCompositeOp = 16; -pub const CopyOpacityCompositeOp = 17; -pub const ClearCompositeOp = 18; -pub const DissolveCompositeOp = 19; -pub const DisplaceCompositeOp = 20; -pub const ModulateCompositeOp = 21; -pub const ThresholdCompositeOp = 22; -pub const NoCompositeOp = 23; -pub const DarkenCompositeOp = 24; -pub const LightenCompositeOp = 25; -pub const HueCompositeOp = 26; -pub const SaturateCompositeOp = 27; -pub const ColorizeCompositeOp = 28; -pub const LuminizeCompositeOp = 29; -pub const ScreenCompositeOp = 30; -pub const OverlayCompositeOp = 31; -pub const CopyCyanCompositeOp = 32; -pub const CopyMagentaCompositeOp = 33; -pub const CopyYellowCompositeOp = 34; -pub const CopyBlackCompositeOp = 35; -pub const DivideCompositeOp = 36; -pub const HardLightCompositeOp = 37; -pub const ExclusionCompositeOp = 38; -pub const ColorDodgeCompositeOp = 39; -pub const ColorBurnCompositeOp = 40; -pub const SoftLightCompositeOp = 41; -pub const LinearBurnCompositeOp = 42; -pub const LinearDodgeCompositeOp = 43; -pub const LinearLightCompositeOp = 44; -pub const VividLightCompositeOp = 45; -pub const PinLightCompositeOp = 46; -pub const HardMixCompositeOp = 47; -pub const CompositeOperator = extern enum { - UndefinedCompositeOp = 0, - OverCompositeOp = 1, - InCompositeOp = 2, - OutCompositeOp = 3, - AtopCompositeOp = 4, - XorCompositeOp = 5, - PlusCompositeOp = 6, - MinusCompositeOp = 7, - AddCompositeOp = 8, - SubtractCompositeOp = 9, - DifferenceCompositeOp = 10, - MultiplyCompositeOp = 11, - BumpmapCompositeOp = 12, - CopyCompositeOp = 13, - CopyRedCompositeOp = 14, - CopyGreenCompositeOp = 15, - CopyBlueCompositeOp = 16, - CopyOpacityCompositeOp = 17, - ClearCompositeOp = 18, - DissolveCompositeOp = 19, - DisplaceCompositeOp = 20, - ModulateCompositeOp = 21, - ThresholdCompositeOp = 22, - NoCompositeOp = 23, - DarkenCompositeOp = 24, - LightenCompositeOp = 25, - HueCompositeOp = 26, - SaturateCompositeOp = 27, - ColorizeCompositeOp = 28, - LuminizeCompositeOp = 29, - ScreenCompositeOp = 30, - OverlayCompositeOp = 31, - CopyCyanCompositeOp = 32, - CopyMagentaCompositeOp = 33, - CopyYellowCompositeOp = 34, - CopyBlackCompositeOp = 35, - DivideCompositeOp = 36, - HardLightCompositeOp = 37, - ExclusionCompositeOp = 38, - ColorDodgeCompositeOp = 39, - ColorBurnCompositeOp = 40, - SoftLightCompositeOp = 41, - LinearBurnCompositeOp = 42, - LinearDodgeCompositeOp = 43, - LinearLightCompositeOp = 44, - VividLightCompositeOp = 45, - PinLightCompositeOp = 46, - HardMixCompositeOp = 47, -}; -pub const UndefinedDispose = 0; -pub const NoneDispose = 1; -pub const BackgroundDispose = 2; -pub const PreviousDispose = 3; -pub const DisposeType = extern enum { - UndefinedDispose = 0, - NoneDispose = 1, - BackgroundDispose = 2, - PreviousDispose = 3, -}; -pub const struct__ErrorInfo = extern struct { - mean_error_per_pixel: f64, - normalized_mean_error: f64, - normalized_maximum_error: f64, -}; -pub const ErrorInfo = struct__ErrorInfo; -pub const struct__Timer = extern struct { - start: f64, - stop: f64, - total: f64, -}; -pub const Timer = struct__Timer; -pub const UndefinedTimerState = 0; -pub const StoppedTimerState = 1; -pub const RunningTimerState = 2; -pub const TimerState = extern enum { - UndefinedTimerState = 0, - StoppedTimerState = 1, - RunningTimerState = 2, -}; -pub const struct__TimerInfo = extern struct { - user: Timer, - elapsed: Timer, - state: TimerState, - signature: c_ulong, -}; -pub const TimerInfo = struct__TimerInfo; -pub const UndefinedException = 0; -pub const EventException = 100; -pub const ExceptionEvent = 101; -pub const ResourceEvent = 102; -pub const ResourceLimitEvent = 102; -pub const TypeEvent = 105; -pub const AnnotateEvent = 105; -pub const OptionEvent = 110; -pub const DelegateEvent = 115; -pub const MissingDelegateEvent = 120; -pub const CorruptImageEvent = 125; -pub const FileOpenEvent = 130; -pub const BlobEvent = 135; -pub const StreamEvent = 140; -pub const CacheEvent = 145; -pub const CoderEvent = 150; -pub const ModuleEvent = 155; -pub const DrawEvent = 160; -pub const RenderEvent = 160; -pub const ImageEvent = 165; -pub const WandEvent = 167; -pub const TemporaryFileEvent = 170; -pub const TransformEvent = 175; -pub const XServerEvent = 180; -pub const X11Event = 181; -pub const UserEvent = 182; -pub const MonitorEvent = 185; -pub const LocaleEvent = 186; -pub const DeprecateEvent = 187; -pub const RegistryEvent = 190; -pub const ConfigureEvent = 195; -pub const WarningException = 300; -pub const ExceptionWarning = 301; -pub const ResourceWarning = 302; -pub const ResourceLimitWarning = 302; -pub const TypeWarning = 305; -pub const AnnotateWarning = 305; -pub const OptionWarning = 310; -pub const DelegateWarning = 315; -pub const MissingDelegateWarning = 320; -pub const CorruptImageWarning = 325; -pub const FileOpenWarning = 330; -pub const BlobWarning = 335; -pub const StreamWarning = 340; -pub const CacheWarning = 345; -pub const CoderWarning = 350; -pub const ModuleWarning = 355; -pub const DrawWarning = 360; -pub const RenderWarning = 360; -pub const ImageWarning = 365; -pub const WandWarning = 367; -pub const TemporaryFileWarning = 370; -pub const TransformWarning = 375; -pub const XServerWarning = 380; -pub const X11Warning = 381; -pub const UserWarning = 382; -pub const MonitorWarning = 385; -pub const LocaleWarning = 386; -pub const DeprecateWarning = 387; -pub const RegistryWarning = 390; -pub const ConfigureWarning = 395; -pub const ErrorException = 400; -pub const ExceptionError = 401; -pub const ResourceError = 402; -pub const ResourceLimitError = 402; -pub const TypeError = 405; -pub const AnnotateError = 405; -pub const OptionError = 410; -pub const DelegateError = 415; -pub const MissingDelegateError = 420; -pub const CorruptImageError = 425; -pub const FileOpenError = 430; -pub const BlobError = 435; -pub const StreamError = 440; -pub const CacheError = 445; -pub const CoderError = 450; -pub const ModuleError = 455; -pub const DrawError = 460; -pub const RenderError = 460; -pub const ImageError = 465; -pub const WandError = 467; -pub const TemporaryFileError = 470; -pub const TransformError = 475; -pub const XServerError = 480; -pub const X11Error = 481; -pub const UserError = 482; -pub const MonitorError = 485; -pub const LocaleError = 486; -pub const DeprecateError = 487; -pub const RegistryError = 490; -pub const ConfigureError = 495; -pub const FatalErrorException = 700; -pub const ExceptionFatalError = 701; -pub const ResourceFatalError = 702; -pub const ResourceLimitFatalError = 702; -pub const TypeFatalError = 705; -pub const AnnotateFatalError = 705; -pub const OptionFatalError = 710; -pub const DelegateFatalError = 715; -pub const MissingDelegateFatalError = 720; -pub const CorruptImageFatalError = 725; -pub const FileOpenFatalError = 730; -pub const BlobFatalError = 735; -pub const StreamFatalError = 740; -pub const CacheFatalError = 745; -pub const CoderFatalError = 750; -pub const ModuleFatalError = 755; -pub const DrawFatalError = 760; -pub const RenderFatalError = 760; -pub const ImageFatalError = 765; -pub const WandFatalError = 767; -pub const TemporaryFileFatalError = 770; -pub const TransformFatalError = 775; -pub const XServerFatalError = 780; -pub const X11FatalError = 781; -pub const UserFatalError = 782; -pub const MonitorFatalError = 785; -pub const LocaleFatalError = 786; -pub const DeprecateFatalError = 787; -pub const RegistryFatalError = 790; -pub const ConfigureFatalError = 795; -pub const ExceptionType = extern enum { - UndefinedException = 0, - EventException = 100, - ExceptionEvent = 101, - ResourceEvent = 102, - pub const ResourceLimitEvent = 102; - TypeEvent = 105, - pub const AnnotateEvent = 105; - OptionEvent = 110, - DelegateEvent = 115, - MissingDelegateEvent = 120, - CorruptImageEvent = 125, - FileOpenEvent = 130, - BlobEvent = 135, - StreamEvent = 140, - CacheEvent = 145, - CoderEvent = 150, - ModuleEvent = 155, - DrawEvent = 160, - pub const RenderEvent = 160; - ImageEvent = 165, - WandEvent = 167, - TemporaryFileEvent = 170, - TransformEvent = 175, - XServerEvent = 180, - X11Event = 181, - UserEvent = 182, - MonitorEvent = 185, - LocaleEvent = 186, - DeprecateEvent = 187, - RegistryEvent = 190, - ConfigureEvent = 195, - WarningException = 300, - ExceptionWarning = 301, - ResourceWarning = 302, - pub const ResourceLimitWarning = 302; - TypeWarning = 305, - pub const AnnotateWarning = 305; - OptionWarning = 310, - DelegateWarning = 315, - MissingDelegateWarning = 320, - CorruptImageWarning = 325, - FileOpenWarning = 330, - BlobWarning = 335, - StreamWarning = 340, - CacheWarning = 345, - CoderWarning = 350, - ModuleWarning = 355, - DrawWarning = 360, - pub const RenderWarning = 360; - ImageWarning = 365, - WandWarning = 367, - TemporaryFileWarning = 370, - TransformWarning = 375, - XServerWarning = 380, - X11Warning = 381, - UserWarning = 382, - MonitorWarning = 385, - LocaleWarning = 386, - DeprecateWarning = 387, - RegistryWarning = 390, - ConfigureWarning = 395, - ErrorException = 400, - ExceptionError = 401, - ResourceError = 402, - pub const ResourceLimitError = 402; - TypeError = 405, - pub const AnnotateError = 405; - OptionError = 410, - DelegateError = 415, - MissingDelegateError = 420, - CorruptImageError = 425, - FileOpenError = 430, - BlobError = 435, - StreamError = 440, - CacheError = 445, - CoderError = 450, - ModuleError = 455, - DrawError = 460, - pub const RenderError = 460; - ImageError = 465, - WandError = 467, - TemporaryFileError = 470, - TransformError = 475, - XServerError = 480, - X11Error = 481, - UserError = 482, - MonitorError = 485, - LocaleError = 486, - DeprecateError = 487, - RegistryError = 490, - ConfigureError = 495, - FatalErrorException = 700, - ExceptionFatalError = 701, - ResourceFatalError = 702, - pub const ResourceLimitFatalError = 702; - TypeFatalError = 705, - pub const AnnotateFatalError = 705; - OptionFatalError = 710, - DelegateFatalError = 715, - MissingDelegateFatalError = 720, - CorruptImageFatalError = 725, - FileOpenFatalError = 730, - BlobFatalError = 735, - StreamFatalError = 740, - CacheFatalError = 745, - CoderFatalError = 750, - ModuleFatalError = 755, - DrawFatalError = 760, - pub const RenderFatalError = 760; - ImageFatalError = 765, - WandFatalError = 767, - TemporaryFileFatalError = 770, - TransformFatalError = 775, - XServerFatalError = 780, - X11FatalError = 781, - UserFatalError = 782, - MonitorFatalError = 785, - LocaleFatalError = 786, - DeprecateFatalError = 787, - RegistryFatalError = 790, - ConfigureFatalError = 795, -}; -pub const struct__ExceptionInfo = extern struct { - severity: ExceptionType, - reason: [*c]u8, - description: [*c]u8, - error_number: c_int, - module: [*c]u8, - function: [*c]u8, - line: c_ulong, - signature: c_ulong, -}; -pub const ExceptionInfo = struct__ExceptionInfo; -pub const struct__ImageExtra = @OpaqueType(); -pub const struct__CacheInfo = @OpaqueType(); -pub const _CacheInfoPtr_ = ?*struct__CacheInfo; -pub const struct__ThreadViewSet = @OpaqueType(); -pub const _ThreadViewSetPtr_ = ?*struct__ThreadViewSet; -pub const struct__ImageAttribute = extern struct { - key: [*c]u8, - value: [*c]u8, - length: usize, - previous: [*c]struct__ImageAttribute, - next: [*c]struct__ImageAttribute, -}; -pub const _ImageAttributePtr_ = [*c]struct__ImageAttribute; -pub const struct__Ascii85Info = extern struct { - offset: c_long, - line_break: c_long, - buffer: [10]magick_uint8_t, -}; -pub const _Ascii85InfoPtr_ = [*c]struct__Ascii85Info; -pub const struct__BlobInfo = @OpaqueType(); -pub const _BlobInfoPtr_ = ?*struct__BlobInfo; -pub const struct__SemaphoreInfo = @OpaqueType(); -pub const _SemaphoreInfoPtr_ = ?*struct__SemaphoreInfo; -pub const struct__Image = extern struct { - storage_class: ClassType, - colorspace: ColorspaceType, - compression: CompressionType, - dither: c_uint, - matte: c_uint, - columns: c_ulong, - rows: c_ulong, - colors: c_uint, - depth: c_uint, - colormap: [*c]PixelPacket, - background_color: PixelPacket, - border_color: PixelPacket, - matte_color: PixelPacket, - gamma: f64, - chromaticity: ChromaticityInfo, - orientation: OrientationType, - rendering_intent: RenderingIntent, - units: ResolutionType, - montage: [*c]u8, - directory: [*c]u8, - geometry: [*c]u8, - offset: c_long, - x_resolution: f64, - y_resolution: f64, - page: RectangleInfo, - tile_info: RectangleInfo, - blur: f64, - fuzz: f64, - filter: FilterTypes, - interlace: InterlaceType, - endian: EndianType, - gravity: GravityType, - compose: CompositeOperator, - dispose: DisposeType, - scene: c_ulong, - delay: c_ulong, - iterations: c_ulong, - total_colors: c_ulong, - start_loop: c_long, - @"error": ErrorInfo, - timer: TimerInfo, - client_data: ?*c_void, - filename: [2053]u8, - magick_filename: [2053]u8, - magick: [2053]u8, - magick_columns: c_ulong, - magick_rows: c_ulong, - exception: ExceptionInfo, - previous: [*c]struct__Image, - next: [*c]struct__Image, - profiles: ?*c_void, - is_monochrome: c_uint, - is_grayscale: c_uint, - taint: c_uint, - extra: ?*struct__ImageExtra, - ping: c_uint, - cache: _CacheInfoPtr_, - default_views: _ThreadViewSetPtr_, - attributes: _ImageAttributePtr_, - ascii85: _Ascii85InfoPtr_, - blob: _BlobInfoPtr_, - reference_count: c_long, - semaphore: _SemaphoreInfoPtr_, - logging: c_uint, - list: [*c]struct__Image, - signature: c_ulong, -}; -pub const ImagePtr = [*c]struct__Image; -pub const ViewInfo = ?*c_void; -pub extern fn RGBTransformImage(arg0: ImagePtr, arg1: ColorspaceType) c_uint; -pub extern fn TransformColorspace(arg0: ImagePtr, arg1: ColorspaceType) c_uint; -pub extern fn TransformRGBImage(arg0: ImagePtr, arg1: ColorspaceType) c_uint; -pub const UndefinedExceptionBase = 0; -pub const ExceptionBase = 1; -pub const ResourceBase = 2; -pub const ResourceLimitBase = 2; -pub const TypeBase = 5; -pub const AnnotateBase = 5; -pub const OptionBase = 10; -pub const DelegateBase = 15; -pub const MissingDelegateBase = 20; -pub const CorruptImageBase = 25; -pub const FileOpenBase = 30; -pub const BlobBase = 35; -pub const StreamBase = 40; -pub const CacheBase = 45; -pub const CoderBase = 50; -pub const ModuleBase = 55; -pub const DrawBase = 60; -pub const RenderBase = 60; -pub const ImageBase = 65; -pub const WandBase = 67; -pub const TemporaryFileBase = 70; -pub const TransformBase = 75; -pub const XServerBase = 80; -pub const X11Base = 81; -pub const UserBase = 82; -pub const MonitorBase = 85; -pub const LocaleBase = 86; -pub const DeprecateBase = 87; -pub const RegistryBase = 90; -pub const ConfigureBase = 95; -pub const ExceptionBaseType = extern enum { - UndefinedExceptionBase = 0, - ExceptionBase = 1, - ResourceBase = 2, - ResourceLimitBase = 2, - TypeBase = 5, - AnnotateBase = 5, - OptionBase = 10, - DelegateBase = 15, - MissingDelegateBase = 20, - CorruptImageBase = 25, - FileOpenBase = 30, - BlobBase = 35, - StreamBase = 40, - CacheBase = 45, - CoderBase = 50, - ModuleBase = 55, - DrawBase = 60, - RenderBase = 60, - ImageBase = 65, - WandBase = 67, - TemporaryFileBase = 70, - TransformBase = 75, - XServerBase = 80, - X11Base = 81, - UserBase = 82, - MonitorBase = 85, - LocaleBase = 86, - DeprecateBase = 87, - RegistryBase = 90, - ConfigureBase = 95, -}; -pub const ErrorHandler = ?extern fn (ExceptionType, [*c]const u8, [*c]const u8) void; -pub const FatalErrorHandler = ?extern fn (ExceptionType, [*c]const u8, [*c]const u8) void; -pub const WarningHandler = ?extern fn (ExceptionType, [*c]const u8, [*c]const u8) void; -pub extern fn GetLocaleExceptionMessage(arg0: ExceptionType, arg1: [*c]const u8) [*c]const u8; -pub extern fn GetLocaleMessage(arg0: [*c]const u8) [*c]const u8; -pub extern fn SetErrorHandler(arg0: ErrorHandler) ErrorHandler; -pub extern fn SetFatalErrorHandler(arg0: FatalErrorHandler) FatalErrorHandler; -pub extern fn CatchException(arg0: [*c]const ExceptionInfo) void; -pub extern fn CopyException(copy: [*c]ExceptionInfo, original: [*c]const ExceptionInfo) void; -pub extern fn DestroyExceptionInfo(arg0: [*c]ExceptionInfo) void; -pub extern fn GetExceptionInfo(arg0: [*c]ExceptionInfo) void; -pub extern fn MagickError(arg0: ExceptionType, arg1: [*c]const u8, arg2: [*c]const u8) void; -pub extern fn MagickFatalError(arg0: ExceptionType, arg1: [*c]const u8, arg2: [*c]const u8) noreturn; -pub extern fn MagickWarning(arg0: ExceptionType, arg1: [*c]const u8, arg2: [*c]const u8) void; -pub extern fn _MagickError(arg0: ExceptionType, arg1: [*c]const u8, arg2: [*c]const u8) void; -pub extern fn _MagickFatalError(arg0: ExceptionType, arg1: [*c]const u8, arg2: [*c]const u8) noreturn; -pub extern fn _MagickWarning(arg0: ExceptionType, arg1: [*c]const u8, arg2: [*c]const u8) void; -pub extern fn SetExceptionInfo(arg0: [*c]ExceptionInfo, arg1: ExceptionType) void; -pub extern fn ThrowException(arg0: [*c]ExceptionInfo, arg1: ExceptionType, arg2: [*c]const u8, arg3: [*c]const u8) void; -pub extern fn ThrowLoggedException(exception: [*c]ExceptionInfo, severity: ExceptionType, reason: [*c]const u8, description: [*c]const u8, module: [*c]const u8, function: [*c]const u8, line: c_ulong) void; -pub extern fn SetWarningHandler(arg0: WarningHandler) WarningHandler; -pub const UndefinedEventMask = 0; -pub const NoEventsMask = 0; -pub const ConfigureEventMask = 1; -pub const AnnotateEventMask = 2; -pub const RenderEventMask = 4; -pub const TransformEventMask = 8; -pub const LocaleEventMask = 16; -pub const CoderEventMask = 32; -pub const X11EventMask = 64; -pub const CacheEventMask = 128; -pub const BlobEventMask = 256; -pub const DeprecateEventMask = 512; -pub const UserEventMask = 1024; -pub const ResourceEventMask = 2048; -pub const TemporaryFileEventMask = 4096; -pub const ExceptionEventMask = 458752; -pub const OptionEventMask = 16384; -pub const InformationEventMask = 32768; -pub const WarningEventMask = 65536; -pub const ErrorEventMask = 131072; -pub const FatalErrorEventMask = 262144; -pub const AllEventsMask = 2147483647; -pub const LogEventType = extern enum { - UndefinedEventMask = 0, - NoEventsMask = 0, - ConfigureEventMask = 1, - AnnotateEventMask = 2, - RenderEventMask = 4, - TransformEventMask = 8, - LocaleEventMask = 16, - CoderEventMask = 32, - X11EventMask = 64, - CacheEventMask = 128, - BlobEventMask = 256, - DeprecateEventMask = 512, - UserEventMask = 1024, - ResourceEventMask = 2048, - TemporaryFileEventMask = 4096, - ExceptionEventMask = 458752, - OptionEventMask = 16384, - InformationEventMask = 32768, - WarningEventMask = 65536, - ErrorEventMask = 131072, - FatalErrorEventMask = 262144, - AllEventsMask = 2147483647, -}; -pub const LogMethod = ?extern fn (ExceptionType, [*c]const u8) void; -pub extern fn IsEventLogging() c_uint; -pub extern fn LogMagickEvent(type_0: ExceptionType, module: [*c]const u8, function: [*c]const u8, line: c_ulong, format: [*c]const u8, ...) c_uint; -pub extern fn LogMagickEventList(type_0: ExceptionType, module: [*c]const u8, function: [*c]const u8, line: c_ulong, format: [*c]const u8, operands: [*c]struct___va_list_tag) c_uint; -pub extern fn SetLogEventMask(events: [*c]const u8) c_ulong; -pub extern fn SetLogFormat(format: [*c]const u8) void; -pub extern fn SetLogMethod(arg0: LogMethod) void; -pub extern fn GetElapsedTime(arg0: [*c]TimerInfo) f64; -pub extern fn GetUserTime(arg0: [*c]TimerInfo) f64; -pub extern fn GetTimerResolution() f64; -pub extern fn ContinueTimer(arg0: [*c]TimerInfo) c_uint; -pub extern fn GetTimerInfo(arg0: [*c]TimerInfo) void; -pub extern fn ResetTimer(arg0: [*c]TimerInfo) void; -pub const UnspecifiedAlpha = 0; -pub const AssociatedAlpha = 1; -pub const UnassociatedAlpha = 2; -pub const AlphaType = extern enum { - UnspecifiedAlpha = 0, - AssociatedAlpha = 1, - UnassociatedAlpha = 2, -}; -pub const UndefinedChannel = 0; -pub const RedChannel = 1; -pub const CyanChannel = 2; -pub const GreenChannel = 3; -pub const MagentaChannel = 4; -pub const BlueChannel = 5; -pub const YellowChannel = 6; -pub const OpacityChannel = 7; -pub const BlackChannel = 8; -pub const MatteChannel = 9; -pub const AllChannels = 10; -pub const GrayChannel = 11; -pub const ChannelType = extern enum { - UndefinedChannel = 0, - RedChannel = 1, - CyanChannel = 2, - GreenChannel = 3, - MagentaChannel = 4, - BlueChannel = 5, - YellowChannel = 6, - OpacityChannel = 7, - BlackChannel = 8, - MatteChannel = 9, - AllChannels = 10, - GrayChannel = 11, -}; -pub const NoValue = 0; -pub const XValue = 1; -pub const YValue = 2; -pub const WidthValue = 4; -pub const HeightValue = 8; -pub const AllValues = 15; -pub const XNegative = 16; -pub const YNegative = 32; -pub const PercentValue = 4096; -pub const AspectValue = 8192; -pub const LessValue = 16384; -pub const GreaterValue = 32768; -pub const AreaValue = 65536; -pub const MinimumValue = 131072; -pub const GeometryFlags = extern enum { - NoValue = 0, - XValue = 1, - YValue = 2, - WidthValue = 4, - HeightValue = 8, - AllValues = 15, - XNegative = 16, - YNegative = 32, - PercentValue = 4096, - AspectValue = 8192, - LessValue = 16384, - GreaterValue = 32768, - AreaValue = 65536, - MinimumValue = 131072, -}; -pub const UndefinedType = 0; -pub const BilevelType = 1; -pub const GrayscaleType = 2; -pub const GrayscaleMatteType = 3; -pub const PaletteType = 4; -pub const PaletteMatteType = 5; -pub const TrueColorType = 6; -pub const TrueColorMatteType = 7; -pub const ColorSeparationType = 8; -pub const ColorSeparationMatteType = 9; -pub const OptimizeType = 10; -pub const ImageType = extern enum { - UndefinedType = 0, - BilevelType = 1, - GrayscaleType = 2, - GrayscaleMatteType = 3, - PaletteType = 4, - PaletteMatteType = 5, - TrueColorType = 6, - TrueColorMatteType = 7, - ColorSeparationType = 8, - ColorSeparationMatteType = 9, - OptimizeType = 10, -}; -pub const UndefinedMode = 0; -pub const FrameMode = 1; -pub const UnframeMode = 2; -pub const ConcatenateMode = 3; -pub const MontageMode = extern enum { - UndefinedMode = 0, - FrameMode = 1, - UnframeMode = 2, - ConcatenateMode = 3, -}; -pub const UniformNoise = 0; -pub const GaussianNoise = 1; -pub const MultiplicativeGaussianNoise = 2; -pub const ImpulseNoise = 3; -pub const LaplacianNoise = 4; -pub const PoissonNoise = 5; -pub const RandomNoise = 6; -pub const UndefinedNoise = 7; -pub const NoiseType = extern enum { - UniformNoise = 0, - GaussianNoise = 1, - MultiplicativeGaussianNoise = 2, - ImpulseNoise = 3, - LaplacianNoise = 4, - PoissonNoise = 5, - RandomNoise = 6, - UndefinedNoise = 7, -}; -pub const UndefinedPreview = 0; -pub const RotatePreview = 1; -pub const ShearPreview = 2; -pub const RollPreview = 3; -pub const HuePreview = 4; -pub const SaturationPreview = 5; -pub const BrightnessPreview = 6; -pub const GammaPreview = 7; -pub const SpiffPreview = 8; -pub const DullPreview = 9; -pub const GrayscalePreview = 10; -pub const QuantizePreview = 11; -pub const DespecklePreview = 12; -pub const ReduceNoisePreview = 13; -pub const AddNoisePreview = 14; -pub const SharpenPreview = 15; -pub const BlurPreview = 16; -pub const ThresholdPreview = 17; -pub const EdgeDetectPreview = 18; -pub const SpreadPreview = 19; -pub const SolarizePreview = 20; -pub const ShadePreview = 21; -pub const RaisePreview = 22; -pub const SegmentPreview = 23; -pub const SwirlPreview = 24; -pub const ImplodePreview = 25; -pub const WavePreview = 26; -pub const OilPaintPreview = 27; -pub const CharcoalDrawingPreview = 28; -pub const JPEGPreview = 29; -pub const PreviewType = extern enum { - UndefinedPreview = 0, - RotatePreview = 1, - ShearPreview = 2, - RollPreview = 3, - HuePreview = 4, - SaturationPreview = 5, - BrightnessPreview = 6, - GammaPreview = 7, - SpiffPreview = 8, - DullPreview = 9, - GrayscalePreview = 10, - QuantizePreview = 11, - DespecklePreview = 12, - ReduceNoisePreview = 13, - AddNoisePreview = 14, - SharpenPreview = 15, - BlurPreview = 16, - ThresholdPreview = 17, - EdgeDetectPreview = 18, - SpreadPreview = 19, - SolarizePreview = 20, - ShadePreview = 21, - RaisePreview = 22, - SegmentPreview = 23, - SwirlPreview = 24, - ImplodePreview = 25, - WavePreview = 26, - OilPaintPreview = 27, - CharcoalDrawingPreview = 28, - JPEGPreview = 29, -}; -pub const struct__AffineMatrix = extern struct { - sx: f64, - rx: f64, - ry: f64, - sy: f64, - tx: f64, - ty: f64, -}; -pub const AffineMatrix = struct__AffineMatrix; -pub const struct__DoublePixelPacket = extern struct { - red: f64, - green: f64, - blue: f64, - opacity: f64, -}; -pub const DoublePixelPacket = struct__DoublePixelPacket; -pub const struct__FloatPixelPacket = extern struct { - red: f32, - green: f32, - blue: f32, - opacity: f32, -}; -pub const FloatPixelPacket = struct__FloatPixelPacket; -pub const struct__FrameInfo = extern struct { - width: c_ulong, - height: c_ulong, - x: c_long, - y: c_long, - inner_bevel: c_long, - outer_bevel: c_long, -}; -pub const FrameInfo = struct__FrameInfo; -pub const IndexPacket = Quantum; -pub const struct__LongPixelPacket = extern struct { - red: c_ulong, - green: c_ulong, - blue: c_ulong, - opacity: c_ulong, -}; -pub const LongPixelPacket = struct__LongPixelPacket; -pub const struct__MontageInfo = extern struct { - geometry: [*c]u8, - tile: [*c]u8, - title: [*c]u8, - frame: [*c]u8, - texture: [*c]u8, - font: [*c]u8, - pointsize: f64, - border_width: c_ulong, - shadow: c_uint, - fill: PixelPacket, - stroke: PixelPacket, - background_color: PixelPacket, - border_color: PixelPacket, - matte_color: PixelPacket, - gravity: GravityType, - filename: [2053]u8, - signature: c_ulong, -}; -pub const MontageInfo = struct__MontageInfo; -pub const struct__ProfileInfo = extern struct { - length: usize, - name: [*c]u8, - info: [*c]u8, -}; -pub const ProfileInfo = struct__ProfileInfo; -pub const struct__SegmentInfo = extern struct { - x1: f64, - y1: f64, - x2: f64, - y2: f64, -}; -pub const SegmentInfo = struct__SegmentInfo; -pub const Image = struct__Image; -pub const struct__ImageInfo = extern struct { - compression: CompressionType, - temporary: c_uint, - adjoin: c_uint, - antialias: c_uint, - subimage: c_ulong, - subrange: c_ulong, - depth: c_ulong, - size: [*c]u8, - tile: [*c]u8, - page: [*c]u8, - interlace: InterlaceType, - endian: EndianType, - units: ResolutionType, - quality: c_ulong, - sampling_factor: [*c]u8, - server_name: [*c]u8, - font: [*c]u8, - texture: [*c]u8, - density: [*c]u8, - pointsize: f64, - fuzz: f64, - pen: PixelPacket, - background_color: PixelPacket, - border_color: PixelPacket, - matte_color: PixelPacket, - dither: c_uint, - monochrome: c_uint, - progress: c_uint, - colorspace: ColorspaceType, - type: ImageType, - group: c_long, - verbose: c_uint, - view: [*c]u8, - authenticate: [*c]u8, - client_data: ?*c_void, - file: [*c]FILE, - magick: [2053]u8, - filename: [2053]u8, - cache: _CacheInfoPtr_, - definitions: ?*c_void, - attributes: [*c]Image, - ping: c_uint, - preview_type: PreviewType, - affirm: c_uint, - blob: _BlobInfoPtr_, - length: usize, - unique: [2053]u8, - zero: [2053]u8, - signature: c_ulong, -}; -pub const ImageInfo = struct__ImageInfo; -pub extern fn CatchImageException(arg0: [*c]Image) ExceptionType; -pub extern fn AllocateImage(arg0: [*c]const ImageInfo) [*c]Image; -pub extern fn AppendImages(arg0: [*c]const Image, arg1: c_uint, arg2: [*c]ExceptionInfo) [*c]Image; -pub extern fn CloneImage(arg0: [*c]const Image, arg1: c_ulong, arg2: c_ulong, arg3: c_uint, arg4: [*c]ExceptionInfo) [*c]Image; -pub extern fn GetImageClipMask(arg0: [*c]const Image, arg1: [*c]ExceptionInfo) [*c]Image; -pub extern fn GetImageCompositeMask(arg0: [*c]const Image, arg1: [*c]ExceptionInfo) [*c]Image; -pub extern fn ReferenceImage(arg0: [*c]Image) [*c]Image; -pub extern fn CloneImageInfo(arg0: [*c]const ImageInfo) [*c]ImageInfo; -pub extern fn AccessDefinition(image_info: [*c]const ImageInfo, magick: [*c]const u8, key: [*c]const u8) [*c]const u8; -pub extern fn GetImageGeometry(arg0: [*c]const Image, arg1: [*c]const u8, arg2: c_uint, arg3: [*c]RectangleInfo) c_int; -pub extern fn IsTaintImage(arg0: [*c]const Image) c_uint; -pub extern fn IsSubimage(arg0: [*c]const u8, arg1: c_uint) c_uint; -pub extern fn AddDefinition(image_info: [*c]ImageInfo, magick: [*c]const u8, key: [*c]const u8, value: [*c]const u8, exception: [*c]ExceptionInfo) c_uint; -pub extern fn AddDefinitions(image_info: [*c]ImageInfo, options: [*c]const u8, exception: [*c]ExceptionInfo) c_uint; -pub extern fn AnimateImages(image_info: [*c]const ImageInfo, image: [*c]Image) c_uint; -pub extern fn ClipImage(image: [*c]Image) c_uint; -pub extern fn ClipPathImage(image: [*c]Image, pathname: [*c]const u8, inside: c_uint) c_uint; -pub extern fn CompositeMaskImage(image: [*c]Image) c_uint; -pub extern fn CompositePathImage(image: [*c]Image, pathname: [*c]const u8, inside: c_uint) c_uint; -pub extern fn DisplayImages(image_info: [*c]const ImageInfo, image: [*c]Image) c_uint; -pub extern fn RemoveDefinitions(image_info: [*c]const ImageInfo, options: [*c]const u8) c_uint; -pub extern fn ResetImagePage(image: [*c]Image, page: [*c]const u8) c_uint; -pub extern fn SetImage(image: [*c]Image, arg1: Quantum) c_uint; -pub extern fn SetImageEx(image: [*c]Image, opacity: Quantum, exception: [*c]ExceptionInfo) c_uint; -pub extern fn SetImageColor(image: [*c]Image, pixel: [*c]const PixelPacket) c_uint; -pub extern fn SetImageColorRegion(image: [*c]Image, x: c_long, y: c_long, width: c_ulong, height: c_ulong, pixel: [*c]const PixelPacket) c_uint; -pub extern fn SetImageClipMask(image: [*c]Image, clip_mask: [*c]const Image) c_uint; -pub extern fn SetImageCompositeMask(image: [*c]Image, composite_mask: [*c]const Image) c_uint; -pub extern fn SetImageDepth(image: [*c]Image, arg1: c_ulong) c_uint; -pub extern fn SetImageInfo(image_info: [*c]ImageInfo, flags: c_uint, exception: [*c]ExceptionInfo) c_uint; -pub extern fn SetImageType(image: [*c]Image, arg1: ImageType) c_uint; -pub extern fn StripImage(image: [*c]Image) c_uint; -pub extern fn SyncImage(image: [*c]Image) c_uint; -pub extern fn AllocateNextImage(arg0: [*c]const ImageInfo, arg1: [*c]Image) void; -pub extern fn DestroyImage(arg0: [*c]Image) void; -pub extern fn DestroyImageInfo(arg0: [*c]ImageInfo) void; -pub extern fn GetImageException(arg0: [*c]Image, arg1: [*c]ExceptionInfo) void; -pub extern fn GetImageInfo(arg0: [*c]ImageInfo) void; -pub extern fn ModifyImage(arg0: [*c]([*c]Image), arg1: [*c]ExceptionInfo) void; -pub extern fn SetImageOpacity(arg0: [*c]Image, arg1: c_uint) void; -pub extern fn ImageGetClipMask(arg0: [*c]const Image) [*c]([*c]Image); -pub extern fn ImageGetCompositeMask(arg0: [*c]const Image) [*c]([*c]Image); -pub const struct__ImageCharacteristics = extern struct { - cmyk: c_uint, - grayscale: c_uint, - monochrome: c_uint, - opaque: c_uint, - palette: c_uint, -}; -pub const ImageCharacteristics = struct__ImageCharacteristics; -pub extern fn GetImageCharacteristics(image: [*c]const Image, characteristics: [*c]ImageCharacteristics, optimize: c_uint, exception: [*c]ExceptionInfo) c_uint; -pub extern fn GetImageDepth(arg0: [*c]const Image, arg1: [*c]ExceptionInfo) c_ulong; -pub extern fn IsGrayImage(image: [*c]const Image, exception: [*c]ExceptionInfo) c_uint; -pub extern fn IsMonochromeImage(image: [*c]const Image, exception: [*c]ExceptionInfo) c_uint; -pub extern fn IsOpaqueImage(image: [*c]const Image, exception: [*c]ExceptionInfo) c_uint; -pub extern fn GetImageType(arg0: [*c]const Image, arg1: [*c]ExceptionInfo) ImageType; -pub extern fn GetImageBoundingBox(arg0: [*c]const Image, exception: [*c]ExceptionInfo) RectangleInfo; -pub const ImageAttribute = struct__ImageAttribute; -pub extern fn GetImageAttribute(image: [*c]const Image, key: [*c]const u8) [*c]const ImageAttribute; -pub extern fn GetImageClippingPathAttribute(image: [*c]const Image) [*c]const ImageAttribute; -pub extern fn GetImageInfoAttribute(image_info: [*c]const ImageInfo, image: [*c]const Image, key: [*c]const u8) [*c]const ImageAttribute; -pub extern fn CloneImageAttributes(clone_image: [*c]Image, original_image: [*c]const Image) c_uint; -pub extern fn SetImageAttribute(image: [*c]Image, key: [*c]const u8, value: [*c]const u8) c_uint; -pub extern fn DestroyImageAttributes(image: [*c]Image) void; -pub extern fn AverageImages(arg0: [*c]const Image, arg1: [*c]ExceptionInfo) [*c]Image; -pub const BlobInfo = struct__BlobInfo; -pub extern fn CloneBlobInfo(blob_info: ?*const BlobInfo) ?*BlobInfo; -pub extern fn ReferenceBlob(blob: ?*BlobInfo) ?*BlobInfo; -pub extern fn DestroyBlobInfo(blob: ?*BlobInfo) void; -pub extern fn DetachBlob(blob: ?*BlobInfo) void; -pub extern fn GetBlobInfo(blob: ?*BlobInfo) void; -pub extern fn AttachBlob(blob_info: ?*BlobInfo, blob: ?*const c_void, length: usize) void; -pub extern fn DestroyBlob(image: [*c]Image) void; -pub extern fn BlobToImage(image_info: [*c]const ImageInfo, blob: ?*const c_void, length: usize, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn PingBlob(image_info: [*c]const ImageInfo, blob: ?*const c_void, length: usize, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn ImageToBlob(image_info: [*c]const ImageInfo, image: [*c]Image, length: [*c]usize, exception: [*c]ExceptionInfo) ?*c_void; -pub const UndefinedBlobMode = 0; -pub const ReadBlobMode = 1; -pub const ReadBinaryBlobMode = 2; -pub const WriteBlobMode = 3; -pub const WriteBinaryBlobMode = 4; -pub const BlobMode = extern enum { - UndefinedBlobMode = 0, - ReadBlobMode = 1, - ReadBinaryBlobMode = 2, - WriteBlobMode = 3, - WriteBinaryBlobMode = 4, -}; -pub extern fn OpenBlob(image_info: [*c]const ImageInfo, image: [*c]Image, mode: BlobMode, exception: [*c]ExceptionInfo) c_uint; -pub extern fn CloseBlob(image: [*c]Image) c_uint; -pub extern fn ReadBlob(image: [*c]Image, length: usize, data: ?*c_void) usize; -pub extern fn ReadBlobZC(image: [*c]Image, length: usize, data: [*c](?*c_void)) usize; -pub extern fn WriteBlob(image: [*c]Image, length: usize, data: ?*const c_void) usize; -pub extern fn SeekBlob(image: [*c]Image, offset: magick_off_t, whence: c_int) magick_off_t; -pub extern fn TellBlob(image: [*c]const Image) magick_off_t; -pub extern fn EOFBlob(image: [*c]const Image) c_int; -pub extern fn GetBlobStatus(image: [*c]const Image) c_int; -pub extern fn GetBlobFirstErrno(image: [*c]const Image) c_int; -pub extern fn GetBlobIsOpen(image: [*c]const Image) c_uint; -pub extern fn GetBlobSize(image: [*c]const Image) magick_off_t; -pub extern fn GetBlobFileHandle(image: [*c]const Image) [*c]FILE; -pub extern fn GetBlobStreamData(image: [*c]const Image) [*c]u8; -pub extern fn ReadBlobByte(image: [*c]Image) c_int; -pub extern fn ReadBlobLSBShort(image: [*c]Image) magick_uint16_t; -pub extern fn ReadBlobLSBSignedShort(image: [*c]Image) magick_int16_t; -pub extern fn ReadBlobLSBShorts(image: [*c]Image, octets: usize, data: [*c]magick_uint16_t) usize; -pub extern fn ReadBlobMSBShort(image: [*c]Image) magick_uint16_t; -pub extern fn ReadBlobMSBSignedShort(image: [*c]Image) magick_int16_t; -pub extern fn ReadBlobMSBShorts(image: [*c]Image, octets: usize, data: [*c]magick_uint16_t) usize; -pub extern fn ReadBlobLSBLong(image: [*c]Image) magick_uint32_t; -pub extern fn ReadBlobLSBSignedLong(image: [*c]Image) magick_int32_t; -pub extern fn ReadBlobLSBLongs(image: [*c]Image, octets: usize, data: [*c]magick_uint32_t) usize; -pub extern fn ReadBlobMSBLong(image: [*c]Image) magick_uint32_t; -pub extern fn ReadBlobMSBSignedLong(image: [*c]Image) magick_int32_t; -pub extern fn ReadBlobMSBLongs(image: [*c]Image, octets: usize, data: [*c]magick_uint32_t) usize; -pub extern fn ReadBlobLSBFloat(image: [*c]Image) f32; -pub extern fn ReadBlobLSBFloats(image: [*c]Image, octets: usize, data: [*c]f32) usize; -pub extern fn ReadBlobMSBFloat(image: [*c]Image) f32; -pub extern fn ReadBlobMSBFloats(image: [*c]Image, octets: usize, data: [*c]f32) usize; -pub extern fn ReadBlobLSBDouble(image: [*c]Image) f64; -pub extern fn ReadBlobLSBDoubles(image: [*c]Image, octets: usize, data: [*c]f64) usize; -pub extern fn ReadBlobMSBDouble(image: [*c]Image) f64; -pub extern fn ReadBlobMSBDoubles(image: [*c]Image, octets: usize, data: [*c]f64) usize; -pub extern fn ReadBlobString(image: [*c]Image, string: [*c]u8) [*c]u8; -pub extern fn WriteBlobByte(image: [*c]Image, value: magick_uint8_t) usize; -pub extern fn WriteBlobFile(image: [*c]Image, filename: [*c]const u8) c_uint; -pub extern fn WriteBlobLSBShort(image: [*c]Image, value: magick_uint16_t) usize; -pub extern fn WriteBlobLSBSignedShort(image: [*c]Image, value: magick_int16_t) usize; -pub extern fn WriteBlobLSBLong(image: [*c]Image, value: magick_uint32_t) usize; -pub extern fn WriteBlobLSBSignedLong(image: [*c]Image, value: magick_int32_t) usize; -pub extern fn WriteBlobMSBLong(image: [*c]Image, value: magick_uint32_t) usize; -pub extern fn WriteBlobMSBSignedLong(image: [*c]Image, value: magick_int32_t) usize; -pub extern fn WriteBlobMSBShort(image: [*c]Image, value: magick_uint16_t) usize; -pub extern fn WriteBlobMSBSignedShort(image: [*c]Image, value: magick_int16_t) usize; -pub extern fn WriteBlobString(image: [*c]Image, string: [*c]const u8) usize; -pub extern fn BlobIsSeekable(image: [*c]const Image) c_uint; -pub extern fn SetBlobClosable(image: [*c]Image, closable: c_uint) void; -pub extern fn SetBlobTemporary(image: [*c]Image, isTemporary: c_uint) void; -pub extern fn GetBlobTemporary(image: [*c]const Image) c_uint; -pub const ReadMode = 0; -pub const WriteMode = 1; -pub const IOMode = 2; -pub const MapMode = extern enum { - ReadMode = 0, - WriteMode = 1, - IOMode = 2, -}; -pub extern fn UnmapBlob(map: ?*c_void, length: usize) c_uint; -pub extern fn MapBlob(file: c_int, mode: MapMode, offset: magick_off_t, length: usize) ?*c_void; -pub extern fn BlobToFile(filename: [*c]const u8, blob: ?*const c_void, length: usize, exception: [*c]ExceptionInfo) c_uint; -pub extern fn FileToBlob(filename: [*c]const u8, length: [*c]usize, exception: [*c]ExceptionInfo) ?*c_void; -pub extern fn BlobReserveSize(image: [*c]Image, size: magick_off_t) c_uint; -pub extern fn ImageToFile(image: [*c]Image, filename: [*c]const u8, exception: [*c]ExceptionInfo) c_uint; -pub extern fn GetConfigureBlob(filename: [*c]const u8, path: [*c]u8, length: [*c]usize, exception: [*c]ExceptionInfo) ?*c_void; -pub extern fn MSBOrderLong(buffer: [*c]u8, length: usize) void; -pub extern fn MSBOrderShort(p: [*c]u8, length: usize) void; -pub extern fn DisassociateBlob(arg0: [*c]Image) void; -pub extern fn CdlImage(image: [*c]Image, cdl: [*c]const u8) c_uint; -pub extern fn ExportImageChannel(image: [*c]const Image, channel: ChannelType, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn GetImageChannelDepth(image: [*c]const Image, channel: ChannelType, exception: [*c]ExceptionInfo) c_uint; -pub extern fn ChannelImage(image: [*c]Image, channel: ChannelType) c_uint; -pub extern fn ImportImageChannel(src_image: [*c]const Image, dst_image: [*c]Image, channel: ChannelType) c_uint; -pub extern fn ImportImageChannelsMasked(source_image: [*c]const Image, update_image: [*c]Image, channels: ChannelType) c_uint; -pub extern fn SetImageChannelDepth(image: [*c]Image, channel: ChannelType, depth: c_uint) c_uint; -pub const struct__HistogramColorPacket = extern struct { - pixel: PixelPacket, - count: c_ulong, -}; -pub const HistogramColorPacket = struct__HistogramColorPacket; -pub extern fn GetColorHistogram(image: [*c]const Image, colors: [*c]c_ulong, exception: [*c]ExceptionInfo) [*c]HistogramColorPacket; -pub extern fn GetNumberColors(image: [*c]const Image, file: [*c]FILE, exception: [*c]ExceptionInfo) c_ulong; -pub extern fn GetColorTuple(color: [*c]const PixelPacket, depth: c_uint, matte: c_uint, hex: c_uint, tuple: [*c]u8) void; -pub extern fn IsPaletteImage(image: [*c]const Image, exception: [*c]ExceptionInfo) c_uint; -pub const UndefinedCompliance = 0; -pub const NoCompliance = 0; -pub const SVGCompliance = 1; -pub const X11Compliance = 2; -pub const XPMCompliance = 4; -pub const AllCompliance = 65535; -pub const ComplianceType = extern enum { - UndefinedCompliance = 0, - NoCompliance = 0, - SVGCompliance = 1, - X11Compliance = 2, - XPMCompliance = 4, - AllCompliance = 65535, -}; -pub extern fn GetColorList(pattern: [*c]const u8, number_colors: [*c]c_ulong) [*c]([*c]u8); -pub extern fn QueryColorDatabase(name: [*c]const u8, color: [*c]PixelPacket, exception: [*c]ExceptionInfo) c_uint; -pub extern fn QueryColorname(image: [*c]const Image, color: [*c]const PixelPacket, compliance: ComplianceType, name: [*c]u8, exception: [*c]ExceptionInfo) c_uint; -pub extern fn AllocateImageColormap(arg0: [*c]Image, colors: c_ulong) c_uint; -pub extern fn CycleColormapImage(image: [*c]Image, amount: c_int) c_uint; -pub extern fn ReallocateImageColormap(arg0: [*c]Image, colors: c_uint) c_uint; -pub extern fn ReplaceImageColormap(image: [*c]Image, colormap: [*c]const PixelPacket, colors: c_uint) c_uint; -pub extern fn SortColormapByIntensity(image: [*c]Image) c_uint; -pub extern fn AnimateImageCommand(image_info: [*c]ImageInfo, argc: c_int, argv: [*c]([*c]u8), metadata: [*c]([*c]u8), exception: [*c]ExceptionInfo) c_uint; -pub extern fn BenchmarkImageCommand(image_info: [*c]ImageInfo, argc: c_int, argv: [*c]([*c]u8), metadata: [*c]([*c]u8), exception: [*c]ExceptionInfo) c_uint; -pub extern fn CompareImageCommand(image_info: [*c]ImageInfo, argc: c_int, argv: [*c]([*c]u8), metadata: [*c]([*c]u8), exception: [*c]ExceptionInfo) c_uint; -pub extern fn CompositeImageCommand(image_info: [*c]ImageInfo, argc: c_int, argv: [*c]([*c]u8), metadata: [*c]([*c]u8), exception: [*c]ExceptionInfo) c_uint; -pub extern fn ConjureImageCommand(image_info: [*c]ImageInfo, argc: c_int, argv: [*c]([*c]u8), metadata: [*c]([*c]u8), exception: [*c]ExceptionInfo) c_uint; -pub extern fn ConvertImageCommand(image_info: [*c]ImageInfo, argc: c_int, argv: [*c]([*c]u8), metadata: [*c]([*c]u8), exception: [*c]ExceptionInfo) c_uint; -pub extern fn DisplayImageCommand(image_info: [*c]ImageInfo, argc: c_int, argv: [*c]([*c]u8), metadata: [*c]([*c]u8), exception: [*c]ExceptionInfo) c_uint; -pub extern fn IdentifyImageCommand(image_info: [*c]ImageInfo, argc: c_int, argv: [*c]([*c]u8), metadata: [*c]([*c]u8), exception: [*c]ExceptionInfo) c_uint; -pub extern fn ImportImageCommand(image_info: [*c]ImageInfo, argc: c_int, argv: [*c]([*c]u8), metadata: [*c]([*c]u8), exception: [*c]ExceptionInfo) c_uint; -pub extern fn MagickCommand(image_info: [*c]ImageInfo, argc: c_int, argv: [*c]([*c]u8), metadata: [*c]([*c]u8), exception: [*c]ExceptionInfo) c_uint; -pub extern fn MogrifyImage(arg0: [*c]const ImageInfo, arg1: c_int, arg2: [*c]([*c]u8), arg3: [*c]([*c]Image)) c_uint; -pub extern fn MogrifyImageCommand(image_info: [*c]ImageInfo, argc: c_int, argv: [*c]([*c]u8), metadata: [*c]([*c]u8), exception: [*c]ExceptionInfo) c_uint; -pub extern fn MogrifyImages(arg0: [*c]const ImageInfo, arg1: c_int, arg2: [*c]([*c]u8), arg3: [*c]([*c]Image)) c_uint; -pub extern fn MontageImageCommand(image_info: [*c]ImageInfo, argc: c_int, argv: [*c]([*c]u8), metadata: [*c]([*c]u8), exception: [*c]ExceptionInfo) c_uint; -pub extern fn TimeImageCommand(image_info: [*c]ImageInfo, argc: c_int, argv: [*c]([*c]u8), metadata: [*c]([*c]u8), exception: [*c]ExceptionInfo) c_uint; -pub extern fn GMCommand(argc: c_int, argv: [*c]([*c]u8)) c_int; -pub const UndefinedHighlightStyle = 0; -pub const AssignHighlightStyle = 1; -pub const ThresholdHighlightStyle = 2; -pub const TintHighlightStyle = 3; -pub const XorHighlightStyle = 4; -pub const HighlightStyle = extern enum { - UndefinedHighlightStyle = 0, - AssignHighlightStyle = 1, - ThresholdHighlightStyle = 2, - TintHighlightStyle = 3, - XorHighlightStyle = 4, -}; -pub const struct__DifferenceImageOptions = extern struct { - channel: ChannelType, - highlight_style: HighlightStyle, - highlight_color: PixelPacket, -}; -pub const DifferenceImageOptions = struct__DifferenceImageOptions; -pub extern fn InitializeDifferenceImageOptions(options: [*c]DifferenceImageOptions, exception: [*c]ExceptionInfo) void; -pub extern fn DifferenceImage(reference_image: [*c]const Image, compare_image: [*c]const Image, difference_options: [*c]const DifferenceImageOptions, exception: [*c]ExceptionInfo) [*c]Image; -pub const UndefinedMetric = 0; -pub const MeanAbsoluteErrorMetric = 1; -pub const MeanSquaredErrorMetric = 2; -pub const PeakAbsoluteErrorMetric = 3; -pub const PeakSignalToNoiseRatioMetric = 4; -pub const RootMeanSquaredErrorMetric = 5; -pub const MetricType = extern enum { - UndefinedMetric = 0, - MeanAbsoluteErrorMetric = 1, - MeanSquaredErrorMetric = 2, - PeakAbsoluteErrorMetric = 3, - PeakSignalToNoiseRatioMetric = 4, - RootMeanSquaredErrorMetric = 5, -}; -pub const struct__DifferenceStatistics = extern struct { - red: f64, - green: f64, - blue: f64, - opacity: f64, - combined: f64, -}; -pub const DifferenceStatistics = struct__DifferenceStatistics; -pub extern fn InitializeDifferenceStatistics(difference_statistics: [*c]DifferenceStatistics, exception: [*c]ExceptionInfo) void; -pub extern fn GetImageChannelDifference(reference_image: [*c]const Image, compare_image: [*c]const Image, metric: MetricType, statistics: [*c]DifferenceStatistics, exception: [*c]ExceptionInfo) c_uint; -pub extern fn GetImageChannelDistortion(reference_image: [*c]const Image, compare_image: [*c]const Image, channel: ChannelType, metric: MetricType, distortion: [*c]f64, exception: [*c]ExceptionInfo) c_uint; -pub extern fn GetImageDistortion(reference_image: [*c]const Image, compare_image: [*c]const Image, metric: MetricType, distortion: [*c]f64, exception: [*c]ExceptionInfo) c_uint; -pub extern fn IsImagesEqual(arg0: [*c]Image, arg1: [*c]const Image) c_uint; -pub const struct__CompositeOptions_t = extern struct { - percent_brightness: f64, - amount: f64, - threshold: f64, -}; -pub const CompositeOptions_t = struct__CompositeOptions_t; -pub extern fn CompositeImage(canvas_image: [*c]Image, compose: CompositeOperator, update_image: [*c]const Image, x_offset: c_long, y_offset: c_long) c_uint; -pub extern fn CompositeImageRegion(compose: CompositeOperator, options: [*c]const CompositeOptions_t, columns: c_ulong, rows: c_ulong, update_image: [*c]const Image, update_x: c_long, update_y: c_long, canvas_image: [*c]Image, canvas_x: c_long, canvas_y: c_long, exception: [*c]ExceptionInfo) c_uint; -pub extern fn MagickCompositeImageUnderColor(image: [*c]Image, undercolor: [*c]const PixelPacket, exception: [*c]ExceptionInfo) c_uint; -pub const Ascii85Info = struct__Ascii85Info; -pub const WriteByteHook = ?extern fn ([*c]Image, magick_uint8_t, ?*c_void) c_uint; -pub extern fn Ascii85WriteByteHook(image: [*c]Image, code: magick_uint8_t, info: ?*c_void) c_uint; -pub extern fn BlobWriteByteHook(image: [*c]Image, code: magick_uint8_t, info: ?*c_void) c_uint; -pub extern fn HuffmanDecodeImage(image: [*c]Image) c_uint; -pub extern fn HuffmanEncodeImage(image_info: [*c]const ImageInfo, image: [*c]Image) c_uint; -pub extern fn HuffmanEncode2Image(image_info: [*c]const ImageInfo, image: [*c]Image, write_byte: WriteByteHook, info: ?*c_void) c_uint; -pub extern fn LZWEncodeImage(image: [*c]Image, length: usize, pixels: [*c]magick_uint8_t) c_uint; -pub extern fn LZWEncode2Image(image: [*c]Image, length: usize, pixels: [*c]magick_uint8_t, write_byte: WriteByteHook, info: ?*c_void) c_uint; -pub extern fn PackbitsEncodeImage(image: [*c]Image, length: usize, pixels: [*c]magick_uint8_t) c_uint; -pub extern fn PackbitsEncode2Image(image: [*c]Image, length: usize, pixels: [*c]magick_uint8_t, write_byte: WriteByteHook, info: ?*c_void) c_uint; -pub extern fn ImageToHuffman2DBlob(image: [*c]const Image, image_info: [*c]const ImageInfo, length: [*c]usize, exception: [*c]ExceptionInfo) [*c]u8; -pub extern fn ImageToJPEGBlob(image: [*c]const Image, image_info: [*c]const ImageInfo, length: [*c]usize, exception: [*c]ExceptionInfo) [*c]u8; -pub extern fn Ascii85Encode(image: [*c]Image, code: magick_uint8_t) void; -pub extern fn Ascii85Flush(image: [*c]Image) void; -pub extern fn Ascii85Initialize(image: [*c]Image) void; -pub const UndefinedConfirmAccessMode = 0; -pub const FileExecuteConfirmAccessMode = 1; -pub const FileReadConfirmAccessMode = 2; -pub const FileWriteConfirmAccessMode = 3; -pub const URLGetFTPConfirmAccessMode = 4; -pub const URLGetFileConfirmAccessMode = 5; -pub const URLGetHTTPConfirmAccessMode = 6; -pub const ConfirmAccessMode = extern enum { - UndefinedConfirmAccessMode = 0, - FileExecuteConfirmAccessMode = 1, - FileReadConfirmAccessMode = 2, - FileWriteConfirmAccessMode = 3, - URLGetFTPConfirmAccessMode = 4, - URLGetFileConfirmAccessMode = 5, - URLGetHTTPConfirmAccessMode = 6, -}; -pub const ConfirmAccessHandler = ?extern fn (ConfirmAccessMode, [*c]const u8, [*c]ExceptionInfo) c_uint; -pub extern fn MagickConfirmAccess(mode: ConfirmAccessMode, path: [*c]const u8, exception: [*c]ExceptionInfo) c_uint; -pub extern fn MagickSetConfirmAccessHandler(handler: ConfirmAccessHandler) ConfirmAccessHandler; -pub const UndefinedQuantum = 0; -pub const IndexQuantum = 1; -pub const GrayQuantum = 2; -pub const IndexAlphaQuantum = 3; -pub const GrayAlphaQuantum = 4; -pub const RedQuantum = 5; -pub const CyanQuantum = 6; -pub const GreenQuantum = 7; -pub const YellowQuantum = 8; -pub const BlueQuantum = 9; -pub const MagentaQuantum = 10; -pub const AlphaQuantum = 11; -pub const BlackQuantum = 12; -pub const RGBQuantum = 13; -pub const RGBAQuantum = 14; -pub const CMYKQuantum = 15; -pub const CMYKAQuantum = 16; -pub const CIEYQuantum = 17; -pub const CIEXYZQuantum = 18; -pub const QuantumType = extern enum { - UndefinedQuantum = 0, - IndexQuantum = 1, - GrayQuantum = 2, - IndexAlphaQuantum = 3, - GrayAlphaQuantum = 4, - RedQuantum = 5, - CyanQuantum = 6, - GreenQuantum = 7, - YellowQuantum = 8, - BlueQuantum = 9, - MagentaQuantum = 10, - AlphaQuantum = 11, - BlackQuantum = 12, - RGBQuantum = 13, - RGBAQuantum = 14, - CMYKQuantum = 15, - CMYKAQuantum = 16, - CIEYQuantum = 17, - CIEXYZQuantum = 18, -}; -pub const UndefinedQuantumSampleType = 0; -pub const UnsignedQuantumSampleType = 1; -pub const FloatQuantumSampleType = 2; -pub const QuantumSampleType = extern enum { - UndefinedQuantumSampleType = 0, - UnsignedQuantumSampleType = 1, - FloatQuantumSampleType = 2, -}; -pub const CharPixel = 0; -pub const ShortPixel = 1; -pub const IntegerPixel = 2; -pub const LongPixel = 3; -pub const FloatPixel = 4; -pub const DoublePixel = 5; -pub const StorageType = extern enum { - CharPixel = 0, - ShortPixel = 1, - IntegerPixel = 2, - LongPixel = 3, - FloatPixel = 4, - DoublePixel = 5, -}; -pub const struct__ExportPixelAreaOptions = extern struct { - sample_type: QuantumSampleType, - double_minvalue: f64, - double_maxvalue: f64, - grayscale_miniswhite: c_uint, - pad_bytes: c_ulong, - pad_value: u8, - endian: EndianType, - signature: c_ulong, -}; -pub const ExportPixelAreaOptions = struct__ExportPixelAreaOptions; -pub const struct__ExportPixelAreaInfo = extern struct { - bytes_exported: usize, -}; -pub const ExportPixelAreaInfo = struct__ExportPixelAreaInfo; -pub const struct__ImportPixelAreaOptions = extern struct { - sample_type: QuantumSampleType, - double_minvalue: f64, - double_maxvalue: f64, - grayscale_miniswhite: c_uint, - endian: EndianType, - signature: c_ulong, -}; -pub const ImportPixelAreaOptions = struct__ImportPixelAreaOptions; -pub const struct__ImportPixelAreaInfo = extern struct { - bytes_imported: usize, -}; -pub const ImportPixelAreaInfo = struct__ImportPixelAreaInfo; -pub extern fn StorageTypeToString(storage_type: StorageType) [*c]const u8; -pub extern fn QuantumSampleTypeToString(sample_type: QuantumSampleType) [*c]const u8; -pub extern fn QuantumTypeToString(quantum_type: QuantumType) [*c]const u8; -pub extern fn ConstituteImage(width: c_ulong, height: c_ulong, map: [*c]const u8, type_0: StorageType, pixels: ?*const c_void, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn ConstituteTextureImage(columns: c_ulong, rows: c_ulong, texture: [*c]const Image, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn PingImage(image_info: [*c]const ImageInfo, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn ReadImage(image_info: [*c]const ImageInfo, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn ReadInlineImage(image_info: [*c]const ImageInfo, content: [*c]const u8, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn DispatchImage(image: [*c]const Image, x_offset: c_long, y_offset: c_long, columns: c_ulong, rows: c_ulong, map: [*c]const u8, type_0: StorageType, pixels: ?*c_void, exception: [*c]ExceptionInfo) c_uint; -pub extern fn ExportImagePixelArea(image: [*c]const Image, quantum_type: QuantumType, quantum_size: c_uint, destination: [*c]u8, options: [*c]const ExportPixelAreaOptions, export_info: [*c]ExportPixelAreaInfo) c_uint; -pub extern fn ExportViewPixelArea(view: [*c]const ViewInfo, quantum_type: QuantumType, quantum_size: c_uint, destination: [*c]u8, options: [*c]const ExportPixelAreaOptions, export_info: [*c]ExportPixelAreaInfo) c_uint; -pub extern fn ImportImagePixelArea(image: [*c]Image, quantum_type: QuantumType, quantum_size: c_uint, source: [*c]const u8, options: [*c]const ImportPixelAreaOptions, import_info: [*c]ImportPixelAreaInfo) c_uint; -pub extern fn ImportViewPixelArea(view: [*c]ViewInfo, quantum_type: QuantumType, quantum_size: c_uint, source: [*c]const u8, options: [*c]const ImportPixelAreaOptions, import_info: [*c]ImportPixelAreaInfo) c_uint; -pub extern fn WriteImage(image_info: [*c]const ImageInfo, image: [*c]Image) c_uint; -pub extern fn WriteImages(image_info: [*c]const ImageInfo, image: [*c]Image, filename: [*c]const u8, exception: [*c]ExceptionInfo) c_uint; -pub extern fn WriteImagesFile(image_info: [*c]const ImageInfo, image: [*c]Image, file: [*c]FILE, exception: [*c]ExceptionInfo) c_uint; -pub extern fn ExportPixelAreaOptionsInit(options: [*c]ExportPixelAreaOptions) void; -pub extern fn ImportPixelAreaOptionsInit(options: [*c]ImportPixelAreaOptions) void; -pub extern fn MagickFindRawImageMinMax(image: [*c]Image, endian: EndianType, width: c_ulong, height: c_ulong, type_0: StorageType, scanline_octets: c_uint, scanline_buffer: ?*c_void, min: [*c]f64, max: [*c]f64) c_uint; -pub extern fn MagickGetQuantumSamplesPerPixel(quantum_type: QuantumType) c_uint; -pub extern fn BorderImage(arg0: [*c]const Image, arg1: [*c]const RectangleInfo, arg2: [*c]ExceptionInfo) [*c]Image; -pub extern fn FrameImage(arg0: [*c]const Image, arg1: [*c]const FrameInfo, arg2: [*c]ExceptionInfo) [*c]Image; -pub extern fn RaiseImage(arg0: [*c]Image, arg1: [*c]const RectangleInfo, arg2: c_int) c_uint; -pub const struct__DelegateInfo = extern struct { - path: [*c]u8, - decode: [*c]u8, - encode: [*c]u8, - commands: [*c]u8, - mode: c_int, - stealth: c_uint, - signature: c_ulong, - previous: [*c]struct__DelegateInfo, - next: [*c]struct__DelegateInfo, -}; -pub const DelegateInfo = struct__DelegateInfo; -pub extern fn GetDelegateCommand(image_info: [*c]const ImageInfo, image: [*c]Image, decode: [*c]const u8, encode: [*c]const u8, exception: [*c]ExceptionInfo) [*c]u8; -pub extern fn GetDelegateInfo(decode: [*c]const u8, encode: [*c]const u8, exception: [*c]ExceptionInfo) [*c]const DelegateInfo; -pub extern fn GetPostscriptDelegateInfo(image_info: [*c]const ImageInfo, antialias: [*c]c_uint, exception: [*c]ExceptionInfo) [*c]const DelegateInfo; -pub extern fn SetDelegateInfo(arg0: [*c]DelegateInfo) [*c]DelegateInfo; -pub extern fn InvokePostscriptDelegate(verbose: c_uint, command: [*c]const u8, exception: [*c]ExceptionInfo) c_uint; -pub extern fn InvokeDelegate(image_info: [*c]ImageInfo, image: [*c]Image, decode: [*c]const u8, encode: [*c]const u8, exception: [*c]ExceptionInfo) c_uint; -pub extern fn ListDelegateInfo(file: [*c]FILE, exception: [*c]ExceptionInfo) c_uint; -pub extern fn PopImagePixels(arg0: [*c]const Image, arg1: QuantumType, arg2: [*c]u8) c_uint; -pub extern fn PushImagePixels(arg0: [*c]Image, arg1: QuantumType, arg2: [*c]const u8) c_uint; -pub extern fn AcquireMemory(arg0: usize) ?*c_void; -pub extern fn CloneMemory(arg0: ?*c_void, arg1: ?*const c_void, arg2: usize) ?*c_void; -pub extern fn LiberateMemory(arg0: [*c](?*c_void)) void; -pub extern fn ReacquireMemory(arg0: [*c](?*c_void), arg1: usize) void; -pub extern fn AcquireCacheView(view: [*c]ViewInfo, x: c_long, y: c_long, columns: c_ulong, rows: c_ulong, exception: [*c]ExceptionInfo) [*c]const PixelPacket; -pub extern fn GetCacheView(view: [*c]ViewInfo, x: c_long, y: c_long, columns: c_ulong, rows: c_ulong) [*c]PixelPacket; -pub extern fn SetCacheView(view: [*c]ViewInfo, x: c_long, y: c_long, columns: c_ulong, rows: c_ulong) [*c]PixelPacket; -pub extern fn SyncCacheView(view: [*c]ViewInfo) c_uint; -pub extern fn DescribeImage(image: [*c]Image, file: [*c]FILE, verbose: c_uint) c_uint; -pub const NormalStretch = 0; -pub const UltraCondensedStretch = 1; -pub const ExtraCondensedStretch = 2; -pub const CondensedStretch = 3; -pub const SemiCondensedStretch = 4; -pub const SemiExpandedStretch = 5; -pub const ExpandedStretch = 6; -pub const ExtraExpandedStretch = 7; -pub const UltraExpandedStretch = 8; -pub const AnyStretch = 9; -pub const StretchType = extern enum { - NormalStretch = 0, - UltraCondensedStretch = 1, - ExtraCondensedStretch = 2, - CondensedStretch = 3, - SemiCondensedStretch = 4, - SemiExpandedStretch = 5, - ExpandedStretch = 6, - ExtraExpandedStretch = 7, - UltraExpandedStretch = 8, - AnyStretch = 9, -}; -pub const NormalStyle = 0; -pub const ItalicStyle = 1; -pub const ObliqueStyle = 2; -pub const AnyStyle = 3; -pub const StyleType = extern enum { - NormalStyle = 0, - ItalicStyle = 1, - ObliqueStyle = 2, - AnyStyle = 3, -}; -pub const struct__TypeInfo = extern struct { - path: [*c]u8, - name: [*c]u8, - description: [*c]u8, - family: [*c]u8, - style: StyleType, - stretch: StretchType, - weight: c_ulong, - encoding: [*c]u8, - foundry: [*c]u8, - format: [*c]u8, - metrics: [*c]u8, - glyphs: [*c]u8, - stealth: c_uint, - signature: c_ulong, - previous: [*c]struct__TypeInfo, - next: [*c]struct__TypeInfo, -}; -pub const TypeInfo = struct__TypeInfo; -pub extern fn GetTypeList(arg0: [*c]const u8, arg1: [*c]c_ulong) [*c]([*c]u8); -pub extern fn ListTypeInfo(arg0: [*c]FILE, arg1: [*c]ExceptionInfo) c_uint; -pub extern fn GetTypeInfo(arg0: [*c]const u8, arg1: [*c]ExceptionInfo) [*c]const TypeInfo; -pub extern fn GetTypeInfoByFamily(arg0: [*c]const u8, arg1: StyleType, arg2: StretchType, arg3: c_ulong, arg4: [*c]ExceptionInfo) [*c]const TypeInfo; -pub const UndefinedAlign = 0; -pub const LeftAlign = 1; -pub const CenterAlign = 2; -pub const RightAlign = 3; -pub const AlignType = extern enum { - UndefinedAlign = 0, - LeftAlign = 1, - CenterAlign = 2, - RightAlign = 3, -}; -pub const UserSpace = 0; -pub const UserSpaceOnUse = 1; -pub const ObjectBoundingBox = 2; -pub const ClipPathUnits = extern enum { - UserSpace = 0, - UserSpaceOnUse = 1, - ObjectBoundingBox = 2, -}; -pub const NoDecoration = 0; -pub const UnderlineDecoration = 1; -pub const OverlineDecoration = 2; -pub const LineThroughDecoration = 3; -pub const DecorationType = extern enum { - NoDecoration = 0, - UnderlineDecoration = 1, - OverlineDecoration = 2, - LineThroughDecoration = 3, -}; -pub const UndefinedRule = 0; -pub const EvenOddRule = 1; -pub const NonZeroRule = 2; -pub const FillRule = extern enum { - UndefinedRule = 0, - EvenOddRule = 1, - NonZeroRule = 2, -}; -pub const UndefinedGradient = 0; -pub const LinearGradient = 1; -pub const RadialGradient = 2; -pub const GradientType = extern enum { - UndefinedGradient = 0, - LinearGradient = 1, - RadialGradient = 2, -}; -pub const UndefinedCap = 0; -pub const ButtCap = 1; -pub const RoundCap = 2; -pub const SquareCap = 3; -pub const LineCap = extern enum { - UndefinedCap = 0, - ButtCap = 1, - RoundCap = 2, - SquareCap = 3, -}; -pub const UndefinedJoin = 0; -pub const MiterJoin = 1; -pub const RoundJoin = 2; -pub const BevelJoin = 3; -pub const LineJoin = extern enum { - UndefinedJoin = 0, - MiterJoin = 1, - RoundJoin = 2, - BevelJoin = 3, -}; -pub const PointMethod = 0; -pub const ReplaceMethod = 1; -pub const FloodfillMethod = 2; -pub const FillToBorderMethod = 3; -pub const ResetMethod = 4; -pub const PaintMethod = extern enum { - PointMethod = 0, - ReplaceMethod = 1, - FloodfillMethod = 2, - FillToBorderMethod = 3, - ResetMethod = 4, -}; -pub const UndefinedPrimitive = 0; -pub const PointPrimitive = 1; -pub const LinePrimitive = 2; -pub const RectanglePrimitive = 3; -pub const RoundRectanglePrimitive = 4; -pub const ArcPrimitive = 5; -pub const EllipsePrimitive = 6; -pub const CirclePrimitive = 7; -pub const PolylinePrimitive = 8; -pub const PolygonPrimitive = 9; -pub const BezierPrimitive = 10; -pub const ColorPrimitive = 11; -pub const MattePrimitive = 12; -pub const TextPrimitive = 13; -pub const ImagePrimitive = 14; -pub const PathPrimitive = 15; -pub const PrimitiveType = extern enum { - UndefinedPrimitive = 0, - PointPrimitive = 1, - LinePrimitive = 2, - RectanglePrimitive = 3, - RoundRectanglePrimitive = 4, - ArcPrimitive = 5, - EllipsePrimitive = 6, - CirclePrimitive = 7, - PolylinePrimitive = 8, - PolygonPrimitive = 9, - BezierPrimitive = 10, - ColorPrimitive = 11, - MattePrimitive = 12, - TextPrimitive = 13, - ImagePrimitive = 14, - PathPrimitive = 15, -}; -pub const UndefinedReference = 0; -pub const GradientReference = 1; -pub const ReferenceType = extern enum { - UndefinedReference = 0, - GradientReference = 1, -}; -pub const UndefinedSpread = 0; -pub const PadSpread = 1; -pub const ReflectSpead = 2; -pub const RepeatSpread = 3; -pub const SpreadMethod = extern enum { - UndefinedSpread = 0, - PadSpread = 1, - ReflectSpead = 2, - RepeatSpread = 3, -}; -pub const struct__GradientInfo = extern struct { - type: GradientType, - color: PixelPacket, - stop: SegmentInfo, - length: c_ulong, - spread: SpreadMethod, - signature: c_ulong, - previous: [*c]struct__GradientInfo, - next: [*c]struct__GradientInfo, -}; -pub const GradientInfo = struct__GradientInfo; -pub const struct__ElementReference = extern struct { - id: [*c]u8, - type: ReferenceType, - gradient: GradientInfo, - signature: c_ulong, - previous: [*c]struct__ElementReference, - next: [*c]struct__ElementReference, -}; -pub const ElementReference = struct__ElementReference; -pub const struct__DrawInfoExtra = @OpaqueType(); -pub const struct__DrawInfo = extern struct { - primitive: [*c]u8, - geometry: [*c]u8, - affine: AffineMatrix, - gravity: GravityType, - fill: PixelPacket, - stroke: PixelPacket, - stroke_width: f64, - gradient: GradientInfo, - fill_pattern: [*c]Image, - tile: [*c]Image, - stroke_pattern: [*c]Image, - stroke_antialias: c_uint, - text_antialias: c_uint, - fill_rule: FillRule, - linecap: LineCap, - linejoin: LineJoin, - miterlimit: c_ulong, - dash_offset: f64, - decorate: DecorationType, - compose: CompositeOperator, - text: [*c]u8, - font: [*c]u8, - family: [*c]u8, - style: StyleType, - stretch: StretchType, - weight: c_ulong, - encoding: [*c]u8, - pointsize: f64, - density: [*c]u8, - @"align": AlignType, - undercolor: PixelPacket, - border_color: PixelPacket, - server_name: [*c]u8, - dash_pattern: [*c]f64, - extra: ?*struct__DrawInfoExtra, - bounds: SegmentInfo, - clip_units: ClipPathUnits, - opacity: Quantum, - render: c_uint, - flags: c_uint, - element_reference: ElementReference, - signature: c_ulong, -}; -pub const DrawInfo = struct__DrawInfo; -pub const struct__PointInfo = extern struct { - x: f64, - y: f64, -}; -pub const PointInfo = struct__PointInfo; -pub const struct__TypeMetric = extern struct { - pixels_per_em: PointInfo, - ascent: f64, - descent: f64, - width: f64, - height: f64, - max_advance: f64, - bounds: SegmentInfo, - underline_position: f64, - underline_thickness: f64, -}; -pub const TypeMetric = struct__TypeMetric; -pub extern fn CloneDrawInfo(arg0: [*c]const ImageInfo, arg1: [*c]const DrawInfo) [*c]DrawInfo; -pub extern fn AnnotateImage(arg0: [*c]Image, arg1: [*c]const DrawInfo) c_uint; -pub extern fn DrawAffineImage(arg0: [*c]Image, arg1: [*c]const Image, arg2: [*c]const AffineMatrix) c_uint; -pub extern fn DrawClipPath(arg0: [*c]Image, arg1: [*c]const DrawInfo, arg2: [*c]const u8) c_uint; -pub extern fn DrawImage(arg0: [*c]Image, arg1: [*c]const DrawInfo) c_uint; -pub extern fn DrawPatternPath(arg0: [*c]Image, arg1: [*c]const DrawInfo, arg2: [*c]const u8, arg3: [*c]([*c]Image)) c_uint; -pub extern fn GetTypeMetrics(arg0: [*c]Image, arg1: [*c]const DrawInfo, arg2: [*c]TypeMetric) c_uint; -pub extern fn DestroyDrawInfo(arg0: [*c]DrawInfo) void; -pub extern fn GetDrawInfo(arg0: [*c]const ImageInfo, arg1: [*c]DrawInfo) void; -pub extern fn DrawInfoGetClipPath(arg0: [*c]const DrawInfo) [*c]([*c]u8); -pub extern fn DrawInfoGetCompositePath(arg0: [*c]const DrawInfo) [*c]([*c]u8); -pub const struct__DrawContext = @OpaqueType(); -pub const DrawContext = ?*struct__DrawContext; -pub extern fn DrawGetClipUnits(context: DrawContext) ClipPathUnits; -pub extern fn DrawPeekGraphicContext(context: DrawContext) [*c]DrawInfo; -pub extern fn DrawGetTextDecoration(context: DrawContext) DecorationType; -pub extern fn DrawAllocateContext(draw_info: [*c]const DrawInfo, image: [*c]Image) DrawContext; -pub extern fn DrawGetClipRule(context: DrawContext) FillRule; -pub extern fn DrawGetFillRule(context: DrawContext) FillRule; -pub extern fn DrawGetGravity(context: DrawContext) GravityType; -pub extern fn DrawGetStrokeLineCap(context: DrawContext) LineCap; -pub extern fn DrawGetStrokeLineJoin(context: DrawContext) LineJoin; -pub extern fn DrawGetFillColor(context: DrawContext) PixelPacket; -pub extern fn DrawGetStrokeColor(context: DrawContext) PixelPacket; -pub extern fn DrawGetTextUnderColor(context: DrawContext) PixelPacket; -pub extern fn DrawGetFontStretch(context: DrawContext) StretchType; -pub extern fn DrawGetFontStyle(context: DrawContext) StyleType; -pub extern fn DrawGetClipPath(context: DrawContext) [*c]u8; -pub extern fn DrawGetFont(context: DrawContext) [*c]u8; -pub extern fn DrawGetFontFamily(context: DrawContext) [*c]u8; -pub extern fn DrawGetTextEncoding(context: DrawContext) [*c]u8; -pub extern fn DrawRender(context: DrawContext) c_int; -pub extern fn DrawGetStrokeAntialias(context: DrawContext) c_uint; -pub extern fn DrawGetTextAntialias(context: DrawContext) c_uint; -pub extern fn DrawGetFontWeight(context: DrawContext) c_ulong; -pub extern fn DrawGetStrokeMiterLimit(context: DrawContext) c_ulong; -pub extern fn DrawGetFillOpacity(context: DrawContext) f64; -pub extern fn DrawGetFontSize(context: DrawContext) f64; -pub extern fn DrawGetStrokeDashArray(context: DrawContext, num_elems: [*c]c_ulong) [*c]f64; -pub extern fn DrawGetStrokeDashOffset(context: DrawContext) f64; -pub extern fn DrawGetStrokeOpacity(context: DrawContext) f64; -pub extern fn DrawGetStrokeWidth(context: DrawContext) f64; -pub extern fn DrawAffine(context: DrawContext, affine: [*c]const AffineMatrix) void; -pub extern fn DrawAnnotation(context: DrawContext, x: f64, y: f64, text: [*c]const u8) void; -pub extern fn DrawArc(context: DrawContext, sx: f64, sy: f64, ex: f64, ey: f64, sd: f64, ed: f64) void; -pub extern fn DrawBezier(context: DrawContext, num_coords: c_ulong, coordinates: [*c]const PointInfo) void; -pub extern fn DrawCircle(context: DrawContext, ox: f64, oy: f64, px: f64, py: f64) void; -pub extern fn DrawColor(context: DrawContext, x: f64, y: f64, paintMethod: PaintMethod) void; -pub extern fn DrawComment(context: DrawContext, comment: [*c]const u8) void; -pub extern fn DrawDestroyContext(context: DrawContext) void; -pub extern fn DrawEllipse(context: DrawContext, ox: f64, oy: f64, rx: f64, ry: f64, start: f64, end: f64) void; -pub extern fn DrawComposite(context: DrawContext, composite_operator: CompositeOperator, x: f64, y: f64, width: f64, height: f64, image: [*c]const Image) void; -pub extern fn DrawLine(context: DrawContext, sx: f64, sy: f64, ex: f64, ey: f64) void; -pub extern fn DrawMatte(context: DrawContext, x: f64, y: f64, paint_method: PaintMethod) void; -pub extern fn DrawPathClose(context: DrawContext) void; -pub extern fn DrawPathCurveToAbsolute(context: DrawContext, x1: f64, y1: f64, x2: f64, y2: f64, x: f64, y: f64) void; -pub extern fn DrawPathCurveToRelative(context: DrawContext, x1: f64, y1: f64, x2: f64, y2: f64, x: f64, y: f64) void; -pub extern fn DrawPathCurveToQuadraticBezierAbsolute(context: DrawContext, x1: f64, y1: f64, x: f64, y: f64) void; -pub extern fn DrawPathCurveToQuadraticBezierRelative(context: DrawContext, x1: f64, y1: f64, x: f64, y: f64) void; -pub extern fn DrawPathCurveToQuadraticBezierSmoothAbsolute(context: DrawContext, x: f64, y: f64) void; -pub extern fn DrawPathCurveToQuadraticBezierSmoothRelative(context: DrawContext, x: f64, y: f64) void; -pub extern fn DrawPathCurveToSmoothAbsolute(context: DrawContext, x2: f64, y2: f64, x: f64, y: f64) void; -pub extern fn DrawPathCurveToSmoothRelative(context: DrawContext, x2: f64, y2: f64, x: f64, y: f64) void; -pub extern fn DrawPathEllipticArcAbsolute(context: DrawContext, rx: f64, ry: f64, x_axis_rotation: f64, large_arc_flag: c_uint, sweep_flag: c_uint, x: f64, y: f64) void; -pub extern fn DrawPathEllipticArcRelative(context: DrawContext, rx: f64, ry: f64, x_axis_rotation: f64, large_arc_flag: c_uint, sweep_flag: c_uint, x: f64, y: f64) void; -pub extern fn DrawPathFinish(context: DrawContext) void; -pub extern fn DrawPathLineToAbsolute(context: DrawContext, x: f64, y: f64) void; -pub extern fn DrawPathLineToRelative(context: DrawContext, x: f64, y: f64) void; -pub extern fn DrawPathLineToHorizontalAbsolute(context: DrawContext, x: f64) void; -pub extern fn DrawPathLineToHorizontalRelative(context: DrawContext, x: f64) void; -pub extern fn DrawPathLineToVerticalAbsolute(context: DrawContext, y: f64) void; -pub extern fn DrawPathLineToVerticalRelative(context: DrawContext, y: f64) void; -pub extern fn DrawPathMoveToAbsolute(context: DrawContext, x: f64, y: f64) void; -pub extern fn DrawPathMoveToRelative(context: DrawContext, x: f64, y: f64) void; -pub extern fn DrawPathStart(context: DrawContext) void; -pub extern fn DrawPoint(context: DrawContext, x: f64, y: f64) void; -pub extern fn DrawPolygon(context: DrawContext, num_coords: c_ulong, coordinates: [*c]const PointInfo) void; -pub extern fn DrawPolyline(context: DrawContext, num_coords: c_ulong, coordinates: [*c]const PointInfo) void; -pub extern fn DrawPopClipPath(context: DrawContext) void; -pub extern fn DrawPopDefs(context: DrawContext) void; -pub extern fn DrawPopGraphicContext(context: DrawContext) void; -pub extern fn DrawPopPattern(context: DrawContext) void; -pub extern fn DrawPushClipPath(context: DrawContext, clip_path_id: [*c]const u8) void; -pub extern fn DrawPushDefs(context: DrawContext) void; -pub extern fn DrawPushGraphicContext(context: DrawContext) void; -pub extern fn DrawPushPattern(context: DrawContext, pattern_id: [*c]const u8, x: f64, y: f64, width: f64, height: f64) void; -pub extern fn DrawRectangle(context: DrawContext, x1: f64, y1: f64, x2: f64, y2: f64) void; -pub extern fn DrawRoundRectangle(context: DrawContext, x1: f64, y1: f64, x2: f64, y2: f64, rx: f64, ry: f64) void; -pub extern fn DrawScale(context: DrawContext, x: f64, y: f64) void; -pub extern fn DrawSetClipPath(context: DrawContext, clip_path: [*c]const u8) void; -pub extern fn DrawSetClipRule(context: DrawContext, fill_rule: FillRule) void; -pub extern fn DrawSetClipUnits(context: DrawContext, clip_units: ClipPathUnits) void; -pub extern fn DrawSetFillColor(context: DrawContext, fill_color: [*c]const PixelPacket) void; -pub extern fn DrawSetFillColorString(context: DrawContext, fill_color: [*c]const u8) void; -pub extern fn DrawSetFillOpacity(context: DrawContext, fill_opacity: f64) void; -pub extern fn DrawSetFillRule(context: DrawContext, fill_rule: FillRule) void; -pub extern fn DrawSetFillPatternURL(context: DrawContext, fill_url: [*c]const u8) void; -pub extern fn DrawSetFont(context: DrawContext, font_name: [*c]const u8) void; -pub extern fn DrawSetFontFamily(context: DrawContext, font_family: [*c]const u8) void; -pub extern fn DrawSetFontSize(context: DrawContext, font_pointsize: f64) void; -pub extern fn DrawSetFontStretch(context: DrawContext, font_stretch: StretchType) void; -pub extern fn DrawSetFontStyle(context: DrawContext, font_style: StyleType) void; -pub extern fn DrawSetFontWeight(context: DrawContext, font_weight: c_ulong) void; -pub extern fn DrawSetGravity(context: DrawContext, gravity: GravityType) void; -pub extern fn DrawRotate(context: DrawContext, degrees: f64) void; -pub extern fn DrawSkewX(context: DrawContext, degrees: f64) void; -pub extern fn DrawSkewY(context: DrawContext, degrees: f64) void; -pub extern fn DrawSetStrokeAntialias(context: DrawContext, true_false: c_uint) void; -pub extern fn DrawSetStrokeColor(context: DrawContext, stroke_color: [*c]const PixelPacket) void; -pub extern fn DrawSetStrokeColorString(context: DrawContext, stroke_color: [*c]const u8) void; -pub extern fn DrawSetStrokeDashArray(context: DrawContext, num_elems: c_ulong, dasharray: [*c]const f64) void; -pub extern fn DrawSetStrokeDashOffset(context: DrawContext, dashoffset: f64) void; -pub extern fn DrawSetStrokeLineCap(context: DrawContext, linecap: LineCap) void; -pub extern fn DrawSetStrokeLineJoin(context: DrawContext, linejoin: LineJoin) void; -pub extern fn DrawSetStrokeMiterLimit(context: DrawContext, miterlimit: c_ulong) void; -pub extern fn DrawSetStrokeOpacity(context: DrawContext, opacity: f64) void; -pub extern fn DrawSetStrokePatternURL(context: DrawContext, stroke_url: [*c]const u8) void; -pub extern fn DrawSetStrokeWidth(context: DrawContext, width: f64) void; -pub extern fn DrawSetTextAntialias(context: DrawContext, true_false: c_uint) void; -pub extern fn DrawSetTextDecoration(context: DrawContext, decoration: DecorationType) void; -pub extern fn DrawSetTextEncoding(context: DrawContext, encoding: [*c]const u8) void; -pub extern fn DrawSetTextUnderColor(context: DrawContext, color: [*c]const PixelPacket) void; -pub extern fn DrawSetTextUnderColorString(context: DrawContext, under_color: [*c]const u8) void; -pub extern fn DrawSetViewbox(context: DrawContext, x1: c_ulong, y1: c_ulong, x2: c_ulong, y2: c_ulong) void; -pub extern fn DrawTranslate(context: DrawContext, x: f64, y: f64) void; -pub extern fn AdaptiveThresholdImage(arg0: [*c]const Image, arg1: c_ulong, arg2: c_ulong, arg3: f64, arg4: [*c]ExceptionInfo) [*c]Image; -pub extern fn AddNoiseImage(arg0: [*c]const Image, arg1: NoiseType, arg2: [*c]ExceptionInfo) [*c]Image; -pub extern fn AddNoiseImageChannel(image: [*c]const Image, channel: ChannelType, noise_type: NoiseType, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn BlurImage(arg0: [*c]const Image, arg1: f64, arg2: f64, arg3: [*c]ExceptionInfo) [*c]Image; -pub extern fn BlurImageChannel(image: [*c]const Image, channel: ChannelType, radius: f64, sigma: f64, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn ConvolveImage(arg0: [*c]const Image, arg1: c_uint, arg2: [*c]const f64, arg3: [*c]ExceptionInfo) [*c]Image; -pub extern fn DespeckleImage(arg0: [*c]const Image, arg1: [*c]ExceptionInfo) [*c]Image; -pub extern fn EdgeImage(arg0: [*c]const Image, arg1: f64, arg2: [*c]ExceptionInfo) [*c]Image; -pub extern fn EmbossImage(arg0: [*c]const Image, arg1: f64, arg2: f64, arg3: [*c]ExceptionInfo) [*c]Image; -pub extern fn EnhanceImage(arg0: [*c]const Image, arg1: [*c]ExceptionInfo) [*c]Image; -pub extern fn GaussianBlurImage(arg0: [*c]const Image, arg1: f64, arg2: f64, arg3: [*c]ExceptionInfo) [*c]Image; -pub extern fn GaussianBlurImageChannel(image: [*c]const Image, channel: ChannelType, radius: f64, sigma: f64, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn MedianFilterImage(arg0: [*c]const Image, arg1: f64, arg2: [*c]ExceptionInfo) [*c]Image; -pub extern fn MotionBlurImage(arg0: [*c]const Image, arg1: f64, arg2: f64, arg3: f64, arg4: [*c]ExceptionInfo) [*c]Image; -pub extern fn ReduceNoiseImage(arg0: [*c]const Image, arg1: f64, arg2: [*c]ExceptionInfo) [*c]Image; -pub extern fn ShadeImage(arg0: [*c]const Image, arg1: c_uint, arg2: f64, arg3: f64, arg4: [*c]ExceptionInfo) [*c]Image; -pub extern fn SharpenImage(arg0: [*c]const Image, arg1: f64, arg2: f64, arg3: [*c]ExceptionInfo) [*c]Image; -pub extern fn SharpenImageChannel(image: [*c]const Image, channel: ChannelType, radius: f64, sigma: f64, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn SpreadImage(arg0: [*c]const Image, arg1: c_uint, arg2: [*c]ExceptionInfo) [*c]Image; -pub extern fn UnsharpMaskImage(arg0: [*c]const Image, arg1: f64, arg2: f64, arg3: f64, arg4: f64, arg5: [*c]ExceptionInfo) [*c]Image; -pub extern fn UnsharpMaskImageChannel(image: [*c]const Image, channel: ChannelType, radius: f64, sigma: f64, amount: f64, threshold: f64, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn BlackThresholdImage(image: [*c]Image, thresholds: [*c]const u8) c_uint; -pub extern fn ChannelThresholdImage(arg0: [*c]Image, arg1: [*c]const u8) c_uint; -pub extern fn RandomChannelThresholdImage(arg0: [*c]Image, arg1: [*c]const u8, arg2: [*c]const u8, exception: [*c]ExceptionInfo) c_uint; -pub extern fn ThresholdImage(arg0: [*c]Image, arg1: f64) c_uint; -pub extern fn WhiteThresholdImage(image: [*c]Image, thresholds: [*c]const u8) c_uint; -pub extern fn ContrastImage(arg0: [*c]Image, arg1: c_uint) c_uint; -pub extern fn EqualizeImage(arg0: [*c]Image) c_uint; -pub extern fn GammaImage(arg0: [*c]Image, arg1: [*c]const u8) c_uint; -pub extern fn LevelImage(arg0: [*c]Image, arg1: [*c]const u8) c_uint; -pub extern fn LevelImageChannel(arg0: [*c]Image, arg1: ChannelType, arg2: f64, arg3: f64, arg4: f64) c_uint; -pub extern fn ModulateImage(arg0: [*c]Image, arg1: [*c]const u8) c_uint; -pub extern fn NegateImage(arg0: [*c]Image, arg1: c_uint) c_uint; -pub extern fn NormalizeImage(arg0: [*c]Image) c_uint; -pub extern fn CharcoalImage(arg0: [*c]const Image, arg1: f64, arg2: f64, arg3: [*c]ExceptionInfo) [*c]Image; -pub extern fn ColorizeImage(arg0: [*c]const Image, arg1: [*c]const u8, arg2: PixelPacket, arg3: [*c]ExceptionInfo) [*c]Image; -pub extern fn ImplodeImage(arg0: [*c]const Image, arg1: f64, arg2: [*c]ExceptionInfo) [*c]Image; -pub extern fn MorphImages(arg0: [*c]const Image, arg1: c_ulong, arg2: [*c]ExceptionInfo) [*c]Image; -pub extern fn OilPaintImage(arg0: [*c]const Image, arg1: f64, arg2: [*c]ExceptionInfo) [*c]Image; -pub extern fn SteganoImage(arg0: [*c]const Image, arg1: [*c]const Image, arg2: [*c]ExceptionInfo) [*c]Image; -pub extern fn StereoImage(arg0: [*c]const Image, arg1: [*c]const Image, arg2: [*c]ExceptionInfo) [*c]Image; -pub extern fn SwirlImage(arg0: [*c]const Image, arg1: f64, arg2: [*c]ExceptionInfo) [*c]Image; -pub extern fn WaveImage(arg0: [*c]const Image, arg1: f64, arg2: f64, arg3: [*c]ExceptionInfo) [*c]Image; -pub extern fn ColorMatrixImage(image: [*c]Image, order: c_uint, matrix: [*c]const f64) c_uint; -pub extern fn SolarizeImage(arg0: [*c]Image, arg1: f64) c_uint; -pub const struct__MagickRandomKernel = extern struct { - z: magick_uint32_t, - w: magick_uint32_t, -}; -pub const MagickRandomKernel = struct__MagickRandomKernel; -pub extern fn MagickRandomInteger() magick_uint32_t; -pub extern fn MagickRandomReal() f64; -pub extern fn ExpandAffine(arg0: [*c]const AffineMatrix) f64; -pub extern fn GenerateDifferentialNoise(pixel: Quantum, noise_type: NoiseType, kernel: [*c]MagickRandomKernel) f64; -pub extern fn GetOptimalKernelWidth(arg0: f64, arg1: f64) c_int; -pub extern fn GetOptimalKernelWidth1D(arg0: f64, arg1: f64) c_int; -pub extern fn GetOptimalKernelWidth2D(arg0: f64, arg1: f64) c_int; -pub extern fn GenerateNoise(arg0: Quantum, arg1: NoiseType) Quantum; -pub extern fn Contrast(arg0: c_int, arg1: [*c]Quantum, arg2: [*c]Quantum, arg3: [*c]Quantum) void; -pub extern fn HSLTransform(arg0: f64, arg1: f64, arg2: f64, arg3: [*c]Quantum, arg4: [*c]Quantum, arg5: [*c]Quantum) void; -pub extern fn HWBTransform(arg0: f64, arg1: f64, arg2: f64, arg3: [*c]Quantum, arg4: [*c]Quantum, arg5: [*c]Quantum) void; -pub extern fn Hull(arg0: c_long, arg1: c_long, arg2: c_ulong, arg3: c_ulong, arg4: [*c]Quantum, arg5: [*c]Quantum, arg6: c_int) void; -pub extern fn IdentityAffine(arg0: [*c]AffineMatrix) void; -pub extern fn Modulate(arg0: f64, arg1: f64, arg2: f64, arg3: [*c]Quantum, arg4: [*c]Quantum, arg5: [*c]Quantum) void; -pub extern fn TransformHSL(arg0: Quantum, arg1: Quantum, arg2: Quantum, arg3: [*c]f64, arg4: [*c]f64, arg5: [*c]f64) void; -pub extern fn TransformHWB(arg0: Quantum, arg1: Quantum, arg2: Quantum, arg3: [*c]f64, arg4: [*c]f64, arg5: [*c]f64) void; -pub extern fn GradientImage(arg0: [*c]Image, arg1: [*c]const PixelPacket, arg2: [*c]const PixelPacket) c_uint; -pub extern fn HaldClutImage(arg0: [*c]Image, clut: [*c]const Image) c_uint; -pub extern fn CloneImageList(arg0: [*c]const Image, arg1: [*c]ExceptionInfo) [*c]Image; -pub extern fn GetFirstImageInList(arg0: [*c]const Image) [*c]Image; -pub extern fn GetImageFromList(arg0: [*c]const Image, arg1: c_long) [*c]Image; -pub extern fn GetLastImageInList(arg0: [*c]const Image) [*c]Image; -pub extern fn GetNextImageInList(arg0: [*c]const Image) [*c]Image; -pub extern fn GetPreviousImageInList(arg0: [*c]const Image) [*c]Image; -pub extern fn ImageListToArray(arg0: [*c]const Image, arg1: [*c]ExceptionInfo) [*c]([*c]Image); -pub extern fn NewImageList() [*c]Image; -pub extern fn RemoveLastImageFromList(arg0: [*c]([*c]Image)) [*c]Image; -pub extern fn RemoveFirstImageFromList(arg0: [*c]([*c]Image)) [*c]Image; -pub extern fn SplitImageList(arg0: [*c]Image) [*c]Image; -pub extern fn SyncNextImageInList(arg0: [*c]const Image) [*c]Image; -pub extern fn GetImageIndexInList(arg0: [*c]const Image) c_long; -pub extern fn GetImageListLength(arg0: [*c]const Image) c_ulong; -pub extern fn AppendImageToList(arg0: [*c]([*c]Image), arg1: [*c]Image) void; -pub extern fn DeleteImageFromList(arg0: [*c]([*c]Image)) void; -pub extern fn DestroyImageList(arg0: [*c]Image) void; -pub extern fn InsertImageInList(arg0: [*c]([*c]Image), arg1: [*c]Image) void; -pub extern fn PrependImageToList(arg0: [*c]([*c]Image), arg1: [*c]Image) void; -pub extern fn ReplaceImageInList(images: [*c]([*c]Image), image: [*c]Image) void; -pub extern fn ReverseImageList(arg0: [*c]([*c]Image)) void; -pub extern fn SpliceImageIntoList(arg0: [*c]([*c]Image), arg1: c_ulong, arg2: [*c]Image) void; -pub extern fn GetMagickFileFormat(header: [*c]const u8, header_length: usize, format: [*c]u8, format_length: usize, exception: [*c]ExceptionInfo) c_uint; -pub extern fn ListMagicInfo(file: [*c]FILE, exception: [*c]ExceptionInfo) c_uint; -pub const DecoderHandler = ?extern fn ([*c]const ImageInfo, [*c]ExceptionInfo) [*c]Image; -pub const EncoderHandler = ?extern fn ([*c]const ImageInfo, [*c]Image) c_uint; -pub const MagickHandler = ?extern fn ([*c]const u8, usize) c_uint; -pub const BrokenCoderClass = -1; -pub const UnstableCoderClass = 0; -pub const StableCoderClass = 1; -pub const PrimaryCoderClass = 2; -pub const CoderClass = extern enum { - BrokenCoderClass = -1, - UnstableCoderClass = 0, - StableCoderClass = 1, - PrimaryCoderClass = 2, -}; -pub const HintExtensionTreatment = 0; -pub const ObeyExtensionTreatment = 1; -pub const IgnoreExtensionTreatment = 2; -pub const ExtensionTreatment = extern enum { - HintExtensionTreatment = 0, - ObeyExtensionTreatment = 1, - IgnoreExtensionTreatment = 2, -}; -pub const struct__MagickInfo = extern struct { - next: [*c]struct__MagickInfo, - previous: [*c]struct__MagickInfo, - name: [*c]const u8, - description: [*c]const u8, - note: [*c]const u8, - version: [*c]const u8, - module: [*c]const u8, - decoder: DecoderHandler, - encoder: EncoderHandler, - magick: MagickHandler, - client_data: ?*c_void, - adjoin: c_uint, - raw: c_uint, - stealth: c_uint, - seekable_stream: c_uint, - blob_support: c_uint, - thread_support: c_uint, - coder_class: CoderClass, - extension_treatment: ExtensionTreatment, - signature: c_ulong, -}; -pub const MagickInfo = struct__MagickInfo; -pub extern fn MagickToMime(magick: [*c]const u8) [*c]u8; -pub extern fn GetImageMagick(magick: [*c]const u8, length: usize) [*c]const u8; -pub extern fn IsMagickConflict(magick: [*c]const u8) c_uint; -pub extern fn ListModuleMap(file: [*c]FILE, exception: [*c]ExceptionInfo) c_uint; -pub extern fn ListMagickInfo(file: [*c]FILE, exception: [*c]ExceptionInfo) c_uint; -pub extern fn UnregisterMagickInfo(name: [*c]const u8) c_uint; -pub extern fn DestroyMagick() void; -pub extern fn InitializeMagick(path: [*c]const u8) void; -pub extern fn PanicDestroyMagick() void; -pub extern fn GetMagickInfo(name: [*c]const u8, exception: [*c]ExceptionInfo) [*c]const MagickInfo; -pub extern fn GetMagickInfoArray(exception: [*c]ExceptionInfo) [*c]([*c]MagickInfo); -pub extern fn RegisterMagickInfo(magick_info: [*c]MagickInfo) [*c]MagickInfo; -pub extern fn SetMagickInfo(name: [*c]const u8) [*c]MagickInfo; -pub const MagickMallocFunc = ?extern fn (usize) ?*c_void; -pub const MagickFreeFunc = ?extern fn (?*c_void) void; -pub const MagickReallocFunc = ?extern fn (?*c_void, usize) ?*c_void; -pub extern fn MagickAllocFunctions(free_func: MagickFreeFunc, malloc_func: MagickMallocFunc, realloc_func: MagickReallocFunc) void; -pub extern fn MagickMalloc(size: usize) ?*c_void; -pub extern fn MagickMallocAligned(alignment: usize, size: usize) ?*c_void; -pub extern fn MagickMallocCleared(size: usize) ?*c_void; -pub extern fn MagickCloneMemory(destination: ?*c_void, source: ?*const c_void, size: usize) ?*c_void; -pub extern fn MagickRealloc(memory: ?*c_void, size: usize) ?*c_void; -pub extern fn MagickFree(memory: ?*c_void) void; -pub extern fn MagickFreeAligned(memory: ?*c_void) void; -pub extern fn ListModuleInfo(file: [*c]FILE, exception: [*c]ExceptionInfo) c_uint; -pub extern fn ExecuteModuleProcess(tag: [*c]const u8, image: [*c]([*c]Image), argc: c_int, argv: [*c]([*c]u8)) c_uint; -pub const MonitorHandler = ?extern fn ([*c]const u8, magick_int64_t, magick_uint64_t, [*c]ExceptionInfo) c_uint; -pub extern fn SetMonitorHandler(handler: MonitorHandler) MonitorHandler; -pub extern fn MagickMonitor(text: [*c]const u8, quantum: magick_int64_t, span: magick_uint64_t, exception: [*c]ExceptionInfo) c_uint; -pub extern fn MagickMonitorFormatted(quantum: magick_int64_t, span: magick_uint64_t, exception: [*c]ExceptionInfo, format: [*c]const u8, ...) c_uint; -pub extern fn MontageImages(arg0: [*c]const Image, arg1: [*c]const MontageInfo, arg2: [*c]ExceptionInfo) [*c]Image; -pub extern fn CloneMontageInfo(arg0: [*c]const ImageInfo, arg1: [*c]const MontageInfo) [*c]MontageInfo; -pub extern fn DestroyMontageInfo(arg0: [*c]MontageInfo) void; -pub extern fn GetMontageInfo(arg0: [*c]const ImageInfo, arg1: [*c]MontageInfo) void; -pub const UndefinedQuantumOp = 0; -pub const AddQuantumOp = 1; -pub const AndQuantumOp = 2; -pub const AssignQuantumOp = 3; -pub const DivideQuantumOp = 4; -pub const LShiftQuantumOp = 5; -pub const MultiplyQuantumOp = 6; -pub const OrQuantumOp = 7; -pub const RShiftQuantumOp = 8; -pub const SubtractQuantumOp = 9; -pub const ThresholdQuantumOp = 10; -pub const ThresholdBlackQuantumOp = 11; -pub const ThresholdWhiteQuantumOp = 12; -pub const XorQuantumOp = 13; -pub const NoiseGaussianQuantumOp = 14; -pub const NoiseImpulseQuantumOp = 15; -pub const NoiseLaplacianQuantumOp = 16; -pub const NoiseMultiplicativeQuantumOp = 17; -pub const NoisePoissonQuantumOp = 18; -pub const NoiseUniformQuantumOp = 19; -pub const NegateQuantumOp = 20; -pub const GammaQuantumOp = 21; -pub const DepthQuantumOp = 22; -pub const LogQuantumOp = 23; -pub const MaxQuantumOp = 24; -pub const MinQuantumOp = 25; -pub const PowQuantumOp = 26; -pub const NoiseRandomQuantumOp = 27; -pub const ThresholdBlackNegateQuantumOp = 28; -pub const ThresholdWhiteNegateQuantumOp = 29; -pub const QuantumOperator = extern enum { - UndefinedQuantumOp = 0, - AddQuantumOp = 1, - AndQuantumOp = 2, - AssignQuantumOp = 3, - DivideQuantumOp = 4, - LShiftQuantumOp = 5, - MultiplyQuantumOp = 6, - OrQuantumOp = 7, - RShiftQuantumOp = 8, - SubtractQuantumOp = 9, - ThresholdQuantumOp = 10, - ThresholdBlackQuantumOp = 11, - ThresholdWhiteQuantumOp = 12, - XorQuantumOp = 13, - NoiseGaussianQuantumOp = 14, - NoiseImpulseQuantumOp = 15, - NoiseLaplacianQuantumOp = 16, - NoiseMultiplicativeQuantumOp = 17, - NoisePoissonQuantumOp = 18, - NoiseUniformQuantumOp = 19, - NegateQuantumOp = 20, - GammaQuantumOp = 21, - DepthQuantumOp = 22, - LogQuantumOp = 23, - MaxQuantumOp = 24, - MinQuantumOp = 25, - PowQuantumOp = 26, - NoiseRandomQuantumOp = 27, - ThresholdBlackNegateQuantumOp = 28, - ThresholdWhiteNegateQuantumOp = 29, -}; -pub extern fn QuantumOperatorImage(image: [*c]Image, channel: ChannelType, quantum_operator: QuantumOperator, rvalue: f64, exception: [*c]ExceptionInfo) c_uint; -pub extern fn QuantumOperatorImageMultivalue(image: [*c]Image, quantum_operator: QuantumOperator, values: [*c]const u8) c_uint; -pub extern fn QuantumOperatorRegionImage(image: [*c]Image, x: c_long, y: c_long, columns: c_ulong, rows: c_ulong, channel: ChannelType, quantum_operator: QuantumOperator, rvalue: f64, exception: [*c]ExceptionInfo) c_uint; -pub extern fn ColorFloodfillImage(arg0: [*c]Image, arg1: [*c]const DrawInfo, arg2: PixelPacket, arg3: c_long, arg4: c_long, arg5: PaintMethod) c_uint; -pub extern fn MatteFloodfillImage(arg0: [*c]Image, arg1: PixelPacket, arg2: c_uint, arg3: c_long, arg4: c_long, arg5: PaintMethod) c_uint; -pub extern fn OpaqueImage(arg0: [*c]Image, arg1: PixelPacket, arg2: PixelPacket) c_uint; -pub extern fn TransparentImage(arg0: [*c]Image, arg1: PixelPacket, arg2: c_uint) c_uint; -pub const UndefinedVirtualPixelMethod = 0; -pub const ConstantVirtualPixelMethod = 1; -pub const EdgeVirtualPixelMethod = 2; -pub const MirrorVirtualPixelMethod = 3; -pub const TileVirtualPixelMethod = 4; -pub const VirtualPixelMethod = extern enum { - UndefinedVirtualPixelMethod = 0, - ConstantVirtualPixelMethod = 1, - EdgeVirtualPixelMethod = 2, - MirrorVirtualPixelMethod = 3, - TileVirtualPixelMethod = 4, -}; -pub const Cache = _CacheInfoPtr_; -pub extern fn AcquireImagePixels(image: [*c]const Image, x: c_long, y: c_long, columns: c_ulong, rows: c_ulong, exception: [*c]ExceptionInfo) [*c]const PixelPacket; -pub extern fn AccessImmutableIndexes(image: [*c]const Image) [*c]const IndexPacket; -pub extern fn AcquireOnePixel(image: [*c]const Image, x: c_long, y: c_long, exception: [*c]ExceptionInfo) PixelPacket; -pub extern fn GetImagePixels(image: [*c]Image, x: c_long, y: c_long, columns: c_ulong, rows: c_ulong) [*c]PixelPacket; -pub extern fn GetImagePixelsEx(image: [*c]Image, x: c_long, y: c_long, columns: c_ulong, rows: c_ulong, exception: [*c]ExceptionInfo) [*c]PixelPacket; -pub extern fn GetImageVirtualPixelMethod(image: [*c]const Image) VirtualPixelMethod; -pub extern fn GetPixels(image: [*c]const Image) [*c]PixelPacket; -pub extern fn AccessMutablePixels(image: [*c]Image) [*c]PixelPacket; -pub extern fn GetIndexes(image: [*c]const Image) [*c]IndexPacket; -pub extern fn AccessMutableIndexes(image: [*c]Image) [*c]IndexPacket; -pub extern fn GetOnePixel(image: [*c]Image, x: c_long, y: c_long) PixelPacket; -pub extern fn GetPixelCacheArea(image: [*c]const Image) magick_off_t; -pub extern fn SetImagePixels(image: [*c]Image, x: c_long, y: c_long, columns: c_ulong, rows: c_ulong) [*c]PixelPacket; -pub extern fn SetImagePixelsEx(image: [*c]Image, x: c_long, y: c_long, columns: c_ulong, rows: c_ulong, exception: [*c]ExceptionInfo) [*c]PixelPacket; -pub extern fn SetImageVirtualPixelMethod(image: [*c]const Image, method: VirtualPixelMethod) c_uint; -pub extern fn SyncImagePixels(image: [*c]Image) c_uint; -pub extern fn SyncImagePixelsEx(image: [*c]Image, exception: [*c]ExceptionInfo) c_uint; -pub extern fn OpenCacheView(image: [*c]Image) [*c]ViewInfo; -pub extern fn CloseCacheView(view: [*c]ViewInfo) void; -pub extern fn AccessCacheViewPixels(view: [*c]const ViewInfo) [*c]PixelPacket; -pub extern fn AcquireCacheViewIndexes(view: [*c]const ViewInfo) [*c]const IndexPacket; -pub extern fn AcquireCacheViewPixels(view: [*c]ViewInfo, x: c_long, y: c_long, columns: c_ulong, rows: c_ulong, exception: [*c]ExceptionInfo) [*c]const PixelPacket; -pub extern fn AcquireOneCacheViewPixel(view: [*c]ViewInfo, pixel: [*c]PixelPacket, x: c_long, y: c_long, exception: [*c]ExceptionInfo) c_uint; -pub extern fn GetCacheViewArea(view: [*c]const ViewInfo) magick_off_t; -pub extern fn GetCacheViewImage(view: [*c]const ViewInfo) [*c]Image; -pub extern fn GetCacheViewIndexes(view: [*c]const ViewInfo) [*c]IndexPacket; -pub extern fn GetCacheViewPixels(view: [*c]ViewInfo, x: c_long, y: c_long, columns: c_ulong, rows: c_ulong, exception: [*c]ExceptionInfo) [*c]PixelPacket; -pub extern fn GetCacheViewRegion(view: [*c]const ViewInfo) RectangleInfo; -pub extern fn SetCacheViewPixels(view: [*c]ViewInfo, x: c_long, y: c_long, columns: c_ulong, rows: c_ulong, exception: [*c]ExceptionInfo) [*c]PixelPacket; -pub extern fn SyncCacheViewPixels(view: [*c]const ViewInfo, exception: [*c]ExceptionInfo) c_uint; -pub const struct__PixelIteratorOptions = extern struct { - max_threads: c_int, - signature: c_ulong, -}; -pub const PixelIteratorOptions = struct__PixelIteratorOptions; -pub extern fn InitializePixelIteratorOptions(options: [*c]PixelIteratorOptions, exception: [*c]ExceptionInfo) void; -pub const PixelIteratorMonoReadCallback = ?extern fn (?*c_void, ?*const c_void, [*c]const Image, [*c]const PixelPacket, [*c]const IndexPacket, c_long, [*c]ExceptionInfo) c_uint; -pub extern fn PixelIterateMonoRead(call_back: PixelIteratorMonoReadCallback, options: [*c]const PixelIteratorOptions, description: [*c]const u8, mutable_data: ?*c_void, immutable_data: ?*const c_void, x: c_long, y: c_long, columns: c_ulong, rows: c_ulong, image: [*c]const Image, exception: [*c]ExceptionInfo) c_uint; -pub const PixelIteratorMonoModifyCallback = ?extern fn (?*c_void, ?*const c_void, [*c]Image, [*c]PixelPacket, [*c]IndexPacket, c_long, [*c]ExceptionInfo) c_uint; -pub extern fn PixelIterateMonoSet(call_back: PixelIteratorMonoModifyCallback, options: [*c]const PixelIteratorOptions, description: [*c]const u8, mutable_data: ?*c_void, immutable_data: ?*const c_void, x: c_long, y: c_long, columns: c_ulong, rows: c_ulong, image: [*c]Image, exception: [*c]ExceptionInfo) c_uint; -pub extern fn PixelIterateMonoModify(call_back: PixelIteratorMonoModifyCallback, options: [*c]const PixelIteratorOptions, description: [*c]const u8, mutable_data: ?*c_void, immutable_data: ?*const c_void, x: c_long, y: c_long, columns: c_ulong, rows: c_ulong, image: [*c]Image, exception: [*c]ExceptionInfo) c_uint; -pub const PixelIteratorDualReadCallback = ?extern fn (?*c_void, ?*const c_void, [*c]const Image, [*c]const PixelPacket, [*c]const IndexPacket, [*c]const Image, [*c]const PixelPacket, [*c]const IndexPacket, c_long, [*c]ExceptionInfo) c_uint; -pub extern fn PixelIterateDualRead(call_back: PixelIteratorDualReadCallback, options: [*c]const PixelIteratorOptions, description: [*c]const u8, mutable_data: ?*c_void, immutable_data: ?*const c_void, columns: c_ulong, rows: c_ulong, first_image: [*c]const Image, first_x: c_long, first_y: c_long, second_image: [*c]const Image, second_x: c_long, second_y: c_long, exception: [*c]ExceptionInfo) c_uint; -pub const PixelIteratorDualModifyCallback = ?extern fn (?*c_void, ?*const c_void, [*c]const Image, [*c]const PixelPacket, [*c]const IndexPacket, [*c]Image, [*c]PixelPacket, [*c]IndexPacket, c_long, [*c]ExceptionInfo) c_uint; -pub extern fn PixelIterateDualModify(call_back: PixelIteratorDualModifyCallback, options: [*c]const PixelIteratorOptions, description: [*c]const u8, mutable_data: ?*c_void, immutable_data: ?*const c_void, columns: c_ulong, rows: c_ulong, source_image: [*c]const Image, source_x: c_long, source_y: c_long, update_image: [*c]Image, update_x: c_long, update_y: c_long, exception: [*c]ExceptionInfo) c_uint; -pub const PixelIteratorDualNewCallback = PixelIteratorDualModifyCallback; -pub extern fn PixelIterateDualNew(call_back: PixelIteratorDualNewCallback, options: [*c]const PixelIteratorOptions, description: [*c]const u8, mutable_data: ?*c_void, immutable_data: ?*const c_void, columns: c_ulong, rows: c_ulong, source_image: [*c]const Image, source_x: c_long, source_y: c_long, new_image: [*c]Image, new_x: c_long, new_y: c_long, exception: [*c]ExceptionInfo) c_uint; -pub const PixelIteratorTripleModifyCallback = ?extern fn (?*c_void, ?*const c_void, [*c]const Image, [*c]const PixelPacket, [*c]const IndexPacket, [*c]const Image, [*c]const PixelPacket, [*c]const IndexPacket, [*c]Image, [*c]PixelPacket, [*c]IndexPacket, c_long, [*c]ExceptionInfo) c_uint; -pub extern fn PixelIterateTripleModify(call_back: PixelIteratorTripleModifyCallback, options: [*c]const PixelIteratorOptions, description: [*c]const u8, mutable_data: ?*c_void, immutable_data: ?*const c_void, columns: c_ulong, rows: c_ulong, source1_image: [*c]const Image, source2_image: [*c]const Image, source_x: c_long, source_y: c_long, update_image: [*c]Image, update_x: c_long, update_y: c_long, exception: [*c]ExceptionInfo) c_uint; -pub const PixelIteratorTripleNewCallback = PixelIteratorTripleModifyCallback; -pub extern fn PixelIterateTripleNew(call_back: PixelIteratorTripleNewCallback, options: [*c]const PixelIteratorOptions, description: [*c]const u8, mutable_data: ?*c_void, immutable_data: ?*const c_void, columns: c_ulong, rows: c_ulong, source1_image: [*c]const Image, source2_image: [*c]const Image, source_x: c_long, source_y: c_long, new_image: [*c]Image, new_x: c_long, new_y: c_long, exception: [*c]ExceptionInfo) c_uint; -pub extern fn PlasmaImage(image: [*c]Image, segment: [*c]const SegmentInfo, attenuate: c_ulong, depth: c_ulong) c_uint; -pub extern fn GetImageProfile(image: [*c]const Image, name: [*c]const u8, length: [*c]usize) [*c]const u8; -pub extern fn DeleteImageProfile(image: [*c]Image, name: [*c]const u8) c_uint; -pub extern fn ProfileImage(image: [*c]Image, name: [*c]const u8, profile: [*c]u8, length: usize, clone: c_uint) c_uint; -pub extern fn SetImageProfile(image: [*c]Image, name: [*c]const u8, profile: [*c]const u8, length: usize) c_uint; -pub extern fn AppendImageProfile(image: [*c]Image, name: [*c]const u8, profile_chunk: [*c]const u8, chunk_length: usize) c_uint; -pub const ImageProfileIterator = ?*c_void; -pub extern fn AllocateImageProfileIterator(image: [*c]const Image) ImageProfileIterator; -pub extern fn NextImageProfile(profile_iterator: ImageProfileIterator, name: [*c]([*c]const u8), profile: [*c]([*c]const u8), length: [*c]usize) c_uint; -pub extern fn DeallocateImageProfileIterator(profile_iterator: ImageProfileIterator) void; -pub const struct__QuantizeInfo = extern struct { - number_colors: c_ulong, - tree_depth: c_uint, - dither: c_uint, - colorspace: ColorspaceType, - measure_error: c_uint, - signature: c_ulong, -}; -pub const QuantizeInfo = struct__QuantizeInfo; -pub extern fn CloneQuantizeInfo(arg0: [*c]const QuantizeInfo) [*c]QuantizeInfo; -pub extern fn GetImageQuantizeError(arg0: [*c]Image) c_uint; -pub extern fn MapImage(arg0: [*c]Image, arg1: [*c]const Image, arg2: c_uint) c_uint; -pub extern fn MapImages(arg0: [*c]Image, arg1: [*c]const Image, arg2: c_uint) c_uint; -pub extern fn OrderedDitherImage(arg0: [*c]Image) c_uint; -pub extern fn QuantizeImage(arg0: [*c]const QuantizeInfo, arg1: [*c]Image) c_uint; -pub extern fn QuantizeImages(arg0: [*c]const QuantizeInfo, arg1: [*c]Image) c_uint; -pub extern fn SegmentImage(arg0: [*c]Image, arg1: ColorspaceType, arg2: c_uint, arg3: f64, arg4: f64) c_uint; -pub extern fn CompressImageColormap(arg0: [*c]Image) void; -pub extern fn DestroyQuantizeInfo(arg0: [*c]QuantizeInfo) void; -pub extern fn GetQuantizeInfo(arg0: [*c]QuantizeInfo) void; -pub extern fn GrayscalePseudoClassImage(arg0: [*c]Image, arg1: c_uint) void; -pub const UndefinedRegistryType = 0; -pub const ImageRegistryType = 1; -pub const ImageInfoRegistryType = 2; -pub const RegistryType = extern enum { - UndefinedRegistryType = 0, - ImageRegistryType = 1, - ImageInfoRegistryType = 2, -}; -pub extern fn GetImageFromMagickRegistry(name: [*c]const u8, id: [*c]c_long, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn SetMagickRegistry(type_0: RegistryType, blob: ?*const c_void, length: usize, exception: [*c]ExceptionInfo) c_long; -pub extern fn DeleteMagickRegistry(id: c_long) c_uint; -pub extern fn GetMagickRegistry(id: c_long, type_0: [*c]RegistryType, length: [*c]usize, exception: [*c]ExceptionInfo) ?*c_void; -pub extern fn MagnifyImage(arg0: [*c]const Image, arg1: [*c]ExceptionInfo) [*c]Image; -pub extern fn MinifyImage(arg0: [*c]const Image, arg1: [*c]ExceptionInfo) [*c]Image; -pub extern fn ResizeImage(arg0: [*c]const Image, arg1: c_ulong, arg2: c_ulong, arg3: FilterTypes, arg4: f64, arg5: [*c]ExceptionInfo) [*c]Image; -pub extern fn SampleImage(arg0: [*c]const Image, arg1: c_ulong, arg2: c_ulong, arg3: [*c]ExceptionInfo) [*c]Image; -pub extern fn ScaleImage(arg0: [*c]const Image, arg1: c_ulong, arg2: c_ulong, arg3: [*c]ExceptionInfo) [*c]Image; -pub extern fn ThumbnailImage(arg0: [*c]const Image, arg1: c_ulong, arg2: c_ulong, arg3: [*c]ExceptionInfo) [*c]Image; -pub extern fn ZoomImage(arg0: [*c]const Image, arg1: c_ulong, arg2: c_ulong, arg3: [*c]ExceptionInfo) [*c]Image; -pub const UndefinedResource = 0; -pub const DiskResource = 1; -pub const FileResource = 2; -pub const MapResource = 3; -pub const MemoryResource = 4; -pub const PixelsResource = 5; -pub const ThreadsResource = 6; -pub const WidthResource = 7; -pub const HeightResource = 8; -pub const ResourceType = extern enum { - UndefinedResource = 0, - DiskResource = 1, - FileResource = 2, - MapResource = 3, - MemoryResource = 4, - PixelsResource = 5, - ThreadsResource = 6, - WidthResource = 7, - HeightResource = 8, -}; -pub extern fn AcquireMagickResource(type_0: ResourceType, size: magick_uint64_t) c_uint; -pub extern fn ListMagickResourceInfo(file: [*c]FILE, exception: [*c]ExceptionInfo) c_uint; -pub extern fn SetMagickResourceLimit(type_0: ResourceType, limit: magick_int64_t) c_uint; -pub extern fn GetMagickResource(type_0: ResourceType) magick_int64_t; -pub extern fn GetMagickResourceLimit(type_0: ResourceType) magick_int64_t; -pub extern fn DestroyMagickResources() void; -pub extern fn InitializeMagickResources() void; -pub extern fn LiberateMagickResource(type_0: ResourceType, size: magick_uint64_t) void; -pub extern fn AffineTransformImage(arg0: [*c]const Image, arg1: [*c]const AffineMatrix, arg2: [*c]ExceptionInfo) [*c]Image; -pub extern fn AutoOrientImage(image: [*c]const Image, current_orientation: OrientationType, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn RotateImage(arg0: [*c]const Image, arg1: f64, arg2: [*c]ExceptionInfo) [*c]Image; -pub extern fn ShearImage(arg0: [*c]const Image, arg1: f64, arg2: f64, arg3: [*c]ExceptionInfo) [*c]Image; -pub const struct__SignatureInfo = extern struct { - digest: [8]c_ulong, - low_order: c_ulong, - high_order: c_ulong, - offset: c_long, - message: [64]u8, -}; -pub const SignatureInfo = struct__SignatureInfo; -pub extern fn SignatureImage(arg0: [*c]Image) c_uint; -pub extern fn FinalizeSignature(arg0: [*c]SignatureInfo) void; -pub extern fn GetSignatureInfo(arg0: [*c]SignatureInfo) void; -pub extern fn TransformSignature(arg0: [*c]SignatureInfo) void; -pub extern fn UpdateSignature(arg0: [*c]SignatureInfo, arg1: [*c]const u8, arg2: usize) void; -pub const struct__ImageChannelStatistics = extern struct { - maximum: f64, - minimum: f64, - mean: f64, - standard_deviation: f64, - variance: f64, -}; -pub const ImageChannelStatistics = struct__ImageChannelStatistics; -pub const struct__ImageStatistics = extern struct { - red: ImageChannelStatistics, - green: ImageChannelStatistics, - blue: ImageChannelStatistics, - opacity: ImageChannelStatistics, -}; -pub const ImageStatistics = struct__ImageStatistics; -pub extern fn GetImageStatistics(image: [*c]const Image, statistics: [*c]ImageStatistics, exception: [*c]ExceptionInfo) c_uint; -pub extern fn TextureImage(arg0: [*c]Image, arg1: [*c]const Image) c_uint; -pub extern fn ChopImage(image: [*c]const Image, chop_info: [*c]const RectangleInfo, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn CoalesceImages(image: [*c]const Image, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn CropImage(image: [*c]const Image, geometry: [*c]const RectangleInfo, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn DeconstructImages(image: [*c]const Image, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn ExtentImage(image: [*c]const Image, geometry: [*c]const RectangleInfo, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn FlattenImages(image: [*c]const Image, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn FlipImage(image: [*c]const Image, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn FlopImage(image: [*c]const Image, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn MosaicImages(image: [*c]const Image, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn RollImage(image: [*c]const Image, x_offset: c_long, y_offset: c_long, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn ShaveImage(image: [*c]const Image, shave_info: [*c]const RectangleInfo, exception: [*c]ExceptionInfo) [*c]Image; -pub extern fn TransformImage(arg0: [*c]([*c]Image), arg1: [*c]const u8, arg2: [*c]const u8) void; -pub const RootPath = 0; -pub const HeadPath = 1; -pub const TailPath = 2; -pub const BasePath = 3; -pub const ExtensionPath = 4; -pub const MagickPath = 5; -pub const SubImagePath = 6; -pub const FullPath = 7; -pub const PathType = extern enum { - RootPath = 0, - HeadPath = 1, - TailPath = 2, - BasePath = 3, - ExtensionPath = 4, - MagickPath = 5, - SubImagePath = 6, - FullPath = 7, -}; -pub const struct__TokenInfo = extern struct { - state: c_int, - flag: c_uint, - offset: c_long, - quote: u8, -}; -pub const TokenInfo = struct__TokenInfo; -pub const MagickTextTranslate = ?extern fn ([*c]u8, [*c]const u8, usize) usize; -pub extern fn AcquireString(arg0: [*c]const u8) [*c]u8; -pub extern fn AllocateString(arg0: [*c]const u8) [*c]u8; -pub extern fn Base64Encode(arg0: [*c]const u8, arg1: usize, arg2: [*c]usize) [*c]u8; -pub extern fn EscapeString(arg0: [*c]const u8, arg1: u8) [*c]u8; -pub extern fn GetPageGeometry(arg0: [*c]const u8) [*c]u8; -pub extern fn ListFiles(arg0: [*c]const u8, arg1: [*c]const u8, arg2: [*c]c_long) [*c]([*c]u8); -pub extern fn StringToArgv(arg0: [*c]const u8, arg1: [*c]c_int) [*c]([*c]u8); -pub extern fn StringToList(arg0: [*c]const u8) [*c]([*c]u8); -pub extern fn TranslateText(arg0: [*c]const ImageInfo, arg1: [*c]Image, arg2: [*c]const u8) [*c]u8; -pub extern fn TranslateTextEx(arg0: [*c]const ImageInfo, arg1: [*c]Image, arg2: [*c]const u8, arg3: MagickTextTranslate) [*c]u8; -pub extern fn GetClientFilename() [*c]const u8; -pub extern fn GetClientName() [*c]const u8; -pub extern fn GetClientPath() [*c]const u8; -pub extern fn SetClientFilename(arg0: [*c]const u8) [*c]const u8; -pub extern fn SetClientName(arg0: [*c]const u8) [*c]const u8; -pub extern fn SetClientPath(arg0: [*c]const u8) [*c]const u8; -pub extern fn StringToDouble(arg0: [*c]const u8, arg1: f64) f64; -pub extern fn GetGeometry(arg0: [*c]const u8, arg1: [*c]c_long, arg2: [*c]c_long, arg3: [*c]c_ulong, arg4: [*c]c_ulong) c_int; -pub extern fn GlobExpression(arg0: [*c]const u8, arg1: [*c]const u8) c_int; -pub extern fn LocaleNCompare(arg0: [*c]const u8, arg1: [*c]const u8, arg2: usize) c_int; -pub extern fn LocaleCompare(arg0: [*c]const u8, arg1: [*c]const u8) c_int; -pub extern fn GetMagickDimension(str: [*c]const u8, width: [*c]f64, height: [*c]f64, xoff: [*c]f64, yoff: [*c]f64) c_int; -pub extern fn GetMagickGeometry(geometry: [*c]const u8, x: [*c]c_long, y: [*c]c_long, width: [*c]c_ulong, height: [*c]c_ulong) c_int; -pub extern fn MagickRandReentrant(seed: [*c]c_uint) c_int; -pub extern fn MagickSpawnVP(verbose: c_uint, file: [*c]const u8, argv: [*c]const ([*c]u8)) c_int; -pub extern fn SystemCommand(arg0: c_uint, arg1: [*c]const u8) c_int; -pub extern fn Tokenizer(arg0: [*c]TokenInfo, arg1: c_uint, arg2: [*c]u8, arg3: usize, arg4: [*c]u8, arg5: [*c]u8, arg6: [*c]u8, arg7: [*c]u8, arg8: u8, arg9: [*c]u8, arg10: [*c]c_int, arg11: [*c]u8) c_int; -pub extern fn MagickRandNewSeed() c_uint; -pub extern fn Base64Decode(arg0: [*c]const u8, arg1: [*c]usize) [*c]u8; -pub extern fn CloneString(arg0: [*c]([*c]u8), arg1: [*c]const u8) c_uint; -pub extern fn ConcatenateString(arg0: [*c]([*c]u8), arg1: [*c]const u8) c_uint; -pub extern fn ExpandFilenames(arg0: [*c]c_int, arg1: [*c]([*c]([*c]u8))) c_uint; -pub extern fn GetExecutionPath(arg0: [*c]u8) c_uint; -pub extern fn GetExecutionPathUsingName(arg0: [*c]u8) c_uint; -pub extern fn MagickCreateDirectoryPath(dir: [*c]const u8, exception: [*c]ExceptionInfo) c_uint; -pub extern fn IsAccessible(arg0: [*c]const u8) c_uint; -pub extern fn IsAccessibleNoLogging(arg0: [*c]const u8) c_uint; -pub extern fn IsAccessibleAndNotEmpty(arg0: [*c]const u8) c_uint; -pub extern fn IsGeometry(arg0: [*c]const u8) c_uint; -pub extern fn IsGlob(arg0: [*c]const u8) c_uint; -pub extern fn IsWriteable(arg0: [*c]const u8) c_uint; -pub extern fn MagickSceneFileName(filename: [*c]u8, filename_template: [*c]const u8, scene_template: [*c]const u8, force: c_uint, scene: c_ulong) c_uint; -pub extern fn SubstituteString(buffer: [*c]([*c]u8), search: [*c]const u8, replace: [*c]const u8) c_uint; -pub extern fn MultilineCensus(arg0: [*c]const u8) c_ulong; -pub extern fn AppendImageFormat(arg0: [*c]const u8, arg1: [*c]u8) void; -pub extern fn DefineClientName(arg0: [*c]const u8) void; -pub extern fn DefineClientPathAndName(arg0: [*c]const u8) void; -pub extern fn ExpandFilename(arg0: [*c]u8) void; -pub extern fn FormatSize(size: magick_int64_t, format: [*c]u8) void; -pub extern fn GetPathComponent(arg0: [*c]const u8, arg1: PathType, arg2: [*c]u8) void; -pub extern fn GetToken(arg0: [*c]const u8, arg1: [*c]([*c]u8), arg2: [*c]u8) void; -pub extern fn LocaleLower(arg0: [*c]u8) void; -pub extern fn LocaleUpper(arg0: [*c]u8) void; -pub extern fn Strip(arg0: [*c]u8) void; -pub extern fn SetGeometry(arg0: [*c]const Image, arg1: [*c]RectangleInfo) void; -pub extern fn FormatString(string: [*c]u8, format: [*c]const u8, ...) void; -pub extern fn FormatStringList(string: [*c]u8, format: [*c]const u8, operands: [*c]struct___va_list_tag) void; -pub extern fn MagickFormatString(string: [*c]u8, length: usize, format: [*c]const u8, ...) void; -pub extern fn MagickFormatStringList(string: [*c]u8, length: usize, format: [*c]const u8, operands: [*c]struct___va_list_tag) void; -pub extern fn MagickSizeStrToInt64(str: [*c]const u8, kilo: c_uint) magick_int64_t; -pub extern fn MagickGetToken(start: [*c]const u8, end: [*c]([*c]u8), token: [*c]u8, buffer_length: usize) usize; -pub extern fn MagickStripSpacesFromString(string: [*c]u8) usize; -pub extern fn MagickStrlCat(dst: [*c]u8, src: [*c]const u8, size: usize) usize; -pub extern fn MagickStrlCpy(dst: [*c]u8, src: [*c]const u8, size: usize) usize; -pub extern fn MagickStrlCpyTrunc(dst: [*c]u8, src: [*c]const u8, size: usize) usize; -pub extern fn GetMagickCopyright() [*c]const u8; -pub extern fn GetMagickVersion(arg0: [*c]c_ulong) [*c]const u8; -pub extern fn GetMagickWebSite() [*c]const u8; -pub const struct__PixelWand = @OpaqueType(); -pub const PixelWand = struct__PixelWand; -pub extern fn PixelGetColorAsString(arg0: ?*const PixelWand) [*c]u8; -pub extern fn PixelGetBlack(arg0: ?*const PixelWand) f64; -pub extern fn PixelGetBlue(arg0: ?*const PixelWand) f64; -pub extern fn PixelGetCyan(arg0: ?*const PixelWand) f64; -pub extern fn PixelGetGreen(arg0: ?*const PixelWand) f64; -pub extern fn PixelGetMagenta(arg0: ?*const PixelWand) f64; -pub extern fn PixelGetOpacity(arg0: ?*const PixelWand) f64; -pub extern fn PixelGetRed(arg0: ?*const PixelWand) f64; -pub extern fn PixelGetYellow(arg0: ?*const PixelWand) f64; -pub extern fn ClonePixelWand(arg0: ?*const PixelWand) ?*PixelWand; -pub extern fn ClonePixelWands(arg0: [*c](?*const PixelWand), arg1: c_ulong) [*c](?*PixelWand); -pub extern fn NewPixelWand() ?*PixelWand; -pub extern fn NewPixelWands(arg0: c_ulong) [*c](?*PixelWand); -pub extern fn PixelGetBlackQuantum(arg0: ?*const PixelWand) Quantum; -pub extern fn PixelGetBlueQuantum(arg0: ?*const PixelWand) Quantum; -pub extern fn PixelGetCyanQuantum(arg0: ?*const PixelWand) Quantum; -pub extern fn PixelGetGreenQuantum(arg0: ?*const PixelWand) Quantum; -pub extern fn PixelGetMagentaQuantum(arg0: ?*const PixelWand) Quantum; -pub extern fn PixelGetOpacityQuantum(arg0: ?*const PixelWand) Quantum; -pub extern fn PixelGetRedQuantum(arg0: ?*const PixelWand) Quantum; -pub extern fn PixelGetYellowQuantum(arg0: ?*const PixelWand) Quantum; -pub extern fn PixelSetColor(arg0: ?*PixelWand, arg1: [*c]const u8) c_uint; -pub extern fn PixelGetColorCount(arg0: ?*const PixelWand) c_ulong; -pub extern fn DestroyPixelWand(arg0: ?*PixelWand) void; -pub extern fn PixelGetQuantumColor(arg0: ?*const PixelWand, arg1: [*c]PixelPacket) void; -pub extern fn PixelSetBlack(arg0: ?*PixelWand, arg1: f64) void; -pub extern fn PixelSetBlackQuantum(arg0: ?*PixelWand, arg1: Quantum) void; -pub extern fn PixelSetBlue(arg0: ?*PixelWand, arg1: f64) void; -pub extern fn PixelSetBlueQuantum(arg0: ?*PixelWand, arg1: Quantum) void; -pub extern fn PixelSetColorCount(arg0: ?*PixelWand, arg1: c_ulong) void; -pub extern fn PixelSetCyan(arg0: ?*PixelWand, arg1: f64) void; -pub extern fn PixelSetCyanQuantum(arg0: ?*PixelWand, arg1: Quantum) void; -pub extern fn PixelSetGreen(arg0: ?*PixelWand, arg1: f64) void; -pub extern fn PixelSetGreenQuantum(arg0: ?*PixelWand, arg1: Quantum) void; -pub extern fn PixelSetMagenta(arg0: ?*PixelWand, arg1: f64) void; -pub extern fn PixelSetMagentaQuantum(arg0: ?*PixelWand, arg1: Quantum) void; -pub extern fn PixelSetOpacity(arg0: ?*PixelWand, arg1: f64) void; -pub extern fn PixelSetOpacityQuantum(arg0: ?*PixelWand, arg1: Quantum) void; -pub extern fn PixelSetQuantumColor(arg0: ?*PixelWand, arg1: [*c]PixelPacket) void; -pub extern fn PixelSetRed(arg0: ?*PixelWand, arg1: f64) void; -pub extern fn PixelSetRedQuantum(arg0: ?*PixelWand, arg1: Quantum) void; -pub extern fn PixelSetYellow(arg0: ?*PixelWand, arg1: f64) void; -pub extern fn PixelSetYellowQuantum(arg0: ?*PixelWand, arg1: Quantum) void; -pub const struct__DrawingWand = @OpaqueType(); -pub const DrawingWand = struct__DrawingWand; -pub extern fn MagickDrawGetClipPath(arg0: ?*const DrawingWand) [*c]u8; -pub extern fn MagickDrawGetException(arg0: ?*const DrawingWand, arg1: [*c]ExceptionType) [*c]u8; -pub extern fn MagickDrawGetFont(arg0: ?*const DrawingWand) [*c]u8; -pub extern fn MagickDrawGetFontFamily(arg0: ?*const DrawingWand) [*c]u8; -pub extern fn MagickDrawGetTextEncoding(arg0: ?*const DrawingWand) [*c]u8; -pub extern fn MagickDrawGetClipUnits(arg0: ?*const DrawingWand) ClipPathUnits; -pub extern fn MagickDrawGetTextDecoration(arg0: ?*const DrawingWand) DecorationType; -pub extern fn MagickDrawGetFillOpacity(arg0: ?*const DrawingWand) f64; -pub extern fn MagickDrawGetFontSize(arg0: ?*const DrawingWand) f64; -pub extern fn MagickDrawGetStrokeDashArray(arg0: ?*const DrawingWand, arg1: [*c]c_ulong) [*c]f64; -pub extern fn MagickDrawGetStrokeDashOffset(arg0: ?*const DrawingWand) f64; -pub extern fn MagickDrawGetStrokeOpacity(arg0: ?*const DrawingWand) f64; -pub extern fn MagickDrawGetStrokeWidth(arg0: ?*const DrawingWand) f64; -pub extern fn MagickDrawPeekGraphicContext(arg0: ?*const DrawingWand) [*c]DrawInfo; -pub extern fn MagickCloneDrawingWand(drawing_wand: ?*const DrawingWand) ?*DrawingWand; -pub extern fn MagickDrawAllocateWand(arg0: [*c]const DrawInfo, arg1: [*c]Image) ?*DrawingWand; -pub extern fn MagickNewDrawingWand() ?*DrawingWand; -pub extern fn MagickDrawGetClipRule(arg0: ?*const DrawingWand) FillRule; -pub extern fn MagickDrawGetFillRule(arg0: ?*const DrawingWand) FillRule; -pub extern fn MagickDrawGetGravity(arg0: ?*const DrawingWand) GravityType; -pub extern fn MagickDrawGetStrokeLineCap(arg0: ?*const DrawingWand) LineCap; -pub extern fn MagickDrawGetStrokeLineJoin(arg0: ?*const DrawingWand) LineJoin; -pub extern fn MagickDrawGetFontStretch(arg0: ?*const DrawingWand) StretchType; -pub extern fn MagickDrawGetFontStyle(arg0: ?*const DrawingWand) StyleType; -pub extern fn MagickDrawClearException(arg0: ?*DrawingWand) c_uint; -pub extern fn MagickDrawGetStrokeAntialias(arg0: ?*const DrawingWand) c_uint; -pub extern fn MagickDrawGetTextAntialias(arg0: ?*const DrawingWand) c_uint; -pub extern fn MagickDrawRender(arg0: ?*const DrawingWand) c_uint; -pub extern fn MagickDrawGetFontWeight(arg0: ?*const DrawingWand) c_ulong; -pub extern fn MagickDrawGetStrokeMiterLimit(arg0: ?*const DrawingWand) c_ulong; -pub extern fn MagickDrawAffine(arg0: ?*DrawingWand, arg1: [*c]const AffineMatrix) void; -pub extern fn MagickDrawAnnotation(arg0: ?*DrawingWand, arg1: f64, arg2: f64, arg3: [*c]const u8) void; -pub extern fn MagickDrawArc(arg0: ?*DrawingWand, arg1: f64, arg2: f64, arg3: f64, arg4: f64, arg5: f64, arg6: f64) void; -pub extern fn MagickDrawBezier(arg0: ?*DrawingWand, arg1: c_ulong, arg2: [*c]const PointInfo) void; -pub extern fn MagickDrawCircle(arg0: ?*DrawingWand, arg1: f64, arg2: f64, arg3: f64, arg4: f64) void; -pub extern fn MagickDrawColor(arg0: ?*DrawingWand, arg1: f64, arg2: f64, arg3: PaintMethod) void; -pub extern fn MagickDrawComment(arg0: ?*DrawingWand, arg1: [*c]const u8) void; -pub extern fn MagickDestroyDrawingWand(arg0: ?*DrawingWand) void; -pub extern fn MagickDrawEllipse(arg0: ?*DrawingWand, arg1: f64, arg2: f64, arg3: f64, arg4: f64, arg5: f64, arg6: f64) void; -pub extern fn MagickDrawComposite(arg0: ?*DrawingWand, arg1: CompositeOperator, arg2: f64, arg3: f64, arg4: f64, arg5: f64, arg6: [*c]const Image) void; -pub extern fn MagickDrawGetFillColor(arg0: ?*const DrawingWand, arg1: ?*PixelWand) void; -pub extern fn MagickDrawGetStrokeColor(arg0: ?*const DrawingWand, arg1: ?*PixelWand) void; -pub extern fn MagickDrawGetTextUnderColor(arg0: ?*const DrawingWand, arg1: ?*PixelWand) void; -pub extern fn MagickDrawLine(arg0: ?*DrawingWand, arg1: f64, arg2: f64, arg3: f64, arg4: f64) void; -pub extern fn MagickDrawMatte(arg0: ?*DrawingWand, arg1: f64, arg2: f64, arg3: PaintMethod) void; -pub extern fn MagickDrawPathClose(arg0: ?*DrawingWand) void; -pub extern fn MagickDrawPathCurveToAbsolute(arg0: ?*DrawingWand, arg1: f64, arg2: f64, arg3: f64, arg4: f64, arg5: f64, arg6: f64) void; -pub extern fn MagickDrawPathCurveToRelative(arg0: ?*DrawingWand, arg1: f64, arg2: f64, arg3: f64, arg4: f64, arg5: f64, arg6: f64) void; -pub extern fn MagickDrawPathCurveToQuadraticBezierAbsolute(arg0: ?*DrawingWand, arg1: f64, arg2: f64, arg3: f64, arg4: f64) void; -pub extern fn MagickDrawPathCurveToQuadraticBezierRelative(arg0: ?*DrawingWand, arg1: f64, arg2: f64, arg3: f64, arg4: f64) void; -pub extern fn MagickDrawPathCurveToQuadraticBezierSmoothAbsolute(arg0: ?*DrawingWand, arg1: f64, arg2: f64) void; -pub extern fn MagickDrawPathCurveToQuadraticBezierSmoothRelative(arg0: ?*DrawingWand, arg1: f64, arg2: f64) void; -pub extern fn MagickDrawPathCurveToSmoothAbsolute(arg0: ?*DrawingWand, arg1: f64, arg2: f64, arg3: f64, arg4: f64) void; -pub extern fn MagickDrawPathCurveToSmoothRelative(arg0: ?*DrawingWand, arg1: f64, arg2: f64, arg3: f64, arg4: f64) void; -pub extern fn MagickDrawPathEllipticArcAbsolute(arg0: ?*DrawingWand, arg1: f64, arg2: f64, arg3: f64, arg4: c_uint, arg5: c_uint, arg6: f64, arg7: f64) void; -pub extern fn MagickDrawPathEllipticArcRelative(arg0: ?*DrawingWand, arg1: f64, arg2: f64, arg3: f64, arg4: c_uint, arg5: c_uint, arg6: f64, arg7: f64) void; -pub extern fn MagickDrawPathFinish(arg0: ?*DrawingWand) void; -pub extern fn MagickDrawPathLineToAbsolute(arg0: ?*DrawingWand, arg1: f64, arg2: f64) void; -pub extern fn MagickDrawPathLineToRelative(arg0: ?*DrawingWand, arg1: f64, arg2: f64) void; -pub extern fn MagickDrawPathLineToHorizontalAbsolute(arg0: ?*DrawingWand, arg1: f64) void; -pub extern fn MagickDrawPathLineToHorizontalRelative(arg0: ?*DrawingWand, arg1: f64) void; -pub extern fn MagickDrawPathLineToVerticalAbsolute(arg0: ?*DrawingWand, arg1: f64) void; -pub extern fn MagickDrawPathLineToVerticalRelative(arg0: ?*DrawingWand, arg1: f64) void; -pub extern fn MagickDrawPathMoveToAbsolute(arg0: ?*DrawingWand, arg1: f64, arg2: f64) void; -pub extern fn MagickDrawPathMoveToRelative(arg0: ?*DrawingWand, arg1: f64, arg2: f64) void; -pub extern fn MagickDrawPathStart(arg0: ?*DrawingWand) void; -pub extern fn MagickDrawPoint(arg0: ?*DrawingWand, arg1: f64, arg2: f64) void; -pub extern fn MagickDrawPolygon(arg0: ?*DrawingWand, arg1: c_ulong, arg2: [*c]const PointInfo) void; -pub extern fn MagickDrawPolyline(arg0: ?*DrawingWand, arg1: c_ulong, arg2: [*c]const PointInfo) void; -pub extern fn MagickDrawPopClipPath(arg0: ?*DrawingWand) void; -pub extern fn MagickDrawPopDefs(arg0: ?*DrawingWand) void; -pub extern fn MagickDrawPopGraphicContext(arg0: ?*DrawingWand) void; -pub extern fn MagickDrawPopPattern(arg0: ?*DrawingWand) void; -pub extern fn MagickDrawPushClipPath(arg0: ?*DrawingWand, arg1: [*c]const u8) void; -pub extern fn MagickDrawPushDefs(arg0: ?*DrawingWand) void; -pub extern fn MagickDrawPushGraphicContext(arg0: ?*DrawingWand) void; -pub extern fn MagickDrawPushPattern(arg0: ?*DrawingWand, arg1: [*c]const u8, arg2: f64, arg3: f64, arg4: f64, arg5: f64) void; -pub extern fn MagickDrawRectangle(arg0: ?*DrawingWand, arg1: f64, arg2: f64, arg3: f64, arg4: f64) void; -pub extern fn MagickDrawRotate(arg0: ?*DrawingWand, arg1: f64) void; -pub extern fn MagickDrawRoundRectangle(arg0: ?*DrawingWand, arg1: f64, arg2: f64, arg3: f64, arg4: f64, arg5: f64, arg6: f64) void; -pub extern fn MagickDrawScale(arg0: ?*DrawingWand, arg1: f64, arg2: f64) void; -pub extern fn MagickDrawSetClipPath(arg0: ?*DrawingWand, arg1: [*c]const u8) void; -pub extern fn MagickDrawSetClipRule(arg0: ?*DrawingWand, arg1: FillRule) void; -pub extern fn MagickDrawSetClipUnits(arg0: ?*DrawingWand, arg1: ClipPathUnits) void; -pub extern fn MagickDrawSetFillColor(arg0: ?*DrawingWand, arg1: ?*const PixelWand) void; -pub extern fn MagickDrawSetFillOpacity(arg0: ?*DrawingWand, arg1: f64) void; -pub extern fn MagickDrawSetFillRule(arg0: ?*DrawingWand, arg1: FillRule) void; -pub extern fn MagickDrawSetFillPatternURL(arg0: ?*DrawingWand, arg1: [*c]const u8) void; -pub extern fn MagickDrawSetFont(arg0: ?*DrawingWand, arg1: [*c]const u8) void; -pub extern fn MagickDrawSetFontFamily(arg0: ?*DrawingWand, arg1: [*c]const u8) void; -pub extern fn MagickDrawSetFontSize(arg0: ?*DrawingWand, arg1: f64) void; -pub extern fn MagickDrawSetFontStretch(arg0: ?*DrawingWand, arg1: StretchType) void; -pub extern fn MagickDrawSetFontStyle(arg0: ?*DrawingWand, arg1: StyleType) void; -pub extern fn MagickDrawSetFontWeight(arg0: ?*DrawingWand, arg1: c_ulong) void; -pub extern fn MagickDrawSetGravity(arg0: ?*DrawingWand, arg1: GravityType) void; -pub extern fn MagickDrawSkewX(arg0: ?*DrawingWand, arg1: f64) void; -pub extern fn MagickDrawSkewY(arg0: ?*DrawingWand, arg1: f64) void; -pub extern fn MagickDrawSetStrokeAntialias(arg0: ?*DrawingWand, arg1: c_uint) void; -pub extern fn MagickDrawSetStrokeColor(arg0: ?*DrawingWand, arg1: ?*const PixelWand) void; -pub extern fn MagickDrawSetStrokeDashArray(arg0: ?*DrawingWand, arg1: c_ulong, arg2: [*c]const f64) void; -pub extern fn MagickDrawSetStrokeDashOffset(arg0: ?*DrawingWand, dashoffset: f64) void; -pub extern fn MagickDrawSetStrokeLineCap(arg0: ?*DrawingWand, arg1: LineCap) void; -pub extern fn MagickDrawSetStrokeLineJoin(arg0: ?*DrawingWand, arg1: LineJoin) void; -pub extern fn MagickDrawSetStrokeMiterLimit(arg0: ?*DrawingWand, arg1: c_ulong) void; -pub extern fn MagickDrawSetStrokeOpacity(arg0: ?*DrawingWand, arg1: f64) void; -pub extern fn MagickDrawSetStrokePatternURL(arg0: ?*DrawingWand, arg1: [*c]const u8) void; -pub extern fn MagickDrawSetStrokeWidth(arg0: ?*DrawingWand, arg1: f64) void; -pub extern fn MagickDrawSetTextAntialias(arg0: ?*DrawingWand, arg1: c_uint) void; -pub extern fn MagickDrawSetTextDecoration(arg0: ?*DrawingWand, arg1: DecorationType) void; -pub extern fn MagickDrawSetTextEncoding(arg0: ?*DrawingWand, arg1: [*c]const u8) void; -pub extern fn MagickDrawSetTextUnderColor(arg0: ?*DrawingWand, arg1: ?*const PixelWand) void; -pub extern fn MagickDrawSetViewbox(arg0: ?*DrawingWand, arg1: c_ulong, arg2: c_ulong, arg3: c_ulong, arg4: c_ulong) void; -pub extern fn MagickDrawTranslate(arg0: ?*DrawingWand, arg1: f64, arg2: f64) void; -pub extern fn FormatMagickString(arg0: [*c]u8, arg1: usize, arg2: [*c]const u8, ...) c_int; -pub extern fn CopyMagickString(arg0: [*c]u8, arg1: [*c]const u8, arg2: usize) usize; -pub const struct__MagickWand = @OpaqueType(); -pub const MagickWand = struct__MagickWand; -pub extern fn MagickDescribeImage(arg0: ?*MagickWand) [*c]u8; -pub extern fn MagickGetConfigureInfo(arg0: ?*MagickWand, arg1: [*c]const u8) [*c]u8; -pub extern fn MagickGetException(arg0: ?*const MagickWand, arg1: [*c]ExceptionType) [*c]u8; -pub extern fn MagickGetFilename(arg0: ?*const MagickWand) [*c]u8; -pub extern fn MagickGetImageAttribute(arg0: ?*MagickWand, arg1: [*c]const u8) [*c]u8; -pub extern fn MagickGetImageFilename(arg0: ?*MagickWand) [*c]u8; -pub extern fn MagickGetImageFormat(arg0: ?*MagickWand) [*c]u8; -pub extern fn MagickGetImageSignature(arg0: ?*MagickWand) [*c]u8; -pub extern fn MagickQueryFonts(arg0: [*c]const u8, arg1: [*c]c_ulong) [*c]([*c]u8); -pub extern fn MagickQueryFormats(arg0: [*c]const u8, arg1: [*c]c_ulong) [*c]([*c]u8); -pub extern fn MagickGetImageCompose(arg0: ?*MagickWand) CompositeOperator; -pub extern fn MagickGetImageColorspace(arg0: ?*MagickWand) ColorspaceType; -pub extern fn MagickGetImageCompression(arg0: ?*MagickWand) CompressionType; -pub extern fn MagickGetCopyright() [*c]const u8; -pub extern fn MagickGetHomeURL() [*c]const u8; -pub extern fn MagickGetImageGeometry(arg0: ?*MagickWand) [*c]const u8; -pub extern fn MagickGetPackageName() [*c]const u8; -pub extern fn MagickGetQuantumDepth(arg0: [*c]c_ulong) [*c]const u8; -pub extern fn MagickGetReleaseDate() [*c]const u8; -pub extern fn MagickGetVersion(arg0: [*c]c_ulong) [*c]const u8; -pub extern fn MagickGetImageDispose(arg0: ?*MagickWand) DisposeType; -pub extern fn MagickGetImageGamma(arg0: ?*MagickWand) f64; -pub extern fn MagickGetImageFuzz(arg0: ?*MagickWand) f64; -pub extern fn MagickGetSamplingFactors(arg0: ?*MagickWand, arg1: [*c]c_ulong) [*c]f64; -pub extern fn MagickQueryFontMetrics(arg0: ?*MagickWand, arg1: ?*const DrawingWand, arg2: [*c]const u8) [*c]f64; -pub extern fn MagickGetImageGravity(wand: ?*MagickWand) GravityType; -pub extern fn MagickGetImageType(arg0: ?*MagickWand) ImageType; -pub extern fn MagickGetImageSavedType(arg0: ?*MagickWand) ImageType; -pub extern fn MagickGetImageInterlaceScheme(arg0: ?*MagickWand) InterlaceType; -pub extern fn MagickGetImageIndex(arg0: ?*MagickWand) c_long; -pub extern fn MagickGetImageSize(arg0: ?*MagickWand) magick_int64_t; -pub extern fn CloneMagickWand(arg0: ?*const MagickWand) ?*MagickWand; -pub extern fn MagickAppendImages(arg0: ?*MagickWand, arg1: c_uint) ?*MagickWand; -pub extern fn MagickAverageImages(arg0: ?*MagickWand) ?*MagickWand; -pub extern fn MagickCoalesceImages(arg0: ?*MagickWand) ?*MagickWand; -pub extern fn MagickCompareImageChannels(arg0: ?*MagickWand, arg1: ?*const MagickWand, arg2: ChannelType, arg3: MetricType, arg4: [*c]f64) ?*MagickWand; -pub extern fn MagickCompareImages(arg0: ?*MagickWand, arg1: ?*const MagickWand, arg2: MetricType, arg3: [*c]f64) ?*MagickWand; -pub extern fn MagickDeconstructImages(arg0: ?*MagickWand) ?*MagickWand; -pub extern fn MagickFlattenImages(arg0: ?*MagickWand) ?*MagickWand; -pub extern fn MagickFxImage(arg0: ?*MagickWand, arg1: [*c]const u8) ?*MagickWand; -pub extern fn MagickFxImageChannel(arg0: ?*MagickWand, arg1: ChannelType, arg2: [*c]const u8) ?*MagickWand; -pub extern fn MagickGetImage(arg0: ?*MagickWand) ?*MagickWand; -pub extern fn MagickMorphImages(arg0: ?*MagickWand, arg1: c_ulong) ?*MagickWand; -pub extern fn MagickMosaicImages(arg0: ?*MagickWand) ?*MagickWand; -pub extern fn MagickMontageImage(arg0: ?*MagickWand, arg1: ?*const DrawingWand, arg2: [*c]const u8, arg3: [*c]const u8, arg4: MontageMode, arg5: [*c]const u8) ?*MagickWand; -pub extern fn MagickPreviewImages(wand: ?*MagickWand, arg1: PreviewType) ?*MagickWand; -pub extern fn MagickSteganoImage(arg0: ?*MagickWand, arg1: ?*const MagickWand, arg2: c_long) ?*MagickWand; -pub extern fn MagickStereoImage(arg0: ?*MagickWand, arg1: ?*const MagickWand) ?*MagickWand; -pub extern fn MagickTextureImage(arg0: ?*MagickWand, arg1: ?*const MagickWand) ?*MagickWand; -pub extern fn MagickTransformImage(arg0: ?*MagickWand, arg1: [*c]const u8, arg2: [*c]const u8) ?*MagickWand; -pub extern fn NewMagickWand() ?*MagickWand; -pub extern fn MagickGetImageOrientation(arg0: ?*MagickWand) OrientationType; -pub extern fn MagickGetImageHistogram(arg0: ?*MagickWand, arg1: [*c]c_ulong) [*c](?*PixelWand); -pub extern fn MagickGetImageRenderingIntent(arg0: ?*MagickWand) RenderingIntent; -pub extern fn MagickGetImageUnits(arg0: ?*MagickWand) ResolutionType; -pub extern fn DestroyMagickWand(arg0: ?*MagickWand) c_uint; -pub extern fn MagickAdaptiveThresholdImage(arg0: ?*MagickWand, arg1: c_ulong, arg2: c_ulong, arg3: c_long) c_uint; -pub extern fn MagickAddImage(arg0: ?*MagickWand, arg1: ?*const MagickWand) c_uint; -pub extern fn MagickAddNoiseImage(arg0: ?*MagickWand, arg1: NoiseType) c_uint; -pub extern fn MagickAffineTransformImage(arg0: ?*MagickWand, arg1: ?*const DrawingWand) c_uint; -pub extern fn MagickAnnotateImage(arg0: ?*MagickWand, arg1: ?*const DrawingWand, arg2: f64, arg3: f64, arg4: f64, arg5: [*c]const u8) c_uint; -pub extern fn MagickAnimateImages(arg0: ?*MagickWand, arg1: [*c]const u8) c_uint; -pub extern fn MagickAutoOrientImage(wand: ?*MagickWand, arg1: OrientationType) c_uint; -pub extern fn MagickBlackThresholdImage(arg0: ?*MagickWand, arg1: ?*const PixelWand) c_uint; -pub extern fn MagickBlurImage(arg0: ?*MagickWand, arg1: f64, arg2: f64) c_uint; -pub extern fn MagickBorderImage(arg0: ?*MagickWand, arg1: ?*const PixelWand, arg2: c_ulong, arg3: c_ulong) c_uint; -pub extern fn MagickCdlImage(wand: ?*MagickWand, cdl: [*c]const u8) c_uint; -pub extern fn MagickCharcoalImage(arg0: ?*MagickWand, arg1: f64, arg2: f64) c_uint; -pub extern fn MagickChopImage(arg0: ?*MagickWand, arg1: c_ulong, arg2: c_ulong, arg3: c_long, arg4: c_long) c_uint; -pub extern fn MagickClipImage(arg0: ?*MagickWand) c_uint; -pub extern fn MagickClipPathImage(arg0: ?*MagickWand, arg1: [*c]const u8, arg2: c_uint) c_uint; -pub extern fn MagickColorFloodfillImage(arg0: ?*MagickWand, arg1: ?*const PixelWand, arg2: f64, arg3: ?*const PixelWand, arg4: c_long, arg5: c_long) c_uint; -pub extern fn MagickColorizeImage(arg0: ?*MagickWand, arg1: ?*const PixelWand, arg2: ?*const PixelWand) c_uint; -pub extern fn MagickCommentImage(arg0: ?*MagickWand, arg1: [*c]const u8) c_uint; -pub extern fn MagickCompositeImage(arg0: ?*MagickWand, arg1: ?*const MagickWand, arg2: CompositeOperator, arg3: c_long, arg4: c_long) c_uint; -pub extern fn MagickContrastImage(arg0: ?*MagickWand, arg1: c_uint) c_uint; -pub extern fn MagickConvolveImage(arg0: ?*MagickWand, arg1: c_ulong, arg2: [*c]const f64) c_uint; -pub extern fn MagickCropImage(arg0: ?*MagickWand, arg1: c_ulong, arg2: c_ulong, arg3: c_long, arg4: c_long) c_uint; -pub extern fn MagickCycleColormapImage(arg0: ?*MagickWand, arg1: c_long) c_uint; -pub extern fn MagickDespeckleImage(arg0: ?*MagickWand) c_uint; -pub extern fn MagickDisplayImage(arg0: ?*MagickWand, arg1: [*c]const u8) c_uint; -pub extern fn MagickDisplayImages(arg0: ?*MagickWand, arg1: [*c]const u8) c_uint; -pub extern fn MagickDrawImage(arg0: ?*MagickWand, arg1: ?*const DrawingWand) c_uint; -pub extern fn MagickEdgeImage(arg0: ?*MagickWand, arg1: f64) c_uint; -pub extern fn MagickEmbossImage(arg0: ?*MagickWand, arg1: f64, arg2: f64) c_uint; -pub extern fn MagickEnhanceImage(arg0: ?*MagickWand) c_uint; -pub extern fn MagickEqualizeImage(arg0: ?*MagickWand) c_uint; -pub extern fn MagickExtentImage(arg0: ?*MagickWand, arg1: usize, arg2: usize, arg3: isize, arg4: isize) c_uint; -pub extern fn MagickFlipImage(arg0: ?*MagickWand) c_uint; -pub extern fn MagickFlopImage(arg0: ?*MagickWand) c_uint; -pub extern fn MagickFrameImage(arg0: ?*MagickWand, arg1: ?*const PixelWand, arg2: c_ulong, arg3: c_ulong, arg4: c_long, arg5: c_long) c_uint; -pub extern fn MagickGammaImage(arg0: ?*MagickWand, arg1: f64) c_uint; -pub extern fn MagickGammaImageChannel(arg0: ?*MagickWand, arg1: ChannelType, arg2: f64) c_uint; -pub extern fn MagickGetImageBackgroundColor(arg0: ?*MagickWand, arg1: ?*PixelWand) c_uint; -pub extern fn MagickGetImageBluePrimary(arg0: ?*MagickWand, arg1: [*c]f64, arg2: [*c]f64) c_uint; -pub extern fn MagickGetImageBorderColor(arg0: ?*MagickWand, arg1: ?*PixelWand) c_uint; -pub extern fn MagickGetImageBoundingBox(wand: ?*MagickWand, fuzz: f64, width: [*c]c_ulong, height: [*c]c_ulong, x: [*c]c_long, y: [*c]c_long) c_uint; -pub extern fn MagickGetImageChannelExtrema(arg0: ?*MagickWand, arg1: ChannelType, arg2: [*c]c_ulong, arg3: [*c]c_ulong) c_uint; -pub extern fn MagickGetImageChannelMean(arg0: ?*MagickWand, arg1: ChannelType, arg2: [*c]f64, arg3: [*c]f64) c_uint; -pub extern fn MagickGetImageColormapColor(arg0: ?*MagickWand, arg1: c_ulong, arg2: ?*PixelWand) c_uint; -pub extern fn MagickGetImageExtrema(arg0: ?*MagickWand, arg1: [*c]c_ulong, arg2: [*c]c_ulong) c_uint; -pub extern fn MagickGetImageGreenPrimary(arg0: ?*MagickWand, arg1: [*c]f64, arg2: [*c]f64) c_uint; -pub extern fn MagickGetImageMatte(arg0: ?*MagickWand) c_uint; -pub extern fn MagickGetImageMatteColor(arg0: ?*MagickWand, arg1: ?*PixelWand) c_uint; -pub extern fn MagickGetImagePage(wand: ?*MagickWand, width: [*c]c_ulong, height: [*c]c_ulong, x: [*c]c_long, y: [*c]c_long) c_uint; -pub extern fn MagickGetImagePixels(arg0: ?*MagickWand, arg1: c_long, arg2: c_long, arg3: c_ulong, arg4: c_ulong, arg5: [*c]const u8, arg6: StorageType, arg7: [*c]u8) c_uint; -pub extern fn MagickGetImageRedPrimary(arg0: ?*MagickWand, arg1: [*c]f64, arg2: [*c]f64) c_uint; -pub extern fn MagickGetImageResolution(arg0: ?*MagickWand, arg1: [*c]f64, arg2: [*c]f64) c_uint; -pub extern fn MagickGetImageWhitePoint(arg0: ?*MagickWand, arg1: [*c]f64, arg2: [*c]f64) c_uint; -pub extern fn MagickGetSize(arg0: ?*const MagickWand, arg1: [*c]c_ulong, arg2: [*c]c_ulong) c_uint; -pub extern fn MagickHaldClutImage(wand: ?*MagickWand, clut_wand: ?*const MagickWand) c_uint; -pub extern fn MagickHasColormap(arg0: ?*MagickWand, arg1: [*c]c_uint) c_uint; -pub extern fn MagickHasNextImage(arg0: ?*MagickWand) c_uint; -pub extern fn MagickHasPreviousImage(arg0: ?*MagickWand) c_uint; -pub extern fn MagickImplodeImage(arg0: ?*MagickWand, arg1: f64) c_uint; -pub extern fn MagickIsGrayImage(arg0: ?*MagickWand, arg1: [*c]c_uint) c_uint; -pub extern fn MagickIsMonochromeImage(arg0: ?*MagickWand, arg1: [*c]c_uint) c_uint; -pub extern fn MagickIsOpaqueImage(arg0: ?*MagickWand, arg1: [*c]c_uint) c_uint; -pub extern fn MagickIsPaletteImage(arg0: ?*MagickWand, arg1: [*c]c_uint) c_uint; -pub extern fn MagickLabelImage(arg0: ?*MagickWand, arg1: [*c]const u8) c_uint; -pub extern fn MagickLevelImage(arg0: ?*MagickWand, arg1: f64, arg2: f64, arg3: f64) c_uint; -pub extern fn MagickLevelImageChannel(arg0: ?*MagickWand, arg1: ChannelType, arg2: f64, arg3: f64, arg4: f64) c_uint; -pub extern fn MagickMagnifyImage(arg0: ?*MagickWand) c_uint; -pub extern fn MagickMapImage(arg0: ?*MagickWand, arg1: ?*const MagickWand, arg2: c_uint) c_uint; -pub extern fn MagickMatteFloodfillImage(arg0: ?*MagickWand, arg1: Quantum, arg2: f64, arg3: ?*const PixelWand, arg4: c_long, arg5: c_long) c_uint; -pub extern fn MagickMedianFilterImage(arg0: ?*MagickWand, arg1: f64) c_uint; -pub extern fn MagickMinifyImage(arg0: ?*MagickWand) c_uint; -pub extern fn MagickModulateImage(arg0: ?*MagickWand, arg1: f64, arg2: f64, arg3: f64) c_uint; -pub extern fn MagickMotionBlurImage(arg0: ?*MagickWand, arg1: f64, arg2: f64, arg3: f64) c_uint; -pub extern fn MagickNegateImage(arg0: ?*MagickWand, arg1: c_uint) c_uint; -pub extern fn MagickNegateImageChannel(arg0: ?*MagickWand, arg1: ChannelType, arg2: c_uint) c_uint; -pub extern fn MagickNextImage(arg0: ?*MagickWand) c_uint; -pub extern fn MagickNormalizeImage(arg0: ?*MagickWand) c_uint; -pub extern fn MagickOilPaintImage(arg0: ?*MagickWand, arg1: f64) c_uint; -pub extern fn MagickOpaqueImage(arg0: ?*MagickWand, arg1: ?*const PixelWand, arg2: ?*const PixelWand, arg3: f64) c_uint; -pub extern fn MagickOperatorImageChannel(arg0: ?*MagickWand, arg1: ChannelType, arg2: QuantumOperator, arg3: f64) c_uint; -pub extern fn MagickPingImage(arg0: ?*MagickWand, arg1: [*c]const u8) c_uint; -pub extern fn MagickPreviousImage(arg0: ?*MagickWand) c_uint; -pub extern fn MagickProfileImage(arg0: ?*MagickWand, arg1: [*c]const u8, arg2: [*c]const u8, arg3: c_ulong) c_uint; -pub extern fn MagickQuantizeImage(arg0: ?*MagickWand, arg1: c_ulong, arg2: ColorspaceType, arg3: c_ulong, arg4: c_uint, arg5: c_uint) c_uint; -pub extern fn MagickQuantizeImages(arg0: ?*MagickWand, arg1: c_ulong, arg2: ColorspaceType, arg3: c_ulong, arg4: c_uint, arg5: c_uint) c_uint; -pub extern fn MagickRadialBlurImage(arg0: ?*MagickWand, arg1: f64) c_uint; -pub extern fn MagickRaiseImage(arg0: ?*MagickWand, arg1: c_ulong, arg2: c_ulong, arg3: c_long, arg4: c_long, arg5: c_uint) c_uint; -pub extern fn MagickReadImage(arg0: ?*MagickWand, arg1: [*c]const u8) c_uint; -pub extern fn MagickReadImageBlob(arg0: ?*MagickWand, arg1: [*c]const u8, length: usize) c_uint; -pub extern fn MagickReadImageFile(arg0: ?*MagickWand, arg1: [*c]FILE) c_uint; -pub extern fn MagickReduceNoiseImage(arg0: ?*MagickWand, arg1: f64) c_uint; -pub extern fn MagickRelinquishMemory(arg0: ?*c_void) c_uint; -pub extern fn MagickRemoveImage(arg0: ?*MagickWand) c_uint; -pub extern fn MagickRemoveImageOption(wand: ?*MagickWand, arg1: [*c]const u8, arg2: [*c]const u8) c_uint; -pub extern fn MagickResampleImage(arg0: ?*MagickWand, arg1: f64, arg2: f64, arg3: FilterTypes, arg4: f64) c_uint; -pub extern fn MagickResizeImage(arg0: ?*MagickWand, arg1: c_ulong, arg2: c_ulong, arg3: FilterTypes, arg4: f64) c_uint; -pub extern fn MagickRollImage(arg0: ?*MagickWand, arg1: c_long, arg2: c_long) c_uint; -pub extern fn MagickRotateImage(arg0: ?*MagickWand, arg1: ?*const PixelWand, arg2: f64) c_uint; -pub extern fn MagickSampleImage(arg0: ?*MagickWand, arg1: c_ulong, arg2: c_ulong) c_uint; -pub extern fn MagickScaleImage(arg0: ?*MagickWand, arg1: c_ulong, arg2: c_ulong) c_uint; -pub extern fn MagickSeparateImageChannel(arg0: ?*MagickWand, arg1: ChannelType) c_uint; -pub extern fn MagickSetCompressionQuality(wand: ?*MagickWand, quality: c_ulong) c_uint; -pub extern fn MagickSetFilename(arg0: ?*MagickWand, arg1: [*c]const u8) c_uint; -pub extern fn MagickSetFormat(arg0: ?*MagickWand, arg1: [*c]const u8) c_uint; -pub extern fn MagickSetImage(arg0: ?*MagickWand, arg1: ?*const MagickWand) c_uint; -pub extern fn MagickSetImageAttribute(arg0: ?*MagickWand, arg1: [*c]const u8, arg2: [*c]const u8) c_uint; -pub extern fn MagickSetImageBackgroundColor(arg0: ?*MagickWand, arg1: ?*const PixelWand) c_uint; -pub extern fn MagickSetImageBluePrimary(arg0: ?*MagickWand, arg1: f64, arg2: f64) c_uint; -pub extern fn MagickSetImageBorderColor(arg0: ?*MagickWand, arg1: ?*const PixelWand) c_uint; -pub extern fn MagickSetImageChannelDepth(arg0: ?*MagickWand, arg1: ChannelType, arg2: c_ulong) c_uint; -pub extern fn MagickSetImageColormapColor(arg0: ?*MagickWand, arg1: c_ulong, arg2: ?*const PixelWand) c_uint; -pub extern fn MagickSetImageCompose(arg0: ?*MagickWand, arg1: CompositeOperator) c_uint; -pub extern fn MagickSetImageCompression(arg0: ?*MagickWand, arg1: CompressionType) c_uint; -pub extern fn MagickSetImageDelay(arg0: ?*MagickWand, arg1: c_ulong) c_uint; -pub extern fn MagickSetImageDepth(arg0: ?*MagickWand, arg1: c_ulong) c_uint; -pub extern fn MagickSetImageDispose(arg0: ?*MagickWand, arg1: DisposeType) c_uint; -pub extern fn MagickSetImageColorspace(arg0: ?*MagickWand, arg1: ColorspaceType) c_uint; -pub extern fn MagickSetImageGreenPrimary(arg0: ?*MagickWand, arg1: f64, arg2: f64) c_uint; -pub extern fn MagickSetImageGamma(arg0: ?*MagickWand, arg1: f64) c_uint; -pub extern fn MagickSetImageGeometry(arg0: ?*MagickWand, arg1: [*c]const u8) c_uint; -pub extern fn MagickSetImageGravity(arg0: ?*MagickWand, arg1: GravityType) c_uint; -pub extern fn MagickSetImageFilename(arg0: ?*MagickWand, arg1: [*c]const u8) c_uint; -pub extern fn MagickSetImageFormat(wand: ?*MagickWand, format: [*c]const u8) c_uint; -pub extern fn MagickSetImageFuzz(arg0: ?*MagickWand, arg1: f64) c_uint; -pub extern fn MagickSetImageIndex(arg0: ?*MagickWand, arg1: c_long) c_uint; -pub extern fn MagickSetImageInterlaceScheme(arg0: ?*MagickWand, arg1: InterlaceType) c_uint; -pub extern fn MagickSetImageIterations(arg0: ?*MagickWand, arg1: c_ulong) c_uint; -pub extern fn MagickSetImageMatte(arg0: ?*MagickWand, arg1: c_uint) c_uint; -pub extern fn MagickSetImageMatteColor(arg0: ?*MagickWand, arg1: ?*const PixelWand) c_uint; -pub extern fn MagickSetImageOption(arg0: ?*MagickWand, arg1: [*c]const u8, arg2: [*c]const u8, arg3: [*c]const u8) c_uint; -pub extern fn MagickSetImageOrientation(arg0: ?*MagickWand, arg1: OrientationType) c_uint; -pub extern fn MagickSetImagePage(wand: ?*MagickWand, width: c_ulong, height: c_ulong, x: c_long, y: c_long) c_uint; -pub extern fn MagickSetImagePixels(arg0: ?*MagickWand, arg1: c_long, arg2: c_long, arg3: c_ulong, arg4: c_ulong, arg5: [*c]const u8, arg6: StorageType, arg7: [*c]u8) c_uint; -pub extern fn MagickSetImageRedPrimary(arg0: ?*MagickWand, arg1: f64, arg2: f64) c_uint; -pub extern fn MagickSetImageRenderingIntent(arg0: ?*MagickWand, arg1: RenderingIntent) c_uint; -pub extern fn MagickSetImageResolution(arg0: ?*MagickWand, arg1: f64, arg2: f64) c_uint; -pub extern fn MagickSetImageScene(arg0: ?*MagickWand, arg1: c_ulong) c_uint; -pub extern fn MagickSetImageType(arg0: ?*MagickWand, arg1: ImageType) c_uint; -pub extern fn MagickSetImageSavedType(arg0: ?*MagickWand, arg1: ImageType) c_uint; -pub extern fn MagickSetImageUnits(arg0: ?*MagickWand, arg1: ResolutionType) c_uint; -pub extern fn MagickSetImageVirtualPixelMethod(arg0: ?*MagickWand, arg1: VirtualPixelMethod) c_uint; -pub extern fn MagickSetPassphrase(arg0: ?*MagickWand, arg1: [*c]const u8) c_uint; -pub extern fn MagickSetImageProfile(arg0: ?*MagickWand, arg1: [*c]const u8, arg2: [*c]const u8, arg3: c_ulong) c_uint; -pub extern fn MagickSetResolution(wand: ?*MagickWand, x_resolution: f64, y_resolution: f64) c_uint; -pub extern fn MagickSetResolutionUnits(wand: ?*MagickWand, units: ResolutionType) c_uint; -pub extern fn MagickSetResourceLimit(type_0: ResourceType, limit: c_ulong) c_uint; -pub extern fn MagickSetSamplingFactors(arg0: ?*MagickWand, arg1: c_ulong, arg2: [*c]const f64) c_uint; -pub extern fn MagickSetSize(arg0: ?*MagickWand, arg1: c_ulong, arg2: c_ulong) c_uint; -pub extern fn MagickSetImageWhitePoint(arg0: ?*MagickWand, arg1: f64, arg2: f64) c_uint; -pub extern fn MagickSetInterlaceScheme(arg0: ?*MagickWand, arg1: InterlaceType) c_uint; -pub extern fn MagickSharpenImage(arg0: ?*MagickWand, arg1: f64, arg2: f64) c_uint; -pub extern fn MagickShaveImage(arg0: ?*MagickWand, arg1: c_ulong, arg2: c_ulong) c_uint; -pub extern fn MagickShearImage(arg0: ?*MagickWand, arg1: ?*const PixelWand, arg2: f64, arg3: f64) c_uint; -pub extern fn MagickSolarizeImage(arg0: ?*MagickWand, arg1: f64) c_uint; -pub extern fn MagickSpreadImage(arg0: ?*MagickWand, arg1: f64) c_uint; -pub extern fn MagickStripImage(arg0: ?*MagickWand) c_uint; -pub extern fn MagickSwirlImage(arg0: ?*MagickWand, arg1: f64) c_uint; -pub extern fn MagickTintImage(arg0: ?*MagickWand, arg1: ?*const PixelWand, arg2: ?*const PixelWand) c_uint; -pub extern fn MagickThresholdImage(arg0: ?*MagickWand, arg1: f64) c_uint; -pub extern fn MagickThresholdImageChannel(arg0: ?*MagickWand, arg1: ChannelType, arg2: f64) c_uint; -pub extern fn MagickTransparentImage(arg0: ?*MagickWand, arg1: ?*const PixelWand, arg2: Quantum, arg3: f64) c_uint; -pub extern fn MagickTrimImage(arg0: ?*MagickWand, arg1: f64) c_uint; -pub extern fn MagickUnsharpMaskImage(arg0: ?*MagickWand, arg1: f64, arg2: f64, arg3: f64, arg4: f64) c_uint; -pub extern fn MagickWaveImage(arg0: ?*MagickWand, arg1: f64, arg2: f64) c_uint; -pub extern fn MagickWhiteThresholdImage(arg0: ?*MagickWand, arg1: ?*const PixelWand) c_uint; -pub extern fn MagickWriteImage(arg0: ?*MagickWand, arg1: [*c]const u8) c_uint; -pub extern fn MagickWriteImageFile(arg0: ?*MagickWand, arg1: [*c]FILE) c_uint; -pub extern fn MagickWriteImagesFile(arg0: ?*MagickWand, arg1: [*c]FILE, arg2: c_uint) c_uint; -pub extern fn MagickWriteImages(arg0: ?*MagickWand, arg1: [*c]const u8, arg2: c_uint) c_uint; -pub extern fn MagickGetImageColors(arg0: ?*MagickWand) c_ulong; -pub extern fn MagickGetImageDelay(arg0: ?*MagickWand) c_ulong; -pub extern fn MagickGetImageChannelDepth(arg0: ?*MagickWand, arg1: ChannelType) c_ulong; -pub extern fn MagickGetImageDepth(arg0: ?*MagickWand) c_ulong; -pub extern fn MagickGetImageHeight(arg0: ?*MagickWand) c_ulong; -pub extern fn MagickGetImageIterations(arg0: ?*MagickWand) c_ulong; -pub extern fn MagickGetImageScene(arg0: ?*MagickWand) c_ulong; -pub extern fn MagickGetImageWidth(arg0: ?*MagickWand) c_ulong; -pub extern fn MagickGetNumberImages(arg0: ?*MagickWand) c_ulong; -pub extern fn MagickGetResourceLimit(arg0: ResourceType) c_ulong; -pub extern fn MagickGetImageVirtualPixelMethod(arg0: ?*MagickWand) VirtualPixelMethod; -pub extern fn MagickGetImageProfile(arg0: ?*MagickWand, arg1: [*c]const u8, arg2: [*c]c_ulong) [*c]u8; -pub extern fn MagickRemoveImageProfile(arg0: ?*MagickWand, arg1: [*c]const u8, arg2: [*c]c_ulong) [*c]u8; -pub extern fn MagickWriteImageBlob(arg0: ?*MagickWand, arg1: [*c]usize) [*c]u8; -pub extern fn MagickClearException(arg0: ?*MagickWand) void; -pub extern fn MagickResetIterator(arg0: ?*MagickWand) void; -pub const __GCC_ATOMIC_TEST_AND_SET_TRUEVAL = 1; -pub const _STDC_PREDEF_H = 1; -pub const __FLT16_MAX_EXP__ = 15; -pub const __GNUC_VA_LIST = 1; -pub const __BIGGEST_ALIGNMENT__ = 16; -pub const EXIT_SUCCESS = 0; -pub const _IO_USER_LOCK = 32768; -pub const __INT64_FMTd__ = "ld"; -pub const __STDC_VERSION__ = c_long(201112); -pub const __SIZEOF_FLOAT__ = 4; -pub const MagickSignature = c_ulong(2880220587); -pub const __INT_LEAST32_FMTi__ = "i"; -pub const MagickLibInterfaceOldest = 3; -pub const __INT_LEAST8_FMTi__ = "hhi"; -pub const __LDBL_EPSILON__ = 0.000000; -pub const __LZCNT__ = 1; -pub const MaxTextExtent = 2053; -pub const __STDC_UTF_32__ = 1; -pub const __INT_LEAST32_FMTd__ = "d"; -pub const __INVPCID__ = 1; -pub const __SIG_ATOMIC_WIDTH__ = 32; -pub const __FD_ZERO_STOS = "stosq"; -pub const __UINT_FAST64_FMTX__ = "lX"; -pub const __GCC_ATOMIC_LLONG_LOCK_FREE = 2; -pub const DrawGetException = MagickDrawGetException; -pub const __clang_version__ = "8.0.0 (tags/RELEASE_800/final)"; -pub const __UINT_LEAST8_FMTo__ = "hho"; -pub const __SIZEOF_DOUBLE__ = 8; -pub const __INTMAX_FMTd__ = "ld"; -pub const __HAVE_DISTINCT_FLOAT16 = __HAVE_FLOAT16; -pub const __CLANG_ATOMIC_CHAR_LOCK_FREE = 2; -pub const LITTLE_ENDIAN = __LITTLE_ENDIAN; -pub const __INT_LEAST16_FMTi__ = "hi"; -pub const __GCC_ATOMIC_SHORT_LOCK_FREE = 2; -pub const MAGICK_OFF_F = MAGICK_INT64_F; -pub const _STDLIB_H = 1; -pub const _BITS_STDIO_LIM_H = 1; -pub const __FMA__ = 1; -pub const __MMX__ = 1; -pub const __HAVE_FLOAT64 = 1; -pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 = 1; -pub const BYTE_ORDER = __BYTE_ORDER; -pub const __SIZE_FMTX__ = "lX"; -pub const __ID_T_TYPE = __U32_TYPE; -pub const _THREAD_SHARED_TYPES_H = 1; -pub const MinBlobExtent = c_long(32768); -pub const __RDSEED__ = 1; -pub const RunlengthEncodedCompression = RLECompression; -pub const __INO_T_TYPE = __SYSCALL_ULONG_TYPE; -pub const _BITS_TYPES_H = 1; -pub const __FSBLKCNT_T_TYPE = __SYSCALL_ULONG_TYPE; -pub const __ptr_t = [*c]void; -pub const __WCHAR_WIDTH__ = 32; -pub const __FSGSBASE__ = 1; -pub const __STDC_IEC_559_COMPLEX__ = 1; -pub const __USE_MISC = 1; -pub const __FSBLKCNT64_T_TYPE = __UQUAD_TYPE; -pub const __SIZEOF_PTHREAD_ATTR_T = 56; -pub const __PTRDIFF_FMTd__ = "ld"; -pub const __DBL_MIN_EXP__ = -1021; -pub const MAGICK_UINT32_F = ""; -pub const __lldiv_t_defined = 1; -pub const __HAVE_FLOAT32X = 1; -pub const __FLT_EVAL_METHOD__ = 0; -pub const __USECONDS_T_TYPE = __U32_TYPE; -pub const __SSE_MATH__ = 1; -pub const __PID_T_TYPE = __S32_TYPE; -pub const __UINT_FAST8_FMTo__ = "hho"; -pub const __UINT_LEAST64_MAX__ = c_ulong(18446744073709551615); -pub const SignatureSize = 64; -pub const _ALLOCA_H = 1; -pub const __UINT_LEAST64_FMTx__ = "lx"; -pub const __INT8_MAX__ = 127; -pub const __NLINK_T_TYPE = __SYSCALL_ULONG_TYPE; -pub const __DBL_HAS_DENORM__ = 1; -pub const __FLOAT128__ = 1; -pub const __HAVE_GENERIC_SELECTION = 1; -pub const __FLT16_HAS_QUIET_NAN__ = 1; -pub const __ATOMIC_RELAXED = 0; -pub const __DBL_DECIMAL_DIG__ = 17; -pub const __XSAVEC__ = 1; -pub const __SIZEOF_SHORT__ = 2; -pub const ____FILE_defined = 1; -pub const __UINT16_FMTX__ = "hX"; -pub const __UINT_FAST16_MAX__ = 65535; -pub const __PTHREAD_MUTEX_HAVE_PREV = 1; -pub const __timeval_defined = 1; -pub const __CLANG_ATOMIC_SHORT_LOCK_FREE = 2; -pub const __SSSE3__ = 1; -pub const __CONSTANT_CFSTRINGS__ = 1; -pub const WEXITED = 4; -pub const __MODE_T_TYPE = __U32_TYPE; -pub const _SYS_CDEFS_H = 1; -pub const _ATFILE_SOURCE = 1; -pub const __AVX2__ = 1; -pub const __RLIM_T_TYPE = __SYSCALL_ULONG_TYPE; -pub const __WINT_MAX__ = c_uint(4294967295); -pub const __LDBL_MAX_EXP__ = 16384; -pub const __USE_POSIX199309 = 1; -pub const _STDIO_H = 1; -pub const __STDC_ISO_10646__ = c_long(201706); -pub const __NO_MATH_INLINES = 1; -pub const __WCHAR_TYPE__ = int; -pub const NewDrawingWand = MagickNewDrawingWand; -pub const __BLKCNT64_T_TYPE = __SQUAD_TYPE; -pub const __LONG_MAX__ = c_long(9223372036854775807); -pub const __STDC_HOSTED__ = 1; -pub const __pic__ = 2; -pub const __PTRDIFF_WIDTH__ = 64; -pub const __INT_FAST16_FMTi__ = "hi"; -pub const __INT_LEAST32_TYPE__ = int; -pub const __SCHAR_MAX__ = 127; -pub const __USE_POSIX2 = 1; -pub const __LDBL_DENORM_MIN__ = 0.000000; -pub const __HAVE_FLOATN_NOT_TYPEDEF = 0; -pub const __FLT16_MIN_EXP__ = -14; -pub const __TIMESIZE = __WORDSIZE; -pub const RAND_MAX = 2147483647; -pub const __USE_XOPEN2K = 1; -pub const __FLOAT_WORD_ORDER = __BYTE_ORDER; -pub const _IOFBF = 0; -pub const __PRFCHW__ = 1; -pub const __USE_FORTIFY_LEVEL = 0; -pub const __ELF__ = 1; -pub const __INT64_C_SUFFIX__ = L; -pub const __FSFILCNT_T_TYPE = __SYSCALL_ULONG_TYPE; -pub const __LDBL_MANT_DIG__ = 64; -pub const __PTHREAD_MUTEX_LOCK_ELISION = 1; -pub const __SSIZE_T_TYPE = __SWORD_TYPE; -pub const __USE_XOPEN2K8 = 1; -pub const MaxRGBFloat = 65535.000000; -pub const __CLANG_ATOMIC_INT_LOCK_FREE = 2; -pub const __SIZEOF_PTRDIFF_T__ = 8; -pub const ExtendedSignedIntegralType = magick_int64_t; -pub const __SIG_ATOMIC_MAX__ = 2147483647; -pub const __struct_FILE_defined = 1; -pub const _IO_EOF_SEEN = 16; -pub const __USE_ATFILE = 1; -pub const __UINT64_FMTX__ = "lX"; -pub const __WALL = 1073741824; -pub const __UINT64_MAX__ = c_ulong(18446744073709551615); -pub const __DBL_MANT_DIG__ = 53; -pub const __FLT_DECIMAL_DIG__ = 9; -pub const _____fpos_t_defined = 1; -pub const __INT_LEAST32_MAX__ = 2147483647; -pub const __DBL_DIG__ = 15; -pub const __GLIBC_USE_DEPRECATED_SCANF = 0; -pub const MagickLogFilename = "log.mgk"; -pub const __ATOMIC_ACQUIRE = 2; -pub const __OPENCL_MEMORY_SCOPE_WORK_GROUP = 1; -pub const __USE_ISOC95 = 1; -pub const __FLT16_HAS_DENORM__ = 1; -pub const __UID_T_TYPE = __U32_TYPE; -pub const __UINT_FAST16_FMTu__ = "hu"; -pub const __INTPTR_FMTi__ = "li"; -pub const __UINT_FAST8_FMTX__ = "hhX"; -pub const __LITTLE_ENDIAN__ = 1; -pub const __SSE__ = 1; -pub const __FLT_HAS_QUIET_NAN__ = 1; -pub const __SIZEOF_SIZE_T__ = 8; -pub const __UINT_LEAST16_FMTo__ = "ho"; -pub const __UINT8_FMTo__ = "hho"; -pub const MagickSizeType = magick_int64_t; -pub const __HAVE_FLOAT32 = 1; -pub const __UINT_LEAST16_FMTx__ = "hx"; -pub const __CLANG_ATOMIC_WCHAR_T_LOCK_FREE = 2; -pub const MagickFalse = 0; -pub const __UINT_FAST16_FMTX__ = "hX"; -pub const __UINT_FAST32_FMTx__ = "x"; -pub const __VERSION__ = "4.2.1 Compatible Clang 8.0.0 (tags/RELEASE_800/final)"; -pub const MagickQuantumDepth = "Q16"; -pub const __UINTPTR_MAX__ = c_ulong(18446744073709551615); -pub const __UINT_FAST8_FMTu__ = "hhu"; -pub const __UINT_LEAST8_FMTu__ = "hhu"; -pub const __UINT_LEAST64_FMTo__ = "lo"; -pub const __clockid_t_defined = 1; -pub const __UINT_LEAST8_MAX__ = 255; -pub const OpaqueOpacity = c_ulong(0); -pub const __SYSCALL_ULONG_TYPE = __ULONGWORD_TYPE; -pub const __warnattr = msg; -pub const __RDRND__ = 1; -pub const __STD_TYPE = typedef; -pub const __SIZEOF_WCHAR_T__ = 4; -pub const __MOVBE__ = 1; -pub const __GLIBC_USE_DEPRECATED_GETS = 0; -pub const MaxMap = c_uint(65535); -pub const __LDBL_MAX__ = inf; -pub const __UINT16_MAX__ = 65535; -pub const _LP64 = 1; -pub const __CLOCK_T_TYPE = __SYSCALL_SLONG_TYPE; -pub const FD_SETSIZE = __FD_SETSIZE; -pub const __x86_64 = 1; -pub const __PTHREAD_RWLOCK_INT_FLAGS_SHARED = 1; -pub const __code_model_small_ = 1; -pub const linux = 1; -pub const __SIZEOF_WINT_T__ = 4; -pub const DestroyDrawingWand = MagickDestroyDrawingWand; -pub const __UINTMAX_FMTo__ = "lo"; -pub const __FLT_DIG__ = 6; -pub const __UINT_LEAST8_FMTX__ = "hhX"; -pub const __INT16_MAX__ = 32767; -pub const __HAVE_FLOAT64X = 1; -pub const MagickReleaseDate = "2019-06-15"; -pub const __HAVE_FLOAT16 = 0; -pub const __WINT_UNSIGNED__ = 1; -pub const __FLT_MAX_10_EXP__ = 38; -pub const MAGICK_UINTPTR_F = "l"; -pub const _FEATURES_H = 1; -pub const __CLANG_ATOMIC_POINTER_LOCK_FREE = 2; -pub const __UINTPTR_FMTX__ = "lX"; -pub const __UINT_LEAST16_FMTu__ = "hu"; -pub const __WINT_WIDTH__ = 32; -pub const MagickChangeDate = "20190615"; -pub const __F16C__ = 1; -pub const AreaResource = UndefinedResource; -pub const __SHRT_MAX__ = 32767; -pub const __SIZEOF_PTHREAD_RWLOCKATTR_T = 8; -pub const MagickLibInterfaceNewest = 23; -pub const __GCC_ATOMIC_BOOL_LOCK_FREE = 2; -pub const __POINTER_WIDTH__ = 64; -pub const __PTRDIFF_MAX__ = c_long(9223372036854775807); -pub const __tune_corei7__ = 1; -pub const __FLT16_DIG__ = 3; -pub const __INT32_FMTd__ = "d"; -pub const __DBL_MIN__ = 0.000000; -pub const __SIZEOF_LONG__ = 8; -pub const __S32_TYPE = int; -pub const __TIME_T_TYPE = __SYSCALL_SLONG_TYPE; -pub const __INTPTR_WIDTH__ = 64; -pub const __FLT16_MAX_10_EXP__ = 4; -pub const __INT_FAST32_TYPE__ = int; -pub const __TIME64_T_TYPE = __TIME_T_TYPE; -pub const __W_CONTINUED = 65535; -pub const __NO_INLINE__ = 1; -pub const __UINT_FAST32_FMTX__ = "X"; -pub const _POSIX_SOURCE = 1; -pub const __LITTLE_ENDIAN = 1234; -pub const __HAVE_FLOAT128 = 0; -pub const __gnu_linux__ = 1; -pub const __INT_FAST32_MAX__ = 2147483647; -pub const _BITS_PTHREADTYPES_COMMON_H = 1; -pub const __corei7__ = 1; -pub const __UINTMAX_FMTu__ = "lu"; -pub const __BMI__ = 1; -pub const __FILE_defined = 1; -pub const CloneDrawingWand = MagickCloneDrawingWand; -pub const _____fpos64_t_defined = 1; -pub const __FLT_RADIX__ = 2; -pub const __GLIBC_MINOR__ = 29; -pub const __timer_t_defined = 1; -pub const __FLT16_HAS_INFINITY__ = 1; -pub const MaxMapDepth = 16; -pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 = 1; -pub const __GCC_ATOMIC_INT_LOCK_FREE = 2; -pub const _BITS_BYTESWAP_H = 1; -pub const IndexChannel = BlackChannel; -pub const __SGX__ = 1; -pub const __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES = 3; -pub const _STRUCT_TIMESPEC = 1; -pub const _BITS_STDINT_INTN_H = 1; -pub const __FLT16_DECIMAL_DIG__ = 5; -pub const __PRAGMA_REDEFINE_EXTNAME = 1; -pub const __INT_FAST8_FMTd__ = "hhd"; -pub const __KEY_T_TYPE = __S32_TYPE; -pub const SEEK_SET = 0; -pub const __INT32_TYPE__ = int; -pub const __USE_POSIX199506 = 1; -pub const __CPU_MASK_TYPE = __SYSCALL_ULONG_TYPE; -pub const MagickFail = 0; -pub const FOPEN_MAX = 16; -pub const MAGICK_OPTIMIZE_FUNC = opt; -pub const MAGICK_INT64_F = "l"; -pub const __UINTMAX_WIDTH__ = 64; -pub const MAGICK_SSIZE_T_F = "l"; -pub const __PTHREAD_MUTEX_USE_UNION = 0; -pub const __FLT_MIN__ = 0.000000; -pub const __INT64_FMTi__ = "li"; -pub const __UINT_FAST64_FMTu__ = "lu"; -pub const __INT8_FMTd__ = "hhd"; -pub const MagickLibVersion = 2301952; -pub const __INT_FAST16_TYPE__ = short; -pub const YCbCrColorspace = Rec601YCbCrColorspace; -pub const __HAVE_DISTINCT_FLOAT128 = 0; -pub const __FLT_MAX_EXP__ = 128; -pub const __XSAVE__ = 1; -pub const __DBL_MAX_10_EXP__ = 308; -pub const __LDBL_MIN__ = 0.000000; -pub const __INT_FAST64_FMTi__ = "li"; -pub const __INT_LEAST8_FMTd__ = "hhd"; -pub const __CLANG_ATOMIC_LLONG_LOCK_FREE = 2; -pub const __FSFILCNT64_T_TYPE = __UQUAD_TYPE; -pub const MAGICK_RANDOM_MAX = 4294967295; -pub const __UINT_LEAST32_FMTX__ = "X"; -pub const __PIC__ = 2; -pub const __GID_T_TYPE = __U32_TYPE; -pub const MagickLibVersionText = "1.3.32"; -pub const __UINTMAX_MAX__ = c_ulong(18446744073709551615); -pub const __UINT_FAST16_FMTo__ = "ho"; -pub const _DEFAULT_SOURCE = 1; -pub const __FD_SETSIZE = 1024; -pub const __LDBL_DECIMAL_DIG__ = 21; -pub const __UINT_LEAST64_FMTX__ = "lX"; -pub const __clang_minor__ = 0; -pub const __LDBL_REDIR_DECL = name; -pub const __OFF64_T_TYPE = __SQUAD_TYPE; -pub const __SIZEOF_FLOAT128__ = 16; -pub const __CLOCKID_T_TYPE = __S32_TYPE; -pub const __UINT_FAST64_FMTo__ = "lo"; -pub const __SIZE_FMTx__ = "lx"; -pub const __DBL_MAX__ = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878; -pub const __DBL_EPSILON__ = 0.000000; -pub const __UINT64_FMTx__ = "lx"; -pub const MAGICK_UINTMAX_F = "l"; -pub const P_tmpdir = "/tmp"; -pub const __BLKCNT_T_TYPE = __SYSCALL_SLONG_TYPE; -pub const __CHAR_BIT__ = 8; -pub const __WCOREFLAG = 128; -pub const SEEK_END = 2; -pub const __INT16_FMTi__ = "hi"; -pub const __SLONG32_TYPE = int; -pub const SEEK_CUR = 1; -pub const _DEBUG = 1; -pub const __GNUC_MINOR__ = 2; -pub const __restrict_arr = __restrict; -pub const __UINT_FAST32_MAX__ = c_uint(4294967295); -pub const __RLIM_T_MATCHES_RLIM64_T = 1; -pub const __UINT8_FMTX__ = "hhX"; -pub const NFDBITS = __NFDBITS; -pub const __FLT_EPSILON__ = 0.000000; -pub const __UINTPTR_WIDTH__ = 64; -pub const MAGICK_PIXELS_BGRA = 1; -pub const __llvm__ = 1; -pub const __UINT_FAST64_MAX__ = c_ulong(18446744073709551615); -pub const __INT_FAST32_FMTi__ = "i"; -pub const __WNOTHREAD = 536870912; -pub const __time_t_defined = 1; -pub const __FLT_HAS_INFINITY__ = 1; -pub const __FSWORD_T_TYPE = __SYSCALL_SLONG_TYPE; -pub const __DADDR_T_TYPE = __S32_TYPE; -pub const __AES__ = 1; -pub const NULL = if (@typeId(@typeOf(0)) == @import("builtin").TypeId.Pointer) @ptrCast([*c]void, 0) else if (@typeId(@typeOf(0)) == @import("builtin").TypeId.Int) @intToPtr([*c]void, 0) else ([*c]void)(0); -pub const __OFF_T_TYPE = __SYSCALL_SLONG_TYPE; -pub const __UINT8_FMTx__ = "hhx"; -pub const __INTMAX_C_SUFFIX__ = L; -pub const __ORDER_LITTLE_ENDIAN__ = 1234; -pub const __time64_t = __time_t; -pub const MagickRationalType = double; -pub const DrawClearException = MagickDrawClearException; -pub const __GCC_ATOMIC_CHAR16_T_LOCK_FREE = 2; -pub const __INT16_FMTd__ = "hd"; -pub const __UINT32_FMTX__ = "X"; -pub const __SUSECONDS_T_TYPE = __SYSCALL_SLONG_TYPE; -pub const HasX11 = 1; -pub const MAGICK_INT32_F = ""; -pub const __PTHREAD_MUTEX_NUSERS_AFTER_KIND = 0; -pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 = 1; -pub const MagickPass = 1; -pub const __UINT32_C_SUFFIX__ = U; -pub const MagickSignedType = magick_int64_t; -pub const __INT32_MAX__ = 2147483647; -pub const __GCC_ATOMIC_CHAR_LOCK_FREE = 2; -pub const __INTMAX_WIDTH__ = 64; -pub const MaxRGB = c_uint(65535); -pub const __INO64_T_TYPE = __UQUAD_TYPE; -pub const __CLANG_ATOMIC_BOOL_LOCK_FREE = 2; -pub const EXIT_FAILURE = 1; -pub const __USE_POSIX = 1; -pub const __BIT_TYPES_DEFINED__ = 1; -pub const TransparentOpacity = MaxRGB; -pub const __SIZE_FMTo__ = "lo"; -pub const __DBL_HAS_QUIET_NAN__ = 1; -pub const __PDP_ENDIAN = 3412; -pub const __INT_FAST8_FMTi__ = "hhi"; -pub const __UINT_LEAST32_FMTo__ = "o"; -pub const __STDC_UTF_16__ = 1; -pub const __UINT_LEAST32_MAX__ = c_uint(4294967295); -pub const __ATOMIC_RELEASE = 3; -pub const __UINT_FAST16_FMTx__ = "hx"; -pub const __UINTMAX_C_SUFFIX__ = UL; -pub const __FLT_MIN_EXP__ = -125; -pub const __SIZEOF_LONG_DOUBLE__ = 16; -pub const __UINT_LEAST64_FMTu__ = "lu"; -pub const __ldiv_t_defined = 1; -pub const __GCC_ATOMIC_LONG_LOCK_FREE = 2; -pub const __ORDER_PDP_ENDIAN__ = 3412; -pub const __SIZEOF_PTHREAD_BARRIER_T = 32; -pub const __GLIBC_USE_IEC_60559_FUNCS_EXT = 0; -pub const __INT_FAST64_FMTd__ = "ld"; -pub const FILENAME_MAX = 4096; -pub const ExtendedUnsignedIntegralType = magick_uint64_t; -pub const __CLANG_ATOMIC_LONG_LOCK_FREE = 2; -pub const __GXX_ABI_VERSION = 1002; -pub const __INT16_TYPE__ = short; -pub const __SSE2_MATH__ = 1; -pub const __FLT_MANT_DIG__ = 24; -pub const __GLIBC_USE_IEC_60559_TYPES_EXT = 0; -pub const __UINT_FAST64_FMTx__ = "lx"; -pub const __STDC__ = 1; -pub const __HAVE_FLOAT64X_LONG_DOUBLE = 1; -pub const __INT_FAST8_MAX__ = 127; -pub const __INTPTR_FMTd__ = "ld"; -pub const __GNUC_PATCHLEVEL__ = 1; -pub const __SIZE_WIDTH__ = 64; -pub const __UINT_LEAST8_FMTx__ = "hhx"; -pub const __MPX__ = 1; -pub const __INT_LEAST64_FMTi__ = "li"; -pub const __HAVE_DISTINCT_FLOAT64 = 0; -pub const __SSE4_2__ = 1; -pub const __STDC_IEC_559__ = 1; -pub const __AVX__ = 1; -pub const __INT_FAST16_MAX__ = 32767; -pub const __USE_ISOC99 = 1; -pub const __INTPTR_MAX__ = c_long(9223372036854775807); -pub const __CLANG_ATOMIC_CHAR16_T_LOCK_FREE = 2; -pub const __UINT64_FMTu__ = "lu"; -pub const __have_pthread_attr_t = 1; -pub const __BYTE_ORDER__ = __ORDER_LITTLE_ENDIAN__; -pub const __SSE2__ = 1; -pub const MaxMapDouble = 65535.000000; -pub const MAGICK_UINT64_F = "l"; -pub const __INT_MAX__ = 2147483647; -pub const __BLKSIZE_T_TYPE = __SYSCALL_SLONG_TYPE; -pub const __INTMAX_FMTi__ = "li"; -pub const __DBL_DENORM_MIN__ = 0.000000; -pub const __clang_major__ = 8; -pub const __FLT16_MANT_DIG__ = 11; -pub const __GNUC__ = 4; -pub const __UINT32_MAX__ = c_uint(4294967295); -pub const MaxRGBDouble = 65535.000000; -pub const _POSIX_C_SOURCE = c_long(200809); -pub const __FLT_DENORM_MIN__ = 0.000000; -pub const __DBL_MAX_EXP__ = 1024; -pub const __INT8_FMTi__ = "hhi"; -pub const L_tmpnam = 20; -pub const __BIG_ENDIAN = 4321; -pub const __UINT_LEAST16_MAX__ = 65535; -pub const __HAVE_DISTINCT_FLOAT32X = 0; -pub const __XSAVES__ = 1; -pub const __LDBL_HAS_DENORM__ = 1; -pub const __FLT16_MIN_10_EXP__ = -13; -pub const __LDBL_HAS_QUIET_NAN__ = 1; -pub const TMP_MAX = 238328; -pub const __UINT_FAST8_MAX__ = 255; -pub const __DBL_MIN_10_EXP__ = -307; -pub const __GLIBC_USE_LIB_EXT2 = 0; -pub const __SIZEOF_PTHREAD_MUTEX_T = 40; -pub const __UINT8_FMTu__ = "hhu"; -pub const __OFF_T_MATCHES_OFF64_T = 1; -pub const __RLIM64_T_TYPE = __UQUAD_TYPE; -pub const __HAVE_FLOAT128X = 0; -pub const __INT_FAST64_MAX__ = c_long(9223372036854775807); -pub const __SSE3__ = 1; -pub const __UINT16_FMTu__ = "hu"; -pub const __ATOMIC_SEQ_CST = 5; -pub const __SIZE_FMTu__ = "lu"; -pub const __LDBL_MIN_EXP__ = -16381; -pub const __UINT_FAST32_FMTu__ = "u"; -pub const DrawAllocateWand = MagickDrawAllocateWand; -pub const __SSP_STRONG__ = 2; -pub const __BYTE_ORDER = __LITTLE_ENDIAN; -pub const __clang_patchlevel__ = 0; -pub const MaxMapFloat = 65535.000000; -pub const __SIZEOF_LONG_LONG__ = 8; -pub const __BMI2__ = 1; -pub const EOF = -1; -pub const __HAVE_DISTINCT_FLOAT64X = 0; -pub const __GNUC_STDC_INLINE__ = 1; -pub const MagickTrue = 1; -pub const __FXSR__ = 1; -pub const __PCLMUL__ = 1; -pub const __UINT8_MAX__ = 255; -pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 = 1; -pub const _IOLBF = 1; -pub const __UINT32_FMTx__ = "x"; -pub const __UINT16_FMTo__ = "ho"; -pub const __POPCNT__ = 1; -pub const __OPENCL_MEMORY_SCOPE_DEVICE = 2; -pub const __SIZEOF_PTHREAD_CONDATTR_T = 4; -pub const __UINT32_FMTu__ = "u"; -pub const WNOHANG = 1; -pub const __SIZEOF_PTHREAD_COND_T = 48; -pub const __SIZEOF_POINTER__ = 8; -pub const __TIMER_T_TYPE = [*c]void; -pub const __SIZE_MAX__ = c_ulong(18446744073709551615); -pub const __unix = 1; -pub const _BITS_UINTN_IDENTITY_H = 1; -pub const __GLIBC_USE_IEC_60559_BFP_EXT = 0; -pub const MagickPackageName = "GraphicsMagick"; -pub const __INT_FAST16_FMTd__ = "hd"; -pub const unix = 1; -pub const __UINT_LEAST32_FMTu__ = "u"; -pub const __FLT_MAX__ = 340282346999999984391321947108527833088.000000; -pub const __corei7 = 1; -pub const BUFSIZ = 8192; -pub const __HAVE_DISTINCT_FLOAT32 = 0; -pub const __USE_ISOC11 = 1; -pub const __GCC_ATOMIC_WCHAR_T_LOCK_FREE = 2; -pub const __ATOMIC_CONSUME = 1; -pub const __unix__ = 1; -pub const __x86_64__ = 1; -pub const __LDBL_HAS_INFINITY__ = 1; -pub const __WORDSIZE_TIME64_COMPAT32 = 1; -pub const __UINTMAX_FMTx__ = "lx"; -pub const __UINT64_C_SUFFIX__ = UL; -pub const __GNU_LIBRARY__ = 6; -pub const __INT_LEAST16_MAX__ = 32767; -pub const __FLT_MIN_10_EXP__ = -37; -pub const __clock_t_defined = 1; -pub const __UINT32_FMTo__ = "o"; -pub const __UINTPTR_FMTo__ = "lo"; -pub const _SYS_SELECT_H = 1; -pub const MaxColormapSize = c_uint(65536); -pub const __INT_LEAST16_FMTd__ = "hd"; -pub const __UINTPTR_FMTx__ = "lx"; -pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 = 1; -pub const _IONBF = 2; -pub const __INT_LEAST64_FMTd__ = "ld"; -pub const _SYS_TYPES_H = 1; -pub const __INT_LEAST16_TYPE__ = short; -pub const __attribute_alloc_size__ = params; -pub const __attribute_copy__ = arg; -pub const __ORDER_BIG_ENDIAN__ = 4321; -pub const __LDBL_MIN_10_EXP__ = -4931; -pub const __INT_LEAST8_MAX__ = 127; -pub const __SIZEOF_INT__ = 4; -pub const __USE_POSIX_IMPLICITLY = 1; -pub const __GCC_ATOMIC_POINTER_LOCK_FREE = 2; -pub const NodesInAList = 1536; -pub const _IO_ERR_SEEN = 32; -pub const __amd64 = 1; -pub const _BITS_TIME64_H = 1; -pub const __OBJC_BOOL_IS_BOOL = 0; -pub const __ADX__ = 1; -pub const __LDBL_MAX_10_EXP__ = 4932; -pub const L_ctermid = 9; -pub const __SIZEOF_INT128__ = 16; -pub const __UINT_FAST8_FMTx__ = "hhx"; -pub const __SIZEOF_PTHREAD_RWLOCK_T = 56; -pub const __glibc_c99_flexarr_available = 1; -pub const __linux = 1; -pub const __sigset_t_defined = 1; -pub const __UINT16_FMTx__ = "hx"; -pub const MaxTreeDepth = 8; -pub const __UINTPTR_FMTu__ = "lu"; -pub const __UINT_LEAST16_FMTX__ = "hX"; -pub const __SIZEOF_PTHREAD_MUTEXATTR_T = 4; -pub const __CLFLUSHOPT__ = 1; -pub const __amd64__ = 1; -pub const __UINT_FAST32_FMTo__ = "o"; -pub const __linux__ = 1; -pub const __clang__ = 1; -pub const __LP64__ = 1; -pub const __SYSCALL_WORDSIZE = 64; -pub const __PTRDIFF_FMTi__ = "li"; -pub const __SSE4_1__ = 1; -pub const __LDBL_DIG__ = 18; -pub const __GCC_ATOMIC_CHAR32_T_LOCK_FREE = 2; -pub const _BITS_TYPESIZES_H = 1; -pub const DefaultResizeFilter = LanczosFilter; -pub const WCONTINUED = 8; -pub const ReplaceCompositeOp = CopyCompositeOp; -pub const __XSAVEOPT__ = 1; -pub const __UINT64_FMTo__ = "lo"; -pub const __INT_FAST32_FMTd__ = "d"; -pub const __HAVE_DISTINCT_FLOAT128X = __HAVE_FLOAT128X; -pub const _BITS_PTHREADTYPES_ARCH_H = 1; -pub const BIG_ENDIAN = __BIG_ENDIAN; -pub const __ATOMIC_ACQ_REL = 4; -pub const PDP_ENDIAN = __PDP_ENDIAN; -pub const __SIZEOF_PTHREAD_BARRIERATTR_T = 4; -pub const __LONG_LONG_MAX__ = c_longlong(9223372036854775807); -pub const __OPENCL_MEMORY_SCOPE_SUB_GROUP = 4; -pub const ____mbstate_t_defined = 1; -pub const _ENDIAN_H = 1; -pub const __INO_T_MATCHES_INO64_T = 1; -pub const __GLIBC__ = 2; -pub const WUNTRACED = 2; -pub const DefaultThumbnailFilter = BoxFilter; -pub const __INTMAX_MAX__ = c_long(9223372036854775807); -pub const __UINT_LEAST32_FMTx__ = "x"; -pub const __WORDSIZE = 64; -pub const MagickUnsignedType = magick_uint64_t; -pub const __WCHAR_MAX__ = 2147483647; -pub const __INT64_MAX__ = c_long(9223372036854775807); -pub const WSTOPPED = 2; -pub const MAGICK_SIZE_T_F = "l"; -pub const __CLANG_ATOMIC_CHAR32_T_LOCK_FREE = 2; -pub const MagickCopyright = "Copyright (C) 2002-2019 GraphicsMagick Group.\nAdditional copyrights and licenses apply to this software.\nSee http://www.GraphicsMagick.org/www/Copyright.html for details."; -pub const __INT_LEAST64_MAX__ = c_long(9223372036854775807); -pub const WNOWAIT = 16777216; -pub const __UINTMAX_FMTX__ = "lX"; -pub const __OPENCL_MEMORY_SCOPE_WORK_ITEM = 0; -pub const __FLT_HAS_DENORM__ = 1; -pub const __DECIMAL_DIG__ = __LDBL_DECIMAL_DIG__; -pub const __SYSCALL_SLONG_TYPE = __SLONGWORD_TYPE; -pub const __WCLONE = 2147483648; -pub const __DEV_T_TYPE = __UQUAD_TYPE; -pub const __INT32_FMTi__ = "i"; -pub const __DBL_HAS_INFINITY__ = 1; -pub const QuantumDepth = 16; -pub const __FINITE_MATH_ONLY__ = 0; -pub const __va_list_tag = struct___va_list_tag; -pub const _G_fpos_t = struct__G_fpos_t; -pub const _G_fpos64_t = struct__G_fpos64_t; -pub const _IO_marker = struct__IO_marker; -pub const _IO_codecvt = struct__IO_codecvt; -pub const _IO_wide_data = struct__IO_wide_data; -pub const _IO_FILE = struct__IO_FILE; -pub const timeval = struct_timeval; -pub const timespec = struct_timespec; -pub const __pthread_rwlock_arch_t = struct___pthread_rwlock_arch_t; -pub const __pthread_internal_list = struct___pthread_internal_list; -pub const __pthread_mutex_s = struct___pthread_mutex_s; -pub const __pthread_cond_s = struct___pthread_cond_s; -pub const random_data = struct_random_data; -pub const drand48_data = struct_drand48_data; -pub const _PixelPacket = struct__PixelPacket; -pub const _PrimaryInfo = struct__PrimaryInfo; -pub const _ChromaticityInfo = struct__ChromaticityInfo; -pub const _RectangleInfo = struct__RectangleInfo; -pub const _ErrorInfo = struct__ErrorInfo; -pub const _Timer = struct__Timer; -pub const _TimerInfo = struct__TimerInfo; -pub const _ExceptionInfo = struct__ExceptionInfo; -pub const _ImageExtra = struct__ImageExtra; -pub const _CacheInfo = struct__CacheInfo; -pub const _ThreadViewSet = struct__ThreadViewSet; -pub const _ImageAttribute = struct__ImageAttribute; -pub const _Ascii85Info = struct__Ascii85Info; -pub const _BlobInfo = struct__BlobInfo; -pub const _SemaphoreInfo = struct__SemaphoreInfo; -pub const _Image = struct__Image; -pub const _AffineMatrix = struct__AffineMatrix; -pub const _DoublePixelPacket = struct__DoublePixelPacket; -pub const _FloatPixelPacket = struct__FloatPixelPacket; -pub const _FrameInfo = struct__FrameInfo; -pub const _LongPixelPacket = struct__LongPixelPacket; -pub const _MontageInfo = struct__MontageInfo; -pub const _ProfileInfo = struct__ProfileInfo; -pub const _SegmentInfo = struct__SegmentInfo; -pub const _ImageInfo = struct__ImageInfo; -pub const _ImageCharacteristics = struct__ImageCharacteristics; -pub const _HistogramColorPacket = struct__HistogramColorPacket; -pub const _DifferenceImageOptions = struct__DifferenceImageOptions; -pub const _DifferenceStatistics = struct__DifferenceStatistics; -pub const _CompositeOptions_t = struct__CompositeOptions_t; -pub const _ExportPixelAreaOptions = struct__ExportPixelAreaOptions; -pub const _ExportPixelAreaInfo = struct__ExportPixelAreaInfo; -pub const _ImportPixelAreaOptions = struct__ImportPixelAreaOptions; -pub const _ImportPixelAreaInfo = struct__ImportPixelAreaInfo; -pub const _DelegateInfo = struct__DelegateInfo; -pub const _TypeInfo = struct__TypeInfo; -pub const _GradientInfo = struct__GradientInfo; -pub const _ElementReference = struct__ElementReference; -pub const _DrawInfoExtra = struct__DrawInfoExtra; -pub const _DrawInfo = struct__DrawInfo; -pub const _PointInfo = struct__PointInfo; -pub const _TypeMetric = struct__TypeMetric; -pub const _DrawContext = struct__DrawContext; -pub const _MagickRandomKernel = struct__MagickRandomKernel; -pub const _MagickInfo = struct__MagickInfo; -pub const _PixelIteratorOptions = struct__PixelIteratorOptions; -pub const _QuantizeInfo = struct__QuantizeInfo; -pub const _SignatureInfo = struct__SignatureInfo; -pub const _ImageChannelStatistics = struct__ImageChannelStatistics; -pub const _ImageStatistics = struct__ImageStatistics; -pub const _TokenInfo = struct__TokenInfo; -pub const _PixelWand = struct__PixelWand; -pub const _DrawingWand = struct__DrawingWand; -pub const _MagickWand = struct__MagickWand; From e462b4e9d6bd4fe4bb2947ccace31fbeea87ee4d Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 30 May 2020 15:56:58 -0300 Subject: [PATCH 070/182] fix for latest zig --- src/image.zig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/image.zig b/src/image.zig index 704213d..7f8deb4 100644 --- a/src/image.zig +++ b/src/image.zig @@ -79,7 +79,8 @@ pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 { var nam = try allocator.alloc(u8, template.len); std.mem.copy(u8, nam, template); - var r = std.rand.DefaultPrng.init(std.time.timestamp()); + const seed = @bitCast(u64, std.time.timestamp()); + var r = std.rand.DefaultPrng.init(seed); var fill = nam[template_start.len..nam.len]; @@ -409,7 +410,7 @@ pub const Image = struct { try self.checkValid(); var time_taken = timer.read(); - std.debug.warn("\ttook {d:.2}ms running plugin\n", .{time_taken / std.time.millisecond}); + std.debug.warn("\ttook {d:.2}ms running plugin\n", .{time_taken / std.time.us_per_ms}); } pub fn saveTo(self: *Image, out_path: []const u8) !void { From d86e9efe433f53194f9fc5c03c39d4fcc4a61c8b Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 30 May 2020 16:57:00 -0300 Subject: [PATCH 071/182] add main command struct and make fillKeywords mostly-comptime --- src/lang.zig | 81 ++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 34c5004..88dcda1 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -51,6 +51,37 @@ pub const CommandType = enum { 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 { command: CommandType, args: ArgList, @@ -182,48 +213,18 @@ pub const Lang = struct { } fn fillKeywords(self: *Lang) !void { - _ = try self.keywords.put("noop", .Noop); - _ = try self.keywords.put("load", .Load); - _ = try self.keywords.put("quicksave", .Quicksave); - _ = try self.keywords.put("runqs", .RunQS); + inline for (@typeInfo(NewCommand).Struct.decls) |cmd_struct_decl| { + const struct_name = cmd_struct_decl.name; - _ = try self.keywords.put("amp", .Amp); - _ = try self.keywords.put("rflanger", .RFlanger); - _ = try self.keywords.put("eq", .Eq); - _ = try self.keywords.put("mbeq", .Mbeq); - _ = 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); + comptime var lowered_command_name = [_]u8{0} ** struct_name.len; + comptime { + for (struct_name) |c, i| { + lowered_command_name[i] = std.ascii.toLower(c); + } + } - // custom implementations (not lv2) - _ = 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); + _ = try self.keywords.put(&lowered_command_name, @field(CommandType, struct_name)); + } } pub fn getCommand(self: *Lang, stmt: []const u8) ?CommandType { From 27f499dfbb2dd926611865babbab90e58a96dcb5 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 30 May 2020 17:48:14 -0300 Subject: [PATCH 072/182] add basics of generic command parsing --- src/lang.zig | 63 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 88dcda1..2b3c003 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -318,32 +318,51 @@ pub const Lang = struct { self.doError("No command given", .{}); continue; } - var command = cmd_opt.?; + const command_string = cmd_opt.?; - var ctype_opt = self.getCommand(command); - var ctype: CommandType = undefined; - if (ctype_opt) |ctype_val| { - ctype = ctype_val; - } else { - self.doError("Unknown command '{}' ({})", .{ command, command.len }); + var found: bool = false; + + inline for (@typeInfo(NewCommand).Struct.decls) |cmd_struct_decl| { + const struct_name = cmd_struct_decl.name; + comptime var lowered_command_name = [_]u8{0} ** struct_name.len; + comptime { + for (struct_name) |c, i| { + lowered_command_name[i] = std.ascii.toLower(c); + } + } + + if (std.mem.eql(u8, &lowered_command_name, command_string)) { + found = true; + + // Based on the command struct fields, we need to decide + // how to actually get its arguments and creating the struct + // itself. + + const command_struct = cmd_struct_decl.data.Type; + var cmd: command_struct = undefined; + inline for (@typeInfo(command_struct).Struct.fields) |cmd_field| { + + // TODO: crash when no arguments are left but we still need + // arguments... + const argument = tok_it.next().?; + const argument_value = switch (cmd_field.field_type) { + usize => try std.fmt.parseInt(usize, arg, 10), + i32 => try std.fmt.parseInt(i32, arg, 10), + f32 => try std.fmt.parseFloat(f32, arg), + else => @panic("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."), + }; + + @field(cmd, cmd_field.name) = argument_value; + } + } + } + + if (!found) { + self.doError("Unknown command '{}' ({})", .{ command_string, command_string.len }); continue; } - var args = ArgList.init(self.allocator); - errdefer args.deinit(); - - while (tok_it.next()) |arg| { - try args.append(arg); - } - - // construct final Command based on command - var cmd = Command{ .command = ctype, .args = args }; - self.validateCommand(cmd) catch |err| { - //self.doError("error validating command '{}': {}", command, err); - continue; - }; - - try cmds.append(cmd); + // try cmds.append(cmd); } if (self.has_error) return ParseError.ParseFail; From 154032f9b17c0a21cf8002134a61865e32b52e03 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 30 May 2020 22:25:30 -0300 Subject: [PATCH 073/182] revamp command structure for tags and base types --- src/lang.zig | 155 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 129 insertions(+), 26 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 2b3c003..8a2a9ce 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -58,25 +58,91 @@ pub const Type = enum { }; pub const NewCommand = struct { - pub const Noop = struct {}; + tag: Tag, + + pub const Tag = enum { + noop, + load, + quicksave, + runqs, + + amp, + rflanger, + eq, + phaser, + mbeq, + chorus, + pitchscaler, + reverb, + highpass, + delay, + vinyl, + revdelay, + gate, + detune, + overdrive, + degrade, + repsycho, + talkbox, + dyncomp, + thruzero, + foverdrive, + gverb, + invert, + tapedelay, + moddelay, + multichorus, + saturator, + vintagedelay, + + noise, + wildnoise, + write, + embed, + + rotate, + }; + + pub fn cast(base: *@This(), comptime T: type) ?*T { + if (base.tag != T.base_tag) + return null; + + return @fieldParentPtr(T, "base", base); + } + + pub const Noop = struct { + pub const base_tag = Tag.noop; + base: NewCommand, + }; pub const Load = struct { + pub const base_tag = Tag.load; + base: NewCommand, path: []const u8, }; - pub const Quicksave = struct {}; + pub const Quicksave = struct { + pub const base_tag = Tag.quicksave; + base: NewCommand, + }; pub const RunQS = struct { + pub const base_tag = Tag.runqs; program: []const u8, + base: NewCommand, }; pub const Amp = struct { + pub const base_tag = Tag.amp; pub const base_type = Type.lv2_command; + base: NewCommand, gain: f64 }; pub const RFlanger = struct { + pub const base_tag = Tag.rflanger; pub const base_type = Type.lv2_command; + base: NewCommand, delay_depth_avg: f64, law_freq: f64, }; @@ -183,7 +249,7 @@ pub const Command = struct { } }; -pub const CommandList = std.ArrayList(Command); +pub const CommandList = std.ArrayList(NewCommand); pub const ArgList = std.ArrayList([]const u8); pub const KeywordMap = std.StringHashMap(CommandType); @@ -214,6 +280,14 @@ pub const Lang = struct { fn fillKeywords(self: *Lang) !void { inline for (@typeInfo(NewCommand).Struct.decls) |cmd_struct_decl| { + switch (cmd_struct_decl.data) { + .Type => |typ| switch (@typeInfo(typ)) { + .Struct => {}, + else => continue, + }, + else => continue, + } + const struct_name = cmd_struct_decl.name; comptime var lowered_command_name = [_]u8{0} ** struct_name.len; @@ -297,9 +371,42 @@ pub const Lang = struct { self.has_error = true; } + fn parseCommandArguments( + self: *@This(), + comptime command_struct: type, + tok_it: *std.mem.TokenIterator, + commands: *CommandList, + ) !void { + // Based on the command struct fields, we can parse the arguments. + var cmd = try self.allocator.create(command_struct); + + inline for (@typeInfo(command_struct).Struct.fields) |cmd_field| { + comptime { + if (std.mem.eql(u8, cmd_field.name, "base")) { + continue; + } + } + + // TODO: crash when no arguments are left but we still need + // arguments... + const arg = tok_it.next().?; + const argument_value = switch (cmd_field.field_type) { + usize => try std.fmt.parseInt(usize, arg, 10), + i32 => try std.fmt.parseInt(i32, arg, 10), + f32 => try std.fmt.parseFloat(f32, arg), + []const u8 => arg, + else => @panic("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."), + }; + + @field(cmd, cmd_field.name) = argument_value; + } + + try commands.append(cmd.base); + } + pub fn parse(self: *Lang, data: []const u8) ParseError!CommandList { var splitted_it = std.mem.split(data, ";"); - try self.fillKeywords(); + // try self.fillKeywords(); var cmds = CommandList.init(self.allocator); while (splitted_it.next()) |stmt_orig| { @@ -310,7 +417,7 @@ pub const Lang = struct { if (stmt.len == 0) continue; if (std.mem.startsWith(u8, stmt, "#")) continue; - // TODO better tokenizer instead of just tokenize(" "); + // TODO better tokenizer instead of just tokenize(" ")...maybe???? var tok_it = std.mem.tokenize(stmt, " "); var cmd_opt = tok_it.next(); @@ -323,6 +430,14 @@ pub const Lang = struct { var found: bool = false; inline for (@typeInfo(NewCommand).Struct.decls) |cmd_struct_decl| { + switch (cmd_struct_decl.data) { + .Type => |typ| switch (@typeInfo(typ)) { + .Struct => {}, + else => continue, + }, + else => continue, + } + const struct_name = cmd_struct_decl.name; comptime var lowered_command_name = [_]u8{0} ** struct_name.len; comptime { @@ -331,29 +446,17 @@ pub const Lang = struct { } } + // if we have a match, we know the proper struct type + // to use. this actually works compared to storing command_struct + // in a variable because then that variable must be comptime. + + // the drawback of this approach is that our emitted code is basically linear + // because we don't use the hashmap anymore. maybe #5359 can help. + if (std.mem.eql(u8, &lowered_command_name, command_string)) { found = true; - - // Based on the command struct fields, we need to decide - // how to actually get its arguments and creating the struct - // itself. - - const command_struct = cmd_struct_decl.data.Type; - var cmd: command_struct = undefined; - inline for (@typeInfo(command_struct).Struct.fields) |cmd_field| { - - // TODO: crash when no arguments are left but we still need - // arguments... - const argument = tok_it.next().?; - const argument_value = switch (cmd_field.field_type) { - usize => try std.fmt.parseInt(usize, arg, 10), - i32 => try std.fmt.parseInt(i32, arg, 10), - f32 => try std.fmt.parseFloat(f32, arg), - else => @panic("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."), - }; - - @field(cmd, cmd_field.name) = argument_value; - } + const cmd_struct_type = cmd_struct_decl.data.Type; + try self.parseCommandArguments(cmd_struct_type, &tok_it, &cmds); } } From f20079b807f5d0a015024f8a9242da21706787c1 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 30 May 2020 22:25:43 -0300 Subject: [PATCH 074/182] disable codepaths not supporting new commands --- src/main.zig | 3 ++- src/runner.zig | 14 ++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main.zig b/src/main.zig index 04bcf2d..9971f24 100644 --- a/src/main.zig +++ b/src/main.zig @@ -185,7 +185,8 @@ 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")) { - return try doRepl(allocator, &args_it); + @panic("TODO bring repl back"); + // return try doRepl(allocator, &args_it); } var file = try std.fs.cwd().openFile(scri_path, .{}); diff --git a/src/runner.zig b/src/runner.zig index 6276954..5496e8a 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -374,6 +374,8 @@ pub const Runner = struct { try image.runPlugin("http://calf.sourceforge.net/plugins/VintageDelay", pos, params); } + fn newRunCommand(self: *@This(), cmd: lang.NewCommand) !void {} + fn runCommand(self: *Runner, cmd: *lang.Command) !void { var params = ParamList.init(self.allocator); defer params.deinit(); @@ -775,14 +777,10 @@ pub const Runner = struct { cmds: lang.CommandList, debug_flag: bool, ) !void { - for (cmds.items) |const_cmd| { - if (debug_flag) const_cmd.print(); - - // copy the command so we own its memory - var cmd = try const_cmd.copy(self.allocator); - defer self.allocator.destroy(cmd); - - try self.runCommand(cmd); + for (cmds.items) |cmd| { + // TODO + // if (debug_flag) const_cmd.print(); + try self.newRunCommand(cmd); } } }; From c3b83c3e4b5d1a35ce7b740856b97596641303f7 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 30 May 2020 22:29:13 -0300 Subject: [PATCH 075/182] replace f64 to f32 on some commands --- src/lang.zig | 8 ++++---- src/runner.zig | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 8a2a9ce..3b65c9d 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -136,15 +136,15 @@ pub const NewCommand = struct { pub const base_tag = Tag.amp; pub const base_type = Type.lv2_command; base: NewCommand, - gain: f64 + gain: f32 }; pub const RFlanger = struct { pub const base_tag = Tag.rflanger; pub const base_type = Type.lv2_command; base: NewCommand, - delay_depth_avg: f64, - law_freq: f64, + delay_depth_avg: f32, + law_freq: f32, }; }; @@ -404,7 +404,7 @@ pub const Lang = struct { try commands.append(cmd.base); } - pub fn parse(self: *Lang, data: []const u8) ParseError!CommandList { + pub fn parse(self: *Lang, data: []const u8) !CommandList { var splitted_it = std.mem.split(data, ";"); // try self.fillKeywords(); var cmds = CommandList.init(self.allocator); diff --git a/src/runner.zig b/src/runner.zig index 5496e8a..bde8eb9 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -778,7 +778,6 @@ pub const Runner = struct { debug_flag: bool, ) !void { for (cmds.items) |cmd| { - // TODO // if (debug_flag) const_cmd.print(); try self.newRunCommand(cmd); } From 47a97636cd472769741666b81162ea71b5a553c4 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 30 May 2020 22:39:45 -0300 Subject: [PATCH 076/182] enable command debug printing --- src/lang.zig | 17 +++++++++++++++++ src/runner.zig | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/lang.zig b/src/lang.zig index 3b65c9d..ff406a9 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -103,6 +103,19 @@ pub const NewCommand = struct { rotate, }; + pub fn tagToType(tag: Tag) type { + return switch (tag) { + .noop => Noop, + .load => Load, + .quicksave => Quicksave, + .runqs => RunQS, + + .amp => Amp, + .rflanger => RFlanger, + else => @panic("TODO"), + }; + } + pub fn cast(base: *@This(), comptime T: type) ?*T { if (base.tag != T.base_tag) return null; @@ -110,6 +123,10 @@ pub const NewCommand = struct { return @fieldParentPtr(T, "base", base); } + pub fn print(base: *const @This()) void { + std.debug.warn("{}\n", .{base.tag}); + } + pub const Noop = struct { pub const base_tag = Tag.noop; base: NewCommand, diff --git a/src/runner.zig b/src/runner.zig index bde8eb9..eacc3c7 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -778,7 +778,7 @@ pub const Runner = struct { debug_flag: bool, ) !void { for (cmds.items) |cmd| { - // if (debug_flag) const_cmd.print(); + cmd.print(); try self.newRunCommand(cmd); } } From eb18d01cdd63d67fbccd54a3a336d813826c3ea2 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 30 May 2020 22:39:52 -0300 Subject: [PATCH 077/182] copy struct base tag into command base tag --- src/lang.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lang.zig b/src/lang.zig index ff406a9..10df1be 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -418,6 +418,8 @@ pub const Lang = struct { @field(cmd, cmd_field.name) = argument_value; } + cmd.base.tag = command_struct.base_tag; + try commands.append(cmd.base); } From 6497fc1dd8d7a600c00c38bfbe5e9df8775a96ed Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 30 May 2020 22:42:41 -0300 Subject: [PATCH 078/182] add split/index decls to Amp, RFlanger --- src/lang.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 10df1be..1a747b9 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -151,15 +151,17 @@ pub const NewCommand = struct { pub const Amp = struct { pub const base_tag = Tag.amp; - pub const base_type = Type.lv2_command; base: NewCommand, + split: usize, + index: usize, gain: f32 }; pub const RFlanger = struct { pub const base_tag = Tag.rflanger; - pub const base_type = Type.lv2_command; base: NewCommand, + split: usize, + index: usize, delay_depth_avg: f32, law_freq: f32, }; From 7d519b73b69de726fb8fbc67f9e07c2c261dd1c0 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 30 May 2020 22:56:45 -0300 Subject: [PATCH 079/182] add runner support on command cast --- src/lang.zig | 2 +- src/runner.zig | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 1a747b9..07d3d50 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -116,7 +116,7 @@ pub const NewCommand = struct { }; } - pub fn cast(base: *@This(), comptime T: type) ?*T { + pub fn cast(base: *const @This(), comptime T: type) ?*const T { if (base.tag != T.base_tag) return null; diff --git a/src/runner.zig b/src/runner.zig index eacc3c7..024fa42 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -374,7 +374,23 @@ pub const Runner = struct { try image.runPlugin("http://calf.sourceforge.net/plugins/VintageDelay", pos, params); } - fn newRunCommand(self: *@This(), cmd: lang.NewCommand) !void {} + fn newRunCommandSingle( + self: *@This(), + cmd: lang.NewCommand, + comptime tag: lang.NewCommand.Tag, + ) !void { + comptime const typ = lang.NewCommand.tagToType(tag); + const command = cmd.cast(typ).?; + + std.debug.warn("{}\n", .{command}); + } + + fn newRunCommand(self: *@This(), cmd: lang.NewCommand) !void { + switch (cmd.tag) { + .load => try self.newRunCommandSingle(cmd, .load), + else => @panic("TODO"), + } + } fn runCommand(self: *Runner, cmd: *lang.Command) !void { var params = ParamList.init(self.allocator); From d518369314cc96348fe0604f314a591f51912aad Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 30 May 2020 23:57:34 -0300 Subject: [PATCH 080/182] add random debug statements --- src/lang.zig | 2 +- src/runner.zig | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 07d3d50..77ec179 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -124,7 +124,7 @@ pub const NewCommand = struct { } pub fn print(base: *const @This()) void { - std.debug.warn("{}\n", .{base.tag}); + std.debug.warn("tag: {}\n", .{base.tag}); } pub const Noop = struct { diff --git a/src/runner.zig b/src/runner.zig index 024fa42..a27c945 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -381,6 +381,7 @@ pub const Runner = struct { ) !void { comptime const typ = lang.NewCommand.tagToType(tag); const command = cmd.cast(typ).?; + std.debug.warn("{} {}\n", .{ command.path.ptr, command.path.len }); std.debug.warn("{}\n", .{command}); } @@ -795,7 +796,15 @@ pub const Runner = struct { ) !void { for (cmds.items) |cmd| { cmd.print(); - try self.newRunCommand(cmd); + + switch (cmd.tag) { + .load => { + const proper_cmd = cmd.cast(lang.NewCommand.Load).?; + std.debug.warn("got load! {}\n", .{proper_cmd}); + }, + else => @panic("TODO"), + } + try self.newRunCommand(cmd.*); } } }; From 9c6387973fc5f2d70762905abd45ce38aaef5b9d Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 30 May 2020 23:57:42 -0300 Subject: [PATCH 081/182] convert command list to ptr command list, fixing mem issues --- src/lang.zig | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 77ec179..c45aff8 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -268,7 +268,7 @@ pub const Command = struct { } }; -pub const CommandList = std.ArrayList(NewCommand); +pub const CommandList = std.ArrayList(*NewCommand); pub const ArgList = std.ArrayList([]const u8); pub const KeywordMap = std.StringHashMap(CommandType); @@ -413,21 +413,24 @@ 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), - []const u8 => arg, + []const u8 => try self.allocator.dupe(u8, arg), else => @panic("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."), }; + std.debug.warn("parsing {}, arg of type {} => {}\n", .{ @typeName(command_struct), @typeName(@TypeOf(argument_value)), argument_value }); + @field(cmd, cmd_field.name) = argument_value; } cmd.base.tag = command_struct.base_tag; + const command = cmd.base.cast(command_struct).?; + std.debug.warn("cmd: {}\n", .{command}); - try commands.append(cmd.base); + try commands.append(&cmd.base); } pub fn parse(self: *Lang, data: []const u8) !CommandList { var splitted_it = std.mem.split(data, ";"); - // try self.fillKeywords(); var cmds = CommandList.init(self.allocator); while (splitted_it.next()) |stmt_orig| { From f9c18517345111994e123b11de3248362667aa4c Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 15:20:19 -0300 Subject: [PATCH 082/182] add support for generic lv2 command running --- src/lang.zig | 8 +++++- src/runner.zig | 69 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 64 insertions(+), 13 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index c45aff8..0e8fdd0 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -51,7 +51,7 @@ pub const CommandType = enum { Rotate, }; -pub const Type = enum { +pub const NewCommandType = enum { /// "LV2 Commands" are commands that receive split, index, and then receive /// any f64 arguments. lv2_command, @@ -151,6 +151,9 @@ pub const NewCommand = struct { pub const Amp = struct { pub const base_tag = Tag.amp; + pub const command_type = NewCommandType.lv2_command; + pub const lv2_url = "http://lv2plug.in/plugins/eg-amp"; + base: NewCommand, split: usize, index: usize, @@ -159,6 +162,9 @@ pub const NewCommand = struct { pub const RFlanger = struct { pub const base_tag = Tag.rflanger; + pub const command_type = NewCommandType.lv2_command; + pub const lv2_url = "http://plugin.org.uk/swh-plugins/retroFlange"; + base: NewCommand, split: usize, index: usize, diff --git a/src/runner.zig b/src/runner.zig index a27c945..4ffa606 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -374,6 +374,38 @@ pub const Runner = struct { try image.runPlugin("http://calf.sourceforge.net/plugins/VintageDelay", pos, params); } + fn executeLV2Command(self: *@This(), command: var) !void { + const pos = plugin.Position{ + .split = command.split, + .index = command.index, + }; + + var params = ParamList.init(self.allocator); + defer params.deinit(); + + const typ = @TypeOf(command); + + inline for (@typeInfo(typ).Struct.fields) |cmd_field| { + // ignore fields that can't be symbols for lv2 execution + comptime { + if (std.mem.eql(u8, cmd_field.name, "base") or + std.mem.eql(u8, cmd_field.name, "split") or + std.mem.eql(u8, cmd_field.name, "index")) + { + continue; + } + } + + try params.append(plugin.Param{ + .sym = cmd_field.name, + .value = @field(command, cmd_field.name), + }); + } + + var image = try self.getImage(); + try image.runPlugin(typ.lv2_url, pos, params); + } + fn newRunCommandSingle( self: *@This(), cmd: lang.NewCommand, @@ -381,15 +413,36 @@ pub const Runner = struct { ) !void { comptime const typ = lang.NewCommand.tagToType(tag); const command = cmd.cast(typ).?; - std.debug.warn("{} {}\n", .{ command.path.ptr, command.path.len }); + inline for (@typeInfo(typ).Struct.decls) |decl| { + comptime { + if (!std.mem.eql(u8, decl.name, "command_type")) { + continue; + } + } - std.debug.warn("{}\n", .{command}); + const ctype = typ.command_type; + switch (ctype) { + .lv2_command => try self.executeLV2Command(command.*), + else => @panic("TODO support command type"), + } + } } fn newRunCommand(self: *@This(), cmd: lang.NewCommand) !void { + // .load => try self.newRunCommandSingle(cmd, .load), switch (cmd.tag) { - .load => try self.newRunCommandSingle(cmd, .load), - else => @panic("TODO"), + .load => { + const command = cmd.cast(lang.NewCommand.Load).?; + try self.loadCmd(command.path); + }, + .quicksave => { + try self.quicksaveCmd(); + }, + .amp => try self.newRunCommandSingle(cmd, .amp), + else => { + std.debug.warn("TODO support {}\n", .{@tagName(cmd.tag)}); + @panic("TODO support tag"); + }, } } @@ -796,14 +849,6 @@ pub const Runner = struct { ) !void { for (cmds.items) |cmd| { cmd.print(); - - switch (cmd.tag) { - .load => { - const proper_cmd = cmd.cast(lang.NewCommand.Load).?; - std.debug.warn("got load! {}\n", .{proper_cmd}); - }, - else => @panic("TODO"), - } try self.newRunCommand(cmd.*); } } From 94c9695110dc72e50943b89fffd27153f07b8ed7 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 16:55:50 -0300 Subject: [PATCH 083/182] add helper to make lv2 command structs --- src/lang.zig | 91 +++++++++++++++++++++++++++++++++++++++----------- src/runner.zig | 51 ++++++++++++++++------------ 2 files changed, 101 insertions(+), 41 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 0e8fdd0..2749610 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -57,6 +57,23 @@ pub const NewCommandType = enum { lv2_command, }; +fn LV2Command( + comptime tag: NewCommand.Tag, + comptime lv2_url: []const u8, + comptime LV2Parameters: type, +) type { + return struct { + pub const base_tag = tag; + pub const command_type = NewCommandType.lv2_command; + pub const lv2_url = lv2_url; + + base: NewCommand, + split: usize, + index: usize, + parameters: LV2Parameters, + }; +} + pub const NewCommand = struct { tag: Tag, @@ -112,6 +129,33 @@ pub const NewCommand = struct { .amp => Amp, .rflanger => RFlanger, + .eq => Eq, + .phaser => Phaser, + // .mbeq => Mbeq, + // .chorus => Chorus, + // .pitchscaler => Pitchscaler, + // .reverb => Reverb, + // .highpass => Highpass, + // .delay => Delay, + // .vinyl => Vinyl, + // .revdelay => Revdelay, + // .gate => Gate, + // .detune => Detune, + // .overdrive => Overdrive, + // .degrade => Degrade, + // .repsycho => Repsycho, + // .talkbox => Talkbox, + // .dyncomp => Dyncomp, + // .thruzero => Thruzero, + // .foverdrive => Foverdrive, + // .gverb => Gverb, + // .invert => Invert, + // .tapedelay => Tapedelay, + // .moddelay => Moddelay, + // .multichorus => Multichorus, + // .saturator => Saturator, + // .vintagedelay => Vintagedelay, + else => @panic("TODO"), }; } @@ -149,28 +193,37 @@ pub const NewCommand = struct { base: NewCommand, }; - pub const Amp = struct { - pub const base_tag = Tag.amp; - pub const command_type = NewCommandType.lv2_command; - pub const lv2_url = "http://lv2plug.in/plugins/eg-amp"; + pub const Amp = LV2Command( + .amp, + "http://lv2plug.in/plugins/eg-amp", + struct { + gain: f32 + }, + ); - base: NewCommand, - split: usize, - index: usize, - gain: f32 - }; + pub const RFlanger = LV2Command( + .rflanger, + "http://plugin.org.uk/swh-plugins/retroFlange", + struct { + delay_depth_avg: f32, law_freq: f32 + }, + ); - pub const RFlanger = struct { - pub const base_tag = Tag.rflanger; - pub const command_type = NewCommandType.lv2_command; - pub const lv2_url = "http://plugin.org.uk/swh-plugins/retroFlange"; + pub const Eq = LV2Command( + .rflanger, + "http://plugin.org.uk/swh-plugins/dj_eq_mono", + struct { + lo: f32, mid: f32, hi: f32 + }, + ); - base: NewCommand, - split: usize, - index: usize, - delay_depth_avg: f32, - law_freq: f32, - }; + pub const Phaser = LV2Command( + .rflanger, + "http://plugin.org.uk/swh-plugins/lfoPhaser", + struct { + lfo_rate: f32, lfo_depth: f32, fb: f32, spread: f32 + }, + ); }; pub const Command = struct { diff --git a/src/runner.zig b/src/runner.zig index 4ffa606..fe9db82 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -439,6 +439,35 @@ pub const Runner = struct { try self.quicksaveCmd(); }, .amp => try self.newRunCommandSingle(cmd, .amp), + + .rflanger => try self.newRunCommandSingle(cmd, .rflanger), + .eq => try self.newRunCommandSingle(cmd, .eq), + .phaser => try self.newRunCommandSingle(cmd, .phaser), + // .mbeq => try self.newRunCommandSingle(cmd, .mbeq), + // .chorus => try self.newRunCommandSingle(cmd, .chorus), + // .pitchscaler => try self.newRunCommandSingle(cmd, .pitchscaler), + // .reverb => try self.newRunCommandSingle(cmd, .reverb), + // .highpass => try self.newRunCommandSingle(cmd, .highpass), + // .delay => try self.newRunCommandSingle(cmd, .delay), + // .vinyl => try self.newRunCommandSingle(cmd, .vinyl), + // .revdelay => try self.newRunCommandSingle(cmd, .revdelay), + // .gate => try self.newRunCommandSingle(cmd, .gate), + // .detune => try self.newRunCommandSingle(cmd, .detune), + // .overdrive => try self.newRunCommandSingle(cmd, .overdrive), + // .degrade => try self.newRunCommandSingle(cmd, .degrade), + // .repsycho => try self.newRunCommandSingle(cmd, .repsycho), + // .talkbox => try self.newRunCommandSingle(cmd, .talkbox), + // .dyncomp => try self.newRunCommandSingle(cmd, .dyncomp), + // .thruzero => try self.newRunCommandSingle(cmd, .thruzero), + // .foverdrive => try self.newRunCommandSingle(cmd, .foverdrive), + // .gverb => try self.newRunCommandSingle(cmd, .gverb), + // .invert => try self.newRunCommandSingle(cmd, .invert), + // .tapedelay => try self.newRunCommandSingle(cmd, .tapedelay), + // .moddelay => try self.newRunCommandSingle(cmd, .moddelay), + // .multichorus => try self.newRunCommandSingle(cmd, .multichorus), + // .saturator => try self.newRunCommandSingle(cmd, .saturator), + // .vintagedelay => try self.newRunCommandSingle(cmd, .vintagedelay), + else => { std.debug.warn("TODO support {}\n", .{@tagName(cmd.tag)}); @panic("TODO support tag"); @@ -465,28 +494,6 @@ pub const Runner = struct { .Quicksave => try self.quicksaveCmd(), .RunQS => try self.runQSCmd(cmd.args.items[0]), - .Amp => blk: { - const pos = try cmd.consumePosition(); - try cmd.appendParam(¶ms, "gain"); - try self.ampCmd(pos, params); - }, - - .RFlanger => blk: { - const pos = try cmd.consumePosition(); - try cmd.appendParam(¶ms, "delay_depth_avg"); - try cmd.appendParam(¶ms, "law_freq"); - try self.rFlangerCmd(pos, params); - }, - - .Eq => blk: { - const pos = try cmd.consumePosition(); - try cmd.appendParam(¶ms, "lo"); - try cmd.appendParam(¶ms, "mid"); - try cmd.appendParam(¶ms, "hi"); - - try self.eqCmd(pos, params); - }, - .Phaser => blk: { const pos = try cmd.consumePosition(); From b21960d37275380510a4f941ee6b3a718f01dd90 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 16:57:12 -0300 Subject: [PATCH 084/182] remove unused code off parser --- src/lang.zig | 93 +--------------------------------------------------- 1 file changed, 1 insertion(+), 92 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 2749610..883c468 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -335,7 +335,6 @@ pub const KeywordMap = std.StringHashMap(CommandType); /// A parser. pub const Lang = struct { allocator: *std.mem.Allocator, - keywords: KeywordMap, has_error: bool = false, line: usize = 0, @@ -343,105 +342,15 @@ pub const Lang = struct { pub fn init(allocator: *std.mem.Allocator) Lang { return Lang{ .allocator = allocator, - .keywords = KeywordMap.init(allocator), }; } - pub fn deinit(self: *Lang) void { - self.keywords.deinit(); - } + pub fn deinit(self: *Lang) void {} pub fn reset(self: *Lang) void { self.has_error = false; self.line = 0; } - - fn fillKeywords(self: *Lang) !void { - inline for (@typeInfo(NewCommand).Struct.decls) |cmd_struct_decl| { - switch (cmd_struct_decl.data) { - .Type => |typ| switch (@typeInfo(typ)) { - .Struct => {}, - else => continue, - }, - else => continue, - } - - const struct_name = cmd_struct_decl.name; - - comptime var lowered_command_name = [_]u8{0} ** struct_name.len; - comptime { - for (struct_name) |c, i| { - lowered_command_name[i] = std.ascii.toLower(c); - } - } - - _ = try self.keywords.put(&lowered_command_name, @field(CommandType, struct_name)); - } - } - - pub fn getCommand(self: *Lang, stmt: []const u8) ?CommandType { - var kv_opt = self.keywords.get(stmt); - - if (kv_opt) |kv| { - return kv.value; - } else { - return null; - } - } - - fn expectAny(self: *Lang, count: usize, args: ArgList) !void { - if (args.items.len != count) { - self.doError("expected {} arguments, found {}", .{ count, args.items.len }); - return error.ArgRequired; - } - } - - fn expectSingle(self: *Lang, args: ArgList) !void { - return try self.expectAny(1, args); - } - - fn expectFloat(self: *Lang, count: usize, args: ArgList) !void { - var i: usize = 0; - - if (args.items.len != count) { - self.doError("expected {} arguments, found {}", .{ count, args.items.len }); - return error.ArgRequired; - } - - while (i < count) : (i += 1) { - var arg = args.items[i]; - _ = std.fmt.parseFloat(f32, arg) catch |err| { - std.debug.warn("failed to parse f32: {}\n", .{err}); - return error.FloatParseFail; - }; - } - } - - fn validateCommand(self: *Lang, cmd: Command) !void { - switch (cmd.command) { - .Quicksave, .Noop => {}, - .Load, .RunQS => try self.expectSingle(cmd.args), - .Amp => try self.expectFloat(3, cmd.args), - .RFlanger => try self.expectFloat(4, cmd.args), - .Eq => try self.expectFloat(5, cmd.args), - .Phaser => try self.expectFloat(6, cmd.args), - .Mbeq => try self.expectFloat(17, cmd.args), - .Chorus => try self.expectFloat(8, cmd.args), - .PitchScaler => try self.expectFloat(3, cmd.args), - .Reverb => try self.expectFloat(12, cmd.args), - .Highpass => try self.expectFloat(5, cmd.args), - .Delay => try self.expectFloat(12, cmd.args), - .Vinyl => try self.expectFloat(7, cmd.args), - .RevDelay => try self.expectFloat(7, cmd.args), - .Noise => try self.expectFloat(4, cmd.args), - .WildNoise => try self.expectFloat(4, cmd.args), - .Write => try self.expectFloat(3, cmd.args), - .Rotate => try self.expectAny(2, cmd.args), - .Embed => try self.expectAny(3, cmd.args), - else => std.debug.warn("WARN unchecked command {}\n", .{cmd.command}), - } - } - fn doError(self: *Lang, comptime fmt: []const u8, args: var) void { std.debug.warn("error at line {}: ", .{self.line}); std.debug.warn(fmt, args); From dca5d7b644683f1b4c31d84819b9864057ef6b09 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 17:08:35 -0300 Subject: [PATCH 085/182] parse lv2 commands' split/index automatically --- src/lang.zig | 65 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 883c468..fbc5bf7 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -366,28 +366,57 @@ pub const Lang = struct { ) !void { // Based on the command struct fields, we can parse the arguments. var cmd = try self.allocator.create(command_struct); + const is_lv2_command = switch (command_struct.base_tag) { + .noop, .load, .quicksave, .runqs => false, + else => command_struct.command_type == .lv2_command, + }; - inline for (@typeInfo(command_struct).Struct.fields) |cmd_field| { - comptime { - if (std.mem.eql(u8, cmd_field.name, "base")) { - continue; - } + // TODO: crash when no arguments are left but we still need + // arguments... + + if (is_lv2_command) { + cmd.split = try std.fmt.parseInt(usize, tok_it.next().?, 10); + cmd.index = try std.fmt.parseInt(usize, tok_it.next().?, 10); + + inline for (@typeInfo(@typeOf(command_struct.parameters)).Struct.fields) |cmd_field| { + const arg = tok_it.next().?; + const argument_value = switch (cmd_field.field_type) { + f32 => try std.fmt.parseFloat(f32, arg), + else => @compileError("LV2 parameter struct can only have f32 fields"), + }; + + std.debug.warn("parsing {}, arg of type {} => {}\n", .{ + @typeName(command_struct), + @typeName(@TypeOf(argument_value)), + argument_value, + }); + + @field(cmd.params, cmd_field.name) = argument_value; } + } else { + inline for (@typeInfo(command_struct).Struct.fields) |cmd_field| { + comptime { + if (std.mem.eql(u8, cmd_field.name, "base")) { + continue; + } + } + const arg = tok_it.next().?; + const argument_value = switch (cmd_field.field_type) { + usize => try std.fmt.parseInt(usize, arg, 10), + i32 => try std.fmt.parseInt(i32, arg, 10), + f32 => try std.fmt.parseFloat(f32, arg), + []const u8 => try self.allocator.dupe(u8, arg), + else => @panic("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."), + }; - // TODO: crash when no arguments are left but we still need - // arguments... - const arg = tok_it.next().?; - const argument_value = switch (cmd_field.field_type) { - usize => try std.fmt.parseInt(usize, arg, 10), - i32 => try std.fmt.parseInt(i32, arg, 10), - f32 => try std.fmt.parseFloat(f32, arg), - []const u8 => try self.allocator.dupe(u8, arg), - else => @panic("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."), - }; + std.debug.warn("parsing {}, arg of type {} => {}\n", .{ + @typeName(command_struct), + @typeName(@TypeOf(argument_value)), + argument_value, + }); - std.debug.warn("parsing {}, arg of type {} => {}\n", .{ @typeName(command_struct), @typeName(@TypeOf(argument_value)), argument_value }); - - @field(cmd, cmd_field.name) = argument_value; + @field(cmd.params, cmd_field.name) = argument_value; + } } cmd.base.tag = command_struct.base_tag; From dd1b493da24f56055f6df6284ce6d88af2999a3f Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 17:11:17 -0300 Subject: [PATCH 086/182] fix typo --- src/lang.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index fbc5bf7..d855a47 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -59,13 +59,13 @@ pub const NewCommandType = enum { fn LV2Command( comptime tag: NewCommand.Tag, - comptime lv2_url: []const u8, + comptime plugin_url: []const u8, comptime LV2Parameters: type, ) type { return struct { pub const base_tag = tag; pub const command_type = NewCommandType.lv2_command; - pub const lv2_url = lv2_url; + pub const lv2_url = plugin_url; base: NewCommand, split: usize, From b5512c45fb9362021104d71326fdeb0d6219ac84 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 17:11:26 -0300 Subject: [PATCH 087/182] fix fetching of lv2 params --- src/lang.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index d855a47..d13ef2f 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -378,7 +378,7 @@ pub const Lang = struct { cmd.split = try std.fmt.parseInt(usize, tok_it.next().?, 10); cmd.index = try std.fmt.parseInt(usize, tok_it.next().?, 10); - inline for (@typeInfo(@typeOf(command_struct.parameters)).Struct.fields) |cmd_field| { + inline for (@typeInfo(@TypeOf(cmd.parameters)).Struct.fields) |cmd_field| { const arg = tok_it.next().?; const argument_value = switch (cmd_field.field_type) { f32 => try std.fmt.parseFloat(f32, arg), @@ -391,7 +391,7 @@ pub const Lang = struct { argument_value, }); - @field(cmd.params, cmd_field.name) = argument_value; + @field(cmd.parameters, cmd_field.name) = argument_value; } } else { inline for (@typeInfo(command_struct).Struct.fields) |cmd_field| { From 5412934f277093214c99681c7a691ac4db638540 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 17:11:32 -0300 Subject: [PATCH 088/182] fix fetching of non-lv2 params --- src/lang.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lang.zig b/src/lang.zig index d13ef2f..44566e5 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -415,7 +415,7 @@ pub const Lang = struct { argument_value, }); - @field(cmd.params, cmd_field.name) = argument_value; + @field(cmd, cmd_field.name) = argument_value; } } From d09603c005794bd4e25e2edf130ec02f673a6512 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 17:11:40 -0300 Subject: [PATCH 089/182] add runner support for LV2Command() spec --- src/runner.zig | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/runner.zig b/src/runner.zig index fe9db82..438ce0b 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -385,20 +385,10 @@ pub const Runner = struct { const typ = @TypeOf(command); - inline for (@typeInfo(typ).Struct.fields) |cmd_field| { - // ignore fields that can't be symbols for lv2 execution - comptime { - if (std.mem.eql(u8, cmd_field.name, "base") or - std.mem.eql(u8, cmd_field.name, "split") or - std.mem.eql(u8, cmd_field.name, "index")) - { - continue; - } - } - + inline for (@typeInfo(@TypeOf(command.parameters)).Struct.fields) |cmd_field| { try params.append(plugin.Param{ .sym = cmd_field.name, - .value = @field(command, cmd_field.name), + .value = @field(command.parameters, cmd_field.name), }); } From 8e0ebbe5e02ab5959e96af4bd743285abb49535c Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 17:16:57 -0300 Subject: [PATCH 090/182] remove old Command struct --- src/lang.zig | 146 +-------------------------------------------------- 1 file changed, 1 insertion(+), 145 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 44566e5..059e30b 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -9,49 +9,6 @@ pub const ParseError = error{ }; pub const CommandType = enum { - Noop, - Load, - Quicksave, - RunQS, - - Amp, - RFlanger, - Eq, - Phaser, - Mbeq, - Chorus, - PitchScaler, - Reverb, - Highpass, - Delay, - Vinyl, - RevDelay, - Gate, - Detune, - Overdrive, - Degrade, - RePsycho, - TalkBox, - DynComp, - ThruZero, - Foverdrive, - Gverb, - Invert, - TapeDelay, - ModDelay, - MultiChorus, - Saturator, - VintageDelay, - - Noise, - WildNoise, - Write, - Embed, - - Rotate, -}; - -pub const NewCommandType = enum { /// "LV2 Commands" are commands that receive split, index, and then receive /// any f64 arguments. lv2_command, @@ -64,7 +21,7 @@ fn LV2Command( ) type { return struct { pub const base_tag = tag; - pub const command_type = NewCommandType.lv2_command; + pub const command_type = CommandType.lv2_command; pub const lv2_url = plugin_url; base: NewCommand, @@ -226,107 +183,6 @@ pub const NewCommand = struct { ); }; -pub const Command = struct { - command: CommandType, - args: ArgList, - cur_idx: usize = 0, - - pub fn print(self: Command) void { - std.debug.warn("cmd:{}\n", .{self.command}); - } - - pub fn argAt(self: Command, idx: usize) ![]const u8 { - std.debug.warn("{} {}", .{ idx, self.args.items.len }); - - if (idx > (self.args.items.len - 1)) { - std.debug.warn("Expected argument at index {}\n", .{idx}); - return ParseError.ArgRequired; - } - - return self.args.items[idx]; - } - - pub fn usizeArgAt(self: Command, idx: usize) !usize { - var arg = try self.argAt(idx); - return try std.fmt.parseInt(usize, arg, 10); - } - - pub fn consumePosition(self: *Command) !plugin.Position { - self.cur_idx = 2; - return plugin.Position{ - .split = try self.usizeArgAt(0), - .index = try self.usizeArgAt(1), - }; - } - - pub fn intArgAt(self: Command, idx: usize) !i32 { - var arg = try self.argAt(idx); - return try std.fmt.parseInt(i32, arg, 10); - } - - pub fn floatArgAt(self: Command, idx: usize) !f32 { - var arg = try self.argAt(idx); - return try std.fmt.parseFloat(f32, arg); - } - - pub fn floatArgMany( - self: Command, - allocator: *std.mem.Allocator, - start_index: usize, - elements: usize, - default: f32, - ) ![]const f32 { - var i: usize = start_index; - var arr = std.ArrayList(f32).init(allocator); - - while (i < elements) : (i += 1) { - var value: f32 = self.floatArgAt(i) catch |err| blk: { - std.debug.warn("\tdoing default on arg {}\n", .{i}); - break :blk default; - }; - - try arr.append(value); - } - - return arr.items; - } - - pub fn appendParam( - self: *Command, - params: *plugin.ParamList, - symbol: []const u8, - ) !void { - var val = try self.floatArgAt(self.cur_idx); - self.cur_idx += 1; - - try params.append(plugin.Param{ - .sym = symbol, - .value = val, - }); - } - - pub fn appendParamMap( - self: *Command, - map: *plugin.ParamMap, - symbol: []const u8, - ) !void { - var val = try self.floatArgAt(self.cur_idx); - self.cur_idx += 1; - _ = try map.put(symbol, val); - } - - pub fn copy(self: Command, allocator: *std.mem.Allocator) !*Command { - var cmd = try allocator.create(Command); - cmd.* = Command{ - .command = self.command, - .args = self.args, - .cur_idx = self.cur_idx, - }; - - return cmd; - } -}; - pub const CommandList = std.ArrayList(*NewCommand); pub const ArgList = std.ArrayList([]const u8); From c6c31f5a60606cd519dd81421cb0352f63837bf1 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 17:18:36 -0300 Subject: [PATCH 091/182] rename NewCommand to Command --- src/lang.zig | 18 +++++++++--------- src/runner.zig | 11 +++++------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 059e30b..8b1e16e 100644 --- a/src/lang.zig +++ b/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 => {}, diff --git a/src/runner.zig b/src/runner.zig index 438ce0b..962cfcc 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -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 => { From 3a7009f9bf651947b2c25dd6c415927c931d8489 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 17:53:33 -0300 Subject: [PATCH 092/182] convert more commands to new form --- src/lang.zig | 196 +++++++++++++++++++++++++++++++++++++---- src/runner.zig | 234 ++++--------------------------------------------- 2 files changed, 197 insertions(+), 233 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 8b1e16e..4fb3fb4 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -88,23 +88,23 @@ pub const Command = struct { .rflanger => RFlanger, .eq => Eq, .phaser => Phaser, - // .mbeq => Mbeq, - // .chorus => Chorus, - // .pitchscaler => Pitchscaler, - // .reverb => Reverb, - // .highpass => Highpass, - // .delay => Delay, - // .vinyl => Vinyl, - // .revdelay => Revdelay, - // .gate => Gate, - // .detune => Detune, - // .overdrive => Overdrive, - // .degrade => Degrade, - // .repsycho => Repsycho, - // .talkbox => Talkbox, - // .dyncomp => Dyncomp, - // .thruzero => Thruzero, - // .foverdrive => Foverdrive, + .mbeq => Mbeq, + .chorus => Chorus, + .pitchscaler => Pitchscaler, + .reverb => Reverb, + .highpass => Highpass, + .delay => Delay, + .vinyl => Vinyl, + .revdelay => Revdelay, + .gate => Gate, + .detune => Detune, + .overdrive => Overdrive, + .degrade => Degrade, + .repsycho => Repsycho, + .talkbox => Talkbox, + .dyncomp => Dyncomp, + .thruzero => Thruzero, + .foverdrive => Foverdrive, // .gverb => Gverb, // .invert => Invert, // .tapedelay => Tapedelay, @@ -175,12 +175,172 @@ pub const Command = struct { ); pub const Phaser = LV2Command( - .rflanger, + .phaser, "http://plugin.org.uk/swh-plugins/lfoPhaser", struct { lfo_rate: f32, lfo_depth: f32, fb: f32, spread: f32 }, ); + + pub const Mbeq = LV2Command( + .mbeq, + "http://plugin.org.uk/swh-plugins/mbeq", + struct { + band_1: f32, + band_2: f32, + band_3: f32, + band_4: f32, + band_5: f32, + band_6: f32, + band_7: f32, + band_8: f32, + band_9: f32, + band_10: f32, + band_11: f32, + band_12: f32, + band_13: f32, + band_14: f32, + band_15: f32, + }, + ); + + pub const Chorus = LV2Command( + .chorus, + "http://plugin.org.uk/swh-plugins/multivoiceChorus", + struct { + voices: f32, + delay_base: f32, + voice_spread: f32, + detune: f32, + law_freq: f32, + attendb: f32, + }, + ); + + pub const Pitchscaler = LV2Command( + .pitchscaler, + "http://plugin.org.uk/swh-plugins/pitchScaleHQ", + struct { mult: f32 }, + ); + + pub const Reverb = LV2Command( + .reverb, + "http://invadarecords.com/plugins/lv2/erreverb/mono", + struct { + roomLength: f32, + roomWidth: f32, + roomHeight: f32, + sourceLR: f32, + sourceFB: f32, + listLR: f32, + listFB: f32, + hpf: f32, + warmth: f32, + diffusion: f32, + }, + ); + + pub const Highpass = LV2Command(.highpass, "http://invadarecords.com/plugins/lv2/filter/hpf/mono", struct { + freq: f32, + gain: f32, + noClip: f32, + }); + + pub const Delay = LV2Command(.delay, "http://plugin.org.uk/swh-plugins/delayorama", struct { + seed: f32, + gain: f32, + feedback_pc: f32, + tap_count: f32, + first_delay: f32, + delay_range: f32, + delay_scale: f32, + delay_rand_pc: f32, + gain_scale: f32, + wet: f32, + }); + + pub const Vinyl = LV2Command(.vinyl, "http://plugin.org.uk/swh-plugins/vynil", struct { + year: f32, + rpm: f32, + warp: f32, + click: f32, + wear: f32, + }); + + pub const Revdelay = LV2Command(.revdelay, "http://plugin.org.uk/swh-plugins/revdelay", struct { + delay_time: f32, + dry_level: f32, + wet_level: f32, + feedback: f32, + xfade_samp: f32, + }); + // pub const Noise= LV2Command(.,,struct{}); + pub const Gate = LV2Command(.gate, "http://hippie.lt/lv2/gate", struct { + @"switch": f32, + threshold: f32, + attack: f32, + hold: f32, + decay: f32, + gaterange: f32, + }); + pub const Detune = LV2Command(.detune, "http://drobilla.net/plugins/mda/Detune", struct { + @"switch": f32, + threshold: f32, + attack: f32, + hold: f32, + decay: f32, + gaterange: f32, + detune: f32, + mix: f32, + output: f32, + latency: f32, + }); + pub const Overdrive = LV2Command(.overdrive, "http://drobilla.net/plugins/mda/Overdrive", struct { + drive: f32, + muffle: f32, + output: f32, + }); + pub const Degrade = LV2Command(.degrade, "http://drobilla.net/plugins/mda/Degrade", struct { + headroom: f32, + quant: f32, + rate: f32, + post_filt: f32, + non_lin: f32, + output: f32, + }); + pub const Repsycho = LV2Command(.repsycho, "http://drobilla.net/plugins/mda/RePsycho", struct { + tune: f32, + fine: f32, + decay: f32, + thresh: f32, + hold: f32, + mix: f32, + quality: f32, + }); + pub const Talkbox = LV2Command(.talkbox, "http://drobilla.net/plugins/mda/TalkBox", struct { + wet: f32, + dry: f32, + carrier: f32, + quality: f32, + }); + pub const Dyncomp = LV2Command(.dyncomp, "http://gareus.org/oss/lv2/darc#mono", struct { + enable: f32, + hold: f32, + inputgain: f32, + threshold: f32, + ratio: f32, + attack: f32, + release: f32, + gain_min: f32, + gain_max: f32, + rms: f32, + }); + pub const Foverdrive = LV2Command(.foverdrive, "http://plugin.org.uk/swh-plugins/foverdrive", struct { + drive: f32, + }); + pub const Thruzero = LV2Command(.thruzero, "http://drobilla.net/plugins/mda/ThruZero", struct { + rate: f32, mix: f32, feedback: f32, depth_mod: f32 + }); }; pub const CommandList = std.ArrayList(*Command); diff --git a/src/runner.zig b/src/runner.zig index 962cfcc..b4bf4af 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -190,58 +190,6 @@ pub const Runner = struct { _ = try proc.spawnAndWait(); } - /// Run the http://lv2plug.in/plugins/eg-amp plugin over the file. - fn ampCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://lv2plug.in/plugins/eg-amp", pos, params); - } - - fn rFlangerCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://plugin.org.uk/swh-plugins/retroFlange", pos, params); - } - - fn eqCmd(self: *Runner, position: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://plugin.org.uk/swh-plugins/dj_eq_mono", position, params); - } - - fn phaserCmd(self: *Runner, position: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://plugin.org.uk/swh-plugins/lfoPhaser", position, params); - } - - fn mbeqCmd(self: *Runner, position: Position, bands: []const f32) !void { - var image = try self.getImage(); - var params = ParamList.init(self.allocator); - defer params.deinit(); - - for (bands) |band_value, idx| { - var sym = try std.fmt.allocPrint(self.allocator, "band_{}", .{idx + 1}); - try params.append(plugin.Param{ - .sym = sym, - .value = band_value, - }); - } - - try image.runPlugin("http://plugin.org.uk/swh-plugins/mbeq", position, params); - } - - fn chorusCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://plugin.org.uk/swh-plugins/multivoiceChorus", pos, params); - } - - fn pitchScalerCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://plugin.org.uk/swh-plugins/pitchScaleHQ", pos, params); - } - - fn reverbCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://invadarecords.com/plugins/lv2/erreverb/mono", pos, params); - } - fn highpassCmd(self: *Runner, pos: Position, params: ParamList) !void { var image = try self.getImage(); try image.runPlugin("http://invadarecords.com/plugins/lv2/filter/hpf/mono", pos, params); @@ -432,23 +380,23 @@ pub const Runner = struct { .rflanger => try self.newRunCommandSingle(cmd, .rflanger), .eq => try self.newRunCommandSingle(cmd, .eq), .phaser => try self.newRunCommandSingle(cmd, .phaser), - // .mbeq => try self.newRunCommandSingle(cmd, .mbeq), - // .chorus => try self.newRunCommandSingle(cmd, .chorus), - // .pitchscaler => try self.newRunCommandSingle(cmd, .pitchscaler), - // .reverb => try self.newRunCommandSingle(cmd, .reverb), - // .highpass => try self.newRunCommandSingle(cmd, .highpass), - // .delay => try self.newRunCommandSingle(cmd, .delay), - // .vinyl => try self.newRunCommandSingle(cmd, .vinyl), - // .revdelay => try self.newRunCommandSingle(cmd, .revdelay), - // .gate => try self.newRunCommandSingle(cmd, .gate), - // .detune => try self.newRunCommandSingle(cmd, .detune), - // .overdrive => try self.newRunCommandSingle(cmd, .overdrive), - // .degrade => try self.newRunCommandSingle(cmd, .degrade), - // .repsycho => try self.newRunCommandSingle(cmd, .repsycho), - // .talkbox => try self.newRunCommandSingle(cmd, .talkbox), - // .dyncomp => try self.newRunCommandSingle(cmd, .dyncomp), - // .thruzero => try self.newRunCommandSingle(cmd, .thruzero), - // .foverdrive => try self.newRunCommandSingle(cmd, .foverdrive), + .mbeq => try self.newRunCommandSingle(cmd, .mbeq), + .chorus => try self.newRunCommandSingle(cmd, .chorus), + .pitchscaler => try self.newRunCommandSingle(cmd, .pitchscaler), + .reverb => try self.newRunCommandSingle(cmd, .reverb), + .highpass => try self.newRunCommandSingle(cmd, .highpass), + .delay => try self.newRunCommandSingle(cmd, .delay), + .vinyl => try self.newRunCommandSingle(cmd, .vinyl), + .revdelay => try self.newRunCommandSingle(cmd, .revdelay), + .gate => try self.newRunCommandSingle(cmd, .gate), + .detune => try self.newRunCommandSingle(cmd, .detune), + .overdrive => try self.newRunCommandSingle(cmd, .overdrive), + .degrade => try self.newRunCommandSingle(cmd, .degrade), + .repsycho => try self.newRunCommandSingle(cmd, .repsycho), + .talkbox => try self.newRunCommandSingle(cmd, .talkbox), + .dyncomp => try self.newRunCommandSingle(cmd, .dyncomp), + .thruzero => try self.newRunCommandSingle(cmd, .thruzero), + .foverdrive => try self.newRunCommandSingle(cmd, .foverdrive), // .gverb => try self.newRunCommandSingle(cmd, .gverb), // .invert => try self.newRunCommandSingle(cmd, .invert), // .tapedelay => try self.newRunCommandSingle(cmd, .tapedelay), @@ -483,112 +431,6 @@ pub const Runner = struct { .Quicksave => try self.quicksaveCmd(), .RunQS => try self.runQSCmd(cmd.args.items[0]), - .Phaser => blk: { - const pos = try cmd.consumePosition(); - - try cmd.appendParam(¶ms, "lfo_rate"); - try cmd.appendParam(¶ms, "lfo_depth"); - try cmd.appendParam(¶ms, "fb"); - try cmd.appendParam(¶ms, "spread"); - - try self.phaserCmd(pos, params); - }, - - .Mbeq => blk: { - const pos = try cmd.consumePosition(); - const bands = try cmd.floatArgMany(self.allocator, 2, 15, @as(f32, 0)); - defer self.allocator.free(bands); - - try self.mbeqCmd(pos, bands); - }, - - .Chorus => blk: { - const pos = try cmd.consumePosition(); - - try cmd.appendParam(¶ms, "voices"); - try cmd.appendParam(¶ms, "delay_base"); - try cmd.appendParam(¶ms, "voice_spread"); - try cmd.appendParam(¶ms, "detune"); - try cmd.appendParam(¶ms, "law_freq"); - try cmd.appendParam(¶ms, "attendb"); - - try self.chorusCmd(pos, params); - }, - - .PitchScaler => blk: { - const pos = try cmd.consumePosition(); - try cmd.appendParam(¶ms, "mult"); - try self.pitchScalerCmd(pos, params); - }, - - .Reverb => blk: { - const pos = try cmd.consumePosition(); - - try cmd.appendParam(¶ms, "roomLength"); - try cmd.appendParam(¶ms, "roomWidth"); - try cmd.appendParam(¶ms, "roomHeight"); - try cmd.appendParam(¶ms, "sourceLR"); - try cmd.appendParam(¶ms, "sourceFB"); - try cmd.appendParam(¶ms, "listLR"); - try cmd.appendParam(¶ms, "listFB"); - try cmd.appendParam(¶ms, "hpf"); - try cmd.appendParam(¶ms, "warmth"); - try cmd.appendParam(¶ms, "diffusion"); - - try self.reverbCmd(pos, params); - }, - - .Highpass => blk: { - const pos = try cmd.consumePosition(); - - try cmd.appendParam(¶ms, "freq"); - try cmd.appendParam(¶ms, "gain"); - try cmd.appendParam(¶ms, "noClip"); - - try self.highpassCmd(pos, params); - }, - - .Delay => blk: { - const pos = try cmd.consumePosition(); - - try cmd.appendParam(¶ms, "seed"); - try cmd.appendParam(¶ms, "gain"); - try cmd.appendParam(¶ms, "feedback_pc"); - try cmd.appendParam(¶ms, "tap_count"); - try cmd.appendParam(¶ms, "first_delay"); - try cmd.appendParam(¶ms, "delay_range"); - try cmd.appendParam(¶ms, "delay_scale"); - try cmd.appendParam(¶ms, "delay_rand_pc"); - try cmd.appendParam(¶ms, "gain_scale"); - try cmd.appendParam(¶ms, "wet"); - - try self.delayCmd(pos, params); - }, - - .Vinyl => blk: { - const pos = try cmd.consumePosition(); - - try cmd.appendParam(¶ms, "year"); - try cmd.appendParam(¶ms, "rpm"); - try cmd.appendParam(¶ms, "warp"); - try cmd.appendParam(¶ms, "click"); - try cmd.appendParam(¶ms, "wear"); - - try self.vinylCmd(pos, params); - }, - - .RevDelay => blk: { - const pos = try cmd.consumePosition(); - - try cmd.appendParam(¶ms, "delay_time"); - try cmd.appendParam(¶ms, "dry_level"); - try cmd.appendParam(¶ms, "wet_level"); - try cmd.appendParam(¶ms, "feedback"); - try cmd.appendParam(¶ms, "xfade_samp"); - - try self.revDelayCmd(pos, params); - }, - .Noise => blk: { const pos = try cmd.consumePosition(); @@ -627,76 +469,38 @@ pub const Runner = struct { .Gate => { const pos = try cmd.consumePosition(); - try cmd.appendParam(¶ms, "switch"); - try cmd.appendParam(¶ms, "threshold"); - try cmd.appendParam(¶ms, "attack"); - try cmd.appendParam(¶ms, "hold"); - try cmd.appendParam(¶ms, "decay"); - try cmd.appendParam(¶ms, "gaterange"); try self.gateCmd(pos, params); }, .Detune => { const pos = try cmd.consumePosition(); - try cmd.appendParam(¶ms, "detune"); - try cmd.appendParam(¶ms, "mix"); - try cmd.appendParam(¶ms, "output"); - try cmd.appendParam(¶ms, "latency"); try self.detuneCmd(pos, params); }, .Overdrive => { const pos = try cmd.consumePosition(); - try cmd.appendParam(¶ms, "drive"); - try cmd.appendParam(¶ms, "muffle"); - try cmd.appendParam(¶ms, "output"); try self.overdriveCmd(pos, params); }, .Degrade => { const pos = try cmd.consumePosition(); - try cmd.appendParam(¶ms, "headroom"); - try cmd.appendParam(¶ms, "quant"); - try cmd.appendParam(¶ms, "rate"); - try cmd.appendParam(¶ms, "post_filt"); - try cmd.appendParam(¶ms, "non_lin"); - try cmd.appendParam(¶ms, "output"); try self.degradeCmd(pos, params); }, .RePsycho => { const pos = try cmd.consumePosition(); - try cmd.appendParam(¶ms, "tune"); - try cmd.appendParam(¶ms, "fine"); - try cmd.appendParam(¶ms, "decay"); - try cmd.appendParam(¶ms, "thresh"); - try cmd.appendParam(¶ms, "hold"); - try cmd.appendParam(¶ms, "mix"); - try cmd.appendParam(¶ms, "quality"); try self.repsychoCmd(pos, params); }, .TalkBox => { const pos = try cmd.consumePosition(); - try cmd.appendParam(¶ms, "wet"); - try cmd.appendParam(¶ms, "dry"); - try cmd.appendParam(¶ms, "carrier"); - try cmd.appendParam(¶ms, "quality"); + try self.talkboxCmd(pos, params); }, .DynComp => { const pos = try cmd.consumePosition(); - try cmd.appendParam(¶ms, "enable"); - try cmd.appendParam(¶ms, "hold"); - try cmd.appendParam(¶ms, "inputgain"); - try cmd.appendParam(¶ms, "threshold"); - try cmd.appendParam(¶ms, "ratio"); - try cmd.appendParam(¶ms, "attack"); - try cmd.appendParam(¶ms, "release"); - try cmd.appendParam(¶ms, "gain_min"); - try cmd.appendParam(¶ms, "gain_max"); - try cmd.appendParam(¶ms, "rms"); + try self.dynCompCmd(pos, params); }, From 0de2d05fa396d94ece6ac4b45c087682873d899a Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 17:54:43 -0300 Subject: [PATCH 093/182] fix detune command definition --- src/lang.zig | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 4fb3fb4..6d444c9 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -284,12 +284,6 @@ pub const Command = struct { gaterange: f32, }); pub const Detune = LV2Command(.detune, "http://drobilla.net/plugins/mda/Detune", struct { - @"switch": f32, - threshold: f32, - attack: f32, - hold: f32, - decay: f32, - gaterange: f32, detune: f32, mix: f32, output: f32, From 325e7b110286ebbb19d36d819109c8a06c3f8236 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 18:29:42 -0300 Subject: [PATCH 094/182] add support for the rest of lv2 commands --- src/lang.zig | 100 ++++++++++++++++++++++++++++++--- src/runner.zig | 149 +++---------------------------------------------- 2 files changed, 101 insertions(+), 148 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 6d444c9..a455a1f 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -105,13 +105,13 @@ pub const Command = struct { .dyncomp => Dyncomp, .thruzero => Thruzero, .foverdrive => Foverdrive, - // .gverb => Gverb, - // .invert => Invert, - // .tapedelay => Tapedelay, - // .moddelay => Moddelay, - // .multichorus => Multichorus, - // .saturator => Saturator, - // .vintagedelay => Vintagedelay, + .gverb => Gverb, + .invert => Invert, + .tapedelay => Tapedelay, + .moddelay => Moddelay, + .multichorus => Multichorus, + .saturator => Saturator, + .vintagedelay => Vintagedelay, else => @panic("TODO"), }; @@ -335,6 +335,92 @@ pub const Command = struct { pub const Thruzero = LV2Command(.thruzero, "http://drobilla.net/plugins/mda/ThruZero", struct { rate: f32, mix: f32, feedback: f32, depth_mod: f32 }); + + pub const Gverb = LV2Command(.gverb, "http://plugin.org.uk/swh-plugins/gverb", struct { + roomsize: f32, + revtime: f32, + damping: f32, + inputbandwidth: f32, + drylevel: f32, + earlylevel: f32, + taillevel: f32, + }); + pub const Invert = LV2Command(.invert, "http://plugin.org.uk/swh-plugins/inv", struct {}); + pub const Tapedelay = LV2Command(.tapedelay, "http://plugin.org.uk/swh-plugins/tapeDelay", struct { + speed: f32, + da_db: f32, + + t1d: f32, + t1a_db: f32, + + t2d: f32, + t2a_db: f32, + + t3d: f32, + t3a_db: f32, + + t4d: f32, + t4a_db: f32, + }); + pub const Moddelay = LV2Command(.moddelay, "http://plugin.org.uk/swh-plugins/modDelay", struct { + base: f32, + }); + + pub const Multichorus = LV2Command(.multichorus, "http://calf.sourceforge.net/plugins/MultiChorus", struct { + min_delay: f32, + mod_depth: f32, + mod_rate: f32, + stereo: f32, + voices: f32, + vphase: f32, + amount: f32, + dry: f32, + freq: f32, + freq2: f32, + q: f32, + overlap: f32, + level_in: f32, + level_out: f32, + lfo: f32, + }); + pub const Saturator = LV2Command(.saturator, "http://calf.sourceforge.net/plugins/Saturator", struct { + bypass: f32, + level_in: f32, + level_out: f32, + mix: f32, + drive: f32, + blend: f32, + lp_pre_freq: f32, + hp_pre_freq: f32, + lp_post_freq: f32, + hp_post_freq: f32, + p_freq: f32, + p_level: f32, + p_q: f32, + pre: f32, + post: f32, + }); + pub const Vintagedelay = LV2Command(.vintagedelay, "http://calf.sourceforge.net/plugins/VintageDelay", struct { + level_in: f32, + level_out: f32, + subdiv: f32, + time_l: f32, + time_r: f32, + feedback: f32, + amount: f32, + mix_mode: f32, + medium: f32, + dry: f32, + width: f32, + fragmentation: f32, + pbeats: f32, + pfrag: f32, + timing: f32, + bpm: f32, + ms: f32, + hz: f32, + bpm_host: f32, + }); }; pub const CommandList = std.ArrayList(*Command); diff --git a/src/runner.zig b/src/runner.zig index b4bf4af..7922c30 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -292,11 +292,6 @@ pub const Runner = struct { try image.runPlugin("http://plugin.org.uk/swh-plugins/gverb", pos, params); } - fn invertCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://plugin.org.uk/swh-plugins/inv", pos, params); - } - fn tapedelayCmd(self: *Runner, pos: Position, params: ParamList) !void { var image = try self.getImage(); try image.runPlugin("http://plugin.org.uk/swh-plugins/tapeDelay", pos, params); @@ -397,13 +392,13 @@ pub const Runner = struct { .dyncomp => try self.newRunCommandSingle(cmd, .dyncomp), .thruzero => try self.newRunCommandSingle(cmd, .thruzero), .foverdrive => try self.newRunCommandSingle(cmd, .foverdrive), - // .gverb => try self.newRunCommandSingle(cmd, .gverb), - // .invert => try self.newRunCommandSingle(cmd, .invert), - // .tapedelay => try self.newRunCommandSingle(cmd, .tapedelay), - // .moddelay => try self.newRunCommandSingle(cmd, .moddelay), - // .multichorus => try self.newRunCommandSingle(cmd, .multichorus), - // .saturator => try self.newRunCommandSingle(cmd, .saturator), - // .vintagedelay => try self.newRunCommandSingle(cmd, .vintagedelay), + .gverb => try self.newRunCommandSingle(cmd, .gverb), + .invert => try self.newRunCommandSingle(cmd, .invert), + .tapedelay => try self.newRunCommandSingle(cmd, .tapedelay), + .moddelay => try self.newRunCommandSingle(cmd, .moddelay), + .multichorus => try self.newRunCommandSingle(cmd, .multichorus), + .saturator => try self.newRunCommandSingle(cmd, .saturator), + .vintagedelay => try self.newRunCommandSingle(cmd, .vintagedelay), else => { std.debug.warn("TODO support {}\n", .{@tagName(cmd.tag)}); @@ -467,67 +462,8 @@ pub const Runner = struct { try self.rotateCmd(deg, bgfill); }, - .Gate => { - const pos = try cmd.consumePosition(); - try self.gateCmd(pos, params); - }, - - .Detune => { - const pos = try cmd.consumePosition(); - try self.detuneCmd(pos, params); - }, - - .Overdrive => { - const pos = try cmd.consumePosition(); - try self.overdriveCmd(pos, params); - }, - - .Degrade => { - const pos = try cmd.consumePosition(); - try self.degradeCmd(pos, params); - }, - - .RePsycho => { - const pos = try cmd.consumePosition(); - try self.repsychoCmd(pos, params); - }, - - .TalkBox => { - const pos = try cmd.consumePosition(); - - try self.talkboxCmd(pos, params); - }, - - .DynComp => { - const pos = try cmd.consumePosition(); - - try self.dynCompCmd(pos, params); - }, - - .ThruZero => { - const pos = try cmd.consumePosition(); - try cmd.appendParam(¶ms, "rate"); - try cmd.appendParam(¶ms, "mix"); - try cmd.appendParam(¶ms, "feedback"); - try cmd.appendParam(¶ms, "depth_mod"); - try self.thruZeroCmd(pos, params); - }, - - .Foverdrive => { - const pos = try cmd.consumePosition(); - try cmd.appendParam(¶ms, "drive"); - try self.foverdriveCmd(pos, params); - }, - .Gverb => { const pos = try cmd.consumePosition(); - try cmd.appendParam(¶ms, "roomsize"); - try cmd.appendParam(¶ms, "revtime"); - try cmd.appendParam(¶ms, "damping"); - try cmd.appendParam(¶ms, "inputbandwidth"); - try cmd.appendParam(¶ms, "drylevel"); - try cmd.appendParam(¶ms, "earlylevel"); - try cmd.appendParam(¶ms, "taillevel"); try self.gverbCmd(pos, params); }, @@ -538,20 +474,6 @@ pub const Runner = struct { .TapeDelay => { const pos = try cmd.consumePosition(); - try cmd.appendParam(¶ms, "speed"); - try cmd.appendParam(¶ms, "da_db"); - - try cmd.appendParam(¶ms, "t1d"); - try cmd.appendParam(¶ms, "t1a_db"); - - try cmd.appendParam(¶ms, "t2d"); - try cmd.appendParam(¶ms, "t2a_db"); - - try cmd.appendParam(¶ms, "t3d"); - try cmd.appendParam(¶ms, "t3a_db"); - - try cmd.appendParam(¶ms, "t4d"); - try cmd.appendParam(¶ms, "t4a_db"); try self.tapedelayCmd(pos, params); }, @@ -564,73 +486,18 @@ pub const Runner = struct { .MultiChorus => { const pos = try cmd.consumePosition(); - try cmd.appendParam(¶ms, "min_delay"); - try cmd.appendParam(¶ms, "mod_depth"); - try cmd.appendParam(¶ms, "mod_rate"); - try cmd.appendParam(¶ms, "stereo"); - try cmd.appendParam(¶ms, "voices"); - try cmd.appendParam(¶ms, "vphase"); - try cmd.appendParam(¶ms, "amount"); - try cmd.appendParam(¶ms, "dry"); - try cmd.appendParam(¶ms, "freq"); - try cmd.appendParam(¶ms, "freq2"); - try cmd.appendParam(¶ms, "q"); - try cmd.appendParam(¶ms, "overlap"); - try cmd.appendParam(¶ms, "level_in"); - try cmd.appendParam(¶ms, "level_out"); - try cmd.appendParam(¶ms, "lfo"); + try self.multichorusCmd(pos, params); }, .Saturator => { const pos = try cmd.consumePosition(); - try cmd.appendParam(¶ms, "bypass"); - try cmd.appendParam(¶ms, "level_in"); - try cmd.appendParam(¶ms, "level_out"); - try cmd.appendParam(¶ms, "mix"); - try cmd.appendParam(¶ms, "drive"); - try cmd.appendParam(¶ms, "blend"); - try cmd.appendParam(¶ms, "lp_pre_freq"); - try cmd.appendParam(¶ms, "hp_pre_freq"); - try cmd.appendParam(¶ms, "lp_post_freq"); - try cmd.appendParam(¶ms, "hp_post_freq"); - try cmd.appendParam(¶ms, "p_freq"); - try cmd.appendParam(¶ms, "p_level"); - try cmd.appendParam(¶ms, "p_q"); - try cmd.appendParam(¶ms, "pre"); - try cmd.appendParam(¶ms, "post"); try self.saturatorCmd(pos, params); }, .VintageDelay => { const pos = try cmd.consumePosition(); - const PARAMS = [_][]const u8{ - "level_in", - "level_out", - "subdiv", - "time_l", - "time_r", - "feedback", - "amount", - "mix_mode", - "medium", - "dry", - "width", - "fragmentation", - "pbeats", - "pfrag", - "timing", - "bpm", - "ms", - "hz", - "bpm_host", - }; - - inline for (PARAMS) |param| { - try cmd.appendParam(¶ms, param); - } - try self.vintagedelayCmd(pos, params); }, From 7543ecafaa38e4ef7ba8d063162cc48a35fa34ac Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 18:30:39 -0300 Subject: [PATCH 095/182] remove unused blocks of code --- src/runner.zig | 134 ------------------------------------------------- 1 file changed, 134 deletions(-) diff --git a/src/runner.zig b/src/runner.zig index 7922c30..e65bac0 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -190,26 +190,6 @@ pub const Runner = struct { _ = try proc.spawnAndWait(); } - fn highpassCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://invadarecords.com/plugins/lv2/filter/hpf/mono", pos, params); - } - - fn delayCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://plugin.org.uk/swh-plugins/delayorama", pos, params); - } - - fn vinylCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://plugin.org.uk/swh-plugins/vynil", pos, params); - } - - fn revDelayCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://plugin.org.uk/swh-plugins/revdelay", pos, params); - } - fn noiseCmd(self: *Runner, pos: Position, map: *ParamMap) !void { var image = try self.getImage(); try image.runCustomPlugin(custom.RandomNoise, pos, *ParamMap, map); @@ -242,81 +222,6 @@ pub const Runner = struct { try magick.runRotate(image, deg, c_bgfill); } - fn gateCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://hippie.lt/lv2/gate", pos, params); - } - - fn detuneCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://drobilla.net/plugins/mda/Detune", pos, params); - } - - fn overdriveCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://drobilla.net/plugins/mda/Overdrive", pos, params); - } - - fn degradeCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://drobilla.net/plugins/mda/Degrade", pos, params); - } - - fn repsychoCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://drobilla.net/plugins/mda/RePsycho", pos, params); - } - - fn talkboxCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://drobilla.net/plugins/mda/TalkBox", pos, params); - } - - fn dynCompCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://gareus.org/oss/lv2/darc#mono", pos, params); - } - - fn foverdriveCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://plugin.org.uk/swh-plugins/foverdrive", pos, params); - } - - fn thruZeroCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://drobilla.net/plugins/mda/ThruZero", pos, params); - } - - fn gverbCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://plugin.org.uk/swh-plugins/gverb", pos, params); - } - - fn tapedelayCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://plugin.org.uk/swh-plugins/tapeDelay", pos, params); - } - - fn moddelayCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://plugin.org.uk/swh-plugins/modDelay", pos, params); - } - - fn multichorusCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://calf.sourceforge.net/plugins/MultiChorus", pos, params); - } - - fn saturatorCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://calf.sourceforge.net/plugins/Saturator", pos, params); - } - - fn vintagedelayCmd(self: *Runner, pos: Position, params: ParamList) !void { - var image = try self.getImage(); - try image.runPlugin("http://calf.sourceforge.net/plugins/VintageDelay", pos, params); - } - fn executeLV2Command(self: *@This(), command: var) !void { const pos = plugin.Position{ .split = command.split, @@ -462,45 +367,6 @@ pub const Runner = struct { try self.rotateCmd(deg, bgfill); }, - .Gverb => { - const pos = try cmd.consumePosition(); - try self.gverbCmd(pos, params); - }, - - .Invert => { - const pos = try cmd.consumePosition(); - try self.gverbCmd(pos, params); - }, - - .TapeDelay => { - const pos = try cmd.consumePosition(); - - try self.tapedelayCmd(pos, params); - }, - - .ModDelay => { - const pos = try cmd.consumePosition(); - try cmd.appendParam(¶ms, "base"); - try self.moddelayCmd(pos, params); - }, - - .MultiChorus => { - const pos = try cmd.consumePosition(); - - try self.multichorusCmd(pos, params); - }, - - .Saturator => { - const pos = try cmd.consumePosition(); - - try self.saturatorCmd(pos, params); - }, - - .VintageDelay => { - const pos = try cmd.consumePosition(); - try self.vintagedelayCmd(pos, params); - }, - else => blk: { std.debug.warn("Unsupported command: {}\n", .{cmd.command}); break :blk RunError.UnknownCommand; From 8ce844ceed75fb41abda0cecf2e461c8cff2f9dc Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 21:10:43 -0300 Subject: [PATCH 096/182] add validation for split/index args --- src/lang.zig | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index a455a1f..89ed749 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -362,9 +362,14 @@ pub const Command = struct { t4d: f32, t4a_db: f32, }); - pub const Moddelay = LV2Command(.moddelay, "http://plugin.org.uk/swh-plugins/modDelay", struct { - base: f32, - }); + + pub const Moddelay = LV2Command( + .moddelay, + "http://plugin.org.uk/swh-plugins/modDelay", + struct { + base: f32, + }, + ); pub const Multichorus = LV2Command(.multichorus, "http://calf.sourceforge.net/plugins/MultiChorus", struct { min_delay: f32, @@ -471,8 +476,20 @@ pub const Lang = struct { // arguments... if (is_lv2_command) { - cmd.split = try std.fmt.parseInt(usize, tok_it.next().?, 10); - cmd.index = try std.fmt.parseInt(usize, tok_it.next().?, 10); + const split = tok_it.next(); + if (split == null) { + self.doError("Expected split parameter, got EOL", .{}); + return; + } + + const index = tok_it.next(); + if (index == null) { + self.doError("Expected index parameter, got EOL", .{}); + return; + } + + cmd.split = try std.fmt.parseInt(usize, split.?, 10); + cmd.index = try std.fmt.parseInt(usize, index.?, 10); inline for (@typeInfo(@TypeOf(cmd.parameters)).Struct.fields) |cmd_field| { const arg = tok_it.next().?; From d9358ed79408a4b4a0a096a9922d2b01860fc92c Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 21:25:25 -0300 Subject: [PATCH 097/182] add lv2 parameter validation --- src/lang.zig | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 89ed749..4db0cb7 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -453,7 +453,7 @@ pub const Lang = struct { self.line = 0; } fn doError(self: *Lang, comptime fmt: []const u8, args: var) void { - std.debug.warn("error at line {}: ", .{self.line}); + std.debug.warn("ERROR! at line {}: ", .{self.line}); std.debug.warn(fmt, args); std.debug.warn("\n", .{}); self.has_error = true; @@ -491,19 +491,21 @@ pub const Lang = struct { cmd.split = try std.fmt.parseInt(usize, split.?, 10); cmd.index = try std.fmt.parseInt(usize, index.?, 10); + // All parameters for LV2 plugins are f32. inline for (@typeInfo(@TypeOf(cmd.parameters)).Struct.fields) |cmd_field| { - const arg = tok_it.next().?; + const maybe_arg = tok_it.next(); + if (maybe_arg == null) { + self.doError("Expected parameter for {}, got nothing", .{cmd_field.name}); + return; + } + + const arg = maybe_arg.?; + const argument_value = switch (cmd_field.field_type) { f32 => try std.fmt.parseFloat(f32, arg), else => @compileError("LV2 parameter struct can only have f32 fields"), }; - std.debug.warn("parsing {}, arg of type {} => {}\n", .{ - @typeName(command_struct), - @typeName(@TypeOf(argument_value)), - argument_value, - }); - @field(cmd.parameters, cmd_field.name) = argument_value; } } else { From 82dc99d7d57e74e329799030bc5c95d7090ea7bc Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 21:26:27 -0300 Subject: [PATCH 098/182] remove unecessary switch --- src/lang.zig | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 4db0cb7..73ece6a 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -500,13 +500,10 @@ pub const Lang = struct { } const arg = maybe_arg.?; + if (cmd_field.field_type != f32) + @compileError("LV2 parameter struct can only have f32 fields"); - const argument_value = switch (cmd_field.field_type) { - f32 => try std.fmt.parseFloat(f32, arg), - else => @compileError("LV2 parameter struct can only have f32 fields"), - }; - - @field(cmd.parameters, cmd_field.name) = argument_value; + @field(cmd.parameters, cmd_field.name) = try std.fmt.parseFloat(f32, arg); } } else { inline for (@typeInfo(command_struct).Struct.fields) |cmd_field| { From ca751e58f7ea2aeb5b83be38154ca5dcb3791a86 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 21:33:19 -0300 Subject: [PATCH 099/182] add draft declarations for custom commands --- src/lang.zig | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/lang.zig b/src/lang.zig index 73ece6a..824a3bb 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -113,6 +113,13 @@ pub const Command = struct { .saturator => Saturator, .vintagedelay => Vintagedelay, + .noise => Noise, + .wildnoise => Wildnoise, + .write => Write, + .embed => Embed, + + .rotate => Rotate, + else => @panic("TODO"), }; } @@ -146,8 +153,37 @@ pub const Command = struct { pub const RunQS = struct { pub const base_tag = Tag.runqs; - program: []const u8, base: Command, + program: []const u8, + }; + + pub const Noise = CustomCommand(Tag.noise, custom.RandomNoise, struct { + seed: f32, + fill_bytes: f32, + }); + + pub const Wildnoise = CustomCommand(Tag.wildnoise, custom.WildNoise, struct { + seed: f32, + fill_bytes: f32, + }); + + pub const Write = CustomCommand(Tag.write, custom.Write, struct { + data: f32, + }); + + pub const Embed = struct { + pub const base_tag = Tag.embed; + base: Command, + split: usize, + index: usize, + path: []const u8, + }; + + pub const Rotate = struct { + pub const base_tag = Tag.rotate; + base: Command, + deg: usize, + bgfill: []const u8, }; pub const Amp = LV2Command( From e669b74ffb0b5444f2b77dc157c536bb524d5c8d Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 21:34:49 -0300 Subject: [PATCH 100/182] add CustomCommand function --- src/lang.zig | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/lang.zig b/src/lang.zig index 824a3bb..03a6c52 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -31,6 +31,23 @@ fn LV2Command( }; } +fn CustomCommand( + comptime tag: Command.tag, + comptime plugin: type, + comptime parameters: type, +) type { + return struct { + pub const base_tag = tag; + pub const command_type = CommandType.plugin_command; + pub const plugin_type = plugin; + + base: Command, + split: usize, + index: usize, + parameters: LV2Parameters, + }; +} + pub const Command = struct { tag: Tag, @@ -182,7 +199,7 @@ pub const Command = struct { pub const Rotate = struct { pub const base_tag = Tag.rotate; base: Command, - deg: usize, + deg: f32, bgfill: []const u8, }; From e8808c501bcf1136f98f2b777e03ffde4ef49ff8 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 21:38:18 -0300 Subject: [PATCH 101/182] make Embed follow existing custom plugin structure --- src/custom.zig | 4 ++-- src/lang.zig | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/custom.zig b/src/custom.zig index f346fa0..4f9bbc2 100644 --- a/src/custom.zig +++ b/src/custom.zig @@ -140,10 +140,10 @@ pub const Embed = struct { sndfile: *c.SNDFILE = undefined, buf: []f32 = undefined, - pub fn init(allocator: *std.mem.Allocator, filepath: []const u8) @This() { + pub fn init(allocator: *std.mem.Allocator, params: *plugins.ParmaMap) @This() { return Embed{ .allocator = allocator, - .filepath = filepath, + .filepath = params.get("path").?, }; } diff --git a/src/lang.zig b/src/lang.zig index 03a6c52..ef886b9 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -1,6 +1,7 @@ const std = @import("std"); const plugin = @import("plugin.zig"); +const custom = @import("custom.zig"); pub const ParseError = error{ OutOfMemory, @@ -188,13 +189,9 @@ pub const Command = struct { data: f32, }); - pub const Embed = struct { - pub const base_tag = Tag.embed; - base: Command, - split: usize, - index: usize, + pub const Embed = CustomCommand(Tag.write, custom.Embed, struct { path: []const u8, - }; + }); pub const Rotate = struct { pub const base_tag = Tag.rotate; From 1fac8c73128821630dad4c3c5e911e254a51c157 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 21:40:31 -0300 Subject: [PATCH 102/182] fix putting KV on a string --- src/custom.zig | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/custom.zig b/src/custom.zig index 4f9bbc2..a91bdd2 100644 --- a/src/custom.zig +++ b/src/custom.zig @@ -120,9 +120,8 @@ pub const Write = struct { allocator: *std.mem.Allocator, params: *plugins.ParamMap, ) Write { - const data = params.get("data").?; return Write{ - .data = data.value, + .data = params.get("data").?.value, }; } @@ -143,7 +142,7 @@ pub const Embed = struct { pub fn init(allocator: *std.mem.Allocator, params: *plugins.ParmaMap) @This() { return Embed{ .allocator = allocator, - .filepath = params.get("path").?, + .filepath = params.get("path").?.value, }; } From 1c1e525b1daf6cc32d5c62901bca4eb59414908f Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 21:47:31 -0300 Subject: [PATCH 103/182] add support for plugin command types --- src/runner.zig | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/runner.zig b/src/runner.zig index e65bac0..a1bed65 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -190,26 +190,6 @@ pub const Runner = struct { _ = try proc.spawnAndWait(); } - fn noiseCmd(self: *Runner, pos: Position, map: *ParamMap) !void { - var image = try self.getImage(); - try image.runCustomPlugin(custom.RandomNoise, pos, *ParamMap, map); - } - - fn wildNoiseCmd(self: *Runner, pos: Position, map: *ParamMap) !void { - var image = try self.getImage(); - try image.runCustomPlugin(custom.WildNoise, pos, *ParamMap, map); - } - - fn writeCmd(self: *Runner, pos: Position, map: *ParamMap) !void { - var image = try self.getImage(); - try image.runCustomPlugin(custom.Write, pos, *ParamMap, map); - } - - fn embedCmd(self: *Runner, pos: Position, path: []const u8) !void { - var image = try self.getImage(); - try image.runCustomPlugin(custom.Embed, pos, []const u8, path); - } - fn rotateCmd( self: *Runner, deg: f32, @@ -244,6 +224,26 @@ pub const Runner = struct { try image.runPlugin(typ.lv2_url, pos, params); } + fn executePlugin(self: *@This(), command: var) !void { + const pos = plugin.Position{ + .split = command.split, + .index = command.index, + }; + + var params = ParamMap.init(self.allocator); + defer params.deinit(); + + inline for (@typeInfo(@TypeOf(command.parameters)).Struct.fields) |cmd_field| { + try params.put( + cmd_field.name, + @field(command.parameters, cmd_field.name), + ); + } + + var image = try self.getImage(); + try image.runCustomPlugin(typ.plugin_type, pos, map); + } + fn newRunCommandSingle( self: *@This(), cmd: lang.Command, @@ -261,6 +261,7 @@ pub const Runner = struct { const ctype = typ.command_type; switch (ctype) { .lv2_command => try self.executeLV2Command(command.*), + .plugin_command => try self.executePlugin(command.*), else => @panic("TODO support command type"), } } @@ -305,6 +306,8 @@ pub const Runner = struct { .saturator => try self.newRunCommandSingle(cmd, .saturator), .vintagedelay => try self.newRunCommandSingle(cmd, .vintagedelay), + .noise, .wildnoise, .write, .embed => |tag| try self.newRunCommandSingle(cmd, tag), + else => { std.debug.warn("TODO support {}\n", .{@tagName(cmd.tag)}); @panic("TODO support tag"); From 303a40758df71dfda00c37808ac5c4c613f60b6c Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 21:55:03 -0300 Subject: [PATCH 104/182] make custom plugins always receive ParamMap --- src/image.zig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/image.zig b/src/image.zig index 7f8deb4..d677afa 100644 --- a/src/image.zig +++ b/src/image.zig @@ -422,8 +422,7 @@ pub const Image = struct { self: *Image, comptime Plugin: type, position: plugins.Position, - comptime ExtraType: type, - extra: ExtraType, + extra: *ParamMap, ) !void { var plugin_opt: ?Plugin = Plugin.init(self.allocator, extra); if (plugin_opt == null) { From 10b2c69605bf3be961579ee5fa8cfe24ca4d80c7 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 21:55:22 -0300 Subject: [PATCH 105/182] fix typos --- src/lang.zig | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index ef886b9..04195f5 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -13,6 +13,8 @@ pub const CommandType = enum { /// "LV2 Commands" are commands that receive split, index, and then receive /// any f64 arguments. lv2_command, + + custom_command, }; fn LV2Command( @@ -33,19 +35,19 @@ fn LV2Command( } fn CustomCommand( - comptime tag: Command.tag, - comptime plugin: type, - comptime parameters: type, + comptime tag: Command.Tag, + comptime Plugin: type, + comptime PluginParameters: type, ) type { return struct { pub const base_tag = tag; - pub const command_type = CommandType.plugin_command; - pub const plugin_type = plugin; + pub const command_type = CommandType.custom_command; + pub const plugin_type = Plugin; base: Command, split: usize, index: usize, - parameters: LV2Parameters, + parameters: PluginParameters, }; } From 83996b889fba82dc24f716203f2450b59fa622dc Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 21:55:27 -0300 Subject: [PATCH 106/182] make rotate not be a typed command --- src/lang.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lang.zig b/src/lang.zig index 04195f5..cc8d58a 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -520,7 +520,7 @@ pub const Lang = struct { // Based on the command struct fields, we can parse the arguments. var cmd = try self.allocator.create(command_struct); const is_lv2_command = switch (command_struct.base_tag) { - .noop, .load, .quicksave, .runqs => false, + .noop, .load, .quicksave, .runqs, .rotate => false, else => command_struct.command_type == .lv2_command, }; From 2b4f4288903a0952f44bdc916b68c07a3227c92c Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 21:55:44 -0300 Subject: [PATCH 107/182] fix typo --- src/runner.zig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/runner.zig b/src/runner.zig index a1bed65..efaf568 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -234,14 +234,14 @@ pub const Runner = struct { defer params.deinit(); inline for (@typeInfo(@TypeOf(command.parameters)).Struct.fields) |cmd_field| { - try params.put( + _ = try params.put( cmd_field.name, @field(command.parameters, cmd_field.name), ); } var image = try self.getImage(); - try image.runCustomPlugin(typ.plugin_type, pos, map); + try image.runCustomPlugin(@TypeOf(command).plugin_type, pos, ¶ms); } fn newRunCommandSingle( @@ -261,7 +261,7 @@ pub const Runner = struct { const ctype = typ.command_type; switch (ctype) { .lv2_command => try self.executeLV2Command(command.*), - .plugin_command => try self.executePlugin(command.*), + .custom_command => try self.executePlugin(command.*), else => @panic("TODO support command type"), } } From 9801e303c0fbeaf8617a1cccd8b90f934c8777cd Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 21:55:48 -0300 Subject: [PATCH 108/182] flatten switch values --- src/runner.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/runner.zig b/src/runner.zig index efaf568..db40493 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -306,7 +306,10 @@ pub const Runner = struct { .saturator => try self.newRunCommandSingle(cmd, .saturator), .vintagedelay => try self.newRunCommandSingle(cmd, .vintagedelay), - .noise, .wildnoise, .write, .embed => |tag| try self.newRunCommandSingle(cmd, tag), + .noise => try self.newRunCommandSingle(cmd, .noise), + .wildnoise => try self.newRunCommandSingle(cmd, .wildnoise), + .write => try self.newRunCommandSingle(cmd, .write), + .embed => try self.newRunCommandSingle(cmd, .embed), else => { std.debug.warn("TODO support {}\n", .{@tagName(cmd.tag)}); From 89afa8af106dfce777ce83817aecc3507a63de43 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 22:27:11 -0300 Subject: [PATCH 109/182] convert from ParamMap to ducktyped param struct --- src/custom.zig | 30 ++++++++++++------------------ src/image.zig | 2 +- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/custom.zig b/src/custom.zig index a91bdd2..0420bd3 100644 --- a/src/custom.zig +++ b/src/custom.zig @@ -16,15 +16,12 @@ pub const RandomNoise = struct { pub fn init( allocator: *std.mem.Allocator, - params: *plugins.ParamMap, + params: var, ) ?RandomNoise { - const seed = @floatToInt(u64, params.get("seed").?.value); - const fillbytes = @floatToInt(usize, params.get("fill_bytes").?.value); + var r = std.rand.DefaultPrng.init(params.seed); - var r = std.rand.DefaultPrng.init(seed); - - if (fillbytes > 0) { - var rand_buf = allocator.alloc(f32, fillbytes) catch return null; + if (params.fill_bytes > 0) { + var rand_buf = allocator.alloc(f32, params.fill_bytes) catch return null; for (rand_buf) |_, idx| { rand_buf[idx] = r.random.float(f32); @@ -67,15 +64,12 @@ pub const WildNoise = struct { pub fn init( allocator: *std.mem.Allocator, - params: *plugins.ParamMap, + params: var, ) ?WildNoise { - const seed = @floatToInt(u64, params.get("seed").?.value); - const fillbytes = @floatToInt(usize, params.get("fill_bytes").?.value); + var r = std.rand.DefaultPrng.init(params.seed); - var r = std.rand.DefaultPrng.init(seed); - - if (fillbytes > 0) { - var rand_buf = allocator.alloc(f32, fillbytes) catch return null; + if (params.fill_bytes > 0) { + var rand_buf = allocator.alloc(f32, params.fill_bytes) catch return null; for (rand_buf) |_, idx| { rand_buf[idx] = @intToFloat(f32, r.random.int(u1)); @@ -118,10 +112,10 @@ pub const Write = struct { pub fn init( allocator: *std.mem.Allocator, - params: *plugins.ParamMap, + params: var, ) Write { return Write{ - .data = params.get("data").?.value, + .data = params.data, }; } @@ -139,10 +133,10 @@ pub const Embed = struct { sndfile: *c.SNDFILE = undefined, buf: []f32 = undefined, - pub fn init(allocator: *std.mem.Allocator, params: *plugins.ParmaMap) @This() { + pub fn init(allocator: *std.mem.Allocator, params: var) @This() { return Embed{ .allocator = allocator, - .filepath = params.get("path").?.value, + .filepath = params.path, }; } diff --git a/src/image.zig b/src/image.zig index d677afa..b9202ef 100644 --- a/src/image.zig +++ b/src/image.zig @@ -422,7 +422,7 @@ pub const Image = struct { self: *Image, comptime Plugin: type, position: plugins.Position, - extra: *ParamMap, + extra: var, ) !void { var plugin_opt: ?Plugin = Plugin.init(self.allocator, extra); if (plugin_opt == null) { From 30da41293a074b990320816fbdf56a05d1d337bf Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 22:27:24 -0300 Subject: [PATCH 110/182] fix type defs for noise cmds --- src/lang.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index cc8d58a..05f631f 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -178,13 +178,13 @@ pub const Command = struct { }; pub const Noise = CustomCommand(Tag.noise, custom.RandomNoise, struct { - seed: f32, - fill_bytes: f32, + seed: u64, + fill_bytes: usize, }); pub const Wildnoise = CustomCommand(Tag.wildnoise, custom.WildNoise, struct { - seed: f32, - fill_bytes: f32, + seed: u64, + fill_bytes: usize, }); pub const Write = CustomCommand(Tag.write, custom.Write, struct { From 690ab89cfddbc1d513776eee2e388a64f5894fb1 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 22:27:38 -0300 Subject: [PATCH 111/182] allow any typed command to use lv2 param parse logic --- src/lang.zig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 05f631f..329aa7e 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -521,7 +521,7 @@ pub const Lang = struct { var cmd = try self.allocator.create(command_struct); const is_lv2_command = switch (command_struct.base_tag) { .noop, .load, .quicksave, .runqs, .rotate => false, - else => command_struct.command_type == .lv2_command, + else => true, }; // TODO: crash when no arguments are left but we still need @@ -543,7 +543,6 @@ pub const Lang = struct { cmd.split = try std.fmt.parseInt(usize, split.?, 10); cmd.index = try std.fmt.parseInt(usize, index.?, 10); - // All parameters for LV2 plugins are f32. inline for (@typeInfo(@TypeOf(cmd.parameters)).Struct.fields) |cmd_field| { const maybe_arg = tok_it.next(); if (maybe_arg == null) { From 72379e63ee5a6a64fcdbbba58d0d34f16d489227 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 22:27:56 -0300 Subject: [PATCH 112/182] add support for more types on lv2 parameter structs --- src/lang.zig | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 329aa7e..3b7a542 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -551,10 +551,15 @@ pub const Lang = struct { } const arg = maybe_arg.?; - if (cmd_field.field_type != f32) - @compileError("LV2 parameter struct can only have f32 fields"); + const arg_value = switch (cmd_field.field_type) { + f32 => try std.fmt.parseFloat(f32, arg), + u64 => try std.fmt.parseInt(u64, arg, 10), + usize => try std.fmt.parseInt(usize, arg, 10), + []const u8 => try self.allocator.dupe(u8, arg), + else => @compileError("parameter struct has unsupported type " ++ @typeName(cmd_field.field_type)), + }; - @field(cmd.parameters, cmd_field.name) = try std.fmt.parseFloat(f32, arg); + @field(cmd.parameters, cmd_field.name) = arg_value; } } else { inline for (@typeInfo(command_struct).Struct.fields) |cmd_field| { @@ -569,7 +574,7 @@ pub const Lang = struct { i32 => try std.fmt.parseInt(i32, arg, 10), f32 => try std.fmt.parseFloat(f32, arg), []const u8 => try self.allocator.dupe(u8, arg), - else => @panic("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."), + else => @compileError("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."), }; std.debug.warn("parsing {}, arg of type {} => {}\n", .{ From 36937a5fdeee43e0b64e35059274f0b21e68a649 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 31 May 2020 22:28:10 -0300 Subject: [PATCH 113/182] remove ParamMap creation from runner --- src/runner.zig | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/runner.zig b/src/runner.zig index db40493..dd5fcd2 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -230,18 +230,8 @@ pub const Runner = struct { .index = command.index, }; - var params = ParamMap.init(self.allocator); - defer params.deinit(); - - inline for (@typeInfo(@TypeOf(command.parameters)).Struct.fields) |cmd_field| { - _ = try params.put( - cmd_field.name, - @field(command.parameters, cmd_field.name), - ); - } - var image = try self.getImage(); - try image.runCustomPlugin(@TypeOf(command).plugin_type, pos, ¶ms); + try image.runCustomPlugin(@TypeOf(command).plugin_type, pos, command.parameters); } fn newRunCommandSingle( From b238517b3399ed634f15b9206782bb565ef0d8d5 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 21:41:10 -0300 Subject: [PATCH 114/182] update symbols for Dyncomp --- src/lang.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lang.zig b/src/lang.zig index 3b7a542..2a506c2 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -374,7 +374,7 @@ pub const Command = struct { hold: f32, inputgain: f32, threshold: f32, - ratio: f32, + Ratio: f32, attack: f32, release: f32, gain_min: f32, From 76b353e5934d406f634fb7bfac6811072d9a019f Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 21:51:51 -0300 Subject: [PATCH 115/182] remove code for old runner commands --- src/runner.zig | 63 -------------------------------------------------- 1 file changed, 63 deletions(-) diff --git a/src/runner.zig b/src/runner.zig index dd5fcd2..def019d 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -307,69 +307,6 @@ pub const Runner = struct { }, } } - - fn runCommand(self: *Runner, cmd: *lang.Command) !void { - var params = ParamList.init(self.allocator); - defer params.deinit(); - - var map = ParamMap.init(self.allocator); - defer map.deinit(); - - return switch (cmd.command) { - .Noop => {}, - .Load => blk: { - var path = cmd.args.items[0]; - try self.loadCmd(path); - - // TODO is this needed? - break :blk; - }, - .Quicksave => try self.quicksaveCmd(), - .RunQS => try self.runQSCmd(cmd.args.items[0]), - - .Noise => blk: { - const pos = try cmd.consumePosition(); - - try cmd.appendParamMap(&map, "seed"); - try cmd.appendParamMap(&map, "fill_bytes"); - - try self.noiseCmd(pos, &map); - }, - - .WildNoise => blk: { - const pos = try cmd.consumePosition(); - - try cmd.appendParamMap(&map, "seed"); - try cmd.appendParamMap(&map, "fill_bytes"); - - try self.wildNoiseCmd(pos, &map); - }, - - .Write => blk: { - const pos = try cmd.consumePosition(); - try cmd.appendParamMap(&map, "data"); - try self.writeCmd(pos, &map); - }, - - .Embed => blk: { - const pos = try cmd.consumePosition(); - const path = cmd.args.items[2]; - try self.embedCmd(pos, path); - }, - - .Rotate => blk: { - const deg = try cmd.floatArgAt(0); - const bgfill = try cmd.argAt(1); - try self.rotateCmd(deg, bgfill); - }, - - else => blk: { - std.debug.warn("Unsupported command: {}\n", .{cmd.command}); - break :blk RunError.UnknownCommand; - }, - }; - } - /// Run a list of commands. pub fn runCommands( self: *Runner, From 54919110a5c63b951bdf83d5b98f5dfb8593be0b Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 21:54:10 -0300 Subject: [PATCH 116/182] refactor: remove 'new' prefix from functions --- src/runner.zig | 74 +++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/runner.zig b/src/runner.zig index def019d..c4b916d 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -224,7 +224,7 @@ pub const Runner = struct { try image.runPlugin(typ.lv2_url, pos, params); } - fn executePlugin(self: *@This(), command: var) !void { + fn executeCustomCommand(self: *@This(), command: var) !void { const pos = plugin.Position{ .split = command.split, .index = command.index, @@ -234,7 +234,7 @@ pub const Runner = struct { try image.runCustomPlugin(@TypeOf(command).plugin_type, pos, command.parameters); } - fn newRunCommandSingle( + fn runSingleCommand( self: *@This(), cmd: lang.Command, comptime tag: lang.Command.Tag, @@ -251,13 +251,13 @@ pub const Runner = struct { const ctype = typ.command_type; switch (ctype) { .lv2_command => try self.executeLV2Command(command.*), - .custom_command => try self.executePlugin(command.*), + .custom_command => try self.executeCustomCommand(command.*), else => @panic("TODO support command type"), } } } - fn newRunCommand(self: *@This(), cmd: lang.Command) !void { + fn runCommand(self: *@This(), cmd: lang.Command) !void { switch (cmd.tag) { .load => { const command = cmd.cast(lang.Command.Load).?; @@ -266,40 +266,40 @@ pub const Runner = struct { .quicksave => { try self.quicksaveCmd(); }, - .amp => try self.newRunCommandSingle(cmd, .amp), + .amp => try self.runSingleCommand(cmd, .amp), - .rflanger => try self.newRunCommandSingle(cmd, .rflanger), - .eq => try self.newRunCommandSingle(cmd, .eq), - .phaser => try self.newRunCommandSingle(cmd, .phaser), - .mbeq => try self.newRunCommandSingle(cmd, .mbeq), - .chorus => try self.newRunCommandSingle(cmd, .chorus), - .pitchscaler => try self.newRunCommandSingle(cmd, .pitchscaler), - .reverb => try self.newRunCommandSingle(cmd, .reverb), - .highpass => try self.newRunCommandSingle(cmd, .highpass), - .delay => try self.newRunCommandSingle(cmd, .delay), - .vinyl => try self.newRunCommandSingle(cmd, .vinyl), - .revdelay => try self.newRunCommandSingle(cmd, .revdelay), - .gate => try self.newRunCommandSingle(cmd, .gate), - .detune => try self.newRunCommandSingle(cmd, .detune), - .overdrive => try self.newRunCommandSingle(cmd, .overdrive), - .degrade => try self.newRunCommandSingle(cmd, .degrade), - .repsycho => try self.newRunCommandSingle(cmd, .repsycho), - .talkbox => try self.newRunCommandSingle(cmd, .talkbox), - .dyncomp => try self.newRunCommandSingle(cmd, .dyncomp), - .thruzero => try self.newRunCommandSingle(cmd, .thruzero), - .foverdrive => try self.newRunCommandSingle(cmd, .foverdrive), - .gverb => try self.newRunCommandSingle(cmd, .gverb), - .invert => try self.newRunCommandSingle(cmd, .invert), - .tapedelay => try self.newRunCommandSingle(cmd, .tapedelay), - .moddelay => try self.newRunCommandSingle(cmd, .moddelay), - .multichorus => try self.newRunCommandSingle(cmd, .multichorus), - .saturator => try self.newRunCommandSingle(cmd, .saturator), - .vintagedelay => try self.newRunCommandSingle(cmd, .vintagedelay), + .rflanger => try self.runSingleCommand(cmd, .rflanger), + .eq => try self.runSingleCommand(cmd, .eq), + .phaser => try self.runSingleCommand(cmd, .phaser), + .mbeq => try self.runSingleCommand(cmd, .mbeq), + .chorus => try self.runSingleCommand(cmd, .chorus), + .pitchscaler => try self.runSingleCommand(cmd, .pitchscaler), + .reverb => try self.runSingleCommand(cmd, .reverb), + .highpass => try self.runSingleCommand(cmd, .highpass), + .delay => try self.runSingleCommand(cmd, .delay), + .vinyl => try self.runSingleCommand(cmd, .vinyl), + .revdelay => try self.runSingleCommand(cmd, .revdelay), + .gate => try self.runSingleCommand(cmd, .gate), + .detune => try self.runSingleCommand(cmd, .detune), + .overdrive => try self.runSingleCommand(cmd, .overdrive), + .degrade => try self.runSingleCommand(cmd, .degrade), + .repsycho => try self.runSingleCommand(cmd, .repsycho), + .talkbox => try self.runSingleCommand(cmd, .talkbox), + .dyncomp => try self.runSingleCommand(cmd, .dyncomp), + .thruzero => try self.runSingleCommand(cmd, .thruzero), + .foverdrive => try self.runSingleCommand(cmd, .foverdrive), + .gverb => try self.runSingleCommand(cmd, .gverb), + .invert => try self.runSingleCommand(cmd, .invert), + .tapedelay => try self.runSingleCommand(cmd, .tapedelay), + .moddelay => try self.runSingleCommand(cmd, .moddelay), + .multichorus => try self.runSingleCommand(cmd, .multichorus), + .saturator => try self.runSingleCommand(cmd, .saturator), + .vintagedelay => try self.runSingleCommand(cmd, .vintagedelay), - .noise => try self.newRunCommandSingle(cmd, .noise), - .wildnoise => try self.newRunCommandSingle(cmd, .wildnoise), - .write => try self.newRunCommandSingle(cmd, .write), - .embed => try self.newRunCommandSingle(cmd, .embed), + .noise => try self.runSingleCommand(cmd, .noise), + .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)}); @@ -315,7 +315,7 @@ pub const Runner = struct { ) !void { for (cmds.items) |cmd| { cmd.print(); - try self.newRunCommand(cmd.*); + try self.runCommand(cmd.*); } } }; From b0525f23862d98900799be4d0c1c031eb3a5ff9b Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 22:06:15 -0300 Subject: [PATCH 117/182] add proper support on rotateCmd for lang.Command.Rotate --- src/runner.zig | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/runner.zig b/src/runner.zig index c4b916d..445c391 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -190,16 +190,14 @@ pub const Runner = struct { _ = try proc.spawnAndWait(); } - fn rotateCmd( - self: *Runner, - deg: f32, - bgfill: []const u8, - ) !void { + fn rotateCmd(self: *Runner, cmd: lang.Command) !void { + const rotate_cmd = cmd.cast(lang.Command.Rotate).?; + var image = try self.getImage(); - var c_bgfill = try std.cstr.addNullByte(self.allocator, bgfill); + var c_bgfill = try std.cstr.addNullByte(self.allocator, rotate_cmd.bgfill); defer self.allocator.free(c_bgfill); - try magick.runRotate(image, deg, c_bgfill); + try magick.runRotate(image, rotate_cmd.deg, c_bgfill); } fn executeLV2Command(self: *@This(), command: var) !void { @@ -263,11 +261,10 @@ pub const Runner = struct { const command = cmd.cast(lang.Command.Load).?; try self.loadCmd(command.path); }, - .quicksave => { - try self.quicksaveCmd(); - }, - .amp => try self.runSingleCommand(cmd, .amp), + .quicksave => try self.quicksaveCmd(), + .rotate => try self.rotateCmd(cmd), + .amp => try self.runSingleCommand(cmd, .amp), .rflanger => try self.runSingleCommand(cmd, .rflanger), .eq => try self.runSingleCommand(cmd, .eq), .phaser => try self.runSingleCommand(cmd, .phaser), From 0b816a512e3513d256717d030c831602fd2e452d Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 22:08:01 -0300 Subject: [PATCH 118/182] lang: remove unused declarations --- src/lang.zig | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 2a506c2..b8f5a85 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -3,11 +3,7 @@ const std = @import("std"); const plugin = @import("plugin.zig"); const custom = @import("custom.zig"); -pub const ParseError = error{ - OutOfMemory, - ArgRequired, - ParseFail, -}; +pub const ParseError = error{ParseFail}; pub const CommandType = enum { /// "LV2 Commands" are commands that receive split, index, and then receive @@ -481,9 +477,6 @@ pub const Command = struct { }; pub const CommandList = std.ArrayList(*Command); -pub const ArgList = std.ArrayList([]const u8); - -pub const KeywordMap = std.StringHashMap(CommandType); /// A parser. pub const Lang = struct { @@ -653,8 +646,6 @@ pub const Lang = struct { self.doError("Unknown command '{}' ({})", .{ command_string, command_string.len }); continue; } - - // try cmds.append(cmd); } if (self.has_error) return ParseError.ParseFail; From b00ab8e839967612cbc813e144398db9ae0bff94 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 22:14:12 -0300 Subject: [PATCH 119/182] remove the big switch when printing commands --- src/printer.zig | 44 +------------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/src/printer.zig b/src/printer.zig index ea91ec2..b7592db 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -2,49 +2,7 @@ const langs = @import("lang.zig"); pub fn printList(list: langs.CommandList, stream: var) !void { for (list.items) |cmd| { - var command = switch (cmd.command) { - .Noop => "noop", - .Load => "load", - .Quicksave => "quicksave", - .RunQS => "runqs", - - .Amp => "amp", - .RFlanger => "rflanger", - .Eq => "eq", - .Phaser => "phaser", - .Mbeq => "mbeq", - .Chorus => "chorus", - .PitchScaler => "pitchscaler", - .Reverb => "reverb", - .Highpass => "highpass", - .Delay => "delay", - .Vinyl => "vinyl", - .RevDelay => "revdelay", - .Gate => "gate", - .Detune => "detune", - .Overdrive => "overdrive", - .Degrade => "Degrade", - .RePsycho => "repsycho", - .TalkBox => "talkbox", - .DynComp => "dyncomp", - .ThruZero => "thruzero", - .Foverdrive => "foverdrive", - .Gverb => "gverb", - .Invert => "invert", - .TapeDelay => "tapedelay", - .ModDelay => "moddelay", - .MultiChorus => "multichorus", - .Saturator => "saturator", - .VintageDelay => "vintagedelay", - - .Noise => "noise", - .WildNoise => "wildnoise", - .Write => "write", - .Embed => "embed", - - .Rotate => "rotate", - }; - + const command = @tagName(cmd.tag); try stream.print("{}", .{command}); for (cmd.args.items) |arg| { From 9cb82e3180b2325ab95170f81e60c415f41fee36 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 22:34:48 -0300 Subject: [PATCH 120/182] remove unecessary code --- src/runner.zig | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/src/runner.zig b/src/runner.zig index 445c391..036975d 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -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. From e71eba583e2a92928d72821e2444c35ced987979 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 22:34:56 -0300 Subject: [PATCH 121/182] make load command own its path memory --- src/lang.zig | 3 ++- src/main.zig | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index b8f5a85..305eb4a 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -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) ++ "."), }; diff --git a/src/main.zig b/src/main.zig index 9971f24..1553aff 100644 --- a/src/main.zig +++ b/src/main.zig @@ -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| { From 128f58c5022104937c7d08cbefd1ffb83acfe737 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 22:35:07 -0300 Subject: [PATCH 122/182] re-enable repl --- src/main.zig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.zig b/src/main.zig index 1553aff..541ba53 100644 --- a/src/main.zig +++ b/src/main.zig @@ -188,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, .{}); From f973d6807daa3d34cb1d14c47b3010419962d61b Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 22:35:16 -0300 Subject: [PATCH 123/182] add basics of printing under new command structure --- src/printer.zig | 66 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/src/printer.zig b/src/printer.zig index b7592db..73a0e8a 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -1,12 +1,74 @@ 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), + + else => @compileError("unhandled command"), } _ = try stream.write(";\n"); From b06bab9ec56bc10f5eddcd89398b5dbee311c944 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 22:35:29 -0300 Subject: [PATCH 124/182] remove unecessary compileError call --- src/printer.zig | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/printer.zig b/src/printer.zig index 73a0e8a..3efdde7 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -67,8 +67,6 @@ pub fn printList(list: langs.CommandList, stream: var) !void { .wildnoise => try printCommand(cmd, .wildnoise), .write => try printCommand(cmd, .write), .embed => try printCommand(cmd, .embed), - - else => @compileError("unhandled command"), } _ = try stream.write(";\n"); From 7f008db540eb554e89ec8eb63429edd9184506d0 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 22:45:35 -0300 Subject: [PATCH 125/182] part 2 of printing commands --- src/printer.zig | 93 +++++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/src/printer.zig b/src/printer.zig index 3efdde7..0cf8e85 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -1,6 +1,13 @@ const langs = @import("lang.zig"); -pub fn printCommand(cmd: langs.Command, comptime tag: langs.Command.Tag) !void { +fn printCommandWithParams(stream: var, command: var) !void { + const Parameters = @TypeOf(command.parameters); + inline for (@typeInfo(Parameters).Struct.fields) |field| { + try stream.print(" {}", .{@field(command.parameters, field.name)}); + } +} + +fn printCommand(stream: var, cmd: *langs.Command, comptime tag: langs.Command.Tag) !void { const CommandStruct = langs.Command.tagToType(tag); const casted = cmd.cast(CommandStruct).?; @@ -10,10 +17,10 @@ pub fn printCommand(cmd: langs.Command, comptime tag: langs.Command.Tag) !void { else => true, }; - const ctype = typ.command_type; + const ctype = CommandStruct.command_type; switch (ctype) { - .lv2_command => try printLV2Command(casted), - .custom_command => try printCustomCommand(casted), + .lv2_command => try printCommandWithParams(stream, casted), + .custom_command => try printCommandWithParams(stream, casted), else => @panic("TODO support command type"), } } @@ -25,48 +32,52 @@ pub fn printList(list: langs.CommandList, stream: var) !void { switch (cmd.tag) { .load => { - const load = command.cast(langs.Command.Load).?; - try stream.print("{}", .{load.path}); + const load = cmd.cast(langs.Command.Load).?; + try stream.print(" {}", .{load.path}); }, - .quicksave => {}, + .runqs => { + const runqs = cmd.cast(langs.Command.RunQS).?; + try stream.print(" {}", .{runqs.program}); + }, + .noop, .quicksave => {}, .rotate => { - const rotate = command.cast(langs.Command.Rotate).?; - try stream.print("{} {}", .{ rotate.deg, rotate.bgfill }); + const rotate = cmd.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), + .amp => try printCommand(stream, cmd, .amp), + .rflanger => try printCommand(stream, cmd, .rflanger), + .eq => try printCommand(stream, cmd, .eq), + .phaser => try printCommand(stream, cmd, .phaser), + .mbeq => try printCommand(stream, cmd, .mbeq), + .chorus => try printCommand(stream, cmd, .chorus), + .pitchscaler => try printCommand(stream, cmd, .pitchscaler), + .reverb => try printCommand(stream, cmd, .reverb), + .highpass => try printCommand(stream, cmd, .highpass), + .delay => try printCommand(stream, cmd, .delay), + .vinyl => try printCommand(stream, cmd, .vinyl), + .revdelay => try printCommand(stream, cmd, .revdelay), + .gate => try printCommand(stream, cmd, .gate), + .detune => try printCommand(stream, cmd, .detune), + .overdrive => try printCommand(stream, cmd, .overdrive), + .degrade => try printCommand(stream, cmd, .degrade), + .repsycho => try printCommand(stream, cmd, .repsycho), + .talkbox => try printCommand(stream, cmd, .talkbox), + .dyncomp => try printCommand(stream, cmd, .dyncomp), + .thruzero => try printCommand(stream, cmd, .thruzero), + .foverdrive => try printCommand(stream, cmd, .foverdrive), + .gverb => try printCommand(stream, cmd, .gverb), + .invert => try printCommand(stream, cmd, .invert), + .tapedelay => try printCommand(stream, cmd, .tapedelay), + .moddelay => try printCommand(stream, cmd, .moddelay), + .multichorus => try printCommand(stream, cmd, .multichorus), + .saturator => try printCommand(stream, cmd, .saturator), + .vintagedelay => try printCommand(stream, cmd, .vintagedelay), - .noise => try printCommand(cmd, .noise), - .wildnoise => try printCommand(cmd, .wildnoise), - .write => try printCommand(cmd, .write), - .embed => try printCommand(cmd, .embed), + .noise => try printCommand(stream, cmd, .noise), + .wildnoise => try printCommand(stream, cmd, .wildnoise), + .write => try printCommand(stream, cmd, .write), + .embed => try printCommand(stream, cmd, .embed), } _ = try stream.write(";\n"); From 0453f3730556c178ca50a9e5ae82569e329fd736 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 22:47:21 -0300 Subject: [PATCH 126/182] add noop, runqs support to runner --- src/runner.zig | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/runner.zig b/src/runner.zig index 036975d..6b9f478 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -175,18 +175,19 @@ pub const Runner = struct { try image.saveTo(out_path); } - fn runQSCmd(self: *Runner, program: []const u8) !void { + fn runQSCmd(self: *Runner, cmd: lang.Command) !void { + const runqs = cmd.cast(lang.Command.RunQS).?; var image = try self.getImage(); const out_path = try self.makeGlitchedPath(); try image.saveTo(out_path); var proc = try std.ChildProcess.init( - &[_][]const u8{ program, out_path }, + &[_][]const u8{ runqs.program, out_path }, self.allocator, ); defer proc.deinit(); - std.debug.warn("running '{} {}'\n", .{ program, out_path }); + std.debug.warn("running '{} {}'\n", .{ runqs.program, out_path }); _ = try proc.spawnAndWait(); } @@ -249,12 +250,14 @@ pub const Runner = struct { fn runCommand(self: *@This(), cmd: lang.Command) !void { switch (cmd.tag) { + .noop => {}, .load => { const command = cmd.cast(lang.Command.Load).?; try self.loadCmd(command.path); }, .quicksave => try self.quicksaveCmd(), .rotate => try self.rotateCmd(cmd), + .runqs => try self.runQSCmd(cmd), .amp => try self.runSingleCommand(cmd, .amp), .rflanger => try self.runSingleCommand(cmd, .rflanger), From ee7ffd1be7d8f5f5f58f193b924445a548261b28 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 23:10:30 -0300 Subject: [PATCH 127/182] move repl commands to the heap --- src/main.zig | 78 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 12 deletions(-) diff --git a/src/main.zig b/src/main.zig index 541ba53..a2716d7 100644 --- a/src/main.zig +++ b/src/main.zig @@ -16,12 +16,26 @@ const readline = @cImport({ @cInclude("readline/history.h"); }); -fn wrapInCmdList(allocator: *std.mem.Allocator, cmd: langs.Command) !langs.CommandList { +fn wrapInCmdList(allocator: *std.mem.Allocator, cmd: *langs.Command) !langs.CommandList { var cmds = langs.CommandList.init(allocator); try cmds.append(cmd); return cmds; } +fn copyCommandToHeap(allocator: *std.mem.Allocator, command: langs.Command, comptime tag: langs.Command.Tag) !*langs.Command { + const CommandStruct = langs.Command.tagToType(tag); + const casted = command.cast(CommandStruct).?; + var heap_cmd = try allocator.create(CommandStruct); + + @memcpy( + @ptrCast([*]u8, &heap_cmd), + @ptrCast([*]const u8, &casted), + @sizeOf(CommandStruct), + ); + + return &heap_cmd.base; +} + pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { var stdout_file = std.io.getStdOut(); const stdout = &stdout_file.outStream(); @@ -104,11 +118,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(); - const wanted_runner: []const u8 = std.os.getenv("SCRITCHER_RUNNER") orelse "ristretto"; - try runqs_args.append(wanted_runner); + + var runqs_cmd = langs.Command.RunQS{ + .base = langs.Command{ .tag = langs.Command.Tag.runqs }, + .program = wanted_runner, + }; while (true) { lang.reset(); @@ -124,11 +139,51 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { var line = rd_line[0..std.mem.len(rd_line)]; if (std.mem.eql(u8, line, "push")) { - try cmds.append(current); + const heap_cmd = switch (current.tag) { + .noop => try copyCommandToHeap(allocator, current, .noop), + .load => try copyCommandToHeap(allocator, current, .load), + .quicksave => try copyCommandToHeap(allocator, current, .quicksave), + .runqs => try copyCommandToHeap(allocator, current, .runqs), + .amp => try copyCommandToHeap(allocator, current, .amp), + .rflanger => try copyCommandToHeap(allocator, current, .rflanger), + .eq => try copyCommandToHeap(allocator, current, .eq), + .phaser => try copyCommandToHeap(allocator, current, .phaser), + .mbeq => try copyCommandToHeap(allocator, current, .mbeq), + .chorus => try copyCommandToHeap(allocator, current, .chorus), + .pitchscaler => try copyCommandToHeap(allocator, current, .pitchscaler), + .reverb => try copyCommandToHeap(allocator, current, .reverb), + .highpass => try copyCommandToHeap(allocator, current, .highpass), + .delay => try copyCommandToHeap(allocator, current, .delay), + .vinyl => try copyCommandToHeap(allocator, current, .vinyl), + .revdelay => try copyCommandToHeap(allocator, current, .revdelay), + .gate => try copyCommandToHeap(allocator, current, .gate), + .detune => try copyCommandToHeap(allocator, current, .detune), + .overdrive => try copyCommandToHeap(allocator, current, .overdrive), + .degrade => try copyCommandToHeap(allocator, current, .degrade), + .repsycho => try copyCommandToHeap(allocator, current, .repsycho), + .talkbox => try copyCommandToHeap(allocator, current, .talkbox), + .dyncomp => try copyCommandToHeap(allocator, current, .dyncomp), + .thruzero => try copyCommandToHeap(allocator, current, .thruzero), + .foverdrive => try copyCommandToHeap(allocator, current, .foverdrive), + .gverb => try copyCommandToHeap(allocator, current, .gverb), + .invert => try copyCommandToHeap(allocator, current, .invert), + .tapedelay => try copyCommandToHeap(allocator, current, .tapedelay), + .moddelay => try copyCommandToHeap(allocator, current, .moddelay), + .multichorus => try copyCommandToHeap(allocator, current, .multichorus), + .saturator => try copyCommandToHeap(allocator, current, .saturator), + .vintagedelay => try copyCommandToHeap(allocator, current, .vintagedelay), + .noise => try copyCommandToHeap(allocator, current, .noise), + .wildnoise => try copyCommandToHeap(allocator, current, .wildnoise), + .write => try copyCommandToHeap(allocator, current, .write), + .embed => try copyCommandToHeap(allocator, current, .embed), + .rotate => try copyCommandToHeap(allocator, current, .rotate), + }; + + try cmds.append(heap_cmd); // run the current added command to main cmds list // with the main parent runner - var cmds_wrapped = try wrapInCmdList(allocator, current); + var cmds_wrapped = try wrapInCmdList(allocator, heap_cmd); defer cmds_wrapped.deinit(); try runner.runCommands(cmds_wrapped, true); @@ -153,7 +208,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { std.debug.warn("repl: error while parsing: {}\n", .{err}); continue; }; - current = cmds_parsed.items[0]; + current = cmds_parsed.items[0].*; // by cloning the parent runner, we can iteratively write // whatever command we want and only commit the good results @@ -161,10 +216,9 @@ 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, - }); + // taking address is fine, because runqs_cmd lives in the lifetime + // of this function. + try cmds.append(&runqs_cmd.base); try runner_clone.runCommands(cmds_parsed, true); _ = try stdout.write("\n"); From 5235482ab4631b3c112038f2d73c849772dea1ae Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 1 Jun 2020 23:58:56 -0300 Subject: [PATCH 128/182] print float parameters with decimal notation --- src/printer.zig | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/printer.zig b/src/printer.zig index 0cf8e85..2302cfc 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -1,9 +1,14 @@ +const std = @import("std"); const langs = @import("lang.zig"); fn printCommandWithParams(stream: var, command: var) !void { const Parameters = @TypeOf(command.parameters); inline for (@typeInfo(Parameters).Struct.fields) |field| { - try stream.print(" {}", .{@field(command.parameters, field.name)}); + if (field.field_type == f32 or field.field_type == f64) { + try stream.print(" {d}", .{@field(command.parameters, field.name)}); + } else { + try stream.print(" {}", .{@field(command.parameters, field.name)}); + } } } @@ -42,7 +47,7 @@ pub fn printList(list: langs.CommandList, stream: var) !void { .noop, .quicksave => {}, .rotate => { const rotate = cmd.cast(langs.Command.Rotate).?; - try stream.print(" {} {}", .{ rotate.deg, rotate.bgfill }); + try stream.print(" {d} {}", .{ rotate.deg, rotate.bgfill }); }, .amp => try printCommand(stream, cmd, .amp), From d6c92c0231aeb8db3f756616180f50c8438dc002 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 2 Jun 2020 16:00:54 -0300 Subject: [PATCH 129/182] add split and index when printing custom/lv2 cmds --- src/printer.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/printer.zig b/src/printer.zig index 2302cfc..bf32f76 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -3,6 +3,7 @@ const langs = @import("lang.zig"); fn printCommandWithParams(stream: var, command: var) !void { const Parameters = @TypeOf(command.parameters); + try stream.print(" {} {}", .{ command.split, command.index }); inline for (@typeInfo(Parameters).Struct.fields) |field| { if (field.field_type == f32 or field.field_type == f64) { try stream.print(" {d}", .{@field(command.parameters, field.name)}); From 0240b10a3c4d934644ffaf04e1ecc65d97caa4bf Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 2 Jun 2020 16:11:30 -0300 Subject: [PATCH 130/182] close handles while making temporary paths --- src/image.zig | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/image.zig b/src/image.zig index b9202ef..ef27b7a 100644 --- a/src/image.zig +++ b/src/image.zig @@ -95,12 +95,16 @@ pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 { } // if we fail to access it, we assume it doesn't exist and return it. - - _ = std.fs.cwd().openFile(nam, .{ .read = true, .write = false }) catch |err| { - if (err == error.FileNotFound) { - return nam; - } + var tmp_file: std.fs.File = std.fs.cwd().openFile( + nam, + .{ .read = true, .write = false }, + ) catch |err| blk: { + if (err == error.FileNotFound) return nam else continue; }; + + // if we actually found someone, close the handle so that we don't + // get EMFILE later on. + tmp_file.close(); } return error.TempGenFail; From c7eb70a06f083cfafb0c23feeaf6d25992ab481e Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 2 Jun 2020 16:16:43 -0300 Subject: [PATCH 131/182] ignore lines without commands --- src/main.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.zig b/src/main.zig index a2716d7..4a65230 100644 --- a/src/main.zig +++ b/src/main.zig @@ -208,6 +208,10 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { std.debug.warn("repl: error while parsing: {}\n", .{err}); continue; }; + + // no command? ignore! + if (cmds_parsed.items.len == 0) continue; + current = cmds_parsed.items[0].*; // by cloning the parent runner, we can iteratively write From 542ba75b01638751b9ddb2ea6fd94c287fbd3de5 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 2 Jun 2020 16:16:49 -0300 Subject: [PATCH 132/182] make repl cloned runner run the runqs cmd --- src/main.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.zig b/src/main.zig index 4a65230..7d6cc00 100644 --- a/src/main.zig +++ b/src/main.zig @@ -224,7 +224,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { // of this function. try cmds.append(&runqs_cmd.base); - try runner_clone.runCommands(cmds_parsed, true); + try runner_clone.runCommands(cmds, true); _ = try stdout.write("\n"); } } From aeb76fe6c0b97f342566a05a3c2e807518e298de Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 2 Jun 2020 16:35:42 -0300 Subject: [PATCH 133/182] add more possibilities on temporary file paths --- src/image.zig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/image.zig b/src/image.zig index ef27b7a..c43f88e 100644 --- a/src/image.zig +++ b/src/image.zig @@ -75,7 +75,7 @@ pub fn sseek(file: *c.SNDFILE, offset: usize) void { /// Caller owns the returned memory. pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 { const template_start = "/temp/temp_"; - const template = "/tmp/temp_XXXXXXXXXXX"; + const template = "/tmp/temp_XXXXXXXXXXXXXXXXXXXXX"; var nam = try allocator.alloc(u8, template.len); std.mem.copy(u8, nam, template); @@ -86,7 +86,6 @@ pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 { var i: usize = 0; while (i < 100) : (i += 1) { - // generate a random uppercase letter, that is, 65 + random number. for (fill) |_, f_idx| { var idx = @intCast(u8, r.random.uintLessThan(u5, 24)); From dc98c7a22fd8825db25d8bf913c03a4ae08529b0 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 2 Jun 2020 16:59:36 -0300 Subject: [PATCH 134/182] use better seed --- src/image.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/image.zig b/src/image.zig index c43f88e..e0fea67 100644 --- a/src/image.zig +++ b/src/image.zig @@ -79,7 +79,7 @@ pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 { var nam = try allocator.alloc(u8, template.len); std.mem.copy(u8, nam, template); - const seed = @bitCast(u64, std.time.timestamp()); + const seed = @truncate(u64, @bitCast(u128, std.time.nanoTimestamp())); var r = std.rand.DefaultPrng.init(seed); var fill = nam[template_start.len..nam.len]; From c78ca9dd5b81e23bfbeebd7c25e3732d16532236 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 2 Jun 2020 16:59:53 -0300 Subject: [PATCH 135/182] refactor argument fetching for load cmd --- src/runner.zig | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/runner.zig b/src/runner.zig index 6b9f478..234e59e 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -49,20 +49,22 @@ pub const Runner = struct { // parse the index from 1 to end var index = try std.fmt.parseInt(usize, load_path[1..], 10); - // don't care about the 'repl' being prepended when we're in repl - if (self.repl) index += 1; + // if it isn't in the repl, args look like this: + // 'scritcher ./script ./image' + // if it is, it looks like this + // 'scritcher repl ./script ./image' - var args_it = std.process.args(); - _ = args_it.skip(); + // ':0' should ALWAYS point to the image. + if (self.repl) index += 3 else index += 2; - var i: usize = 0; - while (i <= index) : (i += 1) { - _ = args_it.skip(); + var args = try std.process.argsAlloc(self.allocator); + defer std.process.argsFree(self.allocator, args); + std.debug.warn("ARGS!! {} \n", .{args.len}); + for (args) |arg, idx| { + std.debug.warn("arg{} = {}\n", .{ idx, arg }); } - - const arg = try (args_it.next(self.allocator) orelse @panic("expected argument")); - - return arg; + std.debug.warn("fetch arg idx={}, val={}\n", .{ index, args[index] }); + return args[index]; } else { return load_path; } @@ -90,7 +92,7 @@ pub const Runner = struct { // krita/gimp and make it export a bmp and while in the program you can // apply filters, etc. if (!std.mem.endsWith(u8, load_path, ".bmp") and !std.mem.endsWith(u8, load_path, ".ppm")) { - std.debug.warn("Only BMP files are allowed to be loaded.\n", .{}); + std.debug.warn("Only BMP files are allowed to be loaded. Got path '{}'\n", .{load_path}); return RunError.NoBMP; } From a2ea8fb53ea5cce02744a7dd0a5beeea6c79cd24 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 2 Jun 2020 17:12:34 -0300 Subject: [PATCH 136/182] make args live through lifetime of runner we just assign cloned runners the args of the parent runner and don't free the parent's, maintaining okay memory usage. --- src/runner.zig | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/runner.zig b/src/runner.zig index 234e59e..3ca9bc9 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -26,10 +26,13 @@ pub const Runner = struct { /// If the runner is in REPL mode repl: bool = false, + args: [][]u8, + pub fn init(allocator: *std.mem.Allocator, repl: bool) Runner { return Runner{ .allocator = allocator, .repl = repl, + .args = std.process.argsAlloc(allocator) catch unreachable, }; } @@ -41,7 +44,11 @@ pub const Runner = struct { 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 }; + return Runner{ + .allocator = self.allocator, + .image = cloned_image, + .args = self.args, + }; } fn resolveArg(self: *Runner, load_path: []const u8) ![]const u8 { @@ -57,14 +64,12 @@ pub const Runner = struct { // ':0' should ALWAYS point to the image. if (self.repl) index += 3 else index += 2; - var args = try std.process.argsAlloc(self.allocator); - defer std.process.argsFree(self.allocator, args); - std.debug.warn("ARGS!! {} \n", .{args.len}); - for (args) |arg, idx| { + std.debug.warn("ARGS!! {} \n", .{self.args.len}); + for (self.args) |arg, idx| { std.debug.warn("arg{} = {}\n", .{ idx, arg }); } - std.debug.warn("fetch arg idx={}, val={}\n", .{ index, args[index] }); - return args[index]; + std.debug.warn("fetch arg idx={}, val={}\n", .{ index, self.args[index] }); + return self.args[index]; } else { return load_path; } From 1b59705eae99d84f9c189a35f87114d7c4fe7f55 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 2 Jun 2020 17:15:50 -0300 Subject: [PATCH 137/182] cloned runners inherit repl flag from parent --- src/runner.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/runner.zig b/src/runner.zig index 3ca9bc9..66a77c8 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -47,6 +47,7 @@ pub const Runner = struct { return Runner{ .allocator = self.allocator, .image = cloned_image, + .repl = self.repl, .args = self.args, }; } From af0ea574e1d8c08e788b72ab8a2584b85e32fc68 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 2 Jun 2020 17:16:02 -0300 Subject: [PATCH 138/182] remove default value for Runner.repl field --- src/runner.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runner.zig b/src/runner.zig index 66a77c8..a089a67 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -24,7 +24,7 @@ pub const Runner = struct { image: ?*Image = null, /// If the runner is in REPL mode - repl: bool = false, + repl: bool, args: [][]u8, From 6d8614e6784cc4987771323f8b520bb4922e7481 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 2 Jun 2020 17:25:03 -0300 Subject: [PATCH 139/182] revert cloned runner using parsed cmd list --- src/main.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.zig b/src/main.zig index 7d6cc00..be1b672 100644 --- a/src/main.zig +++ b/src/main.zig @@ -222,9 +222,9 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { // taking address is fine, because runqs_cmd lives in the lifetime // of this function. - try cmds.append(&runqs_cmd.base); + try cmds_parsed.append(&runqs_cmd.base); - try runner_clone.runCommands(cmds, true); + try runner_clone.runCommands(cmds_parsed, true); _ = try stdout.write("\n"); } } From 0ba2c5ffcc5ca89a6565572de34bc1c0cf2492b9 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 2 Jun 2020 21:42:26 -0300 Subject: [PATCH 140/182] add basics of searching for lilv --- build.zig | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/build.zig b/build.zig index 622961e..da24ddb 100644 --- a/build.zig +++ b/build.zig @@ -1,5 +1,6 @@ -const builds = @import("std").build; -const Builder = @import("std").build.Builder; +const std = @import("std"); +const builds = std.build; +const Builder = std.build.Builder; fn setupLinks(step: *builds.LibExeObjStep) void { step.linkSystemLibrary("c"); @@ -11,8 +12,26 @@ fn setupLinks(step: *builds.LibExeObjStep) void { step.linkSystemLibrary("GraphicsMagickWand"); step.linkSystemLibrary("GraphicsMagick"); - step.addIncludeDir("/usr/include/lilv-0"); step.addIncludeDir("/usr/include/GraphicsMagick"); + + const possible_lilv_include_dirs = [_][]const u8{ + "/usr/include/lilv-0", + "/usr/include/lilv-0/lilv", + }; + var found_any_lilv = false; + + for (possible_lilv_include_dirs) |possible_lilv_dir| { + var possible_dir = std.fs.cwd().openDir(possible_lilv_dir) catch |err| { + continue; + }; + possible_dir.close(); + found_any_lilv = true; + } + + if (!found_any_lilv) { + std.debug.warn("No LILV library was found :(\n"); + @panic("no lilv found"); + } } pub fn build(b: *Builder) void { From c80a6d0df70c8ef27637cf38be1f5645ab23eaee Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 2 Jun 2020 21:54:39 -0300 Subject: [PATCH 141/182] fix typos and actually add dirs to step --- build.zig | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/build.zig b/build.zig index da24ddb..8b3484b 100644 --- a/build.zig +++ b/build.zig @@ -13,23 +13,29 @@ fn setupLinks(step: *builds.LibExeObjStep) void { step.linkSystemLibrary("GraphicsMagick"); step.addIncludeDir("/usr/include/GraphicsMagick"); + step.addIncludeDir("/usr/include"); const possible_lilv_include_dirs = [_][]const u8{ - "/usr/include/lilv-0", "/usr/include/lilv-0/lilv", + "/usr/include/lilv-0", }; var found_any_lilv = false; for (possible_lilv_include_dirs) |possible_lilv_dir| { - var possible_dir = std.fs.cwd().openDir(possible_lilv_dir) catch |err| { + var possible_dir = std.fs.cwd().openDir(possible_lilv_dir, .{}) catch |err| { + std.debug.warn("possible lilv {} fail: {}\n", .{ possible_lilv_dir, err }); continue; }; + possible_dir.close(); found_any_lilv = true; + + std.debug.warn("found lilv at '{}'\n", .{possible_lilv_dir}); + step.addIncludeDir(possible_lilv_dir); } if (!found_any_lilv) { - std.debug.warn("No LILV library was found :(\n"); + std.debug.warn("No LILV library was found :(\n", .{}); @panic("no lilv found"); } } From 8d312cd987abd076b40bda6b5c92068aa21985a0 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 2 Jun 2020 22:24:43 -0300 Subject: [PATCH 142/182] use lv2.h provided at root of /usr/include fixes ubuntu issues --- .gitignore | 1 + build.zig | 1 + src/lv2_helpers.zig | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b43912f..44f7213 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ zig-cache/ *.mp3 *.wav +build_runner.zig diff --git a/build.zig b/build.zig index 8b3484b..6858c80 100644 --- a/build.zig +++ b/build.zig @@ -19,6 +19,7 @@ fn setupLinks(step: *builds.LibExeObjStep) void { "/usr/include/lilv-0/lilv", "/usr/include/lilv-0", }; + var found_any_lilv = false; for (possible_lilv_include_dirs) |possible_lilv_dir| { diff --git a/src/lv2_helpers.zig b/src/lv2_helpers.zig index abc9c8f..a72e07d 100644 --- a/src/lv2_helpers.zig +++ b/src/lv2_helpers.zig @@ -4,7 +4,7 @@ const plugin = @import("plugin.zig"); pub const c = @cImport({ @cInclude("sndfile.h"); @cInclude("lilv/lilv.h"); - @cInclude("lv2/core/lv2.h"); + @cInclude("lv2.h"); }); pub fn Lv2Core(comptime ns: []const u8) []const u8 { From fa7e993ec21010dc778a91bd1257d94361c0e5fa Mon Sep 17 00:00:00 2001 From: Luna Date: Thu, 23 Jul 2020 16:31:32 -0300 Subject: [PATCH 143/182] zig fmt pass --- src/custom.zig | 8 ++++---- src/image.zig | 2 +- src/lang.zig | 2 +- src/main.zig | 2 +- src/printer.zig | 6 +++--- src/runner.zig | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/custom.zig b/src/custom.zig index 0420bd3..e1a9107 100644 --- a/src/custom.zig +++ b/src/custom.zig @@ -16,7 +16,7 @@ pub const RandomNoise = struct { pub fn init( allocator: *std.mem.Allocator, - params: var, + params: anytype, ) ?RandomNoise { var r = std.rand.DefaultPrng.init(params.seed); @@ -64,7 +64,7 @@ pub const WildNoise = struct { pub fn init( allocator: *std.mem.Allocator, - params: var, + params: anytype, ) ?WildNoise { var r = std.rand.DefaultPrng.init(params.seed); @@ -112,7 +112,7 @@ pub const Write = struct { pub fn init( allocator: *std.mem.Allocator, - params: var, + params: anytype, ) Write { return Write{ .data = params.data, @@ -133,7 +133,7 @@ pub const Embed = struct { sndfile: *c.SNDFILE = undefined, buf: []f32 = undefined, - pub fn init(allocator: *std.mem.Allocator, params: var) @This() { + pub fn init(allocator: *std.mem.Allocator, params: anytype) @This() { return Embed{ .allocator = allocator, .filepath = params.path, diff --git a/src/image.zig b/src/image.zig index e0fea67..0501e70 100644 --- a/src/image.zig +++ b/src/image.zig @@ -425,7 +425,7 @@ pub const Image = struct { self: *Image, comptime Plugin: type, position: plugins.Position, - extra: var, + extra: anytype, ) !void { var plugin_opt: ?Plugin = Plugin.init(self.allocator, extra); if (plugin_opt == null) { diff --git a/src/lang.zig b/src/lang.zig index 305eb4a..134307b 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -497,7 +497,7 @@ pub const Lang = struct { self.has_error = false; self.line = 0; } - fn doError(self: *Lang, comptime fmt: []const u8, args: var) void { + fn doError(self: *Lang, comptime fmt: []const u8, args: anytype) void { std.debug.warn("ERROR! at line {}: ", .{self.line}); std.debug.warn(fmt, args); std.debug.warn("\n", .{}); diff --git a/src/main.zig b/src/main.zig index be1b672..a53c1fb 100644 --- a/src/main.zig +++ b/src/main.zig @@ -36,7 +36,7 @@ fn copyCommandToHeap(allocator: *std.mem.Allocator, command: langs.Command, comp return &heap_cmd.base; } -pub fn doRepl(allocator: *std.mem.Allocator, args_it: var) !void { +pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void { var stdout_file = std.io.getStdOut(); const stdout = &stdout_file.outStream(); const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path")); diff --git a/src/printer.zig b/src/printer.zig index bf32f76..d0b8f2f 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -1,7 +1,7 @@ const std = @import("std"); const langs = @import("lang.zig"); -fn printCommandWithParams(stream: var, command: var) !void { +fn printCommandWithParams(stream: anytype, command: anytype) !void { const Parameters = @TypeOf(command.parameters); try stream.print(" {} {}", .{ command.split, command.index }); inline for (@typeInfo(Parameters).Struct.fields) |field| { @@ -13,7 +13,7 @@ fn printCommandWithParams(stream: var, command: var) !void { } } -fn printCommand(stream: var, cmd: *langs.Command, comptime tag: langs.Command.Tag) !void { +fn printCommand(stream: anytype, cmd: *langs.Command, comptime tag: langs.Command.Tag) !void { const CommandStruct = langs.Command.tagToType(tag); const casted = cmd.cast(CommandStruct).?; @@ -31,7 +31,7 @@ fn printCommand(stream: var, cmd: *langs.Command, comptime tag: langs.Command.Ta } } -pub fn printList(list: langs.CommandList, stream: var) !void { +pub fn printList(list: langs.CommandList, stream: anytype) !void { for (list.items) |cmd| { const command = @tagName(cmd.tag); try stream.print("{}", .{command}); diff --git a/src/runner.zig b/src/runner.zig index a089a67..acffe2a 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -209,7 +209,7 @@ pub const Runner = struct { try magick.runRotate(image, rotate_cmd.deg, c_bgfill); } - fn executeLV2Command(self: *@This(), command: var) !void { + fn executeLV2Command(self: *@This(), command: anytype) !void { const pos = plugin.Position{ .split = command.split, .index = command.index, @@ -231,7 +231,7 @@ pub const Runner = struct { try image.runPlugin(typ.lv2_url, pos, params); } - fn executeCustomCommand(self: *@This(), command: var) !void { + fn executeCustomCommand(self: *@This(), command: anytype) !void { const pos = plugin.Position{ .split = command.split, .index = command.index, From 8aa65958d046012c0ceab023e3943c8f94acb380 Mon Sep 17 00:00:00 2001 From: Luna Date: Thu, 23 Jul 2020 16:32:33 -0300 Subject: [PATCH 144/182] cast ptr --- src/plugin.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugin.zig b/src/plugin.zig index b979833..4a5725c 100644 --- a/src/plugin.zig +++ b/src/plugin.zig @@ -142,7 +142,7 @@ pub fn makeContext(allocator: *std.mem.Allocator, plugin_uri: []const u8) !Conte }; defer c.lilv_node_free(uri); - const plugins: *const c.LilvPlugins = c.lilv_world_get_all_plugins(world); + const plugins: *const c.LilvPlugins = c.lilv_world_get_all_plugins(world).?; var plugin: *const c.LilvPlugin = c.lilv_plugins_get_by_uri(plugins, uri) orelse blk: { std.debug.warn("Plugin <{}> not found\n", .{plugin_uri}); From 353d8d69472329666c5df472091da9713231f1db Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 18 Aug 2020 17:49:23 -0300 Subject: [PATCH 145/182] fix for latest zig --- src/image.zig | 4 ++-- src/lang.zig | 2 -- src/lv2_helpers.zig | 22 +++++++++++----------- src/plugin.zig | 8 ++++---- src/printer.zig | 1 - src/runner.zig | 1 - 6 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/image.zig b/src/image.zig index 0501e70..2d40b97 100644 --- a/src/image.zig +++ b/src/image.zig @@ -97,7 +97,7 @@ pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 { var tmp_file: std.fs.File = std.fs.cwd().openFile( nam, .{ .read = true, .write = false }, - ) catch |err| blk: { + ) catch |err| { if (err == error.FileNotFound) return nam else continue; }; @@ -321,7 +321,7 @@ pub const Image = struct { defer self.allocator.free(sym_cstr); var sym = c.lilv_new_string(ctx.world, sym_cstr.ptr); - const port = c.lilv_plugin_get_port_by_symbol(ctx.plugin, sym) orelse blk: { + const port = c.lilv_plugin_get_port_by_symbol(ctx.plugin, sym) orelse { std.debug.warn("assert fail: symbol {} not found on port\n", .{param.sym}); return ImageError.InvalidSymbol; }; diff --git a/src/lang.zig b/src/lang.zig index 134307b..3d33909 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -135,8 +135,6 @@ pub const Command = struct { .embed => Embed, .rotate => Rotate, - - else => @panic("TODO"), }; } diff --git a/src/lv2_helpers.zig b/src/lv2_helpers.zig index a72e07d..1612974 100644 --- a/src/lv2_helpers.zig +++ b/src/lv2_helpers.zig @@ -81,20 +81,20 @@ pub fn setupPorts(ctx: *plugin.Context) ![]Port { defer ctx.allocator.free(values); c.lilv_plugin_get_port_ranges_float(ctx.plugin, null, null, values.ptr); - var lv2_InputPort = c.lilv_new_uri(world, LV2_CORE__InputPort.ptr); - defer std.heap.c_allocator.destroy(lv2_InputPort); + var lv2_InputPort = c.lilv_new_uri(world, LV2_CORE__InputPort.ptr).?; + //defer std.heap.c_allocator.destroy(lv2_InputPort); - var lv2_OutputPort = c.lilv_new_uri(world, LV2_CORE__OutputPort.ptr); - defer std.heap.c_allocator.destroy(lv2_OutputPort); + var lv2_OutputPort = c.lilv_new_uri(world, LV2_CORE__OutputPort.ptr).?; + //defer std.heap.c_allocator.destroy(lv2_OutputPort); - var lv2_AudioPort = c.lilv_new_uri(world, LV2_CORE__AudioPort.ptr); - defer std.heap.c_allocator.destroy(lv2_AudioPort); + var lv2_AudioPort = c.lilv_new_uri(world, LV2_CORE__AudioPort.ptr).?; + //defer std.heap.c_allocator.destroy(lv2_AudioPort); - var lv2_ControlPort = c.lilv_new_uri(world, LV2_CORE__ControlPort.ptr); - defer std.heap.c_allocator.destroy(lv2_ControlPort); + var lv2_ControlPort = c.lilv_new_uri(world, LV2_CORE__ControlPort.ptr).?; + //defer std.heap.c_allocator.destroy(lv2_ControlPort); - var lv2_connectionOptional = c.lilv_new_uri(world, LV2_CORE__connectionOptional.ptr); - defer std.heap.c_allocator.destroy(lv2_connectionOptional); + var lv2_connection_string = c.lilv_new_uri(world, LV2_CORE__connectionOptional.ptr).?; + //defer std.heap.c_allocator.destroy(lv2_connection_string); var i: u32 = 0; while (i < n_ports) : (i += 1) { @@ -111,7 +111,7 @@ pub fn setupPorts(ctx: *plugin.Context) ![]Port { port.value = values[i]; } - port.optional = c.lilv_port_has_property(ctx.plugin, lport, lv2_connectionOptional); + port.optional = c.lilv_port_has_property(ctx.plugin, lport, lv2_connection_string); if (c.lilv_port_is_a(ctx.plugin, lport, lv2_InputPort)) { port.is_input = true; diff --git a/src/plugin.zig b/src/plugin.zig index 4a5725c..78e8a6d 100644 --- a/src/plugin.zig +++ b/src/plugin.zig @@ -104,7 +104,7 @@ pub const RunContext = struct { switch (port.ptype) { .Control => lv2.lilv_instance_connect_port(self.instance, p, &port.value), - .Audio => blk: { + .Audio => { if (port.is_input) { lv2.lilv_instance_connect_port( self.instance, @@ -121,7 +121,7 @@ pub const RunContext = struct { o += 1; } }, - else => lv2.lilv_instance_connect_port(self.instance, p, null), + // else => lv2.lilv_instance_connect_port(self.instance, p, null), } } } @@ -136,7 +136,7 @@ pub fn makeContext(allocator: *std.mem.Allocator, plugin_uri: []const u8) !Conte c.lilv_world_load_all(world); - var uri: *c.LilvNode = c.lilv_new_uri(world, cstr_plugin_uri.ptr) orelse blk: { + var uri: *c.LilvNode = c.lilv_new_uri(world, cstr_plugin_uri.ptr) orelse { std.debug.warn("Invalid plugin URI <{}>\n", .{plugin_uri}); return ImageError.InvalidPlugin; }; @@ -144,7 +144,7 @@ pub fn makeContext(allocator: *std.mem.Allocator, plugin_uri: []const u8) !Conte const plugins: *const c.LilvPlugins = c.lilv_world_get_all_plugins(world).?; - var plugin: *const c.LilvPlugin = c.lilv_plugins_get_by_uri(plugins, uri) orelse blk: { + var plugin: *const c.LilvPlugin = c.lilv_plugins_get_by_uri(plugins, uri) orelse { std.debug.warn("Plugin <{}> not found\n", .{plugin_uri}); return ImageError.UnknownPlugin; }; diff --git a/src/printer.zig b/src/printer.zig index d0b8f2f..69cc4b5 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -27,7 +27,6 @@ fn printCommand(stream: anytype, cmd: *langs.Command, comptime tag: langs.Comman switch (ctype) { .lv2_command => try printCommandWithParams(stream, casted), .custom_command => try printCommandWithParams(stream, casted), - else => @panic("TODO support command type"), } } diff --git a/src/runner.zig b/src/runner.zig index acffe2a..36c4687 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -252,7 +252,6 @@ pub const Runner = struct { switch (ctype) { .lv2_command => try self.executeLV2Command(command.*), .custom_command => try self.executeCustomCommand(command.*), - else => @panic("TODO support command type"), } } From 4adf80e51a8ebae30c8cb6f403b68741ca1e5cbb Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 18 Aug 2020 17:58:04 -0300 Subject: [PATCH 146/182] fix some memory leaks --- src/runner.zig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/runner.zig b/src/runner.zig index 36c4687..a9ea3e3 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -40,6 +40,8 @@ pub const Runner = struct { if (self.image) |image| { image.close(); } + + std.process.argsFree(self.allocator, self.args); } pub fn clone(self: *Runner) !Runner { @@ -117,6 +119,7 @@ pub const Runner = struct { } } + /// Caller owns returned memory. fn makeGlitchedPath(self: *Runner) ![]const u8 { // we want to transform basename, if it is "x.bmp" to "x_gN.bmp", where // N is the maximum non-used integer. @@ -180,6 +183,7 @@ pub const Runner = struct { fn quicksaveCmd(self: *Runner) !void { var image = try self.getImage(); const out_path = try self.makeGlitchedPath(); + defer self.allocator.free(out_path); try image.saveTo(out_path); } @@ -187,6 +191,7 @@ pub const Runner = struct { const runqs = cmd.cast(lang.Command.RunQS).?; var image = try self.getImage(); const out_path = try self.makeGlitchedPath(); + defer self.allocator.free(out_path); try image.saveTo(out_path); var proc = try std.ChildProcess.init( From f61e9b013f2b881de15cdae6bf19aa08efc5eef4 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 18 Aug 2020 20:40:06 -0300 Subject: [PATCH 147/182] make CommandList free its command pointers --- src/lang.zig | 24 +++++++++++++++++++++++- src/main.zig | 7 +++---- src/printer.zig | 2 +- src/runner.zig | 2 +- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 3d33909..80450f3 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -474,7 +474,29 @@ pub const Command = struct { }); }; -pub const CommandList = std.ArrayList(*Command); +const CmdArrayList = std.ArrayList(*Command); + +pub const CommandList = struct { + list: CmdArrayList, + const Self = @This(); + + pub fn init(allocator: *std.mem.Allocator) Self { + return .{ + .list = CmdArrayList.init(allocator), + }; + } + + pub fn deinit(self: *Self) void { + for (self.list.items) |cmd_ptr| { + self.list.allocator.destroy(cmd_ptr); + } + self.list.deinit(); + } + + pub fn append(self: *Self, cmd: *Command) !void { + return try self.list.append(cmd); + } +}; /// A parser. pub const Lang = struct { diff --git a/src/main.zig b/src/main.zig index a53c1fb..119009e 100644 --- a/src/main.zig +++ b/src/main.zig @@ -65,7 +65,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void { defer existing_cmds.deinit(); // copy the existing command list into the repl's command list - for (existing_cmds.items) |existing_cmd| { + for (existing_cmds.list.items) |existing_cmd| { try cmds.append(existing_cmd); } } else { @@ -210,9 +210,8 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void { }; // no command? ignore! - if (cmds_parsed.items.len == 0) continue; - - current = cmds_parsed.items[0].*; + if (cmds_parsed.list.items.len == 0) continue; + current = cmds_parsed.list.items[0].*; // by cloning the parent runner, we can iteratively write // whatever command we want and only commit the good results diff --git a/src/printer.zig b/src/printer.zig index 69cc4b5..5ea5a7b 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -31,7 +31,7 @@ fn printCommand(stream: anytype, cmd: *langs.Command, comptime tag: langs.Comman } pub fn printList(list: langs.CommandList, stream: anytype) !void { - for (list.items) |cmd| { + for (list.list.items) |cmd| { const command = @tagName(cmd.tag); try stream.print("{}", .{command}); diff --git a/src/runner.zig b/src/runner.zig index a9ea3e3..37fade3 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -312,7 +312,7 @@ pub const Runner = struct { cmds: lang.CommandList, debug_flag: bool, ) !void { - for (cmds.items) |cmd| { + for (cmds.list.items) |cmd| { cmd.print(); try self.runCommand(cmd.*); } From 708ef45600b244fb8836000249848c3a561b1efb Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 18 Aug 2020 20:41:57 -0300 Subject: [PATCH 148/182] fix use-after-free on repl --- src/main.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.zig b/src/main.zig index 119009e..15e1524 100644 --- a/src/main.zig +++ b/src/main.zig @@ -60,9 +60,11 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void { var scri_existing = try allocator.alloc(u8, total_bytes); _ = try file_read_opt.?.read(scri_existing); - // we can defer this because we copy the Command structs back to cmds + // we can't defer this directly because we copy the + // Command pointers to the cmds list. running deinit() directly + // would cause those pointers to be freed. var existing_cmds = try lang.parse(scri_existing); - defer existing_cmds.deinit(); + defer existing_cmds.list.deinit(); // copy the existing command list into the repl's command list for (existing_cmds.list.items) |existing_cmd| { From 0cd47be7ac9a398f3c9e4d44fb33132867644c2e Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 18 Aug 2020 20:53:54 -0300 Subject: [PATCH 149/182] remove need to dupe strings to command structs --- src/lang.zig | 7 +++---- src/main.zig | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 80450f3..c80af14 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -157,7 +157,7 @@ pub const Command = struct { pub const Load = struct { pub const base_tag = Tag.load; base: Command, - path: []u8, + path: []const u8, }; pub const Quicksave = struct { @@ -568,7 +568,7 @@ pub const Lang = struct { f32 => try std.fmt.parseFloat(f32, arg), u64 => try std.fmt.parseInt(u64, arg, 10), usize => try std.fmt.parseInt(usize, arg, 10), - []const u8 => try self.allocator.dupe(u8, arg), + []const u8 => arg, else => @compileError("parameter struct has unsupported type " ++ @typeName(cmd_field.field_type)), }; @@ -586,8 +586,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), + []const u8 => arg, else => @compileError("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."), }; diff --git a/src/main.zig b/src/main.zig index 15e1524..4fd6525 100644 --- a/src/main.zig +++ b/src/main.zig @@ -77,7 +77,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void { // 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.path = ":0"; load_cmd.base.tag = langs.Command.Tag.load; // taking address is fine, because load_cmd lives in the lifetime From 9527426d484d680f4db373c72f98fe1e2c35ef7d Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 18 Aug 2020 20:54:04 -0300 Subject: [PATCH 150/182] remove memleak when getting args --- src/main.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.zig b/src/main.zig index 4fd6525..962684b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -242,9 +242,9 @@ pub fn main() !void { var args_it = std.process.args(); // TODO print help - - _ = try (args_it.next(allocator) orelse @panic("expected exe name")); + _ = args_it.skip(); const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path or 'repl'")); + defer allocator.free(scri_path); if (std.mem.eql(u8, scri_path, "repl")) { return try doRepl(allocator, &args_it); From 77cceab2886f2b117b4ee4683323067a12ef9fe5 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 18 Aug 2020 20:57:33 -0300 Subject: [PATCH 151/182] make Image free its paths --- src/image.zig | 5 +++-- src/runner.zig | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/image.zig b/src/image.zig index 2d40b97..51c1eef 100644 --- a/src/image.zig +++ b/src/image.zig @@ -179,8 +179,9 @@ pub const Image = struct { } pub fn close(self: *Image) void { - //self.allocator.free(self.path); - //self.allocator.free(self.curpath); + self.allocator.free(self.path); + self.allocator.free(self.curpath); + var st: i32 = c.sf_close(self.sndfile); if (st != 0) { diff --git a/src/runner.zig b/src/runner.zig index 37fade3..47f2cab 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -78,6 +78,7 @@ pub const Runner = struct { } } + // Caller owns returned memory. fn resolveArgPath(self: *Runner, path_or_argidx: []const u8) ![]const u8 { const path = try self.resolveArg(path_or_argidx); const resolved_path = try std.fs.path.resolve( @@ -89,7 +90,7 @@ pub const Runner = struct { } fn loadCmd(self: *Runner, path_or_argidx: []const u8) !void { - var load_path = try self.resolveArgPath(path_or_argidx); + const load_path = try self.resolveArgPath(path_or_argidx); std.debug.warn("\tload path: {}\n", .{load_path}); // we could use ImageMagick to convert from X to BMP From c2834f8254616f5bd2a1a5007ea0b240c6fcefac Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 18 Aug 2020 21:00:07 -0300 Subject: [PATCH 152/182] properly free Image contents --- src/image.zig | 11 +++++++---- src/runner.zig | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/image.zig b/src/image.zig index 51c1eef..46acb24 100644 --- a/src/image.zig +++ b/src/image.zig @@ -179,17 +179,20 @@ pub const Image = struct { } pub fn close(self: *Image) void { - self.allocator.free(self.path); - self.allocator.free(self.curpath); - var st: i32 = c.sf_close(self.sndfile); - if (st != 0) { std.debug.warn("Failed to close {} ({})\n", .{ self.path, c.sf_error_number(st), }); } + + self.allocator.free(self.path); + self.allocator.free(self.curpath); + + var allocator = self.allocator; + self.* = undefined; + allocator.destroy(self); } pub fn read(self: *Image, file_chans: c_int, buf: []f32) bool { diff --git a/src/runner.zig b/src/runner.zig index 47f2cab..442068d 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -108,6 +108,7 @@ pub const Runner = struct { // we don't copy load_path into a temporary file because we're already // loading it under the SFM_READ mode, which won't cause any destructive // operations on the file. + if (self.image) |image| image.close(); self.image = try Image.open(self.allocator, load_path); } From 7097334201a80fd6cd579ef7991dd7d5437a8575 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 18 Aug 2020 21:00:16 -0300 Subject: [PATCH 153/182] turn on gpa --- src/main.zig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.zig b/src/main.zig index 962684b..8ea264d 100644 --- a/src/main.zig +++ b/src/main.zig @@ -231,7 +231,12 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void { } pub fn main() !void { - const allocator = std.heap.page_allocator; + // const allocator = std.heap.page_allocator; + var allocator_instance = std.heap.GeneralPurposeAllocator(.{}){}; + defer { + _ = allocator_instance.deinit(); + } + const allocator = &allocator_instance.allocator; var lang = langs.Lang.init(allocator); defer lang.deinit(); From 5e8093b26fbeb93ad9ff376ca5f78f8fd16c5afc Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 18 Aug 2020 21:02:43 -0300 Subject: [PATCH 154/182] free lv2 ports slice --- src/image.zig | 1 + src/lv2_helpers.zig | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/image.zig b/src/image.zig index 46acb24..32a93ec 100644 --- a/src/image.zig +++ b/src/image.zig @@ -307,6 +307,7 @@ pub const Image = struct { defer ctx.deinit(); var ports = try lv2.setupPorts(&ctx); + defer ctx.allocator.free(ports); if (ctx.n_audio_in > 2) { std.debug.warn("plugin <{}> has more than two inputs.\n", .{plugin_uri}); diff --git a/src/lv2_helpers.zig b/src/lv2_helpers.zig index 1612974..fcfa2c9 100644 --- a/src/lv2_helpers.zig +++ b/src/lv2_helpers.zig @@ -59,6 +59,8 @@ pub const Port = struct { /// Setup ports for a given plugin. Gives an array to pointers of Port structs. /// This setup is required so we link the plugin to the ports later on, and /// also link our buffers, and control values. +/// +/// Caller owns returned memory. pub fn setupPorts(ctx: *plugin.Context) ![]Port { var world = ctx.world; const n_ports: u32 = c.lilv_plugin_get_num_ports(ctx.plugin); From ebf716de179eeca1a1f2fceeea2237927426baa6 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 8 Nov 2020 18:47:40 -0300 Subject: [PATCH 155/182] fix type for Runner.args --- src/runner.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runner.zig b/src/runner.zig index 442068d..a10b7a5 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -26,7 +26,7 @@ pub const Runner = struct { /// If the runner is in REPL mode repl: bool, - args: [][]u8, + args: []const [:0]u8, pub fn init(allocator: *std.mem.Allocator, repl: bool) Runner { return Runner{ From 2acb45fdcace0fa50e108e7a8889358eabd6be43 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 3 Apr 2021 21:09:30 -0300 Subject: [PATCH 156/182] build.zig: fix for latest zig --- build.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index 6858c80..467240c 100644 --- a/build.zig +++ b/build.zig @@ -24,14 +24,14 @@ fn setupLinks(step: *builds.LibExeObjStep) void { for (possible_lilv_include_dirs) |possible_lilv_dir| { var possible_dir = std.fs.cwd().openDir(possible_lilv_dir, .{}) catch |err| { - std.debug.warn("possible lilv {} fail: {}\n", .{ possible_lilv_dir, err }); + std.debug.warn("possible lilv {s} fail: {s}\n", .{ possible_lilv_dir, err }); continue; }; possible_dir.close(); found_any_lilv = true; - std.debug.warn("found lilv at '{}'\n", .{possible_lilv_dir}); + std.debug.warn("found lilv at '{s}'\n", .{possible_lilv_dir}); step.addIncludeDir(possible_lilv_dir); } From 667e6cbdac71044e5685351f39bea8fd22ee2bfc Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 3 Apr 2021 21:09:44 -0300 Subject: [PATCH 157/182] zig fmt pass --- src/lang.zig | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index c80af14..d5c193a 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -199,33 +199,25 @@ pub const Command = struct { pub const Amp = LV2Command( .amp, "http://lv2plug.in/plugins/eg-amp", - struct { - gain: f32 - }, + struct { gain: f32 }, ); pub const RFlanger = LV2Command( .rflanger, "http://plugin.org.uk/swh-plugins/retroFlange", - struct { - delay_depth_avg: f32, law_freq: f32 - }, + struct { delay_depth_avg: f32, law_freq: f32 }, ); pub const Eq = LV2Command( .rflanger, "http://plugin.org.uk/swh-plugins/dj_eq_mono", - struct { - lo: f32, mid: f32, hi: f32 - }, + struct { lo: f32, mid: f32, hi: f32 }, ); pub const Phaser = LV2Command( .phaser, "http://plugin.org.uk/swh-plugins/lfoPhaser", - struct { - lfo_rate: f32, lfo_depth: f32, fb: f32, spread: f32 - }, + struct { lfo_rate: f32, lfo_depth: f32, fb: f32, spread: f32 }, ); pub const Mbeq = LV2Command( @@ -378,9 +370,7 @@ pub const Command = struct { pub const Foverdrive = LV2Command(.foverdrive, "http://plugin.org.uk/swh-plugins/foverdrive", struct { drive: f32, }); - pub const Thruzero = LV2Command(.thruzero, "http://drobilla.net/plugins/mda/ThruZero", struct { - rate: f32, mix: f32, feedback: f32, depth_mod: f32 - }); + pub const Thruzero = LV2Command(.thruzero, "http://drobilla.net/plugins/mda/ThruZero", struct { rate: f32, mix: f32, feedback: f32, depth_mod: f32 }); pub const Gverb = LV2Command(.gverb, "http://plugin.org.uk/swh-plugins/gverb", struct { roomsize: f32, From 9937365433e06adc4571d5edbf0954542fe26041 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 3 Apr 2021 22:16:04 -0300 Subject: [PATCH 158/182] update to latest zig --- src/bmp_valid.zig | 2 +- src/custom.zig | 2 +- src/image.zig | 32 ++++++++++++++++---------------- src/lang.zig | 10 +++++----- src/lv2_helpers.zig | 4 ++-- src/magick.zig | 4 ++-- src/main.zig | 4 ++-- src/plugin.zig | 4 ++-- src/printer.zig | 20 ++++++++------------ src/runner.zig | 15 +++++++-------- 10 files changed, 46 insertions(+), 51 deletions(-) diff --git a/src/bmp_valid.zig b/src/bmp_valid.zig index c4f9438..6468658 100644 --- a/src/bmp_valid.zig +++ b/src/bmp_valid.zig @@ -20,7 +20,7 @@ pub fn magicValid(magic: []const u8) !void { } if (!valid) { - std.debug.warn("\tINVALID HEADER: '{}'\n", .{magic}); + std.debug.warn("\tINVALID HEADER: '{s}'\n", .{magic}); return BMPValidError.InvalidMagic; } } diff --git a/src/custom.zig b/src/custom.zig index e1a9107..03120f0 100644 --- a/src/custom.zig +++ b/src/custom.zig @@ -174,7 +174,7 @@ pub const Embed = struct { if (read_bytes < 0) { const st: i32 = c.sf_error(self.sndfile); - std.debug.warn("Failed to read {} ({})\n", .{ + std.debug.warn("Failed to read {s} ({s})\n", .{ self.filepath, c.sf_error_number(st), }); diff --git a/src/image.zig b/src/image.zig index 32a93ec..b6e13ae 100644 --- a/src/image.zig +++ b/src/image.zig @@ -32,7 +32,7 @@ pub fn sopen( const st: i32 = c.sf_error(file); if (st != 0) { - std.debug.warn("Failed to open {} ({})\n", .{ + std.debug.warn("Failed to open {s} ({s})\n", .{ path, c.sf_error_number(st), }); @@ -181,7 +181,7 @@ pub const Image = struct { pub fn close(self: *Image) void { var st: i32 = c.sf_close(self.sndfile); if (st != 0) { - std.debug.warn("Failed to close {} ({})\n", .{ + std.debug.warn("Failed to close {s} ({s})\n", .{ self.path, c.sf_error_number(st), }); @@ -228,7 +228,7 @@ pub const Image = struct { sseek(out_file, start); while (i <= end) : (i += buf.len) { - std.debug.warn("\t\ti={}, buf.len={}, end={}\n", .{ i, buf.len, end }); + std.debug.warn("\t\ti={d}, buf.len={d}, end={d}\n", .{ i, buf.len, end }); sseek(self.sndfile, i); sseek(out_file, i); @@ -254,7 +254,7 @@ pub const Image = struct { fn getSeekPos(self: *Image, position: plugins.Position) plugins.SeekPos { const file_end = self.frames; var seek_pos = position.seekPos(file_end); - std.debug.warn("\tstart {} end {}\n", .{ seek_pos.start, seek_pos.end }); + std.debug.warn("\tstart {d} end {d}\n", .{ seek_pos.start, seek_pos.end }); return seek_pos; } @@ -267,7 +267,7 @@ pub const Image = struct { self.curpath = path; self.frames = @intCast(usize, in_fmt.frames); - std.debug.warn("\timage: reopened on '{}' (frames={}, fmt.frames={})\n", .{ + std.debug.warn("\timage: reopened on '{s}' (frames={d}, fmt.frames={d})\n", .{ self.curpath, self.frames, in_fmt.frames, @@ -310,12 +310,12 @@ pub const Image = struct { defer ctx.allocator.free(ports); if (ctx.n_audio_in > 2) { - std.debug.warn("plugin <{}> has more than two inputs.\n", .{plugin_uri}); + std.debug.warn("plugin <{s}> has more than two inputs.\n", .{plugin_uri}); return ImageError.InvalidPlugin; } if (ctx.n_audio_out > 2) { - std.debug.warn("plugin <{}> has more than two outputs.\n", .{plugin_uri}); + std.debug.warn("plugin <{s}> has more than two outputs.\n", .{plugin_uri}); return ImageError.InvalidPlugin; } @@ -327,14 +327,14 @@ pub const Image = struct { var sym = c.lilv_new_string(ctx.world, sym_cstr.ptr); const port = c.lilv_plugin_get_port_by_symbol(ctx.plugin, sym) orelse { - std.debug.warn("assert fail: symbol {} not found on port\n", .{param.sym}); + std.debug.warn("assert fail: symbol {s} not found on port\n", .{param.sym}); return ImageError.InvalidSymbol; }; c.lilv_node_free(sym); var idx = c.lilv_port_get_index(ctx.plugin, port); - std.debug.warn("\tset sym={}, idx={} to val={}\n", .{ + std.debug.warn("\tset sym={s}, idx={d} to val={}\n", .{ param.sym, idx, param.value, @@ -345,7 +345,7 @@ pub const Image = struct { // now we need to generate a temporary file and put the output of // running the plugin on that file var tmpnam = try temporaryName(self.allocator); - std.debug.warn("\trunning plugin from '{}' to '{}'\n", .{ self.curpath, tmpnam }); + std.debug.warn("\trunning plugin from '{s}' to '{s}'\n", .{ self.curpath, tmpnam }); var out_fmt = mkSfInfo(); var out_file = try sopen(self.allocator, tmpnam, c.SFM_WRITE, &out_fmt); @@ -378,7 +378,7 @@ pub const Image = struct { sseek(self.sndfile, seek_pos.start); var i: usize = seek_pos.start; - std.debug.warn("\tseek pos start: {} end: {}\n", .{ seek_pos.start, seek_pos.end }); + std.debug.warn("\tseek pos start: {d} end: {d}\n", .{ seek_pos.start, seek_pos.end }); var inbuf = &rctx.buffers.in; var outbuf = &rctx.buffers.out; @@ -389,7 +389,7 @@ pub const Image = struct { const read_bytes = c.sf_readf_float(self.sndfile, inbuf, 1); if (read_bytes == 0) { - std.debug.warn("WARN! reached EOF at idx={}\n", .{i}); + std.debug.warn("WARN! reached EOF at idx={d}\n", .{i}); break; } @@ -422,7 +422,7 @@ pub const Image = struct { } pub fn saveTo(self: *Image, out_path: []const u8) !void { - std.debug.warn("\timg: copy from '{}' to '{}'\n", .{ self.curpath, out_path }); + std.debug.warn("\timg: copy from '{s}' to '{s}'\n", .{ self.curpath, out_path }); try std.fs.copyFileAbsolute(self.curpath, out_path, .{}); } @@ -450,7 +450,7 @@ pub const Image = struct { // the code here is a copypaste of runPlugin() without the specific // lilv things. var tmpnam = try temporaryName(self.allocator); - std.debug.warn("\trunning CUSTOM plugin from '{}' to '{}'\n", .{ self.curpath, tmpnam }); + std.debug.warn("\trunning CUSTOM plugin from '{s}' to '{s}'\n", .{ self.curpath, tmpnam }); var out_fmt = mkSfInfo(); var out_file = try sopen(self.allocator, tmpnam, c.SFM_WRITE, &out_fmt); @@ -477,7 +477,7 @@ pub const Image = struct { sseek(self.sndfile, seek_pos.start); var i: usize = seek_pos.start; - std.debug.warn("\tseek pos start: {} end: {}\n", .{ seek_pos.start, seek_pos.end }); + std.debug.warn("\tseek pos start: {d} end: {d}\n", .{ seek_pos.start, seek_pos.end }); var inbuf = &bufs.in; var outbuf = &bufs.out; @@ -485,7 +485,7 @@ pub const Image = struct { while (i <= seek_pos.end) : (i += 1) { const read_bytes = c.sf_readf_float(self.sndfile, inbuf, 1); if (read_bytes == 0) { - std.debug.warn("WARN! reached EOF at idx={}\n", .{i}); + std.debug.warn("WARN! reached EOF at idx={d}\n", .{i}); break; } diff --git a/src/lang.zig b/src/lang.zig index d5c193a..b299ae0 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -146,7 +146,7 @@ pub const Command = struct { } pub fn print(base: *const @This()) void { - std.debug.warn("tag: {}\n", .{base.tag}); + std.debug.warn("tag: {s}\n", .{base.tag}); } pub const Noop = struct { @@ -549,7 +549,7 @@ pub const Lang = struct { inline for (@typeInfo(@TypeOf(cmd.parameters)).Struct.fields) |cmd_field| { const maybe_arg = tok_it.next(); if (maybe_arg == null) { - self.doError("Expected parameter for {}, got nothing", .{cmd_field.name}); + self.doError("Expected parameter for {s}, got nothing", .{cmd_field.name}); return; } @@ -580,7 +580,7 @@ pub const Lang = struct { else => @compileError("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."), }; - std.debug.warn("parsing {}, arg of type {} => {}\n", .{ + std.debug.warn("parsing {s}, arg of type {s} => {any}\n", .{ @typeName(command_struct), @typeName(@TypeOf(argument_value)), argument_value, @@ -592,7 +592,7 @@ pub const Lang = struct { cmd.base.tag = command_struct.base_tag; const command = cmd.base.cast(command_struct).?; - std.debug.warn("cmd: {}\n", .{command}); + std.debug.warn("cmd: {s}\n", .{command}); try commands.append(&cmd.base); } @@ -653,7 +653,7 @@ pub const Lang = struct { } if (!found) { - self.doError("Unknown command '{}' ({})", .{ command_string, command_string.len }); + self.doError("Unknown command '{s}' ({d} bytes)", .{ command_string, command_string.len }); continue; } } diff --git a/src/lv2_helpers.zig b/src/lv2_helpers.zig index fcfa2c9..599370c 100644 --- a/src/lv2_helpers.zig +++ b/src/lv2_helpers.zig @@ -118,7 +118,7 @@ pub fn setupPorts(ctx: *plugin.Context) ![]Port { if (c.lilv_port_is_a(ctx.plugin, lport, lv2_InputPort)) { port.is_input = true; } else if (!c.lilv_port_is_a(ctx.plugin, lport, lv2_OutputPort) and !port.optional) { - std.debug.warn("Port {} is neither input or output\n", .{i}); + std.debug.warn("Port {d} is neither input or output\n", .{i}); return error.UnassignedIOPort; } @@ -134,7 +134,7 @@ pub fn setupPorts(ctx: *plugin.Context) ![]Port { ctx.n_audio_out += 1; } } else if (!port.optional) { - std.debug.warn("Port {} has unsupported type\n", .{i}); + std.debug.warn("Port {d} has unsupported type\n", .{i}); return error.UnsupportedPortType; } } diff --git a/src/magick.zig b/src/magick.zig index 33ba882..dd5f295 100644 --- a/src/magick.zig +++ b/src/magick.zig @@ -39,7 +39,7 @@ fn magickLoad(image: *Image) !MagickContext { var curpath = try std.cstr.addNullByte(image.allocator, image.curpath); defer image.allocator.free(curpath); - std.debug.warn("loading '{}'\n", .{curpath}); + std.debug.warn("loading '{s}'\n", .{curpath}); if (mc.MagickReadImage(mctx.wand, curpath.ptr) != 1) return error.MagickReadFail; @@ -54,7 +54,7 @@ fn magickSave(image: *Image, wand: *mc.MagickWand) !void { var c_tmpnam = try std.cstr.addNullByte(allocator, tmpnam); defer allocator.free(c_tmpnam); - std.debug.warn("\tmagick: saving to '{}'..", .{c_tmpnam}); + std.debug.warn("\tmagick: saving to '{s}'..", .{c_tmpnam}); if (mc.MagickWriteImage(wand, c_tmpnam.ptr) != 1) return error.MagickWriteFail; diff --git a/src/main.zig b/src/main.zig index 8ea264d..6ebe124 100644 --- a/src/main.zig +++ b/src/main.zig @@ -38,7 +38,7 @@ fn copyCommandToHeap(allocator: *std.mem.Allocator, command: langs.Command, comp pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void { var stdout_file = std.io.getStdOut(); - const stdout = &stdout_file.outStream(); + const stdout = &stdout_file.writer(); const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path")); var file_read_opt: ?std.fs.File = std.fs.cwd().openFile(scri_path, .{}) catch |err| blk: { @@ -95,7 +95,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void { }); defer file.close(); - var out = file.outStream(); + var out = file.writer(); var stream = &out; // since we opened the file for writing, it becomes empty, so, to ensure diff --git a/src/plugin.zig b/src/plugin.zig index 78e8a6d..cb8c64a 100644 --- a/src/plugin.zig +++ b/src/plugin.zig @@ -137,7 +137,7 @@ pub fn makeContext(allocator: *std.mem.Allocator, plugin_uri: []const u8) !Conte c.lilv_world_load_all(world); var uri: *c.LilvNode = c.lilv_new_uri(world, cstr_plugin_uri.ptr) orelse { - std.debug.warn("Invalid plugin URI <{}>\n", .{plugin_uri}); + std.debug.warn("Invalid plugin URI <{s}>\n", .{plugin_uri}); return ImageError.InvalidPlugin; }; defer c.lilv_node_free(uri); @@ -145,7 +145,7 @@ pub fn makeContext(allocator: *std.mem.Allocator, plugin_uri: []const u8) !Conte const plugins: *const c.LilvPlugins = c.lilv_world_get_all_plugins(world).?; var plugin: *const c.LilvPlugin = c.lilv_plugins_get_by_uri(plugins, uri) orelse { - std.debug.warn("Plugin <{}> not found\n", .{plugin_uri}); + std.debug.warn("Plugin <{s}> not found\n", .{plugin_uri}); return ImageError.UnknownPlugin; }; diff --git a/src/printer.zig b/src/printer.zig index 5ea5a7b..c1fab31 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -3,12 +3,14 @@ const langs = @import("lang.zig"); fn printCommandWithParams(stream: anytype, command: anytype) !void { const Parameters = @TypeOf(command.parameters); - try stream.print(" {} {}", .{ command.split, command.index }); + try stream.print(" {d} {d}", .{ command.split, command.index }); inline for (@typeInfo(Parameters).Struct.fields) |field| { if (field.field_type == f32 or field.field_type == f64) { + try stream.print(" {}", .{@field(command.parameters, field.name)}); + } else if (field.field_type == usize or field.field_type == u64) { try stream.print(" {d}", .{@field(command.parameters, field.name)}); } else { - try stream.print(" {}", .{@field(command.parameters, field.name)}); + try stream.print(" {s}", .{@field(command.parameters, field.name)}); } } } @@ -17,12 +19,6 @@ fn printCommand(stream: anytype, cmd: *langs.Command, comptime tag: langs.Comman 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 = CommandStruct.command_type; switch (ctype) { .lv2_command => try printCommandWithParams(stream, casted), @@ -33,21 +29,21 @@ fn printCommand(stream: anytype, cmd: *langs.Command, comptime tag: langs.Comman pub fn printList(list: langs.CommandList, stream: anytype) !void { for (list.list.items) |cmd| { const command = @tagName(cmd.tag); - try stream.print("{}", .{command}); + try stream.print("{s}", .{command}); switch (cmd.tag) { .load => { const load = cmd.cast(langs.Command.Load).?; - try stream.print(" {}", .{load.path}); + try stream.print(" {s}", .{load.path}); }, .runqs => { const runqs = cmd.cast(langs.Command.RunQS).?; - try stream.print(" {}", .{runqs.program}); + try stream.print(" {s}", .{runqs.program}); }, .noop, .quicksave => {}, .rotate => { const rotate = cmd.cast(langs.Command.Rotate).?; - try stream.print(" {d} {}", .{ rotate.deg, rotate.bgfill }); + try stream.print(" {d} {s}", .{ rotate.deg, rotate.bgfill }); }, .amp => try printCommand(stream, cmd, .amp), diff --git a/src/runner.zig b/src/runner.zig index a10b7a5..1bec75a 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -67,11 +67,10 @@ pub const Runner = struct { // ':0' should ALWAYS point to the image. if (self.repl) index += 3 else index += 2; - std.debug.warn("ARGS!! {} \n", .{self.args.len}); for (self.args) |arg, idx| { - std.debug.warn("arg{} = {}\n", .{ idx, arg }); + std.debug.warn("arg{d} = {s}\n", .{ idx, arg }); } - std.debug.warn("fetch arg idx={}, val={}\n", .{ index, self.args[index] }); + std.debug.warn("fetch arg idx={d}, val={s}\n", .{ index, self.args[index] }); return self.args[index]; } else { return load_path; @@ -91,7 +90,7 @@ pub const Runner = struct { fn loadCmd(self: *Runner, path_or_argidx: []const u8) !void { const load_path = try self.resolveArgPath(path_or_argidx); - std.debug.warn("\tload path: {}\n", .{load_path}); + std.debug.warn("\tload path: {s}\n", .{load_path}); // we could use ImageMagick to convert from X to BMP // but i can't find an easy way to do things in memory. @@ -101,7 +100,7 @@ pub const Runner = struct { // krita/gimp and make it export a bmp and while in the program you can // apply filters, etc. if (!std.mem.endsWith(u8, load_path, ".bmp") and !std.mem.endsWith(u8, load_path, ".ppm")) { - std.debug.warn("Only BMP files are allowed to be loaded. Got path '{}'\n", .{load_path}); + std.debug.warn("Only BMP files are allowed to be loaded. Got path '{s}'\n", .{load_path}); return RunError.NoBMP; } @@ -138,7 +137,7 @@ pub const Runner = struct { // starts_with would be "x_g", we want to find all files in the directory // that start with that name. - const starts_with = try std.fmt.allocPrint(self.allocator, "{}_g", .{ + const starts_with = try std.fmt.allocPrint(self.allocator, "{s}_g", .{ basename[0..period_idx], }); defer self.allocator.free(starts_with); @@ -172,7 +171,7 @@ pub const Runner = struct { } } - const out_path = try std.fmt.allocPrint(self.allocator, "{}/{}{}{}", .{ + const out_path = try std.fmt.allocPrint(self.allocator, "{s}/{s}{d}{s}", .{ dirname, starts_with, max + 1, @@ -202,7 +201,7 @@ pub const Runner = struct { ); defer proc.deinit(); - std.debug.warn("running '{} {}'\n", .{ runqs.program, out_path }); + std.debug.warn("running '{s} {s}'\n", .{ runqs.program, out_path }); _ = try proc.spawnAndWait(); } From 32b01976d86f49afcbeb63c48f6b6c15a512faf0 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 3 Apr 2021 23:05:56 -0300 Subject: [PATCH 159/182] change default scri path to 'run' cli command --- src/main.zig | 43 +++++++++++++++++++++++++------------------ src/runner.zig | 2 +- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/main.zig b/src/main.zig index 6ebe124..d810652 100644 --- a/src/main.zig +++ b/src/main.zig @@ -248,25 +248,32 @@ pub fn main() !void { // TODO print help _ = args_it.skip(); - const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path or 'repl'")); - defer allocator.free(scri_path); + const cli_command = try (args_it.next(allocator) orelse @panic("expected 'run', 'help', or 'repl'")); + defer allocator.free(cli_command); - if (std.mem.eql(u8, scri_path, "repl")) { + if (std.mem.eql(u8, cli_command, "help")) { + //return try doHelp(); + } else if (std.mem.eql(u8, cli_command, "repl")) { return try doRepl(allocator, &args_it); + } else if (std.mem.eql(u8, cli_command, "run")) { + const scri_path = try (args_it.next(allocator) orelse @panic("run: expected scri path")); + defer allocator.free(scri_path); + + var file = try std.fs.cwd().openFile(scri_path, .{}); + defer file.close(); + + // sadly, we read it all into memory. such is life + const total_bytes = try file.getEndPos(); + + var data = try allocator.alloc(u8, total_bytes); + defer allocator.free(data); + _ = try file.read(data); + + var cmds = try lang.parse(data); + defer cmds.deinit(); + + try runner.runCommands(cmds, true); + } else { + @panic("expected 'run', 'help', or 'repl'"); } - - var file = try std.fs.cwd().openFile(scri_path, .{}); - defer file.close(); - - // sadly, we read it all into memory. such is life - const total_bytes = try file.getEndPos(); - - var data = try allocator.alloc(u8, total_bytes); - defer allocator.free(data); - _ = try file.read(data); - - var cmds = try lang.parse(data); - defer cmds.deinit(); - - try runner.runCommands(cmds, true); } diff --git a/src/runner.zig b/src/runner.zig index 1bec75a..16bbc12 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -65,7 +65,7 @@ pub const Runner = struct { // 'scritcher repl ./script ./image' // ':0' should ALWAYS point to the image. - if (self.repl) index += 3 else index += 2; + if (self.repl) index += 4 else index += 3; for (self.args) |arg, idx| { std.debug.warn("arg{d} = {s}\n", .{ idx, arg }); From 73c52141468b59d48750ca29c7cc03e859a8eacc Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 3 Apr 2021 23:20:17 -0300 Subject: [PATCH 160/182] add 'help' command --- src/main.zig | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main.zig b/src/main.zig index d810652..865ce42 100644 --- a/src/main.zig +++ b/src/main.zig @@ -230,6 +230,13 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void { } } +fn doHelp() void { + std.debug.warn("scritcher!\n", .{}); + std.debug.warn("usage: scritcher [run|help|repl]\n", .{}); + std.debug.warn("\tscritcher run path_to_script.scri path_to_input_file.bmp\n", .{}); + std.debug.warn("\tscritcher repl path_to_script.scri path_to_input_file.bmp\n", .{}); +} + pub fn main() !void { // const allocator = std.heap.page_allocator; var allocator_instance = std.heap.GeneralPurposeAllocator(.{}){}; @@ -248,11 +255,16 @@ pub fn main() !void { // TODO print help _ = args_it.skip(); - const cli_command = try (args_it.next(allocator) orelse @panic("expected 'run', 'help', or 'repl'")); + const cli_command_opt = args_it.next(allocator); + if (cli_command_opt == null) { + return doHelp(); + } + + const cli_command = try cli_command_opt.?; defer allocator.free(cli_command); if (std.mem.eql(u8, cli_command, "help")) { - //return try doHelp(); + return doHelp(); } else if (std.mem.eql(u8, cli_command, "repl")) { return try doRepl(allocator, &args_it); } else if (std.mem.eql(u8, cli_command, "run")) { @@ -274,6 +286,7 @@ pub fn main() !void { try runner.runCommands(cmds, true); } else { - @panic("expected 'run', 'help', or 'repl'"); + std.debug.warn("unknown command: '{s}'\n", .{cli_command}); + return error.UnknownCommand; } } From 79d7e137d2e9dd972a800a744499e6483f8047cd Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 3 Apr 2021 23:21:50 -0300 Subject: [PATCH 161/182] refactor into 'doRun' function --- src/main.zig | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/src/main.zig b/src/main.zig index 865ce42..8e68ab3 100644 --- a/src/main.zig +++ b/src/main.zig @@ -237,6 +237,32 @@ fn doHelp() void { std.debug.warn("\tscritcher repl path_to_script.scri path_to_input_file.bmp\n", .{}); } +fn doRun(allocator: *std.mem.Allocator, args_it: anytype) !void { + var lang = langs.Lang.init(allocator); + defer lang.deinit(); + + var runner = runners.Runner.init(allocator, false); + defer runner.deinit(); + + const scri_path = try (args_it.next(allocator) orelse @panic("run: expected scri path")); + defer allocator.free(scri_path); + + var file = try std.fs.cwd().openFile(scri_path, .{}); + defer file.close(); + + // sadly, we read it all into memory. such is life + const total_bytes = try file.getEndPos(); + + var data = try allocator.alloc(u8, total_bytes); + defer allocator.free(data); + _ = try file.read(data); + + var cmds = try lang.parse(data); + defer cmds.deinit(); + + try runner.runCommands(cmds, true); +} + pub fn main() !void { // const allocator = std.heap.page_allocator; var allocator_instance = std.heap.GeneralPurposeAllocator(.{}){}; @@ -245,12 +271,6 @@ pub fn main() !void { } const allocator = &allocator_instance.allocator; - var lang = langs.Lang.init(allocator); - defer lang.deinit(); - - var runner = runners.Runner.init(allocator, false); - defer runner.deinit(); - var args_it = std.process.args(); // TODO print help @@ -268,23 +288,7 @@ pub fn main() !void { } else if (std.mem.eql(u8, cli_command, "repl")) { return try doRepl(allocator, &args_it); } else if (std.mem.eql(u8, cli_command, "run")) { - const scri_path = try (args_it.next(allocator) orelse @panic("run: expected scri path")); - defer allocator.free(scri_path); - - var file = try std.fs.cwd().openFile(scri_path, .{}); - defer file.close(); - - // sadly, we read it all into memory. such is life - const total_bytes = try file.getEndPos(); - - var data = try allocator.alloc(u8, total_bytes); - defer allocator.free(data); - _ = try file.read(data); - - var cmds = try lang.parse(data); - defer cmds.deinit(); - - try runner.runCommands(cmds, true); + return try doRun(allocator, &args_it); } else { std.debug.warn("unknown command: '{s}'\n", .{cli_command}); return error.UnknownCommand; From a9e4c5823a063ee7dcade1211b59f505d13a5b69 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 3 Apr 2021 23:22:22 -0300 Subject: [PATCH 162/182] remove implemented TODO --- src/main.zig | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main.zig b/src/main.zig index 8e68ab3..f1cb3c8 100644 --- a/src/main.zig +++ b/src/main.zig @@ -264,7 +264,6 @@ fn doRun(allocator: *std.mem.Allocator, args_it: anytype) !void { } pub fn main() !void { - // const allocator = std.heap.page_allocator; var allocator_instance = std.heap.GeneralPurposeAllocator(.{}){}; defer { _ = allocator_instance.deinit(); @@ -273,7 +272,6 @@ pub fn main() !void { var args_it = std.process.args(); - // TODO print help _ = args_it.skip(); const cli_command_opt = args_it.next(allocator); if (cli_command_opt == null) { From 78cc7fab4b4a232473acc82d7153fa06ae77fff7 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 4 Apr 2021 17:08:53 -0300 Subject: [PATCH 163/182] fix tests --- src/lang.zig | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index b299ae0..127ff04 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -665,18 +665,18 @@ pub const Lang = struct { }; test "noop" { - var lang = Lang.init(std.heap.direct_allocator); + var lang = Lang.init(std.testing.allocator); defer lang.deinit(); var cmds = try lang.parse("noop;"); defer cmds.deinit(); - std.testing.expectEqual(cmds.len, 1); - std.testing.expectEqual(cmds.items[0].command, .Noop); + std.testing.expectEqual(cmds.list.items.len, 1); + std.testing.expectEqual(cmds.list.items[0].tag, .noop); } test "load, phaser, quicksave" { - var lang = Lang.init(std.heap.direct_allocator); + var lang = Lang.init(std.testing.allocator); defer lang.deinit(); const prog = @@ -688,8 +688,8 @@ test "load, phaser, quicksave" { var cmds = try lang.parse(prog); defer cmds.deinit(); - std.testing.expectEqual(cmds.len, 3); - std.testing.expectEqual(cmds.items[0].command, .Load); - std.testing.expectEqual(cmds.items[1].command, .Phaser); - std.testing.expectEqual(cmds.items[2].command, .Quicksave); + std.testing.expectEqual(cmds.list.items.len, 3); + std.testing.expectEqual(cmds.list.items[0].tag, .load); + std.testing.expectEqual(cmds.list.items[1].tag, .phaser); + std.testing.expectEqual(cmds.list.items[2].tag, .quicksave); } From 2a801a129b29f15bd225c7ee8ba41dc7a315c2af Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 4 Apr 2021 17:45:14 -0300 Subject: [PATCH 164/182] add note about comptime hash map --- src/lang.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lang.zig b/src/lang.zig index 127ff04..3747941 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -643,7 +643,10 @@ pub const Lang = struct { // in a variable because then that variable must be comptime. // the drawback of this approach is that our emitted code is basically linear - // because we don't use the hashmap anymore. maybe #5359 can help. + // because we don't use the hashmap anymore. + // + // Attempting to use ComptimeHashMap hits compiler bugs and I'm + // not sure if we can map strings to *types* in it. if (std.mem.eql(u8, &lowered_command_name, command_string)) { found = true; From b28f208e659b5ef50258b0ea579f27529c81eff3 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 4 Apr 2021 17:56:59 -0300 Subject: [PATCH 165/182] add error for non-lv2 args not getting enough args --- src/lang.zig | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 3747941..e70b553 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -527,9 +527,6 @@ pub const Lang = struct { else => true, }; - // TODO: crash when no arguments are left but we still need - // arguments... - if (is_lv2_command) { const split = tok_it.next(); if (split == null) { @@ -571,7 +568,14 @@ pub const Lang = struct { continue; } } - const arg = tok_it.next().?; + + const arg_opt = tok_it.next(); + if (arg_opt == null) { + self.doError("Expected parameter for {s}, got nothing", .{cmd_field.name}); + return; + } + const arg = arg_opt.?; + const argument_value = switch (cmd_field.field_type) { usize => try std.fmt.parseInt(usize, arg, 10), i32 => try std.fmt.parseInt(i32, arg, 10), From ea3850b99d851f58498581d5b12ce236ae5b787d Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 4 Apr 2021 18:15:42 -0300 Subject: [PATCH 166/182] add test for parse errors --- src/lang.zig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lang.zig b/src/lang.zig index e70b553..2f2b4ac 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -507,6 +507,7 @@ pub const Lang = struct { self.has_error = false; self.line = 0; } + fn doError(self: *Lang, comptime fmt: []const u8, args: anytype) void { std.debug.warn("ERROR! at line {}: ", .{self.line}); std.debug.warn(fmt, args); @@ -700,3 +701,20 @@ test "load, phaser, quicksave" { std.testing.expectEqual(cmds.list.items[1].tag, .phaser); std.testing.expectEqual(cmds.list.items[2].tag, .quicksave); } + +test "load, phaser with errors, quicksave" { + var lang = Lang.init(std.testing.allocator); + defer lang.deinit(); + + const prog = + \\load :0; + \\phaser 3 1 25; + \\quicksave; + ; + + var cmds = lang.parse(prog) catch |err| { + return; + }; + + unreachable; +} From b195577dee63a0683f8a7ac8c441e51d359e0132 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 4 Apr 2021 20:47:18 -0300 Subject: [PATCH 167/182] prevent memleaks on parse errors --- src/lang.zig | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 2f2b4ac..3ad0c41 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -523,6 +523,11 @@ pub const Lang = struct { ) !void { // Based on the command struct fields, we can parse the arguments. var cmd = try self.allocator.create(command_struct); + + // we already add the command to the list to prevent memory leaks + // by commands that error out + try commands.append(&cmd.base); + const is_lv2_command = switch (command_struct.base_tag) { .noop, .load, .quicksave, .runqs, .rotate => false, else => true, @@ -598,13 +603,12 @@ pub const Lang = struct { cmd.base.tag = command_struct.base_tag; const command = cmd.base.cast(command_struct).?; std.debug.warn("cmd: {s}\n", .{command}); - - try commands.append(&cmd.base); } pub fn parse(self: *Lang, data: []const u8) !CommandList { var splitted_it = std.mem.split(data, ";"); var cmds = CommandList.init(self.allocator); + errdefer cmds.deinit(); while (splitted_it.next()) |stmt_orig| { self.line += 1; From d7d43852422f1abec1fba6b9ba38ca50ebadcacc Mon Sep 17 00:00:00 2001 From: Luna Date: Wed, 27 Apr 2022 20:01:00 -0300 Subject: [PATCH 168/182] fix memory leak on string arguments --- src/lang.zig | 19 +++++++++++++++++-- src/main.zig | 6 +++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 3ad0c41..f465895 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -479,6 +479,21 @@ pub const CommandList = struct { pub fn deinit(self: *Self) void { for (self.list.items) |cmd_ptr| { self.list.allocator.destroy(cmd_ptr); + inline for (@typeInfo(Command.Tag).Enum.fields) |field| { + if (cmd_ptr.tag == @field(Command.Tag, field.name)) { + const actual_tag = + @field(Command.Tag, field.name); + // if we find a match on the tag, we can get the type + const typ = Command.tagToType(actual_tag); + + inline for (@typeInfo(typ).Struct.fields) |cmd_field| { + switch (cmd_field.field_type) { + []u8, []const u8 => self.list.allocator.destroy(@field(typ, cmd_field.name)), + else => {}, + } + } + } + } } self.list.deinit(); } @@ -561,7 +576,7 @@ pub const Lang = struct { f32 => try std.fmt.parseFloat(f32, arg), u64 => try std.fmt.parseInt(u64, arg, 10), usize => try std.fmt.parseInt(usize, arg, 10), - []const u8 => arg, + []const u8 => @as([]const u8, try self.allocator.dupe(u8, arg)), else => @compileError("parameter struct has unsupported type " ++ @typeName(cmd_field.field_type)), }; @@ -586,7 +601,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), - []const u8 => arg, + []const u8 => @as([]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) ++ "."), }; diff --git a/src/main.zig b/src/main.zig index f1cb3c8..a096f4f 100644 --- a/src/main.zig +++ b/src/main.zig @@ -40,6 +40,8 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void { var stdout_file = std.io.getStdOut(); const stdout = &stdout_file.writer(); const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path")); + errdefer allocator.free(scri_path); + defer allocator.free(scri_path); var file_read_opt: ?std.fs.File = std.fs.cwd().openFile(scri_path, .{}) catch |err| blk: { if (err == error.FileNotFound) break :blk null; @@ -54,11 +56,9 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void { defer lang.deinit(); if (total_bytes > 0) { - // this MUST BE long lived (a reference to it is kept inside - // existing_cmds, and then passed along to cmds), - // we can't defer them here var scri_existing = try allocator.alloc(u8, total_bytes); _ = try file_read_opt.?.read(scri_existing); + defer allocator.free(scri_existing); // we can't defer this directly because we copy the // Command pointers to the cmds list. running deinit() directly From 268be1074cf44eb4e0d60a519cd3a3258574710b Mon Sep 17 00:00:00 2001 From: Luna Date: Wed, 27 Apr 2022 20:01:06 -0300 Subject: [PATCH 169/182] port to latest zig fs api --- src/main.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.zig b/src/main.zig index a096f4f..005100b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -89,9 +89,9 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void { file_read.close(); } - var file = try std.fs.cwd().openFile(scri_path, .{ - .write = true, + var file = try std.fs.cwd().createFile(scri_path, .{ .read = false, + .truncate = true, }); defer file.close(); From c817170a0423fa65ef28aa15e512db9284edeaa9 Mon Sep 17 00:00:00 2001 From: Luna Date: Wed, 27 Apr 2022 20:01:09 -0300 Subject: [PATCH 170/182] port to latest zig: use std.log --- build.zig | 6 +++--- src/bmp_valid.zig | 5 ++--- src/custom.zig | 3 ++- src/image.zig | 41 +++++++++++++++++++++-------------------- src/lang.zig | 13 +++++++------ src/lv2_helpers.zig | 8 +++++--- src/magick.zig | 7 ++++--- src/main.zig | 18 ++++++++++-------- src/plugin.zig | 5 +++-- src/printer.zig | 2 ++ src/runner.zig | 16 +++++++++------- 11 files changed, 68 insertions(+), 56 deletions(-) diff --git a/build.zig b/build.zig index 467240c..f7b08f9 100644 --- a/build.zig +++ b/build.zig @@ -24,19 +24,19 @@ fn setupLinks(step: *builds.LibExeObjStep) void { for (possible_lilv_include_dirs) |possible_lilv_dir| { var possible_dir = std.fs.cwd().openDir(possible_lilv_dir, .{}) catch |err| { - std.debug.warn("possible lilv {s} fail: {s}\n", .{ possible_lilv_dir, err }); + std.debug.print("possible lilv {s} fail: {s}\n", .{ possible_lilv_dir, err }); continue; }; possible_dir.close(); found_any_lilv = true; - std.debug.warn("found lilv at '{s}'\n", .{possible_lilv_dir}); + std.debug.print("found lilv at '{s}'\n", .{possible_lilv_dir}); step.addIncludeDir(possible_lilv_dir); } if (!found_any_lilv) { - std.debug.warn("No LILV library was found :(\n", .{}); + std.debug.print("No LILV library was found :(\n", .{}); @panic("no lilv found"); } } diff --git a/src/bmp_valid.zig b/src/bmp_valid.zig index 6468658..55970b8 100644 --- a/src/bmp_valid.zig +++ b/src/bmp_valid.zig @@ -1,11 +1,10 @@ const std = @import("std"); - +const log = std.log.scoped(.scritcher_bmp); pub const BMPValidError = error{InvalidMagic}; const VALID_MAGICS = [_][]const u8{ "BM", "BA", - "CI", "CP", "IC", @@ -20,7 +19,7 @@ pub fn magicValid(magic: []const u8) !void { } if (!valid) { - std.debug.warn("\tINVALID HEADER: '{s}'\n", .{magic}); + log.debug("\tINVALID HEADER: '{s}'\n", .{magic}); return BMPValidError.InvalidMagic; } } diff --git a/src/custom.zig b/src/custom.zig index 03120f0..401b39f 100644 --- a/src/custom.zig +++ b/src/custom.zig @@ -4,6 +4,7 @@ const lv2 = @import("lv2_helpers.zig"); const plugins = @import("plugin.zig"); const image = @import("image.zig"); +const log = std.log.scoped(.scritcher_custom); const c = lv2.c; const RunBuffers = plugins.RunBuffers; @@ -174,7 +175,7 @@ pub const Embed = struct { if (read_bytes < 0) { const st: i32 = c.sf_error(self.sndfile); - std.debug.warn("Failed to read {s} ({s})\n", .{ + log.debug("Failed to read {s} ({s})\n", .{ self.filepath, c.sf_error_number(st), }); diff --git a/src/image.zig b/src/image.zig index b6e13ae..4a01845 100644 --- a/src/image.zig +++ b/src/image.zig @@ -3,6 +3,7 @@ const lv2 = @import("lv2_helpers.zig"); const c = lv2.c; const bmp = @import("bmp_valid.zig"); +const log = std.log.scoped(.scritcher_image); const plugins = @import("plugin.zig"); /// Buffer size for main image copying. @@ -32,7 +33,7 @@ pub fn sopen( const st: i32 = c.sf_error(file); if (st != 0) { - std.debug.warn("Failed to open {s} ({s})\n", .{ + log.debug("Failed to open {s} ({s})\n", .{ path, c.sf_error_number(st), }); @@ -47,7 +48,7 @@ pub fn sopen( const frames_on_end_by_end = c.sf_seek(file, frames_on_end, c.SEEK_SET); std.testing.expectEqual(frames_on_end, frames_on_end_by_end); - std.debug.warn("frames on end: {}, frame on end (2): {}\n", .{ frames_on_end, frames_on_end_by_end }); + log.debug("frames on end: {}, frame on end (2): {}\n", .{ frames_on_end, frames_on_end_by_end }); return file.?; } @@ -56,7 +57,7 @@ pub fn swrite(file: *c.SNDFILE, buf: [*]f32, frames: i64) !void { const count = c.sf_writef_float(file, buf, frames); if (count != frames) { - std.debug.warn("Wanted to write {}, got {}\n", .{ frames, count }); + log.debug("Wanted to write {}, got {}\n", .{ frames, count }); return ImageError.WriteFail; } } @@ -68,7 +69,7 @@ pub fn sseek(file: *c.SNDFILE, offset: usize) void { std.testing.expectEqual(frames, frames_current); if (frames != offset_i64) { - std.debug.warn("failed to seek to {} (seeked {} frames, offset_i64={})\n", .{ offset, frames, offset_i64 }); + log.debug("failed to seek to {} (seeked {} frames, offset_i64={})\n", .{ offset, frames, offset_i64 }); } } @@ -181,7 +182,7 @@ pub const Image = struct { pub fn close(self: *Image) void { var st: i32 = c.sf_close(self.sndfile); if (st != 0) { - std.debug.warn("Failed to close {s} ({s})\n", .{ + log.debug("Failed to close {s} ({s})\n", .{ self.path, c.sf_error_number(st), }); @@ -228,7 +229,7 @@ pub const Image = struct { sseek(out_file, start); while (i <= end) : (i += buf.len) { - std.debug.warn("\t\ti={d}, buf.len={d}, end={d}\n", .{ i, buf.len, end }); + log.debug("\t\ti={d}, buf.len={d}, end={d}\n", .{ i, buf.len, end }); sseek(self.sndfile, i); sseek(out_file, i); @@ -254,7 +255,7 @@ pub const Image = struct { fn getSeekPos(self: *Image, position: plugins.Position) plugins.SeekPos { const file_end = self.frames; var seek_pos = position.seekPos(file_end); - std.debug.warn("\tstart {d} end {d}\n", .{ seek_pos.start, seek_pos.end }); + log.debug("\tstart {d} end {d}\n", .{ seek_pos.start, seek_pos.end }); return seek_pos; } @@ -267,7 +268,7 @@ pub const Image = struct { self.curpath = path; self.frames = @intCast(usize, in_fmt.frames); - std.debug.warn("\timage: reopened on '{s}' (frames={d}, fmt.frames={d})\n", .{ + log.debug("\timage: reopened on '{s}' (frames={d}, fmt.frames={d})\n", .{ self.curpath, self.frames, in_fmt.frames, @@ -310,12 +311,12 @@ pub const Image = struct { defer ctx.allocator.free(ports); if (ctx.n_audio_in > 2) { - std.debug.warn("plugin <{s}> has more than two inputs.\n", .{plugin_uri}); + log.debug("plugin <{s}> has more than two inputs.\n", .{plugin_uri}); return ImageError.InvalidPlugin; } if (ctx.n_audio_out > 2) { - std.debug.warn("plugin <{s}> has more than two outputs.\n", .{plugin_uri}); + log.debug("plugin <{s}> has more than two outputs.\n", .{plugin_uri}); return ImageError.InvalidPlugin; } @@ -327,14 +328,14 @@ pub const Image = struct { var sym = c.lilv_new_string(ctx.world, sym_cstr.ptr); const port = c.lilv_plugin_get_port_by_symbol(ctx.plugin, sym) orelse { - std.debug.warn("assert fail: symbol {s} not found on port\n", .{param.sym}); + log.debug("assert fail: symbol {s} not found on port\n", .{param.sym}); return ImageError.InvalidSymbol; }; c.lilv_node_free(sym); var idx = c.lilv_port_get_index(ctx.plugin, port); - std.debug.warn("\tset sym={s}, idx={d} to val={}\n", .{ + log.debug("\tset sym={s}, idx={d} to val={}\n", .{ param.sym, idx, param.value, @@ -345,7 +346,7 @@ pub const Image = struct { // now we need to generate a temporary file and put the output of // running the plugin on that file var tmpnam = try temporaryName(self.allocator); - std.debug.warn("\trunning plugin from '{s}' to '{s}'\n", .{ self.curpath, tmpnam }); + log.debug("\trunning plugin from '{s}' to '{s}'\n", .{ self.curpath, tmpnam }); var out_fmt = mkSfInfo(); var out_file = try sopen(self.allocator, tmpnam, c.SFM_WRITE, &out_fmt); @@ -378,7 +379,7 @@ pub const Image = struct { sseek(self.sndfile, seek_pos.start); var i: usize = seek_pos.start; - std.debug.warn("\tseek pos start: {d} end: {d}\n", .{ seek_pos.start, seek_pos.end }); + log.debug("\tseek pos start: {d} end: {d}\n", .{ seek_pos.start, seek_pos.end }); var inbuf = &rctx.buffers.in; var outbuf = &rctx.buffers.out; @@ -389,7 +390,7 @@ pub const Image = struct { const read_bytes = c.sf_readf_float(self.sndfile, inbuf, 1); if (read_bytes == 0) { - std.debug.warn("WARN! reached EOF at idx={d}\n", .{i}); + log.debug("WARN! reached EOF at idx={d}\n", .{i}); break; } @@ -418,11 +419,11 @@ pub const Image = struct { try self.checkValid(); var time_taken = timer.read(); - std.debug.warn("\ttook {d:.2}ms running plugin\n", .{time_taken / std.time.us_per_ms}); + log.debug("\ttook {d:.2}ms running plugin\n", .{time_taken / std.time.us_per_ms}); } pub fn saveTo(self: *Image, out_path: []const u8) !void { - std.debug.warn("\timg: copy from '{s}' to '{s}'\n", .{ self.curpath, out_path }); + log.debug("\timg: copy from '{s}' to '{s}'\n", .{ self.curpath, out_path }); try std.fs.copyFileAbsolute(self.curpath, out_path, .{}); } @@ -450,7 +451,7 @@ pub const Image = struct { // the code here is a copypaste of runPlugin() without the specific // lilv things. var tmpnam = try temporaryName(self.allocator); - std.debug.warn("\trunning CUSTOM plugin from '{s}' to '{s}'\n", .{ self.curpath, tmpnam }); + log.debug("\trunning CUSTOM plugin from '{s}' to '{s}'\n", .{ self.curpath, tmpnam }); var out_fmt = mkSfInfo(); var out_file = try sopen(self.allocator, tmpnam, c.SFM_WRITE, &out_fmt); @@ -477,7 +478,7 @@ pub const Image = struct { sseek(self.sndfile, seek_pos.start); var i: usize = seek_pos.start; - std.debug.warn("\tseek pos start: {d} end: {d}\n", .{ seek_pos.start, seek_pos.end }); + log.debug("\tseek pos start: {d} end: {d}\n", .{ seek_pos.start, seek_pos.end }); var inbuf = &bufs.in; var outbuf = &bufs.out; @@ -485,7 +486,7 @@ pub const Image = struct { while (i <= seek_pos.end) : (i += 1) { const read_bytes = c.sf_readf_float(self.sndfile, inbuf, 1); if (read_bytes == 0) { - std.debug.warn("WARN! reached EOF at idx={d}\n", .{i}); + log.debug("WARN! reached EOF at idx={d}\n", .{i}); break; } diff --git a/src/lang.zig b/src/lang.zig index f465895..4c4f8f5 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -3,6 +3,7 @@ const std = @import("std"); const plugin = @import("plugin.zig"); const custom = @import("custom.zig"); +const log = std.log.scoped(.scritcher_lang); pub const ParseError = error{ParseFail}; pub const CommandType = enum { @@ -146,7 +147,7 @@ pub const Command = struct { } pub fn print(base: *const @This()) void { - std.debug.warn("tag: {s}\n", .{base.tag}); + log.debug("tag: {s}\n", .{base.tag}); } pub const Noop = struct { @@ -524,9 +525,9 @@ pub const Lang = struct { } fn doError(self: *Lang, comptime fmt: []const u8, args: anytype) void { - std.debug.warn("ERROR! at line {}: ", .{self.line}); - std.debug.warn(fmt, args); - std.debug.warn("\n", .{}); + log.debug("ERROR! at line {}: ", .{self.line}); + log.debug(fmt, args); + log.debug("\n", .{}); self.has_error = true; } @@ -605,7 +606,7 @@ pub const Lang = struct { else => @compileError("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."), }; - std.debug.warn("parsing {s}, arg of type {s} => {any}\n", .{ + log.debug("parsing {s}, arg of type {s} => {any}\n", .{ @typeName(command_struct), @typeName(@TypeOf(argument_value)), argument_value, @@ -617,7 +618,7 @@ pub const Lang = struct { cmd.base.tag = command_struct.base_tag; const command = cmd.base.cast(command_struct).?; - std.debug.warn("cmd: {s}\n", .{command}); + log.debug("cmd: {s}\n", .{command}); } pub fn parse(self: *Lang, data: []const u8) !CommandList { diff --git a/src/lv2_helpers.zig b/src/lv2_helpers.zig index 599370c..62570df 100644 --- a/src/lv2_helpers.zig +++ b/src/lv2_helpers.zig @@ -1,6 +1,8 @@ const std = @import("std"); const plugin = @import("plugin.zig"); +const log = std.log.scoped(.scritcher_lv2); + pub const c = @cImport({ @cInclude("sndfile.h"); @cInclude("lilv/lilv.h"); @@ -21,7 +23,7 @@ const LV2_CORE__connectionOptional = Lv2Core("#connectionOptional"); pub fn lilv_instance_connect_port( instance: [*c]c.LilvInstance, port_index: u32, - data_location: ?*c_void, + data_location: ?*anyopaque, ) void { instance.?.*.lv2_descriptor.?.*.connect_port.?(instance.?.*.lv2_handle, port_index, data_location); } @@ -118,7 +120,7 @@ pub fn setupPorts(ctx: *plugin.Context) ![]Port { if (c.lilv_port_is_a(ctx.plugin, lport, lv2_InputPort)) { port.is_input = true; } else if (!c.lilv_port_is_a(ctx.plugin, lport, lv2_OutputPort) and !port.optional) { - std.debug.warn("Port {d} is neither input or output\n", .{i}); + log.debug("Port {d} is neither input or output\n", .{i}); return error.UnassignedIOPort; } @@ -134,7 +136,7 @@ pub fn setupPorts(ctx: *plugin.Context) ![]Port { ctx.n_audio_out += 1; } } else if (!port.optional) { - std.debug.warn("Port {d} has unsupported type\n", .{i}); + log.debug("Port {d} has unsupported type\n", .{i}); return error.UnsupportedPortType; } } diff --git a/src/magick.zig b/src/magick.zig index dd5f295..21f6d2d 100644 --- a/src/magick.zig +++ b/src/magick.zig @@ -2,6 +2,7 @@ const std = @import("std"); const images = @import("image.zig"); +const log = std.log.scoped(.scritcher_magick); const Image = images.Image; const mc = @cImport({ @@ -39,7 +40,7 @@ fn magickLoad(image: *Image) !MagickContext { var curpath = try std.cstr.addNullByte(image.allocator, image.curpath); defer image.allocator.free(curpath); - std.debug.warn("loading '{s}'\n", .{curpath}); + log.debug("loading '{s}'\n", .{curpath}); if (mc.MagickReadImage(mctx.wand, curpath.ptr) != 1) return error.MagickReadFail; @@ -54,12 +55,12 @@ fn magickSave(image: *Image, wand: *mc.MagickWand) !void { var c_tmpnam = try std.cstr.addNullByte(allocator, tmpnam); defer allocator.free(c_tmpnam); - std.debug.warn("\tmagick: saving to '{s}'..", .{c_tmpnam}); + log.debug("\tmagick: saving to '{s}'..", .{c_tmpnam}); if (mc.MagickWriteImage(wand, c_tmpnam.ptr) != 1) return error.MagickWriteFail; - std.debug.warn("OK\n", .{}); + log.debug("OK\n", .{}); try image.reopen(tmpnam); } diff --git a/src/main.zig b/src/main.zig index 005100b..c41d2e4 100644 --- a/src/main.zig +++ b/src/main.zig @@ -3,6 +3,8 @@ const langs = @import("lang.zig"); const runners = @import("runner.zig"); const printer = @import("printer.zig"); +const log = std.log.scoped(.scritcher); + test "scritcher" { _ = @import("lang.zig"); _ = @import("runner.zig"); @@ -132,7 +134,7 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void { var rd_line = readline.readline("> "); if (rd_line == null) { - std.debug.warn("leaving from eof\n", .{}); + log.debug("leaving from eof\n", .{}); break; } readline.add_history(rd_line); @@ -200,14 +202,14 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void { try printer.printList(cmds, stream); continue; } else if (std.mem.eql(u8, line, "quit") or std.mem.eql(u8, line, "q")) { - std.debug.warn("leaving\n", .{}); + log.debug("leaving\n", .{}); break; } else if (std.mem.startsWith(u8, line, "#")) { continue; } var cmds_parsed = lang.parse(line) catch |err| { - std.debug.warn("repl: error while parsing: {}\n", .{err}); + log.debug("repl: error while parsing: {}\n", .{err}); continue; }; @@ -231,10 +233,10 @@ pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void { } fn doHelp() void { - std.debug.warn("scritcher!\n", .{}); - std.debug.warn("usage: scritcher [run|help|repl]\n", .{}); - std.debug.warn("\tscritcher run path_to_script.scri path_to_input_file.bmp\n", .{}); - std.debug.warn("\tscritcher repl path_to_script.scri path_to_input_file.bmp\n", .{}); + log.debug("scritcher!\n", .{}); + log.debug("usage: scritcher [run|help|repl]\n", .{}); + log.debug("\tscritcher run path_to_script.scri path_to_input_file.bmp\n", .{}); + log.debug("\tscritcher repl path_to_script.scri path_to_input_file.bmp\n", .{}); } fn doRun(allocator: *std.mem.Allocator, args_it: anytype) !void { @@ -288,7 +290,7 @@ pub fn main() !void { } else if (std.mem.eql(u8, cli_command, "run")) { return try doRun(allocator, &args_it); } else { - std.debug.warn("unknown command: '{s}'\n", .{cli_command}); + log.debug("unknown command: '{s}'\n", .{cli_command}); return error.UnknownCommand; } } diff --git a/src/plugin.zig b/src/plugin.zig index cb8c64a..d046edb 100644 --- a/src/plugin.zig +++ b/src/plugin.zig @@ -3,6 +3,7 @@ const std = @import("std"); const lv2 = @import("lv2_helpers.zig"); const c = lv2.c; +const log = std.log.scoped(.scritcher_plugin); const ImageError = @import("image.zig").ImageError; /// Control port @@ -137,7 +138,7 @@ pub fn makeContext(allocator: *std.mem.Allocator, plugin_uri: []const u8) !Conte c.lilv_world_load_all(world); var uri: *c.LilvNode = c.lilv_new_uri(world, cstr_plugin_uri.ptr) orelse { - std.debug.warn("Invalid plugin URI <{s}>\n", .{plugin_uri}); + log.debug("Invalid plugin URI <{s}>\n", .{plugin_uri}); return ImageError.InvalidPlugin; }; defer c.lilv_node_free(uri); @@ -145,7 +146,7 @@ pub fn makeContext(allocator: *std.mem.Allocator, plugin_uri: []const u8) !Conte const plugins: *const c.LilvPlugins = c.lilv_world_get_all_plugins(world).?; var plugin: *const c.LilvPlugin = c.lilv_plugins_get_by_uri(plugins, uri) orelse { - std.debug.warn("Plugin <{s}> not found\n", .{plugin_uri}); + log.debug("Plugin <{s}> not found\n", .{plugin_uri}); return ImageError.UnknownPlugin; }; diff --git a/src/printer.zig b/src/printer.zig index c1fab31..a851602 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -1,6 +1,8 @@ const std = @import("std"); const langs = @import("lang.zig"); +const log = std.log.scoped(.scritcher_printer); + fn printCommandWithParams(stream: anytype, command: anytype) !void { const Parameters = @TypeOf(command.parameters); try stream.print(" {d} {d}", .{ command.split, command.index }); diff --git a/src/runner.zig b/src/runner.zig index 16bbc12..40684a3 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -5,6 +5,8 @@ const plugin = @import("plugin.zig"); const custom = @import("custom.zig"); const magick = @import("magick.zig"); +const log = std.log.scoped(.scritcher_runner); + const Position = plugin.Position; const ParamList = plugin.ParamList; const ParamMap = plugin.ParamMap; @@ -65,12 +67,12 @@ pub const Runner = struct { // 'scritcher repl ./script ./image' // ':0' should ALWAYS point to the image. - if (self.repl) index += 4 else index += 3; + if (self.repl) index += 3 else index += 3; for (self.args) |arg, idx| { - std.debug.warn("arg{d} = {s}\n", .{ idx, arg }); + log.debug("arg{d} = {s}\n", .{ idx, arg }); } - std.debug.warn("fetch arg idx={d}, val={s}\n", .{ index, self.args[index] }); + log.debug("fetch arg idx={d}, val={s}\n", .{ index, self.args[index] }); return self.args[index]; } else { return load_path; @@ -90,7 +92,7 @@ pub const Runner = struct { fn loadCmd(self: *Runner, path_or_argidx: []const u8) !void { const load_path = try self.resolveArgPath(path_or_argidx); - std.debug.warn("\tload path: {s}\n", .{load_path}); + log.debug("\tload path: {s}\n", .{load_path}); // we could use ImageMagick to convert from X to BMP // but i can't find an easy way to do things in memory. @@ -100,7 +102,7 @@ pub const Runner = struct { // krita/gimp and make it export a bmp and while in the program you can // apply filters, etc. if (!std.mem.endsWith(u8, load_path, ".bmp") and !std.mem.endsWith(u8, load_path, ".ppm")) { - std.debug.warn("Only BMP files are allowed to be loaded. Got path '{s}'\n", .{load_path}); + log.debug("Only BMP files are allowed to be loaded. Got path '{s}'\n", .{load_path}); return RunError.NoBMP; } @@ -115,7 +117,7 @@ pub const Runner = struct { if (self.image) |image| { return image; } else { - std.debug.warn("image is required!\n", .{}); + log.debug("image is required!\n", .{}); return RunError.ImageRequired; } } @@ -201,7 +203,7 @@ pub const Runner = struct { ); defer proc.deinit(); - std.debug.warn("running '{s} {s}'\n", .{ runqs.program, out_path }); + log.debug("running '{s} {s}'\n", .{ runqs.program, out_path }); _ = try proc.spawnAndWait(); } From 5d1bcf33ee17a39a27bf91b141d54e9bf1cfa360 Mon Sep 17 00:00:00 2001 From: Luna Date: Wed, 27 Apr 2022 20:01:12 -0300 Subject: [PATCH 171/182] fixes for latest zig: a lot of stuff --- src/custom.zig | 31 ++++++++++++++----------- src/image.zig | 24 +++++++++----------- src/lang.zig | 61 +++++++++++++++++++++++++------------------------- src/magick.zig | 1 + src/main.zig | 8 +++---- src/plugin.zig | 8 ++++--- src/runner.zig | 22 +++++++++--------- 7 files changed, 80 insertions(+), 75 deletions(-) diff --git a/src/custom.zig b/src/custom.zig index 401b39f..4e48d6a 100644 --- a/src/custom.zig +++ b/src/custom.zig @@ -12,11 +12,11 @@ const RunBuffers = plugins.RunBuffers; pub const RandomNoise = struct { r: std.rand.DefaultPrng, rand_buf: ?[]f32 = null, - allocator: ?*std.mem.Allocator = null, + allocator: ?std.mem.Allocator = null, cnt: usize = 0, pub fn init( - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, params: anytype, ) ?RandomNoise { var r = std.rand.DefaultPrng.init(params.seed); @@ -25,7 +25,7 @@ pub const RandomNoise = struct { var rand_buf = allocator.alloc(f32, params.fill_bytes) catch return null; for (rand_buf) |_, idx| { - rand_buf[idx] = r.random.float(f32); + rand_buf[idx] = r.random().float(f32); } return RandomNoise{ @@ -52,7 +52,7 @@ pub const RandomNoise = struct { bufs.out[0] = rand_buf[self.cnt]; self.cnt += 1; } else { - bufs.out[0] = self.r.random.float(f32); + bufs.out[0] = self.r.random().float(f32); } } }; @@ -60,11 +60,11 @@ pub const RandomNoise = struct { pub const WildNoise = struct { r: std.rand.DefaultPrng, rand_buf: ?[]f32 = null, - allocator: ?*std.mem.Allocator = null, + allocator: ?std.mem.Allocator = null, cnt: usize = 0, pub fn init( - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, params: anytype, ) ?WildNoise { var r = std.rand.DefaultPrng.init(params.seed); @@ -73,7 +73,7 @@ pub const WildNoise = struct { var rand_buf = allocator.alloc(f32, params.fill_bytes) catch return null; for (rand_buf) |_, idx| { - rand_buf[idx] = @intToFloat(f32, r.random.int(u1)); + rand_buf[idx] = @intToFloat(f32, r.random().int(u1)); } return WildNoise{ @@ -99,7 +99,7 @@ pub const WildNoise = struct { bufs.out[0] = rand_buf[self.cnt]; self.cnt += 1; } else { - bufs.out[0] = @intToFloat(f32, self.r.random.int(u1)); + bufs.out[0] = @intToFloat(f32, self.r.random().int(u1)); } } }; @@ -112,15 +112,18 @@ pub const Write = struct { data: f32, pub fn init( - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, params: anytype, ) Write { + _ = allocator; return Write{ .data = params.data, }; } - pub fn deinit(self: *Write) void {} + pub fn deinit(self: *Write) void { + _ = self; + } pub fn run(self: *Write, bufs: *RunBuffers) void { bufs.out[0] = self.data; @@ -128,13 +131,13 @@ pub const Write = struct { }; pub const Embed = struct { - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, filepath: []const u8, sndfile: *c.SNDFILE = undefined, buf: []f32 = undefined, - pub fn init(allocator: *std.mem.Allocator, params: anytype) @This() { + pub fn init(allocator: std.mem.Allocator, params: anytype) @This() { return Embed{ .allocator = allocator, .filepath = params.path, @@ -163,7 +166,9 @@ pub const Embed = struct { self.buf = try self.allocator.alloc(f32, @intCast(usize, in_fmt.channels)); } - pub fn deinit(self: *@This()) void {} + pub fn deinit(self: *@This()) void { + _ = self; + } pub fn run(self: *@This(), bufs: *RunBuffers) void { const read_bytes = c.sf_readf_float(self.sndfile, self.buf.ptr, 1); diff --git a/src/image.zig b/src/image.zig index 4a01845..073ffc4 100644 --- a/src/image.zig +++ b/src/image.zig @@ -21,7 +21,7 @@ pub const ImageError = error{ /// Low level integration function with libsndfile. pub fn sopen( - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, path: []const u8, mode: i32, fmt: *c.SF_INFO, @@ -43,10 +43,10 @@ pub fn sopen( const frames_on_end = c.sf_seek(file, 0, c.SEEK_END); _ = c.sf_seek(file, 0, c.SEEK_SET); - std.testing.expectEqual(fmt.frames, frames_on_end); + try std.testing.expectEqual(fmt.frames, frames_on_end); const frames_on_end_by_end = c.sf_seek(file, frames_on_end, c.SEEK_SET); - std.testing.expectEqual(frames_on_end, frames_on_end_by_end); + try std.testing.expectEqual(frames_on_end, frames_on_end_by_end); log.debug("frames on end: {}, frame on end (2): {}\n", .{ frames_on_end, frames_on_end_by_end }); @@ -66,7 +66,7 @@ pub fn sseek(file: *c.SNDFILE, offset: usize) void { const offset_i64 = @intCast(i64, offset); const frames = c.sf_seek(file, offset_i64, c.SEEK_SET); const frames_current = c.sf_seek(file, 0, c.SEEK_CUR); - std.testing.expectEqual(frames, frames_current); + std.debug.assert(frames == frames_current); if (frames != offset_i64) { log.debug("failed to seek to {} (seeked {} frames, offset_i64={})\n", .{ offset, frames, offset_i64 }); @@ -74,7 +74,7 @@ pub fn sseek(file: *c.SNDFILE, offset: usize) void { } /// Caller owns the returned memory. -pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 { +pub fn temporaryName(allocator: std.mem.Allocator) ![]u8 { const template_start = "/temp/temp_"; const template = "/tmp/temp_XXXXXXXXXXXXXXXXXXXXX"; var nam = try allocator.alloc(u8, template.len); @@ -89,7 +89,7 @@ pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 { while (i < 100) : (i += 1) { // generate a random uppercase letter, that is, 65 + random number. for (fill) |_, f_idx| { - var idx = @intCast(u8, r.random.uintLessThan(u5, 24)); + var idx = @intCast(u8, r.random().uintLessThan(u5, 24)); var letter = @as(u8, 65) + idx; fill[f_idx] = letter; } @@ -97,7 +97,7 @@ pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 { // if we fail to access it, we assume it doesn't exist and return it. var tmp_file: std.fs.File = std.fs.cwd().openFile( nam, - .{ .read = true, .write = false }, + .{ .mode = .read_only }, ) catch |err| { if (err == error.FileNotFound) return nam else continue; }; @@ -122,7 +122,7 @@ pub fn mkSfInfo() c.SF_INFO { } pub const Image = struct { - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, /// Pointer to the underlying libsndfile's SNDFILE struct. sndfile: *c.SNDFILE, @@ -137,7 +137,7 @@ pub const Image = struct { curpath: []const u8, /// Open a BMP image for later. - pub fn open(allocator: *std.mem.Allocator, path: []const u8) !*Image { + pub fn open(allocator: std.mem.Allocator, path: []const u8) !*Image { var in_fmt = mkSfInfo(); var sndfile = try sopen(allocator, path, c.SFM_READ, &in_fmt); @@ -197,9 +197,7 @@ pub const Image = struct { } pub fn read(self: *Image, file_chans: c_int, buf: []f32) bool { - var file = file_opt.?; - - const n_read: c.sf_count_t = c.sf_readf_float(file, buf.ptr, 1); + const n_read: c.sf_count_t = c.sf_readf_float(self.sndfile, buf.ptr, 1); const buf_chans = @intCast(c_int, buf.len); var i = file_chans - 1; @@ -276,7 +274,7 @@ pub const Image = struct { } pub fn checkValid(self: *Image) !void { - var file = try std.fs.cwd().openFile(self.path, .{ .read = true }); + var file = try std.fs.cwd().openFile(self.path, .{ .mode = .read_only }); defer file.close(); // main bmp header: diff --git a/src/lang.zig b/src/lang.zig index 4c4f8f5..4c5973e 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -471,7 +471,7 @@ pub const CommandList = struct { list: CmdArrayList, const Self = @This(); - pub fn init(allocator: *std.mem.Allocator) Self { + pub fn init(allocator: std.mem.Allocator) Self { return .{ .list = CmdArrayList.init(allocator), }; @@ -486,13 +486,16 @@ pub const CommandList = struct { @field(Command.Tag, field.name); // if we find a match on the tag, we can get the type const typ = Command.tagToType(actual_tag); + _ = typ; - inline for (@typeInfo(typ).Struct.fields) |cmd_field| { - switch (cmd_field.field_type) { - []u8, []const u8 => self.list.allocator.destroy(@field(typ, cmd_field.name)), - else => {}, - } - } + // TODO fix + + //inline for (@typeInfo(typ).Struct.fields) |cmd_field| { + // switch (cmd_field.field_type) { + // []u8, []const u8 => self.list.allocator.destroy(@field(typ, cmd_field.name)), + // else => {}, + // } + //} } } } @@ -506,18 +509,20 @@ pub const CommandList = struct { /// A parser. pub const Lang = struct { - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, has_error: bool = false, line: usize = 0, - pub fn init(allocator: *std.mem.Allocator) Lang { + pub fn init(allocator: std.mem.Allocator) Lang { return Lang{ .allocator = allocator, }; } - pub fn deinit(self: *Lang) void {} + pub fn deinit(self: *Lang) void { + _ = self; + } pub fn reset(self: *Lang) void { self.has_error = false; @@ -534,7 +539,7 @@ pub const Lang = struct { fn parseCommandArguments( self: *@This(), comptime command_struct: type, - tok_it: *std.mem.TokenIterator, + tok_it: *std.mem.SplitIterator(u8), commands: *CommandList, ) !void { // Based on the command struct fields, we can parse the arguments. @@ -622,7 +627,7 @@ pub const Lang = struct { } pub fn parse(self: *Lang, data: []const u8) !CommandList { - var splitted_it = std.mem.split(data, ";"); + var splitted_it = std.mem.split(u8, data, ";"); var cmds = CommandList.init(self.allocator); errdefer cmds.deinit(); @@ -635,7 +640,7 @@ pub const Lang = struct { if (std.mem.startsWith(u8, stmt, "#")) continue; // TODO better tokenizer instead of just tokenize(" ")...maybe???? - var tok_it = std.mem.tokenize(stmt, " "); + var tok_it = std.mem.split(u8, stmt, " "); var cmd_opt = tok_it.next(); if (cmd_opt == null) { @@ -647,15 +652,14 @@ pub const Lang = struct { var found: bool = false; inline for (@typeInfo(Command).Struct.decls) |cmd_struct_decl| { - switch (cmd_struct_decl.data) { - .Type => |typ| switch (@typeInfo(typ)) { - .Struct => {}, - else => continue, - }, + const struct_name = cmd_struct_decl.name; + const cmd_struct_type = @field(Command, struct_name); + + switch (@typeInfo(@TypeOf(cmd_struct_type))) { + .Struct => {}, else => continue, } - const struct_name = cmd_struct_decl.name; comptime var lowered_command_name = [_]u8{0} ** struct_name.len; comptime { for (struct_name) |c, i| { @@ -675,7 +679,6 @@ pub const Lang = struct { if (std.mem.eql(u8, &lowered_command_name, command_string)) { found = true; - const cmd_struct_type = cmd_struct_decl.data.Type; try self.parseCommandArguments(cmd_struct_type, &tok_it, &cmds); } } @@ -699,8 +702,8 @@ test "noop" { var cmds = try lang.parse("noop;"); defer cmds.deinit(); - std.testing.expectEqual(cmds.list.items.len, 1); - std.testing.expectEqual(cmds.list.items[0].tag, .noop); + try std.testing.expectEqual(cmds.list.items.len, 1); + try std.testing.expectEqual(cmds.list.items[0].tag, .noop); } test "load, phaser, quicksave" { @@ -716,10 +719,10 @@ test "load, phaser, quicksave" { var cmds = try lang.parse(prog); defer cmds.deinit(); - std.testing.expectEqual(cmds.list.items.len, 3); - std.testing.expectEqual(cmds.list.items[0].tag, .load); - std.testing.expectEqual(cmds.list.items[1].tag, .phaser); - std.testing.expectEqual(cmds.list.items[2].tag, .quicksave); + try std.testing.expectEqual(cmds.list.items.len, 3); + try std.testing.expectEqual(cmds.list.items[0].tag, .load); + try std.testing.expectEqual(cmds.list.items[1].tag, .phaser); + try std.testing.expectEqual(cmds.list.items[2].tag, .quicksave); } test "load, phaser with errors, quicksave" { @@ -732,9 +735,5 @@ test "load, phaser with errors, quicksave" { \\quicksave; ; - var cmds = lang.parse(prog) catch |err| { - return; - }; - - unreachable; + try std.testing.expectError(error.ParseFail, lang.parse(prog)); } diff --git a/src/magick.zig b/src/magick.zig index 21f6d2d..c88ceba 100644 --- a/src/magick.zig +++ b/src/magick.zig @@ -29,6 +29,7 @@ pub const MagickContext = struct { } pub fn doErr(self: *MagickContext) !void { + _ = self; return error.WandError; } }; diff --git a/src/main.zig b/src/main.zig index c41d2e4..9045304 100644 --- a/src/main.zig +++ b/src/main.zig @@ -18,13 +18,13 @@ const readline = @cImport({ @cInclude("readline/history.h"); }); -fn wrapInCmdList(allocator: *std.mem.Allocator, cmd: *langs.Command) !langs.CommandList { +fn wrapInCmdList(allocator: std.mem.Allocator, cmd: *langs.Command) !langs.CommandList { var cmds = langs.CommandList.init(allocator); try cmds.append(cmd); return cmds; } -fn copyCommandToHeap(allocator: *std.mem.Allocator, command: langs.Command, comptime tag: langs.Command.Tag) !*langs.Command { +fn copyCommandToHeap(allocator: std.mem.Allocator, command: langs.Command, comptime tag: langs.Command.Tag) !*langs.Command { const CommandStruct = langs.Command.tagToType(tag); const casted = command.cast(CommandStruct).?; var heap_cmd = try allocator.create(CommandStruct); @@ -38,7 +38,7 @@ fn copyCommandToHeap(allocator: *std.mem.Allocator, command: langs.Command, comp return &heap_cmd.base; } -pub fn doRepl(allocator: *std.mem.Allocator, args_it: anytype) !void { +pub fn doRepl(allocator: std.mem.Allocator, args_it: anytype) !void { var stdout_file = std.io.getStdOut(); const stdout = &stdout_file.writer(); const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path")); @@ -239,7 +239,7 @@ fn doHelp() void { log.debug("\tscritcher repl path_to_script.scri path_to_input_file.bmp\n", .{}); } -fn doRun(allocator: *std.mem.Allocator, args_it: anytype) !void { +fn doRun(allocator: std.mem.Allocator, args_it: anytype) !void { var lang = langs.Lang.init(allocator); defer lang.deinit(); diff --git a/src/plugin.zig b/src/plugin.zig index d046edb..8e88283 100644 --- a/src/plugin.zig +++ b/src/plugin.zig @@ -47,7 +47,7 @@ pub const Position = struct { /// Represents the starting context for a single plugin run. pub const Context = struct { - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, world: *c.LilvWorld, plugin: *const c.LilvPlugin, @@ -75,9 +75,11 @@ pub const RunContext = struct { instance: *c.LilvInstance, pub fn init( - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, plugin: *const c.LilvPlugin, ) !RunContext { + _ = allocator; // TODO batch RunBuffers? + var instance = c.lilv_plugin_instantiate(plugin, @as(f64, 44100), null); errdefer c.lilv_instance_free(instance); @@ -128,7 +130,7 @@ pub const RunContext = struct { } }; -pub fn makeContext(allocator: *std.mem.Allocator, plugin_uri: []const u8) !Context { +pub fn makeContext(allocator: std.mem.Allocator, plugin_uri: []const u8) !Context { const cstr_plugin_uri = try std.cstr.addNullByte(allocator, plugin_uri); defer allocator.free(cstr_plugin_uri); diff --git a/src/runner.zig b/src/runner.zig index 40684a3..eb41231 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -20,7 +20,7 @@ pub const RunError = error{ }; pub const Runner = struct { - allocator: *std.mem.Allocator, + allocator: std.mem.Allocator, /// The currently opened image in the runner image: ?*Image = null, @@ -30,7 +30,7 @@ pub const Runner = struct { args: []const [:0]u8, - pub fn init(allocator: *std.mem.Allocator, repl: bool) Runner { + pub fn init(allocator: std.mem.Allocator, repl: bool) Runner { return Runner{ .allocator = allocator, .repl = repl, @@ -164,6 +164,8 @@ pub const Runner = struct { // if N isn't a number, we just ignore that file const idx_str = entry.name[entry_gidx + 2 .. entry_pidx]; const idx = std.fmt.parseInt(usize, idx_str, 10) catch |err| { + log.debug("ignoring file {s}", .{@errorName(err)}); + break :blk {}; }; @@ -254,7 +256,7 @@ pub const Runner = struct { cmd: lang.Command, comptime tag: lang.Command.Tag, ) !void { - comptime const typ = lang.Command.tagToType(tag); + const typ = lang.Command.tagToType(tag); const command = cmd.cast(typ).?; const ctype = typ.command_type; switch (ctype) { @@ -315,6 +317,7 @@ pub const Runner = struct { cmds: lang.CommandList, debug_flag: bool, ) !void { + _ = debug_flag; for (cmds.list.items) |cmd| { cmd.print(); try self.runCommand(cmd.*); @@ -323,18 +326,15 @@ pub const Runner = struct { }; test "running noop" { - const allocator = std.heap.direct_allocator; + const allocator = std.testing.allocator; var cmds = lang.CommandList.init(allocator); defer cmds.deinit(); - var cmd_ptr = try allocator.create(lang.Command); - cmd_ptr.* = lang.Command{ - .command = .Noop, - .args = lang.ArgList.init(allocator), - }; - try cmds.append(cmd_ptr); + var command = lang.Command{ .tag = .noop }; + var noop = lang.Command.Noop{ .base = command }; + try cmds.append(&noop.base); - var runner = Runner.init(allocator); + var runner = Runner.init(allocator, false); defer runner.deinit(); try runner.runCommands(cmds, false); From 1987c4d497d479fe81367fa7bef9c7768518a40d Mon Sep 17 00:00:00 2001 From: Luna Date: Wed, 27 Apr 2022 20:01:14 -0300 Subject: [PATCH 172/182] fix command parsing --- src/lang.zig | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 4c5973e..98b1e77 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -479,7 +479,7 @@ pub const CommandList = struct { pub fn deinit(self: *Self) void { for (self.list.items) |cmd_ptr| { - self.list.allocator.destroy(cmd_ptr); + //self.list.allocator.destroy(cmd_ptr); inline for (@typeInfo(Command.Tag).Enum.fields) |field| { if (cmd_ptr.tag == @field(Command.Tag, field.name)) { const actual_tag = @@ -530,9 +530,9 @@ pub const Lang = struct { } fn doError(self: *Lang, comptime fmt: []const u8, args: anytype) void { - log.debug("ERROR! at line {}: ", .{self.line}); - log.debug(fmt, args); - log.debug("\n", .{}); + log.err("ERROR! at line {}: ", .{self.line}); + log.err(fmt, args); + log.err("\n", .{}); self.has_error = true; } @@ -655,7 +655,16 @@ pub const Lang = struct { const struct_name = cmd_struct_decl.name; const cmd_struct_type = @field(Command, struct_name); - switch (@typeInfo(@TypeOf(cmd_struct_type))) { + const info_of_info = @typeInfo(@TypeOf(cmd_struct_type)); + + switch (info_of_info) { + .Type => {}, + else => continue, + } + + const info = @typeInfo(cmd_struct_type); + + switch (info) { .Struct => {}, else => continue, } @@ -677,7 +686,7 @@ pub const Lang = struct { // Attempting to use ComptimeHashMap hits compiler bugs and I'm // not sure if we can map strings to *types* in it. - if (std.mem.eql(u8, &lowered_command_name, command_string)) { + if ((!found) and std.mem.eql(u8, &lowered_command_name, command_string)) { found = true; try self.parseCommandArguments(cmd_struct_type, &tok_it, &cmds); } From 2796b654e54e96db6f51824616eaaef22d0edeba Mon Sep 17 00:00:00 2001 From: Luna Date: Thu, 28 Apr 2022 00:08:52 -0300 Subject: [PATCH 173/182] port main() code path to latest zig --- .gitignore | 1 + src/image.zig | 2 +- src/main.zig | 15 +++++++-------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 44f7213..346c11d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ zig-cache/ +zig-out/ *.mp3 *.wav build_runner.zig diff --git a/src/image.zig b/src/image.zig index 073ffc4..45aa6da 100644 --- a/src/image.zig +++ b/src/image.zig @@ -161,7 +161,7 @@ pub const Image = struct { var in_fmt = mkSfInfo(); // clone sndfile var sndfile = try sopen(self.allocator, self.curpath, c.SFM_READ, &in_fmt); - std.testing.expectEqual(self.frames, @intCast(usize, in_fmt.frames)); + std.debug.assert(self.frames == @intCast(usize, in_fmt.frames)); var image = try self.allocator.create(Image); diff --git a/src/main.zig b/src/main.zig index 9045304..ee269c1 100644 --- a/src/main.zig +++ b/src/main.zig @@ -41,7 +41,7 @@ fn copyCommandToHeap(allocator: std.mem.Allocator, command: langs.Command, compt pub fn doRepl(allocator: std.mem.Allocator, args_it: anytype) !void { var stdout_file = std.io.getStdOut(); const stdout = &stdout_file.writer(); - const scri_path = try (args_it.next(allocator) orelse @panic("expected scri path")); + const scri_path = (args_it.next() orelse @panic("expected scri path")); errdefer allocator.free(scri_path); defer allocator.free(scri_path); @@ -246,8 +246,7 @@ fn doRun(allocator: std.mem.Allocator, args_it: anytype) !void { var runner = runners.Runner.init(allocator, false); defer runner.deinit(); - const scri_path = try (args_it.next(allocator) orelse @panic("run: expected scri path")); - defer allocator.free(scri_path); + const scri_path = (args_it.next() orelse @panic("run: expected scri path")); var file = try std.fs.cwd().openFile(scri_path, .{}); defer file.close(); @@ -270,18 +269,18 @@ pub fn main() !void { defer { _ = allocator_instance.deinit(); } - const allocator = &allocator_instance.allocator; + const allocator = allocator_instance.allocator(); - var args_it = std.process.args(); + var args_it = try std.process.argsWithAllocator(allocator); + defer args_it.deinit(); _ = args_it.skip(); - const cli_command_opt = args_it.next(allocator); + const cli_command_opt = args_it.next(); if (cli_command_opt == null) { return doHelp(); } - const cli_command = try cli_command_opt.?; - defer allocator.free(cli_command); + const cli_command = cli_command_opt.?; if (std.mem.eql(u8, cli_command, "help")) { return doHelp(); From 6b2ce7e4250719ac4b15158ec289bd3fcf645fb5 Mon Sep 17 00:00:00 2001 From: Luna Date: Thu, 28 Apr 2022 00:28:07 -0300 Subject: [PATCH 174/182] properly fix memleaks --- src/lang.zig | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 98b1e77..5ded695 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -479,25 +479,24 @@ pub const CommandList = struct { pub fn deinit(self: *Self) void { for (self.list.items) |cmd_ptr| { - //self.list.allocator.destroy(cmd_ptr); inline for (@typeInfo(Command.Tag).Enum.fields) |field| { if (cmd_ptr.tag == @field(Command.Tag, field.name)) { const actual_tag = @field(Command.Tag, field.name); // if we find a match on the tag, we can get the type const typ = Command.tagToType(actual_tag); - _ = typ; - // TODO fix - - //inline for (@typeInfo(typ).Struct.fields) |cmd_field| { - // switch (cmd_field.field_type) { - // []u8, []const u8 => self.list.allocator.destroy(@field(typ, cmd_field.name)), - // else => {}, - // } - //} + const inner_command = cmd_ptr.cast(typ).?; + inline for (@typeInfo(typ).Struct.fields) |cmd_field| { + switch (cmd_field.field_type) { + []u8, []const u8 => self.list.allocator.free(@field(inner_command, cmd_field.name)), + else => {}, + } + } } } + + self.list.allocator.destroy(cmd_ptr); } self.list.deinit(); } From ef6c68705dcdaa724d97519390e41b8102e1eb4d Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 8 Oct 2022 15:05:15 -0300 Subject: [PATCH 175/182] port to latest zig --- build.zig | 8 ++++---- src/lang.zig | 12 ++++++------ src/runner.zig | 11 +++++++---- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/build.zig b/build.zig index f7b08f9..ad6f87d 100644 --- a/build.zig +++ b/build.zig @@ -12,8 +12,8 @@ fn setupLinks(step: *builds.LibExeObjStep) void { step.linkSystemLibrary("GraphicsMagickWand"); step.linkSystemLibrary("GraphicsMagick"); - step.addIncludeDir("/usr/include/GraphicsMagick"); - step.addIncludeDir("/usr/include"); + step.addIncludePath("/usr/include/GraphicsMagick"); + step.addIncludePath("/usr/include"); const possible_lilv_include_dirs = [_][]const u8{ "/usr/include/lilv-0/lilv", @@ -24,7 +24,7 @@ fn setupLinks(step: *builds.LibExeObjStep) void { for (possible_lilv_include_dirs) |possible_lilv_dir| { var possible_dir = std.fs.cwd().openDir(possible_lilv_dir, .{}) catch |err| { - std.debug.print("possible lilv {s} fail: {s}\n", .{ possible_lilv_dir, err }); + std.debug.print("possible lilv {s} fail: {s}\n", .{ possible_lilv_dir, @errorName(err) }); continue; }; @@ -32,7 +32,7 @@ fn setupLinks(step: *builds.LibExeObjStep) void { found_any_lilv = true; std.debug.print("found lilv at '{s}'\n", .{possible_lilv_dir}); - step.addIncludeDir(possible_lilv_dir); + step.addIncludePath(possible_lilv_dir); } if (!found_any_lilv) { diff --git a/src/lang.zig b/src/lang.zig index 5ded695..e4a742d 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -94,7 +94,7 @@ pub const Command = struct { rotate, }; - pub fn tagToType(tag: Tag) type { + pub fn tagToType(comptime tag: Tag) type { return switch (tag) { .noop => Noop, .load => Load, @@ -147,7 +147,7 @@ pub const Command = struct { } pub fn print(base: *const @This()) void { - log.debug("tag: {s}\n", .{base.tag}); + log.debug("tag: {}\n", .{base.tag}); } pub const Noop = struct { @@ -529,9 +529,9 @@ pub const Lang = struct { } fn doError(self: *Lang, comptime fmt: []const u8, args: anytype) void { - log.err("ERROR! at line {}: ", .{self.line}); - log.err(fmt, args); - log.err("\n", .{}); + log.warn("ERROR! at line {}: ", .{self.line}); + log.warn(fmt, args); + log.warn("\n", .{}); self.has_error = true; } @@ -622,7 +622,7 @@ pub const Lang = struct { cmd.base.tag = command_struct.base_tag; const command = cmd.base.cast(command_struct).?; - log.debug("cmd: {s}\n", .{command}); + log.debug("cmd: {}\n", .{command}); } pub fn parse(self: *Lang, data: []const u8) !CommandList { diff --git a/src/runner.zig b/src/runner.zig index eb41231..969c469 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -57,6 +57,7 @@ pub const Runner = struct { } fn resolveArg(self: *Runner, load_path: []const u8) ![]const u8 { + std.debug.assert(load_path.len > 0); if (load_path[0] == ':') { // parse the index from 1 to end var index = try std.fmt.parseInt(usize, load_path[1..], 10); @@ -131,7 +132,7 @@ pub const Runner = struct { const basename = std.fs.path.basename(image.path); const dirname = std.fs.path.dirname(image.path).?; - var dir = try std.fs.cwd().openDir(dirname, .{ .iterate = true }); + var dir = try std.fs.cwd().openIterableDir(dirname, .{}); defer dir.close(); const period_idx = std.mem.lastIndexOf(u8, basename, ".").?; @@ -199,11 +200,11 @@ pub const Runner = struct { defer self.allocator.free(out_path); try image.saveTo(out_path); - var proc = try std.ChildProcess.init( + var proc = std.ChildProcess.init( &[_][]const u8{ runqs.program, out_path }, self.allocator, ); - defer proc.deinit(); + //defer proc.deinit(); log.debug("running '{s} {s}'\n", .{ runqs.program, out_path }); _ = try proc.spawnAndWait(); @@ -331,7 +332,9 @@ test "running noop" { defer cmds.deinit(); var command = lang.Command{ .tag = .noop }; - var noop = lang.Command.Noop{ .base = command }; + + var noop = try allocator.create(lang.Command.Noop); + noop.* = lang.Command.Noop{ .base = command }; try cmds.append(&noop.base); var runner = Runner.init(allocator, false); From 43dad638f20280184dd14eb6b968a0177f0a6b27 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 8 Oct 2022 15:06:14 -0300 Subject: [PATCH 176/182] use stage1 --- build.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/build.zig b/build.zig index ad6f87d..520aeb9 100644 --- a/build.zig +++ b/build.zig @@ -45,6 +45,7 @@ pub fn build(b: *Builder) void { const mode = b.standardReleaseOptions(); const exe = b.addExecutable("scritcher", "src/main.zig"); exe.setBuildMode(mode); + exe.use_stage1 = true; exe.install(); setupLinks(exe); From 0f6ac055a484f2e499be79b1e266211c93fc7659 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 8 Oct 2022 15:14:56 -0300 Subject: [PATCH 177/182] remove extra newlines from log calls --- src/bmp_valid.zig | 2 +- src/custom.zig | 2 +- src/image.zig | 40 ++++++++++++++++++++-------------------- src/lang.zig | 7 +++---- src/lv2_helpers.zig | 4 ++-- src/magick.zig | 4 ++-- src/main.zig | 16 ++++++++-------- src/plugin.zig | 4 ++-- src/runner.zig | 13 +++++++------ 9 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/bmp_valid.zig b/src/bmp_valid.zig index 55970b8..6e256e8 100644 --- a/src/bmp_valid.zig +++ b/src/bmp_valid.zig @@ -19,7 +19,7 @@ pub fn magicValid(magic: []const u8) !void { } if (!valid) { - log.debug("\tINVALID HEADER: '{s}'\n", .{magic}); + log.debug("\tINVALID HEADER: '{s}'", .{magic}); return BMPValidError.InvalidMagic; } } diff --git a/src/custom.zig b/src/custom.zig index 4e48d6a..ffb129c 100644 --- a/src/custom.zig +++ b/src/custom.zig @@ -180,7 +180,7 @@ pub const Embed = struct { if (read_bytes < 0) { const st: i32 = c.sf_error(self.sndfile); - log.debug("Failed to read {s} ({s})\n", .{ + log.debug("Failed to read {s} ({s})", .{ self.filepath, c.sf_error_number(st), }); diff --git a/src/image.zig b/src/image.zig index 45aa6da..6a7481c 100644 --- a/src/image.zig +++ b/src/image.zig @@ -33,7 +33,7 @@ pub fn sopen( const st: i32 = c.sf_error(file); if (st != 0) { - log.debug("Failed to open {s} ({s})\n", .{ + log.debug("Failed to open {s} ({s})", .{ path, c.sf_error_number(st), }); @@ -48,7 +48,7 @@ pub fn sopen( const frames_on_end_by_end = c.sf_seek(file, frames_on_end, c.SEEK_SET); try std.testing.expectEqual(frames_on_end, frames_on_end_by_end); - log.debug("frames on end: {}, frame on end (2): {}\n", .{ frames_on_end, frames_on_end_by_end }); + log.debug("frames on end: {}, frame on end (2): {}", .{ frames_on_end, frames_on_end_by_end }); return file.?; } @@ -57,7 +57,7 @@ pub fn swrite(file: *c.SNDFILE, buf: [*]f32, frames: i64) !void { const count = c.sf_writef_float(file, buf, frames); if (count != frames) { - log.debug("Wanted to write {}, got {}\n", .{ frames, count }); + log.debug("Wanted to write {}, got {}", .{ frames, count }); return ImageError.WriteFail; } } @@ -69,7 +69,7 @@ pub fn sseek(file: *c.SNDFILE, offset: usize) void { std.debug.assert(frames == frames_current); if (frames != offset_i64) { - log.debug("failed to seek to {} (seeked {} frames, offset_i64={})\n", .{ offset, frames, offset_i64 }); + log.debug("failed to seek to {} (seeked {} frames, offset_i64={})", .{ offset, frames, offset_i64 }); } } @@ -182,7 +182,7 @@ pub const Image = struct { pub fn close(self: *Image) void { var st: i32 = c.sf_close(self.sndfile); if (st != 0) { - log.debug("Failed to close {s} ({s})\n", .{ + log.debug("Failed to close {s} ({s})", .{ self.path, c.sf_error_number(st), }); @@ -227,7 +227,7 @@ pub const Image = struct { sseek(out_file, start); while (i <= end) : (i += buf.len) { - log.debug("\t\ti={d}, buf.len={d}, end={d}\n", .{ i, buf.len, end }); + log.debug("\t\ti={d}, buf.len={d}, end={d}", .{ i, buf.len, end }); sseek(self.sndfile, i); sseek(out_file, i); @@ -253,7 +253,7 @@ pub const Image = struct { fn getSeekPos(self: *Image, position: plugins.Position) plugins.SeekPos { const file_end = self.frames; var seek_pos = position.seekPos(file_end); - log.debug("\tstart {d} end {d}\n", .{ seek_pos.start, seek_pos.end }); + log.debug("\tstart {d} end {d}", .{ seek_pos.start, seek_pos.end }); return seek_pos; } @@ -266,7 +266,7 @@ pub const Image = struct { self.curpath = path; self.frames = @intCast(usize, in_fmt.frames); - log.debug("\timage: reopened on '{s}' (frames={d}, fmt.frames={d})\n", .{ + log.debug("\timage: reopened on '{s}' (frames={d}, fmt.frames={d})", .{ self.curpath, self.frames, in_fmt.frames, @@ -309,12 +309,12 @@ pub const Image = struct { defer ctx.allocator.free(ports); if (ctx.n_audio_in > 2) { - log.debug("plugin <{s}> has more than two inputs.\n", .{plugin_uri}); + log.debug("plugin <{s}> has more than two inputs.", .{plugin_uri}); return ImageError.InvalidPlugin; } if (ctx.n_audio_out > 2) { - log.debug("plugin <{s}> has more than two outputs.\n", .{plugin_uri}); + log.debug("plugin <{s}> has more than two outputs.", .{plugin_uri}); return ImageError.InvalidPlugin; } @@ -326,14 +326,14 @@ pub const Image = struct { var sym = c.lilv_new_string(ctx.world, sym_cstr.ptr); const port = c.lilv_plugin_get_port_by_symbol(ctx.plugin, sym) orelse { - log.debug("assert fail: symbol {s} not found on port\n", .{param.sym}); + log.debug("assert fail: symbol {s} not found on port", .{param.sym}); return ImageError.InvalidSymbol; }; c.lilv_node_free(sym); var idx = c.lilv_port_get_index(ctx.plugin, port); - log.debug("\tset sym={s}, idx={d} to val={}\n", .{ + log.debug("\tset sym={s}, idx={d} to val={}", .{ param.sym, idx, param.value, @@ -344,7 +344,7 @@ pub const Image = struct { // now we need to generate a temporary file and put the output of // running the plugin on that file var tmpnam = try temporaryName(self.allocator); - log.debug("\trunning plugin from '{s}' to '{s}'\n", .{ self.curpath, tmpnam }); + log.debug("\trunning plugin from '{s}' to '{s}'", .{ self.curpath, tmpnam }); var out_fmt = mkSfInfo(); var out_file = try sopen(self.allocator, tmpnam, c.SFM_WRITE, &out_fmt); @@ -377,7 +377,7 @@ pub const Image = struct { sseek(self.sndfile, seek_pos.start); var i: usize = seek_pos.start; - log.debug("\tseek pos start: {d} end: {d}\n", .{ seek_pos.start, seek_pos.end }); + log.debug("\tseek pos start: {d} end: {d}", .{ seek_pos.start, seek_pos.end }); var inbuf = &rctx.buffers.in; var outbuf = &rctx.buffers.out; @@ -388,7 +388,7 @@ pub const Image = struct { const read_bytes = c.sf_readf_float(self.sndfile, inbuf, 1); if (read_bytes == 0) { - log.debug("WARN! reached EOF at idx={d}\n", .{i}); + log.debug("WARN! reached EOF at idx={d}", .{i}); break; } @@ -417,11 +417,11 @@ pub const Image = struct { try self.checkValid(); var time_taken = timer.read(); - log.debug("\ttook {d:.2}ms running plugin\n", .{time_taken / std.time.us_per_ms}); + log.debug("\ttook {d:.2}ms running plugin", .{time_taken / std.time.us_per_ms}); } pub fn saveTo(self: *Image, out_path: []const u8) !void { - log.debug("\timg: copy from '{s}' to '{s}'\n", .{ self.curpath, out_path }); + log.debug("\timg: copy from '{s}' to '{s}'", .{ self.curpath, out_path }); try std.fs.copyFileAbsolute(self.curpath, out_path, .{}); } @@ -449,7 +449,7 @@ pub const Image = struct { // the code here is a copypaste of runPlugin() without the specific // lilv things. var tmpnam = try temporaryName(self.allocator); - log.debug("\trunning CUSTOM plugin from '{s}' to '{s}'\n", .{ self.curpath, tmpnam }); + log.debug("\trunning CUSTOM plugin from '{s}' to '{s}'", .{ self.curpath, tmpnam }); var out_fmt = mkSfInfo(); var out_file = try sopen(self.allocator, tmpnam, c.SFM_WRITE, &out_fmt); @@ -476,7 +476,7 @@ pub const Image = struct { sseek(self.sndfile, seek_pos.start); var i: usize = seek_pos.start; - log.debug("\tseek pos start: {d} end: {d}\n", .{ seek_pos.start, seek_pos.end }); + log.debug("\tseek pos start: {d} end: {d}", .{ seek_pos.start, seek_pos.end }); var inbuf = &bufs.in; var outbuf = &bufs.out; @@ -484,7 +484,7 @@ pub const Image = struct { while (i <= seek_pos.end) : (i += 1) { const read_bytes = c.sf_readf_float(self.sndfile, inbuf, 1); if (read_bytes == 0) { - log.debug("WARN! reached EOF at idx={d}\n", .{i}); + log.debug("WARN! reached EOF at idx={d}", .{i}); break; } diff --git a/src/lang.zig b/src/lang.zig index e4a742d..08346ff 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -147,7 +147,7 @@ pub const Command = struct { } pub fn print(base: *const @This()) void { - log.debug("tag: {}\n", .{base.tag}); + log.debug("tag: {}", .{base.tag}); } pub const Noop = struct { @@ -531,7 +531,6 @@ pub const Lang = struct { fn doError(self: *Lang, comptime fmt: []const u8, args: anytype) void { log.warn("ERROR! at line {}: ", .{self.line}); log.warn(fmt, args); - log.warn("\n", .{}); self.has_error = true; } @@ -610,7 +609,7 @@ pub const Lang = struct { else => @compileError("Invalid parameter type (" ++ @typeName(cmd_field.field_type) ++ ") left on command struct " ++ @typeName(command_struct) ++ "."), }; - log.debug("parsing {s}, arg of type {s} => {any}\n", .{ + log.debug("parsing {s}, arg of type {s} => {any}", .{ @typeName(command_struct), @typeName(@TypeOf(argument_value)), argument_value, @@ -622,7 +621,7 @@ pub const Lang = struct { cmd.base.tag = command_struct.base_tag; const command = cmd.base.cast(command_struct).?; - log.debug("cmd: {}\n", .{command}); + log.debug("cmd: {}", .{command}); } pub fn parse(self: *Lang, data: []const u8) !CommandList { diff --git a/src/lv2_helpers.zig b/src/lv2_helpers.zig index 62570df..82c961d 100644 --- a/src/lv2_helpers.zig +++ b/src/lv2_helpers.zig @@ -120,7 +120,7 @@ pub fn setupPorts(ctx: *plugin.Context) ![]Port { if (c.lilv_port_is_a(ctx.plugin, lport, lv2_InputPort)) { port.is_input = true; } else if (!c.lilv_port_is_a(ctx.plugin, lport, lv2_OutputPort) and !port.optional) { - log.debug("Port {d} is neither input or output\n", .{i}); + log.debug("Port {d} is neither input or output", .{i}); return error.UnassignedIOPort; } @@ -136,7 +136,7 @@ pub fn setupPorts(ctx: *plugin.Context) ![]Port { ctx.n_audio_out += 1; } } else if (!port.optional) { - log.debug("Port {d} has unsupported type\n", .{i}); + log.debug("Port {d} has unsupported type", .{i}); return error.UnsupportedPortType; } } diff --git a/src/magick.zig b/src/magick.zig index c88ceba..c6adf3c 100644 --- a/src/magick.zig +++ b/src/magick.zig @@ -41,7 +41,7 @@ fn magickLoad(image: *Image) !MagickContext { var curpath = try std.cstr.addNullByte(image.allocator, image.curpath); defer image.allocator.free(curpath); - log.debug("loading '{s}'\n", .{curpath}); + log.debug("loading '{s}'", .{curpath}); if (mc.MagickReadImage(mctx.wand, curpath.ptr) != 1) return error.MagickReadFail; @@ -61,7 +61,7 @@ fn magickSave(image: *Image, wand: *mc.MagickWand) !void { if (mc.MagickWriteImage(wand, c_tmpnam.ptr) != 1) return error.MagickWriteFail; - log.debug("OK\n", .{}); + log.debug("OK", .{}); try image.reopen(tmpnam); } diff --git a/src/main.zig b/src/main.zig index ee269c1..083b204 100644 --- a/src/main.zig +++ b/src/main.zig @@ -134,7 +134,7 @@ pub fn doRepl(allocator: std.mem.Allocator, args_it: anytype) !void { var rd_line = readline.readline("> "); if (rd_line == null) { - log.debug("leaving from eof\n", .{}); + log.debug("leaving from eof", .{}); break; } readline.add_history(rd_line); @@ -202,14 +202,14 @@ pub fn doRepl(allocator: std.mem.Allocator, args_it: anytype) !void { try printer.printList(cmds, stream); continue; } else if (std.mem.eql(u8, line, "quit") or std.mem.eql(u8, line, "q")) { - log.debug("leaving\n", .{}); + log.debug("leaving", .{}); break; } else if (std.mem.startsWith(u8, line, "#")) { continue; } var cmds_parsed = lang.parse(line) catch |err| { - log.debug("repl: error while parsing: {}\n", .{err}); + log.debug("repl: error while parsing: {}", .{err}); continue; }; @@ -233,10 +233,10 @@ pub fn doRepl(allocator: std.mem.Allocator, args_it: anytype) !void { } fn doHelp() void { - log.debug("scritcher!\n", .{}); - log.debug("usage: scritcher [run|help|repl]\n", .{}); - log.debug("\tscritcher run path_to_script.scri path_to_input_file.bmp\n", .{}); - log.debug("\tscritcher repl path_to_script.scri path_to_input_file.bmp\n", .{}); + log.debug("scritcher!", .{}); + log.debug("usage: scritcher [run|help|repl]", .{}); + log.debug("\tscritcher run path_to_script.scri path_to_input_file.bmp", .{}); + log.debug("\tscritcher repl path_to_script.scri path_to_input_file.bmp", .{}); } fn doRun(allocator: std.mem.Allocator, args_it: anytype) !void { @@ -289,7 +289,7 @@ pub fn main() !void { } else if (std.mem.eql(u8, cli_command, "run")) { return try doRun(allocator, &args_it); } else { - log.debug("unknown command: '{s}'\n", .{cli_command}); + log.debug("unknown command: '{s}'", .{cli_command}); return error.UnknownCommand; } } diff --git a/src/plugin.zig b/src/plugin.zig index 8e88283..b0fb504 100644 --- a/src/plugin.zig +++ b/src/plugin.zig @@ -140,7 +140,7 @@ pub fn makeContext(allocator: std.mem.Allocator, plugin_uri: []const u8) !Contex c.lilv_world_load_all(world); var uri: *c.LilvNode = c.lilv_new_uri(world, cstr_plugin_uri.ptr) orelse { - log.debug("Invalid plugin URI <{s}>\n", .{plugin_uri}); + log.debug("Invalid plugin URI <{s}>", .{plugin_uri}); return ImageError.InvalidPlugin; }; defer c.lilv_node_free(uri); @@ -148,7 +148,7 @@ pub fn makeContext(allocator: std.mem.Allocator, plugin_uri: []const u8) !Contex const plugins: *const c.LilvPlugins = c.lilv_world_get_all_plugins(world).?; var plugin: *const c.LilvPlugin = c.lilv_plugins_get_by_uri(plugins, uri) orelse { - log.debug("Plugin <{s}> not found\n", .{plugin_uri}); + log.debug("Plugin <{s}> not found", .{plugin_uri}); return ImageError.UnknownPlugin; }; diff --git a/src/runner.zig b/src/runner.zig index 969c469..76f54a0 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -71,9 +71,10 @@ pub const Runner = struct { if (self.repl) index += 3 else index += 3; for (self.args) |arg, idx| { - log.debug("arg{d} = {s}\n", .{ idx, arg }); + log.debug("arg{d} = {s}", .{ idx, arg }); } - log.debug("fetch arg idx={d}, val={s}\n", .{ index, self.args[index] }); + log.debug("fetch arg idx={d}", .{index}); + log.debug("fetch arg val={s}", .{self.args[index]}); return self.args[index]; } else { return load_path; @@ -93,7 +94,7 @@ pub const Runner = struct { fn loadCmd(self: *Runner, path_or_argidx: []const u8) !void { const load_path = try self.resolveArgPath(path_or_argidx); - log.debug("\tload path: {s}\n", .{load_path}); + log.debug("\tload path: {s}", .{load_path}); // we could use ImageMagick to convert from X to BMP // but i can't find an easy way to do things in memory. @@ -103,7 +104,7 @@ pub const Runner = struct { // krita/gimp and make it export a bmp and while in the program you can // apply filters, etc. if (!std.mem.endsWith(u8, load_path, ".bmp") and !std.mem.endsWith(u8, load_path, ".ppm")) { - log.debug("Only BMP files are allowed to be loaded. Got path '{s}'\n", .{load_path}); + log.debug("Only BMP files are allowed to be loaded. Got path '{s}'", .{load_path}); return RunError.NoBMP; } @@ -118,7 +119,7 @@ pub const Runner = struct { if (self.image) |image| { return image; } else { - log.debug("image is required!\n", .{}); + log.debug("image is required!", .{}); return RunError.ImageRequired; } } @@ -206,7 +207,7 @@ pub const Runner = struct { ); //defer proc.deinit(); - log.debug("running '{s} {s}'\n", .{ runqs.program, out_path }); + log.debug("running '{s} {s}'", .{ runqs.program, out_path }); _ = try proc.spawnAndWait(); } From ed67a52b151d8531bbe81e783d383864ffc914c5 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 4 Aug 2023 21:34:17 -0300 Subject: [PATCH 178/182] fixes for some version of zig --- build.zig | 1 - src/lang.zig | 6 +++--- src/printer.zig | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/build.zig b/build.zig index 520aeb9..ad6f87d 100644 --- a/build.zig +++ b/build.zig @@ -45,7 +45,6 @@ pub fn build(b: *Builder) void { const mode = b.standardReleaseOptions(); const exe = b.addExecutable("scritcher", "src/main.zig"); exe.setBuildMode(mode); - exe.use_stage1 = true; exe.install(); setupLinks(exe); diff --git a/src/lang.zig b/src/lang.zig index 08346ff..ca5fbec 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -488,7 +488,7 @@ pub const CommandList = struct { const inner_command = cmd_ptr.cast(typ).?; inline for (@typeInfo(typ).Struct.fields) |cmd_field| { - switch (cmd_field.field_type) { + switch (cmd_field.type) { []u8, []const u8 => self.list.allocator.free(@field(inner_command, cmd_field.name)), else => {}, } @@ -576,7 +576,7 @@ pub const Lang = struct { } const arg = maybe_arg.?; - const arg_value = switch (cmd_field.field_type) { + const arg_value = switch (cmd_field.type) { f32 => try std.fmt.parseFloat(f32, arg), u64 => try std.fmt.parseInt(u64, arg, 10), usize => try std.fmt.parseInt(usize, arg, 10), @@ -601,7 +601,7 @@ pub const Lang = struct { } const arg = arg_opt.?; - const argument_value = switch (cmd_field.field_type) { + const argument_value = switch (cmd_field.type) { usize => try std.fmt.parseInt(usize, arg, 10), i32 => try std.fmt.parseInt(i32, arg, 10), f32 => try std.fmt.parseFloat(f32, arg), diff --git a/src/printer.zig b/src/printer.zig index a851602..b3da89b 100644 --- a/src/printer.zig +++ b/src/printer.zig @@ -7,9 +7,9 @@ fn printCommandWithParams(stream: anytype, command: anytype) !void { const Parameters = @TypeOf(command.parameters); try stream.print(" {d} {d}", .{ command.split, command.index }); inline for (@typeInfo(Parameters).Struct.fields) |field| { - if (field.field_type == f32 or field.field_type == f64) { + if (field.type == f32 or field.type == f64) { try stream.print(" {}", .{@field(command.parameters, field.name)}); - } else if (field.field_type == usize or field.field_type == u64) { + } else if (field.type == usize or field.type == u64) { try stream.print(" {d}", .{@field(command.parameters, field.name)}); } else { try stream.print(" {s}", .{@field(command.parameters, field.name)}); From 7cc93c2976208ce6070b6d12843b6e2268061fc0 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 4 Aug 2023 21:34:51 -0300 Subject: [PATCH 179/182] zig fmt --- src/custom.zig | 10 +++++----- src/image.zig | 26 +++++++++++++------------- src/lang.zig | 2 +- src/lv2_helpers.zig | 2 +- src/main.zig | 4 ++-- src/plugin.zig | 4 ++-- src/runner.zig | 2 +- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/custom.zig b/src/custom.zig index ffb129c..d942a3b 100644 --- a/src/custom.zig +++ b/src/custom.zig @@ -24,7 +24,7 @@ pub const RandomNoise = struct { if (params.fill_bytes > 0) { var rand_buf = allocator.alloc(f32, params.fill_bytes) catch return null; - for (rand_buf) |_, idx| { + for (rand_buf, 0..) |_, idx| { rand_buf[idx] = r.random().float(f32); } @@ -72,8 +72,8 @@ pub const WildNoise = struct { if (params.fill_bytes > 0) { var rand_buf = allocator.alloc(f32, params.fill_bytes) catch return null; - for (rand_buf) |_, idx| { - rand_buf[idx] = @intToFloat(f32, r.random().int(u1)); + for (rand_buf, 0..) |_, idx| { + rand_buf[idx] = @as(f32, @floatFromInt(r.random().int(u1))); } return WildNoise{ @@ -99,7 +99,7 @@ pub const WildNoise = struct { bufs.out[0] = rand_buf[self.cnt]; self.cnt += 1; } else { - bufs.out[0] = @intToFloat(f32, self.r.random().int(u1)); + bufs.out[0] = @as(f32, @floatFromInt(self.r.random().int(u1))); } } }; @@ -163,7 +163,7 @@ pub const Embed = struct { image.sseek(self.sndfile, 0); - self.buf = try self.allocator.alloc(f32, @intCast(usize, in_fmt.channels)); + self.buf = try self.allocator.alloc(f32, @as(usize, @intCast(in_fmt.channels))); } pub fn deinit(self: *@This()) void { diff --git a/src/image.zig b/src/image.zig index 6a7481c..47be1cd 100644 --- a/src/image.zig +++ b/src/image.zig @@ -63,7 +63,7 @@ pub fn swrite(file: *c.SNDFILE, buf: [*]f32, frames: i64) !void { } pub fn sseek(file: *c.SNDFILE, offset: usize) void { - const offset_i64 = @intCast(i64, offset); + const offset_i64 = @as(i64, @intCast(offset)); const frames = c.sf_seek(file, offset_i64, c.SEEK_SET); const frames_current = c.sf_seek(file, 0, c.SEEK_CUR); std.debug.assert(frames == frames_current); @@ -80,7 +80,7 @@ pub fn temporaryName(allocator: std.mem.Allocator) ![]u8 { var nam = try allocator.alloc(u8, template.len); std.mem.copy(u8, nam, template); - const seed = @truncate(u64, @bitCast(u128, std.time.nanoTimestamp())); + const seed = @as(u64, @truncate(@as(u128, @bitCast(std.time.nanoTimestamp())))); var r = std.rand.DefaultPrng.init(seed); var fill = nam[template_start.len..nam.len]; @@ -88,8 +88,8 @@ pub fn temporaryName(allocator: std.mem.Allocator) ![]u8 { var i: usize = 0; while (i < 100) : (i += 1) { // generate a random uppercase letter, that is, 65 + random number. - for (fill) |_, f_idx| { - var idx = @intCast(u8, r.random().uintLessThan(u5, 24)); + for (fill, 0..) |_, f_idx| { + var idx = @as(u8, @intCast(r.random().uintLessThan(u5, 24))); var letter = @as(u8, 65) + idx; fill[f_idx] = letter; } @@ -151,7 +151,7 @@ pub const Image = struct { .sndfile = sndfile, .path = path, .curpath = path, - .frames = @intCast(usize, in_fmt.frames), + .frames = @as(usize, @intCast(in_fmt.frames)), }; return image; @@ -161,7 +161,7 @@ pub const Image = struct { var in_fmt = mkSfInfo(); // clone sndfile var sndfile = try sopen(self.allocator, self.curpath, c.SFM_READ, &in_fmt); - std.debug.assert(self.frames == @intCast(usize, in_fmt.frames)); + std.debug.assert(self.frames == @as(usize, @intCast(in_fmt.frames))); var image = try self.allocator.create(Image); @@ -173,7 +173,7 @@ pub const Image = struct { .sndfile = sndfile, .path = self.path, .curpath = self.curpath, - .frames = @intCast(usize, in_fmt.frames), + .frames = @as(usize, @intCast(in_fmt.frames)), }; return image; @@ -198,12 +198,12 @@ pub const Image = struct { pub fn read(self: *Image, file_chans: c_int, buf: []f32) bool { const n_read: c.sf_count_t = c.sf_readf_float(self.sndfile, buf.ptr, 1); - const buf_chans = @intCast(c_int, buf.len); + const buf_chans = @as(c_int, @intCast(buf.len)); var i = file_chans - 1; while (i < buf_chans) : (i += 1) { //buf[@intCast(usize, i)] = buf[i % file_chans]; - buf[@intCast(usize, i)] = buf[@intCast(usize, @mod(i, file_chans))]; + buf[@as(usize, @intCast(i))] = buf[@as(usize, @intCast(@mod(i, file_chans)))]; } return n_read == 1; @@ -237,13 +237,13 @@ pub const Image = struct { var view: []f32 = buf[0..buf.len]; if (bytes_until_end < buf.len) { - read_bytes = c.sf_readf_float(self.sndfile, buf.ptr, @intCast(i64, bytes_until_end)); + read_bytes = c.sf_readf_float(self.sndfile, buf.ptr, @as(i64, @intCast(bytes_until_end))); view = buf[0..bytes_until_end]; } else { - read_bytes = c.sf_readf_float(self.sndfile, buf.ptr, @intCast(i64, buf.len)); + read_bytes = c.sf_readf_float(self.sndfile, buf.ptr, @as(i64, @intCast(buf.len))); } - try swrite(out_file, view.ptr, @intCast(i64, view.len)); + try swrite(out_file, view.ptr, @as(i64, @intCast(view.len))); } sseek(self.sndfile, end); @@ -264,7 +264,7 @@ pub const Image = struct { // std.testing.expectEqual(self.frames, @intCast(usize, in_fmt.frames)); self.curpath = path; - self.frames = @intCast(usize, in_fmt.frames); + self.frames = @as(usize, @intCast(in_fmt.frames)); log.debug("\timage: reopened on '{s}' (frames={d}, fmt.frames={d})", .{ self.curpath, diff --git a/src/lang.zig b/src/lang.zig index ca5fbec..9f85d0f 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -669,7 +669,7 @@ pub const Lang = struct { comptime var lowered_command_name = [_]u8{0} ** struct_name.len; comptime { - for (struct_name) |c, i| { + for (struct_name, 0..) |c, i| { lowered_command_name[i] = std.ascii.toLower(c); } } diff --git a/src/lv2_helpers.zig b/src/lv2_helpers.zig index 82c961d..1d3df64 100644 --- a/src/lv2_helpers.zig +++ b/src/lv2_helpers.zig @@ -69,7 +69,7 @@ pub fn setupPorts(ctx: *plugin.Context) ![]Port { var ports = try ctx.allocator.alloc(Port, n_ports); - for (ports) |_, idx| { + for (ports, 0..) |_, idx| { var port: *Port = &ports[idx]; port.* = Port{ .lilv_port = null, diff --git a/src/main.zig b/src/main.zig index 083b204..7b7b66b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -30,8 +30,8 @@ fn copyCommandToHeap(allocator: std.mem.Allocator, command: langs.Command, compt var heap_cmd = try allocator.create(CommandStruct); @memcpy( - @ptrCast([*]u8, &heap_cmd), - @ptrCast([*]const u8, &casted), + @as([*]u8, @ptrCast(&heap_cmd)), + @as([*]const u8, @ptrCast(&casted)), @sizeOf(CommandStruct), ); diff --git a/src/plugin.zig b/src/plugin.zig index b0fb504..57f8059 100644 --- a/src/plugin.zig +++ b/src/plugin.zig @@ -101,8 +101,8 @@ pub const RunContext = struct { var i: usize = 0; var o: usize = 0; - for (ports) |_, p_idx| { - var p = @intCast(u32, p_idx); + for (ports, 0..) |_, p_idx| { + var p = @as(u32, @intCast(p_idx)); var port: *lv2.Port = &ports[p_idx]; switch (port.ptype) { diff --git a/src/runner.zig b/src/runner.zig index 76f54a0..739a95f 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -70,7 +70,7 @@ pub const Runner = struct { // ':0' should ALWAYS point to the image. if (self.repl) index += 3 else index += 3; - for (self.args) |arg, idx| { + for (self.args, 0..) |arg, idx| { log.debug("arg{d} = {s}", .{ idx, arg }); } log.debug("fetch arg idx={d}", .{index}); From c73b98a3565a4e39de836ddfb6bb5194f742af3e Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 4 Aug 2023 21:50:59 -0300 Subject: [PATCH 180/182] fix for zig 0.11 --- build.zig | 38 +++++++++++++++++++++++++------------- src/image.zig | 4 ++-- src/lang.zig | 7 ++++--- src/magick.zig | 4 ++-- src/main.zig | 6 +----- src/plugin.zig | 2 +- src/runner.zig | 4 ++-- 7 files changed, 37 insertions(+), 28 deletions(-) diff --git a/build.zig b/build.zig index ad6f87d..e969b99 100644 --- a/build.zig +++ b/build.zig @@ -12,8 +12,8 @@ fn setupLinks(step: *builds.LibExeObjStep) void { step.linkSystemLibrary("GraphicsMagickWand"); step.linkSystemLibrary("GraphicsMagick"); - step.addIncludePath("/usr/include/GraphicsMagick"); - step.addIncludePath("/usr/include"); + step.addIncludePath(.{ .path = "/usr/include/GraphicsMagick" }); + step.addIncludePath(.{ .path = "/usr/include" }); const possible_lilv_include_dirs = [_][]const u8{ "/usr/include/lilv-0/lilv", @@ -32,7 +32,7 @@ fn setupLinks(step: *builds.LibExeObjStep) void { found_any_lilv = true; std.debug.print("found lilv at '{s}'\n", .{possible_lilv_dir}); - step.addIncludePath(possible_lilv_dir); + step.addIncludePath(.{ .path = possible_lilv_dir }); } if (!found_any_lilv) { @@ -42,22 +42,34 @@ fn setupLinks(step: *builds.LibExeObjStep) void { } pub fn build(b: *Builder) void { - const mode = b.standardReleaseOptions(); - const exe = b.addExecutable("scritcher", "src/main.zig"); - exe.setBuildMode(mode); - exe.install(); + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + const exe = b.addExecutable(.{ + .name = "scritcher", + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); setupLinks(exe); + b.installArtifact(exe); - const test_obj_step = b.addTest("src/main.zig"); - setupLinks(test_obj_step); + const run_cmd = b.addRunArtifact(exe); - const run_cmd = exe.run(); - run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); - const test_step = b.step("test", "Run tests"); - test_step.dependOn(&test_obj_step.step); + const test_step = b.addTest(.{ + .root_source_file = .{ .path = "src/main.zig" }, + .target = target, + .optimize = optimize, + }); + setupLinks(test_step); + const run_unit_tests = b.addRunArtifact(test_step); + const test_cmd = b.step("test", "run unit tests"); + test_cmd.dependOn(&run_unit_tests.step); } diff --git a/src/image.zig b/src/image.zig index 47be1cd..3905ea5 100644 --- a/src/image.zig +++ b/src/image.zig @@ -26,7 +26,7 @@ pub fn sopen( mode: i32, fmt: *c.SF_INFO, ) !*c.SNDFILE { - var cstr_path = try std.cstr.addNullByte(allocator, path); + var cstr_path = try allocator.dupeZ(u8, path); defer allocator.free(cstr_path); var file = c.sf_open(cstr_path.ptr, mode, fmt); @@ -321,7 +321,7 @@ pub const Image = struct { // now, for each param for the plugin, we find its port, and set // the value for the port there. for (params.items) |param| { - var sym_cstr = try std.cstr.addNullByte(self.allocator, param.sym); + var sym_cstr = try self.allocator.dupeZ(u8, param.sym); defer self.allocator.free(sym_cstr); var sym = c.lilv_new_string(ctx.world, sym_cstr.ptr); diff --git a/src/lang.zig b/src/lang.zig index 9f85d0f..b18b0fb 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -496,7 +496,8 @@ pub const CommandList = struct { } } - self.list.allocator.destroy(cmd_ptr); + //TODO this is ian invalid free + //self.list.allocator.destroy(cmd_ptr); } self.list.deinit(); } @@ -537,7 +538,7 @@ pub const Lang = struct { fn parseCommandArguments( self: *@This(), comptime command_struct: type, - tok_it: *std.mem.SplitIterator(u8), + tok_it: *std.mem.SplitIterator(u8, .sequence), commands: *CommandList, ) !void { // Based on the command struct fields, we can parse the arguments. @@ -638,7 +639,7 @@ pub const Lang = struct { if (std.mem.startsWith(u8, stmt, "#")) continue; // TODO better tokenizer instead of just tokenize(" ")...maybe???? - var tok_it = std.mem.split(u8, stmt, " "); + var tok_it = std.mem.splitSequence(u8, stmt, " "); var cmd_opt = tok_it.next(); if (cmd_opt == null) { diff --git a/src/magick.zig b/src/magick.zig index c6adf3c..e79f513 100644 --- a/src/magick.zig +++ b/src/magick.zig @@ -38,7 +38,7 @@ fn magickLoad(image: *Image) !MagickContext { var mctx = try MagickContext.init(); errdefer mctx.deinit(); - var curpath = try std.cstr.addNullByte(image.allocator, image.curpath); + var curpath = try image.allocator.dupeZ(u8, image.curpath); defer image.allocator.free(curpath); log.debug("loading '{s}'", .{curpath}); @@ -53,7 +53,7 @@ fn magickSave(image: *Image, wand: *mc.MagickWand) !void { const allocator = image.allocator; var tmpnam = try images.temporaryName(allocator); - var c_tmpnam = try std.cstr.addNullByte(allocator, tmpnam); + var c_tmpnam = try allocator.dupeZ(u8, tmpnam); defer allocator.free(c_tmpnam); log.debug("\tmagick: saving to '{s}'..", .{c_tmpnam}); diff --git a/src/main.zig b/src/main.zig index 7b7b66b..7563392 100644 --- a/src/main.zig +++ b/src/main.zig @@ -29,11 +29,7 @@ fn copyCommandToHeap(allocator: std.mem.Allocator, command: langs.Command, compt const casted = command.cast(CommandStruct).?; var heap_cmd = try allocator.create(CommandStruct); - @memcpy( - @as([*]u8, @ptrCast(&heap_cmd)), - @as([*]const u8, @ptrCast(&casted)), - @sizeOf(CommandStruct), - ); + heap_cmd.* = casted.*; return &heap_cmd.base; } diff --git a/src/plugin.zig b/src/plugin.zig index 57f8059..f5f6517 100644 --- a/src/plugin.zig +++ b/src/plugin.zig @@ -131,7 +131,7 @@ pub const RunContext = struct { }; pub fn makeContext(allocator: std.mem.Allocator, plugin_uri: []const u8) !Context { - const cstr_plugin_uri = try std.cstr.addNullByte(allocator, plugin_uri); + const cstr_plugin_uri = try allocator.dupeZ(u8, plugin_uri); defer allocator.free(cstr_plugin_uri); var world: *c.LilvWorld = c.lilv_world_new().?; diff --git a/src/runner.zig b/src/runner.zig index 739a95f..0eea50b 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -152,7 +152,7 @@ pub const Runner = struct { while (try it.next()) |entry| { switch (entry.kind) { - .File => blk: { + .file => blk: { if (!std.mem.startsWith(u8, entry.name, starts_with)) break :blk {}; // we want to get the N in x_gN.ext @@ -215,7 +215,7 @@ pub const Runner = struct { const rotate_cmd = cmd.cast(lang.Command.Rotate).?; var image = try self.getImage(); - var c_bgfill = try std.cstr.addNullByte(self.allocator, rotate_cmd.bgfill); + var c_bgfill = try self.allocator.dupeZ(u8, rotate_cmd.bgfill); defer self.allocator.free(c_bgfill); try magick.runRotate(image, rotate_cmd.deg, c_bgfill); From c0da5e68b7d3144ca729b25cb9aea91b3bd853ae Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 1 Jun 2024 15:46:37 -0300 Subject: [PATCH 181/182] base port to zig 0.12 --- build.zig | 10 ++++------ src/image.zig | 46 ++++++++++++++++++++++----------------------- src/lang.zig | 10 +++++++--- src/lv2_helpers.zig | 16 ++++++++-------- src/magick.zig | 10 +++++----- src/main.zig | 12 +++++++----- src/plugin.zig | 12 ++++++------ src/runner.zig | 12 ++++++------ 8 files changed, 66 insertions(+), 62 deletions(-) diff --git a/build.zig b/build.zig index e969b99..5f2ff5e 100644 --- a/build.zig +++ b/build.zig @@ -1,8 +1,6 @@ const std = @import("std"); -const builds = std.build; -const Builder = std.build.Builder; -fn setupLinks(step: *builds.LibExeObjStep) void { +fn setupLinks(step: *std.Build.Step.Compile) void { step.linkSystemLibrary("c"); step.linkSystemLibrary("lilv-0"); @@ -41,13 +39,13 @@ fn setupLinks(step: *builds.LibExeObjStep) void { } } -pub fn build(b: *Builder) void { +pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const exe = b.addExecutable(.{ .name = "scritcher", - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); @@ -64,7 +62,7 @@ pub fn build(b: *Builder) void { run_step.dependOn(&run_cmd.step); const test_step = b.addTest(.{ - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); diff --git a/src/image.zig b/src/image.zig index 3905ea5..e20cfe7 100644 --- a/src/image.zig +++ b/src/image.zig @@ -26,10 +26,10 @@ pub fn sopen( mode: i32, fmt: *c.SF_INFO, ) !*c.SNDFILE { - var cstr_path = try allocator.dupeZ(u8, path); + const cstr_path = try allocator.dupeZ(u8, path); defer allocator.free(cstr_path); - var file = c.sf_open(cstr_path.ptr, mode, fmt); + const file = c.sf_open(cstr_path.ptr, mode, fmt); const st: i32 = c.sf_error(file); if (st != 0) { @@ -78,7 +78,7 @@ pub fn temporaryName(allocator: std.mem.Allocator) ![]u8 { const template_start = "/temp/temp_"; const template = "/tmp/temp_XXXXXXXXXXXXXXXXXXXXX"; var nam = try allocator.alloc(u8, template.len); - std.mem.copy(u8, nam, template); + std.mem.copyForwards(u8, nam, template); const seed = @as(u64, @truncate(@as(u128, @bitCast(std.time.nanoTimestamp())))); var r = std.rand.DefaultPrng.init(seed); @@ -89,8 +89,8 @@ pub fn temporaryName(allocator: std.mem.Allocator) ![]u8 { while (i < 100) : (i += 1) { // generate a random uppercase letter, that is, 65 + random number. for (fill, 0..) |_, f_idx| { - var idx = @as(u8, @intCast(r.random().uintLessThan(u5, 24))); - var letter = @as(u8, 65) + idx; + const idx = @as(u8, @intCast(r.random().uintLessThan(u5, 24))); + const letter = @as(u8, 65) + idx; fill[f_idx] = letter; } @@ -139,9 +139,9 @@ pub const Image = struct { /// Open a BMP image for later. pub fn open(allocator: std.mem.Allocator, path: []const u8) !*Image { var in_fmt = mkSfInfo(); - var sndfile = try sopen(allocator, path, c.SFM_READ, &in_fmt); + const sndfile = try sopen(allocator, path, c.SFM_READ, &in_fmt); - var image = try allocator.create(Image); + const image = try allocator.create(Image); std.debug.assert(in_fmt.frames > @as(i64, 0)); std.debug.assert(in_fmt.seekable == @as(i32, 1)); @@ -160,10 +160,10 @@ pub const Image = struct { pub fn clone(self: *Image) !*Image { var in_fmt = mkSfInfo(); // clone sndfile - var sndfile = try sopen(self.allocator, self.curpath, c.SFM_READ, &in_fmt); + const sndfile = try sopen(self.allocator, self.curpath, c.SFM_READ, &in_fmt); std.debug.assert(self.frames == @as(usize, @intCast(in_fmt.frames))); - var image = try self.allocator.create(Image); + const image = try self.allocator.create(Image); std.debug.assert(in_fmt.frames > @as(i64, 0)); std.debug.assert(in_fmt.seekable == @as(i32, 1)); @@ -180,7 +180,7 @@ pub const Image = struct { } pub fn close(self: *Image) void { - var st: i32 = c.sf_close(self.sndfile); + const st: i32 = c.sf_close(self.sndfile); if (st != 0) { log.debug("Failed to close {s} ({s})", .{ self.path, @@ -252,7 +252,7 @@ pub const Image = struct { fn getSeekPos(self: *Image, position: plugins.Position) plugins.SeekPos { const file_end = self.frames; - var seek_pos = position.seekPos(file_end); + const seek_pos = position.seekPos(file_end); log.debug("\tstart {d} end {d}", .{ seek_pos.start, seek_pos.end }); return seek_pos; } @@ -321,10 +321,10 @@ pub const Image = struct { // now, for each param for the plugin, we find its port, and set // the value for the port there. for (params.items) |param| { - var sym_cstr = try self.allocator.dupeZ(u8, param.sym); + const sym_cstr = try self.allocator.dupeZ(u8, param.sym); defer self.allocator.free(sym_cstr); - var sym = c.lilv_new_string(ctx.world, sym_cstr.ptr); + const sym = c.lilv_new_string(ctx.world, sym_cstr.ptr); const port = c.lilv_plugin_get_port_by_symbol(ctx.plugin, sym) orelse { log.debug("assert fail: symbol {s} not found on port", .{param.sym}); return ImageError.InvalidSymbol; @@ -332,7 +332,7 @@ pub const Image = struct { c.lilv_node_free(sym); - var idx = c.lilv_port_get_index(ctx.plugin, port); + const idx = c.lilv_port_get_index(ctx.plugin, port); log.debug("\tset sym={s}, idx={d} to val={}", .{ param.sym, idx, @@ -343,11 +343,11 @@ pub const Image = struct { // now we need to generate a temporary file and put the output of // running the plugin on that file - var tmpnam = try temporaryName(self.allocator); + const tmpnam = try temporaryName(self.allocator); log.debug("\trunning plugin from '{s}' to '{s}'", .{ self.curpath, tmpnam }); var out_fmt = mkSfInfo(); - var out_file = try sopen(self.allocator, tmpnam, c.SFM_WRITE, &out_fmt); + const out_file = try sopen(self.allocator, tmpnam, c.SFM_WRITE, &out_fmt); var rctx = try plugins.RunContext.init(self.allocator, ctx.plugin); defer rctx.deinit(); @@ -380,7 +380,7 @@ pub const Image = struct { log.debug("\tseek pos start: {d} end: {d}", .{ seek_pos.start, seek_pos.end }); var inbuf = &rctx.buffers.in; - var outbuf = &rctx.buffers.out; + const outbuf = &rctx.buffers.out; while (i <= seek_pos.end) : (i += 1) { inbuf[0] = 0; @@ -416,7 +416,7 @@ pub const Image = struct { try self.reopen(tmpnam); try self.checkValid(); - var time_taken = timer.read(); + const time_taken = timer.read(); log.debug("\ttook {d:.2}ms running plugin", .{time_taken / std.time.us_per_ms}); } @@ -431,7 +431,7 @@ pub const Image = struct { position: plugins.Position, extra: anytype, ) !void { - var plugin_opt: ?Plugin = Plugin.init(self.allocator, extra); + const plugin_opt: ?Plugin = Plugin.init(self.allocator, extra); if (plugin_opt == null) { return ImageError.PluginLoadFail; } @@ -448,11 +448,11 @@ pub const Image = struct { // the code here is a copypaste of runPlugin() without the specific // lilv things. - var tmpnam = try temporaryName(self.allocator); + const tmpnam = try temporaryName(self.allocator); log.debug("\trunning CUSTOM plugin from '{s}' to '{s}'", .{ self.curpath, tmpnam }); var out_fmt = mkSfInfo(); - var out_file = try sopen(self.allocator, tmpnam, c.SFM_WRITE, &out_fmt); + const out_file = try sopen(self.allocator, tmpnam, c.SFM_WRITE, &out_fmt); var bufs = plugins.RunBuffers{}; const seek_pos = self.getSeekPos(position); @@ -478,8 +478,8 @@ pub const Image = struct { var i: usize = seek_pos.start; log.debug("\tseek pos start: {d} end: {d}", .{ seek_pos.start, seek_pos.end }); - var inbuf = &bufs.in; - var outbuf = &bufs.out; + const inbuf = &bufs.in; + const outbuf = &bufs.out; while (i <= seek_pos.end) : (i += 1) { const read_bytes = c.sf_readf_float(self.sndfile, inbuf, 1); diff --git a/src/lang.zig b/src/lang.zig index b18b0fb..72b9e2c 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -143,7 +143,8 @@ pub const Command = struct { if (base.tag != T.base_tag) return null; - return @fieldParentPtr(T, "base", base); + const ptr: *const T = @alignCast(@fieldParentPtr("base", base)); + return ptr; } pub fn print(base: *const @This()) void { @@ -641,7 +642,7 @@ pub const Lang = struct { // TODO better tokenizer instead of just tokenize(" ")...maybe???? var tok_it = std.mem.splitSequence(u8, stmt, " "); - var cmd_opt = tok_it.next(); + const cmd_opt = tok_it.next(); if (cmd_opt == null) { self.doError("No command given", .{}); continue; @@ -669,11 +670,14 @@ pub const Lang = struct { } comptime var lowered_command_name = [_]u8{0} ** struct_name.len; + var runtime_lowered_command_name = [_]u8{0} ** struct_name.len; comptime { for (struct_name, 0..) |c, i| { lowered_command_name[i] = std.ascii.toLower(c); } } + const c_l = lowered_command_name; + std.mem.copyForwards(u8, &runtime_lowered_command_name, &c_l); // if we have a match, we know the proper struct type // to use. this actually works compared to storing command_struct @@ -685,7 +689,7 @@ pub const Lang = struct { // Attempting to use ComptimeHashMap hits compiler bugs and I'm // not sure if we can map strings to *types* in it. - if ((!found) and std.mem.eql(u8, &lowered_command_name, command_string)) { + if ((!found) and std.mem.eql(u8, &runtime_lowered_command_name, command_string)) { found = true; try self.parseCommandArguments(cmd_struct_type, &tok_it, &cmds); } diff --git a/src/lv2_helpers.zig b/src/lv2_helpers.zig index 1d3df64..a59babd 100644 --- a/src/lv2_helpers.zig +++ b/src/lv2_helpers.zig @@ -64,13 +64,13 @@ pub const Port = struct { /// /// Caller owns returned memory. pub fn setupPorts(ctx: *plugin.Context) ![]Port { - var world = ctx.world; + const world = ctx.world; const n_ports: u32 = c.lilv_plugin_get_num_ports(ctx.plugin); var ports = try ctx.allocator.alloc(Port, n_ports); for (ports, 0..) |_, idx| { - var port: *Port = &ports[idx]; + const port: *Port = &ports[idx]; port.* = Port{ .lilv_port = null, .ptype = .Control, @@ -81,23 +81,23 @@ pub fn setupPorts(ctx: *plugin.Context) ![]Port { }; } - var values: []f32 = try ctx.allocator.alloc(f32, n_ports); + const values: []f32 = try ctx.allocator.alloc(f32, n_ports); defer ctx.allocator.free(values); c.lilv_plugin_get_port_ranges_float(ctx.plugin, null, null, values.ptr); - var lv2_InputPort = c.lilv_new_uri(world, LV2_CORE__InputPort.ptr).?; + const lv2_InputPort = c.lilv_new_uri(world, LV2_CORE__InputPort.ptr).?; //defer std.heap.c_allocator.destroy(lv2_InputPort); - var lv2_OutputPort = c.lilv_new_uri(world, LV2_CORE__OutputPort.ptr).?; + const lv2_OutputPort = c.lilv_new_uri(world, LV2_CORE__OutputPort.ptr).?; //defer std.heap.c_allocator.destroy(lv2_OutputPort); - var lv2_AudioPort = c.lilv_new_uri(world, LV2_CORE__AudioPort.ptr).?; + const lv2_AudioPort = c.lilv_new_uri(world, LV2_CORE__AudioPort.ptr).?; //defer std.heap.c_allocator.destroy(lv2_AudioPort); - var lv2_ControlPort = c.lilv_new_uri(world, LV2_CORE__ControlPort.ptr).?; + const lv2_ControlPort = c.lilv_new_uri(world, LV2_CORE__ControlPort.ptr).?; //defer std.heap.c_allocator.destroy(lv2_ControlPort); - var lv2_connection_string = c.lilv_new_uri(world, LV2_CORE__connectionOptional.ptr).?; + const lv2_connection_string = c.lilv_new_uri(world, LV2_CORE__connectionOptional.ptr).?; //defer std.heap.c_allocator.destroy(lv2_connection_string); var i: u32 = 0; diff --git a/src/magick.zig b/src/magick.zig index e79f513..ab59f0a 100644 --- a/src/magick.zig +++ b/src/magick.zig @@ -15,7 +15,7 @@ pub const MagickContext = struct { pub fn init() !MagickContext { mc.InitializeMagick(null); - var wand = mc.NewMagickWand(); + const wand = mc.NewMagickWand(); if (wand == null) return error.WandCreateFail; return MagickContext{ @@ -38,7 +38,7 @@ fn magickLoad(image: *Image) !MagickContext { var mctx = try MagickContext.init(); errdefer mctx.deinit(); - var curpath = try image.allocator.dupeZ(u8, image.curpath); + const curpath = try image.allocator.dupeZ(u8, image.curpath); defer image.allocator.free(curpath); log.debug("loading '{s}'", .{curpath}); @@ -52,8 +52,8 @@ fn magickLoad(image: *Image) !MagickContext { fn magickSave(image: *Image, wand: *mc.MagickWand) !void { const allocator = image.allocator; - var tmpnam = try images.temporaryName(allocator); - var c_tmpnam = try allocator.dupeZ(u8, tmpnam); + const tmpnam = try images.temporaryName(allocator); + const c_tmpnam = try allocator.dupeZ(u8, tmpnam); defer allocator.free(c_tmpnam); log.debug("\tmagick: saving to '{s}'..", .{c_tmpnam}); @@ -72,7 +72,7 @@ pub fn runRotate(image: *Image, deg: f32, bgfill: []const u8) !void { var mctx = try magickLoad(image); defer mctx.deinit(); - var bg = mc.NewPixelWand(); + const bg = mc.NewPixelWand(); defer mc.DestroyPixelWand(bg); if (mc.PixelSetColor(bg, bgfill.ptr) != 1) diff --git a/src/main.zig b/src/main.zig index 7563392..f21087e 100644 --- a/src/main.zig +++ b/src/main.zig @@ -30,6 +30,8 @@ fn copyCommandToHeap(allocator: std.mem.Allocator, command: langs.Command, compt var heap_cmd = try allocator.create(CommandStruct); heap_cmd.* = casted.*; + log.debug("casted: {}", .{casted}); + log.debug("heap_cmd: {}", .{heap_cmd}); return &heap_cmd.base; } @@ -54,7 +56,7 @@ pub fn doRepl(allocator: std.mem.Allocator, args_it: anytype) !void { defer lang.deinit(); if (total_bytes > 0) { - var scri_existing = try allocator.alloc(u8, total_bytes); + const scri_existing = try allocator.alloc(u8, total_bytes); _ = try file_read_opt.?.read(scri_existing); defer allocator.free(scri_existing); @@ -94,7 +96,7 @@ pub fn doRepl(allocator: std.mem.Allocator, args_it: anytype) !void { defer file.close(); var out = file.writer(); - var stream = &out; + const stream = &out; // since we opened the file for writing, it becomes empty, so, to ensure // we don't fuck up later on, we print cmds before starting the repl @@ -118,7 +120,7 @@ pub fn doRepl(allocator: std.mem.Allocator, args_it: anytype) !void { // run the load command try runner.runCommands(cmds, true); - const wanted_runner: []const u8 = std.os.getenv("SCRITCHER_RUNNER") orelse "ristretto"; + const wanted_runner: []const u8 = std.posix.getenv("SCRITCHER_RUNNER") orelse "ristretto"; var runqs_cmd = langs.Command.RunQS{ .base = langs.Command{ .tag = langs.Command.Tag.runqs }, @@ -136,7 +138,7 @@ pub fn doRepl(allocator: std.mem.Allocator, args_it: anytype) !void { readline.add_history(rd_line); //defer std.heap.c_allocator.destroy(rd_line); - var line = rd_line[0..std.mem.len(rd_line)]; + const line = rd_line[0..std.mem.len(rd_line)]; if (std.mem.eql(u8, line, "push")) { const heap_cmd = switch (current.tag) { @@ -250,7 +252,7 @@ fn doRun(allocator: std.mem.Allocator, args_it: anytype) !void { // sadly, we read it all into memory. such is life const total_bytes = try file.getEndPos(); - var data = try allocator.alloc(u8, total_bytes); + const data = try allocator.alloc(u8, total_bytes); defer allocator.free(data); _ = try file.read(data); diff --git a/src/plugin.zig b/src/plugin.zig index f5f6517..29ec224 100644 --- a/src/plugin.zig +++ b/src/plugin.zig @@ -36,7 +36,7 @@ pub const Position = struct { pub fn seekPos(self: Position, total_size: usize) SeekPos { std.debug.assert(self.index <= self.split); - var tot = total_size / self.split; + const tot = total_size / self.split; return SeekPos{ .start = self.index * tot, @@ -80,7 +80,7 @@ pub const RunContext = struct { ) !RunContext { _ = allocator; // TODO batch RunBuffers? - var instance = c.lilv_plugin_instantiate(plugin, @as(f64, 44100), null); + const instance = c.lilv_plugin_instantiate(plugin, @as(f64, 44100), null); errdefer c.lilv_instance_free(instance); if (instance == null) { @@ -102,7 +102,7 @@ pub const RunContext = struct { var o: usize = 0; for (ports, 0..) |_, p_idx| { - var p = @as(u32, @intCast(p_idx)); + const p = @as(u32, @intCast(p_idx)); var port: *lv2.Port = &ports[p_idx]; switch (port.ptype) { @@ -134,12 +134,12 @@ pub fn makeContext(allocator: std.mem.Allocator, plugin_uri: []const u8) !Contex const cstr_plugin_uri = try allocator.dupeZ(u8, plugin_uri); defer allocator.free(cstr_plugin_uri); - var world: *c.LilvWorld = c.lilv_world_new().?; + const world: *c.LilvWorld = c.lilv_world_new().?; errdefer c.lilv_world_free(world); c.lilv_world_load_all(world); - var uri: *c.LilvNode = c.lilv_new_uri(world, cstr_plugin_uri.ptr) orelse { + const uri: *c.LilvNode = c.lilv_new_uri(world, cstr_plugin_uri.ptr) orelse { log.debug("Invalid plugin URI <{s}>", .{plugin_uri}); return ImageError.InvalidPlugin; }; @@ -147,7 +147,7 @@ pub fn makeContext(allocator: std.mem.Allocator, plugin_uri: []const u8) !Contex const plugins: *const c.LilvPlugins = c.lilv_world_get_all_plugins(world).?; - var plugin: *const c.LilvPlugin = c.lilv_plugins_get_by_uri(plugins, uri) orelse { + const plugin: *const c.LilvPlugin = c.lilv_plugins_get_by_uri(plugins, uri) orelse { log.debug("Plugin <{s}> not found", .{plugin_uri}); return ImageError.UnknownPlugin; }; diff --git a/src/runner.zig b/src/runner.zig index 0eea50b..8cc578c 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -47,7 +47,7 @@ pub const Runner = struct { } pub fn clone(self: *Runner) !Runner { - var cloned_image = if (self.image) |image| try image.clone() else null; + const cloned_image = if (self.image) |image| try image.clone() else null; return Runner{ .allocator = self.allocator, .image = cloned_image, @@ -128,12 +128,12 @@ pub const Runner = struct { fn makeGlitchedPath(self: *Runner) ![]const u8 { // we want to transform basename, if it is "x.bmp" to "x_gN.bmp", where // N is the maximum non-used integer. - var image = try self.getImage(); + const image = try self.getImage(); const basename = std.fs.path.basename(image.path); const dirname = std.fs.path.dirname(image.path).?; - var dir = try std.fs.cwd().openIterableDir(dirname, .{}); + var dir = try std.fs.cwd().openDir(dirname, .{ .iterate = true }); defer dir.close(); const period_idx = std.mem.lastIndexOf(u8, basename, ".").?; @@ -214,8 +214,8 @@ pub const Runner = struct { fn rotateCmd(self: *Runner, cmd: lang.Command) !void { const rotate_cmd = cmd.cast(lang.Command.Rotate).?; - var image = try self.getImage(); - var c_bgfill = try self.allocator.dupeZ(u8, rotate_cmd.bgfill); + const image = try self.getImage(); + const c_bgfill = try self.allocator.dupeZ(u8, rotate_cmd.bgfill); defer self.allocator.free(c_bgfill); try magick.runRotate(image, rotate_cmd.deg, c_bgfill); @@ -332,7 +332,7 @@ test "running noop" { var cmds = lang.CommandList.init(allocator); defer cmds.deinit(); - var command = lang.Command{ .tag = .noop }; + const command = lang.Command{ .tag = .noop }; var noop = try allocator.create(lang.Command.Noop); noop.* = lang.Command.Noop{ .base = command }; From 3af4dc575a1cd9cbdcc98b19ee5fbf269b068880 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 1 Jun 2024 16:53:01 -0300 Subject: [PATCH 182/182] fix command ptr alignment --- src/lang.zig | 13 ++++++++++++- src/runner.zig | 10 +++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/lang.zig b/src/lang.zig index 72b9e2c..31e5a73 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -143,7 +143,18 @@ pub const Command = struct { if (base.tag != T.base_tag) return null; - const ptr: *const T = @alignCast(@fieldParentPtr("base", base)); + //const baseInt = @intFromPtr(base); + + //log.debug("casting from {d}", .{baseInt}); + //log.debug("aligns from 8? {d}", .{baseInt % 8}); + //log.debug("align T: {d} {s}", .{ @alignOf(*T), @typeName(T) }); + //log.debug("align base: {d} {s}", .{ @alignOf(*const @This()), @typeName(@This()) }); + const base_aligned: *const @This() = @alignCast(base); + + const parented = @as(*const T, @alignCast(@fieldParentPtr("base", base_aligned))); + + const ptr: *const T = @alignCast(parented); + //log.debug("align: {d}\n", .{@alignOf(@TypeOf(ptr))}); return ptr; } diff --git a/src/runner.zig b/src/runner.zig index 8cc578c..85b8d79 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -194,7 +194,7 @@ pub const Runner = struct { try image.saveTo(out_path); } - fn runQSCmd(self: *Runner, cmd: lang.Command) !void { + fn runQSCmd(self: *Runner, cmd: *lang.Command) !void { const runqs = cmd.cast(lang.Command.RunQS).?; var image = try self.getImage(); const out_path = try self.makeGlitchedPath(); @@ -211,7 +211,7 @@ pub const Runner = struct { _ = try proc.spawnAndWait(); } - fn rotateCmd(self: *Runner, cmd: lang.Command) !void { + fn rotateCmd(self: *Runner, cmd: *lang.Command) !void { const rotate_cmd = cmd.cast(lang.Command.Rotate).?; const image = try self.getImage(); @@ -255,7 +255,7 @@ pub const Runner = struct { fn runSingleCommand( self: *@This(), - cmd: lang.Command, + cmd: *lang.Command, comptime tag: lang.Command.Tag, ) !void { const typ = lang.Command.tagToType(tag); @@ -267,7 +267,7 @@ pub const Runner = struct { } } - fn runCommand(self: *@This(), cmd: lang.Command) !void { + fn runCommand(self: *@This(), cmd: *lang.Command) !void { switch (cmd.tag) { .noop => {}, .load => { @@ -322,7 +322,7 @@ pub const Runner = struct { _ = debug_flag; for (cmds.list.items) |cmd| { cmd.print(); - try self.runCommand(cmd.*); + try self.runCommand(cmd); } } };