From 01a0c2d111adc6ba434b9ef35f02f31aba538f91 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 13 Jun 2024 21:05:59 +0200 Subject: [PATCH] VST3: move runloop into backend (2/3) - remove UI code --- gtk2_ardour/vst3_x11_plugin_ui.cc | 145 ------------------------------ 1 file changed, 145 deletions(-) diff --git a/gtk2_ardour/vst3_x11_plugin_ui.cc b/gtk2_ardour/vst3_x11_plugin_ui.cc index 2b79d85583..ee54c2d0d6 100644 --- a/gtk2_ardour/vst3_x11_plugin_ui.cc +++ b/gtk2_ardour/vst3_x11_plugin_ui.cc @@ -20,11 +20,6 @@ #include "gtk2ardour-config.h" #endif -#include - -#include -#include - #include #include "pbd/unwind.h" @@ -41,149 +36,9 @@ using namespace ARDOUR; using namespace Steinberg; -class VST3X11Runloop : public Linux::IRunLoop -{ -private: - struct EventHandler - { - EventHandler (Linux::IEventHandler* handler = 0, GIOChannel* gio_channel = 0, guint source_id = 0) - : _handler (handler) - , _gio_channel (gio_channel) - , _source_id (source_id) - {} - - bool operator== (EventHandler const& other) { - return other._handler == _handler && other._gio_channel == _gio_channel && other._source_id == _source_id; - } - Linux::IEventHandler* _handler; - GIOChannel* _gio_channel; - guint _source_id; - }; - - boost::unordered_map _event_handlers; - boost::unordered_map _timer_handlers; - - static gboolean event (GIOChannel* source, GIOCondition condition, gpointer data) - { - Linux::IEventHandler* handler = reinterpret_cast (data); - handler->onFDIsSet (g_io_channel_unix_get_fd (source)); - if (condition & ~G_IO_IN) { - /* remove on error */ - return false; - } else { - return true; - } - } - - static gboolean timeout (gpointer data) - { - Linux::ITimerHandler* handler = reinterpret_cast (data); - handler->onTimer (); - return true; - } - -public: - ~VST3X11Runloop () - { - clear (); - } - - void clear () { - Glib::Threads::Mutex::Lock lm (_lock); - for (boost::unordered_map::const_iterator it = _event_handlers.begin (); it != _event_handlers.end (); ++it) { - g_source_remove (it->second._source_id); - g_io_channel_unref (it->second._gio_channel); - } - for (boost::unordered_map::const_iterator it = _timer_handlers.begin (); it != _timer_handlers.end (); ++it) { - g_source_remove (it->first); - } - _event_handlers.clear (); - _timer_handlers.clear (); - } - - /* VST3 IRunLoop interface */ - tresult registerEventHandler (Linux::IEventHandler* handler, FileDescriptor fd) SMTG_OVERRIDE - { - if (!handler || _event_handlers.find(fd) != _event_handlers.end()) { - return kInvalidArgument; - } - - Glib::Threads::Mutex::Lock lm (_lock); - GIOChannel* gio_channel = g_io_channel_unix_new (fd); - guint id = g_io_add_watch (gio_channel, (GIOCondition) (G_IO_IN /*| G_IO_OUT*/ | G_IO_ERR | G_IO_HUP), event, handler); - _event_handlers[fd] = EventHandler (handler, gio_channel, id); - return kResultTrue; - } - - tresult unregisterEventHandler (Linux::IEventHandler* handler) SMTG_OVERRIDE - { - if (!handler) { - return kInvalidArgument; - } - - tresult rv = false; - Glib::Threads::Mutex::Lock lm (_lock); - for (boost::unordered_map::const_iterator it = _event_handlers.begin (); it != _event_handlers.end ();) { - if (it->second._handler == handler) { - g_source_remove (it->second._source_id); - g_io_channel_unref (it->second._gio_channel); - it = _event_handlers.erase (it); - rv = kResultTrue; - } else { - ++it; - } - } - return rv; - } - - tresult registerTimer (Linux::ITimerHandler* handler, TimerInterval milliseconds) SMTG_OVERRIDE - { - if (!handler || milliseconds == 0) { - return kInvalidArgument; - } - Glib::Threads::Mutex::Lock lm (_lock); - guint id = g_timeout_add_full (G_PRIORITY_HIGH_IDLE, milliseconds, timeout, handler, NULL); - _timer_handlers[id] = handler; - return kResultTrue; - - } - - tresult unregisterTimer (Linux::ITimerHandler* handler) SMTG_OVERRIDE - { - if (!handler) { - return kInvalidArgument; - } - - tresult rv = false; - Glib::Threads::Mutex::Lock lm (_lock); - for (boost::unordered_map::const_iterator it = _timer_handlers.begin (); it != _timer_handlers.end ();) { - if (it->second == handler) { - g_source_remove (it->first); - it = _timer_handlers.erase (it); - rv = kResultTrue; - } else { - ++it; - } - } - return rv; - } - - uint32 PLUGIN_API addRef () SMTG_OVERRIDE { return 1; } - uint32 PLUGIN_API release () SMTG_OVERRIDE { return 1; } - tresult queryInterface (const TUID, void**) SMTG_OVERRIDE { return kNoInterface; } - -private: - Glib::Threads::Mutex _lock; -}; - -VST3X11Runloop static_runloop; - VST3X11PluginUI::VST3X11PluginUI (std::shared_ptr pib, std::shared_ptr vst3) : VST3PluginUI (pib, vst3) - //, _runloop (new VST3X11Runloop) { - _vst3->set_runloop (&static_runloop); - pack_start (_gui_widget, true, true); _gui_widget.signal_realize().connect (mem_fun (this, &VST3X11PluginUI::view_realized));