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 "ardour/plugin_insert.h"
25 #include "ardour/mac_vst_plugin.h"
26 #include "ardour/vst_types.h"
27 #include "mac_vst_plugin_ui.h"
32 using namespace ARDOUR;
43 create_mac_vst_gui (boost::shared_ptr<PluginInsert> insert)
45 /* PluginUIWindow::create_mac_vst_editor assures this cast works */
46 boost::shared_ptr<MacVSTPlugin> mvst = boost::dynamic_pointer_cast<MacVSTPlugin> (insert->plugin());
47 return new MacVSTPluginUI (insert, mvst);
51 MacVSTPluginUI::MacVSTPluginUI (boost::shared_ptr<PluginInsert> pi, boost::shared_ptr<VSTPlugin> vst)
52 : VSTPluginUI (pi, vst)
55 low_box.add_events (Gdk::VISIBILITY_NOTIFY_MASK | Gdk::EXPOSURE_MASK);
56 low_box.signal_realize().connect (mem_fun (this, &MacVSTPluginUI::lower_box_realized));
57 pack_start (low_box, true, true);
61 MacVSTPluginUI::~MacVSTPluginUI ()
64 [_ns_view removeFromSuperview];
68 AEffect* plugin = _vst->state()->plugin;
69 plugin->dispatcher (plugin, effEditClose, 0, 0, 0, 0.0f);
70 _idle_connection.disconnect();
74 MacVSTPluginUI::get_nswindow ()
76 Gtk::Container* toplevel = get_toplevel();
77 if (!toplevel || !toplevel->is_toplevel()) {
78 error << _("MacVSTPluginUI: no top level window!") << endmsg;
81 NSWindow* true_parent = gdk_quartz_window_get_nswindow (toplevel->get_window()->gobj());
84 error << _("MacVSTPluginUI: no top level window!") << endmsg;
92 MacVSTPluginUI::package (Gtk::Window& win)
94 VSTPluginUI::package (win);
99 MacVSTPluginUI::forward_key_event (GdkEventKey* ev)
104 MacVSTPluginUI::lower_box_realized ()
106 NSWindow* win = get_nswindow ();
111 [win setAutodisplay:1]; // turn off GTK stuff for this window
113 NSView* view = gdk_quartz_window_get_nsview (low_box.get_window()->gobj());
114 _ns_view = [[NSView new] retain];
115 [view addSubview:_ns_view];
117 AEffect* plugin = _vst->state()->plugin;
118 plugin->dispatcher (plugin, effEditOpen, 0, 0, _ns_view, 0.0f);
120 struct ERect* er = NULL;
121 plugin->dispatcher (plugin, effEditGetRect, 0, 0, &er, 0 );
123 int req_width = er->right - er->left;
124 int req_height = er->bottom - er->top;
126 low_box.set_size_request (req_width, req_height);
129 gtk_widget_translate_coordinates(
130 GTK_WIDGET(low_box.gobj()),
131 GTK_WIDGET(low_box.get_parent()->gobj()),
133 [_ns_view setFrame:NSMakeRect(xx, yy, req_width, req_height)];
136 _idle_connection = Glib::signal_idle().connect (sigc::mem_fun (*this, &MacVSTPluginUI::idle));
140 MacVSTPluginUI::get_XID ()
142 return _vst->state()->xid;
146 MacVSTPluginUI::idle ()
148 AEffect* plugin = _vst->state()->plugin;
149 _vst->state()->wantIdle = plugin->dispatcher (plugin, effEditIdle, 0, 0, NULL, 0);
150 return true; // _vst->state()->wantIdle;