2 Copyright (C) 2006 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 <pbd/transmitter.h>
23 #include <pbd/xml++.h>
24 #include <pbd/whitespace.h>
26 #include <glibmm/thread.h>
27 #include <glibmm/fileutils.h>
28 #include <glibmm/miscutils.h>
30 #include <ardour/ardour.h>
31 #include <ardour/audioengine.h>
32 #include <ardour/io.h>
33 #include <ardour/audio_unit.h>
34 #include <ardour/session.h>
35 #include <ardour/utils.h>
37 #include <appleutility/CAAudioUnit.h>
38 #include <appleutility/CAAUParameter.h>
40 #include <CoreServices/CoreServices.h>
41 #include <AudioUnit/AudioUnit.h>
47 using namespace ARDOUR;
49 AUPluginInfo::CachedInfoMap AUPluginInfo::cached_info;
52 _render_callback(void *userData,
53 AudioUnitRenderActionFlags *ioActionFlags,
54 const AudioTimeStamp *inTimeStamp,
56 UInt32 inNumberFrames,
57 AudioBufferList* ioData)
59 return ((AUPlugin*)userData)->render_callback (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
62 AUPlugin::AUPlugin (AudioEngine& engine, Session& session, boost::shared_ptr<CAComponent> _comp)
63 : Plugin (engine, session),
65 unit (new CAAudioUnit),
76 AUPlugin::AUPlugin (const AUPlugin& other)
78 , comp (other.get_comp())
79 , unit (new CAAudioUnit)
85 , frames_processed (0)
91 AUPlugin::~AUPlugin ()
94 unit->Uninitialize ();
109 err = CAAudioUnit::Open (*(comp.get()), *unit);
111 error << _("Exception thrown during AudioUnit plugin loading - plugin ignored") << endmsg;
112 cerr << _("Exception thrown during AudioUnit plugin loading - plugin ignored") << endl;
113 throw failed_constructor();
117 error << _("AudioUnit: Could not convert CAComponent to CAAudioUnit") << endmsg;
118 throw failed_constructor ();
121 AURenderCallbackStruct renderCallbackInfo;
123 renderCallbackInfo.inputProc = _render_callback;
124 renderCallbackInfo.inputProcRefCon = this;
126 if ((err = unit->SetProperty (kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
127 0, (void*) &renderCallbackInfo, sizeof(renderCallbackInfo))) != 0) {
128 cerr << "cannot install render callback (err = " << err << ')' << endl;
129 throw failed_constructor();
132 unit->GetElementCount (kAudioUnitScope_Global, global_elements);
133 unit->GetElementCount (kAudioUnitScope_Input, input_elements);
134 unit->GetElementCount (kAudioUnitScope_Output, output_elements);
136 /* these keep track of *configured* channel set up,
137 not potential set ups.
141 output_channels = -1;
143 if (_set_block_size (_session.get_block_size())) {
144 error << _("AUPlugin: cannot set processing block size") << endmsg;
145 throw failed_constructor();
148 discover_parameters ();
150 Plugin::setup_controls ();
154 AUPlugin::discover_parameters ()
156 /* discover writable parameters */
158 AudioUnitScope scopes[] = {
159 kAudioUnitScope_Global,
160 kAudioUnitScope_Output,
161 kAudioUnitScope_Input
164 descriptors.clear ();
166 for (uint32_t i = 0; i < sizeof (scopes) / sizeof (scopes[0]); ++i) {
168 AUParamInfo param_info (unit->AU(), false, false, scopes[i]);
170 for (uint32_t i = 0; i < param_info.NumParams(); ++i) {
172 AUParameterDescriptor d;
174 d.id = param_info.ParamID (i);
176 const CAAUParameter* param = param_info.GetParamInfo (d.id);
177 const AudioUnitParameterInfo& info (param->ParamInfo());
179 const int len = CFStringGetLength (param->GetName());;
180 char local_buffer[len*2];
181 Boolean good = CFStringGetCString(param->GetName(),local_buffer,len*2,kCFStringEncodingMacRoman);
185 d.label = local_buffer;
188 d.scope = param_info.GetScope ();
189 d.element = param_info.GetElement ();
191 /* info.units to consider */
193 kAudioUnitParameterUnit_Generic = 0
194 kAudioUnitParameterUnit_Indexed = 1
195 kAudioUnitParameterUnit_Boolean = 2
196 kAudioUnitParameterUnit_Percent = 3
197 kAudioUnitParameterUnit_Seconds = 4
198 kAudioUnitParameterUnit_SampleFrames = 5
199 kAudioUnitParameterUnit_Phase = 6
200 kAudioUnitParameterUnit_Rate = 7
201 kAudioUnitParameterUnit_Hertz = 8
202 kAudioUnitParameterUnit_Cents = 9
203 kAudioUnitParameterUnit_RelativeSemiTones = 10
204 kAudioUnitParameterUnit_MIDINoteNumber = 11
205 kAudioUnitParameterUnit_MIDIController = 12
206 kAudioUnitParameterUnit_Decibels = 13
207 kAudioUnitParameterUnit_LinearGain = 14
208 kAudioUnitParameterUnit_Degrees = 15
209 kAudioUnitParameterUnit_EqualPowerCrossfade = 16
210 kAudioUnitParameterUnit_MixerFaderCurve1 = 17
211 kAudioUnitParameterUnit_Pan = 18
212 kAudioUnitParameterUnit_Meters = 19
213 kAudioUnitParameterUnit_AbsoluteCents = 20
214 kAudioUnitParameterUnit_Octaves = 21
215 kAudioUnitParameterUnit_BPM = 22
216 kAudioUnitParameterUnit_Beats = 23
217 kAudioUnitParameterUnit_Milliseconds = 24
218 kAudioUnitParameterUnit_Ratio = 25
221 /* info.flags to consider */
225 kAudioUnitParameterFlag_CFNameRelease = (1L << 4)
226 kAudioUnitParameterFlag_HasClump = (1L << 20)
227 kAudioUnitParameterFlag_HasName = (1L << 21)
228 kAudioUnitParameterFlag_DisplayLogarithmic = (1L << 22)
229 kAudioUnitParameterFlag_IsHighResolution = (1L << 23)
230 kAudioUnitParameterFlag_NonRealTime = (1L << 24)
231 kAudioUnitParameterFlag_CanRamp = (1L << 25)
232 kAudioUnitParameterFlag_ExpertMode = (1L << 26)
233 kAudioUnitParameterFlag_HasCFNameString = (1L << 27)
234 kAudioUnitParameterFlag_IsGlobalMeta = (1L << 28)
235 kAudioUnitParameterFlag_IsElementMeta = (1L << 29)
236 kAudioUnitParameterFlag_IsReadable = (1L << 30)
237 kAudioUnitParameterFlag_IsWritable = (1L << 31)
240 d.lower = info.minValue;
241 d.upper = info.maxValue;
242 d.default_value = info.defaultValue;
244 d.integer_step = (info.unit & kAudioUnitParameterUnit_Indexed);
245 d.toggled = (info.unit & kAudioUnitParameterUnit_Boolean) ||
246 (d.integer_step && ((d.upper - d.lower) == 1.0));
247 d.sr_dependent = (info.unit & kAudioUnitParameterUnit_SampleFrames);
248 d.automatable = !d.toggled &&
249 !(info.flags & kAudioUnitParameterFlag_NonRealTime) &&
250 (info.flags & kAudioUnitParameterFlag_IsWritable);
252 d.logarithmic = (info.flags & kAudioUnitParameterFlag_DisplayLogarithmic);
258 d.min_unbound = 0; // lower is bound
259 d.max_unbound = 0; // upper is bound
261 descriptors.push_back (d);
268 AUPlugin::unique_id () const
270 return AUPluginInfo::stringify_descriptor (comp->Desc());
274 AUPlugin::label () const
276 return _info->name.c_str();
280 AUPlugin::parameter_count () const
282 return descriptors.size();
286 AUPlugin::default_value (uint32_t port)
288 if (port < descriptors.size()) {
289 return descriptors[port].default_value;
296 AUPlugin::latency () const
298 return unit->Latency() * _session.frame_rate();
302 AUPlugin::set_parameter (uint32_t which, float val)
304 if (which < descriptors.size()) {
305 const AUParameterDescriptor& d (descriptors[which]);
306 unit->SetParameter (d.id, d.scope, d.element, val);
311 AUPlugin::get_parameter (uint32_t which) const
314 if (which < descriptors.size()) {
315 const AUParameterDescriptor& d (descriptors[which]);
316 unit->GetParameter(d.id, d.scope, d.element, val);
322 AUPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& pd) const
324 if (which < descriptors.size()) {
325 pd = descriptors[which];
332 AUPlugin::nth_parameter (uint32_t which, bool& ok) const
334 if (which < descriptors.size()) {
343 AUPlugin::activate ()
347 if ((err = unit->Initialize()) != noErr) {
348 error << string_compose (_("AUPlugin: %1 cannot initialize plugin (err = %2)"), name(), err) << endmsg;
350 frames_processed = 0;
357 AUPlugin::deactivate ()
359 unit->GlobalReset ();
363 AUPlugin::set_block_size (nframes_t nframes)
365 _set_block_size (nframes);
369 AUPlugin::_set_block_size (nframes_t nframes)
371 bool was_initialized = initialized;
372 UInt32 numFrames = nframes;
376 unit->Uninitialize ();
379 if ((err = unit->SetProperty (kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global,
380 0, &numFrames, sizeof (numFrames))) != noErr) {
381 cerr << "cannot set max frames (err = " << err << ')' << endl;
385 if (was_initialized) {
393 AUPlugin::configure_io (int32_t in, int32_t out)
395 AudioStreamBasicDescription streamFormat;
397 streamFormat.mSampleRate = _session.frame_rate();
398 streamFormat.mFormatID = kAudioFormatLinearPCM;
399 streamFormat.mFormatFlags = kAudioFormatFlagIsFloat|kAudioFormatFlagIsPacked|kAudioFormatFlagIsNonInterleaved;
401 #ifdef __LITTLE_ENDIAN__
404 streamFormat.mFormatFlags |= kAudioFormatFlagIsBigEndian;
407 streamFormat.mBitsPerChannel = 32;
408 streamFormat.mFramesPerPacket = 1;
410 /* apple says that for non-interleaved data, these
411 values always refer to a single channel.
413 streamFormat.mBytesPerPacket = 4;
414 streamFormat.mBytesPerFrame = 4;
416 streamFormat.mChannelsPerFrame = in;
418 if (set_input_format (streamFormat) != 0) {
422 streamFormat.mChannelsPerFrame = out;
424 if (set_output_format (streamFormat) != 0) {
428 return Plugin::configure_io (in, out);
432 AUPlugin::can_do (int32_t in, int32_t& out)
434 // XXX as of May 13th 2008, AU plugin support returns a count of either 1 or -1. We never
435 // attempt to multiply-instantiate plugins to meet io configurations.
437 int32_t plugcnt = -1;
438 AUPluginInfoPtr pinfo = boost::dynamic_pointer_cast<AUPluginInfo>(get_info());
442 vector<pair<int,int> >& io_configs = pinfo->cache.io_configs;
444 for (vector<pair<int,int> >::iterator i = io_configs.begin(); i != io_configs.end(); ++i) {
446 int32_t possible_in = i->first;
447 int32_t possible_out = i->second;
449 if (possible_out == 0) {
450 warning << string_compose (_("AU %1 has zero outputs - configuration ignored"), name()) << endmsg;
454 if (possible_in == 0) {
456 /* instrument plugin, always legal but throws away inputs ...
459 if (possible_out == -1) {
460 /* out much match in (UNLIKELY!!) */
463 } else if (possible_out == -2) {
464 /* any configuration possible, pick matching */
467 } else if (possible_out < -2) {
468 /* explicit variable number of outputs, pick maximum */
472 /* exact number of outputs */
478 if (possible_in == -1) {
480 /* wildcard for input */
482 if (possible_out == -1) {
483 /* out much match in */
486 } else if (possible_out == -2) {
487 /* any configuration possible, pick matching */
490 } else if (possible_out < -2) {
491 /* explicit variable number of outputs, pick maximum */
495 /* exact number of outputs */
501 if (possible_in == -2) {
503 if (possible_out == -1) {
504 /* any configuration possible, pick matching */
507 } else if (possible_out == -2) {
508 error << string_compose (_("AU plugin %1 has illegal IO configuration (-2,-2)"), name())
511 } else if (possible_out < -2) {
512 /* explicit variable number of outputs, pick maximum */
516 /* exact number of outputs */
522 if (possible_in < -2) {
524 /* explicit variable number of inputs */
526 if (in > -possible_in) {
527 /* request is too large */
531 if (possible_out == -1) {
532 /* out must match in */
535 } else if (possible_out == -2) {
536 error << string_compose (_("AU plugin %1 has illegal IO configuration (-2,-2)"), name())
539 } else if (possible_out < -2) {
540 /* explicit variable number of outputs, pick maximum */
544 /* exact number of outputs */
550 if (possible_in == in) {
552 /* exact number of inputs ... must match obviously */
554 if (possible_out == -1) {
555 /* out must match in */
558 } else if (possible_out == -2) {
559 /* any output configuration, pick matching */
562 } else if (possible_out < -2) {
563 /* explicit variable number of outputs, pick maximum */
567 /* exact number of outputs */
580 AUPlugin::set_input_format (AudioStreamBasicDescription& fmt)
582 return set_stream_format (kAudioUnitScope_Input, input_elements, fmt);
586 AUPlugin::set_output_format (AudioStreamBasicDescription& fmt)
588 if (set_stream_format (kAudioUnitScope_Output, output_elements, fmt) != 0) {
597 buffers = (AudioBufferList *) malloc (offsetof(AudioBufferList, mBuffers) +
598 fmt.mChannelsPerFrame * sizeof(AudioBuffer));
600 Glib::Mutex::Lock em (_session.engine().process_lock());
601 IO::MoreOutputs (fmt.mChannelsPerFrame);
607 AUPlugin::set_stream_format (int scope, uint32_t cnt, AudioStreamBasicDescription& fmt)
611 for (uint32_t i = 0; i < cnt; ++i) {
612 if ((result = unit->SetFormat (scope, i, fmt)) != 0) {
613 error << string_compose (_("AUPlugin: could not set stream format for %1/%2 (err = %3)"),
614 (scope == kAudioUnitScope_Input ? "input" : "output"), i, result) << endmsg;
619 if (scope == kAudioUnitScope_Input) {
620 input_channels = fmt.mChannelsPerFrame;
622 output_channels = fmt.mChannelsPerFrame;
629 AUPlugin::input_streams() const
631 if (input_channels < 0) {
632 warning << string_compose (_("AUPlugin: %1 input_streams() called without any format set!"), name()) << endmsg;
635 return input_channels;
640 AUPlugin::output_streams() const
642 if (output_channels < 0) {
643 warning << string_compose (_("AUPlugin: %1 output_streams() called without any format set!"), name()) << endmsg;
646 return output_channels;
650 AUPlugin::render_callback(AudioUnitRenderActionFlags *ioActionFlags,
651 const AudioTimeStamp *inTimeStamp,
653 UInt32 inNumberFrames,
654 AudioBufferList* ioData)
656 /* not much to do - the data is already in the buffers given to us in connect_and_run() */
658 if (current_maxbuf == 0) {
659 error << _("AUPlugin: render callback called illegally!") << endmsg;
660 return kAudioUnitErr_CannotDoInCurrentContext;
663 for (uint32_t i = 0; i < current_maxbuf; ++i) {
664 ioData->mBuffers[i].mNumberChannels = 1;
665 ioData->mBuffers[i].mDataByteSize = sizeof (Sample) * inNumberFrames;
666 ioData->mBuffers[i].mData = (*current_buffers)[i] + cb_offset + current_offset;
669 cb_offset += inNumberFrames;
675 AUPlugin::connect_and_run (vector<Sample*>& bufs, uint32_t maxbuf, int32_t& in, int32_t& out, nframes_t nframes, nframes_t offset)
677 AudioUnitRenderActionFlags flags = 0;
680 current_buffers = &bufs;
681 current_maxbuf = maxbuf;
682 current_offset = offset;
685 buffers->mNumberBuffers = maxbuf;
687 for (uint32_t i = 0; i < maxbuf; ++i) {
688 buffers->mBuffers[i].mNumberChannels = 1;
689 buffers->mBuffers[i].mDataByteSize = nframes * sizeof (Sample);
690 buffers->mBuffers[i].mData = 0;
693 ts.mSampleTime = frames_processed;
694 ts.mFlags = kAudioTimeStampSampleTimeValid;
696 if (unit->Render (&flags, &ts, 0, nframes, buffers) == noErr) {
699 frames_processed += nframes;
701 for (uint32_t i = 0; i < maxbuf; ++i) {
702 if (bufs[i] + offset != buffers->mBuffers[i].mData) {
703 memcpy (bufs[i]+offset, buffers->mBuffers[i].mData, nframes * sizeof (Sample));
713 AUPlugin::automatable() const
715 set<uint32_t> automates;
717 for (uint32_t i = 0; i < descriptors.size(); ++i) {
718 if (descriptors[i].automatable) {
719 automates.insert (i);
727 AUPlugin::describe_parameter (uint32_t param)
729 return descriptors[param].label;
733 AUPlugin::print_parameter (uint32_t param, char* buf, uint32_t len) const
735 // NameValue stuff here
739 AUPlugin::parameter_is_audio (uint32_t) const
745 AUPlugin::parameter_is_control (uint32_t) const
751 AUPlugin::parameter_is_input (uint32_t) const
757 AUPlugin::parameter_is_output (uint32_t) const
763 AUPlugin::get_state()
765 XMLNode *root = new XMLNode (state_node_name());
766 LocaleGuard lg (X_("POSIX"));
771 AUPlugin::set_state(const XMLNode& node)
777 AUPlugin::save_preset (string name)
783 AUPlugin::load_preset (const string preset_label)
789 AUPlugin::get_presets ()
791 vector<string> presets;
797 AUPlugin::has_editor () const
799 // even if the plugin doesn't have its own editor, the AU API can be used
800 // to create one that looks native.
804 AUPluginInfo::AUPluginInfo (boost::shared_ptr<CAComponentDescription> d)
810 AUPluginInfo::~AUPluginInfo ()
815 AUPluginInfo::load (Session& session)
820 boost::shared_ptr<CAComponent> comp (new CAComponent(*descriptor));
822 if (!comp->IsValid()) {
823 error << ("AudioUnit: not a valid Component") << endmsg;
825 plugin.reset (new AUPlugin (session.engine(), session, comp));
828 plugin->set_info (PluginInfoPtr (new AUPluginInfo (*this)));
832 catch (failed_constructor &err) {
838 AUPluginInfo::au_cache_path ()
840 return Glib::build_filename (ARDOUR::get_user_ardour_path(), "au_cache");
844 AUPluginInfo::discover ()
848 if (!Glib::file_test (au_cache_path(), Glib::FILE_TEST_EXISTS)) {
849 ARDOUR::BootMessage (_("Discovering AudioUnit plugins (could take some time ...)"));
852 PluginInfoList plugs;
855 discover_music (plugs);
861 AUPluginInfo::discover_music (PluginInfoList& plugs)
863 CAComponentDescription desc;
864 desc.componentFlags = 0;
865 desc.componentFlagsMask = 0;
866 desc.componentSubType = 0;
867 desc.componentManufacturer = 0;
868 desc.componentType = kAudioUnitType_MusicEffect;
870 discover_by_description (plugs, desc);
874 AUPluginInfo::discover_fx (PluginInfoList& plugs)
876 CAComponentDescription desc;
877 desc.componentFlags = 0;
878 desc.componentFlagsMask = 0;
879 desc.componentSubType = 0;
880 desc.componentManufacturer = 0;
881 desc.componentType = kAudioUnitType_Effect;
883 discover_by_description (plugs, desc);
887 AUPluginInfo::discover_by_description (PluginInfoList& plugs, CAComponentDescription& desc)
891 comp = FindNextComponent (NULL, &desc);
893 while (comp != NULL) {
894 CAComponentDescription temp;
895 GetComponentInfo (comp, &temp, NULL, NULL, NULL);
897 AUPluginInfoPtr info (new AUPluginInfo
898 (boost::shared_ptr<CAComponentDescription> (new CAComponentDescription(temp))));
900 /* no panners, format converters or i/o AU's for our purposes
903 switch (info->descriptor->Type()) {
904 case kAudioUnitType_Panner:
905 case kAudioUnitType_OfflineEffect:
906 case kAudioUnitType_FormatConverter:
912 switch (info->descriptor->SubType()) {
913 case kAudioUnitSubType_DefaultOutput:
914 case kAudioUnitSubType_SystemOutput:
915 case kAudioUnitSubType_GenericOutput:
916 case kAudioUnitSubType_AUConverter:
920 case kAudioUnitSubType_DLSSynth:
921 info->category = "DLSSynth";
924 case kAudioUnitType_MusicEffect:
925 info->category = "MusicEffect";
928 case kAudioUnitSubType_Varispeed:
929 info->category = "Varispeed";
932 case kAudioUnitSubType_Delay:
933 info->category = "Delay";
936 case kAudioUnitSubType_LowPassFilter:
937 info->category = "LowPassFilter";
940 case kAudioUnitSubType_HighPassFilter:
941 info->category = "HighPassFilter";
944 case kAudioUnitSubType_BandPassFilter:
945 info->category = "BandPassFilter";
948 case kAudioUnitSubType_HighShelfFilter:
949 info->category = "HighShelfFilter";
952 case kAudioUnitSubType_LowShelfFilter:
953 info->category = "LowShelfFilter";
956 case kAudioUnitSubType_ParametricEQ:
957 info->category = "ParametricEQ";
960 case kAudioUnitSubType_GraphicEQ:
961 info->category = "GraphicEQ";
964 case kAudioUnitSubType_PeakLimiter:
965 info->category = "PeakLimiter";
968 case kAudioUnitSubType_DynamicsProcessor:
969 info->category = "DynamicsProcessor";
972 case kAudioUnitSubType_MultiBandCompressor:
973 info->category = "MultiBandCompressor";
976 case kAudioUnitSubType_MatrixReverb:
977 info->category = "MatrixReverb";
980 case kAudioUnitType_Mixer:
981 info->category = "Mixer";
984 case kAudioUnitSubType_StereoMixer:
985 info->category = "StereoMixer";
988 case kAudioUnitSubType_3DMixer:
989 info->category = "3DMixer";
992 case kAudioUnitSubType_MatrixMixer:
993 info->category = "MatrixMixer";
1000 AUPluginInfo::get_names (temp, info->name, info->creator);
1002 info->type = ARDOUR::AudioUnit;
1003 info->unique_id = stringify_descriptor (*info->descriptor);
1005 /* XXX not sure of the best way to handle plugin versioning yet
1008 CAComponent cacomp (*info->descriptor);
1010 if (cacomp.GetResourceVersion (info->version) != noErr) {
1014 if (cached_io_configuration (info->unique_id, info->version, cacomp, info->cache, info->name)) {
1016 /* here we have to map apple's wildcard system to a simple pair
1020 info->n_inputs = info->cache.io_configs.front().first;
1021 info->n_outputs = info->cache.io_configs.front().second;
1023 if (info->cache.io_configs.size() > 1) {
1024 cerr << "ODD: variable IO config for " << info->unique_id << endl;
1027 plugs.push_back (info);
1030 error << string_compose (_("Cannot get I/O configuration info for AU %1"), info->name) << endmsg;
1033 comp = FindNextComponent (comp, &desc);
1038 AUPluginInfo::cached_io_configuration (const std::string& unique_id,
1041 AUPluginCachedInfo& cinfo,
1042 const std::string& name)
1047 /* concatenate unique ID with version to provide a key for cached info lookup.
1048 this ensures we don't get stale information, or should if plugin developers
1049 follow Apple "guidelines".
1052 snprintf (buf, sizeof (buf), "%u", version);
1057 CachedInfoMap::iterator cim = cached_info.find (id);
1059 if (cim != cached_info.end()) {
1060 cinfo = cim->second;
1065 AUChannelInfo* channel_info;
1069 ARDOUR::BootMessage (string_compose (_("Checking AudioUnit: %1"), name));
1073 if (CAAudioUnit::Open (comp, unit) != noErr) {
1079 warning << string_compose (_("Could not load AU plugin %1 - ignored"), name) << endmsg;
1080 cerr << string_compose (_("Could not load AU plugin %1 - ignored"), name) << endl;
1085 if ((ret = unit.GetChannelInfo (&channel_info, cnt)) < 0) {
1090 /* no explicit info available */
1092 cinfo.io_configs.push_back (pair<int,int> (-1, -1));
1096 /* store each configuration */
1098 for (uint32_t n = 0; n < cnt; ++n) {
1099 cinfo.io_configs.push_back (pair<int,int> (channel_info[n].inChannels,
1100 channel_info[n].outChannels));
1103 free (channel_info);
1106 add_cached_info (id, cinfo);
1107 save_cached_info ();
1113 AUPluginInfo::add_cached_info (const std::string& id, AUPluginCachedInfo& cinfo)
1115 cached_info[id] = cinfo;
1119 AUPluginInfo::save_cached_info ()
1123 node = new XMLNode (X_("AudioUnitPluginCache"));
1125 for (map<string,AUPluginCachedInfo>::iterator i = cached_info.begin(); i != cached_info.end(); ++i) {
1126 XMLNode* parent = new XMLNode (X_("plugin"));
1127 parent->add_property ("id", i->first);
1128 node->add_child_nocopy (*parent);
1130 for (vector<pair<int, int> >::iterator j = i->second.io_configs.begin(); j != i->second.io_configs.end(); ++j) {
1132 XMLNode* child = new XMLNode (X_("io"));
1135 snprintf (buf, sizeof (buf), "%d", j->first);
1136 child->add_property (X_("in"), buf);
1137 snprintf (buf, sizeof (buf), "%d", j->second);
1138 child->add_property (X_("out"), buf);
1139 parent->add_child_nocopy (*child);
1144 Glib::ustring path = au_cache_path ();
1147 tree.set_root (node);
1149 if (!tree.write (path)) {
1150 error << string_compose (_("could not save AU cache to %1"), path) << endmsg;
1151 unlink (path.c_str());
1156 AUPluginInfo::load_cached_info ()
1158 Glib::ustring path = au_cache_path ();
1161 if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
1166 const XMLNode* root (tree.root());
1168 if (root->name() != X_("AudioUnitPluginCache")) {
1172 cached_info.clear ();
1174 const XMLNodeList children = root->children();
1176 for (XMLNodeConstIterator iter = children.begin(); iter != children.end(); ++iter) {
1178 const XMLNode* child = *iter;
1180 if (child->name() == X_("plugin")) {
1182 const XMLNode* gchild;
1183 const XMLNodeList gchildren = child->children();
1184 const XMLProperty* prop = child->property (X_("id"));
1190 std::string id = prop->value();
1192 for (XMLNodeConstIterator giter = gchildren.begin(); giter != gchildren.end(); giter++) {
1196 if (gchild->name() == X_("io")) {
1200 const XMLProperty* iprop;
1201 const XMLProperty* oprop;
1203 if (((iprop = gchild->property (X_("in"))) != 0) &&
1204 ((oprop = gchild->property (X_("out"))) != 0)) {
1205 in = atoi (iprop->value());
1206 out = atoi (iprop->value());
1208 AUPluginCachedInfo cinfo;
1209 cinfo.io_configs.push_back (pair<int,int> (in, out));
1210 add_cached_info (id, cinfo);
1221 AUPluginInfo::get_names (CAComponentDescription& comp_desc, std::string& name, Glib::ustring& maker)
1223 CFStringRef itemName = NULL;
1225 // Marc Poirier-style item name
1226 CAComponent auComponent (comp_desc);
1227 if (auComponent.IsValid()) {
1228 CAComponentDescription dummydesc;
1229 Handle nameHandle = NewHandle(sizeof(void*));
1230 if (nameHandle != NULL) {
1231 OSErr err = GetComponentInfo(auComponent.Comp(), &dummydesc, nameHandle, NULL, NULL);
1233 ConstStr255Param nameString = (ConstStr255Param) (*nameHandle);
1234 if (nameString != NULL) {
1235 itemName = CFStringCreateWithPascalString(kCFAllocatorDefault, nameString, CFStringGetSystemEncoding());
1238 DisposeHandle(nameHandle);
1242 // if Marc-style fails, do the original way
1243 if (itemName == NULL) {
1244 CFStringRef compTypeString = UTCreateStringForOSType(comp_desc.componentType);
1245 CFStringRef compSubTypeString = UTCreateStringForOSType(comp_desc.componentSubType);
1246 CFStringRef compManufacturerString = UTCreateStringForOSType(comp_desc.componentManufacturer);
1248 itemName = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ - %@ - %@"),
1249 compTypeString, compManufacturerString, compSubTypeString);
1251 if (compTypeString != NULL)
1252 CFRelease(compTypeString);
1253 if (compSubTypeString != NULL)
1254 CFRelease(compSubTypeString);
1255 if (compManufacturerString != NULL)
1256 CFRelease(compManufacturerString);
1259 string str = CFStringRefToStdString(itemName);
1260 string::size_type colon = str.find (':');
1263 name = str.substr (colon+1);
1264 maker = str.substr (0, colon);
1265 // strip_whitespace_edges (maker);
1266 // strip_whitespace_edges (name);
1273 // from CAComponentDescription.cpp (in libs/appleutility in ardour source)
1274 extern char *StringForOSType (OSType t, char *writeLocation);
1277 AUPluginInfo::stringify_descriptor (const CAComponentDescription& desc)
1282 s << StringForOSType (desc.Type(), str);
1285 s << StringForOSType (desc.SubType(), str);
1288 s << StringForOSType (desc.Manu(), str);