summaryrefslogtreecommitdiffstats
path: root/src/client/PluginUI.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2013-11-01 21:55:48 +0000
committerDavid Robillard <d@drobilla.net>2013-11-01 21:55:48 +0000
commit22f9b193006de486a569d67f11c82fd12d790181 (patch)
tree19000e60a14b0dd04db352b94a4d4d0baa5b2836 /src/client/PluginUI.cpp
parentb69555d59fed393f7301880a81d8709afda8e1ce (diff)
downloadingen-22f9b193006de486a569d67f11c82fd12d790181.tar.gz
ingen-22f9b193006de486a569d67f11c82fd12d790181.tar.bz2
ingen-22f9b193006de486a569d67f11c82fd12d790181.zip
Implement LV2 UI port_index, subscribe, and unsubscribe features.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@5169 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/client/PluginUI.cpp')
-rw-r--r--src/client/PluginUI.cpp84
1 files changed, 72 insertions, 12 deletions
diff --git a/src/client/PluginUI.cpp b/src/client/PluginUI.cpp
index b24332d6..9bfe69fc 100644
--- a/src/client/PluginUI.cpp
+++ b/src/client/PluginUI.cpp
@@ -30,6 +30,18 @@ namespace Client {
SuilHost* PluginUI::ui_host = NULL;
+static SPtr<const PortModel>
+get_port(PluginUI* ui, uint32_t port_index)
+{
+ if (port_index >= ui->block()->ports().size()) {
+ ui->world()->log().error(
+ fmt("%1% UI tried to access invalid port %2%\n")
+ % ui->block()->plugin()->uri().c_str() % port_index);
+ return SPtr<const PortModel>();
+ }
+ return ui->block()->ports()[port_index];
+}
+
static void
lv2_ui_write(SuilController controller,
uint32_t port_index,
@@ -37,20 +49,13 @@ lv2_ui_write(SuilController controller,
uint32_t format,
const void* buffer)
{
- PluginUI* const ui = (PluginUI*)controller;
-
- const BlockModel::Ports& ports = ui->block()->ports();
- if (port_index >= ports.size()) {
- ui->world()->log().error(
- fmt("%1% UI tried to write to invalid port %2%\n")
- % ui->block()->plugin()->uri().c_str() % port_index);
+ PluginUI* const ui = (PluginUI*)controller;
+ const URIs& uris = ui->world()->uris();
+ SPtr<const PortModel> port = get_port(ui, port_index);
+ if (!port) {
return;
}
- SPtr<const PortModel> port = ports[port_index];
-
- const URIs& uris = ui->world()->uris();
-
// float (special case, always 0)
if (format == 0) {
if (buffer_size != 4) {
@@ -85,6 +90,60 @@ lv2_ui_write(SuilController controller,
}
}
+static uint32_t
+lv2_ui_port_index(SuilController controller, const char* port_symbol)
+{
+ PluginUI* const ui = (PluginUI*)controller;
+
+ const BlockModel::Ports& ports = ui->block()->ports();
+ for (uint32_t i = 0; i < ports.size(); ++i) {
+ if (ports[i]->symbol() == port_symbol) {
+ return i;
+ }
+ }
+ return LV2UI_INVALID_PORT_INDEX;
+}
+
+static uint32_t
+lv2_ui_subscribe(SuilController controller,
+ uint32_t port_index,
+ uint32_t protocol,
+ const LV2_Feature* const* features)
+{
+ PluginUI* const ui = (PluginUI*)controller;
+ SPtr<const PortModel> port = get_port(ui, port_index);
+ if (!port) {
+ return 1;
+ }
+
+ ui->world()->interface()->set_property(
+ ui->block()->ports()[port_index]->uri(),
+ ui->world()->uris().ingen_broadcast,
+ ui->world()->forge().make(true));
+
+ return 0;
+}
+
+static uint32_t
+lv2_ui_unsubscribe(SuilController controller,
+ uint32_t port_index,
+ uint32_t protocol,
+ const LV2_Feature* const* features)
+{
+ PluginUI* const ui = (PluginUI*)controller;
+ SPtr<const PortModel> port = get_port(ui, port_index);
+ if (!port) {
+ return 1;
+ }
+
+ ui->world()->interface()->set_property(
+ ui->block()->ports()[port_index]->uri(),
+ ui->world()->uris().ingen_broadcast,
+ ui->world()->forge().make(false));
+
+ return 0;
+}
+
PluginUI::PluginUI(Ingen::World* world,
SPtr<const BlockModel> block,
const LilvNode* ui_node)
@@ -107,7 +166,8 @@ PluginUI::create(Ingen::World* world,
const LilvPlugin* plugin)
{
if (!PluginUI::ui_host) {
- PluginUI::ui_host = suil_host_new(lv2_ui_write, NULL, NULL, NULL);
+ 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;