diff --git a/src/custom.zig b/src/custom.zig index a91bdd2..f346fa0 100644 --- a/src/custom.zig +++ b/src/custom.zig @@ -120,8 +120,9 @@ pub const Write = struct { allocator: *std.mem.Allocator, params: *plugins.ParamMap, ) Write { + const data = params.get("data").?; return Write{ - .data = params.get("data").?.value, + .data = data.value, }; } @@ -139,10 +140,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, filepath: []const u8) @This() { return Embed{ .allocator = allocator, - .filepath = params.get("path").?.value, + .filepath = filepath, }; } diff --git a/src/image.zig b/src/image.zig index d677afa..7f8deb4 100644 --- a/src/image.zig +++ b/src/image.zig @@ -422,7 +422,8 @@ pub const Image = struct { self: *Image, comptime Plugin: type, position: plugins.Position, - extra: *ParamMap, + comptime ExtraType: type, + extra: ExtraType, ) !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 cc8d58a..03a6c52 100644 --- a/src/lang.zig +++ b/src/lang.zig @@ -1,7 +1,6 @@ const std = @import("std"); const plugin = @import("plugin.zig"); -const custom = @import("custom.zig"); pub const ParseError = error{ OutOfMemory, @@ -13,8 +12,6 @@ pub const CommandType = enum { /// "LV2 Commands" are commands that receive split, index, and then receive /// any f64 arguments. lv2_command, - - custom_command, }; fn LV2Command( @@ -35,19 +32,19 @@ fn LV2Command( } fn CustomCommand( - comptime tag: Command.Tag, - comptime Plugin: type, - comptime PluginParameters: type, + comptime tag: Command.tag, + comptime plugin: type, + comptime parameters: type, ) type { return struct { pub const base_tag = tag; - pub const command_type = CommandType.custom_command; - pub const plugin_type = Plugin; + pub const command_type = CommandType.plugin_command; + pub const plugin_type = plugin; base: Command, split: usize, index: usize, - parameters: PluginParameters, + parameters: LV2Parameters, }; } @@ -191,9 +188,13 @@ pub const Command = struct { data: f32, }); - pub const Embed = CustomCommand(Tag.write, custom.Embed, struct { + 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; @@ -520,7 +521,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, .rotate => false, + .noop, .load, .quicksave, .runqs => false, else => command_struct.command_type == .lv2_command, }; diff --git a/src/runner.zig b/src/runner.zig index a1bed65..e65bac0 100644 --- a/src/runner.zig +++ b/src/runner.zig @@ -190,6 +190,26 @@ 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, @@ -224,26 +244,6 @@ 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,7 +261,6 @@ 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"), } } @@ -306,8 +305,6 @@ 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");