2019-07-09 01:40:52 +00:00
|
|
|
const std = @import("std");
|
|
|
|
|
2019-07-09 03:04:01 +00:00
|
|
|
const c = @cImport({
|
|
|
|
@cInclude("lilv/lilv.h");
|
|
|
|
@cInclude("lv2/core/lv2.h");
|
|
|
|
});
|
|
|
|
|
|
|
|
const ImageError = @import("image.zig").ImageError;
|
|
|
|
|
2019-07-09 01:40:52 +00:00
|
|
|
/// Control port
|
|
|
|
pub const Param = struct {
|
|
|
|
/// Port symbol
|
|
|
|
sym: []const u8,
|
|
|
|
|
|
|
|
/// Control value
|
|
|
|
value: f32,
|
|
|
|
};
|
|
|
|
|
2019-07-09 03:04:01 +00:00
|
|
|
/// List of parameters to be set to control ports.
|
2019-07-09 01:40:52 +00:00
|
|
|
pub const ParamList = std.ArrayList(Param);
|
|
|
|
|
2019-07-09 03:04:01 +00:00
|
|
|
/// Represents a relative position in the image
|
2019-07-09 01:40:52 +00:00
|
|
|
pub const Position = struct {
|
|
|
|
split: usize,
|
|
|
|
index: usize,
|
|
|
|
};
|
2019-07-09 03:04:01 +00:00
|
|
|
|
|
|
|
/// Represents the starting context for a single plugin run.
|
|
|
|
pub const Context = struct {
|
|
|
|
world: *c.LilvWorld,
|
|
|
|
plugin: *const c.LilvPlugin,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn makeContext(allocator: *std.mem.Allocator, plugin_uri: []const u8) !Context {
|
|
|
|
const cstr_plugin_uri = try std.cstr.addNullByte(allocator, plugin_uri);
|
|
|
|
var world = c.lilv_world_new().?;
|
|
|
|
|
|
|
|
c.lilv_world_load_all(world);
|
|
|
|
var uri: *c.LilvNode = c.lilv_new_uri(world, cstr_plugin_uri.ptr) orelse blk: {
|
|
|
|
std.debug.warn("Invalid plugin URI <{}>\n", plugin_uri);
|
|
|
|
return ImageError.InvalidPlugin;
|
|
|
|
};
|
|
|
|
|
|
|
|
const plugins: *const c.LilvPlugins = c.lilv_world_get_all_plugins(world);
|
|
|
|
|
|
|
|
var plugin: *const c.LilvPlugin = c.lilv_plugins_get_by_uri(plugins, uri) orelse blk: {
|
|
|
|
std.debug.warn("Plugin <{}> not found\n", plugin_uri);
|
|
|
|
return ImageError.UnknownPlugin;
|
|
|
|
};
|
|
|
|
|
|
|
|
c.lilv_node_free(uri);
|
|
|
|
|
|
|
|
return Context{ .world = world, .plugin = plugin };
|
|
|
|
}
|