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 <gdk/gdkquartz.h>
24 #include "gui_thread.h"
25 #include "ardour/plugin_insert.h"
26 #include "ardour/mac_vst_plugin.h"
27 #include "ardour/vst_types.h"
28 #include "mac_vst_plugin_ui.h"
33 using namespace ARDOUR;
44 @implementation ResizeNotificationObject
46 - (ResizeNotificationObject*) initWithPluginUI: (MacVSTPluginUI*) vstui
48 self = [ super init ];
53 - (void)viewResized:(NSNotification *)notification
55 (void) notification; // unused
56 plugin_ui->view_resized();
62 create_mac_vst_gui (boost::shared_ptr<PluginInsert> insert)
64 /* PluginUIWindow::create_mac_vst_editor assures this cast works */
65 boost::shared_ptr<MacVSTPlugin> mvst = boost::dynamic_pointer_cast<MacVSTPlugin> (insert->plugin());
66 return new MacVSTPluginUI (insert, mvst);
70 MacVSTPluginUI::MacVSTPluginUI (boost::shared_ptr<PluginInsert> pi, boost::shared_ptr<VSTPlugin> vst)
71 : VSTPluginUI (pi, vst)
74 low_box.add_events (Gdk::VISIBILITY_NOTIFY_MASK | Gdk::EXPOSURE_MASK);
75 low_box.signal_realize().connect (mem_fun (this, &MacVSTPluginUI::lower_box_realized));
76 low_box.signal_visibility_notify_event ().connect (mem_fun (this, &MacVSTPluginUI::lower_box_visibility_notify));
77 low_box.signal_size_request ().connect (mem_fun (this, &MacVSTPluginUI::lower_box_size_request));
78 low_box.signal_size_allocate ().connect (mem_fun (this, &MacVSTPluginUI::lower_box_size_allocate));
79 low_box.signal_map ().connect (mem_fun (this, &MacVSTPluginUI::lower_box_map));
80 low_box.signal_unmap ().connect (mem_fun (this, &MacVSTPluginUI::lower_box_unmap));
82 pack_start (low_box, true, true);
85 vst->LoadPresetProgram.connect (_program_connection, invalidator (*this), boost::bind (&MacVSTPluginUI::set_program, this), gui_context());
87 _ns_view = [[NSView new] retain];
89 AEffect* plugin = _vst->state()->plugin;
90 plugin->dispatcher (plugin, effEditOpen, 0, 0, _ns_view, 0.0f);
91 _idle_connection = Glib::signal_idle().connect (sigc::mem_fun (*this, &MacVSTPluginUI::idle));
93 _resize_notifier = [[ResizeNotificationObject alloc] initWithPluginUI:this];
94 [[NSNotificationCenter defaultCenter] addObserver:_resize_notifier
95 selector:@selector(viewResized:) name:NSViewFrameDidChangeNotification
98 NSArray* subviews = [_ns_view subviews];
99 assert ([subviews count] < 2);
100 for (unsigned long i = 0; i < [subviews count]; ++i) {
101 NSView* subview = [subviews objectAtIndex:i];
102 [[NSNotificationCenter defaultCenter] addObserver:_resize_notifier
103 selector:@selector(viewResized:) name:NSViewFrameDidChangeNotification
108 MacVSTPluginUI::~MacVSTPluginUI ()
110 [[NSNotificationCenter defaultCenter] removeObserver:_resize_notifier];
111 [_resize_notifier release];
113 [_ns_view removeFromSuperview];
116 AEffect* plugin = _vst->state()->plugin;
117 plugin->dispatcher (plugin, effEditClose, 0, 0, 0, 0.0f);
118 _idle_connection.disconnect();
122 MacVSTPluginUI::get_nswindow ()
124 Gtk::Container* toplevel = get_toplevel();
125 if (!toplevel || !toplevel->is_toplevel()) {
126 error << _("MacVSTPluginUI: no top level window!") << endmsg;
129 NSWindow* true_parent = gdk_quartz_window_get_nswindow (toplevel->get_window()->gobj());
132 error << _("MacVSTPluginUI: no top level window!") << endmsg;
140 MacVSTPluginUI::package (Gtk::Window& win)
142 VSTPluginUI::package (win);
147 MacVSTPluginUI::forward_key_event (GdkEventKey* ev)
152 MacVSTPluginUI::lower_box_realized ()
154 NSWindow* win = get_nswindow ();
159 [win setAutodisplay:1]; // turn off GTK stuff for this window
161 NSView* view = gdk_quartz_window_get_nsview (low_box.get_window()->gobj());
162 [view addSubview:_ns_view];
163 low_box.queue_resize ();
167 MacVSTPluginUI::lower_box_visibility_notify (GdkEventVisibility* ev)
172 MacVSTPluginUI::lower_box_map ()
174 [_ns_view setHidden:0];
178 MacVSTPluginUI::lower_box_unmap ()
180 [_ns_view setHidden:1];
184 MacVSTPluginUI::lower_box_size_request (GtkRequisition* requisition)
186 struct ERect* er = NULL;
187 AEffect* plugin = _vst->state()->plugin;
188 plugin->dispatcher (plugin, effEditGetRect, 0, 0, &er, 0 );
190 requisition->width = er->right - er->left;
191 requisition->height = er->bottom - er->top;
193 requisition->width = 600;
194 requisition->height = 400;
199 MacVSTPluginUI::lower_box_size_allocate (Gtk::Allocation& allocation)
202 gtk_widget_translate_coordinates(
203 GTK_WIDGET(low_box.gobj()),
204 GTK_WIDGET(low_box.get_parent()->gobj()),
206 [_ns_view setFrame:NSMakeRect (xx, yy, allocation.get_width (), allocation.get_height ())];
207 NSArray* subviews = [_ns_view subviews];
208 for (unsigned long i = 0; i < [subviews count]; ++i) {
209 NSView* subview = [subviews objectAtIndex:i];
210 [subview setFrame:NSMakeRect (0, 0, allocation.get_width (), allocation.get_height ())];
215 MacVSTPluginUI::view_resized ()
217 low_box.queue_resize ();
221 MacVSTPluginUI::get_XID ()
223 return _vst->state()->xid; // unused
227 MacVSTPluginUI::idle ()
229 AEffect* plugin = _vst->state()->plugin;
230 _vst->state()->wantIdle = plugin->dispatcher (plugin, effEditIdle, 0, 0, NULL, 0);
231 return true; // _vst->state()->wantIdle;
235 MacVSTPluginUI::set_program ()
237 vststate_maybe_set_program (_vst->state());