move lv2 core constants to comptime

This commit is contained in:
Luna 2019-08-10 14:36:51 -03:00
parent 0cab58429c
commit af34f71c8f
1 changed files with 9 additions and 17 deletions

View File

@ -7,17 +7,17 @@ pub const c = @cImport({
@cInclude("lv2/core/lv2.h");
});
const LV2_CORE_URI = "http://lv2plug.in/ns/lv2core";
pub fn Lv2Core(ns: []const u8) ![]const u8 {
var allocator = std.heap.direct_allocator;
return try std.cstr.addNullByte(
allocator,
try std.fmt.allocPrint(allocator, "{}{}", LV2_CORE_URI, ns),
);
pub fn Lv2Core(comptime ns: []const u8) []const u8 {
const LV2_CORE_URI = "http://lv2plug.in/ns/lv2core";
return LV2_CORE_URI ++ ns ++ [_]u8{0};
}
const LV2_CORE__InputPort = Lv2Core("#InputPort");
const LV2_CORE__OutputPort = Lv2Core("#OutputPort");
const LV2_CORE__AudioPort = Lv2Core("#AudioPort");
const LV2_CORE__ControlPort = Lv2Core("#ControlPort");
const LV2_CORE__connectionOptional = Lv2Core("#connectionOptional");
pub fn lilv_instance_connect_port(
instance: [*c]c.LilvInstance,
port_index: u32,
@ -83,14 +83,6 @@ pub fn setupPorts(ctx: *plugin.Context) ![]*Port {
defer ctx.allocator.free(values);
c.lilv_plugin_get_port_ranges_float(ctx.plugin, null, null, values.ptr);
// bad solution, but it really do be like that
const LV2_CORE__InputPort = try Lv2Core("#InputPort");
const LV2_CORE__OutputPort = try Lv2Core("#OutputPort");
const LV2_CORE__AudioPort = try Lv2Core("#AudioPort");
const LV2_CORE__ControlPort = try Lv2Core("#ControlPort");
const LV2_CORE__connectionOptional = try Lv2Core("#connectionOptional");
var lv2_InputPort = c.lilv_new_uri(world, LV2_CORE__InputPort.ptr);
defer std.heap.c_allocator.destroy(lv2_InputPort);