Compare commits
No commits in common. "612421f7b6ff34223a41a19abef4d6a1fb2b6cd8" and "87bab879ed60db02d6c7db4673c1920e15ac9e40" have entirely different histories.
612421f7b6
...
87bab879ed
5 changed files with 9 additions and 92 deletions
|
@ -2,7 +2,6 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const lv2 = @import("lv2_helpers.zig");
|
const lv2 = @import("lv2_helpers.zig");
|
||||||
const plugins = @import("plugin.zig");
|
const plugins = @import("plugin.zig");
|
||||||
const image = @import("image.zig");
|
|
||||||
|
|
||||||
const c = lv2.c;
|
const c = lv2.c;
|
||||||
|
|
||||||
|
@ -132,61 +131,3 @@ pub const Write = struct {
|
||||||
bufs.out[0] = self.data;
|
bufs.out[0] = self.data;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Embed = struct {
|
|
||||||
allocator: *std.mem.Allocator,
|
|
||||||
filepath: []const u8,
|
|
||||||
|
|
||||||
sndfile: *c.SNDFILE = undefined,
|
|
||||||
buf: []f32 = undefined,
|
|
||||||
|
|
||||||
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,
|
|
||||||
);
|
|
||||||
|
|
||||||
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 {
|
|
||||||
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];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const lv2 = @import("lv2_helpers.zig");
|
const lv2 = @import("lv2_helpers.zig");
|
||||||
const c = lv2.c;
|
const c = lv2.c;
|
||||||
|
const custom = @import("custom.zig");
|
||||||
const bmp = @import("bmp_valid.zig");
|
const bmp = @import("bmp_valid.zig");
|
||||||
|
|
||||||
const plugins = @import("plugin.zig");
|
const plugins = @import("plugin.zig");
|
||||||
|
@ -22,7 +23,7 @@ pub const ImageError = error{
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Low level integration function with libsndfile.
|
/// Low level integration function with libsndfile.
|
||||||
pub fn sopen(
|
fn sopen(
|
||||||
allocator: *std.mem.Allocator,
|
allocator: *std.mem.Allocator,
|
||||||
path: []const u8,
|
path: []const u8,
|
||||||
mode: i32,
|
mode: i32,
|
||||||
|
@ -56,7 +57,7 @@ pub fn sopen(
|
||||||
return file.?;
|
return file.?;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn swrite(file: *c.SNDFILE, buf: [*]f32, frames: i64) !void {
|
fn swrite(file: *c.SNDFILE, buf: [*]f32, frames: i64) !void {
|
||||||
const count = c.sf_writef_float(file, buf, frames);
|
const count = c.sf_writef_float(file, buf, frames);
|
||||||
|
|
||||||
if (count != frames) {
|
if (count != frames) {
|
||||||
|
@ -108,7 +109,7 @@ pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 {
|
||||||
return error.TempGenFail;
|
return error.TempGenFail;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mkSfInfo() c.SF_INFO {
|
fn mkSfInfo() c.SF_INFO {
|
||||||
return c.SF_INFO{
|
return c.SF_INFO{
|
||||||
.frames = c_int(0),
|
.frames = c_int(0),
|
||||||
.samplerate = c_int(44100),
|
.samplerate = c_int(44100),
|
||||||
|
@ -421,10 +422,9 @@ pub const Image = struct {
|
||||||
self: *Image,
|
self: *Image,
|
||||||
comptime Plugin: type,
|
comptime Plugin: type,
|
||||||
position: plugins.Position,
|
position: plugins.Position,
|
||||||
comptime ExtraType: type,
|
params: *plugins.ParamMap,
|
||||||
extra: ExtraType,
|
|
||||||
) !void {
|
) !void {
|
||||||
var plugin_opt: ?Plugin = Plugin.init(self.allocator, extra);
|
var plugin_opt: ?Plugin = Plugin.init(self.allocator, params);
|
||||||
if (plugin_opt == null) {
|
if (plugin_opt == null) {
|
||||||
return ImageError.PluginLoadFail;
|
return ImageError.PluginLoadFail;
|
||||||
}
|
}
|
||||||
|
@ -432,13 +432,6 @@ pub const Image = struct {
|
||||||
var plugin = plugin_opt.?;
|
var plugin = plugin_opt.?;
|
||||||
defer plugin.deinit();
|
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
|
// the code here is a copypaste of runPlugin() without the specific
|
||||||
// lilv things.
|
// lilv things.
|
||||||
var tmpnam = try temporaryName(self.allocator);
|
var tmpnam = try temporaryName(self.allocator);
|
||||||
|
|
|
@ -227,7 +227,6 @@ pub const Lang = struct {
|
||||||
"noise",
|
"noise",
|
||||||
"wildnoise",
|
"wildnoise",
|
||||||
"write",
|
"write",
|
||||||
"embed",
|
|
||||||
"rotate",
|
"rotate",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -253,7 +252,6 @@ pub const Lang = struct {
|
||||||
.Noise,
|
.Noise,
|
||||||
.WildNoise,
|
.WildNoise,
|
||||||
.Write,
|
.Write,
|
||||||
.Embed,
|
|
||||||
|
|
||||||
.Rotate,
|
.Rotate,
|
||||||
};
|
};
|
||||||
|
@ -316,7 +314,6 @@ pub const Lang = struct {
|
||||||
.WildNoise => try self.expectFloat(4, cmd.args),
|
.WildNoise => try self.expectFloat(4, cmd.args),
|
||||||
.Write => try self.expectFloat(3, cmd.args),
|
.Write => try self.expectFloat(3, cmd.args),
|
||||||
.Rotate => try self.expectAny(2, 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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@ pub fn printList(list: langs.CommandList, stream: var) !void {
|
||||||
.Noise => "noise",
|
.Noise => "noise",
|
||||||
.WildNoise => "wildnoise",
|
.WildNoise => "wildnoise",
|
||||||
.Write => "write",
|
.Write => "write",
|
||||||
.Embed => "embed",
|
|
||||||
|
|
||||||
.Rotate => "rotate",
|
.Rotate => "rotate",
|
||||||
};
|
};
|
||||||
|
|
|
@ -266,22 +266,17 @@ pub const Runner = struct {
|
||||||
|
|
||||||
fn noiseCmd(self: *Runner, pos: Position, map: *ParamMap) !void {
|
fn noiseCmd(self: *Runner, pos: Position, map: *ParamMap) !void {
|
||||||
var image = try self.getImage();
|
var image = try self.getImage();
|
||||||
try image.runCustomPlugin(custom.RandomNoise, pos, *ParamMap, map);
|
try image.runCustomPlugin(custom.RandomNoise, pos, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wildNoiseCmd(self: *Runner, pos: Position, map: *ParamMap) !void {
|
fn wildNoiseCmd(self: *Runner, pos: Position, map: *ParamMap) !void {
|
||||||
var image = try self.getImage();
|
var image = try self.getImage();
|
||||||
try image.runCustomPlugin(custom.WildNoise, pos, *ParamMap, map);
|
try image.runCustomPlugin(custom.WildNoise, pos, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn writeCmd(self: *Runner, pos: Position, map: *ParamMap) !void {
|
fn writeCmd(self: *Runner, pos: Position, map: *ParamMap) !void {
|
||||||
var image = try self.getImage();
|
var image = try self.getImage();
|
||||||
try image.runCustomPlugin(custom.Write, pos, *ParamMap, map);
|
try image.runCustomPlugin(custom.Write, pos, 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(
|
||||||
|
@ -308,8 +303,6 @@ pub const Runner = struct {
|
||||||
.Load => blk: {
|
.Load => blk: {
|
||||||
var path = cmd.args.at(0);
|
var path = cmd.args.at(0);
|
||||||
try self.loadCmd(path);
|
try self.loadCmd(path);
|
||||||
|
|
||||||
// TODO is this needed?
|
|
||||||
break :blk;
|
break :blk;
|
||||||
},
|
},
|
||||||
.Quicksave => try self.quicksaveCmd(),
|
.Quicksave => try self.quicksaveCmd(),
|
||||||
|
@ -467,12 +460,6 @@ pub const Runner = struct {
|
||||||
try self.writeCmd(pos, &map);
|
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: {
|
.Rotate => blk: {
|
||||||
const deg = try cmd.floatArgAt(0);
|
const deg = try cmd.floatArgAt(0);
|
||||||
const bgfill = try cmd.argAt(1);
|
const bgfill = try cmd.argAt(1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue