2013-01-16 13:22:15 -05:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2013-2015 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2013-01-16 13:22:15 -05:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/******************************************************************/
|
|
|
|
/** VSTFX - An engine based on FST for handling linuxVST plugins **/
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <libgen.h>
|
2014-11-18 15:59:04 -05:00
|
|
|
#include <assert.h>
|
2011-09-20 16:29:47 -04:00
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
#include <glib.h>
|
2013-12-03 10:24:34 -05:00
|
|
|
#include <glibmm/timer.h>
|
2011-09-20 16:29:47 -04:00
|
|
|
|
2020-03-29 08:56:50 -04:00
|
|
|
#include "pbd/pthread_utils.h"
|
|
|
|
|
2011-11-23 14:31:04 -05:00
|
|
|
#include "ardour/linux_vst_support.h"
|
2017-03-07 12:38:01 -05:00
|
|
|
#include "ardour/vst_plugin.h"
|
2011-09-20 16:29:47 -04:00
|
|
|
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
2014-04-21 08:44:36 -04:00
|
|
|
#include <sys/time.h>
|
2011-09-20 16:29:47 -04:00
|
|
|
|
|
|
|
struct ERect{
|
|
|
|
short top;
|
|
|
|
short left;
|
|
|
|
short bottom;
|
|
|
|
short right;
|
|
|
|
};
|
|
|
|
|
|
|
|
static pthread_mutex_t plugin_mutex;
|
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
static VSTState * vstfx_first = NULL;
|
2011-09-20 16:29:47 -04:00
|
|
|
|
|
|
|
const char magic[] = "VSTFX Plugin State v002";
|
|
|
|
|
2024-08-27 22:10:41 -04:00
|
|
|
static volatile int gui_state = -1;
|
2011-09-20 16:29:47 -04:00
|
|
|
|
|
|
|
/*This will be our connection to X*/
|
|
|
|
|
2015-12-30 07:51:09 -05:00
|
|
|
static Display* LXVST_XDisplay = NULL;
|
2011-09-20 16:29:47 -04:00
|
|
|
|
|
|
|
/*The thread handle for the GUI event loop*/
|
|
|
|
|
2015-12-30 07:51:09 -05:00
|
|
|
static pthread_t LXVST_gui_event_thread;
|
2011-09-20 16:29:47 -04:00
|
|
|
|
|
|
|
/*Util functions to get the value of a property attached to an XWindow*/
|
|
|
|
|
2015-12-30 07:51:09 -05:00
|
|
|
static bool LXVST_xerror;
|
2011-09-20 16:29:47 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
int TempErrorHandler (Display *display, XErrorEvent *e)
|
2011-09-20 16:29:47 -04:00
|
|
|
{
|
|
|
|
LXVST_xerror = true;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef LXVST_32BIT
|
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
int getXWindowProperty (Window window, Atom atom)
|
2011-09-20 16:29:47 -04:00
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
int userSize;
|
|
|
|
unsigned long bytes;
|
|
|
|
unsigned long userCount;
|
|
|
|
unsigned char *data;
|
2019-04-13 11:48:27 -04:00
|
|
|
Atom userType;
|
2011-09-20 16:29:47 -04:00
|
|
|
LXVST_xerror = false;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*Use our own Xerror handler while we're in here - in an
|
|
|
|
attempt to stop the brain dead default Xerror behaviour of
|
|
|
|
qutting the entire application because of e.g. an invalid
|
|
|
|
window ID*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
XErrorHandler olderrorhandler = XSetErrorHandler (TempErrorHandler);
|
|
|
|
|
|
|
|
XGetWindowProperty (LXVST_XDisplay, // The display
|
|
|
|
window, // The Window
|
|
|
|
atom, // The property
|
|
|
|
0, // Offset into the data
|
|
|
|
1, // Number of 32Bit chunks of data
|
|
|
|
false, // false = don't delete the property
|
|
|
|
AnyPropertyType, // Required property type mask
|
|
|
|
&userType, // Actual type returned
|
|
|
|
&userSize, // Actual format returned
|
|
|
|
&userCount, // Actual number of items stored in the returned data
|
|
|
|
&bytes, // Number of bytes remaining if a partial read
|
|
|
|
&data); // The actual data read
|
|
|
|
|
|
|
|
if (LXVST_xerror == false && userCount == 1) {
|
|
|
|
result = *(int*)data;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
XSetErrorHandler (olderrorhandler);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*Hopefully this will return zero if the property is not set*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef LXVST_64BIT
|
|
|
|
|
|
|
|
/********************************************************************/
|
|
|
|
/* This is untested - have no 64Bit plugins which use this */
|
|
|
|
/* system of passing an eventProc address */
|
|
|
|
/********************************************************************/
|
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
long getXWindowProperty (Window window, Atom atom)
|
2011-09-20 16:29:47 -04:00
|
|
|
{
|
|
|
|
long result = 0;
|
|
|
|
int userSize;
|
|
|
|
unsigned long bytes;
|
|
|
|
unsigned long userCount;
|
|
|
|
unsigned char *data;
|
2019-04-13 11:48:27 -04:00
|
|
|
Atom userType;
|
2011-09-20 16:29:47 -04:00
|
|
|
LXVST_xerror = false;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*Use our own Xerror handler while we're in here - in an
|
2019-04-13 11:48:27 -04:00
|
|
|
* attempt to stop the brain dead default Xerror behaviour of
|
|
|
|
* qutting the entire application because of e.g. an invalid
|
|
|
|
* window ID
|
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
XErrorHandler olderrorhandler = XSetErrorHandler (TempErrorHandler);
|
|
|
|
|
|
|
|
XGetWindowProperty (LXVST_XDisplay,
|
|
|
|
window,
|
|
|
|
atom,
|
|
|
|
0,
|
|
|
|
2,
|
|
|
|
false,
|
|
|
|
AnyPropertyType,
|
|
|
|
&userType,
|
|
|
|
&userSize,
|
|
|
|
&userCount,
|
|
|
|
&bytes,
|
|
|
|
&data);
|
|
|
|
|
|
|
|
if (LXVST_xerror == false && userCount == 1) {
|
|
|
|
result = *(long*)data;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
XSetErrorHandler (olderrorhandler);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*Hopefully this will return zero if the property is not set*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*The event handler - called from within the main GUI thread to
|
|
|
|
dispatch events to any VST UIs which have callbacks stuck to them*/
|
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
static void
|
|
|
|
dispatch_x_events (XEvent* event, VSTState* vstfx)
|
2011-09-20 16:29:47 -04:00
|
|
|
{
|
|
|
|
/*Handle some of the Events we might be interested in*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
switch (event->type)
|
2011-09-20 16:29:47 -04:00
|
|
|
{
|
|
|
|
/*Configure event - when the window is resized or first drawn*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
case ConfigureNotify:
|
|
|
|
{
|
|
|
|
Window window = event->xconfigure.event;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
int width = event->xconfigure.width;
|
|
|
|
int height = event->xconfigure.height;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-07 12:38:01 -05:00
|
|
|
/* If we get a config notify on the parent window XID then we need to see
|
|
|
|
* if the size has been changed - some plugins re-size their UI window e.g.
|
|
|
|
* when opening a preset manager.
|
|
|
|
*
|
|
|
|
* if the size has changed, we flag this so that in lxvst_pluginui.cc
|
|
|
|
* we can make the change to the GTK parent window in ardour, from its UI thread */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
if (window == (Window) (vstfx->linux_window)) {
|
2017-03-07 12:38:01 -05:00
|
|
|
#ifndef NDEBUG
|
2019-04-13 11:48:27 -04:00
|
|
|
printf ("dispatch_x_events: ConfigureNotify cfg: (%d %d) plugin: (%d %d)\n",
|
2017-03-07 12:38:01 -05:00
|
|
|
width, height,
|
|
|
|
vstfx->width, vstfx->height
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
if (width != vstfx->width || height != vstfx->height) {
|
2011-09-20 16:29:47 -04:00
|
|
|
vstfx->width = width;
|
|
|
|
vstfx->height = height;
|
2017-07-08 12:13:42 -04:00
|
|
|
ARDOUR::VSTPlugin* plug = (ARDOUR::VSTPlugin *)(vstfx->plugin->ptr1);
|
2017-03-07 12:38:01 -05:00
|
|
|
plug->VSTSizeWindow (); /* EMIT SIGNAL */
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-07 12:38:01 -05:00
|
|
|
/* QUIRK : Loomer plugins not only resize the UI but throw it into some random
|
|
|
|
* position at the same time. We need to re-position the window at the origin of
|
|
|
|
* the parent window*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-07 12:38:01 -05:00
|
|
|
if (vstfx->linux_plugin_ui_window) {
|
|
|
|
XMoveWindow (LXVST_XDisplay, vstfx->linux_plugin_ui_window, 0, 0);
|
2011-09-20 16:29:47 -04:00
|
|
|
}
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
break;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*Reparent Notify - when the plugin UI is reparented into
|
|
|
|
our Host Window we will get an event here... probably... */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
case ReparentNotify:
|
|
|
|
{
|
|
|
|
Window ParentWindow = event->xreparent.parent;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*If the ParentWindow matches the window for the vstfx instance then
|
|
|
|
the Child window must be the XID of the pluginUI window created by the
|
|
|
|
plugin, so we need to see if it has a callback stuck to it, and if so
|
|
|
|
set that up in the vstfx */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/***********************************************************/
|
|
|
|
/* 64Bit --- This mechanism is not 64Bit compatible at the */
|
|
|
|
/* present time */
|
|
|
|
/***********************************************************/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
if (ParentWindow == (Window) (vstfx->linux_window)) {
|
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
Window PluginUIWindowID = event->xreparent.window;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
vstfx->linux_plugin_ui_window = PluginUIWindowID;
|
2011-09-20 16:29:47 -04:00
|
|
|
#ifdef LXVST_32BIT
|
2019-04-13 11:48:27 -04:00
|
|
|
int result = getXWindowProperty (PluginUIWindowID, XInternAtom (LXVST_XDisplay, "_XEventProc", false));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
if (result == 0) {
|
2011-09-20 16:29:47 -04:00
|
|
|
vstfx->eventProc = NULL;
|
2011-11-21 21:27:26 -05:00
|
|
|
} else {
|
2011-09-20 16:29:47 -04:00
|
|
|
vstfx->eventProc = (void (*) (void* event))result;
|
2011-11-21 21:27:26 -05:00
|
|
|
}
|
2011-09-20 16:29:47 -04:00
|
|
|
#endif
|
|
|
|
#ifdef LXVST_64BIT
|
2019-04-13 11:48:27 -04:00
|
|
|
long result = getXWindowProperty (PluginUIWindowID, XInternAtom (LXVST_XDisplay, "_XEventProc", false));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
if (result == 0) {
|
2011-09-20 16:29:47 -04:00
|
|
|
vstfx->eventProc = NULL;
|
2019-04-13 11:48:27 -04:00
|
|
|
} else {
|
2011-09-20 16:29:47 -04:00
|
|
|
vstfx->eventProc = (void (*) (void* event))result;
|
2019-04-13 11:48:27 -04:00
|
|
|
}
|
2011-09-20 16:29:47 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
case ClientMessage:
|
|
|
|
{
|
|
|
|
Window window = event->xany.window;
|
|
|
|
Atom message_type = event->xclient.message_type;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*The only client message we are interested in is to signal
|
|
|
|
that the plugin parent window is now valid and can be passed
|
|
|
|
to effEditOpen when the editor is launched*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
if (window == (Window) (vstfx->linux_window)) {
|
2019-04-13 11:48:27 -04:00
|
|
|
char* message = XGetAtomName (LXVST_XDisplay, message_type);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
if (strcmp (message,"LaunchEditor") == 0) {
|
2011-11-21 21:27:26 -05:00
|
|
|
if (event->xclient.data.l[0] == 0x0FEEDBAC) {
|
|
|
|
vstfx_launch_editor (vstfx);
|
|
|
|
}
|
2011-09-20 16:29:47 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
XFree (message);
|
2011-09-20 16:29:47 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/* Some VSTs built with toolkits e.g. JUCE will manager their own UI
|
|
|
|
autonomously in the plugin, running the UI in its own thread, so once
|
|
|
|
we have created a parent window for the plugin, its UI takes care of
|
|
|
|
itself.*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*Other types register a callback as an Xwindow property on the plugin
|
|
|
|
UI window after they create it. If that is the case, we need to call it
|
|
|
|
here, passing the XEvent into it*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
if (vstfx->eventProc == NULL) {
|
2011-09-20 16:29:47 -04:00
|
|
|
return;
|
2011-11-21 21:27:26 -05:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
vstfx->eventProc ((void*)event);
|
2011-09-20 16:29:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** This is the main gui event loop for the plugin, we also need to pass
|
|
|
|
any Xevents to all the UI callbacks plugins 'may' have registered on their
|
|
|
|
windows, that is if they don't manage their own UIs **/
|
|
|
|
|
2020-01-01 15:56:12 -05:00
|
|
|
static void*
|
2024-09-27 17:03:26 -04:00
|
|
|
gui_event_loop (void*)
|
2011-09-20 16:29:47 -04:00
|
|
|
{
|
2011-11-21 21:27:26 -05:00
|
|
|
VSTState* vstfx;
|
2014-04-21 08:44:36 -04:00
|
|
|
int LXVST_sched_timer_interval = 40; //ms, 25fps
|
2011-09-20 16:29:47 -04:00
|
|
|
XEvent event;
|
2014-05-16 12:13:08 -04:00
|
|
|
uint64_t clock1, clock2;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-05-16 12:13:08 -04:00
|
|
|
clock1 = g_get_monotonic_time();
|
2011-09-20 16:29:47 -04:00
|
|
|
/*The 'Forever' loop - runs the plugin UIs etc - based on the FST gui event loop*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2024-08-27 22:10:41 -04:00
|
|
|
while (gui_state == 0)
|
2011-09-20 16:29:47 -04:00
|
|
|
{
|
2015-10-04 14:51:05 -04:00
|
|
|
/* handle window creation requests, destroy requests,
|
2011-09-20 16:29:47 -04:00
|
|
|
and run idle callbacks */
|
|
|
|
|
|
|
|
/*Look at the XEvent queue - if there are any XEvents we need to handle them,
|
|
|
|
including passing them to all the plugin (eventProcs) we are currently managing*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2015-05-27 17:16:59 -04:00
|
|
|
bool may_sleep = true;
|
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
if (LXVST_XDisplay) {
|
2011-09-20 16:29:47 -04:00
|
|
|
/*See if there are any events in the queue*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
int num_events = XPending (LXVST_XDisplay);
|
2015-05-27 17:16:59 -04:00
|
|
|
|
|
|
|
if (num_events > 0) {
|
|
|
|
// keep dispatching events as fast as possible
|
|
|
|
may_sleep = false;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*process them if there are any*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
while (num_events) {
|
|
|
|
XNextEvent (LXVST_XDisplay, &event);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*Call dispatch events, with the event, for each plugin in the linked list*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
for (vstfx = vstfx_first; vstfx; vstfx = vstfx->next) {
|
|
|
|
pthread_mutex_lock (&vstfx->lock);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
dispatch_x_events (&event, vstfx);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
pthread_mutex_unlock (&vstfx->lock);
|
2011-09-20 16:29:47 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
num_events--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*We don't want to use all the CPU.. */
|
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
Glib::usleep (1000);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*See if its time for us to do a scheduled event pass on all the plugins*/
|
|
|
|
|
2014-05-16 12:13:08 -04:00
|
|
|
clock2 = g_get_monotonic_time();
|
|
|
|
const int64_t elapsed_time_ms = (clock2 - clock1) / 1000;
|
2014-04-21 08:44:36 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
if ((LXVST_sched_timer_interval != 0) && elapsed_time_ms >= LXVST_sched_timer_interval) {
|
|
|
|
//printf ("elapsed %d ms ^= %.2f Hz\n", elapsed_time_ms, 1000.0/ (double)elapsed_time_ms); // DEBUG
|
2011-09-20 16:29:47 -04:00
|
|
|
pthread_mutex_lock (&plugin_mutex);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
again:
|
|
|
|
/*Parse through the linked list of plugins*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
for (vstfx = vstfx_first; vstfx; vstfx = vstfx->next)
|
2015-10-05 10:17:49 -04:00
|
|
|
{
|
2011-09-20 16:29:47 -04:00
|
|
|
pthread_mutex_lock (&vstfx->lock);
|
|
|
|
|
|
|
|
/*Window scheduled for destruction*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
if (vstfx->destroy) {
|
|
|
|
if (vstfx->linux_window) {
|
|
|
|
vstfx->plugin->dispatcher (vstfx->plugin, effEditClose, 0, 0, NULL, 0.0);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
XDestroyWindow (LXVST_XDisplay, vstfx->linux_window);
|
|
|
|
/* FIXME - probably safe to assume we never have an XID of 0 but not explicitly true */
|
|
|
|
vstfx->linux_window = 0;
|
2011-09-20 16:29:47 -04:00
|
|
|
vstfx->destroy = FALSE;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
vstfx_event_loop_remove_plugin (vstfx);
|
|
|
|
vstfx->been_activated = FALSE;
|
|
|
|
pthread_cond_signal (&vstfx->window_status_change);
|
|
|
|
pthread_mutex_unlock (&vstfx->lock);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
goto again;
|
2015-10-04 14:51:05 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*Window does not yet exist - scheduled for creation*/
|
2011-11-21 21:27:26 -05:00
|
|
|
|
|
|
|
/* FIXME - probably safe to assume 0 is not a valid XID but not explicitly true */
|
|
|
|
if (vstfx->linux_window == 0) {
|
|
|
|
if (vstfx_create_editor (vstfx)) {
|
2011-09-20 16:29:47 -04:00
|
|
|
vstfx_error ("** ERROR ** VSTFX : Cannot create editor for plugin %s", vstfx->handle->name);
|
|
|
|
vstfx_event_loop_remove_plugin (vstfx);
|
|
|
|
pthread_cond_signal (&vstfx->window_status_change);
|
|
|
|
pthread_mutex_unlock (&vstfx->lock);
|
|
|
|
goto again;
|
2011-11-21 21:27:26 -05:00
|
|
|
} else {
|
2019-04-13 11:48:27 -04:00
|
|
|
/* condition/unlock: it was signalled & unlocked in fst_create_editor() */
|
2011-09-20 16:29:47 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-15 11:07:55 -05:00
|
|
|
vststate_maybe_set_program (vstfx);
|
2011-11-23 14:29:55 -05:00
|
|
|
vstfx->want_program = -1;
|
|
|
|
vstfx->want_chunk = 0;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*scheduled call to dispatcher*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-15 16:06:15 -05:00
|
|
|
if (vstfx->dispatcher_wantcall) {
|
|
|
|
vstfx->dispatcher_retval = vstfx->plugin->dispatcher (
|
2015-10-04 14:51:05 -04:00
|
|
|
vstfx->plugin,
|
2011-11-15 16:06:15 -05:00
|
|
|
vstfx->dispatcher_opcode,
|
|
|
|
vstfx->dispatcher_index,
|
|
|
|
vstfx->dispatcher_val,
|
|
|
|
vstfx->dispatcher_ptr,
|
|
|
|
vstfx->dispatcher_opt
|
|
|
|
);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-15 16:06:15 -05:00
|
|
|
vstfx->dispatcher_wantcall = 0;
|
2011-09-20 16:29:47 -04:00
|
|
|
pthread_cond_signal (&vstfx->plugin_dispatcher_called);
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*Call the editor Idle function in the plugin*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2020-11-13 20:49:24 -05:00
|
|
|
if(vstfx->been_activated) {
|
|
|
|
/* some plugins have issues if effEditIdle is called w/o an editor.
|
|
|
|
* This may happen due to async X11 requests, delaying the call to effEditOpen.
|
|
|
|
*/
|
|
|
|
vstfx->plugin->dispatcher (vstfx->plugin, effEditIdle, 0, 0, NULL, 0);
|
|
|
|
}
|
2011-09-20 16:29:47 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
if (vstfx->wantIdle) {
|
2011-09-20 16:29:47 -04:00
|
|
|
vstfx->plugin->dispatcher (vstfx->plugin, 53, 0, 0, NULL, 0);
|
2019-04-13 11:48:27 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
pthread_mutex_unlock (&vstfx->lock);
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock (&plugin_mutex);
|
2014-04-21 08:44:36 -04:00
|
|
|
|
2014-05-16 12:13:08 -04:00
|
|
|
clock1 = g_get_monotonic_time();
|
2011-09-20 16:29:47 -04:00
|
|
|
}
|
2015-05-27 17:16:59 -04:00
|
|
|
|
2024-08-27 22:10:41 -04:00
|
|
|
if (0 == gui_state && may_sleep && elapsed_time_ms + 1 < LXVST_sched_timer_interval) {
|
2019-04-13 11:48:27 -04:00
|
|
|
Glib::usleep (1000 * (LXVST_sched_timer_interval - elapsed_time_ms - 1));
|
2015-05-27 17:16:59 -04:00
|
|
|
}
|
2011-09-20 16:29:47 -04:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:15:30 -05:00
|
|
|
if (LXVST_XDisplay) {
|
2019-04-13 11:48:27 -04:00
|
|
|
XCloseDisplay (LXVST_XDisplay);
|
2017-03-05 16:15:30 -05:00
|
|
|
LXVST_XDisplay = 0;
|
|
|
|
}
|
2017-03-05 16:14:49 -05:00
|
|
|
|
|
|
|
/* some plugin UIs (looking at you, u-he^abique), do set thread-keys
|
|
|
|
* and free, but not unset them.
|
|
|
|
*
|
|
|
|
* This leads to a double-free in __nptl_deallocate_tsd
|
|
|
|
* nptl/pthread_create.c:175 __pthread_keys[idx].destr (data);
|
|
|
|
* when the event-loop thread is joined.
|
|
|
|
*
|
|
|
|
* This workaround is dedicated to all the plugin-UI-devs
|
|
|
|
* who think their UI owns the complete process memory-space.
|
|
|
|
*
|
|
|
|
* NB. ardour itself does not use thread-keys for the
|
|
|
|
* VST event-loop thread, and anyway, this thread is joined
|
|
|
|
* only when ardour exit()s. If this would result in a leak,
|
|
|
|
* nobody will care.
|
|
|
|
*/
|
|
|
|
if (!getenv ("ARDOUR_RUNNING_UNDER_VALGRIND")) {
|
|
|
|
for (pthread_key_t i = 0; i < PTHREAD_KEYS_MAX; ++i) {
|
|
|
|
if (pthread_getspecific (i)) {
|
|
|
|
pthread_setspecific (i, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-20 16:29:47 -04:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*The VSTFX Init function - this needs to be called before the VSTFX engine
|
|
|
|
can be accessed, it gets the UI thread running, opens a connection to X etc
|
|
|
|
normally started in globals.cc*/
|
|
|
|
|
|
|
|
int vstfx_init (void* ptr)
|
|
|
|
{
|
2024-08-27 22:10:41 -04:00
|
|
|
assert (gui_state == -1);
|
2016-04-27 17:33:28 -04:00
|
|
|
pthread_mutex_init (&plugin_mutex, NULL);
|
2011-09-20 16:29:47 -04:00
|
|
|
|
|
|
|
/*This is where we need to open a connection to X, and start the GUI thread*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*Open our connection to X - all linuxVST plugin UIs handled by the LXVST engine
|
|
|
|
will talk to X down this connection - X cannot handle multi-threaded access via
|
|
|
|
the same Display* */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
if (LXVST_XDisplay == NULL) {
|
|
|
|
LXVST_XDisplay = XOpenDisplay (NULL); //We might be able to make this open a specific screen etc
|
|
|
|
}
|
2011-09-20 16:29:47 -04:00
|
|
|
|
|
|
|
/*Drop out and report the error if we fail to connect to X */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
if (LXVST_XDisplay == NULL) {
|
2011-09-20 16:29:47 -04:00
|
|
|
vstfx_error ("** ERROR ** VSTFX: Failed opening connection to X");
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
return -1;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*We have a connection to X - so start the gui event loop*/
|
2024-08-27 22:10:41 -04:00
|
|
|
gui_state = 0;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*Create the thread - use default attrs for now, don't think we need anything special*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2024-09-27 17:03:26 -04:00
|
|
|
int thread_create_result = pthread_create_and_store ("LXVSTEventLoop", &LXVST_gui_event_thread, gui_event_loop, NULL, 0);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
if (thread_create_result != 0)
|
2011-09-20 16:29:47 -04:00
|
|
|
{
|
|
|
|
/*There was a problem starting the GUI event thread*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
vstfx_error ("** ERROR ** VSTFX: Failed starting GUI event thread");
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
XCloseDisplay (LXVST_XDisplay);
|
2017-03-05 16:15:30 -05:00
|
|
|
LXVST_XDisplay = 0;
|
2024-08-27 22:10:41 -04:00
|
|
|
gui_state = 1;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
return -1;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*The vstfx Quit function*/
|
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
void vstfx_exit ()
|
2011-09-20 16:29:47 -04:00
|
|
|
{
|
2024-08-27 22:10:41 -04:00
|
|
|
if (gui_state) {
|
2015-12-30 07:51:09 -05:00
|
|
|
return;
|
|
|
|
}
|
2024-08-27 22:10:41 -04:00
|
|
|
gui_state = 1;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*We need to pthread_join the gui_thread here so
|
|
|
|
we know when it has stopped*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
pthread_join(LXVST_gui_event_thread, NULL);
|
2016-04-27 17:33:28 -04:00
|
|
|
pthread_mutex_destroy (&plugin_mutex);
|
2011-09-20 16:29:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Adds a new plugin (VSTFX) instance to the linked list*/
|
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
int vstfx_run_editor (VSTState* vstfx)
|
2011-09-20 16:29:47 -04:00
|
|
|
{
|
|
|
|
pthread_mutex_lock (&plugin_mutex);
|
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
/* Add the new VSTFX instance to the linked list */
|
2011-09-20 16:29:47 -04:00
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
if (vstfx_first == NULL) {
|
2011-09-20 16:29:47 -04:00
|
|
|
vstfx_first = vstfx;
|
2011-11-21 21:27:26 -05:00
|
|
|
} else {
|
|
|
|
VSTState* p = vstfx_first;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
while (p->next) {
|
2011-09-20 16:29:47 -04:00
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
p->next = vstfx;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
/* Mark the new end of the list */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
vstfx->next = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_unlock (&plugin_mutex);
|
|
|
|
|
|
|
|
/* wait for the plugin editor window to be created (or not) */
|
|
|
|
|
|
|
|
pthread_mutex_lock (&vstfx->lock);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
if (!vstfx->linux_window) {
|
2011-09-20 16:29:47 -04:00
|
|
|
pthread_cond_wait (&vstfx->window_status_change, &vstfx->lock);
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
pthread_mutex_unlock (&vstfx->lock);
|
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
if (!vstfx->linux_window) {
|
2011-09-20 16:29:47 -04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*Creates an editor for the plugin - normally called from within the gui event loop
|
|
|
|
after run_editor has added the plugin (editor) to the linked list*/
|
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
int vstfx_create_editor (VSTState* vstfx)
|
2011-09-20 16:29:47 -04:00
|
|
|
{
|
|
|
|
Window parent_window;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
int x_size = 1;
|
|
|
|
int y_size = 1;
|
|
|
|
|
2020-01-01 15:56:12 -05:00
|
|
|
if (!LXVST_XDisplay) {
|
|
|
|
vstfx_error ("** ERROR ** VSTFX: No X11 Display available for plugin UI");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/* Note: vstfx->lock is held while this function is called */
|
|
|
|
|
|
|
|
if (!(vstfx->plugin->flags & effFlagsHasEditor))
|
|
|
|
{
|
|
|
|
vstfx_error ("** ERROR ** VSTFX: Plugin \"%s\" has no editor", vstfx->handle->name);
|
|
|
|
return -1;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*Create an XWindow for the plugin to inhabit*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-15 16:06:15 -05:00
|
|
|
parent_window = XCreateSimpleWindow (
|
|
|
|
LXVST_XDisplay,
|
|
|
|
DefaultRootWindow(LXVST_XDisplay),
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
x_size,
|
|
|
|
y_size,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*Select the events we are interested in receiving - we need Substructure notify so that
|
|
|
|
if the plugin resizes its window - e.g. Loomer Manifold then we get a message*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
XSelectInput(LXVST_XDisplay,
|
2011-09-20 16:29:47 -04:00
|
|
|
parent_window,
|
|
|
|
SubstructureNotifyMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | ExposureMask);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
vstfx->linux_window = parent_window;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
vstfx->xid = parent_window; //vstfx->xid will be referenced to connect to GTK UI in ardour later
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*Because the plugin may be operating on a different Display* to us, and therefore
|
|
|
|
the two event queues can be asynchronous, although we have created the window on
|
|
|
|
our display, we can't guarantee it exists in the server yet, which will
|
|
|
|
cause BadWindow crashes if the plugin tries to use it.
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
It would be nice to use CreateNotify events here, but they don't get
|
|
|
|
through on all window managers, so instead we pass a client message
|
|
|
|
into out queue, after the XCreateWindow. When this message pops out
|
|
|
|
in our event handler, it will trigger the second stage of plugin
|
|
|
|
Editor instantiation, and by then the Window should be valid...*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
XClientMessageEvent event;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*Create an atom to identify our message (only if it doesn't already exist)*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
Atom WindowActiveAtom = XInternAtom(LXVST_XDisplay, "LaunchEditor", false);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
event.type = ClientMessage;
|
|
|
|
event.send_event = true;
|
|
|
|
event.window = parent_window;
|
|
|
|
event.message_type = WindowActiveAtom;
|
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
event.format = 32; //Data format
|
|
|
|
event.data.l[0] = 0x0FEEDBAC; //Something we can recognize later
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*Push the event into the queue on our Display*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
XSendEvent(LXVST_XDisplay, parent_window, FALSE, NoEventMask, (XEvent*)&event);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
int
|
|
|
|
vstfx_launch_editor (VSTState* vstfx)
|
2011-09-20 16:29:47 -04:00
|
|
|
{
|
|
|
|
/*This is the second stage of launching the editor (see vstfx_create editor)
|
|
|
|
we get called here in response to receiving the ClientMessage on our Window,
|
|
|
|
therefore it's about as safe (as can be) to assume that the Window we created
|
|
|
|
is now valid in the XServer and can be passed to the plugin in effEditOpen
|
|
|
|
without generating BadWindow errors when the plugin reparents itself into our
|
|
|
|
parent window*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
if(vstfx->been_activated)
|
|
|
|
return 0;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
Window parent_window;
|
2016-02-21 07:24:20 -05:00
|
|
|
struct ERect* er = NULL;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
int x_size = 1;
|
|
|
|
int y_size = 1;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
parent_window = vstfx->linux_window;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*Open the editor - Bah! we have to pass the int windowID as a void pointer - yuck
|
|
|
|
it gets cast back to an int as the parent window XID in the plugin - and we have to pass the
|
|
|
|
Display* as a long */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/**************************************************************/
|
|
|
|
/* 64Bit --- parent window is an int passed as a void* so */
|
|
|
|
/* that should be ok for 64Bit machines */
|
|
|
|
/* */
|
|
|
|
/* Display is passed in as a long - ok on arch's where sizeof */
|
|
|
|
/* long = 8 */
|
|
|
|
/* */
|
|
|
|
/* Most linux VST plugins open a connection to X on their own */
|
|
|
|
/* Display anyway so it may not matter */
|
|
|
|
/* */
|
|
|
|
/* linuxDSP VSTs don't use the host Display* at all */
|
|
|
|
/**************************************************************/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
vstfx->plugin->dispatcher (vstfx->plugin, effEditOpen, 0, (long)LXVST_XDisplay, (void*)(parent_window), 0);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*QUIRK - some plugins need a slight delay after opening the editor before you can
|
|
|
|
ask the window size or they might return zero - specifically discoDSP */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-12-03 10:24:34 -05:00
|
|
|
Glib::usleep(100000);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*Now we can find out how big the parent window should be (and try) to resize it*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
vstfx->plugin->dispatcher (vstfx->plugin, effEditGetRect, 0, 0, &er, 0);
|
2011-09-20 16:29:47 -04:00
|
|
|
|
2016-02-21 07:24:20 -05:00
|
|
|
if (er) {
|
|
|
|
// Don't crash is plugin does not implement effEditGetRect
|
|
|
|
// it'll result in 1x1 px window but that's not our problem :)
|
|
|
|
x_size = er->right - er->left;
|
|
|
|
y_size = er->bottom - er->top;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2016-02-21 07:24:20 -05:00
|
|
|
vstfx->width = x_size;
|
|
|
|
vstfx->height = y_size;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
XResizeWindow (LXVST_XDisplay, parent_window, x_size, y_size);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
XFlush (LXVST_XDisplay);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*Not sure if we need to map the window or if the plugin will do it for us
|
|
|
|
it should be ok because XReparentWindow generates a Map event*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
/*mark the editor as activated - mainly so that vstfx_get_XID
|
|
|
|
will know it is valid*/
|
|
|
|
|
|
|
|
vstfx->been_activated = TRUE;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-09-20 16:29:47 -04:00
|
|
|
pthread_cond_signal (&vstfx->window_status_change);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
/** Destroy the editor window */
|
|
|
|
void
|
|
|
|
vstfx_destroy_editor (VSTState* vstfx)
|
2011-09-20 16:29:47 -04:00
|
|
|
{
|
2024-08-27 23:14:41 -04:00
|
|
|
assert (0 == gui_state);
|
2011-09-20 16:29:47 -04:00
|
|
|
pthread_mutex_lock (&vstfx->lock);
|
2011-11-21 21:27:26 -05:00
|
|
|
if (vstfx->linux_window) {
|
2011-09-20 16:29:47 -04:00
|
|
|
vstfx->destroy = TRUE;
|
|
|
|
pthread_cond_wait (&vstfx->window_status_change, &vstfx->lock);
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock (&vstfx->lock);
|
|
|
|
}
|
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
/** Remove a vstfx instance from the linked list parsed by the
|
|
|
|
event loop
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
vstfx_event_loop_remove_plugin (VSTState* vstfx)
|
2011-09-20 16:29:47 -04:00
|
|
|
{
|
2011-11-21 21:27:26 -05:00
|
|
|
/* This only ever gets called from within our GUI thread
|
|
|
|
so we don't need to lock here - if we did there would be
|
|
|
|
a deadlock anyway
|
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
VSTState* p;
|
|
|
|
VSTState* prev;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
for (p = vstfx_first, prev = NULL; p; prev = p, p = p->next) {
|
|
|
|
if (p == vstfx) {
|
|
|
|
if (prev) {
|
2011-09-20 16:29:47 -04:00
|
|
|
prev->next = p->next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-18 15:59:04 -05:00
|
|
|
// if this function is called, there must be
|
|
|
|
// at least one plugin in the linked list
|
2019-04-13 11:48:27 -04:00
|
|
|
assert (vstfx_first);
|
2014-11-18 15:59:04 -05:00
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
if (vstfx_first == vstfx) {
|
2011-09-20 16:29:47 -04:00
|
|
|
vstfx_first = vstfx_first->next;
|
2011-11-21 21:27:26 -05:00
|
|
|
}
|
2011-09-20 16:29:47 -04:00
|
|
|
}
|
|
|
|
|