add basic plugin position code

This commit is contained in:
Luna 2019-07-09 16:52:46 -03:00
parent 25bef23933
commit 32699a55a5
2 changed files with 34 additions and 1 deletions

View File

@ -4,6 +4,9 @@ const c = lv2.c;
const plugins = @import("plugin.zig"); const plugins = @import("plugin.zig");
/// Approximate size of the BMP header.
pub const BMPHeaderSize: usize = 82000;
pub const ImageError = error{ pub const ImageError = error{
OpenFail, OpenFail,
InvalidPlugin, InvalidPlugin,
@ -38,6 +41,12 @@ fn sopen(
return file.?; return file.?;
} }
fn getEndPos(path: []const u8) !usize {
var file = try std.fs.File.openRead(path);
defer file.close();
return file.getEndPos();
}
fn temporaryName(allocator: *std.mem.Allocator) ![]u8 { fn temporaryName(allocator: *std.mem.Allocator) ![]u8 {
const template_start = "/temp/temp_"; const template_start = "/temp/temp_";
const template = "/tmp/temp_XXXXXX"; const template = "/tmp/temp_XXXXXX";
@ -135,7 +144,7 @@ pub const Image = struct {
pub fn runPlugin( pub fn runPlugin(
self: *Image, self: *Image,
plugin_uri: []const u8, plugin_uri: []const u8,
pos: plugins.Position, position: plugins.Position,
params: plugins.ParamList, params: plugins.ParamList,
) !void { ) !void {
var ctx = try plugins.makeContext(self.allocator, plugin_uri); var ctx = try plugins.makeContext(self.allocator, plugin_uri);
@ -186,5 +195,14 @@ pub const Image = struct {
var rctx = try plugins.RunContext.init(self.allocator, ctx.plugin); var rctx = try plugins.RunContext.init(self.allocator, ctx.plugin);
rctx.connectPorts(ports); rctx.connectPorts(ports);
lv2.lilv_instance_activate(rctx.instance); lv2.lilv_instance_activate(rctx.instance);
// now that we have everything setup, we need to make the part where we
// just copy the original image and the part where we run the plugin
// over the image.
const end_pos = (try getEndPos(self.path)) - BMPHeaderSize;
std.debug.warn("file end: {}\n", end_pos);
const seek_pos = position.seekPos(end_pos);
std.debug.warn("start {} end {}\n", seek_pos.start, seek_pos.end);
} }
}; };

View File

@ -17,10 +17,25 @@ pub const Param = struct {
/// List of parameters to be set to control ports. /// List of parameters to be set to control ports.
pub const ParamList = std.ArrayList(Param); pub const ParamList = std.ArrayList(Param);
/// Represents an absolute position in the image.
pub const SeekPos = struct {
start: usize,
end: usize,
};
/// Represents a relative position in the image /// Represents a relative position in the image
pub const Position = struct { pub const Position = struct {
split: usize, split: usize,
index: usize, index: usize,
pub fn seekPos(self: Position, total_size: usize) SeekPos {
var tot = total_size / self.split;
return SeekPos{
.start = self.index * tot,
.end = (self.index + 1) * tot,
};
}
}; };
/// Represents the starting context for a single plugin run. /// Represents the starting context for a single plugin run.