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 create_mac_vst_gui (boost::shared_ptr<PluginInsert> insert)
46 /* PluginUIWindow::create_mac_vst_editor assures this cast works */
47 boost::shared_ptr<MacVSTPlugin> mvst = boost::dynamic_pointer_cast<MacVSTPlugin> (insert->plugin());
48 return new MacVSTPluginUI (insert, mvst);
52 MacVSTPluginUI::MacVSTPluginUI (boost::shared_ptr<PluginInsert> pi, boost::shared_ptr<VSTPlugin> vst)
53 : VSTPluginUI (pi, vst)
56 low_box.add_events (Gdk::VISIBILITY_NOTIFY_MASK | Gdk::EXPOSURE_MASK);
57 low_box.signal_realize().connect (mem_fun (this, &MacVSTPluginUI::lower_box_realized));
58 pack_start (low_box, true, true);
60 vst->LoadPresetProgram.connect (_program_connection, invalidator (*this), boost::bind (&MacVSTPluginUI::set_program, this), gui_context());
64 MacVSTPluginUI::~MacVSTPluginUI ()
67 [_ns_view removeFromSuperview];
71 AEffect* plugin = _vst->state()->plugin;
72 plugin->dispatcher (plugin, effEditClose, 0, 0, 0, 0.0f);
73 _idle_connection.disconnect();
77 MacVSTPluginUI::get_nswindow ()
79 Gtk::Container* toplevel = get_toplevel();
80 if (!toplevel || !toplevel->is_toplevel()) {
81 error << _("MacVSTPluginUI: no top level window!") << endmsg;
84 NSWindow* true_parent = gdk_quartz_window_get_nswindow (toplevel->get_window()->gobj());
87 error << _("MacVSTPluginUI: no top level window!") << endmsg;
95 MacVSTPluginUI::package (Gtk::Window& win)
97 VSTPluginUI::package (win);
102 MacVSTPluginUI::forward_key_event (GdkEventKey* ev)
107 MacVSTPluginUI::lower_box_realized ()
109 NSWindow* win = get_nswindow ();
114 [win setAutodisplay:1]; // turn off GTK stuff for this window
116 NSView* view = gdk_quartz_window_get_nsview (low_box.get_window()->gobj());
117 _ns_view = [[NSView new] retain];
118 [view addSubview:_ns_view];
120 AEffect* plugin = _vst->state()->plugin;
121 plugin->dispatcher (plugin, effEditOpen, 0, 0, _ns_view, 0.0f);
123 struct ERect* er = NULL;
124 plugin->dispatcher (plugin, effEditGetRect, 0, 0, &er, 0 );
126 int req_width = er->right - er->left;
127 int req_height = er->bottom - er->top;
129 low_box.set_size_request (req_width, req_height);
132 gtk_widget_translate_coordinates(
133 GTK_WIDGET(low_box.gobj()),
134 GTK_WIDGET(low_box.get_parent()->gobj()),
136 [_ns_view setFrame:NSMakeRect(xx, yy, req_width, req_height)];
139 _idle_connection = Glib::signal_idle().connect (sigc::mem_fun (*this, &MacVSTPluginUI::idle));
143 MacVSTPluginUI::get_XID ()
145 return _vst->state()->xid;
149 MacVSTPluginUI::idle ()
151 AEffect* plugin = _vst->state()->plugin;
152 _vst->state()->wantIdle = plugin->dispatcher (plugin, effEditIdle, 0, 0, NULL, 0);
153 return true; // _vst->state()->wantIdle;
157 MacVSTPluginUI::set_program ()
159 vststate_maybe_set_program (_vst->state());