Based on code by Paul Davis, Torben Hohn as part of FST
This program is free software; you can redistribute it and/or modify
Based on code by Paul Davis, Torben Hohn as part of FST
This program is free software; you can redistribute it and/or modify
/** VSTFX - An engine based on FST for handling linuxVST plugins **/
/******************************************************************/
/** VSTFX - An engine based on FST for handling linuxVST plugins **/
/******************************************************************/
/*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*/
/*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*/
&userCount, //Actual number of items stored in the returned data
&bytes, //Number of bytes remaining if a partial read
&data); //The actual data read
&userCount, //Actual number of items stored in the returned data
&bytes, //Number of bytes remaining if a partial read
&data); //The actual data read
/*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*/
/*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*/
dispatch_x_events (XEvent* event, VSTState* vstfx)
{
/*Handle some of the Events we might be interested in*/
dispatch_x_events (XEvent* event, VSTState* vstfx)
{
/*Handle some of the Events we might be interested in*/
/*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 (you might think that should be spawned as a new window...) */
/*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 (you might think that should be spawned as a new window...) */
if (window == (Window) (vstfx->linux_window)) {
if (width != vstfx->width || height!=vstfx->height) {
vstfx->width = width;
vstfx->height = height;
vstfx->want_resize = 1;
if (window == (Window) (vstfx->linux_window)) {
if (width != vstfx->width || height!=vstfx->height) {
vstfx->width = width;
vstfx->height = height;
vstfx->want_resize = 1;
/*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*/
/*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*/
if (vstfx->linux_plugin_ui_window) {
XMoveWindow (LXVST_XDisplay, vstfx->linux_plugin_ui_window, 0, 0);
}
}
}
if (vstfx->linux_plugin_ui_window) {
XMoveWindow (LXVST_XDisplay, vstfx->linux_plugin_ui_window, 0, 0);
}
}
}
/*Reparent Notify - when the plugin UI is reparented into
our Host Window we will get an event here... probably... */
/*Reparent Notify - when the plugin UI is reparented into
our Host Window we will get an event here... probably... */
/*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 */
/*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 */
/***********************************************************/
/* 64Bit --- This mechanism is not 64Bit compatible at the */
/* present time */
/***********************************************************/
/***********************************************************/
/* 64Bit --- This mechanism is not 64Bit compatible at the */
/* present time */
/***********************************************************/
if (ParentWindow == (Window) (vstfx->linux_window)) {
Window PluginUIWindowID = event->xreparent.window;
if (ParentWindow == (Window) (vstfx->linux_window)) {
Window PluginUIWindowID = event->xreparent.window;
vstfx->linux_plugin_ui_window = PluginUIWindowID;
#ifdef LXVST_32BIT
int result = getXWindowProperty(PluginUIWindowID, XInternAtom(LXVST_XDisplay, "_XEventProc", false));
vstfx->linux_plugin_ui_window = PluginUIWindowID;
#ifdef LXVST_32BIT
int result = getXWindowProperty(PluginUIWindowID, XInternAtom(LXVST_XDisplay, "_XEventProc", false));
#endif
#ifdef LXVST_64BIT
long result = getXWindowProperty(PluginUIWindowID, XInternAtom(LXVST_XDisplay, "_XEventProc", false));
#endif
#ifdef LXVST_64BIT
long result = getXWindowProperty(PluginUIWindowID, XInternAtom(LXVST_XDisplay, "_XEventProc", false));
/*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*/
/*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*/
if (window == (Window) (vstfx->linux_window)) {
char* message = XGetAtomName(LXVST_XDisplay, message_type);
if (window == (Window) (vstfx->linux_window)) {
char* message = XGetAtomName(LXVST_XDisplay, message_type);
if (strcmp(message,"LaunchEditor") == 0) {
if (event->xclient.data.l[0] == 0x0FEEDBAC) {
vstfx_launch_editor (vstfx);
}
}
if (strcmp(message,"LaunchEditor") == 0) {
if (event->xclient.data.l[0] == 0x0FEEDBAC) {
vstfx_launch_editor (vstfx);
}
}
/* 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.*/
/* 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.*/
/*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*/
/*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*/
}
vstfx->plugin->dispatcher (vstfx->plugin, effSetProgram, 0, vstfx->want_program, NULL, 0);
}
vstfx->plugin->dispatcher (vstfx->plugin, effSetProgram, 0, vstfx->want_program, NULL, 0);
if (vstfx->vst_version >= 2) {
vstfx->plugin->dispatcher (vstfx->plugin, 68 /* effEndSetProgram */, 0, 0, NULL, 0);
}
if (vstfx->vst_version >= 2) {
vstfx->plugin->dispatcher (vstfx->plugin, 68 /* effEndSetProgram */, 0, 0, NULL, 0);
}
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*/
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*/
- if((LXVST_sched_timer_interval!=0) && (!(LXVST_sched_event_timer% LXVST_sched_timer_interval)))
+ clock2 = g_get_monotonic_time();
+ const int64_t elapsed_time_ms = (clock2 - clock1) / 1000;
+
+ if((LXVST_sched_timer_interval != 0) && elapsed_time_ms >= LXVST_sched_timer_interval)
if (vstfx->destroy) {
if (vstfx->linux_window) {
vstfx->plugin->dispatcher (vstfx->plugin, effEditClose, 0, 0, NULL, 0.0);
if (vstfx->destroy) {
if (vstfx->linux_window) {
vstfx->plugin->dispatcher (vstfx->plugin, effEditClose, 0, 0, NULL, 0.0);
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;
vstfx->destroy = FALSE;
}
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;
vstfx->destroy = FALSE;
}
vstfx_event_loop_remove_plugin (vstfx);
vstfx->been_activated = FALSE;
pthread_cond_signal (&vstfx->window_status_change);
pthread_mutex_unlock (&vstfx->lock);
vstfx_event_loop_remove_plugin (vstfx);
vstfx->been_activated = FALSE;
pthread_cond_signal (&vstfx->window_status_change);
pthread_mutex_unlock (&vstfx->lock);
/*Window does not yet exist - scheduled for creation*/
/* FIXME - probably safe to assume 0 is not a valid XID but not explicitly true */
/*Window does not yet exist - scheduled for creation*/
/* FIXME - probably safe to assume 0 is not a valid XID but not explicitly true */
vstfx->plugin->dispatcher (vstfx->plugin, effEditIdle, 0, 0, NULL, 0);
if(vstfx->wantIdle)
vstfx->plugin->dispatcher (vstfx->plugin, 53, 0, 0, NULL, 0);
vstfx->plugin->dispatcher (vstfx->plugin, effEditIdle, 0, 0, NULL, 0);
if(vstfx->wantIdle)
vstfx->plugin->dispatcher (vstfx->plugin, 53, 0, 0, NULL, 0);
/*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* */
/*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* */
if(LXVST_XDisplay==NULL)
LXVST_XDisplay = XOpenDisplay(NULL); //We might be able to make this open a specific screen etc
/*Drop out and report the error if we fail to connect to X */
if(LXVST_XDisplay==NULL)
LXVST_XDisplay = XOpenDisplay(NULL); //We might be able to make this open a specific screen etc
/*Drop out and report the error if we fail to connect to X */
-
- thread_create_result = pthread_create(&LXVST_gui_event_thread, NULL, gui_event_loop, NULL);
-
+
+ thread_create_result = pthread_create(&LXVST_gui_event_thread, &thread_attributes, gui_event_loop, NULL);
+
if (!vstfx->linux_window) {
pthread_cond_wait (&vstfx->window_status_change, &vstfx->lock);
}
if (!vstfx->linux_window) {
pthread_cond_wait (&vstfx->window_status_change, &vstfx->lock);
}
parent_window = XCreateSimpleWindow (
LXVST_XDisplay,
DefaultRootWindow(LXVST_XDisplay),
parent_window = XCreateSimpleWindow (
LXVST_XDisplay,
DefaultRootWindow(LXVST_XDisplay),
/*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*/
/*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*/
/*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.
/*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.
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...*/
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...*/
XSendEvent(LXVST_XDisplay, parent_window, FALSE, NoEventMask, (XEvent*)&event);
XSendEvent(LXVST_XDisplay, parent_window, FALSE, NoEventMask, (XEvent*)&event);
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*/
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*/
/*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 */
/*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 */
/**************************************************************/
/* 64Bit --- parent window is an int passed as a void* so */
/* that should be ok for 64Bit machines */
/**************************************************************/
/* 64Bit --- parent window is an int passed as a void* so */
/* that should be ok for 64Bit machines */
/* */
/* linuxDSP VSTs don't use the host Display* at all */
/**************************************************************/
/* */
/* linuxDSP VSTs don't use the host Display* at all */
/**************************************************************/
vstfx->plugin->dispatcher (vstfx->plugin, effEditOpen, 0, (long)LXVST_XDisplay, (void*)(parent_window), 0 );
vstfx->plugin->dispatcher (vstfx->plugin, effEditOpen, 0, (long)LXVST_XDisplay, (void*)(parent_window), 0 );
/*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 */
/*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 */
vstfx->plugin->dispatcher (vstfx->plugin, effEditGetRect, 0, 0, &er, 0 );
vstfx->plugin->dispatcher (vstfx->plugin, effEditGetRect, 0, 0, &er, 0 );
- x_size = er->right - er->left;
- y_size = er->bottom - er->top;
-
- vstfx->width = x_size;
- vstfx->height = y_size;
-
+ 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;
+ }
+
+ vstfx->width = x_size;
+ vstfx->height = y_size;
+
XResizeWindow(LXVST_XDisplay, parent_window, x_size, y_size);
XResizeWindow(LXVST_XDisplay, parent_window, x_size, y_size);
/*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*/
/*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*/