+ _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);
+ _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);
+}
+
+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++;
+ }
+
+ 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_count;
+ features = (LV2_Feature**)malloc(
+ sizeof(LV2_Feature*) * (features_count + 2));
+ for (size_t i = 0; i < features_count - 2; ++i) {
+ features[i] = features_src[i];
+ }
+ features[features_count - 2] = &_external_kxui_feature;
+ features[features_count - 1] = &_external_ui_feature;
+ features[features_count] = NULL;
+ } 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_count;
+ features = (LV2_Feature**)malloc(
+ sizeof(LV2_Feature*) * (features_count + 1));
+ for (size_t i = 0; i < features_count - 1; ++i) {
+ features[i] = features_src[i];
+ }
+ features[features_count - 1] = &_parent_feature;
+ features[features_count] = NULL;
+ }
+
+ 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);
+
+#define GET_WIDGET(inst) suil_instance_get_widget((SuilInstance*)inst);
+
+ const uint32_t num_ports = _lv2->num_ports();
+ for (uint32_t i = 0; i < num_ports; ++i) {
+ if (_lv2->parameter_is_output(i)
+ && _lv2->parameter_is_control(i)
+ && is_update_wanted(i)) {
+ _output_ports.push_back(i);
+ }
+ }
+
+ _external_ui_ptr = NULL;
+ if (_inst) {
+ if (!is_external_ui) {
+ GtkWidget* c_widget = (GtkWidget*)GET_WIDGET(_inst);
+ if (!c_widget) {
+ error << _("failed to get LV2 UI widget") << endmsg;
+ suil_instance_free((SuilInstance*)_inst);
+ _inst = NULL;
+ return;
+ }
+ if (!container->get_child()) {
+ // Suil didn't add the UI to the container for us, so do it now
+ container->add(*Gtk::manage(Glib::wrap(c_widget)));
+ }
+ container->show_all();
+ gtk_widget_set_can_focus(c_widget, true);
+ gtk_widget_grab_focus(c_widget);
+ } else {
+ _external_ui_ptr = (struct lv2_external_ui*)GET_WIDGET(_inst);
+ }
+ }
+