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>
23 #include "ardour/plugin_insert.h"
24 #include "ardour/vst_plugin.h"
26 #include "plugin_ui.h"
31 using namespace ARDOUR;
34 VSTPluginUI::VSTPluginUI (boost::shared_ptr<PluginInsert> pi, boost::shared_ptr<VSTPlugin> vp)
40 fst_run_editor (vst->fst());
42 preset_box.set_spacing (6);
43 preset_box.set_border_width (6);
44 preset_box.pack_end (bypass_button, false, false, 10);
45 preset_box.pack_end (delete_button, false, false);
46 preset_box.pack_end (save_button, false, false);
47 preset_box.pack_end (add_button, false, false);
48 preset_box.pack_end (preset_combo, false, false);
50 bypass_button.set_active (!insert->active());
52 pack_start (preset_box, false, false);
53 pack_start (socket, true, true);
54 pack_start (plugin_analysis_expander, true, true);
57 VSTPluginUI::~VSTPluginUI ()
59 // plugin destructor destroys the custom GUI, via Windows fun-and-games,
60 // and then our PluginUIWindow does the rest
64 VSTPluginUI::setting_selected ()
66 int const r = preset_combo.get_active_row_number ();
68 if (r < vst->first_user_preset_index()) {
69 /* This is a plugin-provided preset.
70 We can't dispatch directly here; too many plugins expects only one GUI thread.
72 vst->fst()->want_program = r;
74 /* This is a user preset. This method knows about the direct dispatch restriction, too */
75 plugin->load_preset (preset_combo.get_active_text());
79 update_sensitivity ();
83 VSTPluginUI::get_preferred_height ()
85 return vst->fst()->height;
89 VSTPluginUI::get_preferred_width ()
91 return vst->fst()->width;
95 VSTPluginUI::package (Gtk::Window& win)
97 /* forward configure events to plugin window */
99 win.signal_configure_event().connect (sigc::bind (sigc::mem_fun (*this, &VSTPluginUI::configure_handler), &socket), false);
102 this assumes that the window's owner understands the XEmbed protocol.
105 socket.add_id (fst_get_XID (vst->fst()));
107 fst_move_window_into_view (vst->fst());
113 VSTPluginUI::configure_handler (GdkEventConfigure* ev, Gtk::Socket *socket)
119 if (socket == 0 || ((w = socket->gobj()->plug_window) == 0)) {
123 event.xconfigure.type = ConfigureNotify;
124 event.xconfigure.event = GDK_WINDOW_XWINDOW (w);
125 event.xconfigure.window = GDK_WINDOW_XWINDOW (w);
127 /* The ICCCM says that synthetic events should have root relative
128 * coordinates. We still aren't really ICCCM compliant, since
129 * we don't send events when the real toplevel is moved.
131 gdk_error_trap_push ();
132 gdk_window_get_origin (w, &x, &y);
133 gdk_error_trap_pop ();
135 event.xconfigure.x = x;
136 event.xconfigure.y = y;
137 event.xconfigure.width = GTK_WIDGET(socket->gobj())->allocation.width;
138 event.xconfigure.height = GTK_WIDGET(socket->gobj())->allocation.height;
140 event.xconfigure.border_width = 0;
141 event.xconfigure.above = None;
142 event.xconfigure.override_redirect = False;
144 gdk_error_trap_push ();
145 XSendEvent (GDK_WINDOW_XDISPLAY (w), GDK_WINDOW_XWINDOW (w), False, StructureNotifyMask, &event);
146 gdk_error_trap_pop ();
151 typedef int (*error_handler_t)( Display *, XErrorEvent *);
152 static Display *the_gtk_display;
153 static error_handler_t wine_error_handler;
154 static error_handler_t gtk_error_handler;
157 fst_xerror_handler( Display *disp, XErrorEvent *ev )
159 if (disp == the_gtk_display) {
160 printf ("relaying error to gtk\n");
161 return gtk_error_handler (disp, ev);
163 printf( "relaying error to wine\n" );
164 return wine_error_handler (disp, ev);
169 gui_init (int *argc, char **argv[])
171 wine_error_handler = XSetErrorHandler (NULL);
172 gtk_init (argc, argv);
173 the_gtk_display = gdk_x11_display_get_xdisplay (gdk_display_get_default());
174 gtk_error_handler = XSetErrorHandler( fst_xerror_handler );