Compare commits
No commits in common. "83996b889fba82dc24f716203f2450b59fa622dc" and "e669b74ffb0b5444f2b77dc157c536bb524d5c8d" have entirely different histories.
83996b889f
...
e669b74ffb
4 changed files with 39 additions and 39 deletions
|
@ -120,8 +120,9 @@ 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 = params.get("data").?.value,
|
.data = data.value,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,10 +140,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, params: *plugins.ParmaMap) @This() {
|
pub fn init(allocator: *std.mem.Allocator, filepath: []const u8) @This() {
|
||||||
return Embed{
|
return Embed{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.filepath = params.get("path").?.value,
|
.filepath = filepath,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -422,7 +422,8 @@ pub const Image = struct {
|
||||||
self: *Image,
|
self: *Image,
|
||||||
comptime Plugin: type,
|
comptime Plugin: type,
|
||||||
position: plugins.Position,
|
position: plugins.Position,
|
||||||
extra: *ParamMap,
|
comptime ExtraType: type,
|
||||||
|
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,7 +1,6 @@
|
||||||
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,
|
||||||
|
@ -13,8 +12,6 @@ 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(
|
||||||
|
@ -35,19 +32,19 @@ fn LV2Command(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn CustomCommand(
|
fn CustomCommand(
|
||||||
comptime tag: Command.Tag,
|
comptime tag: Command.tag,
|
||||||
comptime Plugin: type,
|
comptime plugin: type,
|
||||||
comptime PluginParameters: type,
|
comptime parameters: type,
|
||||||
) type {
|
) type {
|
||||||
return struct {
|
return struct {
|
||||||
pub const base_tag = tag;
|
pub const base_tag = tag;
|
||||||
pub const command_type = CommandType.custom_command;
|
pub const command_type = CommandType.plugin_command;
|
||||||
pub const plugin_type = Plugin;
|
pub const plugin_type = plugin;
|
||||||
|
|
||||||
base: Command,
|
base: Command,
|
||||||
split: usize,
|
split: usize,
|
||||||
index: usize,
|
index: usize,
|
||||||
parameters: PluginParameters,
|
parameters: LV2Parameters,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,9 +188,13 @@ pub const Command = struct {
|
||||||
data: f32,
|
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,
|
path: []const u8,
|
||||||
});
|
};
|
||||||
|
|
||||||
pub const Rotate = struct {
|
pub const Rotate = struct {
|
||||||
pub const base_tag = Tag.rotate;
|
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.
|
// 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, .rotate => false,
|
.noop, .load, .quicksave, .runqs => false,
|
||||||
else => command_struct.command_type == .lv2_command,
|
else => command_struct.command_type == .lv2_command,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -190,6 +190,26 @@ 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,
|
||||||
|
@ -224,26 +244,6 @@ 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,7 +261,6 @@ 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"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -306,8 +305,6 @@ 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…
Add table
Add a link
Reference in a new issue