From b50590f499271e6c1807285db538cd7684da327f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 1 Nov 2013 22:40:23 +0000 Subject: Implement static UI port notifications (fix #935). git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@5172 a436a847-0d15-0410-975c-d299462d15a1 --- src/client/PluginUI.cpp | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'src/client/PluginUI.cpp') diff --git a/src/client/PluginUI.cpp b/src/client/PluginUI.cpp index 9bfe69fc..227f6000 100644 --- a/src/client/PluginUI.cpp +++ b/src/client/PluginUI.cpp @@ -1,6 +1,6 @@ /* This file is part of Ingen. - Copyright 2007-2012 David Robillard + Copyright 2007-2013 David Robillard Ingen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free @@ -156,6 +156,9 @@ PluginUI::PluginUI(Ingen::World* world, PluginUI::~PluginUI() { + for (uint32_t i : _subscribed_ports) { + lv2_ui_unsubscribe(this, i, 0, NULL); + } suil_instance_free(_instance); lilv_node_free(_ui_node); } @@ -166,8 +169,10 @@ PluginUI::create(Ingen::World* world, const LilvPlugin* plugin) { if (!PluginUI::ui_host) { - PluginUI::ui_host = suil_host_new( - lv2_ui_write, lv2_ui_port_index, lv2_ui_subscribe, lv2_ui_unsubscribe); + PluginUI::ui_host = suil_host_new(lv2_ui_write, + lv2_ui_port_index, + lv2_ui_subscribe, + lv2_ui_unsubscribe); } static const char* gtk_ui_uri = LV2_UI__GtkUI; @@ -211,12 +216,32 @@ PluginUI::create(Ingen::World* world, lilv_node_free(gtk_ui); - if (instance) { - ret->_instance = instance; - } else { + if (!instance) { world->log().error("Failed to instantiate LV2 UI\n"); - ret.reset(); + return SPtr(); + } + + ret->_instance = instance; + + LilvWorld* lworld = world->lilv_world(); + LilvNode* ui_portNotification = lilv_new_uri(lworld, LV2_UI__portNotification); + LilvNode* lv2_symbol = lilv_new_uri(lworld, LV2_CORE__symbol); + LilvNodes* notes = lilv_world_find_nodes( + lworld, lilv_ui_get_uri(ui), ui_portNotification, NULL); + LILV_FOREACH(nodes, n, notes) { + const LilvNode* note = lilv_nodes_get(notes, n); + const LilvNode* sym = lilv_world_get(lworld, note, lv2_symbol, NULL); + if (sym) { + uint32_t index = lv2_ui_port_index(ret.get(), lilv_node_as_string(sym)); + if (index != LV2UI_INVALID_PORT_INDEX) { + lv2_ui_subscribe(ret.get(), index, 0, NULL); + ret->_subscribed_ports.insert(index); + } + } } + lilv_nodes_free(notes); + lilv_node_free(lv2_symbol); + lilv_node_free(ui_portNotification); return ret; } -- cgit v1.2.1