splash updating on gdk/quartz; more filtering of automatable AU parameters
[ardour.git] / libs / ardour / audio_unit.cc
1 /*
2     Copyright (C) 2006 Paul Davis 
3         
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.
8
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.
13
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.
17
18 */
19
20 #include <sstream>
21
22 #include <pbd/transmitter.h>
23 #include <pbd/xml++.h>
24 #include <pbd/whitespace.h>
25
26 #include <glibmm/thread.h>
27
28 #include <ardour/audioengine.h>
29 #include <ardour/io.h>
30 #include <ardour/audio_unit.h>
31 #include <ardour/session.h>
32 #include <ardour/utils.h>
33
34 #include <appleutility/CAAudioUnit.h>
35 #include <appleutility/CAAUParameter.h>
36
37 #include <CoreServices/CoreServices.h>
38 #include <AudioUnit/AudioUnit.h>
39
40 #include "i18n.h"
41
42 using namespace std;
43 using namespace PBD;
44 using namespace ARDOUR;
45
46 static OSStatus 
47 _render_callback(void *userData,
48                  AudioUnitRenderActionFlags *ioActionFlags,
49                  const AudioTimeStamp    *inTimeStamp,
50                  UInt32       inBusNumber,
51                  UInt32       inNumberFrames,
52                  AudioBufferList*       ioData)
53 {
54         return ((AUPlugin*)userData)->render_callback (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
55 }
56
57 AUPlugin::AUPlugin (AudioEngine& engine, Session& session, boost::shared_ptr<CAComponent> _comp)
58         :
59         Plugin (engine, session),
60         comp (_comp),
61         unit (new CAAudioUnit),
62         initialized (false),
63         buffers (0),
64         current_maxbuf (0),
65         current_offset (0),
66         current_buffers (0),
67         frames_processed (0)
68 {                       
69         OSErr err = CAAudioUnit::Open (*(comp.get()), *unit);
70
71         if (err != noErr) {
72                 error << _("AudioUnit: Could not convert CAComponent to CAAudioUnit") << endmsg;
73                 throw failed_constructor ();
74         }
75         
76         AURenderCallbackStruct renderCallbackInfo;
77
78         renderCallbackInfo.inputProc = _render_callback;
79         renderCallbackInfo.inputProcRefCon = this;
80
81         if ((err = unit->SetProperty (kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 
82                                          0, (void*) &renderCallbackInfo, sizeof(renderCallbackInfo))) != 0) {
83                 cerr << "cannot install render callback (err = " << err << ')' << endl;
84                 throw failed_constructor();
85         }
86
87         unit->GetElementCount (kAudioUnitScope_Global, global_elements);
88         unit->GetElementCount (kAudioUnitScope_Input, input_elements);
89         unit->GetElementCount (kAudioUnitScope_Output, output_elements);
90
91         // set up the basic stream format. these fields do not change
92                             
93         streamFormat.mSampleRate = session.frame_rate();
94         streamFormat.mFormatID = kAudioFormatLinearPCM;
95         streamFormat.mFormatFlags = kAudioFormatFlagIsFloat|kAudioFormatFlagIsPacked|kAudioFormatFlagIsNonInterleaved;
96         streamFormat.mBitsPerChannel = 32;
97         streamFormat.mFramesPerPacket = 1;
98
99         // subject to later modification as we discover channel counts
100
101         streamFormat.mBytesPerPacket = 4;
102         streamFormat.mBytesPerFrame = 4;
103         streamFormat.mChannelsPerFrame = 1;
104
105         format_set = 0;
106
107         if (_set_block_size (_session.get_block_size())) {
108                 error << _("AUPlugin: cannot set processing block size") << endmsg;
109                 throw failed_constructor();
110         }
111
112         discover_parameters ();
113
114         Plugin::setup_controls ();
115 }
116
117 AUPlugin::~AUPlugin ()
118 {
119         if (unit) {
120                 unit->Uninitialize ();
121         }
122
123         if (buffers) {
124                 free (buffers);
125         }
126 }
127
128 void
129 AUPlugin::discover_parameters ()
130 {
131         /* discover writable parameters */
132         
133         cerr << "get param info, there are " << global_elements << " global elements\n";
134
135         AudioUnitScope scopes[] = { 
136                 kAudioUnitScope_Global,
137                 kAudioUnitScope_Output,
138                 kAudioUnitScope_Input
139         };
140
141         descriptors.clear ();
142
143         for (uint32_t i = 0; i < sizeof (scopes) / sizeof (scopes[0]); ++i) {
144
145                 AUParamInfo param_info (unit->AU(), false, false, scopes[i]);
146                 
147                 cerr << "discovered " << param_info.NumParams() << " parameters in scope " << i << endl;
148                 
149                 for (uint32_t i = 0; i < param_info.NumParams(); ++i) {
150
151                         AUParameterDescriptor d;
152
153                         d.id = param_info.ParamID (i);
154
155                         const CAAUParameter* param = param_info.GetParamInfo (d.id);
156                         const AudioUnitParameterInfo& info (param->ParamInfo());
157
158                         const int len = CFStringGetLength (param->GetName());;
159                         char local_buffer[len*2];
160                         Boolean good = CFStringGetCString(param->GetName(),local_buffer,len*2,kCFStringEncodingMacRoman);
161                         if (!good) {
162                                 d.label = "???";
163                         } else {
164                                 d.label = local_buffer;
165                         }
166
167                         d.scope = param_info.GetScope ();
168                         d.element = param_info.GetElement ();
169
170                         /* info.units to consider */
171                         /*
172                           kAudioUnitParameterUnit_Generic             = 0
173                           kAudioUnitParameterUnit_Indexed             = 1
174                           kAudioUnitParameterUnit_Boolean             = 2
175                           kAudioUnitParameterUnit_Percent             = 3
176                           kAudioUnitParameterUnit_Seconds             = 4
177                           kAudioUnitParameterUnit_SampleFrames        = 5
178                           kAudioUnitParameterUnit_Phase               = 6
179                           kAudioUnitParameterUnit_Rate                = 7
180                           kAudioUnitParameterUnit_Hertz               = 8
181                           kAudioUnitParameterUnit_Cents               = 9
182                           kAudioUnitParameterUnit_RelativeSemiTones   = 10
183                           kAudioUnitParameterUnit_MIDINoteNumber      = 11
184                           kAudioUnitParameterUnit_MIDIController      = 12
185                           kAudioUnitParameterUnit_Decibels            = 13
186                           kAudioUnitParameterUnit_LinearGain          = 14
187                           kAudioUnitParameterUnit_Degrees             = 15
188                           kAudioUnitParameterUnit_EqualPowerCrossfade = 16
189                           kAudioUnitParameterUnit_MixerFaderCurve1    = 17
190                           kAudioUnitParameterUnit_Pan                 = 18
191                           kAudioUnitParameterUnit_Meters              = 19
192                           kAudioUnitParameterUnit_AbsoluteCents       = 20
193                           kAudioUnitParameterUnit_Octaves             = 21
194                           kAudioUnitParameterUnit_BPM                 = 22
195                           kAudioUnitParameterUnit_Beats               = 23
196                           kAudioUnitParameterUnit_Milliseconds        = 24
197                           kAudioUnitParameterUnit_Ratio               = 25
198                         */
199
200                         /* info.flags to consider */
201
202                         /*
203
204                           kAudioUnitParameterFlag_CFNameRelease       = (1L << 4)
205                           kAudioUnitParameterFlag_HasClump            = (1L << 20)
206                           kAudioUnitParameterFlag_HasName             = (1L << 21)
207                           kAudioUnitParameterFlag_DisplayLogarithmic  = (1L << 22)
208                           kAudioUnitParameterFlag_IsHighResolution    = (1L << 23)
209                           kAudioUnitParameterFlag_NonRealTime         = (1L << 24)
210                           kAudioUnitParameterFlag_CanRamp             = (1L << 25)
211                           kAudioUnitParameterFlag_ExpertMode          = (1L << 26)
212                           kAudioUnitParameterFlag_HasCFNameString     = (1L << 27)
213                           kAudioUnitParameterFlag_IsGlobalMeta        = (1L << 28)
214                           kAudioUnitParameterFlag_IsElementMeta       = (1L << 29)
215                           kAudioUnitParameterFlag_IsReadable          = (1L << 30)
216                           kAudioUnitParameterFlag_IsWritable          = (1L << 31)
217                         */
218
219                         d.integer_step = (info.unit & kAudioUnitParameterUnit_Indexed);
220                         d.toggled = (info.unit & kAudioUnitParameterUnit_Boolean);
221                         d.sr_dependent = (info.unit & kAudioUnitParameterUnit_SampleFrames);
222                         d.automatable = !d.toggled && 
223                                 !(info.flags & kAudioUnitParameterFlag_NonRealTime) &&
224                                 (info.flags & kAudioUnitParameterFlag_IsWritable);
225                         
226                         d.logarithmic = (info.flags & kAudioUnitParameterFlag_DisplayLogarithmic);
227                         d.unit = info.unit;
228
229                         d.lower = info.minValue;
230                         d.upper = info.maxValue;
231                         d.default_value = info.defaultValue;
232                         d.step = 1.0;
233                         d.smallstep = 0.1;
234                         d.largestep = 10.0;
235                         d.min_unbound = 0; // lower is bound
236                         d.max_unbound = 0; // upper is bound
237
238                         descriptors.push_back (d);
239                 }
240         }
241 }
242
243
244 string
245 AUPlugin::unique_id () const
246 {
247         return AUPluginInfo::stringify_descriptor (comp->Desc());
248 }
249
250 const char *
251 AUPlugin::label () const
252 {
253         return _info->name.c_str();
254 }
255
256 uint32_t
257 AUPlugin::parameter_count () const
258 {
259         return descriptors.size();
260 }
261
262 float
263 AUPlugin::default_value (uint32_t port)
264 {
265         if (port < descriptors.size()) {
266                 return descriptors[port].default_value;
267         }
268
269         return 0;
270 }
271
272 nframes_t
273 AUPlugin::latency () const
274 {
275         return unit->Latency ();
276 }
277
278 void
279 AUPlugin::set_parameter (uint32_t which, float val)
280 {
281         // unit->SetParameter (id, 0, val);
282 }
283
284 float
285 AUPlugin::get_parameter (uint32_t which) const
286 {
287         float outValue = 0.0;
288         
289         // unit->GetParameter(parameter_map[which].first, parameter_map[which].second, 0, outValue);
290         
291         return outValue;
292 }
293
294 int
295 AUPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& pd) const
296 {
297         if (which < descriptors.size()) {
298                 pd = descriptors[which];
299                 return 0;
300         } 
301         return -1;
302 }
303
304 uint32_t
305 AUPlugin::nth_parameter (uint32_t which, bool& ok) const
306 {
307         if (which < descriptors.size()) {
308                 ok = true;
309                 return which;
310         }
311         ok = false;
312         return 0;
313 }
314
315 void
316 AUPlugin::activate ()
317 {
318         if (!initialized) {
319                 OSErr err;
320                 if ((err = unit->Initialize()) != noErr) {
321                         error << string_compose (_("AUPlugin: cannot initialize plugin (err = %1)"), err) << endmsg;
322                 } else {
323                         frames_processed = 0;
324                         initialized = true;
325                 }
326         }
327 }
328
329 void
330 AUPlugin::deactivate ()
331 {
332         unit->GlobalReset ();
333 }
334
335 void
336 AUPlugin::set_block_size (nframes_t nframes)
337 {
338         _set_block_size (nframes);
339 }
340
341 int
342 AUPlugin::_set_block_size (nframes_t nframes)
343 {
344         bool was_initialized = initialized;
345         UInt32 numFrames = nframes;
346         OSErr err;
347
348         if (initialized) {
349                 unit->Uninitialize ();
350         }
351
352         if ((err = unit->SetProperty (kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 
353                                       0, &numFrames, sizeof (numFrames))) != noErr) {
354                 cerr << "cannot set max frames (err = " << err << ')' << endl;
355                 return -1;
356         }
357
358         if (was_initialized) {
359                 activate ();
360         }
361
362         return 0;
363 }
364
365 int32_t 
366 AUPlugin::can_support_input_configuration (int32_t in)
367 {       
368         streamFormat.mChannelsPerFrame = in;
369         /* apple says that for non-interleaved data, these
370            values always refer to a single channel.
371         */
372         streamFormat.mBytesPerPacket = 4;
373         streamFormat.mBytesPerFrame = 4;
374
375         if (set_input_format () == 0) {
376                 return 1;
377         } else {
378                 return -1;
379         }
380 }
381
382 int
383 AUPlugin::set_input_format ()
384 {
385         return set_stream_format (kAudioUnitScope_Input, input_elements);
386 }
387
388 int
389 AUPlugin::set_output_format ()
390 {
391         return set_stream_format (kAudioUnitScope_Output, output_elements);
392 }
393
394 int
395 AUPlugin::set_stream_format (int scope, uint32_t cnt)
396 {
397         OSErr result;
398
399         for (uint32_t i = 0; i < cnt; ++i) {
400                 if ((result = unit->SetFormat (scope, i, streamFormat)) != 0) {
401                         error << string_compose (_("AUPlugin: could not set stream format for %1/%2 (err = %3)"),
402                                                  (scope == kAudioUnitScope_Input ? "input" : "output"), i, result) << endmsg;
403                         return -1;
404                 }
405         }
406
407         if (scope == kAudioUnitScope_Input) {
408                 format_set |= 0x1;
409         } else {
410                 format_set |= 0x2;
411         }
412
413         return 0;
414 }
415
416 int32_t 
417 AUPlugin::compute_output_streams (int32_t nplugins)
418 {
419         /* we will never replicate AU plugins - either they can do the I/O we need
420            or not. thus, we can ignore nplugins entirely.
421         */
422         
423         if (set_output_format() == 0) {
424
425                 if (buffers) {
426                         free (buffers);
427                         buffers = 0;
428                 }
429
430                 buffers = (AudioBufferList *) malloc (offsetof(AudioBufferList, mBuffers) + 
431                                                       streamFormat.mChannelsPerFrame * sizeof(AudioBuffer));
432
433                 Glib::Mutex::Lock em (_session.engine().process_lock());
434                 IO::MoreOutputs (streamFormat.mChannelsPerFrame);
435
436                 return streamFormat.mChannelsPerFrame;
437         } else {
438                 return -1;
439         }
440 }
441
442 uint32_t
443 AUPlugin::output_streams() const
444 {
445         if (!(format_set & 0x2)) {
446                 warning << _("AUPlugin: output_streams() called without any format set!") << endmsg;
447                 return 1;
448         }
449         return streamFormat.mChannelsPerFrame;
450 }
451
452
453 uint32_t
454 AUPlugin::input_streams() const
455 {
456         if (!(format_set & 0x1)) {
457                 warning << _("AUPlugin: input_streams() called without any format set!") << endmsg;
458                 return 1;
459         }
460         return streamFormat.mChannelsPerFrame;
461 }
462
463 OSStatus 
464 AUPlugin::render_callback(AudioUnitRenderActionFlags *ioActionFlags,
465                           const AudioTimeStamp    *inTimeStamp,
466                           UInt32       inBusNumber,
467                           UInt32       inNumberFrames,
468                           AudioBufferList*       ioData)
469 {
470         /* not much to do - the data is already in the buffers given to us in connect_and_run() */
471
472         if (current_maxbuf == 0) {
473                 error << _("AUPlugin: render callback called illegally!") << endmsg;
474                 return kAudioUnitErr_CannotDoInCurrentContext;
475         }
476
477         for (uint32_t i = 0; i < current_maxbuf; ++i) {
478                 ioData->mBuffers[i].mNumberChannels = 1;
479                 ioData->mBuffers[i].mDataByteSize = sizeof (Sample) * inNumberFrames;
480                 ioData->mBuffers[i].mData = (*current_buffers)[i] + cb_offset + current_offset;
481         }
482
483         cb_offset += inNumberFrames;
484
485         return noErr;
486 }
487
488 int
489 AUPlugin::connect_and_run (vector<Sample*>& bufs, uint32_t maxbuf, int32_t& in, int32_t& out, nframes_t nframes, nframes_t offset)
490 {
491         AudioUnitRenderActionFlags flags = 0;
492         AudioTimeStamp ts;
493
494         current_buffers = &bufs;
495         current_maxbuf = maxbuf;
496         current_offset = offset;
497         cb_offset = 0;
498
499         buffers->mNumberBuffers = maxbuf;
500
501         for (uint32_t i = 0; i < maxbuf; ++i) {
502                 buffers->mBuffers[i].mNumberChannels = 1;
503                 buffers->mBuffers[i].mDataByteSize = nframes * sizeof (Sample);
504                 buffers->mBuffers[i].mData = 0;
505         }
506
507         ts.mSampleTime = frames_processed;
508         ts.mFlags = kAudioTimeStampSampleTimeValid;
509
510         if (unit->Render (&flags, &ts, 0, nframes, buffers) == noErr) {
511
512                 current_maxbuf = 0;
513                 frames_processed += nframes;
514                 
515                 for (uint32_t i = 0; i < maxbuf; ++i) {
516                         if (bufs[i] + offset != buffers->mBuffers[i].mData) {
517                                 memcpy (bufs[i]+offset, buffers->mBuffers[i].mData, nframes * sizeof (Sample));
518                         }
519                 }
520                 return 0;
521         }
522
523         return -1;
524 }
525
526 set<uint32_t>
527 AUPlugin::automatable() const
528 {
529         set<uint32_t> automates;
530
531         for (uint32_t i = 0; i < descriptors.size(); ++i) {
532                 if (descriptors[i].automatable) {
533                         automates.insert (i);
534                 }
535         }
536
537         return automates;
538 }
539
540 string
541 AUPlugin::describe_parameter (uint32_t param)
542 {
543         return descriptors[param].label;
544 }
545
546 void
547 AUPlugin::print_parameter (uint32_t param, char* buf, uint32_t len) const
548 {
549         // NameValue stuff here
550 }
551
552 bool
553 AUPlugin::parameter_is_audio (uint32_t) const
554 {
555         return false;
556 }
557
558 bool
559 AUPlugin::parameter_is_control (uint32_t) const
560 {
561         return true;
562 }
563
564 bool
565 AUPlugin::parameter_is_input (uint32_t) const
566 {
567         return false;
568 }
569
570 bool
571 AUPlugin::parameter_is_output (uint32_t) const
572 {
573         return false;
574 }
575
576 XMLNode&
577 AUPlugin::get_state()
578 {
579         XMLNode *root = new XMLNode (state_node_name());
580         LocaleGuard lg (X_("POSIX"));
581         return *root;
582 }
583
584 int
585 AUPlugin::set_state(const XMLNode& node)
586 {
587         return -1;
588 }
589
590 bool
591 AUPlugin::save_preset (string name)
592 {
593         return false;
594 }
595
596 bool
597 AUPlugin::load_preset (const string preset_label)
598 {
599         return false;
600 }
601
602 vector<string>
603 AUPlugin::get_presets ()
604 {
605         vector<string> presets;
606         
607         return presets;
608 }
609
610 bool
611 AUPlugin::has_editor () const
612 {
613         // even if the plugin doesn't have its own editor, the AU API can be used
614         // to create one that looks native.
615         return true;
616 }
617
618 AUPluginInfo::AUPluginInfo (boost::shared_ptr<CAComponentDescription> d)
619         : descriptor (d)
620 {
621
622 }
623
624 AUPluginInfo::~AUPluginInfo ()
625 {
626 }
627
628 PluginPtr
629 AUPluginInfo::load (Session& session)
630 {
631         try {
632                 PluginPtr plugin;
633
634                 boost::shared_ptr<CAComponent> comp (new CAComponent(*descriptor));
635                 
636                 if (!comp->IsValid()) {
637                         error << ("AudioUnit: not a valid Component") << endmsg;
638                 } else {
639                         plugin.reset (new AUPlugin (session.engine(), session, comp));
640                 }
641                 
642                 plugin->set_info (PluginInfoPtr (new AUPluginInfo (*this)));
643                 return plugin;
644         }
645
646         catch (failed_constructor &err) {
647                 return PluginPtr ((Plugin*) 0);
648         }
649 }
650
651 PluginInfoList
652 AUPluginInfo::discover ()
653 {
654         PluginInfoList plugs;
655         
656         discover_fx (plugs);
657         discover_music (plugs);
658
659         return plugs;
660 }
661
662 void
663 AUPluginInfo::discover_music (PluginInfoList& plugs)
664 {
665         CAComponentDescription desc;
666         desc.componentFlags = 0;
667         desc.componentFlagsMask = 0;
668         desc.componentSubType = 0;
669         desc.componentManufacturer = 0;
670         desc.componentType = kAudioUnitType_MusicEffect;
671
672         discover_by_description (plugs, desc);
673 }
674
675 void
676 AUPluginInfo::discover_fx (PluginInfoList& plugs)
677 {
678         CAComponentDescription desc;
679         desc.componentFlags = 0;
680         desc.componentFlagsMask = 0;
681         desc.componentSubType = 0;
682         desc.componentManufacturer = 0;
683         desc.componentType = kAudioUnitType_Effect;
684
685         discover_by_description (plugs, desc);
686 }
687
688 void
689 AUPluginInfo::discover_by_description (PluginInfoList& plugs, CAComponentDescription& desc)
690 {
691         Component comp = 0;
692
693         comp = FindNextComponent (NULL, &desc);
694
695         while (comp != NULL) {
696                 CAComponentDescription temp;
697                 GetComponentInfo (comp, &temp, NULL, NULL, NULL);
698
699                 AUPluginInfoPtr info (new AUPluginInfo 
700                                       (boost::shared_ptr<CAComponentDescription> (new CAComponentDescription(temp))));
701
702                 /* no panners, format converters or i/o AU's for our purposes
703                  */
704
705                 switch (info->descriptor->Type()) {
706                 case kAudioUnitType_Panner:
707                 case kAudioUnitType_OfflineEffect:
708                 case kAudioUnitType_FormatConverter:
709                         continue;
710                 default:
711                         break;
712                 }
713
714                 switch (info->descriptor->SubType()) {
715                 case kAudioUnitSubType_DefaultOutput:
716                 case kAudioUnitSubType_SystemOutput:
717                 case kAudioUnitSubType_GenericOutput:
718                 case kAudioUnitSubType_AUConverter:
719                         continue;
720                         break;
721
722                 case kAudioUnitSubType_DLSSynth:
723                         info->category = "DLSSynth";
724                         break;
725
726                 case kAudioUnitType_MusicEffect:
727                         info->category = "MusicEffect";
728                         break;
729
730                 case kAudioUnitSubType_Varispeed:
731                         info->category = "Varispeed";
732                         break;
733
734                 case kAudioUnitSubType_Delay:
735                         info->category = "Delay";
736                         break;
737
738                 case kAudioUnitSubType_LowPassFilter:
739                         info->category = "LowPassFilter";
740                         break;
741
742                 case kAudioUnitSubType_HighPassFilter:
743                         info->category = "HighPassFilter";
744                         break;
745
746                 case kAudioUnitSubType_BandPassFilter:
747                         info->category = "BandPassFilter";
748                         break;
749
750                 case kAudioUnitSubType_HighShelfFilter:
751                         info->category = "HighShelfFilter";
752                         break;
753
754                 case kAudioUnitSubType_LowShelfFilter:
755                         info->category = "LowShelfFilter";
756                         break;
757
758                 case kAudioUnitSubType_ParametricEQ:
759                         info->category = "ParametricEQ";
760                         break;
761
762                 case kAudioUnitSubType_GraphicEQ:
763                         info->category = "GraphicEQ";
764                         break;
765
766                 case kAudioUnitSubType_PeakLimiter:
767                         info->category = "PeakLimiter";
768                         break;
769
770                 case kAudioUnitSubType_DynamicsProcessor:
771                         info->category = "DynamicsProcessor";
772                         break;
773
774                 case kAudioUnitSubType_MultiBandCompressor:
775                         info->category = "MultiBandCompressor";
776                         break;
777
778                 case kAudioUnitSubType_MatrixReverb:
779                         info->category = "MatrixReverb";
780                         break;
781
782                 case kAudioUnitType_Mixer:
783                         info->category = "Mixer";
784                         break;
785
786                 case kAudioUnitSubType_StereoMixer:
787                         info->category = "StereoMixer";
788                         break;
789
790                 case kAudioUnitSubType_3DMixer:
791                         info->category = "3DMixer";
792                         break;
793
794                 case kAudioUnitSubType_MatrixMixer:
795                         info->category = "MatrixMixer";
796                         break;
797
798                 default:
799                         info->category = "";
800                 }
801
802                 AUPluginInfo::get_names (temp, info->name, info->creator);
803
804                 info->type = ARDOUR::AudioUnit;
805                 info->unique_id = stringify_descriptor (*info->descriptor);
806
807                 /* mark the plugin as having flexible i/o */
808                 
809                 info->n_inputs = -1;
810                 info->n_outputs = -1;
811
812
813                 plugs.push_back (info);
814                 
815                 comp = FindNextComponent (comp, &desc);
816         }
817 }
818
819 void
820 AUPluginInfo::get_names (CAComponentDescription& comp_desc, std::string& name, Glib::ustring& maker)
821 {
822         CFStringRef itemName = NULL;
823
824         // Marc Poirier-style item name
825         CAComponent auComponent (comp_desc);
826         if (auComponent.IsValid()) {
827                 CAComponentDescription dummydesc;
828                 Handle nameHandle = NewHandle(sizeof(void*));
829                 if (nameHandle != NULL) {
830                         OSErr err = GetComponentInfo(auComponent.Comp(), &dummydesc, nameHandle, NULL, NULL);
831                         if (err == noErr) {
832                                 ConstStr255Param nameString = (ConstStr255Param) (*nameHandle);
833                                 if (nameString != NULL) {
834                                         itemName = CFStringCreateWithPascalString(kCFAllocatorDefault, nameString, CFStringGetSystemEncoding());
835                                 }
836                         }
837                         DisposeHandle(nameHandle);
838                 }
839         }
840     
841         // if Marc-style fails, do the original way
842         if (itemName == NULL) {
843                 CFStringRef compTypeString = UTCreateStringForOSType(comp_desc.componentType);
844                 CFStringRef compSubTypeString = UTCreateStringForOSType(comp_desc.componentSubType);
845                 CFStringRef compManufacturerString = UTCreateStringForOSType(comp_desc.componentManufacturer);
846     
847                 itemName = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ - %@ - %@"), 
848                         compTypeString, compManufacturerString, compSubTypeString);
849     
850                 if (compTypeString != NULL)
851                         CFRelease(compTypeString);
852                 if (compSubTypeString != NULL)
853                         CFRelease(compSubTypeString);
854                 if (compManufacturerString != NULL)
855                         CFRelease(compManufacturerString);
856         }
857         
858         string str = CFStringRefToStdString(itemName);
859         string::size_type colon = str.find (':');
860
861         if (colon) {
862                 name = str.substr (colon+1);
863                 maker = str.substr (0, colon);
864                 // strip_whitespace_edges (maker);
865                 // strip_whitespace_edges (name);
866         } else {
867                 name = str;
868                 maker = "unknown";
869         }
870 }
871
872 // from CAComponentDescription.cpp (in libs/appleutility in ardour source)
873 extern char *StringForOSType (OSType t, char *writeLocation);
874
875 std::string
876 AUPluginInfo::stringify_descriptor (const CAComponentDescription& desc)
877 {
878         char str[24];
879         stringstream s;
880
881         s << StringForOSType (desc.Type(), str);
882         s << " - ";
883                 
884         s << StringForOSType (desc.SubType(), str);
885         s << " - ";
886                 
887         s << StringForOSType (desc.Manu(), str);
888
889         return s.str();
890 }