make lv2core namespaces use std.cstr.addNullByte

This commit is contained in:
Luna 2019-07-07 14:39:51 -03:00
parent f7a16447f4
commit 846faafc92

View file

@ -34,15 +34,14 @@ const c = @cImport({
const LV2_CORE_URI = "http://lv2plug.in/ns/lv2core";
fn Lv2Core(comptime ns: []const u8) []const u8 {
return (LV2_CORE_URI ++ ns)[0..];
}
fn Lv2Core(ns: []const u8) ![]const u8 {
var allocator = std.heap.direct_allocator;
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");
return try std.cstr.addNullByte(
allocator,
try std.fmt.allocPrint(allocator, "{}{}", LV2_CORE_URI, ns),
);
}
/// Control port value set from the command line
const Param = struct {
@ -143,6 +142,13 @@ const LV2Apply = struct {
c.lilv_plugin_get_port_ranges_float(self.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);
@ -323,7 +329,7 @@ pub fn main() !void {
self.in_path = in_path.?;
self.out_path = out_path.?;
var plugin_uri = plugin_uri_opt.?;
var plugin_uri = try std.cstr.addNullByte(self.allocator, plugin_uri_opt.?);
self.world = c.lilv_world_new().?;
var uri: *c.LilvNode = c.lilv_new_uri(self.world, plugin_uri.ptr) orelse blk: {