2 Copyright (C) 2006 Paul Davis
3 Written by Taybin Rutkin
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <ardour/audio_unit.h>
22 #include <ardour/insert.h>
24 #include <gtkmm2ext/doi.h>
26 #include "au_pluginui.h"
27 #include "gui_thread.h"
29 #include <appleutility/CAAudioUnit.h>
30 #include <appleutility/CAComponent.h>
32 #include <AudioUnit/AudioUnit.h>
36 using namespace ARDOUR;
39 AUPluginUI::AUPluginUI (boost::shared_ptr<PluginInsert> insert)
41 if ((au = boost::dynamic_pointer_cast<AUPlugin> (insert->plugin())) == 0) {
42 error << _("unknown type of editor-supplying plugin (note: no AudioUnit support in this version of ardour)") << endmsg;
43 throw failed_constructor ();
48 CAComponentDescription desc;
49 Component carbonViewComponent = NULL;
50 AudioUnitCarbonView carbonView = NULL;
52 GetComponentInfo(au->get_comp()->Comp(), &desc, 0, 0, 0);
53 carbonViewComponent = get_carbon_view_component(desc.componentSubType);
54 err = OpenAComponent(carbonViewComponent, &carbonView);
62 ProcessSerialNumber ourPSN;
64 /* Here we will set the MacOSX native section of the process to the foreground for putting up this
65 * dialog box. First step is to get our process serial number. We do this by calling
67 * First Argument: On success this PSN will be our PSN on return.
68 * Return Value: A Macintosh error indicating success or failure.
70 err = GetCurrentProcess(&ourPSN);
72 //If no error then set this process to be frontmost.
74 /* Calling SetFrontProcess to make us frontmost.
75 * First Argument: The Process Serial Number of the process we want to make frontmost. Here
76 * of course we pass our process serial number
77 * Return Value: An error value indicating success or failure. We just ignore the return
80 (void)SetFrontProcess(&ourPSN);
82 error << "couldn't get current process" << endmsg;
85 err = CreateNewWindow (kDocumentWindowClass, kWindowStandardFloatingAttributes, &rec, &wr);
87 ComponentResult auResult;
88 ControlRef rootControl = NULL;
89 GetRootControl(wr, &rootControl);
93 Float32Point location = {30, 30};
94 Float32Point size = {width, height};
95 ControlRef audioUnitControl = NULL;
97 auResult = AudioUnitCarbonViewCreate(carbonView,
107 // AudioUnitCarbonViewSetEventListener(carbonView, EventListener, this);
109 set_name ("PluginEditor");
110 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
112 signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window*> (this)));
115 insert->GoingAway.connect (mem_fun(*this, &AUPluginUI::plugin_going_away));
117 info << "AUPluginUI created" << endmsg;
120 AUPluginUI::~AUPluginUI ()
122 // nothing to do here - plugin destructor destroys the GUI
126 AUPluginUI::plugin_going_away (ARDOUR::Redirect* ignored)
128 ENSURE_GUI_THREAD(bind (mem_fun(*this, &AUPluginUI::plugin_going_away), ignored));
130 delete_when_idle (this);
134 AUPluginUI::get_carbon_view_component(OSType subtype)
136 ComponentDescription desc;
139 desc.componentType = kAudioUnitCarbonViewComponentType; // 'auvw'
140 desc.componentSubType = subtype;
141 desc.componentManufacturer = 0;
142 desc.componentFlags = 0;
143 desc.componentFlagsMask = 0;
145 // First see if we can find a carbon view designed specifically for this
148 component = FindNextComponent(NULL, &desc);
152 // If not, grab the generic carbon view, which will create a GUI for
155 desc.componentSubType = kAUCarbonViewSubType_Generic;
156 component = FindNextComponent(NULL, &desc);