X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fwindows_vst_plugin_ui.cc;h=7d71ef0f7824afed304d0ef7870d8ab8a56aafa0;hb=17f5fb81d2c9d2394f62169b90c15bf371b44f6c;hp=3c80951ff02482dd7fadf58de4fb8bb2891e4509;hpb=d1226a8628f11d32251666d5fb9d9dabbc44446c;p=ardour.git diff --git a/gtk2_ardour/windows_vst_plugin_ui.cc b/gtk2_ardour/windows_vst_plugin_ui.cc index 3c80951ff0..7d71ef0f78 100644 --- a/gtk2_ardour/windows_vst_plugin_ui.cc +++ b/gtk2_ardour/windows_vst_plugin_ui.cc @@ -17,177 +17,166 @@ */ -#include +#include #include #include +#include "gtkmm2ext/gui_thread.h" +#include "fst.h" #include "ardour/plugin_insert.h" #include "ardour/windows_vst_plugin.h" #include "windows_vst_plugin_ui.h" +#ifdef PLATFORM_WINDOWS +#include +#elif defined __APPLE__ +// TODO +#else #include +#endif using namespace Gtk; using namespace ARDOUR; using namespace PBD; -WindowsVSTPluginUI::WindowsVSTPluginUI (boost::shared_ptr pi, boost::shared_ptr vp) - : PlugUIBase (pi), - vst (vp) +WindowsVSTPluginUI::WindowsVSTPluginUI (boost::shared_ptr pi, boost::shared_ptr vp, GtkWidget *parent) + : VSTPluginUI (pi, vp) { - fst_run_editor (vst->state()); - preset_box.set_spacing (6); - preset_box.set_border_width (6); - preset_box.pack_end (focus_button, false, false); - preset_box.pack_end (bypass_button, false, false, 10); - preset_box.pack_end (delete_button, false, false); - preset_box.pack_end (save_button, false, false); - preset_box.pack_end (add_button, false, false); - preset_box.pack_end (_preset_box, false, false); +#ifdef GDK_WINDOWING_WIN32 + gtk_widget_realize(parent); + void* hWndHost = gdk_win32_drawable_get_handle(parent->window); - bypass_button.set_active (!insert->active()); - - pack_start (preset_box, false, false); - pack_start (socket, true, true); + fst_run_editor (_vst->state(), hWndHost); + // TODO pack a placeholder (compare to VSTPluginUI::VSTPluginUI X11 socket) + // have placeholder use VSTPluginUI::get_preferred_height(), width() + // TODO pack plugin_analysis_expander at the bottom. +#else + fst_run_editor (_vst->state(), NULL); pack_start (plugin_analysis_expander, true, true); +#endif } WindowsVSTPluginUI::~WindowsVSTPluginUI () { + fst_destroy_editor (_vst->state()); + // plugin destructor destroys the custom GUI, via Windows fun-and-games, // and then our PluginUIWindow does the rest } void -WindowsVSTPluginUI::preset_selected () +WindowsVSTPluginUI::top_box_allocated (Gtk::Allocation& a) { - socket.grab_focus (); - PlugUIBase::preset_selected (); -} - -int -WindowsVSTPluginUI::get_preferred_height () -{ - return vst->state()->height; + int h = a.get_height() + 12; // 2 * 6px spacing + if (_vst->state()->voffset != h) { +#ifndef NDEBUG + printf("WindowsVSTPluginUI:: update voffset to %d px\n", h); +#endif + _vst->state()->voffset = h; + resize_callback (); + } } -int -WindowsVSTPluginUI::get_preferred_width () +void +WindowsVSTPluginUI::resize_callback () { - return vst->state()->width; + void* gtk_parent_window = _vst->state()->gtk_window_parent; + if (gtk_parent_window) { + int width = _vst->state()->width + _vst->state()->hoffset; + int height = _vst->state()->height + _vst->state()->voffset; +#ifndef NDEBUG + printf ("WindowsVSTPluginUI::resize_callback %d x %d\n", width, height); +#endif + set_size_request (width, height); + ((Gtk::Window*) gtk_parent_window)->set_size_request (width, height); + ((Gtk::Window*) gtk_parent_window)->resize (width, height); + fst_move_window_into_view (_vst->state ()); + } } int WindowsVSTPluginUI::package (Gtk::Window& win) { - /* forward configure events to plugin window */ +#ifndef NDEBUG + printf ("WindowsVSTPluginUI::package\n"); +#endif + VSTPluginUI::package (win); + _vst->state()->gtk_window_parent = (void*) (&win); - win.signal_configure_event().connect (sigc::bind (sigc::mem_fun (*this, &WindowsVSTPluginUI::configure_handler), &socket), false); + _vst->VSTSizeWindow.connect (_resize_connection, invalidator (*this), boost::bind (&WindowsVSTPluginUI::resize_callback, this), gui_context()); - /* - this assumes that the window's owner understands the XEmbed protocol. - */ - - socket.add_id (fst_get_XID (vst->state ())); - - fst_move_window_into_view (vst->state ()); + resize_callback (); return 0; } -bool -WindowsVSTPluginUI::configure_handler (GdkEventConfigure* ev, Gtk::Socket *socket) +void +WindowsVSTPluginUI::forward_key_event (GdkEventKey* ev) { - XEvent event; - gint x, y; - GdkWindow* w; - - if (socket == 0 || ((w = socket->gobj()->plug_window) == 0)) { - return false; + if (dispatch_effeditkey (ev)) { + return; + } +#ifndef PLATFORM_WINDOWS /* linux + wine ; libs/fst/vstwin.c */ + if (ev->type != GDK_KEY_PRESS) { + return; } - 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 (); + VSTState* fst = _vst->state (); + pthread_mutex_lock (&fst->lock); - 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; + if (fst->n_pending_keys == (sizeof (fst->pending_keys) * sizeof (VSTKey))) { + /* buffer full */ + return; + } - event.xconfigure.border_width = 0; - event.xconfigure.above = None; - event.xconfigure.override_redirect = False; + int special_windows_key = 0; + int character_windows_key = 0; + + switch (ev->keyval) { + case GDK_Left: + special_windows_key = 0x25; + break; + case GDK_Right: + special_windows_key = 0x27; + break; + case GDK_Up: + special_windows_key = 0x26; + break; + case GDK_Down: + special_windows_key = 0x28; + break; + case GDK_Return: + case GDK_KP_Enter: + special_windows_key = 0xd; + break; + default: + character_windows_key = ev->keyval; + break; + } - gdk_error_trap_push (); - XSendEvent (GDK_WINDOW_XDISPLAY (w), GDK_WINDOW_XWINDOW (w), False, StructureNotifyMask, &event); - gdk_error_trap_pop (); + fst->pending_keys[fst->n_pending_keys].special = special_windows_key; + fst->pending_keys[fst->n_pending_keys].character = character_windows_key; + fst->n_pending_keys++; - return false; + pthread_mutex_unlock (&fst->lock); +#endif } -void -WindowsVSTPluginUI::forward_key_event (GdkEventKey* ev) +int +WindowsVSTPluginUI::get_XID () { - if (ev->type == GDK_KEY_PRESS) { - - VSTState* fst = vst->state (); - pthread_mutex_lock (&fst->lock); - - if (fst->n_pending_keys == (sizeof (fst->pending_keys) * sizeof (VSTKey))) { - /* buffer full */ - return; - } - - int special_windows_key = 0; - int character_windows_key = 0; - - switch (ev->keyval) { - case GDK_Left: - special_windows_key = 0x25; - break; - case GDK_Right: - special_windows_key = 0x27; - break; - case GDK_Up: - special_windows_key = 0x26; - break; - case GDK_Down: - special_windows_key = 0x28; - break; - case GDK_Return: - case GDK_KP_Enter: - special_windows_key = 0xd; - break; - default: - character_windows_key = ev->keyval; - break; - } - - fst->pending_keys[fst->n_pending_keys].special = special_windows_key; - fst->pending_keys[fst->n_pending_keys].character = character_windows_key; - fst->n_pending_keys++; - - pthread_mutex_unlock (&fst->lock); - } + return _vst->state()->xid; } +#ifdef GDK_WINDOWING_X11 typedef int (*error_handler_t)( Display *, XErrorEvent *); static Display *the_gtk_display; static error_handler_t wine_error_handler; static error_handler_t gtk_error_handler; static int -fst_xerror_handler( Display *disp, XErrorEvent *ev ) +fst_xerror_handler (Display* disp, XErrorEvent* ev) { if (disp == the_gtk_display) { printf ("relaying error to gtk\n"); @@ -197,13 +186,17 @@ fst_xerror_handler( Display *disp, XErrorEvent *ev ) return wine_error_handler (disp, ev); } } +#endif void windows_vst_gui_init (int *argc, char **argv[]) { - wine_error_handler = XSetErrorHandler (NULL); gtk_init (argc, argv); + +#ifdef GDK_WINDOWING_X11 + wine_error_handler = XSetErrorHandler (NULL); the_gtk_display = gdk_x11_display_get_xdisplay (gdk_display_get_default()); gtk_error_handler = XSetErrorHandler (fst_xerror_handler); +#endif }