ardour
vst_plugin_ui.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2000-2010 Paul Davis
3 
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.
8 
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.
13 
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.
17 
18 */
19 
20 #include <gtkmm.h>
21 #include "ardour/vst_plugin.h"
22 #include "ardour/vst_types.h"
23 #include "ardour/plugin_insert.h"
24 #include "vst_plugin_ui.h"
25 
26 #ifdef PLATFORM_WINDOWS
27 #include <gdk/gdkwin32.h>
28 #elif defined __APPLE__
29 // TODO
30 #else
31 #include <gdk/gdkx.h>
32 #endif
33 
35  : PlugUIBase (insert)
36  , _vst (plugin)
37 {
38  Gtk::HBox* box = manage (new Gtk::HBox);
39  box->set_spacing (6);
40  box->set_border_width (6);
41  box->pack_end (focus_button, false, false);
42  box->pack_end (bypass_button, false, false, 4);
43  box->pack_end (reset_button, false, false, 4);
44  box->pack_end (delete_button, false, false);
45  box->pack_end (save_button, false, false);
46  box->pack_end (add_button, false, false);
47  box->pack_end (_preset_combo, false, false);
48 
49  bypass_button.set_active (!insert->active ());
50 
51  pack_start (*box, false, false);
52 #ifdef GDK_WINDOWING_X11
53  pack_start (_socket, true, true);
54  _socket.set_border_width (0);
55 #endif
56 }
57 
59 {
60 
61 }
62 
63 void
65 {
66 #ifdef GDK_WINDOWING_X11
67  _socket.grab_focus ();
68 #endif
70 }
71 
72 int
74 {
75  return _vst->state()->height + _vst->state()->voffset;
76 }
77 
78 int
80 {
81  return _vst->state()->width + _vst->state()->hoffset;
82 }
83 
84 int
85 VSTPluginUI::package (Gtk::Window& win)
86 {
87 #ifdef GDK_WINDOWING_X11
88  /* Forward configure events to plugin window */
89  win.signal_configure_event().connect (sigc::mem_fun (*this, &VSTPluginUI::configure_handler), false);
90 
91  /* This assumes that the window's owner understands the XEmbed protocol */
92  _socket.add_id (get_XID ());
93  _socket.set_size_request(
94  _vst->state()->width + _vst->state()->hoffset,
95  _vst->state()->height + _vst->state()->voffset);
96 #endif
97 
98  return 0;
99 }
100 
101 bool
102 VSTPluginUI::on_window_show(const std::string& title)
103 {
104  _vst->state()->gui_shown = 1;
105  return PlugUIBase::on_window_show(title);
106 }
107 
108 void
110 {
111  _vst->state()->gui_shown = 0;
113 }
114 
115 
116 bool
117 VSTPluginUI::configure_handler (GdkEventConfigure*)
118 {
119 #ifdef GDK_WINDOWING_X11
120  XEvent event;
121  gint x, y;
122  GdkWindow* w;
123 
124  if ((w = _socket.gobj()->plug_window) == 0) {
125  return false;
126  }
127 
128  event.xconfigure.type = ConfigureNotify;
129  event.xconfigure.event = GDK_WINDOW_XWINDOW (w);
130  event.xconfigure.window = GDK_WINDOW_XWINDOW (w);
131 
132  /* The ICCCM says that synthetic events should have root relative
133  * coordinates. We still aren't really ICCCM compliant, since
134  * we don't send events when the real toplevel is moved.
135  */
136  gdk_error_trap_push ();
137  gdk_window_get_origin (w, &x, &y);
138  gdk_error_trap_pop ();
139 
140  event.xconfigure.x = x;
141  event.xconfigure.y = y;
142  event.xconfigure.width = GTK_WIDGET (_socket.gobj())->allocation.width;
143  event.xconfigure.height = GTK_WIDGET (_socket.gobj())->allocation.height;
144 
145  event.xconfigure.border_width = 0;
146  event.xconfigure.above = None;
147  event.xconfigure.override_redirect = False;
148 
149  gdk_error_trap_push ();
150  XSendEvent (GDK_WINDOW_XDISPLAY (w), GDK_WINDOW_XWINDOW (w), False, StructureNotifyMask, &event);
151  gdk_error_trap_pop ();
152 
153 #endif
154  return false;
155 }
bool configure_handler(GdkEventConfigure *)
ArdourDropdown _preset_combo
Definition: plugin_ui.h:119
Gtk::Socket _socket
Definition: vst_plugin_ui.h:50
ArdourButton delete_button
Definition: plugin_ui.h:127
void on_window_hide()
virtual int package(Gtk::Window &)
ArdourButton bypass_button
Definition: plugin_ui.h:131
virtual ~VSTPluginUI()
VSTState * state() const
Definition: vst_plugin.h:75
void preset_selected(ARDOUR::Plugin::PresetRecord preset)
Gtk::EventBox focus_button
Definition: plugin_ui.h:133
virtual bool on_window_show(const std::string &)
Definition: plugin_ui.h:103
int height
Definition: vst_types.h:96
bool on_window_show(const std::string &title)
void set_active(bool)
ArdourButton add_button
Definition: plugin_ui.h:123
int voffset
Definition: vst_types.h:99
virtual int get_preferred_height()
int width
Definition: vst_types.h:95
int hoffset
Definition: vst_types.h:100
int gui_shown
Definition: vst_types.h:101
virtual void on_window_hide()
Definition: plugin_ui.h:104
bool active() const
Definition: processor.h:61
boost::shared_ptr< ARDOUR::VSTPlugin > _vst
Definition: vst_plugin_ui.h:49
ArdourButton reset_button
Definition: plugin_ui.h:129
virtual int get_preferred_width()
virtual int get_XID()=0
virtual void preset_selected(ARDOUR::Plugin::PresetRecord preset)
Definition: plugin_ui.cc:558
ArdourButton save_button
Definition: plugin_ui.h:125
VSTPluginUI(boost::shared_ptr< ARDOUR::PluginInsert >, boost::shared_ptr< ARDOUR::VSTPlugin >)