+ _ardour_buttons_box.set_spacing (6);
+ _ardour_buttons_box.set_border_width (6);
+ _ardour_buttons_box.pack_end (focus_button, false, false);
+ _ardour_buttons_box.pack_end (bypass_button, false, false, 4);
+ if (pi->controls().size() > 0) {
+ _ardour_buttons_box.pack_end (reset_button, false, false, 4);
+ }
+ _ardour_buttons_box.pack_end (delete_button, false, false);
+ _ardour_buttons_box.pack_end (save_button, false, false);
+ _ardour_buttons_box.pack_end (add_button, false, false);
+ _ardour_buttons_box.pack_end (_preset_combo, false, false);
+ _ardour_buttons_box.pack_end (_preset_modified, false, false);
+ _ardour_buttons_box.pack_end (pin_management_button, false, false);
+
+ plugin->PresetLoaded.connect (*this, invalidator (*this), boost::bind (&LV2PluginUI::queue_port_update, this), gui_context ());
+}
+
+void
+LV2PluginUI::lv2ui_instantiate(const std::string& title)
+{
+ bool is_external_ui = _lv2->is_external_ui();
+ LV2_Feature** features_src = const_cast<LV2_Feature**>(_lv2->features());
+ LV2_Feature** features = const_cast<LV2_Feature**>(_lv2->features());
+ size_t features_count = 0;
+ while (*features++) {
+ ++features_count;
+ }
+
+ if (is_external_ui) {
+ features = (LV2_Feature**)malloc(sizeof(LV2_Feature*) * (features_count + 4));
+ } else {
+ features = (LV2_Feature**)malloc(sizeof(LV2_Feature*) * (features_count + 3));
+ }
+
+ size_t fi = 0;
+ for (; fi < features_count; ++fi) {
+ features[fi] = features_src[fi];
+ }
+
+ _lv2ui_request_paramater.handle = this;
+ _lv2ui_request_paramater.request = LV2PluginUI::request_parameter;
+ _lv2ui_request_feature.URI = LV2_UI_PREFIX "requestParameter";
+ _lv2ui_request_feature.data = &_lv2ui_request_paramater;
+
+ features[fi++] = &_lv2ui_request_feature;
+
+ Gtk::Alignment* container = NULL;
+ if (is_external_ui) {
+ _external_ui_host.ui_closed = LV2PluginUI::on_external_ui_closed;
+ _external_ui_host.plugin_human_id = strdup(title.c_str());
+
+ _external_ui_feature.URI = LV2_EXTERNAL_UI_URI;
+ _external_ui_feature.data = &_external_ui_host;
+
+ _external_kxui_feature.URI = LV2_EXTERNAL_UI_KX__Host;
+ _external_kxui_feature.data = &_external_ui_host;
+
+ features[fi++] = &_external_kxui_feature;
+ features[fi++] = &_external_ui_feature;
+ } else {
+ if (_ardour_buttons_box.get_parent()) {
+ _ardour_buttons_box.get_parent()->remove(_ardour_buttons_box);
+ }
+ pack_start(_ardour_buttons_box, false, false);
+ _ardour_buttons_box.show_all();
+
+ _gui_widget = Gtk::manage((container = new Gtk::Alignment()));
+ pack_start(*_gui_widget, true, true);
+ _gui_widget->show();
+
+ _parent_feature.URI = LV2_UI__parent;
+ _parent_feature.data = _gui_widget->gobj();
+
+ features[fi++] = &_parent_feature;
+ }
+
+ features[fi] = NULL;
+ assert (fi == features_count + (is_external_ui ? 3 : 2));
+
+ if (!ui_host) {
+ ui_host = suil_host_new(LV2PluginUI::write_from_ui,
+ LV2PluginUI::port_index,
+ NULL, NULL);
+ suil_host_set_touch_func(ui_host, LV2PluginUI::touch);
+ }
+ const char* container_type = (is_external_ui)
+ ? NS_UI "external"
+ : NS_UI "GtkUI";
+
+ if (_lv2->has_message_output()) {
+ _lv2->enable_ui_emission();
+ }
+
+ const LilvUI* ui = (const LilvUI*)_lv2->c_ui();
+ const LilvNode* bundle = lilv_ui_get_bundle_uri(ui);
+ const LilvNode* binary = lilv_ui_get_binary_uri(ui);
+#ifdef HAVE_LILV_0_21_3
+ char* ui_bundle_path = lilv_file_uri_parse(lilv_node_as_uri(bundle), NULL);
+ char* ui_binary_path = lilv_file_uri_parse(lilv_node_as_uri(binary), NULL);
+#else
+ char* ui_bundle_path = strdup(lilv_uri_to_path(lilv_node_as_uri(bundle)));
+ char* ui_binary_path = strdup(lilv_uri_to_path(lilv_node_as_uri(binary)));
+#endif
+ if (!ui_bundle_path || !ui_binary_path) {
+ error << _("failed to get path for UI bindle or binary") << endmsg;
+ free(ui_bundle_path);
+ free(ui_binary_path);
+ free(features);
+ return;
+ }
+
+ _inst = suil_instance_new(
+ ui_host,
+ this,
+ container_type,
+ _lv2->uri(),
+ lilv_node_as_uri(lilv_ui_get_uri(ui)),
+ lilv_node_as_uri((const LilvNode*)_lv2->c_ui_type()),
+ ui_bundle_path,
+ ui_binary_path,
+ features);
+
+ free(ui_bundle_path);
+ free(ui_binary_path);
+ free(features);
+
+ if (!_inst) {
+ error << _("failed to instantiate LV2 GUI") << endmsg;
+ return;
+ }
+
+#define GET_WIDGET(inst) suil_instance_get_widget((SuilInstance*)inst);
+
+ const uint32_t num_ports = _lv2->num_ports();