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 ();
106 OSErr err = CAAudioUnit::Open (*(comp.get()), *unit);
109 error << _("AudioUnit: Could not convert CAComponent to CAAudioUnit") << endmsg;
110 throw failed_constructor ();
113 AURenderCallbackStruct renderCallbackInfo;
115 renderCallbackInfo.inputProc = _render_callback;
116 renderCallbackInfo.inputProcRefCon = this;
118 if ((err = unit->SetProperty (kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
119 0, (void*) &renderCallbackInfo, sizeof(renderCallbackInfo))) != 0) {
120 cerr << "cannot install render callback (err = " << err << ')' << endl;
121 throw failed_constructor();
124 unit->GetElementCount (kAudioUnitScope_Global, global_elements);
125 unit->GetElementCount (kAudioUnitScope_Input, input_elements);
126 unit->GetElementCount (kAudioUnitScope_Output, output_elements);
128 /* these keep track of *configured* channel set up,
129 not potential set ups.
133 output_channels = -1;
135 if (_set_block_size (_session.get_block_size())) {
136 error << _("AUPlugin: cannot set processing block size") << endmsg;
137 throw failed_constructor();
140 discover_parameters ();
142 Plugin::setup_controls ();
146 AUPlugin::discover_parameters ()
148 /* discover writable parameters */
150 AudioUnitScope scopes[] = {
151 kAudioUnitScope_Global,
152 kAudioUnitScope_Output,
153 kAudioUnitScope_Input
156 descriptors.clear ();
158 for (uint32_t i = 0; i < sizeof (scopes) / sizeof (scopes[0]); ++i) {
160 AUParamInfo param_info (unit->AU(), false, false, scopes[i]);
162 for (uint32_t i = 0; i < param_info.NumParams(); ++i) {
164 AUParameterDescriptor d;
166 d.id = param_info.ParamID (i);
168 const CAAUParameter* param = param_info.GetParamInfo (d.id);
169 const AudioUnitParameterInfo& info (param->ParamInfo());
171 const int len = CFStringGetLength (param->GetName());;
172 char local_buffer[len*2];
173 Boolean good = CFStringGetCString(param->GetName(),local_buffer,len*2,kCFStringEncodingMacRoman);
177 d.label = local_buffer;
180 d.scope = param_info.GetScope ();
181 d.element = param_info.GetElement ();
183 /* info.units to consider */
185 kAudioUnitParameterUnit_Generic = 0
186 kAudioUnitParameterUnit_Indexed = 1
187 kAudioUnitParameterUnit_Boolean = 2
188 kAudioUnitParameterUnit_Percent = 3
189 kAudioUnitParameterUnit_Seconds = 4
190 kAudioUnitParameterUnit_SampleFrames = 5
191 kAudioUnitParameterUnit_Phase = 6
192 kAudioUnitParameterUnit_Rate = 7
193 kAudioUnitParameterUnit_Hertz = 8
194 kAudioUnitParameterUnit_Cents = 9
195 kAudioUnitParameterUnit_RelativeSemiTones = 10
196 kAudioUnitParameterUnit_MIDINoteNumber = 11
197 kAudioUnitParameterUnit_MIDIController = 12
198 kAudioUnitParameterUnit_Decibels = 13
199 kAudioUnitParameterUnit_LinearGain = 14
200 kAudioUnitParameterUnit_Degrees = 15
201 kAudioUnitParameterUnit_EqualPowerCrossfade = 16
202 kAudioUnitParameterUnit_MixerFaderCurve1 = 17
203 kAudioUnitParameterUnit_Pan = 18
204 kAudioUnitParameterUnit_Meters = 19
205 kAudioUnitParameterUnit_AbsoluteCents = 20
206 kAudioUnitParameterUnit_Octaves = 21
207 kAudioUnitParameterUnit_BPM = 22
208 kAudioUnitParameterUnit_Beats = 23
209 kAudioUnitParameterUnit_Milliseconds = 24
210 kAudioUnitParameterUnit_Ratio = 25
213 /* info.flags to consider */
217 kAudioUnitParameterFlag_CFNameRelease = (1L << 4)
218 kAudioUnitParameterFlag_HasClump = (1L << 20)
219 kAudioUnitParameterFlag_HasName = (1L << 21)
220 kAudioUnitParameterFlag_DisplayLogarithmic = (1L << 22)
221 kAudioUnitParameterFlag_IsHighResolution = (1L << 23)
222 kAudioUnitParameterFlag_NonRealTime = (1L << 24)
223 kAudioUnitParameterFlag_CanRamp = (1L << 25)
224 kAudioUnitParameterFlag_ExpertMode = (1L << 26)
225 kAudioUnitParameterFlag_HasCFNameString = (1L << 27)
226 kAudioUnitParameterFlag_IsGlobalMeta = (1L << 28)
227 kAudioUnitParameterFlag_IsElementMeta = (1L << 29)
228 kAudioUnitParameterFlag_IsReadable = (1L << 30)
229 kAudioUnitParameterFlag_IsWritable = (1L << 31)
232 d.lower = info.minValue;
233 d.upper = info.maxValue;
234 d.default_value = info.defaultValue;
236 d.integer_step = (info.unit & kAudioUnitParameterUnit_Indexed);
237 d.toggled = (info.unit & kAudioUnitParameterUnit_Boolean) ||
238 (d.integer_step && ((d.upper - d.lower) == 1.0));
239 d.sr_dependent = (info.unit & kAudioUnitParameterUnit_SampleFrames);
240 d.automatable = !d.toggled &&
241 !(info.flags & kAudioUnitParameterFlag_NonRealTime) &&
242 (info.flags & kAudioUnitParameterFlag_IsWritable);
244 d.logarithmic = (info.flags & kAudioUnitParameterFlag_DisplayLogarithmic);
250 d.min_unbound = 0; // lower is bound
251 d.max_unbound = 0; // upper is bound
253 descriptors.push_back (d);
260 AUPlugin::unique_id () const
262 return AUPluginInfo::stringify_descriptor (comp->Desc());
266 AUPlugin::label () const
268 return _info->name.c_str();
272 AUPlugin::parameter_count () const
274 return descriptors.size();
278 AUPlugin::default_value (uint32_t port)
280 if (port < descriptors.size()) {
281 return descriptors[port].default_value;
288 AUPlugin::latency () const
290 return unit->Latency() * _session.frame_rate();
294 AUPlugin::set_parameter (uint32_t which, float val)
296 if (which < descriptors.size()) {
297 const AUParameterDescriptor& d (descriptors[which]);
298 unit->SetParameter (d.id, d.scope, d.element, val);
303 AUPlugin::get_parameter (uint32_t which) const
306 if (which < descriptors.size()) {
307 const AUParameterDescriptor& d (descriptors[which]);
308 unit->GetParameter(d.id, d.scope, d.element, val);
314 AUPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& pd) const
316 if (which < descriptors.size()) {
317 pd = descriptors[which];
324 AUPlugin::nth_parameter (uint32_t which, bool& ok) const
326 if (which < descriptors.size()) {
335 AUPlugin::activate ()
339 if ((err = unit->Initialize()) != noErr) {
340 error << string_compose (_("AUPlugin: %1 cannot initialize plugin (err = %2)"), name(), err) << endmsg;
342 frames_processed = 0;
349 AUPlugin::deactivate ()
351 unit->GlobalReset ();
355 AUPlugin::set_block_size (nframes_t nframes)
357 _set_block_size (nframes);
361 AUPlugin::_set_block_size (nframes_t nframes)
363 bool was_initialized = initialized;
364 UInt32 numFrames = nframes;
368 unit->Uninitialize ();
371 if ((err = unit->SetProperty (kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global,
372 0, &numFrames, sizeof (numFrames))) != noErr) {
373 cerr << "cannot set max frames (err = " << err << ')' << endl;
377 if (was_initialized) {
385 AUPlugin::configure_io (int32_t in, int32_t out)
387 AudioStreamBasicDescription streamFormat;
389 streamFormat.mSampleRate = _session.frame_rate();
390 streamFormat.mFormatID = kAudioFormatLinearPCM;
391 streamFormat.mFormatFlags = kAudioFormatFlagIsFloat|kAudioFormatFlagIsPacked|kAudioFormatFlagIsNonInterleaved;
393 #ifdef __LITTLE_ENDIAN__
396 streamFormat.mFormatFlags |= kAudioFormatFlagIsBigEndian;
399 streamFormat.mBitsPerChannel = 32;
400 streamFormat.mFramesPerPacket = 1;
402 /* apple says that for non-interleaved data, these
403 values always refer to a single channel.
405 streamFormat.mBytesPerPacket = 4;
406 streamFormat.mBytesPerFrame = 4;
408 streamFormat.mChannelsPerFrame = in;
410 if (set_input_format (streamFormat) != 0) {
414 streamFormat.mChannelsPerFrame = out;
416 if (set_output_format (streamFormat) != 0) {
420 return Plugin::configure_io (in, out);
424 AUPlugin::can_do (int32_t in, int32_t& out)
426 // XXX as of May 13th 2008, AU plugin support returns a count of either 1 or -1. We never
427 // attempt to multiply-instantiate plugins to meet io configurations.
429 int32_t plugcnt = -1;
430 AUPluginInfoPtr pinfo = boost::dynamic_pointer_cast<AUPluginInfo>(get_info());
434 vector<pair<int,int> >& io_configs = pinfo->cache.io_configs;
436 for (vector<pair<int,int> >::iterator i = io_configs.begin(); i != io_configs.end(); ++i) {
438 int32_t possible_in = i->first;
439 int32_t possible_out = i->second;
441 if (possible_out == 0) {
442 warning << string_compose (_("AU %1 has zero outputs - configuration ignored"), name()) << endmsg;
446 if (possible_in == 0) {
448 /* instrument plugin, always legal but throws away inputs ...
451 if (possible_out == -1) {
452 /* out much match in (UNLIKELY!!) */
455 } else if (possible_out == -2) {
456 /* any configuration possible, pick matching */
459 } else if (possible_out < -2) {
460 /* explicit variable number of outputs, pick maximum */
464 /* exact number of outputs */
470 if (possible_in == -1) {
472 /* wildcard for input */
474 if (possible_out == -1) {
475 /* out much match in */
478 } else if (possible_out == -2) {
479 /* any configuration possible, pick matching */
482 } else if (possible_out < -2) {
483 /* explicit variable number of outputs, pick maximum */
487 /* exact number of outputs */
493 if (possible_in == -2) {
495 if (possible_out == -1) {
496 /* any configuration possible, pick matching */
499 } else if (possible_out == -2) {
500 error << string_compose (_("AU plugin %1 has illegal IO configuration (-2,-2)"), name())
503 } else if (possible_out < -2) {
504 /* explicit variable number of outputs, pick maximum */
508 /* exact number of outputs */
514 if (possible_in < -2) {
516 /* explicit variable number of inputs */
518 if (in > -possible_in) {
519 /* request is too large */
523 if (possible_out == -1) {
524 /* out must match in */
527 } else if (possible_out == -2) {
528 error << string_compose (_("AU plugin %1 has illegal IO configuration (-2,-2)"), name())
531 } else if (possible_out < -2) {
532 /* explicit variable number of outputs, pick maximum */
536 /* exact number of outputs */
542 if (possible_in == in) {
544 /* exact number of inputs ... must match obviously */
546 if (possible_out == -1) {
547 /* out must match in */
550 } else if (possible_out == -2) {
551 /* any output configuration, pick matching */
554 } else if (possible_out < -2) {
555 /* explicit variable number of outputs, pick maximum */
559 /* exact number of outputs */
572 AUPlugin::set_input_format (AudioStreamBasicDescription& fmt)
574 return set_stream_format (kAudioUnitScope_Input, input_elements, fmt);
578 AUPlugin::set_output_format (AudioStreamBasicDescription& fmt)
580 if (set_stream_format (kAudioUnitScope_Output, output_elements, fmt) != 0) {
589 buffers = (AudioBufferList *) malloc (offsetof(AudioBufferList, mBuffers) +
590 fmt.mChannelsPerFrame * sizeof(AudioBuffer));
592 Glib::Mutex::Lock em (_session.engine().process_lock());
593 IO::MoreOutputs (fmt.mChannelsPerFrame);
599 AUPlugin::set_stream_format (int scope, uint32_t cnt, AudioStreamBasicDescription& fmt)
603 for (uint32_t i = 0; i < cnt; ++i) {
604 if ((result = unit->SetFormat (scope, i, fmt)) != 0) {
605 error << string_compose (_("AUPlugin: could not set stream format for %1/%2 (err = %3)"),
606 (scope == kAudioUnitScope_Input ? "input" : "output"), i, result) << endmsg;
611 if (scope == kAudioUnitScope_Input) {
612 input_channels = fmt.mChannelsPerFrame;
614 output_channels = fmt.mChannelsPerFrame;
621 AUPlugin::input_streams() const
623 if (input_channels < 0) {
624 warning << string_compose (_("AUPlugin: %1 input_streams() called without any format set!"), name()) << endmsg;
627 return input_channels;
632 AUPlugin::output_streams() const
634 if (output_channels < 0) {
635 warning << string_compose (_("AUPlugin: %1 output_streams() called without any format set!"), name()) << endmsg;
638 return output_channels;
642 AUPlugin::render_callback(AudioUnitRenderActionFlags *ioActionFlags,
643 const AudioTimeStamp *inTimeStamp,
645 UInt32 inNumberFrames,
646 AudioBufferList* ioData)
648 /* not much to do - the data is already in the buffers given to us in connect_and_run() */
650 if (current_maxbuf == 0) {
651 error << _("AUPlugin: render callback called illegally!") << endmsg;
652 return kAudioUnitErr_CannotDoInCurrentContext;
655 for (uint32_t i = 0; i < current_maxbuf; ++i) {
656 ioData->mBuffers[i].mNumberChannels = 1;
657 ioData->mBuffers[i].mDataByteSize = sizeof (Sample) * inNumberFrames;
658 ioData->mBuffers[i].mData = (*current_buffers)[i] + cb_offset + current_offset;
661 cb_offset += inNumberFrames;
667 AUPlugin::connect_and_run (vector<Sample*>& bufs, uint32_t maxbuf, int32_t& in, int32_t& out, nframes_t nframes, nframes_t offset)
669 AudioUnitRenderActionFlags flags = 0;
672 current_buffers = &bufs;
673 current_maxbuf = maxbuf;
674 current_offset = offset;
677 buffers->mNumberBuffers = maxbuf;
679 for (uint32_t i = 0; i < maxbuf; ++i) {
680 buffers->mBuffers[i].mNumberChannels = 1;
681 buffers->mBuffers[i].mDataByteSize = nframes * sizeof (Sample);
682 buffers->mBuffers[i].mData = 0;
685 ts.mSampleTime = frames_processed;
686 ts.mFlags = kAudioTimeStampSampleTimeValid;
688 if (unit->Render (&flags, &ts, 0, nframes, buffers) == noErr) {
691 frames_processed += nframes;
693 for (uint32_t i = 0; i < maxbuf; ++i) {
694 if (bufs[i] + offset != buffers->mBuffers[i].mData) {
695 memcpy (bufs[i]+offset, buffers->mBuffers[i].mData, nframes * sizeof (Sample));
705 AUPlugin::automatable() const
707 set<uint32_t> automates;
709 for (uint32_t i = 0; i < descriptors.size(); ++i) {
710 if (descriptors[i].automatable) {
711 automates.insert (i);
719 AUPlugin::describe_parameter (uint32_t param)
721 return descriptors[param].label;
725 AUPlugin::print_parameter (uint32_t param, char* buf, uint32_t len) const
727 // NameValue stuff here
731 AUPlugin::parameter_is_audio (uint32_t) const
737 AUPlugin::parameter_is_control (uint32_t) const
743 AUPlugin::parameter_is_input (uint32_t) const
749 AUPlugin::parameter_is_output (uint32_t) const
755 AUPlugin::get_state()
757 XMLNode *root = new XMLNode (state_node_name());
758 LocaleGuard lg (X_("POSIX"));
763 AUPlugin::set_state(const XMLNode& node)
769 AUPlugin::save_preset (string name)
775 AUPlugin::load_preset (const string preset_label)
781 AUPlugin::get_presets ()
783 vector<string> presets;
789 AUPlugin::has_editor () const
791 // even if the plugin doesn't have its own editor, the AU API can be used
792 // to create one that looks native.
796 AUPluginInfo::AUPluginInfo (boost::shared_ptr<CAComponentDescription> d)
802 AUPluginInfo::~AUPluginInfo ()
807 AUPluginInfo::load (Session& session)
812 boost::shared_ptr<CAComponent> comp (new CAComponent(*descriptor));
814 if (!comp->IsValid()) {
815 error << ("AudioUnit: not a valid Component") << endmsg;
817 plugin.reset (new AUPlugin (session.engine(), session, comp));
820 plugin->set_info (PluginInfoPtr (new AUPluginInfo (*this)));
824 catch (failed_constructor &err) {
830 AUPluginInfo::au_cache_path ()
832 return Glib::build_filename (ARDOUR::get_user_ardour_path(), "au_cache");
836 AUPluginInfo::discover ()
840 if (!Glib::file_test (au_cache_path(), Glib::FILE_TEST_EXISTS)) {
841 ARDOUR::BootMessage (_("Discovering AudioUnit plugins (could take some time ...)"));
844 PluginInfoList plugs;
847 discover_music (plugs);
853 AUPluginInfo::discover_music (PluginInfoList& plugs)
855 CAComponentDescription desc;
856 desc.componentFlags = 0;
857 desc.componentFlagsMask = 0;
858 desc.componentSubType = 0;
859 desc.componentManufacturer = 0;
860 desc.componentType = kAudioUnitType_MusicEffect;
862 discover_by_description (plugs, desc);
866 AUPluginInfo::discover_fx (PluginInfoList& plugs)
868 CAComponentDescription desc;
869 desc.componentFlags = 0;
870 desc.componentFlagsMask = 0;
871 desc.componentSubType = 0;
872 desc.componentManufacturer = 0;
873 desc.componentType = kAudioUnitType_Effect;
875 discover_by_description (plugs, desc);
879 AUPluginInfo::discover_by_description (PluginInfoList& plugs, CAComponentDescription& desc)
883 comp = FindNextComponent (NULL, &desc);
885 while (comp != NULL) {
886 CAComponentDescription temp;
887 GetComponentInfo (comp, &temp, NULL, NULL, NULL);
889 AUPluginInfoPtr info (new AUPluginInfo
890 (boost::shared_ptr<CAComponentDescription> (new CAComponentDescription(temp))));
892 /* no panners, format converters or i/o AU's for our purposes
895 switch (info->descriptor->Type()) {
896 case kAudioUnitType_Panner:
897 case kAudioUnitType_OfflineEffect:
898 case kAudioUnitType_FormatConverter:
904 switch (info->descriptor->SubType()) {
905 case kAudioUnitSubType_DefaultOutput:
906 case kAudioUnitSubType_SystemOutput:
907 case kAudioUnitSubType_GenericOutput:
908 case kAudioUnitSubType_AUConverter:
912 case kAudioUnitSubType_DLSSynth:
913 info->category = "DLSSynth";
916 case kAudioUnitType_MusicEffect:
917 info->category = "MusicEffect";
920 case kAudioUnitSubType_Varispeed:
921 info->category = "Varispeed";
924 case kAudioUnitSubType_Delay:
925 info->category = "Delay";
928 case kAudioUnitSubType_LowPassFilter:
929 info->category = "LowPassFilter";
932 case kAudioUnitSubType_HighPassFilter:
933 info->category = "HighPassFilter";
936 case kAudioUnitSubType_BandPassFilter:
937 info->category = "BandPassFilter";
940 case kAudioUnitSubType_HighShelfFilter:
941 info->category = "HighShelfFilter";
944 case kAudioUnitSubType_LowShelfFilter:
945 info->category = "LowShelfFilter";
948 case kAudioUnitSubType_ParametricEQ:
949 info->category = "ParametricEQ";
952 case kAudioUnitSubType_GraphicEQ:
953 info->category = "GraphicEQ";
956 case kAudioUnitSubType_PeakLimiter:
957 info->category = "PeakLimiter";
960 case kAudioUnitSubType_DynamicsProcessor:
961 info->category = "DynamicsProcessor";
964 case kAudioUnitSubType_MultiBandCompressor:
965 info->category = "MultiBandCompressor";
968 case kAudioUnitSubType_MatrixReverb:
969 info->category = "MatrixReverb";
972 case kAudioUnitType_Mixer:
973 info->category = "Mixer";
976 case kAudioUnitSubType_StereoMixer:
977 info->category = "StereoMixer";
980 case kAudioUnitSubType_3DMixer:
981 info->category = "3DMixer";
984 case kAudioUnitSubType_MatrixMixer:
985 info->category = "MatrixMixer";
992 AUPluginInfo::get_names (temp, info->name, info->creator);
994 info->type = ARDOUR::AudioUnit;
995 info->unique_id = stringify_descriptor (*info->descriptor);
997 /* XXX not sure of the best way to handle plugin versioning yet
1000 CAComponent cacomp (*info->descriptor);
1002 if (cacomp.GetResourceVersion (info->version) != noErr) {
1006 if (cached_io_configuration (info->unique_id, info->version, cacomp, info->cache, info->name)) {
1008 /* here we have to map apple's wildcard system to a simple pair
1012 info->n_inputs = info->cache.io_configs.front().first;
1013 info->n_outputs = info->cache.io_configs.front().second;
1015 if (info->cache.io_configs.size() > 1) {
1016 cerr << "ODD: variable IO config for " << info->unique_id << endl;
1019 plugs.push_back (info);
1022 error << string_compose (_("Cannot get I/O configuration info for AU %1"), info->name) << endmsg;
1025 comp = FindNextComponent (comp, &desc);
1030 AUPluginInfo::cached_io_configuration (const std::string& unique_id,
1033 AUPluginCachedInfo& cinfo,
1034 const std::string& name)
1039 /* concatenate unique ID with version to provide a key for cached info lookup.
1040 this ensures we don't get stale information, or should if plugin developers
1041 follow Apple "guidelines".
1044 snprintf (buf, sizeof (buf), "%u", version);
1049 CachedInfoMap::iterator cim = cached_info.find (id);
1051 if (cim != cached_info.end()) {
1052 cinfo = cim->second;
1057 AUChannelInfo* channel_info;
1061 ARDOUR::BootMessage (string_compose (_("Checking AudioUnit: %1"), name));
1063 if (CAAudioUnit::Open (comp, unit) != noErr) {
1067 if ((ret = unit.GetChannelInfo (&channel_info, cnt)) < 0) {
1072 /* no explicit info available */
1074 cinfo.io_configs.push_back (pair<int,int> (-1, -1));
1078 /* store each configuration */
1080 for (uint32_t n = 0; n < cnt; ++n) {
1081 cinfo.io_configs.push_back (pair<int,int> (channel_info[n].inChannels,
1082 channel_info[n].outChannels));
1085 free (channel_info);
1088 add_cached_info (id, cinfo);
1089 save_cached_info ();
1095 AUPluginInfo::add_cached_info (const std::string& id, AUPluginCachedInfo& cinfo)
1097 cached_info[id] = cinfo;
1101 AUPluginInfo::save_cached_info ()
1105 node = new XMLNode (X_("AudioUnitPluginCache"));
1107 for (map<string,AUPluginCachedInfo>::iterator i = cached_info.begin(); i != cached_info.end(); ++i) {
1108 XMLNode* parent = new XMLNode (X_("plugin"));
1109 parent->add_property ("id", i->first);
1110 node->add_child_nocopy (*parent);
1112 for (vector<pair<int, int> >::iterator j = i->second.io_configs.begin(); j != i->second.io_configs.end(); ++j) {
1114 XMLNode* child = new XMLNode (X_("io"));
1117 snprintf (buf, sizeof (buf), "%d", j->first);
1118 child->add_property (X_("in"), buf);
1119 snprintf (buf, sizeof (buf), "%d", j->second);
1120 child->add_property (X_("out"), buf);
1121 parent->add_child_nocopy (*child);
1126 Glib::ustring path = au_cache_path ();
1129 tree.set_root (node);
1131 if (!tree.write (path)) {
1132 error << string_compose (_("could not save AU cache to %1"), path) << endmsg;
1133 unlink (path.c_str());
1138 AUPluginInfo::load_cached_info ()
1140 Glib::ustring path = au_cache_path ();
1143 if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
1148 const XMLNode* root (tree.root());
1150 if (root->name() != X_("AudioUnitPluginCache")) {
1154 cached_info.clear ();
1156 const XMLNodeList children = root->children();
1158 for (XMLNodeConstIterator iter = children.begin(); iter != children.end(); ++iter) {
1160 const XMLNode* child = *iter;
1162 if (child->name() == X_("plugin")) {
1164 const XMLNode* gchild;
1165 const XMLNodeList gchildren = child->children();
1166 const XMLProperty* prop = child->property (X_("id"));
1172 std::string id = prop->value();
1174 for (XMLNodeConstIterator giter = gchildren.begin(); giter != gchildren.end(); giter++) {
1178 if (gchild->name() == X_("io")) {
1182 const XMLProperty* iprop;
1183 const XMLProperty* oprop;
1185 if (((iprop = gchild->property (X_("in"))) != 0) &&
1186 ((oprop = gchild->property (X_("out"))) != 0)) {
1187 in = atoi (iprop->value());
1188 out = atoi (iprop->value());
1190 AUPluginCachedInfo cinfo;
1191 cinfo.io_configs.push_back (pair<int,int> (in, out));
1192 add_cached_info (id, cinfo);
1203 AUPluginInfo::get_names (CAComponentDescription& comp_desc, std::string& name, Glib::ustring& maker)
1205 CFStringRef itemName = NULL;
1207 // Marc Poirier-style item name
1208 CAComponent auComponent (comp_desc);
1209 if (auComponent.IsValid()) {
1210 CAComponentDescription dummydesc;
1211 Handle nameHandle = NewHandle(sizeof(void*));
1212 if (nameHandle != NULL) {
1213 OSErr err = GetComponentInfo(auComponent.Comp(), &dummydesc, nameHandle, NULL, NULL);
1215 ConstStr255Param nameString = (ConstStr255Param) (*nameHandle);
1216 if (nameString != NULL) {
1217 itemName = CFStringCreateWithPascalString(kCFAllocatorDefault, nameString, CFStringGetSystemEncoding());
1220 DisposeHandle(nameHandle);
1224 // if Marc-style fails, do the original way
1225 if (itemName == NULL) {
1226 CFStringRef compTypeString = UTCreateStringForOSType(comp_desc.componentType);
1227 CFStringRef compSubTypeString = UTCreateStringForOSType(comp_desc.componentSubType);
1228 CFStringRef compManufacturerString = UTCreateStringForOSType(comp_desc.componentManufacturer);
1230 itemName = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ - %@ - %@"),
1231 compTypeString, compManufacturerString, compSubTypeString);
1233 if (compTypeString != NULL)
1234 CFRelease(compTypeString);
1235 if (compSubTypeString != NULL)
1236 CFRelease(compSubTypeString);
1237 if (compManufacturerString != NULL)
1238 CFRelease(compManufacturerString);
1241 string str = CFStringRefToStdString(itemName);
1242 string::size_type colon = str.find (':');
1245 name = str.substr (colon+1);
1246 maker = str.substr (0, colon);
1247 // strip_whitespace_edges (maker);
1248 // strip_whitespace_edges (name);
1255 // from CAComponentDescription.cpp (in libs/appleutility in ardour source)
1256 extern char *StringForOSType (OSType t, char *writeLocation);
1259 AUPluginInfo::stringify_descriptor (const CAComponentDescription& desc)
1264 s << StringForOSType (desc.Type(), str);
1267 s << StringForOSType (desc.SubType(), str);
1270 s << StringForOSType (desc.Manu(), str);