13
0

VST3: move runloop into backend (2/3) - remove UI code

This commit is contained in:
Robin Gareus 2024-06-13 21:05:59 +02:00
parent 816860e0f5
commit 01a0c2d111
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04

View File

@ -20,11 +20,6 @@
#include "gtk2ardour-config.h" #include "gtk2ardour-config.h"
#endif #endif
#include <boost/unordered_map.hpp>
#include <glibmm/main.h>
#include <glibmm/threads.h>
#include <gtkmm/socket.h> #include <gtkmm/socket.h>
#include "pbd/unwind.h" #include "pbd/unwind.h"
@ -41,149 +36,9 @@
using namespace ARDOUR; using namespace ARDOUR;
using namespace Steinberg; 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<FileDescriptor, EventHandler> _event_handlers;
boost::unordered_map<guint, Linux::ITimerHandler*> _timer_handlers;
static gboolean event (GIOChannel* source, GIOCondition condition, gpointer data)
{
Linux::IEventHandler* handler = reinterpret_cast<Linux::IEventHandler*> (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<Linux::ITimerHandler*> (data);
handler->onTimer ();
return true;
}
public:
~VST3X11Runloop ()
{
clear ();
}
void clear () {
Glib::Threads::Mutex::Lock lm (_lock);
for (boost::unordered_map<FileDescriptor, EventHandler>::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<guint, Linux::ITimerHandler*>::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<FileDescriptor, EventHandler>::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<guint, Linux::ITimerHandler*>::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<PlugInsertBase> pib, std::shared_ptr<VST3Plugin> vst3) VST3X11PluginUI::VST3X11PluginUI (std::shared_ptr<PlugInsertBase> pib, std::shared_ptr<VST3Plugin> vst3)
: VST3PluginUI (pib, vst3) : VST3PluginUI (pib, vst3)
//, _runloop (new VST3X11Runloop)
{ {
_vst3->set_runloop (&static_runloop);
pack_start (_gui_widget, true, true); pack_start (_gui_widget, true, true);
_gui_widget.signal_realize().connect (mem_fun (this, &VST3X11PluginUI::view_realized)); _gui_widget.signal_realize().connect (mem_fun (this, &VST3X11PluginUI::view_realized));