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.
24 #include <pbd/transmitter.h>
25 #include <pbd/xml++.h>
26 #include <pbd/whitespace.h>
27 #include <pbd/pathscanner.h>
29 #include <glibmm/thread.h>
30 #include <glibmm/fileutils.h>
31 #include <glibmm/miscutils.h>
33 #include <ardour/ardour.h>
34 #include <ardour/audioengine.h>
35 #include <ardour/io.h>
36 #include <ardour/audio_unit.h>
37 #include <ardour/session.h>
38 #include <ardour/utils.h>
40 #include <appleutility/CAAudioUnit.h>
41 #include <appleutility/CAAUParameter.h>
43 #include <CoreFoundation/CoreFoundation.h>
44 #include <CoreServices/CoreServices.h>
45 #include <AudioUnit/AudioUnit.h>
51 using namespace ARDOUR
;
53 #ifndef AU_STATE_SUPPORT
54 static bool seen_get_state_message
= false;
55 static bool seen_set_state_message
= false;
56 static bool seen_loading_message
= false;
57 static bool seen_saving_message
= false;
60 AUPluginInfo::CachedInfoMap
AUPluginInfo::cached_info
;
62 static string preset_search_path
= "/Library/Audio/Presets:/Network/Library/Audio/Presets";
63 static string preset_suffix
= ".aupreset";
64 static bool preset_search_path_initialized
= false;
67 _render_callback(void *userData
,
68 AudioUnitRenderActionFlags
*ioActionFlags
,
69 const AudioTimeStamp
*inTimeStamp
,
71 UInt32 inNumberFrames
,
72 AudioBufferList
* ioData
)
74 return ((AUPlugin
*)userData
)->render_callback (ioActionFlags
, inTimeStamp
, inBusNumber
, inNumberFrames
, ioData
);
78 save_property_list (CFPropertyListRef propertyList
, Glib::ustring path
)
84 // Convert the property list into XML data.
86 xmlData
= CFPropertyListCreateXMLData( kCFAllocatorDefault
, propertyList
);
89 error
<< _("Could not create XML version of property list") << endmsg
;
93 // Write the XML data to the file.
95 fd
= open (path
.c_str(), O_WRONLY
|O_CREAT
|O_EXCL
, 0664);
97 if (errno
== EEXIST
) {
98 /* tell any UI's that this file already exists and ask them what to do */
99 bool overwrite
= Plugin::PresetFileExists(); // EMIT SIGNAL
101 fd
= open (path
.c_str(), O_WRONLY
, 0664);
107 error
<< string_compose (_("Cannot open preset file %1 (%2)"), path
, strerror (errno
)) << endmsg
;
112 size_t cnt
= CFDataGetLength (xmlData
);
114 if (write (fd
, CFDataGetBytePtr (xmlData
), cnt
) != cnt
) {
125 static CFPropertyListRef
126 load_property_list (Glib::ustring path
)
129 CFPropertyListRef propertyList
;
131 CFStringRef errorString
;
133 // Read the XML file.
135 if ((fd
= open (path
.c_str(), O_RDONLY
)) < 0) {
140 off_t len
= lseek (fd
, 0, SEEK_END
);
141 char* buf
= new char[len
];
142 lseek (fd
, 0, SEEK_SET
);
144 if (read (fd
, buf
, len
) != len
) {
152 xmlData
= CFDataCreateWithBytesNoCopy (kCFAllocatorDefault
, (UInt8
*) buf
, len
, kCFAllocatorNull
);
154 // Reconstitute the dictionary using the XML data.
156 propertyList
= CFPropertyListCreateFromXMLData( kCFAllocatorDefault
,
158 kCFPropertyListImmutable
,
167 //-----------------------------------------------------------------------------
169 set_preset_name_in_plist (CFPropertyListRef plist
, string preset_name
)
174 CFStringRef pn
= CFStringCreateWithCString (kCFAllocatorDefault
, preset_name
.c_str(), kCFStringEncodingUTF8
);
176 if (CFGetTypeID (plist
) == CFDictionaryGetTypeID()) {
177 CFDictionarySetValue ((CFMutableDictionaryRef
)plist
, CFSTR(kAUPresetNameKey
), pn
);
183 //-----------------------------------------------------------------------------
185 get_preset_name_in_plist (CFPropertyListRef plist
)
193 if (CFGetTypeID (plist
) == CFDictionaryGetTypeID()) {
194 const void *p
= CFDictionaryGetValue ((CFMutableDictionaryRef
)plist
, CFSTR(kAUPresetNameKey
));
196 CFStringRef str
= (CFStringRef
) p
;
197 int len
= CFStringGetLength(str
);
199 char local_buffer
[len
];
200 if (CFStringGetCString (str
, local_buffer
, len
, kCFStringEncodingUTF8
)) {
208 //--------------------------------------------------------------------------
209 // general implementation for ComponentDescriptionsMatch() and ComponentDescriptionsMatch_Loosely()
210 // if inIgnoreType is true, then the type code is ignored in the ComponentDescriptions
211 Boolean
ComponentDescriptionsMatch_General(const ComponentDescription
* inComponentDescription1
, const ComponentDescription
* inComponentDescription2
, Boolean inIgnoreType
);
212 Boolean
ComponentDescriptionsMatch_General(const ComponentDescription
* inComponentDescription1
, const ComponentDescription
* inComponentDescription2
, Boolean inIgnoreType
)
214 if ( (inComponentDescription1
== NULL
) || (inComponentDescription2
== NULL
) )
217 if ( (inComponentDescription1
->componentSubType
== inComponentDescription2
->componentSubType
)
218 && (inComponentDescription1
->componentManufacturer
== inComponentDescription2
->componentManufacturer
) )
220 // only sub-type and manufacturer IDs need to be equal
223 // type, sub-type, and manufacturer IDs all need to be equal in order to call this a match
224 else if (inComponentDescription1
->componentType
== inComponentDescription2
->componentType
)
231 //--------------------------------------------------------------------------
232 // general implementation for ComponentAndDescriptionMatch() and ComponentAndDescriptionMatch_Loosely()
233 // if inIgnoreType is true, then the type code is ignored in the ComponentDescriptions
234 Boolean
ComponentAndDescriptionMatch_General(Component inComponent
, const ComponentDescription
* inComponentDescription
, Boolean inIgnoreType
);
235 Boolean
ComponentAndDescriptionMatch_General(Component inComponent
, const ComponentDescription
* inComponentDescription
, Boolean inIgnoreType
)
238 ComponentDescription desc
;
240 if ( (inComponent
== NULL
) || (inComponentDescription
== NULL
) )
243 // get the ComponentDescription of the input Component
244 status
= GetComponentInfo(inComponent
, &desc
, NULL
, NULL
, NULL
);
248 // check if the Component's ComponentDescription matches the input ComponentDescription
249 return ComponentDescriptionsMatch_General(&desc
, inComponentDescription
, inIgnoreType
);
252 //--------------------------------------------------------------------------
253 // determine if 2 ComponentDescriptions are basically equal
254 // (by that, I mean that the important identifying values are compared,
255 // but not the ComponentDescription flags)
256 Boolean
ComponentDescriptionsMatch(const ComponentDescription
* inComponentDescription1
, const ComponentDescription
* inComponentDescription2
)
258 return ComponentDescriptionsMatch_General(inComponentDescription1
, inComponentDescription2
, FALSE
);
261 //--------------------------------------------------------------------------
262 // determine if 2 ComponentDescriptions have matching sub-type and manufacturer codes
263 Boolean
ComponentDescriptionsMatch_Loose(const ComponentDescription
* inComponentDescription1
, const ComponentDescription
* inComponentDescription2
)
265 return ComponentDescriptionsMatch_General(inComponentDescription1
, inComponentDescription2
, TRUE
);
268 //--------------------------------------------------------------------------
269 // determine if a ComponentDescription basically matches that of a particular Component
270 Boolean
ComponentAndDescriptionMatch(Component inComponent
, const ComponentDescription
* inComponentDescription
)
272 return ComponentAndDescriptionMatch_General(inComponent
, inComponentDescription
, FALSE
);
275 //--------------------------------------------------------------------------
276 // determine if a ComponentDescription matches only the sub-type and manufacturer codes of a particular Component
277 Boolean
ComponentAndDescriptionMatch_Loosely(Component inComponent
, const ComponentDescription
* inComponentDescription
)
279 return ComponentAndDescriptionMatch_General(inComponent
, inComponentDescription
, TRUE
);
283 AUPlugin::AUPlugin (AudioEngine
& engine
, Session
& session
, boost::shared_ptr
<CAComponent
> _comp
)
284 : Plugin (engine
, session
),
286 unit (new CAAudioUnit
),
294 if (!preset_search_path_initialized
) {
295 Glib::ustring p
= Glib::get_home_dir();
296 p
+= "/Library/Audio/Presets:";
297 p
+= preset_search_path
;
298 preset_search_path
= p
;
299 preset_search_path_initialized
= true;
305 AUPlugin::AUPlugin (const AUPlugin
& other
)
307 , comp (other
.get_comp())
308 , unit (new CAAudioUnit
)
309 , initialized (false)
313 , current_buffers (0)
314 , frames_processed (0)
320 AUPlugin::~AUPlugin ()
323 unit
->Uninitialize ();
338 err
= CAAudioUnit::Open (*(comp
.get()), *unit
);
340 error
<< _("Exception thrown during AudioUnit plugin loading - plugin ignored") << endmsg
;
341 throw failed_constructor();
345 error
<< _("AudioUnit: Could not convert CAComponent to CAAudioUnit") << endmsg
;
346 throw failed_constructor ();
349 AURenderCallbackStruct renderCallbackInfo
;
351 renderCallbackInfo
.inputProc
= _render_callback
;
352 renderCallbackInfo
.inputProcRefCon
= this;
354 if ((err
= unit
->SetProperty (kAudioUnitProperty_SetRenderCallback
, kAudioUnitScope_Input
,
355 0, (void*) &renderCallbackInfo
, sizeof(renderCallbackInfo
))) != 0) {
356 cerr
<< "cannot install render callback (err = " << err
<< ')' << endl
;
357 throw failed_constructor();
360 unit
->GetElementCount (kAudioUnitScope_Global
, global_elements
);
361 unit
->GetElementCount (kAudioUnitScope_Input
, input_elements
);
362 unit
->GetElementCount (kAudioUnitScope_Output
, output_elements
);
364 /* these keep track of *configured* channel set up,
365 not potential set ups.
369 output_channels
= -1;
371 if (_set_block_size (_session
.get_block_size())) {
372 error
<< _("AUPlugin: cannot set processing block size") << endmsg
;
373 throw failed_constructor();
376 discover_parameters ();
378 Plugin::setup_controls ();
382 AUPlugin::discover_parameters ()
384 /* discover writable parameters */
386 AudioUnitScope scopes
[] = {
387 kAudioUnitScope_Global
,
388 kAudioUnitScope_Output
,
389 kAudioUnitScope_Input
392 descriptors
.clear ();
394 for (uint32_t i
= 0; i
< sizeof (scopes
) / sizeof (scopes
[0]); ++i
) {
396 AUParamInfo
param_info (unit
->AU(), false, false, scopes
[i
]);
398 for (uint32_t i
= 0; i
< param_info
.NumParams(); ++i
) {
400 AUParameterDescriptor d
;
402 d
.id
= param_info
.ParamID (i
);
404 const CAAUParameter
* param
= param_info
.GetParamInfo (d
.id
);
405 const AudioUnitParameterInfo
& info (param
->ParamInfo());
407 const int len
= CFStringGetLength (param
->GetName());;
408 char local_buffer
[len
*2];
409 Boolean good
= CFStringGetCString(param
->GetName(),local_buffer
,len
*2,kCFStringEncodingMacRoman
);
413 d
.label
= local_buffer
;
416 d
.scope
= param_info
.GetScope ();
417 d
.element
= param_info
.GetElement ();
419 /* info.units to consider */
421 kAudioUnitParameterUnit_Generic = 0
422 kAudioUnitParameterUnit_Indexed = 1
423 kAudioUnitParameterUnit_Boolean = 2
424 kAudioUnitParameterUnit_Percent = 3
425 kAudioUnitParameterUnit_Seconds = 4
426 kAudioUnitParameterUnit_SampleFrames = 5
427 kAudioUnitParameterUnit_Phase = 6
428 kAudioUnitParameterUnit_Rate = 7
429 kAudioUnitParameterUnit_Hertz = 8
430 kAudioUnitParameterUnit_Cents = 9
431 kAudioUnitParameterUnit_RelativeSemiTones = 10
432 kAudioUnitParameterUnit_MIDINoteNumber = 11
433 kAudioUnitParameterUnit_MIDIController = 12
434 kAudioUnitParameterUnit_Decibels = 13
435 kAudioUnitParameterUnit_LinearGain = 14
436 kAudioUnitParameterUnit_Degrees = 15
437 kAudioUnitParameterUnit_EqualPowerCrossfade = 16
438 kAudioUnitParameterUnit_MixerFaderCurve1 = 17
439 kAudioUnitParameterUnit_Pan = 18
440 kAudioUnitParameterUnit_Meters = 19
441 kAudioUnitParameterUnit_AbsoluteCents = 20
442 kAudioUnitParameterUnit_Octaves = 21
443 kAudioUnitParameterUnit_BPM = 22
444 kAudioUnitParameterUnit_Beats = 23
445 kAudioUnitParameterUnit_Milliseconds = 24
446 kAudioUnitParameterUnit_Ratio = 25
449 /* info.flags to consider */
453 kAudioUnitParameterFlag_CFNameRelease = (1L << 4)
454 kAudioUnitParameterFlag_HasClump = (1L << 20)
455 kAudioUnitParameterFlag_HasName = (1L << 21)
456 kAudioUnitParameterFlag_DisplayLogarithmic = (1L << 22)
457 kAudioUnitParameterFlag_IsHighResolution = (1L << 23)
458 kAudioUnitParameterFlag_NonRealTime = (1L << 24)
459 kAudioUnitParameterFlag_CanRamp = (1L << 25)
460 kAudioUnitParameterFlag_ExpertMode = (1L << 26)
461 kAudioUnitParameterFlag_HasCFNameString = (1L << 27)
462 kAudioUnitParameterFlag_IsGlobalMeta = (1L << 28)
463 kAudioUnitParameterFlag_IsElementMeta = (1L << 29)
464 kAudioUnitParameterFlag_IsReadable = (1L << 30)
465 kAudioUnitParameterFlag_IsWritable = (1L << 31)
468 d
.lower
= info
.minValue
;
469 d
.upper
= info
.maxValue
;
470 d
.default_value
= info
.defaultValue
;
472 d
.integer_step
= (info
.unit
& kAudioUnitParameterUnit_Indexed
);
473 d
.toggled
= (info
.unit
& kAudioUnitParameterUnit_Boolean
) ||
474 (d
.integer_step
&& ((d
.upper
- d
.lower
) == 1.0));
475 d
.sr_dependent
= (info
.unit
& kAudioUnitParameterUnit_SampleFrames
);
476 d
.automatable
= !d
.toggled
&&
477 !(info
.flags
& kAudioUnitParameterFlag_NonRealTime
) &&
478 (info
.flags
& kAudioUnitParameterFlag_IsWritable
);
480 d
.logarithmic
= (info
.flags
& kAudioUnitParameterFlag_DisplayLogarithmic
);
486 d
.min_unbound
= 0; // lower is bound
487 d
.max_unbound
= 0; // upper is bound
489 descriptors
.push_back (d
);
496 AUPlugin::unique_id () const
498 return AUPluginInfo::stringify_descriptor (comp
->Desc());
502 AUPlugin::label () const
504 return _info
->name
.c_str();
508 AUPlugin::parameter_count () const
510 return descriptors
.size();
514 AUPlugin::default_value (uint32_t port
)
516 if (port
< descriptors
.size()) {
517 return descriptors
[port
].default_value
;
524 AUPlugin::latency () const
526 return unit
->Latency() * _session
.frame_rate();
530 AUPlugin::set_parameter (uint32_t which
, float val
)
532 if (which
< descriptors
.size()) {
533 const AUParameterDescriptor
& d (descriptors
[which
]);
534 unit
->SetParameter (d
.id
, d
.scope
, d
.element
, val
);
539 AUPlugin::get_parameter (uint32_t which
) const
542 if (which
< descriptors
.size()) {
543 const AUParameterDescriptor
& d (descriptors
[which
]);
544 unit
->GetParameter(d
.id
, d
.scope
, d
.element
, val
);
550 AUPlugin::get_parameter_descriptor (uint32_t which
, ParameterDescriptor
& pd
) const
552 if (which
< descriptors
.size()) {
553 pd
= descriptors
[which
];
560 AUPlugin::nth_parameter (uint32_t which
, bool& ok
) const
562 if (which
< descriptors
.size()) {
571 AUPlugin::activate ()
575 if ((err
= unit
->Initialize()) != noErr
) {
576 error
<< string_compose (_("AUPlugin: %1 cannot initialize plugin (err = %2)"), name(), err
) << endmsg
;
578 frames_processed
= 0;
585 AUPlugin::deactivate ()
587 unit
->GlobalReset ();
591 AUPlugin::set_block_size (nframes_t nframes
)
593 _set_block_size (nframes
);
597 AUPlugin::_set_block_size (nframes_t nframes
)
599 bool was_initialized
= initialized
;
600 UInt32 numFrames
= nframes
;
604 unit
->Uninitialize ();
608 if ((err
= unit
->SetProperty (kAudioUnitProperty_MaximumFramesPerSlice
, kAudioUnitScope_Global
,
609 0, &numFrames
, sizeof (numFrames
))) != noErr
) {
610 cerr
<< "cannot set max frames (err = " << err
<< ')' << endl
;
614 if (was_initialized
) {
622 AUPlugin::configure_io (int32_t in
, int32_t out
)
624 AudioStreamBasicDescription streamFormat
;
626 streamFormat
.mSampleRate
= _session
.frame_rate();
627 streamFormat
.mFormatID
= kAudioFormatLinearPCM
;
628 streamFormat
.mFormatFlags
= kAudioFormatFlagIsFloat
|kAudioFormatFlagIsPacked
|kAudioFormatFlagIsNonInterleaved
;
630 #ifdef __LITTLE_ENDIAN__
633 streamFormat
.mFormatFlags
|= kAudioFormatFlagIsBigEndian
;
636 streamFormat
.mBitsPerChannel
= 32;
637 streamFormat
.mFramesPerPacket
= 1;
639 /* apple says that for non-interleaved data, these
640 values always refer to a single channel.
642 streamFormat
.mBytesPerPacket
= 4;
643 streamFormat
.mBytesPerFrame
= 4;
645 streamFormat
.mChannelsPerFrame
= in
;
647 if (set_input_format (streamFormat
) != 0) {
651 streamFormat
.mChannelsPerFrame
= out
;
653 if (set_output_format (streamFormat
) != 0) {
657 return Plugin::configure_io (in
, out
);
661 AUPlugin::can_do (int32_t in
, int32_t& out
)
663 // XXX as of May 13th 2008, AU plugin support returns a count of either 1 or -1. We never
664 // attempt to multiply-instantiate plugins to meet io configurations.
666 int32_t plugcnt
= -1;
667 AUPluginInfoPtr pinfo
= boost::dynamic_pointer_cast
<AUPluginInfo
>(get_info());
671 vector
<pair
<int,int> >& io_configs
= pinfo
->cache
.io_configs
;
673 for (vector
<pair
<int,int> >::iterator i
= io_configs
.begin(); i
!= io_configs
.end(); ++i
) {
675 int32_t possible_in
= i
->first
;
676 int32_t possible_out
= i
->second
;
678 if (possible_out
== 0) {
679 warning
<< string_compose (_("AU %1 has zero outputs - configuration ignored"), name()) << endmsg
;
683 if (possible_in
== 0) {
685 /* instrument plugin, always legal but throws away inputs ...
688 if (possible_out
== -1) {
689 /* out much match in (UNLIKELY!!) */
692 } else if (possible_out
== -2) {
693 /* any configuration possible, pick matching */
696 } else if (possible_out
< -2) {
697 /* explicit variable number of outputs, pick maximum */
701 /* exact number of outputs */
707 if (possible_in
== -1) {
709 /* wildcard for input */
711 if (possible_out
== -1) {
712 /* out much match in */
715 } else if (possible_out
== -2) {
716 /* any configuration possible, pick matching */
719 } else if (possible_out
< -2) {
720 /* explicit variable number of outputs, pick maximum */
724 /* exact number of outputs */
730 if (possible_in
== -2) {
732 if (possible_out
== -1) {
733 /* any configuration possible, pick matching */
736 } else if (possible_out
== -2) {
737 error
<< string_compose (_("AU plugin %1 has illegal IO configuration (-2,-2)"), name())
740 } else if (possible_out
< -2) {
741 /* explicit variable number of outputs, pick maximum */
745 /* exact number of outputs */
751 if (possible_in
< -2) {
753 /* explicit variable number of inputs */
755 if (in
> -possible_in
) {
756 /* request is too large */
760 if (possible_out
== -1) {
761 /* out must match in */
764 } else if (possible_out
== -2) {
765 error
<< string_compose (_("AU plugin %1 has illegal IO configuration (-2,-2)"), name())
768 } else if (possible_out
< -2) {
769 /* explicit variable number of outputs, pick maximum */
773 /* exact number of outputs */
779 if (possible_in
== in
) {
781 /* exact number of inputs ... must match obviously */
783 if (possible_out
== -1) {
784 /* out must match in */
787 } else if (possible_out
== -2) {
788 /* any output configuration, pick matching */
791 } else if (possible_out
< -2) {
792 /* explicit variable number of outputs, pick maximum */
796 /* exact number of outputs */
812 AUPlugin::set_input_format (AudioStreamBasicDescription
& fmt
)
814 return set_stream_format (kAudioUnitScope_Input
, input_elements
, fmt
);
818 AUPlugin::set_output_format (AudioStreamBasicDescription
& fmt
)
820 if (set_stream_format (kAudioUnitScope_Output
, output_elements
, fmt
) != 0) {
829 buffers
= (AudioBufferList
*) malloc (offsetof(AudioBufferList
, mBuffers
) +
830 fmt
.mChannelsPerFrame
* sizeof(AudioBuffer
));
832 Glib::Mutex::Lock
em (_session
.engine().process_lock());
833 IO::MoreOutputs (fmt
.mChannelsPerFrame
);
839 AUPlugin::set_stream_format (int scope
, uint32_t cnt
, AudioStreamBasicDescription
& fmt
)
843 for (uint32_t i
= 0; i
< cnt
; ++i
) {
844 if ((result
= unit
->SetFormat (scope
, i
, fmt
)) != 0) {
845 error
<< string_compose (_("AUPlugin: could not set stream format for %1/%2 (err = %3)"),
846 (scope
== kAudioUnitScope_Input
? "input" : "output"), i
, result
) << endmsg
;
851 if (scope
== kAudioUnitScope_Input
) {
852 input_channels
= fmt
.mChannelsPerFrame
;
854 output_channels
= fmt
.mChannelsPerFrame
;
861 AUPlugin::input_streams() const
863 if (input_channels
< 0) {
864 warning
<< string_compose (_("AUPlugin: %1 input_streams() called without any format set!"), name()) << endmsg
;
867 return input_channels
;
872 AUPlugin::output_streams() const
874 if (output_channels
< 0) {
875 warning
<< string_compose (_("AUPlugin: %1 output_streams() called without any format set!"), name()) << endmsg
;
878 return output_channels
;
882 AUPlugin::render_callback(AudioUnitRenderActionFlags
*ioActionFlags
,
883 const AudioTimeStamp
*inTimeStamp
,
885 UInt32 inNumberFrames
,
886 AudioBufferList
* ioData
)
888 /* not much to do - the data is already in the buffers given to us in connect_and_run() */
890 if (current_maxbuf
== 0) {
891 error
<< _("AUPlugin: render callback called illegally!") << endmsg
;
892 return kAudioUnitErr_CannotDoInCurrentContext
;
895 for (uint32_t i
= 0; i
< current_maxbuf
; ++i
) {
896 ioData
->mBuffers
[i
].mNumberChannels
= 1;
897 ioData
->mBuffers
[i
].mDataByteSize
= sizeof (Sample
) * inNumberFrames
;
898 ioData
->mBuffers
[i
].mData
= (*current_buffers
)[i
] + cb_offset
+ current_offset
;
901 cb_offset
+= inNumberFrames
;
907 AUPlugin::connect_and_run (vector
<Sample
*>& bufs
, uint32_t maxbuf
, int32_t& in
, int32_t& out
, nframes_t nframes
, nframes_t offset
)
909 AudioUnitRenderActionFlags flags
= 0;
912 current_buffers
= &bufs
;
913 current_maxbuf
= maxbuf
;
914 current_offset
= offset
;
917 buffers
->mNumberBuffers
= maxbuf
;
919 for (uint32_t i
= 0; i
< maxbuf
; ++i
) {
920 buffers
->mBuffers
[i
].mNumberChannels
= 1;
921 buffers
->mBuffers
[i
].mDataByteSize
= nframes
* sizeof (Sample
);
922 buffers
->mBuffers
[i
].mData
= 0;
925 ts
.mSampleTime
= frames_processed
;
926 ts
.mFlags
= kAudioTimeStampSampleTimeValid
;
928 if (unit
->Render (&flags
, &ts
, 0, nframes
, buffers
) == noErr
) {
931 frames_processed
+= nframes
;
933 for (uint32_t i
= 0; i
< maxbuf
; ++i
) {
934 if (bufs
[i
] + offset
!= buffers
->mBuffers
[i
].mData
) {
935 memcpy (bufs
[i
]+offset
, buffers
->mBuffers
[i
].mData
, nframes
* sizeof (Sample
));
945 AUPlugin::automatable() const
947 set
<uint32_t> automates
;
949 for (uint32_t i
= 0; i
< descriptors
.size(); ++i
) {
950 if (descriptors
[i
].automatable
) {
951 automates
.insert (i
);
959 AUPlugin::describe_parameter (uint32_t param
)
961 return descriptors
[param
].label
;
965 AUPlugin::print_parameter (uint32_t param
, char* buf
, uint32_t len
) const
967 // NameValue stuff here
971 AUPlugin::parameter_is_audio (uint32_t) const
977 AUPlugin::parameter_is_control (uint32_t) const
983 AUPlugin::parameter_is_input (uint32_t) const
989 AUPlugin::parameter_is_output (uint32_t) const
995 AUPlugin::get_state()
997 LocaleGuard
lg (X_("POSIX"));
998 XMLNode
*root
= new XMLNode (state_node_name());
1000 #ifdef AU_STATE_SUPPORT
1002 CFPropertyListRef propertyList
;
1004 if (unit
->GetAUPreset (propertyList
) != noErr
) {
1008 // Convert the property list into XML data.
1010 xmlData
= CFPropertyListCreateXMLData( kCFAllocatorDefault
, propertyList
);
1013 error
<< _("Could not create XML version of property list") << endmsg
;
1017 /* re-parse XML bytes to create a libxml++ XMLTree that we can merge into
1018 our state node. GACK!
1023 if (t
.read_buffer (string ((const char*) CFDataGetBytePtr (xmlData
), CFDataGetLength (xmlData
)))) {
1025 root
->add_child_copy (*t
.root());
1029 CFRelease (xmlData
);
1030 CFRelease (propertyList
);
1032 if (!seen_get_state_message
) {
1033 info
<< _("Saving AudioUnit settings is not supported in this build of Ardour. Consider paying for a newer version")
1035 seen_get_state_message
= true;
1043 AUPlugin::set_state(const XMLNode
& node
)
1045 #ifdef AU_STATE_SUPPORT
1047 CFPropertyListRef propertyList
;
1048 LocaleGuard
lg (X_("POSIX"));
1050 if (node
.name() != state_node_name()) {
1051 error
<< _("Bad node sent to AUPlugin::set_state") << endmsg
;
1055 if (node
.children().empty()) {
1059 XMLNode
* top
= node
.children().front();
1060 XMLNode
* copy
= new XMLNode (*top
);
1065 const string
& xml
= t
.write_buffer ();
1066 CFDataRef xmlData
= CFDataCreateWithBytesNoCopy (kCFAllocatorDefault
, (UInt8
*) xml
.data(), xml
.length(), kCFAllocatorNull
);
1067 CFStringRef errorString
;
1069 propertyList
= CFPropertyListCreateFromXMLData( kCFAllocatorDefault
,
1071 kCFPropertyListImmutable
,
1074 CFRelease (xmlData
);
1077 if (unit
->SetAUPreset (propertyList
) == noErr
) {
1080 CFRelease (propertyList
);
1085 if (!seen_set_state_message
) {
1086 info
<< _("Restoring AudioUnit settings is not supported in this build of Ardour. Consider paying for a newer version")
1094 AUPlugin::load_preset (const string preset_label
)
1096 #ifdef AU_STATE_SUPPORT
1098 CFPropertyListRef propertyList
;
1100 PresetMap::iterator x
= preset_map
.find (preset_label
);
1102 if (x
== preset_map
.end()) {
1106 if ((propertyList
= load_property_list (x
->second
)) != 0) {
1107 if (unit
->SetAUPreset (propertyList
) == noErr
) {
1110 CFRelease(propertyList
);
1115 if (!seen_loading_message
) {
1116 info
<< _("Loading AudioUnit presets is not supported in this build of Ardour. Consider paying for a newer version")
1118 seen_loading_message
= true;
1125 AUPlugin::save_preset (string preset_name
)
1127 #ifdef AU_STATE_SUPPORT
1128 CFPropertyListRef propertyList
;
1129 vector
<Glib::ustring
> v
;
1130 Glib::ustring user_preset_path
;
1133 std::string m
= maker();
1134 std::string n
= name();
1136 strip_whitespace_edges (m
);
1137 strip_whitespace_edges (n
);
1139 v
.push_back (Glib::get_home_dir());
1140 v
.push_back ("Library");
1141 v
.push_back ("Audio");
1142 v
.push_back ("Presets");
1146 user_preset_path
= Glib::build_filename (v
);
1148 if (g_mkdir_with_parents (user_preset_path
.c_str(), 0775) < 0) {
1149 error
<< string_compose (_("Cannot create user plugin presets folder (%1)"), user_preset_path
) << endmsg
;
1153 if (unit
->GetAUPreset (propertyList
) != noErr
) {
1157 // add the actual preset name */
1159 v
.push_back (preset_name
+ preset_suffix
);
1163 user_preset_path
= Glib::build_filename (v
);
1165 set_preset_name_in_plist (propertyList
, preset_name
);
1167 if (save_property_list (propertyList
, user_preset_path
)) {
1168 error
<< string_compose (_("Saving plugin state to %1 failed"), user_preset_path
) << endmsg
;
1172 CFRelease(propertyList
);
1176 if (!seen_saving_message
) {
1177 info
<< _("Saving AudioUnit presets is not supported in this build of Ardour. Consider paying for a newer version")
1179 seen_saving_message
= true;
1185 //-----------------------------------------------------------------------------
1186 // this is just a little helper function used by GetAUComponentDescriptionFromPresetFile()
1188 GetDictionarySInt32Value(CFDictionaryRef inAUStateDictionary
, CFStringRef inDictionaryKey
, Boolean
* outSuccess
)
1190 CFNumberRef cfNumber
;
1191 SInt32 numberValue
= 0;
1192 Boolean dummySuccess
;
1194 if (outSuccess
== NULL
)
1195 outSuccess
= &dummySuccess
;
1196 if ( (inAUStateDictionary
== NULL
) || (inDictionaryKey
== NULL
) )
1198 *outSuccess
= FALSE
;
1202 cfNumber
= (CFNumberRef
) CFDictionaryGetValue(inAUStateDictionary
, inDictionaryKey
);
1203 if (cfNumber
== NULL
)
1205 *outSuccess
= FALSE
;
1208 *outSuccess
= CFNumberGetValue(cfNumber
, kCFNumberSInt32Type
, &numberValue
);
1216 GetAUComponentDescriptionFromStateData(CFPropertyListRef inAUStateData
, ComponentDescription
* outComponentDescription
)
1218 CFDictionaryRef auStateDictionary
;
1219 ComponentDescription tempDesc
= {0};
1220 SInt32 versionValue
;
1223 if ( (inAUStateData
== NULL
) || (outComponentDescription
== NULL
) )
1226 // the property list for AU state data must be of the dictionary type
1227 if (CFGetTypeID(inAUStateData
) != CFDictionaryGetTypeID()) {
1228 return kAudioUnitErr_InvalidPropertyValue
;
1231 auStateDictionary
= (CFDictionaryRef
)inAUStateData
;
1233 // first check to make sure that the version of the AU state data is one that we know understand
1234 // XXX should I really do this? later versions would probably still hold these ID keys, right?
1235 versionValue
= GetDictionarySInt32Value(auStateDictionary
, CFSTR(kAUPresetVersionKey
), &gotValue
);
1238 return kAudioUnitErr_InvalidPropertyValue
;
1240 #define kCurrentSavedStateVersion 0
1241 if (versionValue
!= kCurrentSavedStateVersion
) {
1242 return kAudioUnitErr_InvalidPropertyValue
;
1245 // grab the ComponentDescription values from the AU state data
1246 tempDesc
.componentType
= (OSType
) GetDictionarySInt32Value(auStateDictionary
, CFSTR(kAUPresetTypeKey
), NULL
);
1247 tempDesc
.componentSubType
= (OSType
) GetDictionarySInt32Value(auStateDictionary
, CFSTR(kAUPresetSubtypeKey
), NULL
);
1248 tempDesc
.componentManufacturer
= (OSType
) GetDictionarySInt32Value(auStateDictionary
, CFSTR(kAUPresetManufacturerKey
), NULL
);
1249 // zero values are illegit for specific ComponentDescriptions, so zero for any value means that there was an error
1250 if ( (tempDesc
.componentType
== 0) || (tempDesc
.componentSubType
== 0) || (tempDesc
.componentManufacturer
== 0) )
1251 return kAudioUnitErr_InvalidPropertyValue
;
1253 *outComponentDescription
= tempDesc
;
1258 static bool au_preset_filter (const string
& str
, void* arg
)
1260 /* Not a dotfile, has a prefix before a period, suffix is aupreset */
1264 ret
= (str
[0] != '.' && str
.length() > 9 && str
.find (preset_suffix
) == (str
.length() - preset_suffix
.length()));
1268 /* check the preset file path name against this plugin
1269 ID. The idea is that all preset files for this plugin
1270 include "<manufacturer>/<plugin-name>" in their path.
1273 Plugin
* p
= (Plugin
*) arg
;
1274 string match
= p
->maker();
1278 ret
= str
.find (match
) != string::npos
;
1281 string m
= p
->maker ();
1282 string n
= p
->name ();
1283 strip_whitespace_edges (m
);
1284 strip_whitespace_edges (n
);
1289 ret
= str
.find (match
) != string::npos
;
1297 check_and_get_preset_name (Component component
, const string
& pathstr
, string
& preset_name
)
1300 CFPropertyListRef plist
;
1301 ComponentDescription presetDesc
;
1304 plist
= load_property_list (pathstr
);
1310 // get the ComponentDescription from the AU preset file
1312 status
= GetAUComponentDescriptionFromStateData(plist
, &presetDesc
);
1314 if (status
== noErr
) {
1315 if (ComponentAndDescriptionMatch_Loosely(component
, &presetDesc
)) {
1317 /* try to get the preset name from the property list */
1319 if (CFGetTypeID(plist
) == CFDictionaryGetTypeID()) {
1321 const void* psk
= CFDictionaryGetValue ((CFMutableDictionaryRef
)plist
, CFSTR(kAUPresetNameKey
));
1325 const char* p
= CFStringGetCStringPtr ((CFStringRef
) psk
, kCFStringEncodingUTF8
);
1328 char buf
[PATH_MAX
+1];
1330 if (CFStringGetCString ((CFStringRef
)psk
, buf
, sizeof (buf
), kCFStringEncodingUTF8
)) {
1345 AUPlugin::current_preset() const
1349 #ifdef AU_STATE_SUPPORT
1350 CFPropertyListRef propertyList
;
1352 if (unit
->GetAUPreset (propertyList
) == noErr
) {
1353 preset_name
= get_preset_name_in_plist (propertyList
);
1354 CFRelease(propertyList
);
1361 AUPlugin::get_presets ()
1363 vector
<string
*>* preset_files
;
1364 vector
<string
> presets
;
1365 PathScanner scanner
;
1367 preset_files
= scanner (preset_search_path
, au_preset_filter
, this, true, true, -1, true);
1369 if (!preset_files
) {
1373 for (vector
<string
*>::iterator x
= preset_files
->begin(); x
!= preset_files
->end(); ++x
) {
1375 string path
= *(*x
);
1378 /* make an initial guess at the preset name using the path */
1380 preset_name
= Glib::path_get_basename (path
);
1381 preset_name
= preset_name
.substr (0, preset_name
.find_last_of ('.'));
1383 /* check that this preset file really matches this plugin
1384 and potentially get the "real" preset name from
1388 if (check_and_get_preset_name (get_comp()->Comp(), path
, preset_name
)) {
1389 presets
.push_back (preset_name
);
1390 preset_map
[preset_name
] = path
;
1396 delete preset_files
;
1402 AUPlugin::has_editor () const
1404 // even if the plugin doesn't have its own editor, the AU API can be used
1405 // to create one that looks native.
1409 AUPluginInfo::AUPluginInfo (boost::shared_ptr
<CAComponentDescription
> d
)
1415 AUPluginInfo::~AUPluginInfo ()
1420 AUPluginInfo::load (Session
& session
)
1425 boost::shared_ptr
<CAComponent
> comp (new CAComponent(*descriptor
));
1427 if (!comp
->IsValid()) {
1428 error
<< ("AudioUnit: not a valid Component") << endmsg
;
1430 plugin
.reset (new AUPlugin (session
.engine(), session
, comp
));
1433 plugin
->set_info (PluginInfoPtr (new AUPluginInfo (*this)));
1437 catch (failed_constructor
&err
) {
1438 return PluginPtr ();
1443 AUPluginInfo::au_cache_path ()
1445 return Glib::build_filename (ARDOUR::get_user_ardour_path(), "au_cache");
1449 AUPluginInfo::discover ()
1453 if (!Glib::file_test (au_cache_path(), Glib::FILE_TEST_EXISTS
)) {
1454 ARDOUR::BootMessage (_("Discovering AudioUnit plugins (could take some time ...)"));
1457 PluginInfoList plugs
;
1459 discover_fx (plugs
);
1460 discover_music (plugs
);
1461 discover_generators (plugs
);
1467 AUPluginInfo::discover_music (PluginInfoList
& plugs
)
1469 CAComponentDescription desc
;
1470 desc
.componentFlags
= 0;
1471 desc
.componentFlagsMask
= 0;
1472 desc
.componentSubType
= 0;
1473 desc
.componentManufacturer
= 0;
1474 desc
.componentType
= kAudioUnitType_MusicEffect
;
1476 discover_by_description (plugs
, desc
);
1480 AUPluginInfo::discover_fx (PluginInfoList
& plugs
)
1482 CAComponentDescription desc
;
1483 desc
.componentFlags
= 0;
1484 desc
.componentFlagsMask
= 0;
1485 desc
.componentSubType
= 0;
1486 desc
.componentManufacturer
= 0;
1487 desc
.componentType
= kAudioUnitType_Effect
;
1489 discover_by_description (plugs
, desc
);
1493 AUPluginInfo::discover_generators (PluginInfoList
& plugs
)
1495 CAComponentDescription desc
;
1496 desc
.componentFlags
= 0;
1497 desc
.componentFlagsMask
= 0;
1498 desc
.componentSubType
= 0;
1499 desc
.componentManufacturer
= 0;
1500 desc
.componentType
= kAudioUnitType_Generator
;
1502 discover_by_description (plugs
, desc
);
1506 AUPluginInfo::discover_by_description (PluginInfoList
& plugs
, CAComponentDescription
& desc
)
1510 comp
= FindNextComponent (NULL
, &desc
);
1512 while (comp
!= NULL
) {
1513 CAComponentDescription temp
;
1514 GetComponentInfo (comp
, &temp
, NULL
, NULL
, NULL
);
1516 AUPluginInfoPtr
info (new AUPluginInfo
1517 (boost::shared_ptr
<CAComponentDescription
> (new CAComponentDescription(temp
))));
1519 /* no panners, format converters or i/o AU's for our purposes
1522 switch (info
->descriptor
->Type()) {
1523 case kAudioUnitType_Panner
:
1524 case kAudioUnitType_OfflineEffect
:
1525 case kAudioUnitType_FormatConverter
:
1527 case kAudioUnitType_Output
:
1528 case kAudioUnitType_MusicDevice
:
1529 case kAudioUnitType_MusicEffect
:
1530 case kAudioUnitType_Effect
:
1531 case kAudioUnitType_Mixer
:
1532 case kAudioUnitType_Generator
:
1538 switch (info
->descriptor
->SubType()) {
1539 case kAudioUnitSubType_DefaultOutput
:
1540 case kAudioUnitSubType_SystemOutput
:
1541 case kAudioUnitSubType_GenericOutput
:
1542 case kAudioUnitSubType_AUConverter
:
1543 /* we don't want output units here */
1547 case kAudioUnitSubType_DLSSynth
:
1548 info
->category
= "DLS Synth";
1551 case kAudioUnitSubType_Varispeed
:
1552 info
->category
= "Varispeed";
1555 case kAudioUnitSubType_Delay
:
1556 info
->category
= "Delay";
1559 case kAudioUnitSubType_LowPassFilter
:
1560 info
->category
= "Low-pass Filter";
1563 case kAudioUnitSubType_HighPassFilter
:
1564 info
->category
= "High-pass Filter";
1567 case kAudioUnitSubType_BandPassFilter
:
1568 info
->category
= "Band-pass Filter";
1571 case kAudioUnitSubType_HighShelfFilter
:
1572 info
->category
= "High-shelf Filter";
1575 case kAudioUnitSubType_LowShelfFilter
:
1576 info
->category
= "Low-shelf Filter";
1579 case kAudioUnitSubType_ParametricEQ
:
1580 info
->category
= "Parametric EQ";
1583 case kAudioUnitSubType_GraphicEQ
:
1584 info
->category
= "Graphic EQ";
1587 case kAudioUnitSubType_PeakLimiter
:
1588 info
->category
= "Peak Limiter";
1591 case kAudioUnitSubType_DynamicsProcessor
:
1592 info
->category
= "Dynamics Processor";
1595 case kAudioUnitSubType_MultiBandCompressor
:
1596 info
->category
= "Multiband Compressor";
1599 case kAudioUnitSubType_MatrixReverb
:
1600 info
->category
= "Matrix Reverb";
1603 case kAudioUnitSubType_SampleDelay
:
1604 info
->category
= "Sample Delay";
1607 case kAudioUnitSubType_Pitch
:
1608 info
->category
= "Pitch";
1611 case kAudioUnitSubType_NetSend
:
1612 info
->category
= "Net Sender";
1615 case kAudioUnitSubType_3DMixer
:
1616 info
->category
= "3DMixer";
1619 case kAudioUnitSubType_MatrixMixer
:
1620 info
->category
= "MatrixMixer";
1623 case kAudioUnitSubType_ScheduledSoundPlayer
:
1624 info
->category
= "Scheduled Sound Player";
1628 case kAudioUnitSubType_AudioFilePlayer
:
1629 info
->category
= "Audio File Player";
1632 case kAudioUnitSubType_NetReceive
:
1633 info
->category
= "Net Receiver";
1637 info
->category
= "";
1640 AUPluginInfo::get_names (temp
, info
->name
, info
->creator
);
1642 info
->type
= ARDOUR::AudioUnit
;
1643 info
->unique_id
= stringify_descriptor (*info
->descriptor
);
1645 /* XXX not sure of the best way to handle plugin versioning yet
1648 CAComponent
cacomp (*info
->descriptor
);
1650 if (cacomp
.GetResourceVersion (info
->version
) != noErr
) {
1654 if (cached_io_configuration (info
->unique_id
, info
->version
, cacomp
, info
->cache
, info
->name
)) {
1656 /* here we have to map apple's wildcard system to a simple pair
1657 of values. in ::can_do() we use the whole system, but here
1658 we need a single pair of values. XXX probably means we should
1659 remove any use of these values.
1662 info
->n_inputs
= info
->cache
.io_configs
.front().first
;
1663 info
->n_outputs
= info
->cache
.io_configs
.front().second
;
1665 if (info
->cache
.io_configs
.size() > 1) {
1666 cerr
<< "ODD: variable IO config for " << info
->unique_id
<< endl
;
1669 plugs
.push_back (info
);
1672 error
<< string_compose (_("Cannot get I/O configuration info for AU %1"), info
->name
) << endmsg
;
1675 comp
= FindNextComponent (comp
, &desc
);
1680 AUPluginInfo::cached_io_configuration (const std::string
& unique_id
,
1683 AUPluginCachedInfo
& cinfo
,
1684 const std::string
& name
)
1689 /* concatenate unique ID with version to provide a key for cached info lookup.
1690 this ensures we don't get stale information, or should if plugin developers
1691 follow Apple "guidelines".
1694 snprintf (buf
, sizeof (buf
), "%u", version
);
1699 CachedInfoMap::iterator cim
= cached_info
.find (id
);
1701 if (cim
!= cached_info
.end()) {
1702 cinfo
= cim
->second
;
1707 AUChannelInfo
* channel_info
;
1711 ARDOUR::BootMessage (string_compose (_("Checking AudioUnit: %1"), name
));
1715 if (CAAudioUnit::Open (comp
, unit
) != noErr
) {
1721 warning
<< string_compose (_("Could not load AU plugin %1 - ignored"), name
) << endmsg
;
1722 cerr
<< string_compose (_("Could not load AU plugin %1 - ignored"), name
) << endl
;
1727 if ((ret
= unit
.GetChannelInfo (&channel_info
, cnt
)) < 0) {
1732 /* no explicit info available */
1734 cinfo
.io_configs
.push_back (pair
<int,int> (-1, -1));
1738 /* store each configuration */
1740 for (uint32_t n
= 0; n
< cnt
; ++n
) {
1741 cinfo
.io_configs
.push_back (pair
<int,int> (channel_info
[n
].inChannels
,
1742 channel_info
[n
].outChannels
));
1745 free (channel_info
);
1748 add_cached_info (id
, cinfo
);
1749 save_cached_info ();
1755 AUPluginInfo::add_cached_info (const std::string
& id
, AUPluginCachedInfo
& cinfo
)
1757 cached_info
[id
] = cinfo
;
1761 AUPluginInfo::save_cached_info ()
1765 node
= new XMLNode (X_("AudioUnitPluginCache"));
1767 for (map
<string
,AUPluginCachedInfo
>::iterator i
= cached_info
.begin(); i
!= cached_info
.end(); ++i
) {
1768 XMLNode
* parent
= new XMLNode (X_("plugin"));
1769 parent
->add_property ("id", i
->first
);
1770 node
->add_child_nocopy (*parent
);
1772 for (vector
<pair
<int, int> >::iterator j
= i
->second
.io_configs
.begin(); j
!= i
->second
.io_configs
.end(); ++j
) {
1774 XMLNode
* child
= new XMLNode (X_("io"));
1777 snprintf (buf
, sizeof (buf
), "%d", j
->first
);
1778 child
->add_property (X_("in"), buf
);
1779 snprintf (buf
, sizeof (buf
), "%d", j
->second
);
1780 child
->add_property (X_("out"), buf
);
1781 parent
->add_child_nocopy (*child
);
1786 Glib::ustring path
= au_cache_path ();
1789 tree
.set_root (node
);
1791 if (!tree
.write (path
)) {
1792 error
<< string_compose (_("could not save AU cache to %1"), path
) << endmsg
;
1793 unlink (path
.c_str());
1798 AUPluginInfo::load_cached_info ()
1800 Glib::ustring path
= au_cache_path ();
1803 if (!Glib::file_test (path
, Glib::FILE_TEST_EXISTS
)) {
1808 const XMLNode
* root (tree
.root());
1810 if (root
->name() != X_("AudioUnitPluginCache")) {
1814 cached_info
.clear ();
1816 const XMLNodeList children
= root
->children();
1818 for (XMLNodeConstIterator iter
= children
.begin(); iter
!= children
.end(); ++iter
) {
1820 const XMLNode
* child
= *iter
;
1822 if (child
->name() == X_("plugin")) {
1824 const XMLNode
* gchild
;
1825 const XMLNodeList gchildren
= child
->children();
1826 const XMLProperty
* prop
= child
->property (X_("id"));
1832 std::string id
= prop
->value();
1833 AUPluginCachedInfo cinfo
;
1835 for (XMLNodeConstIterator giter
= gchildren
.begin(); giter
!= gchildren
.end(); giter
++) {
1839 if (gchild
->name() == X_("io")) {
1843 const XMLProperty
* iprop
;
1844 const XMLProperty
* oprop
;
1846 if (((iprop
= gchild
->property (X_("in"))) != 0) &&
1847 ((oprop
= gchild
->property (X_("out"))) != 0)) {
1848 in
= atoi (iprop
->value());
1849 out
= atoi (iprop
->value());
1851 cinfo
.io_configs
.push_back (pair
<int,int> (in
, out
));
1856 if (cinfo
.io_configs
.size()) {
1857 add_cached_info (id
, cinfo
);
1866 AUPluginInfo::get_names (CAComponentDescription
& comp_desc
, std::string
& name
, Glib::ustring
& maker
)
1868 CFStringRef itemName
= NULL
;
1870 // Marc Poirier-style item name
1871 CAComponent
auComponent (comp_desc
);
1872 if (auComponent
.IsValid()) {
1873 CAComponentDescription dummydesc
;
1874 Handle nameHandle
= NewHandle(sizeof(void*));
1875 if (nameHandle
!= NULL
) {
1876 OSErr err
= GetComponentInfo(auComponent
.Comp(), &dummydesc
, nameHandle
, NULL
, NULL
);
1878 ConstStr255Param nameString
= (ConstStr255Param
) (*nameHandle
);
1879 if (nameString
!= NULL
) {
1880 itemName
= CFStringCreateWithPascalString(kCFAllocatorDefault
, nameString
, CFStringGetSystemEncoding());
1883 DisposeHandle(nameHandle
);
1887 // if Marc-style fails, do the original way
1888 if (itemName
== NULL
) {
1889 CFStringRef compTypeString
= UTCreateStringForOSType(comp_desc
.componentType
);
1890 CFStringRef compSubTypeString
= UTCreateStringForOSType(comp_desc
.componentSubType
);
1891 CFStringRef compManufacturerString
= UTCreateStringForOSType(comp_desc
.componentManufacturer
);
1893 itemName
= CFStringCreateWithFormat(kCFAllocatorDefault
, NULL
, CFSTR("%@ - %@ - %@"),
1894 compTypeString
, compManufacturerString
, compSubTypeString
);
1896 if (compTypeString
!= NULL
)
1897 CFRelease(compTypeString
);
1898 if (compSubTypeString
!= NULL
)
1899 CFRelease(compSubTypeString
);
1900 if (compManufacturerString
!= NULL
)
1901 CFRelease(compManufacturerString
);
1904 string str
= CFStringRefToStdString(itemName
);
1905 string::size_type colon
= str
.find (':');
1908 name
= str
.substr (colon
+1);
1909 maker
= str
.substr (0, colon
);
1910 // strip_whitespace_edges (maker);
1911 // strip_whitespace_edges (name);
1918 // from CAComponentDescription.cpp (in libs/appleutility in ardour source)
1919 extern char *StringForOSType (OSType t
, char *writeLocation
);
1922 AUPluginInfo::stringify_descriptor (const CAComponentDescription
& desc
)
1927 s
<< StringForOSType (desc
.Type(), str
);
1930 s
<< StringForOSType (desc
.SubType(), str
);
1933 s
<< StringForOSType (desc
.Manu(), str
);