summaryrefslogtreecommitdiff
path: root/gtk2_ardour/lv2_plugin_ui.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2018-11-22 15:02:35 +0100
committerRobin Gareus <robin@gareus.org>2018-11-22 15:02:35 +0100
commite297951b3080bedab8c4cba415178ecdef8e1fb2 (patch)
treeafb0c3c458d348bc68f816e88815ea877245bbe4 /gtk2_ardour/lv2_plugin_ui.cc
parentf795462100cd0a16b86ffa7e07edeb166dc53abd (diff)
Extend LV2UI-Request-Parameter File/Path GUI
This is a bit of a playground implementation, the various `#if 0` code-blocks should be removed.
Diffstat (limited to 'gtk2_ardour/lv2_plugin_ui.cc')
-rw-r--r--gtk2_ardour/lv2_plugin_ui.cc69
1 files changed, 53 insertions, 16 deletions
diff --git a/gtk2_ardour/lv2_plugin_ui.cc b/gtk2_ardour/lv2_plugin_ui.cc
index bf9bddf6cd..f83adef407 100644
--- a/gtk2_ardour/lv2_plugin_ui.cc
+++ b/gtk2_ardour/lv2_plugin_ui.cc
@@ -17,6 +17,8 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <gtkmm/stock.h>
+
#include "ardour/lv2_plugin.h"
#include "ardour/session.h"
#include "pbd/error.h"
@@ -114,6 +116,23 @@ LV2PluginUI::touch(void* controller,
}
}
+void
+LV2PluginUI::set_path_property (int response,
+ const ParameterDescriptor& desc,
+ Gtk::FileChooserDialog* widget)
+{
+ if (response == Gtk::RESPONSE_ACCEPT) {
+ plugin->set_property (desc.key, Variant (Variant::PATH, widget->get_filename()));
+ }
+#if 0
+ widget->hide ();
+ delete_when_idle (widget);
+#else
+ delete widget;
+#endif
+ active_parameter_requests.erase (desc.key);
+}
+
uint32_t
LV2PluginUI::request_parameter (void* handle, LV2_URID key)
{
@@ -122,35 +141,53 @@ LV2PluginUI::request_parameter (void* handle, LV2_URID key)
/* This will return `PropertyDescriptors nothing` when not found */
const ParameterDescriptor& desc (me->_lv2->get_property_descriptor(key));
if (desc.datatype != Variant::PATH) {
- return -1;
+ return 0;
}
- // TODO: check if window for current URID already exists -> return -1;
- // Create and show window, subscribe to file-selected signal
- // then return 0; don't block here.
+#if 0 // MODAL, blocking
- Gtk::FileChooserDialog lv2ui_file_dialog (desc.label, FILE_CHOOSER_ACTION_OPEN);
+ Gtk::FileChooserDialog* lv2ui_file_dialog (desc.label, FILE_CHOOSER_ACTION_OPEN);
Gtkmm2ext::add_volume_shortcuts (lv2ui_file_dialog);
+ lv2ui_file_dialog.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ lv2ui_file_dialog.add_button (Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
+ lv2ui_file_dialog.set_default_response(Gtk::RESPONSE_ACCEPT);
+ if (_file_dialog.run()= Gtk::RESPONSE_ACCEPT) {
+ me->plugin->set_property (desc.key, Variant(Variant::PATH, lv2ui_file_dialog.get_filename()));
+ }
+ return 0;
- /* LV2Plugin does not currently save property values and only
- * emits a PropertyChanged(urid, Variant) signal
- */
- //lv2ui_file_dialog.set_current_folder (TODO)
+#else
+
+ if (me->active_parameter_requests.find (key) != me->active_parameter_requests.end()) {
+ return 0; /* already showing dialog */
+ }
+ me->active_parameter_requests.insert (key);
+
+ Gtk::FileChooserDialog* lv2ui_file_dialog = new Gtk::FileChooserDialog(desc.label, FILE_CHOOSER_ACTION_OPEN);
+ Gtkmm2ext::add_volume_shortcuts (*lv2ui_file_dialog);
+ lv2ui_file_dialog->add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ lv2ui_file_dialog->add_button (Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
+ lv2ui_file_dialog->set_default_response(Gtk::RESPONSE_ACCEPT);
+
+ /* this assumes announce_property_values() was called, or
+ * the plugin has previously sent a patch:Set */
+ const Variant& value = me->_lv2->get_property_value (desc.key);
+ if (value.type() == Variant::PATH) {
+ lv2ui_file_dialog->set_filename (value.get_path());
+ }
-#if 0 // TODO mime-type,
+#if 0 // TODO mime-type, file-extension filter, get from LV2 Parameter Property
FileFilter file_ext_filter;
file_ext_filter.add_pattern ("*.foo");
file_ext_filter.set_name ("Foo File");
lv2ui_file_dialog.add_filter (file_ext_filter);
#endif
- int response = lv2ui_file_dialog.run();
- lv2ui_file_dialog.hide ();
-
- if (response == Gtk::RESPONSE_OK) {
- me->plugin->set_property (desc.key, Variant(Variant::PATH, lv2ui_file_dialog.get_filename()));
- }
+ lv2ui_file_dialog->signal_response().connect (sigc::bind (sigc::mem_fun (*me, &LV2PluginUI::set_path_property), desc, lv2ui_file_dialog));
+ lv2ui_file_dialog->present();
return 0;
+
+#endif
}
void