Compare commits
6 commits
e669b74ffb
...
83996b889f
Author | SHA1 | Date | |
---|---|---|---|
83996b889f | |||
10b2c69605 | |||
303a40758d | |||
1c1e525b1d | |||
1fac8c7312 | |||
e8808c501b |
4 changed files with 39 additions and 39 deletions
|
@ -120,9 +120,8 @@ pub const Write = struct {
|
||||||
allocator: *std.mem.Allocator,
|
allocator: *std.mem.Allocator,
|
||||||
params: *plugins.ParamMap,
|
params: *plugins.ParamMap,
|
||||||
) Write {
|
) Write {
|
||||||
const data = params.get("data").?;
|
|
||||||
return Write{
|
return Write{
|
||||||
.data = data.value,
|
.data = params.get("data").?.value,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,10 +139,10 @@ pub const Embed = struct {
|
||||||
sndfile: *c.SNDFILE = undefined,
|
sndfile: *c.SNDFILE = undefined,
|
||||||
buf: []f32 = 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{
|
return Embed{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.filepath = filepath,
|
.filepath = params.get("path").?.value,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -422,8 +422,7 @@ pub const Image = struct {
|
||||||
self: *Image,
|
self: *Image,
|
||||||
comptime Plugin: type,
|
comptime Plugin: type,
|
||||||
position: plugins.Position,
|
position: plugins.Position,
|
||||||
comptime ExtraType: type,
|
extra: *ParamMap,
|
||||||
extra: ExtraType,
|
|
||||||
) !void {
|
) !void {
|
||||||
var plugin_opt: ?Plugin = Plugin.init(self.allocator, extra);
|
var plugin_opt: ?Plugin = Plugin.init(self.allocator, extra);
|
||||||
if (plugin_opt == null) {
|
if (plugin_opt == null) {
|
||||||
|
|
25
src/lang.zig
25
src/lang.zig
|
@ -1,6 +1,7 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const plugin = @import("plugin.zig");
|
const plugin = @import("plugin.zig");
|
||||||
|
const custom = @import("custom.zig");
|
||||||
|
|
||||||
pub const ParseError = error{
|
pub const ParseError = error{
|
||||||
OutOfMemory,
|
OutOfMemory,
|
||||||
|
@ -12,6 +13,8 @@ pub const CommandType = enum {
|
||||||
/// "LV2 Commands" are commands that receive split, index, and then receive
|
/// "LV2 Commands" are commands that receive split, index, and then receive
|
||||||
/// any f64 arguments.
|
/// any f64 arguments.
|
||||||
lv2_command,
|
lv2_command,
|
||||||
|
|
||||||
|
custom_command,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn LV2Command(
|
fn LV2Command(
|
||||||
|
@ -32,19 +35,19 @@ fn LV2Command(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn CustomCommand(
|
fn CustomCommand(
|
||||||
comptime tag: Command.tag,
|
comptime tag: Command.Tag,
|
||||||
comptime plugin: type,
|
comptime Plugin: type,
|
||||||
comptime parameters: type,
|
comptime PluginParameters: type,
|
||||||
) type {
|
) type {
|
||||||
return struct {
|
return struct {
|
||||||
pub const base_tag = tag;
|
pub const base_tag = tag;
|
||||||
pub const command_type = CommandType.plugin_command;
|
pub const command_type = CommandType.custom_command;
|
||||||
pub const plugin_type = plugin;
|
pub const plugin_type = Plugin;
|
||||||
|
|
||||||
base: Command,
|
base: Command,
|
||||||
split: usize,
|
split: usize,
|
||||||
index: usize,
|
index: usize,
|
||||||
parameters: LV2Parameters,
|
parameters: PluginParameters,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,13 +191,9 @@ pub const Command = struct {
|
||||||
data: f32,
|
data: f32,
|
||||||
});
|
});
|
||||||
|
|
||||||
pub const Embed = struct {
|
pub const Embed = CustomCommand(Tag.write, custom.Embed, struct {
|
||||||
pub const base_tag = Tag.embed;
|
|
||||||
base: Command,
|
|
||||||
split: usize,
|
|
||||||
index: usize,
|
|
||||||
path: []const u8,
|
path: []const u8,
|
||||||
};
|
});
|
||||||
|
|
||||||
pub const Rotate = struct {
|
pub const Rotate = struct {
|
||||||
pub const base_tag = Tag.rotate;
|
pub const base_tag = Tag.rotate;
|
||||||
|
@ -521,7 +520,7 @@ pub const Lang = struct {
|
||||||
// Based on the command struct fields, we can parse the arguments.
|
// Based on the command struct fields, we can parse the arguments.
|
||||||
var cmd = try self.allocator.create(command_struct);
|
var cmd = try self.allocator.create(command_struct);
|
||||||
const is_lv2_command = switch (command_struct.base_tag) {
|
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,
|
else => command_struct.command_type == .lv2_command,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -190,26 +190,6 @@ pub const Runner = struct {
|
||||||
_ = try proc.spawnAndWait();
|
_ = 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(
|
fn rotateCmd(
|
||||||
self: *Runner,
|
self: *Runner,
|
||||||
deg: f32,
|
deg: f32,
|
||||||
|
@ -244,6 +224,26 @@ pub const Runner = struct {
|
||||||
try image.runPlugin(typ.lv2_url, pos, params);
|
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(
|
fn newRunCommandSingle(
|
||||||
self: *@This(),
|
self: *@This(),
|
||||||
cmd: lang.Command,
|
cmd: lang.Command,
|
||||||
|
@ -261,6 +261,7 @@ pub const Runner = struct {
|
||||||
const ctype = typ.command_type;
|
const ctype = typ.command_type;
|
||||||
switch (ctype) {
|
switch (ctype) {
|
||||||
.lv2_command => try self.executeLV2Command(command.*),
|
.lv2_command => try self.executeLV2Command(command.*),
|
||||||
|
.plugin_command => try self.executePlugin(command.*),
|
||||||
else => @panic("TODO support command type"),
|
else => @panic("TODO support command type"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -305,6 +306,8 @@ pub const Runner = struct {
|
||||||
.saturator => try self.newRunCommandSingle(cmd, .saturator),
|
.saturator => try self.newRunCommandSingle(cmd, .saturator),
|
||||||
.vintagedelay => try self.newRunCommandSingle(cmd, .vintagedelay),
|
.vintagedelay => try self.newRunCommandSingle(cmd, .vintagedelay),
|
||||||
|
|
||||||
|
.noise, .wildnoise, .write, .embed => |tag| try self.newRunCommandSingle(cmd, tag),
|
||||||
|
|
||||||
else => {
|
else => {
|
||||||
std.debug.warn("TODO support {}\n", .{@tagName(cmd.tag)});
|
std.debug.warn("TODO support {}\n", .{@tagName(cmd.tag)});
|
||||||
@panic("TODO support tag");
|
@panic("TODO support tag");
|
||||||
|
|
Loading…
Reference in a new issue