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 <pbd/transmitter.h>
22 #include <pbd/xml++.h>
24 #include <ardour/audioengine.h>
25 #include <ardour/audio_unit.h>
26 #include <ardour/session.h>
27 #include <ardour/utils.h>
29 #include <appleutility/CAAudioUnit.h>
31 #include <CoreServices/CoreServices.h>
32 #include <AudioUnit/AudioUnit.h>
38 using namespace ARDOUR;
40 AUPlugin::AUPlugin (AudioEngine& engine, Session& session, CAComponent* _comp)
42 Plugin (engine, session),
44 unit (new CAAudioUnit)
46 OSErr err = CAAudioUnit::Open (*comp, *unit);
48 error << _("AudioUnit: Could not convert CAComponent to CAAudioUnit") << endmsg;
51 throw failed_constructor ();
57 AUPlugin::~AUPlugin ()
60 unit->Uninitialize ();
69 AUPluginInfo::~AUPluginInfo ()
77 AUPlugin::unique_id () const
83 AUPlugin::label () const
89 AUPlugin::maker () const
95 AUPlugin::parameter_count () const
101 AUPlugin::default_value (uint32_t port)
107 AUPlugin::latency () const
113 AUPlugin::set_parameter (uint32_t which, float val)
119 AUPlugin::get_parameter (uint32_t which) const
125 AUPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const
131 AUPlugin::nth_parameter (uint32_t which, bool& ok) const
137 AUPlugin::activate ()
143 AUPlugin::deactivate ()
149 AUPlugin::set_block_size (jack_nframes_t nframes)
155 AUPlugin::connect_and_run (vector<Sample*>& bufs, uint32_t maxbuf, int32_t& in, int32_t& out, jack_nframes_t nframes, jack_nframes_t offset)
161 AUPlugin::automatable() const
163 set<uint32_t> automates;
169 AUPlugin::store_state (ARDOUR::PluginState&)
175 AUPlugin::restore_state (ARDOUR::PluginState&)
181 AUPlugin::describe_parameter (uint32_t)
187 AUPlugin::print_parameter (uint32_t, char*, uint32_t len) const
193 AUPlugin::parameter_is_audio (uint32_t) const
199 AUPlugin::parameter_is_control (uint32_t) const
205 AUPlugin::parameter_is_input (uint32_t) const
211 AUPlugin::parameter_is_output (uint32_t) const
217 AUPlugin::get_state()
219 XMLNode* root = new XMLNode (state_node_name());
225 AUPlugin::set_state(const XMLNode& node)
231 AUPlugin::save_preset (string name)
237 AUPlugin::load_preset (const string preset_label)
243 AUPlugin::get_presets ()
245 vector<string> presets;
251 AUPlugin::has_editor () const
257 AUPluginInfo::load (Session& session)
262 CAComponent* comp = new CAComponent(*desc);
264 if (!comp->IsValid()) {
265 error << ("AudioUnit: not a valid Component") << endmsg;
267 plugin.reset (new AUPlugin (session.engine(), session, comp));
270 plugin->set_info(PluginInfoPtr(new AUPluginInfo(*this)));
274 catch (failed_constructor &err) {
275 return PluginPtr ((Plugin*) 0);
280 AUPluginInfo::discover ()
282 PluginInfoList plugs;
284 int numTypes = 2; // this magic number was retrieved from the apple AUHost example.
286 CAComponentDescription desc;
287 desc.componentFlags = 0;
288 desc.componentFlagsMask = 0;
289 desc.componentSubType = 0;
290 desc.componentManufacturer = 0;
292 for (int i = 0; i < numTypes; ++i) {
294 desc.componentType = kAudioUnitType_MusicEffect;
296 desc.componentType = kAudioUnitType_Effect;
301 comp = FindNextComponent (NULL, &desc);
302 while (comp != NULL) {
303 CAComponentDescription temp;
304 GetComponentInfo (comp, &temp, NULL, NULL, NULL);
306 AUPluginInfoPtr plug(new AUPluginInfo);
307 plug->name = AUPluginInfo::get_name (temp);
308 plug->type = PluginInfo::AudioUnit;
311 plug->category = "AudioUnit";
312 plug->desc = new CAComponentDescription(temp);
314 plugs.push_back(plug);
316 comp = FindNextComponent (comp, &desc);
324 AUPluginInfo::get_name (CAComponentDescription& comp_desc)
326 CFStringRef itemName = NULL;
327 // Marc Poirier -style item name
328 CAComponent auComponent (comp_desc);
329 if (auComponent.IsValid()) {
330 CAComponentDescription dummydesc;
331 Handle nameHandle = NewHandle(sizeof(void*));
332 if (nameHandle != NULL) {
333 OSErr err = GetComponentInfo(auComponent.Comp(), &dummydesc, nameHandle, NULL, NULL);
335 ConstStr255Param nameString = (ConstStr255Param) (*nameHandle);
336 if (nameString != NULL) {
337 itemName = CFStringCreateWithPascalString(kCFAllocatorDefault, nameString, CFStringGetSystemEncoding());
340 DisposeHandle(nameHandle);
344 // if Marc-style fails, do the original way
345 if (itemName == NULL) {
346 CFStringRef compTypeString = UTCreateStringForOSType(comp_desc.componentType);
347 CFStringRef compSubTypeString = UTCreateStringForOSType(comp_desc.componentSubType);
348 CFStringRef compManufacturerString = UTCreateStringForOSType(comp_desc.componentManufacturer);
350 itemName = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ - %@ - %@"),
351 compTypeString, compManufacturerString, compSubTypeString);
353 if (compTypeString != NULL)
354 CFRelease(compTypeString);
355 if (compSubTypeString != NULL)
356 CFRelease(compSubTypeString);
357 if (compManufacturerString != NULL)
358 CFRelease(compManufacturerString);
361 return CFStringRefToStdString(itemName);