From cc3268a8be3ee4ce7a603e9546da21cf72705690 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 20 May 2018 21:48:41 +0200 Subject: [PATCH] Store port notifications in LV2_RDF struct --- source/includes/lv2_rdf.hpp | 40 ++++++++++++++++++++++++- source/utils/CarlaLv2Utils.hpp | 55 ++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) diff --git a/source/includes/lv2_rdf.hpp b/source/includes/lv2_rdf.hpp index 412d54322..46f038c9c 100644 --- a/source/includes/lv2_rdf.hpp +++ b/source/includes/lv2_rdf.hpp @@ -206,6 +206,13 @@ typedef uint32_t LV2_Property; #define LV2_IS_PORT_DESIGNATION_TIME_TICKS_PER_BEAT(x) ((x) == LV2_PORT_DESIGNATION_TIME_TICKS_PER_BEAT) #define LV2_IS_PORT_DESIGNATION_TIME(x) ((x) >= LV2_PORT_DESIGNATION_TIME_BAR && (x) <= LV2_PORT_DESIGNATION_TIME_TICKS_PER_BEAT) +// UI Port Protocol +#define LV2_UI_PORT_PROTOCOL_FLOAT 1 +#define LV2_UI_PORT_PROTOCOL_PEAK 2 + +#define LV2_IS_UI_PORT_PROTOCOL_FLOAT(x) ((x) == LV2_UI_PORT_PROTOCOL_FLOAT) +#define LV2_IS_UI_PORT_PROTOCOL_PEAK(x) ((x) == LV2_UI_PORT_PROTOCOL_PEAK) + // UI Types #define LV2_UI_GTK2 1 #define LV2_UI_GTK3 2 @@ -475,6 +482,27 @@ struct LV2_RDF_Feature { CARLA_DECLARE_NON_COPY_STRUCT(LV2_RDF_Feature) }; +// Port Notification +struct LV2_RDF_UI_PortNotification { + const char* Symbol; + LV2_Property Protocol; + + LV2_RDF_UI_PortNotification() noexcept + : Symbol(nullptr), + Protocol(0) {} + + ~LV2_RDF_UI_PortNotification() noexcept + { + if (Symbol != nullptr) + { + delete[] Symbol; + Symbol = nullptr; + } + } + + CARLA_DECLARE_NON_COPY_STRUCT(LV2_RDF_UI_PortNotification) +}; + // UI struct LV2_RDF_UI { LV2_Property Type; @@ -488,6 +516,9 @@ struct LV2_RDF_UI { uint32_t ExtensionCount; LV2_URI* Extensions; + uint32_t PortNotificationCount; + LV2_RDF_UI_PortNotification* PortNotifications; + LV2_RDF_UI() noexcept : Type(0), URI(nullptr), @@ -496,7 +527,9 @@ struct LV2_RDF_UI { FeatureCount(0), Features(nullptr), ExtensionCount(0), - Extensions(nullptr) {} + Extensions(nullptr), + PortNotificationCount(0), + PortNotifications(nullptr) {} ~LV2_RDF_UI() noexcept { @@ -533,6 +566,11 @@ struct LV2_RDF_UI { delete[] Extensions; Extensions = nullptr; } + if (PortNotifications != nullptr) + { + delete[] PortNotifications; + PortNotifications = nullptr; + } } CARLA_DECLARE_NON_COPY_STRUCT(LV2_RDF_UI) diff --git a/source/utils/CarlaLv2Utils.hpp b/source/utils/CarlaLv2Utils.hpp index 8ddbdf360..0b07a7f13 100644 --- a/source/utils/CarlaLv2Utils.hpp +++ b/source/utils/CarlaLv2Utils.hpp @@ -247,6 +247,9 @@ public: Lilv::Node state_state; + Lilv::Node ui_portNotif; + Lilv::Node ui_protocol; + Lilv::Node value_default; Lilv::Node value_minimum; Lilv::Node value_maximum; @@ -373,6 +376,9 @@ public: state_state (new_uri(LV2_STATE__state)), + ui_portNotif (new_uri(LV2_UI__portNotification)), + ui_protocol (new_uri(LV2_UI__protocol)), + value_default (new_uri(LV2_CORE__default)), value_minimum (new_uri(LV2_CORE__minimum)), value_maximum (new_uri(LV2_CORE__maximum)), @@ -2478,6 +2484,55 @@ const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri, const bool loadPresets) lilv_nodes_free(const_cast(lilvExtensionDataNodes.me)); } + + // ---------------------------------------------------------------------------------------------------- + // Set UI Port Notifications + { + Lilv::Nodes portNotifNodes(lv2World.find_nodes(lilvUI.get_uri(), lv2World.ui_portNotif.me, nullptr)); + + if (portNotifNodes.size() > 0) + { + rdfUI->PortNotificationCount = portNotifNodes.size(); + rdfUI->PortNotifications = new LV2_RDF_UI_PortNotification[rdfUI->PortNotificationCount]; + + carla_stdout("got port notifications!! %u", rdfUI->PortNotificationCount); + + uint32_t h2 = 0; + LILV_FOREACH(nodes, it2, portNotifNodes) + { + CARLA_SAFE_ASSERT_BREAK(h2 < rdfUI->PortNotificationCount); + + Lilv::Node portNotifNode(portNotifNodes.get(it2)); + LV2_RDF_UI_PortNotification* const rdfPortNotif(&rdfUI->PortNotifications[h2++]); + + LilvNode* const symbolNode = lilv_world_get(lv2World.me, portNotifNode, + lv2World.symbol.me, nullptr); + CARLA_SAFE_ASSERT_CONTINUE(symbolNode != nullptr); + + LilvNode* const protocolNode = lilv_world_get(lv2World.me, portNotifNode, + lv2World.ui_protocol.me, nullptr); + CARLA_SAFE_ASSERT_CONTINUE(protocolNode != nullptr); + + CARLA_SAFE_ASSERT_CONTINUE(lilv_node_is_string(symbolNode)); + CARLA_SAFE_ASSERT_CONTINUE(lilv_node_is_uri(protocolNode)); + + const char* const symbol = lilv_node_as_string(symbolNode); + CARLA_SAFE_ASSERT_CONTINUE(symbol != nullptr && symbol[0] != '\0'); + + const char* const protocol = lilv_node_as_uri(protocolNode); + CARLA_SAFE_ASSERT_CONTINUE(protocol != nullptr && protocol[0] != '\0'); + + /**/ if (std::strcmp(protocol, LV2_UI__floatProtocol) == 0) + rdfPortNotif->Protocol = LV2_UI_PORT_PROTOCOL_FLOAT; + else if (std::strcmp(protocol, LV2_UI__peakProtocol) == 0) + rdfPortNotif->Protocol = LV2_UI_PORT_PROTOCOL_PEAK; + + rdfPortNotif->Symbol = carla_strdup_safe(symbol); + } + } + + lilv_nodes_free(const_cast(portNotifNodes.me)); + } } }