From 846faafc92e016c1ef4c0311511fce4aa7c9367f Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 7 Jul 2019 14:39:51 -0300 Subject: [PATCH] make lv2core namespaces use std.cstr.addNullByte --- src/main.zig | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main.zig b/src/main.zig index 926e59b..4e60afe 100644 --- a/src/main.zig +++ b/src/main.zig @@ -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: {