2 Copyright (C) 2004 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <gtk/gtksocket.h>
24 #include "ardour/plugin_insert.h"
25 #include "ardour/windows_vst_plugin.h"
27 #include "windows_vst_plugin_ui.h"
29 #ifdef PLATFORM_WINDOWS
30 #include <gdk/gdkwin32.h>
31 #elif defined __APPLE__
38 using namespace ARDOUR;
41 WindowsVSTPluginUI::WindowsVSTPluginUI (boost::shared_ptr<PluginInsert> pi, boost::shared_ptr<VSTPlugin> vp, GtkWidget *parent)
42 : VSTPluginUI (pi, vp)
45 #ifdef GDK_WINDOWING_WIN32
46 gtk_widget_realize(parent);
47 void* hWndHost = gdk_win32_drawable_get_handle(parent->window);
49 fst_run_editor (_vst->state(), hWndHost);
50 // TODO pack a placeholder (compare to VSTPluginUI::VSTPluginUI X11 socket)
51 // have placeholder use VSTPluginUI::get_preferred_height(), width()
52 // TODO pack plugin_analysis_expander at the bottom.
54 fst_run_editor (_vst->state(), NULL);
55 pack_start (plugin_analysis_expander, true, true);
59 WindowsVSTPluginUI::~WindowsVSTPluginUI ()
61 fst_destroy_editor (_vst->state());
63 // plugin destructor destroys the custom GUI, via Windows fun-and-games,
64 // and then our PluginUIWindow does the rest
68 WindowsVSTPluginUI::package (Gtk::Window& win)
70 VSTPluginUI::package (win);
72 fst_move_window_into_view (_vst->state ());
78 WindowsVSTPluginUI::forward_key_event (GdkEventKey* ev)
80 if (ev->type != GDK_KEY_PRESS) {
84 VSTState* fst = _vst->state ();
85 pthread_mutex_lock (&fst->lock);
87 if (fst->n_pending_keys == (sizeof (fst->pending_keys) * sizeof (VSTKey))) {
92 int special_windows_key = 0;
93 int character_windows_key = 0;
97 special_windows_key = 0x25;
100 special_windows_key = 0x27;
103 special_windows_key = 0x26;
106 special_windows_key = 0x28;
110 special_windows_key = 0xd;
113 character_windows_key = ev->keyval;
117 fst->pending_keys[fst->n_pending_keys].special = special_windows_key;
118 fst->pending_keys[fst->n_pending_keys].character = character_windows_key;
119 fst->n_pending_keys++;
121 pthread_mutex_unlock (&fst->lock);
125 WindowsVSTPluginUI::get_XID ()
127 return _vst->state()->xid;
130 #ifdef GDK_WINDOWING_X11
131 typedef int (*error_handler_t)( Display *, XErrorEvent *);
132 static Display *the_gtk_display;
133 static error_handler_t wine_error_handler;
134 static error_handler_t gtk_error_handler;
137 fst_xerror_handler (Display* disp, XErrorEvent* ev)
139 if (disp == the_gtk_display) {
140 printf ("relaying error to gtk\n");
141 return gtk_error_handler (disp, ev);
143 printf( "relaying error to wine\n" );
144 return wine_error_handler (disp, ev);
150 windows_vst_gui_init (int *argc, char **argv[])
152 gtk_init (argc, argv);
154 #ifdef GDK_WINDOWING_X11
155 wine_error_handler = XSetErrorHandler (NULL);
156 the_gtk_display = gdk_x11_display_get_xdisplay (gdk_display_get_default());
157 gtk_error_handler = XSetErrorHandler (fst_xerror_handler);