From e7032972a234ef8dab18e2115abc6f6d48d32016 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 3 Feb 2011 03:26:39 +0000 Subject: [PATCH] register foreign LV2 external UI threads with GUI to avoid crashing when they try to notify ardour's GUI thread of parameter changes git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@8685 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/lv2_plugin_ui.cc | 17 +++++++++++++++-- gtk2_ardour/lv2_plugin_ui.h | 4 ++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/gtk2_ardour/lv2_plugin_ui.cc b/gtk2_ardour/lv2_plugin_ui.cc index 5c93aa0d59..de37185198 100644 --- a/gtk2_ardour/lv2_plugin_ui.cc +++ b/gtk2_ardour/lv2_plugin_ui.cc @@ -18,9 +18,13 @@ */ +#include + #include #include +#include + #include "ardour_ui.h" #include "lv2_plugin_ui.h" #include "gui_thread.h" @@ -36,10 +40,18 @@ LV2PluginUI::lv2_ui_write(LV2UI_Controller controller, uint32_t format, const void* buffer) { - //cout << "lv2_ui_write" << endl; LV2PluginUI* me = (LV2PluginUI*)controller; + + cout << "lv2_ui_write, thread registered ? " << me->_thread_registered << endl; + + if (!me->_thread_registered && !Gtkmm2ext::UI::instance()->caller_is_ui_thread()) { + cerr << "Registering LV2 external thread " << pthread_self() << endl; + PBD::notify_gui_about_thread_creation (pthread_self(), me->_lv2->name()); + me->_thread_registered = true; + } + if (*(float*)buffer != me->_values[port_index]) { - //cout << "set_parameter " << port_index << ":" << *(float*)buffer << endl; + cout << "set_parameter " << port_index << ":" << *(float*)buffer << endl; me->_lv2->set_parameter(port_index, *(float*)buffer); } } @@ -123,6 +135,7 @@ LV2PluginUI::output_update() LV2PluginUI::LV2PluginUI (boost::shared_ptr pi, boost::shared_ptr lv2p) : PlugUIBase (pi) , _lv2(lv2p) + , _thread_registered (false) , _inst(NULL) , _values(NULL) , _external_ui_ptr(NULL) diff --git a/gtk2_ardour/lv2_plugin_ui.h b/gtk2_ardour/lv2_plugin_ui.h index 9bb1fe60ae..9400aa6a00 100644 --- a/gtk2_ardour/lv2_plugin_ui.h +++ b/gtk2_ardour/lv2_plugin_ui.h @@ -58,11 +58,11 @@ class LV2PluginUI : public PlugUIBase, public Gtk::VBox boost::shared_ptr _lv2; std::vector _output_ports; sigc::connection _screen_update_connection; - + bool _thread_registered; Gtk::Widget* _gui_widget; SLV2UIInstance _inst; float* _values; - + struct lv2_external_ui_host _external_ui_host; LV2_Feature _external_ui_feature; struct lv2_external_ui* _external_ui_ptr;