From e913b03fb6205589494fcc99f05917ec871e81c6 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 23 Nov 2011 00:57:32 +0000 Subject: Missing files / renames. git-svn-id: svn://localhost/ardour2/branches/3.0@10785 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/lxvst_plugin_ui.cc | 181 +++++++++++++++++++++++++++ gtk2_ardour/lxvst_pluginui.cc | 277 ----------------------------------------- gtk2_ardour/vst_plugin_ui.cc | 123 ++++++++++++++++++ gtk2_ardour/vst_plugin_ui.h | 55 ++++++++ 4 files changed, 359 insertions(+), 277 deletions(-) create mode 100644 gtk2_ardour/lxvst_plugin_ui.cc delete mode 100755 gtk2_ardour/lxvst_pluginui.cc create mode 100644 gtk2_ardour/vst_plugin_ui.cc create mode 100644 gtk2_ardour/vst_plugin_ui.h diff --git a/gtk2_ardour/lxvst_plugin_ui.cc b/gtk2_ardour/lxvst_plugin_ui.cc new file mode 100644 index 0000000000..31bb6c879b --- /dev/null +++ b/gtk2_ardour/lxvst_plugin_ui.cc @@ -0,0 +1,181 @@ +/* + Copyright (C) 2004 Paul Davis + + 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "ardour/lxvst_plugin.h" +#include "ardour/vstfx.h" +#include "lxvst_plugin_ui.h" +#include "ardour_ui.h" +#include + +#define LXVST_H_FIDDLE 40 + +using namespace std; +using namespace Gtk; +using namespace ARDOUR; +using namespace PBD; + +LXVSTPluginUI::LXVSTPluginUI (boost::shared_ptr pi, boost::shared_ptr lxvp) + : VSTPluginUI (pi, lxvp) +{ + vstfx_run_editor (_vst->state ()); +} + +LXVSTPluginUI::~LXVSTPluginUI () +{ + _screen_update_connection.disconnect(); + + // plugin destructor destroys the custom GUI, via the vstfx engine, + // and then our PluginUIWindow does the rest +} + + +bool +LXVSTPluginUI::start_updating (GdkEventAny* ignored) +{ + _screen_update_connection.disconnect(); + _screen_update_connection = ARDOUR_UI::instance()->RapidScreenUpdate.connect (mem_fun(*this, &LXVSTPluginUI::resize_callback)); + return false; +} + +bool +LXVSTPluginUI::stop_updating (GdkEventAny* ignored) +{ + _screen_update_connection.disconnect(); + return false; +} + + +void +LXVSTPluginUI::resize_callback () +{ + /* We could maybe use this to resize the plugin GTK parent window + if required + */ + + if (!_vst->state()->want_resize) { + return; + } + + int new_height = _vst->state()->height; + int new_width = _vst->state()->width; + + void* gtk_parent_window = _vst->state()->extra_data; + + if (gtk_parent_window) { + ((Gtk::Window*) gtk_parent_window)->resize (new_width, new_height + LXVST_H_FIDDLE); + } + + _vst->state()->want_resize = 0; +} + +int +LXVSTPluginUI::get_preferred_height () +{ + /* XXX: FIXME */ + + /* 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 + */ + + // May not be 40 for all screen res etc + return VSTPluginUI::get_preferred_height () + LXVST_H_FIDDLE; +} + +int +LXVSTPluginUI::package (Gtk::Window& win) +{ + VSTPluginUI::package (win); + + /* Map the UI start and stop updating events to 'Map' events on the Window */ + + win.signal_map_event().connect (mem_fun (*this, &LXVSTPluginUI::start_updating)); + win.signal_unmap_event().connect (mem_fun (*this, &LXVSTPluginUI::stop_updating)); + + _vst->state()->extra_data = (void*) (&win); + _vst->state()->want_resize = 0; + + return 0; +} + +void +LXVSTPluginUI::forward_key_event (GdkEventKey* ev) +{ + std::cerr << "LXVSTPluginUI : keypress forwarding to linuxVSTs unsupported" << std::endl; +} + +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 + */ + + pthread_mutex_lock (&(_vst->state()->lock)); + + /* The Window may be scheduled for creation + but not actually created by the gui_event_loop yet - + 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 + */ + + while (!(_vst->state()->been_activated)) { + usleep (1000); + } + + int const id = _vst->state()->xid; + + pthread_mutex_unlock (&(_vst->state()->lock)); + + /* Finally it might be safe to return the ID - + 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 + */ + + 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; + +static int +gtk_xerror_handler (Display* disp, XErrorEvent* ev) +{ + std::cerr << "** ERROR ** LXVSTPluginUI : Trapped an X Window System Error" << std::endl; + + 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); +} + diff --git a/gtk2_ardour/lxvst_pluginui.cc b/gtk2_ardour/lxvst_pluginui.cc deleted file mode 100755 index 9c79503a1d..0000000000 --- a/gtk2_ardour/lxvst_pluginui.cc +++ /dev/null @@ -1,277 +0,0 @@ -/* - Copyright (C) 2004 Paul Davis - - 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., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -/******************************************************************/ -/*linuxDSP - pluginui variant for LXVST (native Linux VST) Plugins*/ -/******************************************************************/ - -#include -#include -#include -#include -#include - -#include "ardour_ui.h" -#include "plugin_ui.h" -#include "lxvst_plugin_ui.h" - -#include - -#define LXVST_H_FIDDLE 40 - -using namespace Gtk; -using namespace ARDOUR; -using namespace PBD; - -LXVSTPluginUI::LXVSTPluginUI (boost::shared_ptr pi, boost::shared_ptr lxvp) - : PlugUIBase (pi), - lxvst (lxvp) -{ - create_preset_store (); - - vstfx_run_editor (lxvst->state ()); - - if (lxvst->state()->current_program != -1) { - lxvst_preset_combo.set_active (lxvst->state()->current_program); - } else { - lxvst_preset_combo.set_active (0); - } - - preset_box.set_spacing (6); - preset_box.set_border_width (6); - preset_box.pack_end (bypass_button, false, false, 10); - preset_box.pack_end (save_button, false, false); - preset_box.pack_end (lxvst_preset_combo, false, false); - - lxvst_preset_combo.signal_changed().connect (mem_fun (*this, &LXVSTPluginUI::preset_chosen)); - - if (!insert->active()) { - bypass_button.set_active_state (Gtkmm2ext::Active); - } else { - bypass_button.unset_active_state (); - } - - pack_start (preset_box, false, false); - pack_start (socket, true, true); -} - -LXVSTPluginUI::~LXVSTPluginUI () -{ - - _screen_update_connection.disconnect(); - - // plugin destructor destroys the custom GUI, via the vstfx engine, - // and then our PluginUIWindow does the rest -} - - -bool -LXVSTPluginUI::start_updating (GdkEventAny* ignored) -{ - _screen_update_connection.disconnect(); - _screen_update_connection = ARDOUR_UI::instance()->RapidScreenUpdate.connect - (mem_fun(*this, &LXVSTPluginUI::resize_callback)); - return false; -} - -bool -LXVSTPluginUI::stop_updating (GdkEventAny* ignored) -{ - _screen_update_connection.disconnect(); - return false; -} - - -void -LXVSTPluginUI::resize_callback() -{ - /*We could maybe use this to resize the plugin GTK parent window - if required*/ - - if (lxvst->state()->want_resize) { - int new_height = lxvst->state()->height; - int new_width = lxvst->state()->width; - - void* gtk_parent_window = lxvst->state()->extra_data; - - if (gtk_parent_window) { - ((Gtk::Window*)gtk_parent_window)->resize(new_width, new_height + LXVST_H_FIDDLE); - } - - lxvst->state()->want_resize = 0; - } -} - -void -LXVSTPluginUI::preset_selected () -{ - socket.grab_focus (); - PlugUIBase::preset_selected (); -} - -void -LXVSTPluginUI::preset_chosen () -{ - // we can't dispatch directly here, too many plugins only expects one GUI thread. - - lxvst->state()->want_program = lxvst_preset_combo.get_active_row_number (); - socket.grab_focus (); -} - -int -LXVSTPluginUI::get_preferred_height () -{ - /*FIXME*/ - - /*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*/ - - return (lxvst->state()->height) + LXVST_H_FIDDLE; //May not be 40 for all screen res etc -} - -int -LXVSTPluginUI::get_preferred_width () -{ - return lxvst->state()->width; -} - -int -LXVSTPluginUI::package (Gtk::Window& win) -{ - /* forward configure events to plugin window */ - - win.signal_configure_event().connect (bind (mem_fun (*this, &LXVSTPluginUI::configure_handler), &socket), false); - - /*Map the UI start and stop updating events to 'Map' events on the Window*/ - - win.signal_map_event().connect (mem_fun (*this, &LXVSTPluginUI::start_updating)); - win.signal_unmap_event().connect (mem_fun (*this, &LXVSTPluginUI::stop_updating)); - - /* this assumes that the window's owner understands the XEmbed protocol. */ - - socket.add_id (vstfx_get_XID (lxvst->state ())); - - vstfx_move_window_into_view (lxvst->state ()); - - lxvst->state()->extra_data = (void*)(&win); - lxvst->state()->want_resize = 0; - - return 0; -} - -bool -LXVSTPluginUI::configure_handler (GdkEventConfigure* ev, Gtk::Socket *socket) -{ - XEvent event; - gint x, y; - GdkWindow* w; - - if (socket == 0 || ((w = socket->gobj()->plug_window) == 0)) { - return false; - } - - event.xconfigure.type = ConfigureNotify; - event.xconfigure.event = GDK_WINDOW_XWINDOW (w); - event.xconfigure.window = GDK_WINDOW_XWINDOW (w); - - /* The ICCCM says that synthetic events should have root relative - * coordinates. We still aren't really ICCCM compliant, since - * we don't send events when the real toplevel is moved. - */ - gdk_error_trap_push (); - gdk_window_get_origin (w, &x, &y); - gdk_error_trap_pop (); - - event.xconfigure.x = x; - event.xconfigure.y = y; - event.xconfigure.width = GTK_WIDGET(socket->gobj())->allocation.width; - event.xconfigure.height = GTK_WIDGET(socket->gobj())->allocation.height; - - event.xconfigure.border_width = 0; - event.xconfigure.above = None; - event.xconfigure.override_redirect = False; - - gdk_error_trap_push (); - XSendEvent (GDK_WINDOW_XDISPLAY (w), GDK_WINDOW_XWINDOW (w), False, StructureNotifyMask, &event); - gdk_error_trap_pop (); - - return false; -} - -void -LXVSTPluginUI::forward_key_event (GdkEventKey* ev) -{ - std::cerr << "LXVSTPluginUI : keypress forwarding to linuxVSTs unsupported" << std::endl; -} - - -void -LXVSTPluginUI::create_preset_store () -{ - VSTState* vstfx = lxvst->state (); - - int vst_version = vstfx->plugin->dispatcher (vstfx->plugin, effGetVstVersion, 0, 0, NULL, 0.0f); - - preset_model = ListStore::create (preset_columns); - - for (int i = 0; i < vstfx->plugin->numPrograms; ++i) { - char buf[100]; - TreeModel::Row row = *(preset_model->append()); - - snprintf (buf, 90, "preset %d", i); - - if (vst_version >= 2) { - vstfx->plugin->dispatcher (vstfx->plugin, 29, i, 0, buf, 0.0); - } - - row[preset_columns.name] = buf; - row[preset_columns.number] = i; - } - - lxvst_preset_combo.set_model (preset_model); - - CellRenderer* renderer = manage (new CellRendererText()); - lxvst_preset_combo.pack_start (*renderer, true); - lxvst_preset_combo.add_attribute (*renderer, "text", 0); -} - -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; - -static int -gtk_xerror_handler( Display *disp, XErrorEvent *ev ) -{ - std::cerr << "** ERROR ** LXVSTPluginUI : Trapped an X Window System Error" << std::endl; - - 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 ); -} - diff --git a/gtk2_ardour/vst_plugin_ui.cc b/gtk2_ardour/vst_plugin_ui.cc new file mode 100644 index 0000000000..758c38cd8f --- /dev/null +++ b/gtk2_ardour/vst_plugin_ui.cc @@ -0,0 +1,123 @@ +/* + Copyright (C) 2000-2010 Paul Davis + + 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "ardour/vst_plugin.h" +#include "ardour/vst_types.h" +#include "vst_plugin_ui.h" +#include + +VSTPluginUI::VSTPluginUI (boost::shared_ptr insert, boost::shared_ptr plugin) + : PlugUIBase (insert) + , _vst (plugin) +{ + Gtk::HBox* box = manage (new Gtk::HBox); + box->set_spacing (6); + box->set_border_width (6); + box->pack_end (focus_button, false, false); + box->pack_end (bypass_button, false, false, 10); + box->pack_end (delete_button, false, false); + box->pack_end (save_button, false, false); + box->pack_end (add_button, false, false); + box->pack_end (_preset_box, false, false); + + if (!insert->active ()) { + bypass_button.set_active_state (Gtkmm2ext::Active); + } else { + bypass_button.unset_active_state (); + } + + pack_start (*box, false, false); + pack_start (_socket, true, true); +} + +VSTPluginUI::~VSTPluginUI () +{ + +} + +void +VSTPluginUI::preset_selected () +{ + _socket.grab_focus (); + PlugUIBase::preset_selected (); +} + +int +VSTPluginUI::get_preferred_height () +{ + return _vst->state()->height; +} + +int +VSTPluginUI::get_preferred_width () +{ + return _vst->state()->width; +} + +int +VSTPluginUI::package (Gtk::Window& win) +{ + /* Forward configure events to plugin window */ + win.signal_configure_event().connect (sigc::mem_fun (*this, &VSTPluginUI::configure_handler), false); + + /* This assumes that the window's owner understands the XEmbed protocol */ + _socket.add_id (get_XID ()); + + return 0; +} + +bool +VSTPluginUI::configure_handler (GdkEventConfigure* ev) +{ + XEvent event; + gint x, y; + GdkWindow* w; + + if ((w = _socket.gobj()->plug_window) == 0) { + return false; + } + + event.xconfigure.type = ConfigureNotify; + event.xconfigure.event = GDK_WINDOW_XWINDOW (w); + event.xconfigure.window = GDK_WINDOW_XWINDOW (w); + + /* The ICCCM says that synthetic events should have root relative + * coordinates. We still aren't really ICCCM compliant, since + * we don't send events when the real toplevel is moved. + */ + gdk_error_trap_push (); + gdk_window_get_origin (w, &x, &y); + gdk_error_trap_pop (); + + event.xconfigure.x = x; + event.xconfigure.y = y; + event.xconfigure.width = GTK_WIDGET (_socket.gobj())->allocation.width; + event.xconfigure.height = GTK_WIDGET (_socket.gobj())->allocation.height; + + event.xconfigure.border_width = 0; + event.xconfigure.above = None; + event.xconfigure.override_redirect = False; + + gdk_error_trap_push (); + XSendEvent (GDK_WINDOW_XDISPLAY (w), GDK_WINDOW_XWINDOW (w), False, StructureNotifyMask, &event); + gdk_error_trap_pop (); + + return false; +} + diff --git a/gtk2_ardour/vst_plugin_ui.h b/gtk2_ardour/vst_plugin_ui.h new file mode 100644 index 0000000000..9ab38fe446 --- /dev/null +++ b/gtk2_ardour/vst_plugin_ui.h @@ -0,0 +1,55 @@ +/* + Copyright (C) 2000-2010 Paul Davis + + 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., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef __ardour_vst_plugin_ui_h__ +#define __ardour_vst_plugin_ui_h__ + +#include "plugin_ui.h" + +namespace ARDOUR { + class VSTPlugin; +} + +class VSTPluginUI : public PlugUIBase, public Gtk::VBox +{ +public: + VSTPluginUI (boost::shared_ptr, boost::shared_ptr); + virtual ~VSTPluginUI (); + + virtual int get_preferred_height (); + virtual int get_preferred_width (); + + virtual int package (Gtk::Window &); + + bool non_gtk_gui () const { return true; } + +protected: + + virtual int get_XID () = 0; + + boost::shared_ptr _vst; + Gtk::Socket _socket; + +private: + + bool configure_handler (GdkEventConfigure *); + void preset_selected (); +}; + +#endif -- cgit v1.2.3