2011-11-22 19:57:32 -05:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2011 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2013-2018 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2015-2018 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.
|
|
|
|
*/
|
2011-11-22 19:57:32 -05:00
|
|
|
|
2018-08-11 13:50:42 -04:00
|
|
|
|
2017-03-07 12:38:01 -05:00
|
|
|
#include "gtkmm2ext/gui_thread.h"
|
2011-11-22 19:57:32 -05:00
|
|
|
#include "ardour/lxvst_plugin.h"
|
2011-11-23 14:31:04 -05:00
|
|
|
#include "ardour/linux_vst_support.h"
|
2011-11-22 19:57:32 -05:00
|
|
|
#include "lxvst_plugin_ui.h"
|
2018-08-11 13:50:42 -04:00
|
|
|
|
|
|
|
#include <gdk/gdkx.h> /* must come later than glibmm/object.h */
|
2011-11-22 19:57:32 -05:00
|
|
|
|
|
|
|
#define LXVST_H_FIDDLE 40
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace ARDOUR;
|
|
|
|
using namespace PBD;
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
LXVSTPluginUI::LXVSTPluginUI (std::shared_ptr<PlugInsertBase> pib, std::shared_ptr<VSTPlugin> lxvp)
|
2022-04-04 14:48:56 -04:00
|
|
|
: VSTPluginUI (pib, lxvp)
|
2011-11-22 19:57:32 -05:00
|
|
|
{
|
|
|
|
vstfx_run_editor (_vst->state ());
|
|
|
|
}
|
|
|
|
|
|
|
|
LXVSTPluginUI::~LXVSTPluginUI ()
|
|
|
|
{
|
2017-03-07 12:38:01 -05:00
|
|
|
_resize_connection.disconnect();
|
2022-10-11 13:48:36 -04:00
|
|
|
vstfx_destroy_editor (_vst->state ());
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-22 19:57:32 -05:00
|
|
|
// plugin destructor destroys the custom GUI, via the vstfx engine,
|
|
|
|
// and then our PluginUIWindow does the rest
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LXVSTPluginUI::resize_callback ()
|
|
|
|
{
|
2017-03-07 12:38:01 -05:00
|
|
|
void* gtk_parent_window = _vst->state()->gtk_window_parent;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-22 19:57:32 -05:00
|
|
|
if (gtk_parent_window) {
|
2017-03-07 12:38:01 -05:00
|
|
|
int width = _vst->state()->width;
|
|
|
|
int height = _vst->state()->height;
|
|
|
|
#ifndef NDEBUG
|
|
|
|
printf ("LXVSTPluginUI::resize_callback %d x %d\n", width, height);
|
|
|
|
#endif
|
2015-12-29 04:08:42 -05:00
|
|
|
_socket.set_size_request(
|
2017-03-07 12:38:01 -05:00
|
|
|
width + _vst->state()->hoffset,
|
|
|
|
height + _vst->state()->voffset);
|
2015-12-29 04:08:42 -05:00
|
|
|
|
2017-03-07 12:38:01 -05:00
|
|
|
((Gtk::Window*) gtk_parent_window)->resize (width, height + LXVST_H_FIDDLE);
|
|
|
|
if (_vst->state()->linux_plugin_ui_window) {
|
|
|
|
}
|
2011-11-22 19:57:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
LXVSTPluginUI::get_preferred_height ()
|
2015-10-05 10:17:49 -04:00
|
|
|
{
|
2011-11-22 19:57:32 -05:00
|
|
|
/* XXX: FIXME */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-22 19:57:32 -05:00
|
|
|
/* We have to return the required height of the plugin UI window + a fiddle factor
|
|
|
|
because we can't know how big the preset menu bar is until the window is realised
|
|
|
|
and we can't realise it until we have told it how big we would like it to be
|
|
|
|
which we can't do until it is realised etc
|
|
|
|
*/
|
|
|
|
|
2015-10-05 10:17:49 -04:00
|
|
|
// May not be 40 for all screen res etc
|
2011-11-22 19:57:32 -05:00
|
|
|
return VSTPluginUI::get_preferred_height () + LXVST_H_FIDDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
LXVSTPluginUI::package (Gtk::Window& win)
|
|
|
|
{
|
|
|
|
VSTPluginUI::package (win);
|
2017-03-07 12:38:01 -05:00
|
|
|
_vst->state()->gtk_window_parent = (void*) (&win);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-22 19:57:32 -05:00
|
|
|
/* Map the UI start and stop updating events to 'Map' events on the Window */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2024-10-18 19:51:44 -04:00
|
|
|
_vst->VSTSizeWindow.connect (_resize_connection, invalidator (*this), std::bind (&LXVSTPluginUI::resize_callback, this), gui_context());
|
2011-11-22 19:57:32 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-08-11 13:50:42 -04:00
|
|
|
LXVSTPluginUI::forward_key_event (GdkEventKey* gdk_key)
|
2011-11-22 19:57:32 -05:00
|
|
|
{
|
2018-08-11 13:50:42 -04:00
|
|
|
if (!_vst->state()->gtk_window_parent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Glib::RefPtr<Gdk::Window> gdk_window = ((Gtk::Window*) _vst->state()->gtk_window_parent)->get_window();
|
|
|
|
|
|
|
|
if (!gdk_window) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
XEvent xev;
|
|
|
|
int mask;
|
|
|
|
|
|
|
|
switch (gdk_key->type) {
|
|
|
|
case GDK_KEY_PRESS:
|
|
|
|
xev.xany.type = KeyPress;
|
|
|
|
mask = KeyPressMask;
|
|
|
|
break;
|
|
|
|
case GDK_KEY_RELEASE:
|
2018-10-31 20:27:30 -04:00
|
|
|
xev.xany.type = KeyRelease;
|
2018-08-11 13:50:42 -04:00
|
|
|
mask = KeyReleaseMask;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX relies on GDK using X11 definitions for these fields */
|
|
|
|
|
|
|
|
xev.xkey.state = gdk_key->state;
|
|
|
|
xev.xkey.keycode = gdk_key->hardware_keycode; /* see gdk/x11/gdkevents-x11.c:translate_key_event() */
|
|
|
|
|
|
|
|
xev.xkey.x = 0;
|
|
|
|
xev.xkey.y = 0;
|
|
|
|
xev.xkey.x_root = 0;
|
|
|
|
xev.xkey.y_root = 0;
|
|
|
|
xev.xkey.root = gdk_x11_get_default_root_xwindow();
|
2018-10-31 20:27:30 -04:00
|
|
|
xev.xkey.window = _vst->state()->linux_plugin_ui_window ? _vst->state()->linux_plugin_ui_window : _vst->state()->xid;
|
2018-08-11 13:50:42 -04:00
|
|
|
xev.xkey.subwindow = None;
|
|
|
|
xev.xkey.time = gdk_key->time;
|
|
|
|
|
|
|
|
xev.xany.serial = 0; /* we don't have one */
|
|
|
|
xev.xany.send_event = true; /* pretend we are using XSendEvent */
|
|
|
|
xev.xany.display = GDK_WINDOW_XDISPLAY (gdk_window->gobj());
|
|
|
|
|
2018-11-01 14:14:25 -04:00
|
|
|
if (_vst->state()->eventProc) {
|
2018-08-11 13:50:42 -04:00
|
|
|
_vst->state()->eventProc (&xev);
|
2018-11-01 14:14:25 -04:00
|
|
|
} else if (!dispatch_effeditkey (gdk_key)) {
|
|
|
|
XSendEvent (xev.xany.display, xev.xany.window, TRUE, mask, &xev);
|
2018-08-11 13:50:42 -04:00
|
|
|
}
|
2011-11-22 19:57:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
LXVSTPluginUI::get_XID ()
|
|
|
|
{
|
|
|
|
/* Wait for the lock to become free - otherwise
|
|
|
|
the window might be in the process of being
|
|
|
|
created and we get bad Window errors when trying
|
|
|
|
to embed it in the GTK UI
|
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-22 19:57:32 -05:00
|
|
|
pthread_mutex_lock (&(_vst->state()->lock));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-22 19:57:32 -05:00
|
|
|
/* The Window may be scheduled for creation
|
2015-10-04 14:51:05 -04:00
|
|
|
but not actually created by the gui_event_loop yet -
|
2011-11-22 19:57:32 -05:00
|
|
|
spin here until it has been activated. Possible
|
|
|
|
deadlock if the window never gets activated but
|
|
|
|
should not be called here if the window doesn't
|
|
|
|
exist or will never exist
|
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-22 19:57:32 -05:00
|
|
|
while (!(_vst->state()->been_activated)) {
|
2013-12-03 10:24:34 -05:00
|
|
|
Glib::usleep (1000);
|
2011-11-22 19:57:32 -05:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-22 19:57:32 -05:00
|
|
|
int const id = _vst->state()->xid;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-22 19:57:32 -05:00
|
|
|
pthread_mutex_unlock (&(_vst->state()->lock));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
/* Finally it might be safe to return the ID -
|
2011-11-22 19:57:32 -05:00
|
|
|
problems will arise if we return either a zero ID
|
|
|
|
and GTK tries to socket it or if we return an ID
|
|
|
|
which hasn't yet become real to the server
|
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-22 19:57:32 -05:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef int (*error_handler_t)( Display *, XErrorEvent *);
|
|
|
|
static Display *the_gtk_display;
|
|
|
|
static error_handler_t vstfx_error_handler;
|
|
|
|
static error_handler_t gtk_error_handler;
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
static int
|
2013-01-08 16:36:42 -05:00
|
|
|
gtk_xerror_handler (Display*, XErrorEvent*)
|
2011-11-22 19:57:32 -05:00
|
|
|
{
|
|
|
|
std::cerr << "** ERROR ** LXVSTPluginUI : Trapped an X Window System Error" << std::endl;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-11-22 19:57:32 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gui_init (int* argc, char** argv[])
|
|
|
|
{
|
|
|
|
vstfx_error_handler = XSetErrorHandler (NULL);
|
|
|
|
gtk_init (argc, argv);
|
|
|
|
the_gtk_display = gdk_x11_display_get_xdisplay (gdk_display_get_default());
|
|
|
|
gtk_error_handler = XSetErrorHandler (gtk_xerror_handler);
|
|
|
|
}
|