ardour
audio_unit.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006-2009 Paul Davis
3  Some portions Copyright (C) Sophia Poirier.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 
19 */
20 
21 #include <sstream>
22 #include <fstream>
23 #include <errno.h>
24 #include <string.h>
25 #include <math.h>
26 #include <ctype.h>
27 
28 #include "pbd/transmitter.h"
29 #include "pbd/xml++.h"
30 #include "pbd/convert.h"
31 #include "pbd/whitespace.h"
32 #include "pbd/file_utils.h"
33 #include "pbd/locale_guard.h"
34 
35 #include <glibmm/threads.h>
36 #include <glibmm/fileutils.h>
37 #include <glibmm/miscutils.h>
38 #include <glib/gstdio.h>
39 
40 #include "ardour/ardour.h"
41 #include "ardour/audioengine.h"
42 #include "ardour/audio_buffer.h"
43 #include "ardour/debug.h"
44 #include "ardour/midi_buffer.h"
46 #include "ardour/io.h"
47 #include "ardour/audio_unit.h"
48 #include "ardour/route.h"
49 #include "ardour/session.h"
50 #include "ardour/tempo.h"
51 #include "ardour/utils.h"
52 
53 #include "appleutility/CAAudioUnit.h"
54 #include "appleutility/CAAUParameter.h"
55 
56 #include <CoreFoundation/CoreFoundation.h>
57 #include <CoreServices/CoreServices.h>
58 #include <AudioUnit/AudioUnit.h>
59 #include <AudioToolbox/AudioUnitUtilities.h>
60 #ifdef WITH_CARBON
61 #include <Carbon/Carbon.h>
62 #endif
63 
64 #include "i18n.h"
65 
66 using namespace std;
67 using namespace PBD;
68 using namespace ARDOUR;
69 
70 AUPluginInfo::CachedInfoMap AUPluginInfo::cached_info;
71 
72 static string preset_search_path = "/Library/Audio/Presets:/Network/Library/Audio/Presets";
73 static string preset_suffix = ".aupreset";
74 static bool preset_search_path_initialized = false;
75 FILE * AUPluginInfo::_crashlog_fd = NULL;
76 
77 
78 static void au_blacklist (std::string id)
79 {
80  string fn = Glib::build_filename (ARDOUR::user_cache_directory(), "au_blacklist.txt");
81  FILE * blacklist_fd = NULL;
82  if (! (blacklist_fd = fopen(fn.c_str(), "a"))) {
83  PBD::error << "Cannot append to AU blacklist for '"<< id <<"'\n";
84  return;
85  }
86  assert(id.find("\n") == string::npos);
87  fprintf(blacklist_fd, "%s\n", id.c_str());
88  ::fclose(blacklist_fd);
89 }
90 
91 static void au_unblacklist (std::string id)
92 {
93  string fn = Glib::build_filename (ARDOUR::user_cache_directory(), "au_blacklist.txt");
94  if (!Glib::file_test (fn, Glib::FILE_TEST_EXISTS)) {
95  PBD::warning << "Expected Blacklist file does not exist.\n";
96  return;
97  }
98 
99  std::string bl;
100  std::ifstream ifs(fn.c_str());
101  bl.assign ((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
102  ::g_unlink(fn.c_str());
103 
104  assert(id.find("\n") == string::npos);
105 
106  id += "\n"; // add separator
107  const size_t rpl = bl.find(id);
108  if (rpl != string::npos) {
109  bl.replace(rpl, id.size(), "");
110  }
111  if (bl.empty()) {
112  return;
113  }
114 
115  FILE * blacklist_fd = NULL;
116  if (! (blacklist_fd = fopen(fn.c_str(), "w"))) {
117  PBD::error << "Cannot open AU blacklist.\n";
118  return;
119  }
120  fprintf(blacklist_fd, "%s", bl.c_str());
121  ::fclose(blacklist_fd);
122 }
123 
124 static bool is_blacklisted (std::string id)
125 {
126  string fn = Glib::build_filename (ARDOUR::user_cache_directory(), "au_blacklist.txt");
127  if (!Glib::file_test (fn, Glib::FILE_TEST_EXISTS)) {
128  return false;
129  }
130  std::string bl;
131  std::ifstream ifs(fn.c_str());
132  bl.assign ((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
133 
134  assert(id.find("\n") == string::npos);
135 
136  id += "\n"; // add separator
137  const size_t rpl = bl.find(id);
138  if (rpl != string::npos) {
139  return true;
140  }
141  return false;
142 }
143 
144 
145 
146 static OSStatus
147 _render_callback(void *userData,
148  AudioUnitRenderActionFlags *ioActionFlags,
149  const AudioTimeStamp *inTimeStamp,
150  UInt32 inBusNumber,
151  UInt32 inNumberFrames,
152  AudioBufferList* ioData)
153 {
154  if (userData) {
155  return ((AUPlugin*)userData)->render_callback (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
156  }
157  return paramErr;
158 }
159 
160 static OSStatus
162  Float64* outCurrentBeat,
163  Float64* outCurrentTempo)
164 {
165  if (userData) {
166  return ((AUPlugin*)userData)->get_beat_and_tempo_callback (outCurrentBeat, outCurrentTempo);
167  }
168 
169  return paramErr;
170 }
171 
172 static OSStatus
174  UInt32 * outDeltaSampleOffsetToNextBeat,
175  Float32 * outTimeSig_Numerator,
176  UInt32 * outTimeSig_Denominator,
177  Float64 * outCurrentMeasureDownBeat)
178 {
179  if (userData) {
180  return ((AUPlugin*)userData)->get_musical_time_location_callback (outDeltaSampleOffsetToNextBeat,
181  outTimeSig_Numerator,
182  outTimeSig_Denominator,
183  outCurrentMeasureDownBeat);
184  }
185  return paramErr;
186 }
187 
188 static OSStatus
190  Boolean* outIsPlaying,
191  Boolean* outTransportStateChanged,
192  Float64* outCurrentSampleInTimeLine,
193  Boolean* outIsCycling,
194  Float64* outCycleStartBeat,
195  Float64* outCycleEndBeat)
196 {
197  if (userData) {
198  return ((AUPlugin*)userData)->get_transport_state_callback (
199  outIsPlaying, outTransportStateChanged,
200  outCurrentSampleInTimeLine, outIsCycling,
201  outCycleStartBeat, outCycleEndBeat);
202  }
203  return paramErr;
204 }
205 
206 
207 static int
208 save_property_list (CFPropertyListRef propertyList, Glib::ustring path)
209 
210 {
211  CFDataRef xmlData;
212  int fd;
213 
214  // Convert the property list into XML data.
215 
216  xmlData = CFPropertyListCreateXMLData( kCFAllocatorDefault, propertyList);
217 
218  if (!xmlData) {
219  error << _("Could not create XML version of property list") << endmsg;
220  return -1;
221  }
222 
223  // Write the XML data to the file.
224 
225  fd = open (path.c_str(), O_WRONLY|O_CREAT|O_EXCL, 0664);
226  while (fd < 0) {
227  if (errno == EEXIST) {
228  error << string_compose (_("Preset file %1 exists; not overwriting"),
229  path) << endmsg;
230  } else {
231  error << string_compose (_("Cannot open preset file %1 (%2)"),
232  path, strerror (errno)) << endmsg;
233  }
234  CFRelease (xmlData);
235  return -1;
236  }
237 
238  size_t cnt = CFDataGetLength (xmlData);
239 
240  if (write (fd, CFDataGetBytePtr (xmlData), cnt) != (ssize_t) cnt) {
241  CFRelease (xmlData);
242  close (fd);
243  return -1;
244  }
245 
246  close (fd);
247  return 0;
248 }
249 
250 
251 static CFPropertyListRef
252 load_property_list (Glib::ustring path)
253 {
254  int fd;
255  CFPropertyListRef propertyList = 0;
256  CFDataRef xmlData;
257  CFStringRef errorString;
258 
259  // Read the XML file.
260 
261  if ((fd = open (path.c_str(), O_RDONLY)) < 0) {
262  return propertyList;
263 
264  }
265 
266  off_t len = lseek (fd, 0, SEEK_END);
267  char* buf = new char[len];
268  lseek (fd, 0, SEEK_SET);
269 
270  if (read (fd, buf, len) != len) {
271  delete [] buf;
272  close (fd);
273  return propertyList;
274  }
275 
276  close (fd);
277 
278  xmlData = CFDataCreateWithBytesNoCopy (kCFAllocatorDefault, (UInt8*) buf, len, kCFAllocatorNull);
279 
280  // Reconstitute the dictionary using the XML data.
281 
282  propertyList = CFPropertyListCreateFromXMLData( kCFAllocatorDefault,
283  xmlData,
284  kCFPropertyListImmutable,
285  &errorString);
286 
287  CFRelease (xmlData);
288  delete [] buf;
289 
290  return propertyList;
291 }
292 
293 //-----------------------------------------------------------------------------
294 static void
295 set_preset_name_in_plist (CFPropertyListRef plist, string preset_name)
296 {
297  if (!plist) {
298  return;
299  }
300  CFStringRef pn = CFStringCreateWithCString (kCFAllocatorDefault, preset_name.c_str(), kCFStringEncodingUTF8);
301 
302  if (CFGetTypeID (plist) == CFDictionaryGetTypeID()) {
303  CFDictionarySetValue ((CFMutableDictionaryRef)plist, CFSTR(kAUPresetNameKey), pn);
304  }
305 
306  CFRelease (pn);
307 }
308 
309 //-----------------------------------------------------------------------------
310 static std::string
311 get_preset_name_in_plist (CFPropertyListRef plist)
312 {
313  std::string ret;
314 
315  if (!plist) {
316  return ret;
317  }
318 
319  if (CFGetTypeID (plist) == CFDictionaryGetTypeID()) {
320  const void *p = CFDictionaryGetValue ((CFMutableDictionaryRef)plist, CFSTR(kAUPresetNameKey));
321  if (p) {
322  CFStringRef str = (CFStringRef) p;
323  int len = CFStringGetLength(str);
324  len = (len * 2) + 1;
325  char local_buffer[len];
326  if (CFStringGetCString (str, local_buffer, len, kCFStringEncodingUTF8)) {
327  ret = local_buffer;
328  }
329  }
330  }
331  return ret;
332 }
333 
334 //--------------------------------------------------------------------------
335 // general implementation for ComponentDescriptionsMatch() and ComponentDescriptionsMatch_Loosely()
336 // if inIgnoreType is true, then the type code is ignored in the ComponentDescriptions
337 Boolean ComponentDescriptionsMatch_General(const ComponentDescription * inComponentDescription1, const ComponentDescription * inComponentDescription2, Boolean inIgnoreType);
338 Boolean ComponentDescriptionsMatch_General(const ComponentDescription * inComponentDescription1, const ComponentDescription * inComponentDescription2, Boolean inIgnoreType)
339 {
340  if ( (inComponentDescription1 == NULL) || (inComponentDescription2 == NULL) )
341  return FALSE;
342 
343  if ( (inComponentDescription1->componentSubType == inComponentDescription2->componentSubType)
344  && (inComponentDescription1->componentManufacturer == inComponentDescription2->componentManufacturer) )
345  {
346  // only sub-type and manufacturer IDs need to be equal
347  if (inIgnoreType)
348  return TRUE;
349  // type, sub-type, and manufacturer IDs all need to be equal in order to call this a match
350  else if (inComponentDescription1->componentType == inComponentDescription2->componentType)
351  return TRUE;
352  }
353 
354  return FALSE;
355 }
356 
357 //--------------------------------------------------------------------------
358 // general implementation for ComponentAndDescriptionMatch() and ComponentAndDescriptionMatch_Loosely()
359 // if inIgnoreType is true, then the type code is ignored in the ComponentDescriptions
360 Boolean ComponentAndDescriptionMatch_General(Component inComponent, const ComponentDescription * inComponentDescription, Boolean inIgnoreType);
361 Boolean ComponentAndDescriptionMatch_General(Component inComponent, const ComponentDescription * inComponentDescription, Boolean inIgnoreType)
362 {
363  OSErr status;
364  ComponentDescription desc;
365 
366  if ( (inComponent == NULL) || (inComponentDescription == NULL) )
367  return FALSE;
368 
369  // get the ComponentDescription of the input Component
370  status = GetComponentInfo(inComponent, &desc, NULL, NULL, NULL);
371  if (status != noErr)
372  return FALSE;
373 
374  // check if the Component's ComponentDescription matches the input ComponentDescription
375  return ComponentDescriptionsMatch_General(&desc, inComponentDescription, inIgnoreType);
376 }
377 
378 //--------------------------------------------------------------------------
379 // determine if 2 ComponentDescriptions are basically equal
380 // (by that, I mean that the important identifying values are compared,
381 // but not the ComponentDescription flags)
382 Boolean ComponentDescriptionsMatch(const ComponentDescription * inComponentDescription1, const ComponentDescription * inComponentDescription2)
383 {
384  return ComponentDescriptionsMatch_General(inComponentDescription1, inComponentDescription2, FALSE);
385 }
386 
387 //--------------------------------------------------------------------------
388 // determine if 2 ComponentDescriptions have matching sub-type and manufacturer codes
389 Boolean ComponentDescriptionsMatch_Loose(const ComponentDescription * inComponentDescription1, const ComponentDescription * inComponentDescription2)
390 {
391  return ComponentDescriptionsMatch_General(inComponentDescription1, inComponentDescription2, TRUE);
392 }
393 
394 //--------------------------------------------------------------------------
395 // determine if a ComponentDescription basically matches that of a particular Component
396 Boolean ComponentAndDescriptionMatch(Component inComponent, const ComponentDescription * inComponentDescription)
397 {
398  return ComponentAndDescriptionMatch_General(inComponent, inComponentDescription, FALSE);
399 }
400 
401 //--------------------------------------------------------------------------
402 // determine if a ComponentDescription matches only the sub-type and manufacturer codes of a particular Component
403 Boolean ComponentAndDescriptionMatch_Loosely(Component inComponent, const ComponentDescription * inComponentDescription)
404 {
405  return ComponentAndDescriptionMatch_General(inComponent, inComponentDescription, TRUE);
406 }
407 
408 
409 AUPlugin::AUPlugin (AudioEngine& engine, Session& session, boost::shared_ptr<CAComponent> _comp)
410  : Plugin (engine, session)
411  , comp (_comp)
412  , unit (new CAAudioUnit)
413  , initialized (false)
414  , _current_block_size (0)
415  , _requires_fixed_size_buffers (false)
416  , buffers (0)
417  , input_maxbuf (0)
418  , input_offset (0)
419  , input_buffers (0)
420  , frames_processed (0)
421  , _parameter_listener (0)
422  , _parameter_listener_arg (0)
423  , last_transport_rolling (false)
424  , last_transport_speed (0.0)
425 {
427  Glib::ustring p = Glib::get_home_dir();
428  p += "/Library/Audio/Presets:";
429  p += preset_search_path;
430  preset_search_path = p;
433  }
434 
435  init ();
436 }
437 
438 
440  : Plugin (other)
441  , comp (other.get_comp())
442  , unit (new CAAudioUnit)
443  , initialized (false)
444  , _current_block_size (0)
445  , _last_nframes (0)
446  , _requires_fixed_size_buffers (false)
447  , buffers (0)
448  , input_maxbuf (0)
449  , input_offset (0)
450  , input_buffers (0)
451  , frames_processed (0)
452  , _parameter_listener (0)
453  , _parameter_listener_arg (0)
454 
455 {
456  init ();
457 }
458 
460 {
461  if (_parameter_listener) {
462  AUListenerDispose (_parameter_listener);
464  }
465 
466  if (unit) {
467  DEBUG_TRACE (DEBUG::AudioUnits, "about to call uninitialize in plugin destructor\n");
468  unit->Uninitialize ();
469  }
470 
471  if (buffers) {
472  free (buffers);
473  }
474 }
475 
476 void
478 {
479  CFArrayRef presets;
480  UInt32 dataSize;
481  Boolean isWritable;
482  OSStatus err;
483 
484  if ((err = unit->GetPropertyInfo (kAudioUnitProperty_FactoryPresets, kAudioUnitScope_Global, 0, &dataSize, &isWritable)) != 0) {
485  DEBUG_TRACE (DEBUG::AudioUnits, "no factory presets for AU\n");
486  return;
487  }
488 
489  assert (dataSize == sizeof (presets));
490 
491  if ((err = unit->GetProperty (kAudioUnitProperty_FactoryPresets, kAudioUnitScope_Global, 0, (void*) &presets, &dataSize)) != 0) {
492  error << string_compose (_("cannot get factory preset info: errcode %1"), err) << endmsg;
493  return;
494  }
495 
496  if (!presets) {
497  return;
498  }
499 
500  CFIndex cnt = CFArrayGetCount (presets);
501 
502  for (CFIndex i = 0; i < cnt; ++i) {
503  AUPreset* preset = (AUPreset*) CFArrayGetValueAtIndex (presets, i);
504 
505  string name = CFStringRefToStdString (preset->presetName);
506  factory_preset_map[name] = preset->presetNumber;
507  DEBUG_TRACE (DEBUG::AudioUnits, string_compose("AU Factory Preset: %1 > %2\n", name, preset->presetNumber));
508  }
509 
510  CFRelease (presets);
511 }
512 
513 void
515 {
516  OSErr err;
517  CFStringRef itemName;
518 
519  /* these keep track of *configured* channel set up,
520  not potential set ups.
521  */
522 
523  input_channels = -1;
524  output_channels = -1;
525  {
526  CAComponentDescription temp;
527  GetComponentInfo (comp.get()->Comp(), &temp, NULL, NULL, NULL);
528  CFStringRef compTypeString = UTCreateStringForOSType(temp.componentType);
529  CFStringRef compSubTypeString = UTCreateStringForOSType(temp.componentSubType);
530  CFStringRef compManufacturerString = UTCreateStringForOSType(temp.componentManufacturer);
531  itemName = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ - %@ - %@"),
532  compTypeString, compManufacturerString, compSubTypeString);
533  if (compTypeString != NULL) CFRelease(compTypeString);
534  if (compSubTypeString != NULL) CFRelease(compSubTypeString);
535  if (compManufacturerString != NULL) CFRelease(compManufacturerString);
536  }
537 
538  au_blacklist(CFStringRefToStdString(itemName));
539 
540  try {
541  DEBUG_TRACE (DEBUG::AudioUnits, "opening AudioUnit\n");
542  err = CAAudioUnit::Open (*(comp.get()), *unit);
543  } catch (...) {
544  error << _("Exception thrown during AudioUnit plugin loading - plugin ignored") << endmsg;
545  throw failed_constructor();
546  }
547 
548  if (err != noErr) {
549  error << _("AudioUnit: Could not convert CAComponent to CAAudioUnit") << endmsg;
550  throw failed_constructor ();
551  }
552 
553  DEBUG_TRACE (DEBUG::AudioUnits, "count global elements\n");
554  unit->GetElementCount (kAudioUnitScope_Global, global_elements);
555  DEBUG_TRACE (DEBUG::AudioUnits, "count input elements\n");
556  unit->GetElementCount (kAudioUnitScope_Input, input_elements);
557  DEBUG_TRACE (DEBUG::AudioUnits, "count output elements\n");
558  unit->GetElementCount (kAudioUnitScope_Output, output_elements);
559 
560  if (input_elements > 0) {
561  /* setup render callback: the plugin calls this to get input data
562  */
563 
564  AURenderCallbackStruct renderCallbackInfo;
565 
566  renderCallbackInfo.inputProc = _render_callback;
567  renderCallbackInfo.inputProcRefCon = this;
568 
569  DEBUG_TRACE (DEBUG::AudioUnits, "set render callback in input scope\n");
570  if ((err = unit->SetProperty (kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
571  0, (void*) &renderCallbackInfo, sizeof(renderCallbackInfo))) != 0) {
572  error << string_compose (_("cannot install render callback (err = %1)"), err) << endmsg;
573  throw failed_constructor();
574  }
575  }
576 
577  /* tell the plugin about tempo/meter/transport callbacks in case it wants them */
578 
579  HostCallbackInfo info;
580  memset (&info, 0, sizeof (HostCallbackInfo));
581  info.hostUserData = this;
582  info.beatAndTempoProc = _get_beat_and_tempo_callback;
583  info.musicalTimeLocationProc = _get_musical_time_location_callback;
584  info.transportStateProc = _get_transport_state_callback;
585 
586  //ignore result of this - don't care if the property isn't supported
587  DEBUG_TRACE (DEBUG::AudioUnits, "set host callbacks in global scope\n");
588  unit->SetProperty (kAudioUnitProperty_HostCallbacks,
589  kAudioUnitScope_Global,
590  0, //elementID
591  &info,
592  sizeof (HostCallbackInfo));
593 
595  error << _("AUPlugin: cannot set processing block size") << endmsg;
596  throw failed_constructor();
597  }
598 
602 
603  // Plugin::setup_controls ();
604 
605  au_unblacklist(CFStringRefToStdString(itemName));
606  if (itemName != NULL) CFRelease(itemName);
607 }
608 
609 void
611 {
612  /* discover writable parameters */
613 
614  AudioUnitScope scopes[] = {
615  kAudioUnitScope_Global,
616  kAudioUnitScope_Output,
617  kAudioUnitScope_Input
618  };
619 
620  descriptors.clear ();
621 
622  for (uint32_t i = 0; i < sizeof (scopes) / sizeof (scopes[0]); ++i) {
623 
624  AUParamInfo param_info (unit->AU(), false, /* include read only */ true, scopes[i]);
625 
626  for (uint32_t i = 0; i < param_info.NumParams(); ++i) {
627 
629 
630  d.id = param_info.ParamID (i);
631 
632  const CAAUParameter* param = param_info.GetParamInfo (d.id);
633  const AudioUnitParameterInfo& info (param->ParamInfo());
634 
635  const int len = CFStringGetLength (param->GetName());;
636  char local_buffer[len*2];
637  Boolean good = CFStringGetCString(param->GetName(),local_buffer,len*2,kCFStringEncodingMacRoman);
638  if (!good) {
639  d.label = "???";
640  } else {
641  d.label = local_buffer;
642  }
643 
644  d.scope = param_info.GetScope ();
645  d.element = param_info.GetElement ();
646 
647  /* info.units to consider */
648  /*
649  kAudioUnitParameterUnit_Generic = 0
650  kAudioUnitParameterUnit_Indexed = 1
651  kAudioUnitParameterUnit_Boolean = 2
652  kAudioUnitParameterUnit_Percent = 3
653  kAudioUnitParameterUnit_Seconds = 4
654  kAudioUnitParameterUnit_SampleFrames = 5
655  kAudioUnitParameterUnit_Phase = 6
656  kAudioUnitParameterUnit_Rate = 7
657  kAudioUnitParameterUnit_Hertz = 8
658  kAudioUnitParameterUnit_Cents = 9
659  kAudioUnitParameterUnit_RelativeSemiTones = 10
660  kAudioUnitParameterUnit_MIDINoteNumber = 11
661  kAudioUnitParameterUnit_MIDIController = 12
662  kAudioUnitParameterUnit_Decibels = 13
663  kAudioUnitParameterUnit_LinearGain = 14
664  kAudioUnitParameterUnit_Degrees = 15
665  kAudioUnitParameterUnit_EqualPowerCrossfade = 16
666  kAudioUnitParameterUnit_MixerFaderCurve1 = 17
667  kAudioUnitParameterUnit_Pan = 18
668  kAudioUnitParameterUnit_Meters = 19
669  kAudioUnitParameterUnit_AbsoluteCents = 20
670  kAudioUnitParameterUnit_Octaves = 21
671  kAudioUnitParameterUnit_BPM = 22
672  kAudioUnitParameterUnit_Beats = 23
673  kAudioUnitParameterUnit_Milliseconds = 24
674  kAudioUnitParameterUnit_Ratio = 25
675  */
676 
677  /* info.flags to consider */
678 
679  /*
680 
681  kAudioUnitParameterFlag_CFNameRelease = (1L << 4)
682  kAudioUnitParameterFlag_HasClump = (1L << 20)
683  kAudioUnitParameterFlag_HasName = (1L << 21)
684  kAudioUnitParameterFlag_DisplayLogarithmic = (1L << 22)
685  kAudioUnitParameterFlag_IsHighResolution = (1L << 23)
686  kAudioUnitParameterFlag_NonRealTime = (1L << 24)
687  kAudioUnitParameterFlag_CanRamp = (1L << 25)
688  kAudioUnitParameterFlag_ExpertMode = (1L << 26)
689  kAudioUnitParameterFlag_HasCFNameString = (1L << 27)
690  kAudioUnitParameterFlag_IsGlobalMeta = (1L << 28)
691  kAudioUnitParameterFlag_IsElementMeta = (1L << 29)
692  kAudioUnitParameterFlag_IsReadable = (1L << 30)
693  kAudioUnitParameterFlag_IsWritable = (1L << 31)
694  */
695 
696  d.lower = info.minValue;
697  d.upper = info.maxValue;
698  d.normal = info.defaultValue;
699 
700  d.integer_step = (info.unit == kAudioUnitParameterUnit_Indexed);
701  d.toggled = (info.unit == kAudioUnitParameterUnit_Boolean) ||
702  (d.integer_step && ((d.upper - d.lower) == 1.0));
703  d.sr_dependent = (info.unit == kAudioUnitParameterUnit_SampleFrames);
704  d.automatable = /* !d.toggled && -- ardour can automate toggles, can AU ? */
705  !(info.flags & kAudioUnitParameterFlag_NonRealTime) &&
706  (info.flags & kAudioUnitParameterFlag_IsWritable);
707 
708  d.logarithmic = (info.flags & kAudioUnitParameterFlag_DisplayLogarithmic);
709  d.au_unit = info.unit;
710  switch (info.unit) {
711  case kAudioUnitParameterUnit_Decibels:
713  break;
714  case kAudioUnitParameterUnit_MIDINoteNumber:
716  break;
717  case kAudioUnitParameterUnit_Hertz:
719  break;
720  }
721 
722  d.min_unbound = 0; // lower is bound
723  d.max_unbound = 0; // upper is bound
724  d.update_steps();
725 
726  descriptors.push_back (d);
727 
728  uint32_t last_param = descriptors.size() - 1;
729  parameter_map.insert (pair<uint32_t,uint32_t> (d.id, last_param));
730  listen_to_parameter (last_param);
731  }
732  }
733 }
734 
735 
736 static unsigned int
737 four_ints_to_four_byte_literal (unsigned char n[4])
738 {
739  /* this is actually implementation dependent. sigh. this is what gcc
740  and quite a few others do.
741  */
742  return ((n[0] << 24) + (n[1] << 16) + (n[2] << 8) + n[3]);
743 }
744 
745 std::string
746 AUPlugin::maybe_fix_broken_au_id (const std::string& id)
747 {
748  if (isdigit (id[0])) {
749  return id;
750  }
751 
752  /* ID format is xxxx-xxxx-xxxx
753  where x maybe \xNN or a printable character.
754 
755  Split at the '-' and and process each part into an integer.
756  Then put it back together.
757  */
758 
759 
760  unsigned char nascent[4];
761  const char* cstr = id.c_str();
762  const char* estr = cstr + id.size();
763  uint32_t n[3];
764  int in;
765  int next_int;
766  char short_buf[3];
767  stringstream s;
768 
769  in = 0;
770  next_int = 0;
771  short_buf[2] = '\0';
772 
773  while (*cstr && next_int < 4) {
774 
775  if (*cstr == '\\') {
776 
777  if (estr - cstr < 3) {
778 
779  /* too close to the end for \xNN parsing: treat as literal characters */
780 
781  nascent[in] = *cstr;
782  ++cstr;
783  ++in;
784 
785  } else {
786 
787  if (cstr[1] == 'x' && isxdigit (cstr[2]) && isxdigit (cstr[3])) {
788 
789  /* parse \xNN */
790 
791  memcpy (short_buf, &cstr[2], 2);
792  nascent[in] = strtol (short_buf, NULL, 16);
793  cstr += 4;
794  ++in;
795 
796  } else {
797 
798  /* treat as literal characters */
799  nascent[in] = *cstr;
800  ++cstr;
801  ++in;
802  }
803  }
804 
805  } else {
806 
807  nascent[in] = *cstr;
808  ++cstr;
809  ++in;
810  }
811 
812  if (in && (in % 4 == 0)) {
813  /* nascent is ready */
814  n[next_int] = four_ints_to_four_byte_literal (nascent);
815  in = 0;
816  next_int++;
817 
818  /* swallow space-hyphen-space */
819 
820  if (next_int < 3) {
821  ++cstr;
822  ++cstr;
823  ++cstr;
824  }
825  }
826  }
827 
828  if (next_int != 3) {
829  goto err;
830  }
831 
832  s << n[0] << '-' << n[1] << '-' << n[2];
833 
834  return s.str();
835 
836  err:
837  return string();
838 }
839 
840 string
842 {
843  return AUPluginInfo::stringify_descriptor (comp->Desc());
844 }
845 
846 const char *
848 {
849  return _info->name.c_str();
850 }
851 
852 uint32_t
854 {
855  return descriptors.size();
856 }
857 
858 float
859 AUPlugin::default_value (uint32_t port)
860 {
861  if (port < descriptors.size()) {
862  return descriptors[port].normal;
863  }
864 
865  return 0;
866 }
867 
870 {
871  return unit->Latency() * _session.frame_rate();
872 }
873 
874 void
875 AUPlugin::set_parameter (uint32_t which, float val)
876 {
877  if (which >= descriptors.size()) {
878  return;
879  }
880 
881  if (get_parameter(which) == val) {
882  return;
883  }
884 
885  const AUParameterDescriptor& d (descriptors[which]);
886  DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("set parameter %1 in scope %2 element %3 to %4\n", d.id, d.scope, d.element, val));
887  unit->SetParameter (d.id, d.scope, d.element, val);
888 
889  /* tell the world what we did */
890 
891  AudioUnitEvent theEvent;
892 
893  theEvent.mEventType = kAudioUnitEvent_ParameterValueChange;
894  theEvent.mArgument.mParameter.mAudioUnit = unit->AU();
895  theEvent.mArgument.mParameter.mParameterID = d.id;
896  theEvent.mArgument.mParameter.mScope = d.scope;
897  theEvent.mArgument.mParameter.mElement = d.element;
898 
899  DEBUG_TRACE (DEBUG::AudioUnits, "notify about parameter change\n");
900  AUEventListenerNotify (NULL, NULL, &theEvent);
901 
902  Plugin::set_parameter (which, val);
903 }
904 
905 float
906 AUPlugin::get_parameter (uint32_t which) const
907 {
908  float val = 0.0;
909  if (which < descriptors.size()) {
910  const AUParameterDescriptor& d (descriptors[which]);
911  // DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("get value of parameter %1 in scope %2 element %3\n", d.id, d.scope, d.element));
912  unit->GetParameter(d.id, d.scope, d.element, val);
913  }
914  return val;
915 }
916 
917 int
919 {
920  if (which < descriptors.size()) {
921  pd = descriptors[which];
922  return 0;
923  }
924  return -1;
925 }
926 
927 uint32_t
928 AUPlugin::nth_parameter (uint32_t which, bool& ok) const
929 {
930  if (which < descriptors.size()) {
931  ok = true;
932  return which;
933  }
934  ok = false;
935  return 0;
936 }
937 
938 void
940 {
941  if (!initialized) {
942  OSErr err;
943  DEBUG_TRACE (DEBUG::AudioUnits, "call Initialize in activate()\n");
944  if ((err = unit->Initialize()) != noErr) {
945  error << string_compose (_("AUPlugin: %1 cannot initialize plugin (err = %2)"), name(), err) << endmsg;
946  } else {
947  frames_processed = 0;
948  initialized = true;
949  }
950  }
951 }
952 
953 void
955 {
956  DEBUG_TRACE (DEBUG::AudioUnits, "call Uninitialize in deactivate()\n");
957  unit->Uninitialize ();
958  initialized = false;
959 }
960 
961 void
963 {
964  DEBUG_TRACE (DEBUG::AudioUnits, "call Reset in flush()\n");
965  unit->GlobalReset ();
966 }
967 
968 bool
970 {
972 }
973 
974 
975 int
977 {
978  bool was_initialized = initialized;
979  UInt32 numFrames = nframes;
980  OSErr err;
981 
982  if (initialized) {
983  deactivate ();
984  }
985 
986  DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("set MaximumFramesPerSlice in global scope to %1\n", numFrames));
987  if ((err = unit->SetProperty (kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global,
988  0, &numFrames, sizeof (numFrames))) != noErr) {
989  error << string_compose (_("AU: cannot set max frames (err = %1)"), err) << endmsg;
990  return -1;
991  }
992 
993  if (was_initialized) {
994  activate ();
995  }
996 
997  _current_block_size = nframes;
998 
999  return 0;
1000 }
1001 
1002 bool
1004 {
1005  AudioStreamBasicDescription streamFormat;
1006  bool was_initialized = initialized;
1007  int32_t audio_in = in.n_audio();
1008  int32_t audio_out = out.n_audio();
1009 
1010  DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("configure %1 for %2 in %3 out\n", name(), in, out));
1011 
1012  if (initialized) {
1013  //if we are already running with the requested i/o config, bail out here
1014  if ( (audio_in==input_channels) && (audio_out==output_channels) ) {
1015  return 0;
1016  } else {
1017  deactivate ();
1018  }
1019  }
1020 
1021  streamFormat.mSampleRate = _session.frame_rate();
1022  streamFormat.mFormatID = kAudioFormatLinearPCM;
1023  streamFormat.mFormatFlags = kAudioFormatFlagIsFloat|kAudioFormatFlagIsPacked|kAudioFormatFlagIsNonInterleaved;
1024 
1025 #ifdef __LITTLE_ENDIAN__
1026  /* relax */
1027 #else
1028  streamFormat.mFormatFlags |= kAudioFormatFlagIsBigEndian;
1029 #endif
1030 
1031  streamFormat.mBitsPerChannel = 32;
1032  streamFormat.mFramesPerPacket = 1;
1033 
1034  /* apple says that for non-interleaved data, these
1035  values always refer to a single channel.
1036  */
1037  streamFormat.mBytesPerPacket = 4;
1038  streamFormat.mBytesPerFrame = 4;
1039 
1040  streamFormat.mChannelsPerFrame = audio_in;
1041 
1042  if (set_input_format (streamFormat) != 0) {
1043  return -1;
1044  }
1045 
1046  streamFormat.mChannelsPerFrame = audio_out;
1047 
1048  if (set_output_format (streamFormat) != 0) {
1049  return -1;
1050  }
1051 
1052  /* reset plugin info to show currently configured state */
1053 
1054  _info->n_inputs = in;
1055  _info->n_outputs = out;
1056 
1057  if (was_initialized) {
1058  activate ();
1059  }
1060 
1061  return 0;
1062 }
1063 
1064 ChanCount
1066 {
1067  ChanCount c;
1068 
1069 
1070  if (input_channels < 0) {
1071  // force PluginIoReConfigure -- see also commit msg e38eb06
1072  c.set (DataType::AUDIO, 0);
1073  c.set (DataType::MIDI, 0);
1074  } else {
1076  c.set (DataType::MIDI, _has_midi_input ? 1 : 0);
1077  }
1078 
1079  return c;
1080 }
1081 
1082 
1083 ChanCount
1085 {
1086  ChanCount c;
1087 
1088  if (output_channels < 0) {
1089  // force PluginIoReConfigure - see also commit msg e38eb06
1090  c.set (DataType::AUDIO, 0);
1091  c.set (DataType::MIDI, 0);
1092  } else {
1094  c.set (DataType::MIDI, _has_midi_output ? 1 : 0);
1095  }
1096 
1097  return c;
1098 }
1099 
1100 bool
1102 {
1103  // Note: We never attempt to multiply-instantiate plugins to meet io configurations.
1104 
1105  int32_t audio_in = in.n_audio();
1106  int32_t audio_out;
1107  bool found = false;
1109 
1110  /* lets check MIDI first */
1111 
1112  if (in.n_midi() > 0) {
1113  if (!_has_midi_input) {
1114  return false;
1115  }
1116  }
1117 
1118  vector<pair<int,int> >& io_configs = pinfo->cache.io_configs;
1119 
1120  DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("%1 has %2 IO configurations, looking for %3 in, %4 out\n",
1121  name(), io_configs.size(), in, out));
1122 
1123  //Ardour expects the plugin to tell it the output
1124  //configuration but AU plugins can have multiple I/O
1125  //configurations in most cases. so first lets see
1126  //if there's a configuration that keeps out==in
1127 
1128  if (in.n_midi() > 0 && audio_in == 0) {
1129  audio_out = 2; // prefer stereo version if available.
1130  } else {
1131  audio_out = audio_in;
1132  }
1133 
1134  for (vector<pair<int,int> >::iterator i = io_configs.begin(); i != io_configs.end(); ++i) {
1135 
1136  int32_t possible_in = i->first;
1137  int32_t possible_out = i->second;
1138 
1139  if ((possible_in == audio_in) && (possible_out == audio_out)) {
1140  DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("\tCHOSEN: %1 in %2 out to match in %3 out %4\n",
1141  possible_in, possible_out,
1142  in, out));
1143 
1144  out.set (DataType::MIDI, 0);
1145  out.set (DataType::AUDIO, audio_out);
1146 
1147  return 1;
1148  }
1149  }
1150 
1151  /* now allow potentially "imprecise" matches */
1152 
1153  audio_out = -1;
1154 
1155  for (vector<pair<int,int> >::iterator i = io_configs.begin(); i != io_configs.end(); ++i) {
1156 
1157  int32_t possible_in = i->first;
1158  int32_t possible_out = i->second;
1159 
1160  DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("\tpossible in %1 possible out %2\n", possible_in, possible_out));
1161 
1162  if (possible_out == 0) {
1163  warning << string_compose (_("AU %1 has zero outputs - configuration ignored"), name()) << endmsg;
1164  /* XXX surely this is just a send? (e.g. AUNetSend) */
1165  continue;
1166  }
1167 
1168  if (possible_in == 0) {
1169 
1170  /* instrument plugin, always legal but throws away inputs ...
1171  */
1172 
1173  if (possible_out == -1) {
1174  /* any configuration possible, provide stereo output */
1175  audio_out = 2;
1176  found = true;
1177  } else if (possible_out == -2) {
1178  /* plugins shouldn't really use (0,-2) but might.
1179  any configuration possible, provide stereo output
1180  */
1181  audio_out = 2;
1182  found = true;
1183  } else if (possible_out < -2) {
1184  /* explicitly variable number of outputs.
1185 
1186  Since Ardour can handle any configuration,
1187  we have to somehow pick a number.
1188 
1189  We'll use the number of inputs
1190  to the master bus, or 2 if there
1191  is no master bus.
1192  */
1194  if (master) {
1195  audio_out = master->input()->n_ports().n_audio();
1196  } else {
1197  audio_out = 2;
1198  }
1199  found = true;
1200  } else {
1201  /* exact number of outputs */
1202  audio_out = possible_out;
1203  found = true;
1204  }
1205  }
1206 
1207  if (possible_in == -1) {
1208 
1209  /* wildcard for input */
1210 
1211  if (possible_out == -1) {
1212  /* out much match in */
1213  audio_out = audio_in;
1214  found = true;
1215  } else if (possible_out == -2) {
1216  /* any configuration possible, pick matching */
1217  audio_out = audio_in;
1218  found = true;
1219  } else if (possible_out < -2) {
1220  /* explicitly variable number of outputs, pick maximum */
1221  audio_out = -possible_out;
1222  found = true;
1223  } else {
1224  /* exact number of outputs */
1225  audio_out = possible_out;
1226  found = true;
1227  }
1228  }
1229 
1230  if (possible_in == -2) {
1231 
1232  if (possible_out == -1) {
1233  /* any configuration possible, pick matching */
1234  audio_out = audio_in;
1235  found = true;
1236  } else if (possible_out == -2) {
1237  /* plugins shouldn't really use (-2,-2) but might.
1238  interpret as (-1,-1).
1239  */
1240  audio_out = audio_in;
1241  found = true;
1242  } else if (possible_out < -2) {
1243  /* explicitly variable number of outputs, pick maximum */
1244  audio_out = -possible_out;
1245  found = true;
1246  } else {
1247  /* exact number of outputs */
1248  audio_out = possible_out;
1249  found = true;
1250  }
1251  }
1252 
1253  if (possible_in < -2) {
1254 
1255  /* explicit variable number of inputs */
1256 
1257  if (audio_in > -possible_in) {
1258  /* request is too large */
1259  }
1260 
1261 
1262  if (possible_out == -1) {
1263  /* any output configuration possible, provide stereo out */
1264  audio_out = 2;
1265  found = true;
1266  } else if (possible_out == -2) {
1267  /* plugins shouldn't really use (<-2,-2) but might.
1268  interpret as (<-2,-1): any configuration possible, provide stereo output
1269  */
1270  audio_out = 2;
1271  found = true;
1272  } else if (possible_out < -2) {
1273  /* explicitly variable number of outputs.
1274 
1275  Since Ardour can handle any configuration,
1276  we have to somehow pick a number.
1277 
1278  We'll use the number of inputs
1279  to the master bus, or 2 if there
1280  is no master bus.
1281  */
1283  if (master) {
1284  audio_out = master->input()->n_ports().n_audio();
1285  } else {
1286  audio_out = 2;
1287  }
1288  found = true;
1289  } else {
1290  /* exact number of outputs */
1291  audio_out = possible_out;
1292  found = true;
1293  }
1294  }
1295 
1296  if (possible_in && (possible_in == audio_in)) {
1297 
1298  /* exact number of inputs ... must match obviously */
1299 
1300  if (possible_out == -1) {
1301  /* any output configuration possible, provide stereo output */
1302  audio_out = 2;
1303  found = true;
1304  } else if (possible_out == -2) {
1305  /* plugins shouldn't really use (>0,-2) but might.
1306  interpret as (>0,-1):
1307  any output configuration possible, provide stereo output
1308  */
1309  audio_out = 2;
1310  found = true;
1311  } else if (possible_out < -2) {
1312  /* explicitly variable number of outputs, pick maximum */
1313  audio_out = -possible_out;
1314  found = true;
1315  } else {
1316  /* exact number of outputs */
1317  audio_out = possible_out;
1318  found = true;
1319  }
1320  }
1321 
1322  if (found) {
1323  break;
1324  }
1325 
1326  }
1327 
1328  if (found) {
1329  DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("\tCHOSEN: in %1 out %2\n", in, out));
1330  } else {
1331  DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("\tFAIL: no io configs match %1\n", in));
1332  return false;
1333  }
1334 
1335  out.set (DataType::MIDI, 0);
1336  out.set (DataType::AUDIO, audio_out);
1337 
1338  return true;
1339 }
1340 
1341 int
1342 AUPlugin::set_input_format (AudioStreamBasicDescription& fmt)
1343 {
1344  return set_stream_format (kAudioUnitScope_Input, input_elements, fmt);
1345 }
1346 
1347 int
1348 AUPlugin::set_output_format (AudioStreamBasicDescription& fmt)
1349 {
1350  if (set_stream_format (kAudioUnitScope_Output, output_elements, fmt) != 0) {
1351  return -1;
1352  }
1353 
1354  if (buffers) {
1355  free (buffers);
1356  buffers = 0;
1357  }
1358 
1359  buffers = (AudioBufferList *) malloc (offsetof(AudioBufferList, mBuffers) +
1360  fmt.mChannelsPerFrame * sizeof(::AudioBuffer));
1361 
1362  return 0;
1363 }
1364 
1365 int
1366 AUPlugin::set_stream_format (int scope, uint32_t cnt, AudioStreamBasicDescription& fmt)
1367 {
1368  OSErr result;
1369 
1370  for (uint32_t i = 0; i < cnt; ++i) {
1371  DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("set stream format for %1, scope = %2 element %3\n",
1372  (scope == kAudioUnitScope_Input ? "input" : "output"),
1373  scope, cnt));
1374  if ((result = unit->SetFormat (scope, i, fmt)) != 0) {
1375  error << string_compose (_("AUPlugin: could not set stream format for %1/%2 (err = %3)"),
1376  (scope == kAudioUnitScope_Input ? "input" : "output"), i, result) << endmsg;
1377  return -1;
1378  }
1379  }
1380 
1381  if (scope == kAudioUnitScope_Input) {
1382  input_channels = fmt.mChannelsPerFrame;
1383  } else {
1384  output_channels = fmt.mChannelsPerFrame;
1385  }
1386 
1387  return 0;
1388 }
1389 
1390 OSStatus
1391 AUPlugin::render_callback(AudioUnitRenderActionFlags*,
1392  const AudioTimeStamp*,
1393  UInt32,
1394  UInt32 inNumberFrames,
1395  AudioBufferList* ioData)
1396 {
1397  /* not much to do with audio - the data is already in the buffers given to us in connect_and_run() */
1398 
1399  // DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("%1: render callback, frames %2 bufs %3\n",
1400  // name(), inNumberFrames, ioData->mNumberBuffers));
1401 
1402  if (input_maxbuf == 0) {
1403  error << _("AUPlugin: render callback called illegally!") << endmsg;
1404  return kAudioUnitErr_CannotDoInCurrentContext;
1405  }
1406  uint32_t limit = min ((uint32_t) ioData->mNumberBuffers, input_maxbuf);
1407 
1408  for (uint32_t i = 0; i < limit; ++i) {
1409  ioData->mBuffers[i].mNumberChannels = 1;
1410  ioData->mBuffers[i].mDataByteSize = sizeof (Sample) * inNumberFrames;
1411 
1412  /* we don't use the channel mapping because audiounits are
1413  never replicated. one plugin instance uses all channels/buffers
1414  passed to PluginInsert::connect_and_run()
1415  */
1416 
1417  ioData->mBuffers[i].mData = input_buffers->get_audio (i).data (cb_offset + input_offset);
1418  }
1419 
1420  cb_offset += inNumberFrames;
1421 
1422  return noErr;
1423 }
1424 
1425 int
1427 {
1428  Plugin::connect_and_run (bufs, in_map, out_map, nframes, offset);
1429 
1430  AudioUnitRenderActionFlags flags = 0;
1431  AudioTimeStamp ts;
1432  OSErr err;
1433 
1434  if (requires_fixed_size_buffers() && (nframes != _last_nframes)) {
1435  unit->GlobalReset();
1436  _last_nframes = nframes;
1437  }
1438 
1439  DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("%1 in %2 out %3 MIDI %4 bufs %5 (available %6)\n",
1441  bufs.count(), bufs.available()));
1442 
1443  /* the apparent number of buffers matches our input configuration, but we know that the bufferset
1444  has the capacity to handle our outputs.
1445  */
1446 
1447  assert (bufs.available() >= ChanCount (DataType::AUDIO, output_channels));
1448 
1449  input_buffers = &bufs;
1450  input_maxbuf = bufs.count().n_audio(); // number of input audio buffers
1451  input_offset = offset;
1452  cb_offset = 0;
1453 
1454  buffers->mNumberBuffers = output_channels;
1455 
1456  for (int32_t i = 0; i < output_channels; ++i) {
1457  buffers->mBuffers[i].mNumberChannels = 1;
1458  buffers->mBuffers[i].mDataByteSize = nframes * sizeof (Sample);
1459  /* setting this to 0 indicates to the AU that it can provide buffers here
1460  if necessary. if it can process in-place, it will use the buffers provided
1461  as input by ::render_callback() above.
1462 
1463  a non-null values tells the plugin to render into the buffer pointed
1464  at by the value.
1465  */
1466  buffers->mBuffers[i].mData = 0;
1467  }
1468 
1469  if (_has_midi_input) {
1470 
1471  uint32_t nmidi = bufs.count().n_midi();
1472 
1473  for (uint32_t i = 0; i < nmidi; ++i) {
1474 
1475  /* one MIDI port/buffer only */
1476 
1477  MidiBuffer& m = bufs.get_midi (i);
1478 
1479  for (MidiBuffer::iterator i = m.begin(); i != m.end(); ++i) {
1481 
1482  if (ev.is_channel_event()) {
1483  const uint8_t* b = ev.buffer();
1484  DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("%1: MIDI event %2\n", name(), ev));
1485  unit->MIDIEvent (b[0], b[1], b[2], ev.time());
1486  }
1487 
1488  /* XXX need to handle sysex and other message types */
1489  }
1490  }
1491  }
1492 
1493  /* does this really mean anything ?
1494  */
1495 
1496  ts.mSampleTime = frames_processed;
1497  ts.mFlags = kAudioTimeStampSampleTimeValid;
1498 
1499  DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("%1 render flags=%2 time=%3 nframes=%4 buffers=%5\n",
1500  name(), flags, frames_processed, nframes, buffers->mNumberBuffers));
1501 
1502  if ((err = unit->Render (&flags, &ts, 0, nframes, buffers)) == noErr) {
1503 
1504  input_maxbuf = 0;
1505  frames_processed += nframes;
1506 
1507  DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("%1 rendered %2 buffers of %3\n",
1508  name(), buffers->mNumberBuffers, output_channels));
1509 
1510  int32_t limit = min ((int32_t) buffers->mNumberBuffers, output_channels);
1511  int32_t i;
1512 
1513  for (i = 0; i < limit; ++i) {
1514  Sample* expected_buffer_address= bufs.get_audio (i).data (offset);
1515  if (expected_buffer_address != buffers->mBuffers[i].mData) {
1516  /* plugin provided its own buffer for output so copy it back to where we want it
1517  */
1518  memcpy (expected_buffer_address, buffers->mBuffers[i].mData, nframes * sizeof (Sample));
1519  }
1520  }
1521 
1522  /* now silence any buffers that were passed in but the that the plugin
1523  did not fill/touch/use.
1524  */
1525 
1526  for (;i < output_channels; ++i) {
1527  memset (bufs.get_audio (i).data (offset), 0, nframes * sizeof (Sample));
1528  }
1529 
1530  return 0;
1531  }
1532 
1533  error << string_compose (_("AU: render error for %1, status = %2"), name(), err) << endmsg;
1534  return -1;
1535 }
1536 
1537 OSStatus
1538 AUPlugin::get_beat_and_tempo_callback (Float64* outCurrentBeat,
1539  Float64* outCurrentTempo)
1540 {
1541  TempoMap& tmap (_session.tempo_map());
1542 
1543  DEBUG_TRACE (DEBUG::AudioUnits, "AU calls ardour beat&tempo callback\n");
1544 
1545  /* more than 1 meter or more than 1 tempo means that a simplistic computation
1546  (and interpretation) of a beat position will be incorrect. So refuse to
1547  offer the value.
1548  */
1549 
1550  if (tmap.n_tempos() > 1 || tmap.n_meters() > 1) {
1551  return kAudioUnitErr_CannotDoInCurrentContext;
1552  }
1553 
1554  Timecode::BBT_Time bbt;
1555  TempoMetric metric = tmap.metric_at (_session.transport_frame() + input_offset);
1556  tmap.bbt_time (_session.transport_frame() + input_offset, bbt);
1557 
1558  if (outCurrentBeat) {
1559  float beat;
1560  beat = metric.meter().divisions_per_bar() * bbt.bars;
1561  beat += bbt.beats;
1562  beat += bbt.ticks / Timecode::BBT_Time::ticks_per_beat;
1563  *outCurrentBeat = beat;
1564  }
1565 
1566  if (outCurrentTempo) {
1567  *outCurrentTempo = floor (metric.tempo().beats_per_minute());
1568  }
1569 
1570  return noErr;
1571 
1572 }
1573 
1574 OSStatus
1575 AUPlugin::get_musical_time_location_callback (UInt32* outDeltaSampleOffsetToNextBeat,
1576  Float32* outTimeSig_Numerator,
1577  UInt32* outTimeSig_Denominator,
1578  Float64* outCurrentMeasureDownBeat)
1579 {
1580  TempoMap& tmap (_session.tempo_map());
1581 
1582  DEBUG_TRACE (DEBUG::AudioUnits, "AU calls ardour music time location callback\n");
1583 
1584  /* more than 1 meter or more than 1 tempo means that a simplistic computation
1585  (and interpretation) of a beat position will be incorrect. So refuse to
1586  offer the value.
1587  */
1588 
1589  if (tmap.n_tempos() > 1 || tmap.n_meters() > 1) {
1590  return kAudioUnitErr_CannotDoInCurrentContext;
1591  }
1592 
1593  Timecode::BBT_Time bbt;
1594  TempoMetric metric = tmap.metric_at (_session.transport_frame() + input_offset);
1595  tmap.bbt_time (_session.transport_frame() + input_offset, bbt);
1596 
1597  if (outDeltaSampleOffsetToNextBeat) {
1598  if (bbt.ticks == 0) {
1599  /* on the beat */
1600  *outDeltaSampleOffsetToNextBeat = 0;
1601  } else {
1602  *outDeltaSampleOffsetToNextBeat = (UInt32)
1603  floor (((Timecode::BBT_Time::ticks_per_beat - bbt.ticks)/Timecode::BBT_Time::ticks_per_beat) * // fraction of a beat to next beat
1604  metric.tempo().frames_per_beat (_session.frame_rate())); // frames per beat
1605  }
1606  }
1607 
1608  if (outTimeSig_Numerator) {
1609  *outTimeSig_Numerator = (UInt32) lrintf (metric.meter().divisions_per_bar());
1610  }
1611  if (outTimeSig_Denominator) {
1612  *outTimeSig_Denominator = (UInt32) lrintf (metric.meter().note_divisor());
1613  }
1614 
1615  if (outCurrentMeasureDownBeat) {
1616 
1617  /* beat for the start of the bar.
1618  1|1|0 -> 1
1619  2|1|0 -> 1 + divisions_per_bar
1620  3|1|0 -> 1 + (2 * divisions_per_bar)
1621  etc.
1622  */
1623 
1624  *outCurrentMeasureDownBeat = 1 + metric.meter().divisions_per_bar() * (bbt.bars - 1);
1625  }
1626 
1627  return noErr;
1628 }
1629 
1630 OSStatus
1632  Boolean* outTransportStateChanged,
1633  Float64* outCurrentSampleInTimeLine,
1634  Boolean* outIsCycling,
1635  Float64* outCycleStartBeat,
1636  Float64* outCycleEndBeat)
1637 {
1638  bool rolling;
1639  float speed;
1640 
1641  DEBUG_TRACE (DEBUG::AudioUnits, "AU calls ardour transport state callback\n");
1642 
1643  rolling = _session.transport_rolling();
1644  speed = _session.transport_speed ();
1645 
1646  if (outIsPlaying) {
1647  *outIsPlaying = _session.transport_rolling();
1648  }
1649 
1650  if (outTransportStateChanged) {
1651  if (rolling != last_transport_rolling) {
1652  *outTransportStateChanged = true;
1653  } else if (speed != last_transport_speed) {
1654  *outTransportStateChanged = true;
1655  } else {
1656  *outTransportStateChanged = false;
1657  }
1658  }
1659 
1660  if (outCurrentSampleInTimeLine) {
1661  /* this assumes that the AU can only call this host callback from render context,
1662  where input_offset is valid.
1663  */
1664  *outCurrentSampleInTimeLine = _session.transport_frame() + input_offset;
1665  }
1666 
1667  if (outIsCycling) {
1669 
1670  *outIsCycling = (loc && _session.transport_rolling() && _session.get_play_loop());
1671 
1672  if (*outIsCycling) {
1673 
1674  if (outCycleStartBeat || outCycleEndBeat) {
1675 
1676  TempoMap& tmap (_session.tempo_map());
1677 
1678  /* more than 1 meter means that a simplistic computation (and interpretation) of
1679  a beat position will be incorrect. so refuse to offer the value.
1680  */
1681 
1682  if (tmap.n_meters() > 1) {
1683  return kAudioUnitErr_CannotDoInCurrentContext;
1684  }
1685 
1686  Timecode::BBT_Time bbt;
1687 
1688  if (outCycleStartBeat) {
1689  TempoMetric metric = tmap.metric_at (loc->start() + input_offset);
1690  _session.tempo_map().bbt_time (loc->start(), bbt);
1691 
1692  float beat;
1693  beat = metric.meter().divisions_per_bar() * bbt.bars;
1694  beat += bbt.beats;
1695  beat += bbt.ticks / Timecode::BBT_Time::ticks_per_beat;
1696 
1697  *outCycleStartBeat = beat;
1698  }
1699 
1700  if (outCycleEndBeat) {
1701  TempoMetric metric = tmap.metric_at (loc->end() + input_offset);
1702  _session.tempo_map().bbt_time (loc->end(), bbt);
1703 
1704  float beat;
1705  beat = metric.meter().divisions_per_bar() * bbt.bars;
1706  beat += bbt.beats;
1707  beat += bbt.ticks / Timecode::BBT_Time::ticks_per_beat;
1708 
1709  *outCycleEndBeat = beat;
1710  }
1711  }
1712  }
1713  }
1714 
1715  last_transport_rolling = rolling;
1716  last_transport_speed = speed;
1717 
1718  return noErr;
1719 }
1720 
1721 set<Evoral::Parameter>
1723 {
1724  set<Evoral::Parameter> automates;
1725 
1726  for (uint32_t i = 0; i < descriptors.size(); ++i) {
1727  if (descriptors[i].automatable) {
1728  automates.insert (automates.end(), Evoral::Parameter (PluginAutomation, 0, i));
1729  }
1730  }
1731 
1732  return automates;
1733 }
1734 
1735 string
1737 {
1738  if (param.type() == PluginAutomation && param.id() < parameter_count()) {
1739  return descriptors[param.id()].label;
1740  } else {
1741  return "??";
1742  }
1743 }
1744 
1745 void
1746 AUPlugin::print_parameter (uint32_t /*param*/, char* /*buf*/, uint32_t /*len*/) const
1747 {
1748  // NameValue stuff here
1749 }
1750 
1751 bool
1753 {
1754  return false;
1755 }
1756 
1757 bool
1758 AUPlugin::parameter_is_control (uint32_t param) const
1759 {
1760  assert(param < descriptors.size());
1761  if (descriptors[param].automatable) {
1762  /* corrently ardour expects all controls to be automatable
1763  * IOW ardour GUI elements mandate an Evoral::Parameter
1764  * for all input+control ports.
1765  */
1766  return true;
1767  }
1768  return false;
1769 }
1770 
1771 bool
1772 AUPlugin::parameter_is_input (uint32_t param) const
1773 {
1774  /* AU params that are both readable and writeable,
1775  * are listed in kAudioUnitScope_Global
1776  */
1777  return (descriptors[param].scope == kAudioUnitScope_Input || descriptors[param].scope == kAudioUnitScope_Global);
1778 }
1779 
1780 bool
1781 AUPlugin::parameter_is_output (uint32_t param) const
1782 {
1783  assert(param < descriptors.size());
1784  // TODO check if ardour properly handles ports
1785  // that report is_input + is_output == true
1786  // -> add || descriptors[param].scope == kAudioUnitScope_Global
1787  return (descriptors[param].scope == kAudioUnitScope_Output);
1788 }
1789 
1790 void
1792 {
1793  LocaleGuard lg (X_("C"));
1794  CFDataRef xmlData;
1795  CFPropertyListRef propertyList;
1796 
1797  DEBUG_TRACE (DEBUG::AudioUnits, "get preset state\n");
1798  if (unit->GetAUPreset (propertyList) != noErr) {
1799  return;
1800  }
1801 
1802  // Convert the property list into XML data.
1803 
1804  xmlData = CFPropertyListCreateXMLData( kCFAllocatorDefault, propertyList);
1805 
1806  if (!xmlData) {
1807  error << _("Could not create XML version of property list") << endmsg;
1808  return;
1809  }
1810 
1811  /* re-parse XML bytes to create a libxml++ XMLTree that we can merge into
1812  our state node. GACK!
1813  */
1814 
1815  XMLTree t;
1816 
1817  if (t.read_buffer (string ((const char*) CFDataGetBytePtr (xmlData), CFDataGetLength (xmlData)))) {
1818  if (t.root()) {
1819  root->add_child_copy (*t.root());
1820  }
1821  }
1822 
1823  CFRelease (xmlData);
1824  CFRelease (propertyList);
1825 }
1826 
1827 int
1828 AUPlugin::set_state(const XMLNode& node, int version)
1829 {
1830  int ret = -1;
1831  CFPropertyListRef propertyList;
1832  LocaleGuard lg (X_("C"));
1833 
1834  if (node.name() != state_node_name()) {
1835  error << _("Bad node sent to AUPlugin::set_state") << endmsg;
1836  return -1;
1837  }
1838 
1839 #ifndef NO_PLUGIN_STATE
1840  if (node.children().empty()) {
1841  return -1;
1842  }
1843 
1844  XMLNode* top = node.children().front();
1845  XMLNode* copy = new XMLNode (*top);
1846 
1847  XMLTree t;
1848  t.set_root (copy);
1849 
1850  const string& xml = t.write_buffer ();
1851  CFDataRef xmlData = CFDataCreateWithBytesNoCopy (kCFAllocatorDefault, (UInt8*) xml.data(), xml.length(), kCFAllocatorNull);
1852  CFStringRef errorString;
1853 
1854  propertyList = CFPropertyListCreateFromXMLData( kCFAllocatorDefault,
1855  xmlData,
1856  kCFPropertyListImmutable,
1857  &errorString);
1858 
1859  CFRelease (xmlData);
1860 
1861  if (propertyList) {
1862  DEBUG_TRACE (DEBUG::AudioUnits, "set preset\n");
1863  if (unit->SetAUPreset (propertyList) == noErr) {
1864  ret = 0;
1865 
1866  /* tell the world */
1867 
1868  AudioUnitParameter changedUnit;
1869  changedUnit.mAudioUnit = unit->AU();
1870  changedUnit.mParameterID = kAUParameterListener_AnyParameter;
1871  AUParameterListenerNotify (NULL, NULL, &changedUnit);
1872  }
1873  CFRelease (propertyList);
1874  }
1875 #endif
1876 
1877  Plugin::set_state (node, version);
1878  return ret;
1879 }
1880 
1881 bool
1883 {
1884  Plugin::load_preset (r);
1885 
1886  bool ret = false;
1887  CFPropertyListRef propertyList;
1888  Glib::ustring path;
1889  UserPresetMap::iterator ux;
1890  FactoryPresetMap::iterator fx;
1891 
1892  /* look first in "user" presets */
1893 
1894  if ((ux = user_preset_map.find (r.label)) != user_preset_map.end()) {
1895 
1896  if ((propertyList = load_property_list (ux->second)) != 0) {
1897  DEBUG_TRACE (DEBUG::AudioUnits, "set preset from user presets\n");
1898  if (unit->SetAUPreset (propertyList) == noErr) {
1899  ret = true;
1900 
1901  /* tell the world */
1902 
1903  AudioUnitParameter changedUnit;
1904  changedUnit.mAudioUnit = unit->AU();
1905  changedUnit.mParameterID = kAUParameterListener_AnyParameter;
1906  AUParameterListenerNotify (NULL, NULL, &changedUnit);
1907  }
1908  CFRelease(propertyList);
1909  }
1910 
1911  } else if ((fx = factory_preset_map.find (r.label)) != factory_preset_map.end()) {
1912 
1913  AUPreset preset;
1914 
1915  preset.presetNumber = fx->second;
1916  preset.presetName = CFStringCreateWithCString (kCFAllocatorDefault, fx->first.c_str(), kCFStringEncodingUTF8);
1917 
1918  DEBUG_TRACE (DEBUG::AudioUnits, "set preset from factory presets\n");
1919 
1920  if (unit->SetPresentPreset (preset) == 0) {
1921  ret = true;
1922 
1923  /* tell the world */
1924 
1925  AudioUnitParameter changedUnit;
1926  changedUnit.mAudioUnit = unit->AU();
1927  changedUnit.mParameterID = kAUParameterListener_AnyParameter;
1928  AUParameterListenerNotify (NULL, NULL, &changedUnit);
1929  }
1930  }
1931 
1932  return ret;
1933 }
1934 
1935 void
1937 {
1938 }
1939 
1940 string
1941 AUPlugin::do_save_preset (string preset_name)
1942 {
1943  CFPropertyListRef propertyList;
1944  vector<Glib::ustring> v;
1945  Glib::ustring user_preset_path;
1946 
1947  std::string m = maker();
1948  std::string n = name();
1949 
1952 
1953  v.push_back (Glib::get_home_dir());
1954  v.push_back ("Library");
1955  v.push_back ("Audio");
1956  v.push_back ("Presets");
1957  v.push_back (m);
1958  v.push_back (n);
1959 
1960  user_preset_path = Glib::build_filename (v);
1961 
1962  if (g_mkdir_with_parents (user_preset_path.c_str(), 0775) < 0) {
1963  error << string_compose (_("Cannot create user plugin presets folder (%1)"), user_preset_path) << endmsg;
1964  return string();
1965  }
1966 
1967  DEBUG_TRACE (DEBUG::AudioUnits, "get current preset\n");
1968  if (unit->GetAUPreset (propertyList) != noErr) {
1969  return string();
1970  }
1971 
1972  // add the actual preset name */
1973 
1974  v.push_back (preset_name + preset_suffix);
1975 
1976  // rebuild
1977 
1978  user_preset_path = Glib::build_filename (v);
1979 
1980  set_preset_name_in_plist (propertyList, preset_name);
1981 
1982  if (save_property_list (propertyList, user_preset_path)) {
1983  error << string_compose (_("Saving plugin state to %1 failed"), user_preset_path) << endmsg;
1984  return string();
1985  }
1986 
1987  CFRelease(propertyList);
1988 
1989  user_preset_map[preset_name] = user_preset_path;;
1990 
1991  DEBUG_TRACE (DEBUG::AudioUnits, string_compose("AU Saving Preset to %1\n", user_preset_path));
1992 
1993  return string ("file:///") + user_preset_path;
1994 }
1995 
1996 //-----------------------------------------------------------------------------
1997 // this is just a little helper function used by GetAUComponentDescriptionFromPresetFile()
1998 static SInt32
1999 GetDictionarySInt32Value(CFDictionaryRef inAUStateDictionary, CFStringRef inDictionaryKey, Boolean * outSuccess)
2000 {
2001  CFNumberRef cfNumber;
2002  SInt32 numberValue = 0;
2003  Boolean dummySuccess;
2004 
2005  if (outSuccess == NULL)
2006  outSuccess = &dummySuccess;
2007  if ( (inAUStateDictionary == NULL) || (inDictionaryKey == NULL) )
2008  {
2009  *outSuccess = FALSE;
2010  return 0;
2011  }
2012 
2013  cfNumber = (CFNumberRef) CFDictionaryGetValue(inAUStateDictionary, inDictionaryKey);
2014  if (cfNumber == NULL)
2015  {
2016  *outSuccess = FALSE;
2017  return 0;
2018  }
2019  *outSuccess = CFNumberGetValue(cfNumber, kCFNumberSInt32Type, &numberValue);
2020  if (*outSuccess)
2021  return numberValue;
2022  else
2023  return 0;
2024 }
2025 
2026 static OSStatus
2027 GetAUComponentDescriptionFromStateData(CFPropertyListRef inAUStateData, ComponentDescription * outComponentDescription)
2028 {
2029  CFDictionaryRef auStateDictionary;
2030  ComponentDescription tempDesc = {0,0,0,0,0};
2031  SInt32 versionValue;
2032  Boolean gotValue;
2033 
2034  if ( (inAUStateData == NULL) || (outComponentDescription == NULL) )
2035  return paramErr;
2036 
2037  // the property list for AU state data must be of the dictionary type
2038  if (CFGetTypeID(inAUStateData) != CFDictionaryGetTypeID()) {
2039  return kAudioUnitErr_InvalidPropertyValue;
2040  }
2041 
2042  auStateDictionary = (CFDictionaryRef)inAUStateData;
2043 
2044  // first check to make sure that the version of the AU state data is one that we know understand
2045  // XXX should I really do this? later versions would probably still hold these ID keys, right?
2046  versionValue = GetDictionarySInt32Value(auStateDictionary, CFSTR(kAUPresetVersionKey), &gotValue);
2047 
2048  if (!gotValue) {
2049  return kAudioUnitErr_InvalidPropertyValue;
2050  }
2051 #define kCurrentSavedStateVersion 0
2052  if (versionValue != kCurrentSavedStateVersion) {
2053  return kAudioUnitErr_InvalidPropertyValue;
2054  }
2055 
2056  // grab the ComponentDescription values from the AU state data
2057  tempDesc.componentType = (OSType) GetDictionarySInt32Value(auStateDictionary, CFSTR(kAUPresetTypeKey), NULL);
2058  tempDesc.componentSubType = (OSType) GetDictionarySInt32Value(auStateDictionary, CFSTR(kAUPresetSubtypeKey), NULL);
2059  tempDesc.componentManufacturer = (OSType) GetDictionarySInt32Value(auStateDictionary, CFSTR(kAUPresetManufacturerKey), NULL);
2060  // zero values are illegit for specific ComponentDescriptions, so zero for any value means that there was an error
2061  if ( (tempDesc.componentType == 0) || (tempDesc.componentSubType == 0) || (tempDesc.componentManufacturer == 0) )
2062  return kAudioUnitErr_InvalidPropertyValue;
2063 
2064  *outComponentDescription = tempDesc;
2065  return noErr;
2066 }
2067 
2068 
2069 static bool au_preset_filter (const string& str, void* arg)
2070 {
2071  /* Not a dotfile, has a prefix before a period, suffix is aupreset */
2072 
2073  bool ret;
2074 
2075  ret = (str[0] != '.' && str.length() > 9 && str.find (preset_suffix) == (str.length() - preset_suffix.length()));
2076 
2077  if (ret && arg) {
2078 
2079  /* check the preset file path name against this plugin
2080  ID. The idea is that all preset files for this plugin
2081  include "<manufacturer>/<plugin-name>" in their path.
2082  */
2083 
2084  Plugin* p = (Plugin *) arg;
2085  string match = p->maker();
2086  match += '/';
2087  match += p->name();
2088 
2089  ret = str.find (match) != string::npos;
2090 
2091  if (ret == false) {
2092  string m = p->maker ();
2093  string n = p->name ();
2096  match = m;
2097  match += '/';
2098  match += n;
2099 
2100  ret = str.find (match) != string::npos;
2101  }
2102  }
2103 
2104  return ret;
2105 }
2106 
2107 bool
2108 check_and_get_preset_name (Component component, const string& pathstr, string& preset_name)
2109 {
2110  OSStatus status;
2111  CFPropertyListRef plist;
2112  ComponentDescription presetDesc;
2113  bool ret = false;
2114 
2115  plist = load_property_list (pathstr);
2116 
2117  if (!plist) {
2118  return ret;
2119  }
2120 
2121  // get the ComponentDescription from the AU preset file
2122 
2123  status = GetAUComponentDescriptionFromStateData(plist, &presetDesc);
2124 
2125  if (status == noErr) {
2126  if (ComponentAndDescriptionMatch_Loosely(component, &presetDesc)) {
2127 
2128  /* try to get the preset name from the property list */
2129 
2130  if (CFGetTypeID(plist) == CFDictionaryGetTypeID()) {
2131 
2132  const void* psk = CFDictionaryGetValue ((CFMutableDictionaryRef)plist, CFSTR(kAUPresetNameKey));
2133 
2134  if (psk) {
2135 
2136  const char* p = CFStringGetCStringPtr ((CFStringRef) psk, kCFStringEncodingUTF8);
2137 
2138  if (!p) {
2139  char buf[PATH_MAX+1];
2140 
2141  if (CFStringGetCString ((CFStringRef)psk, buf, sizeof (buf), kCFStringEncodingUTF8)) {
2142  preset_name = buf;
2143  }
2144  }
2145  }
2146  }
2147  }
2148  }
2149 
2150  CFRelease (plist);
2151 
2152  return true;
2153 }
2154 
2155 std::string
2157 {
2158  string preset_name;
2159 
2160  CFPropertyListRef propertyList;
2161 
2162  DEBUG_TRACE (DEBUG::AudioUnits, "get current preset for current_preset()\n");
2163  if (unit->GetAUPreset (propertyList) == noErr) {
2164  preset_name = get_preset_name_in_plist (propertyList);
2165  CFRelease(propertyList);
2166  }
2167 
2168  return preset_name;
2169 }
2170 
2171 void
2173 {
2174  vector<string> preset_files;
2175 
2176  user_preset_map.clear ();
2177 
2178  find_files_matching_filter (preset_files, preset_search_path, au_preset_filter, this, true, true, true);
2179 
2180  if (preset_files.empty()) {
2181  DEBUG_TRACE (DEBUG::AudioUnits, "AU No Preset Files found for given plugin.\n");
2182  return;
2183  }
2184 
2185  for (vector<string>::iterator x = preset_files.begin(); x != preset_files.end(); ++x) {
2186 
2187  string path = *x;
2188  string preset_name;
2189 
2190  /* make an initial guess at the preset name using the path */
2191 
2192  preset_name = Glib::path_get_basename (path);
2193  preset_name = preset_name.substr (0, preset_name.find_last_of ('.'));
2194 
2195  /* check that this preset file really matches this plugin
2196  and potentially get the "real" preset name from
2197  within the file.
2198  */
2199 
2200  if (check_and_get_preset_name (get_comp()->Comp(), path, preset_name)) {
2201  user_preset_map[preset_name] = path;
2202  DEBUG_TRACE (DEBUG::AudioUnits, string_compose("AU Preset File: %1 > %2\n", preset_name, path));
2203  } else {
2204  DEBUG_TRACE (DEBUG::AudioUnits, string_compose("AU INVALID Preset: %1 > %2\n", preset_name, path));
2205  }
2206 
2207  }
2208 
2209  /* now fill the vector<string> with the names we have */
2210 
2211  for (UserPresetMap::iterator i = user_preset_map.begin(); i != user_preset_map.end(); ++i) {
2212  _presets.insert (make_pair (i->second, Plugin::PresetRecord (i->second, i->first)));
2213  DEBUG_TRACE (DEBUG::AudioUnits, string_compose("AU Adding User Preset: %1 > %2\n", i->first, i->second));
2214  }
2215 
2216  /* add factory presets */
2217 
2218  for (FactoryPresetMap::iterator i = factory_preset_map.begin(); i != factory_preset_map.end(); ++i) {
2219  /* XXX: dubious */
2220  string const uri = string_compose ("%1", _presets.size ());
2221  _presets.insert (make_pair (uri, Plugin::PresetRecord (uri, i->first, i->second)));
2222  DEBUG_TRACE (DEBUG::AudioUnits, string_compose("AU Adding Factory Preset: %1 > %2\n", i->first, i->second));
2223  }
2224 }
2225 
2226 bool
2228 {
2229  // even if the plugin doesn't have its own editor, the AU API can be used
2230  // to create one that looks native.
2231  return true;
2232 }
2233 
2235  : descriptor (d)
2236 {
2238 }
2239 
2241 {
2243 }
2244 
2245 PluginPtr
2247 {
2248  try {
2249  PluginPtr plugin;
2250 
2251  DEBUG_TRACE (DEBUG::AudioUnits, "load AU as a component\n");
2252  boost::shared_ptr<CAComponent> comp (new CAComponent(*descriptor));
2253 
2254  if (!comp->IsValid()) {
2255  error << ("AudioUnit: not a valid Component") << endmsg;
2256  } else {
2257  plugin.reset (new AUPlugin (session.engine(), session, comp));
2258  }
2259 
2260  AUPluginInfo *aup = new AUPluginInfo (*this);
2261  DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("plugin info for %1 = %2\n", this, aup));
2262  plugin->set_info (PluginInfoPtr (aup));
2263  boost::dynamic_pointer_cast<AUPlugin> (plugin)->set_fixed_size_buffers (aup->creator == "Universal Audio");
2264  return plugin;
2265  }
2266 
2267  catch (failed_constructor &err) {
2268  DEBUG_TRACE (DEBUG::AudioUnits, "failed to load component/plugin\n");
2269  return PluginPtr ();
2270  }
2271 }
2272 
2273 Glib::ustring
2275 {
2276  return Glib::build_filename (ARDOUR::user_config_directory(), "au_cache");
2277 }
2278 
2281 {
2282  XMLTree tree;
2283 
2284  if (!Glib::file_test (au_cache_path(), Glib::FILE_TEST_EXISTS)) {
2285  ARDOUR::BootMessage (_("Discovering AudioUnit plugins (could take some time ...)"));
2286  }
2287  // create crash log file
2288  au_start_crashlog ();
2289 
2290  PluginInfoList* plugs = new PluginInfoList;
2291 
2292  discover_fx (*plugs);
2293  discover_music (*plugs);
2294  discover_generators (*plugs);
2295  discover_instruments (*plugs);
2296 
2297  // all fine if we get here
2298  au_remove_crashlog ();
2299 
2300  DEBUG_TRACE (DEBUG::PluginManager, string_compose ("AU: discovered %1 plugins\n", plugs->size()));
2301 
2302  return plugs;
2303 }
2304 
2305 void
2307 {
2308  CAComponentDescription desc;
2309  desc.componentFlags = 0;
2310  desc.componentFlagsMask = 0;
2311  desc.componentSubType = 0;
2312  desc.componentManufacturer = 0;
2313  desc.componentType = kAudioUnitType_MusicEffect;
2314 
2315  discover_by_description (plugs, desc);
2316 }
2317 
2318 void
2320 {
2321  CAComponentDescription desc;
2322  desc.componentFlags = 0;
2323  desc.componentFlagsMask = 0;
2324  desc.componentSubType = 0;
2325  desc.componentManufacturer = 0;
2326  desc.componentType = kAudioUnitType_Effect;
2327 
2328  discover_by_description (plugs, desc);
2329 }
2330 
2331 void
2333 {
2334  CAComponentDescription desc;
2335  desc.componentFlags = 0;
2336  desc.componentFlagsMask = 0;
2337  desc.componentSubType = 0;
2338  desc.componentManufacturer = 0;
2339  desc.componentType = kAudioUnitType_Generator;
2340 
2341  discover_by_description (plugs, desc);
2342 }
2343 
2344 void
2346 {
2347  CAComponentDescription desc;
2348  desc.componentFlags = 0;
2349  desc.componentFlagsMask = 0;
2350  desc.componentSubType = 0;
2351  desc.componentManufacturer = 0;
2352  desc.componentType = kAudioUnitType_MusicDevice;
2353 
2354  discover_by_description (plugs, desc);
2355 }
2356 
2357 
2358 bool
2360 {
2361  string fn = Glib::build_filename (ARDOUR::user_cache_directory(), "au_crashlog.txt");
2362  if (!Glib::file_test (fn, Glib::FILE_TEST_EXISTS)) {
2363  return false;
2364  }
2365  std::ifstream ifs(fn.c_str());
2366  msg.assign ((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
2367  au_remove_crashlog ();
2368  return true;
2369 }
2370 
2371 void
2373 {
2374  string fn = Glib::build_filename (ARDOUR::user_cache_directory(), "au_crashlog.txt");
2375  assert(!_crashlog_fd);
2376  DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("Creating AU Log: %1\n", fn));
2377  if (!(_crashlog_fd = fopen(fn.c_str(), "w"))) {
2378  PBD::error << "Cannot create AU error-log" << fn << "\n";
2379  cerr << "Cannot create AU error-log" << fn << "\n";
2380  }
2381 }
2382 
2383 void
2385 {
2386  if (_crashlog_fd) {
2387  ::fclose(_crashlog_fd);
2388  _crashlog_fd = NULL;
2389  }
2390  string fn = Glib::build_filename (ARDOUR::user_cache_directory(), "au_crashlog.txt");
2391  ::g_unlink(fn.c_str());
2392  DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("Remove AU Log: %1\n", fn));
2393 }
2394 
2395 
2396 void
2397 AUPluginInfo::au_crashlog (std::string msg)
2398 {
2399  if (!_crashlog_fd) {
2400  fprintf(stderr, "AU: %s\n", msg.c_str());
2401  } else {
2402  fprintf(_crashlog_fd, "AU: %s\n", msg.c_str());
2403  ::fflush(_crashlog_fd);
2404  }
2405 }
2406 
2407 void
2408 AUPluginInfo::discover_by_description (PluginInfoList& plugs, CAComponentDescription& desc)
2409 {
2410  Component comp = 0;
2411  au_crashlog(string_compose("Start AU discovery for Type: %1", (int)desc.componentType));
2412 
2413  comp = FindNextComponent (NULL, &desc);
2414 
2415  while (comp != NULL) {
2416  CAComponentDescription temp;
2417  GetComponentInfo (comp, &temp, NULL, NULL, NULL);
2418  CFStringRef itemName = NULL;
2419 
2420  {
2421  if (itemName != NULL) CFRelease(itemName);
2422  CFStringRef compTypeString = UTCreateStringForOSType(temp.componentType);
2423  CFStringRef compSubTypeString = UTCreateStringForOSType(temp.componentSubType);
2424  CFStringRef compManufacturerString = UTCreateStringForOSType(temp.componentManufacturer);
2425  itemName = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ - %@ - %@"),
2426  compTypeString, compManufacturerString, compSubTypeString);
2427  au_crashlog(string_compose("Scanning ID: %1", CFStringRefToStdString(itemName)));
2428  if (compTypeString != NULL)
2429  CFRelease(compTypeString);
2430  if (compSubTypeString != NULL)
2431  CFRelease(compSubTypeString);
2432  if (compManufacturerString != NULL)
2433  CFRelease(compManufacturerString);
2434  }
2435 
2436  if (is_blacklisted(CFStringRefToStdString(itemName))) {
2437  info << string_compose (_("Skipped blacklisted AU plugin %1 "), CFStringRefToStdString(itemName)) << endmsg;
2438  comp = FindNextComponent (comp, &desc);
2439  continue;
2440  }
2441 
2443  (boost::shared_ptr<CAComponentDescription> (new CAComponentDescription(temp))));
2444 
2445  /* although apple designed the subtype field to be a "category" indicator,
2446  its really turned into a plugin ID field for a given manufacturer. Hence
2447  there are no categories for AudioUnits. However, to keep the plugins
2448  showing up under "categories", we'll use the "type" as a high level
2449  selector.
2450 
2451  NOTE: no panners, format converters or i/o AU's for our purposes
2452  */
2453 
2454  switch (info->descriptor->Type()) {
2455  case kAudioUnitType_Panner:
2456  case kAudioUnitType_OfflineEffect:
2457  case kAudioUnitType_FormatConverter:
2458  comp = FindNextComponent (comp, &desc);
2459  continue;
2460 
2461  case kAudioUnitType_Output:
2462  info->category = _("AudioUnit Outputs");
2463  break;
2464  case kAudioUnitType_MusicDevice:
2465  info->category = _("AudioUnit Instruments");
2466  break;
2467  case kAudioUnitType_MusicEffect:
2468  info->category = _("AudioUnit MusicEffects");
2469  break;
2470  case kAudioUnitType_Effect:
2471  info->category = _("AudioUnit Effects");
2472  break;
2473  case kAudioUnitType_Mixer:
2474  info->category = _("AudioUnit Mixers");
2475  break;
2476  case kAudioUnitType_Generator:
2477  info->category = _("AudioUnit Generators");
2478  break;
2479  default:
2480  info->category = _("AudioUnit (Unknown)");
2481  break;
2482  }
2483 
2484  au_blacklist(CFStringRefToStdString(itemName));
2485  AUPluginInfo::get_names (temp, info->name, info->creator);
2486  ARDOUR::PluginScanMessage(_("AU"), info->name, false);
2487  au_crashlog(string_compose("Plugin: %1", info->name));
2488 
2489  info->type = ARDOUR::AudioUnit;
2490  info->unique_id = stringify_descriptor (*info->descriptor);
2491 
2492  /* XXX not sure of the best way to handle plugin versioning yet
2493  */
2494 
2495  CAComponent cacomp (*info->descriptor);
2496 
2497  if (cacomp.GetResourceVersion (info->version) != noErr) {
2498  info->version = 0;
2499  }
2500 
2501  if (cached_io_configuration (info->unique_id, info->version, cacomp, info->cache, info->name)) {
2502 
2503  /* here we have to map apple's wildcard system to a simple pair
2504  of values. in ::can_do() we use the whole system, but here
2505  we need a single pair of values. XXX probably means we should
2506  remove any use of these values.
2507 
2508  for now, if the plugin provides a wildcard, treat it as 1. we really
2509  don't care much, because whether we can handle an i/o configuration
2510  depends upon ::can_support_io_configuration(), not these counts.
2511 
2512  they exist because other parts of ardour try to present i/o configuration
2513  info to the user, which should perhaps be revisited.
2514  */
2515 
2516  int32_t possible_in = info->cache.io_configs.front().first;
2517  int32_t possible_out = info->cache.io_configs.front().second;
2518 
2519  if (possible_in > 0) {
2520  info->n_inputs.set (DataType::AUDIO, possible_in);
2521  } else {
2522  info->n_inputs.set (DataType::AUDIO, 1);
2523  }
2524 
2525  if (possible_out > 0) {
2526  info->n_outputs.set (DataType::AUDIO, possible_out);
2527  } else {
2528  info->n_outputs.set (DataType::AUDIO, 1);
2529  }
2530 
2531  DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("detected AU %1 with %2 i/o configurations - %3\n",
2532  info->name.c_str(), info->cache.io_configs.size(), info->unique_id));
2533 
2534  plugs.push_back (info);
2535 
2536  } else {
2537  error << string_compose (_("Cannot get I/O configuration info for AU %1"), info->name) << endmsg;
2538  }
2539 
2540  au_unblacklist(CFStringRefToStdString(itemName));
2541  au_crashlog("Success.");
2542  comp = FindNextComponent (comp, &desc);
2543  if (itemName != NULL) CFRelease(itemName); itemName = NULL;
2544  }
2545  au_crashlog(string_compose("End AU discovery for Type: %1", (int)desc.componentType));
2546 }
2547 
2548 bool
2549 AUPluginInfo::cached_io_configuration (const std::string& unique_id,
2550  UInt32 version,
2551  CAComponent& comp,
2552  AUPluginCachedInfo& cinfo,
2553  const std::string& name)
2554 {
2555  std::string id;
2556  char buf[32];
2557 
2558  /* concatenate unique ID with version to provide a key for cached info lookup.
2559  this ensures we don't get stale information, or should if plugin developers
2560  follow Apple "guidelines".
2561  */
2562 
2563  snprintf (buf, sizeof (buf), "%u", (uint32_t) version);
2564  id = unique_id;
2565  id += '/';
2566  id += buf;
2567 
2568  CachedInfoMap::iterator cim = cached_info.find (id);
2569 
2570  if (cim != cached_info.end()) {
2571  cinfo = cim->second;
2572  return true;
2573  }
2574 
2575  CAAudioUnit unit;
2576  AUChannelInfo* channel_info;
2577  UInt32 cnt;
2578  int ret;
2579 
2580  ARDOUR::BootMessage (string_compose (_("Checking AudioUnit: %1"), name));
2581 
2582  try {
2583 
2584  if (CAAudioUnit::Open (comp, unit) != noErr) {
2585  return false;
2586  }
2587 
2588  } catch (...) {
2589 
2590  warning << string_compose (_("Could not load AU plugin %1 - ignored"), name) << endmsg;
2591  return false;
2592 
2593  }
2594 
2595  DEBUG_TRACE (DEBUG::AudioUnits, "get AU channel info\n");
2596  if ((ret = unit.GetChannelInfo (&channel_info, cnt)) < 0) {
2597  return false;
2598  }
2599 
2600  if (ret > 0) {
2601 
2602  /* no explicit info available, so default to 1in/1out */
2603 
2604  /* XXX this is wrong. we should be indicating wildcard values */
2605 
2606  cinfo.io_configs.push_back (pair<int,int> (-1, -1));
2607 
2608  } else {
2609 
2610  /* store each configuration */
2611 
2612  for (uint32_t n = 0; n < cnt; ++n) {
2613  cinfo.io_configs.push_back (pair<int,int> (channel_info[n].inChannels,
2614  channel_info[n].outChannels));
2615  }
2616 
2617  free (channel_info);
2618  }
2619 
2620  add_cached_info (id, cinfo);
2621  save_cached_info ();
2622 
2623  return true;
2624 }
2625 
2626 void
2627 AUPluginInfo::add_cached_info (const std::string& id, AUPluginCachedInfo& cinfo)
2628 {
2629  cached_info[id] = cinfo;
2630 }
2631 
2632 #define AU_CACHE_VERSION "2.0"
2633 
2634 void
2636 {
2637  XMLNode* node;
2638 
2639  node = new XMLNode (X_("AudioUnitPluginCache"));
2640  node->add_property( "version", AU_CACHE_VERSION );
2641 
2642  for (map<string,AUPluginCachedInfo>::iterator i = cached_info.begin(); i != cached_info.end(); ++i) {
2643  XMLNode* parent = new XMLNode (X_("plugin"));
2644  parent->add_property ("id", i->first);
2645  node->add_child_nocopy (*parent);
2646 
2647  for (vector<pair<int, int> >::iterator j = i->second.io_configs.begin(); j != i->second.io_configs.end(); ++j) {
2648 
2649  XMLNode* child = new XMLNode (X_("io"));
2650  char buf[32];
2651 
2652  snprintf (buf, sizeof (buf), "%d", j->first);
2653  child->add_property (X_("in"), buf);
2654  snprintf (buf, sizeof (buf), "%d", j->second);
2655  child->add_property (X_("out"), buf);
2656  parent->add_child_nocopy (*child);
2657  }
2658 
2659  }
2660 
2661  Glib::ustring path = au_cache_path ();
2662  XMLTree tree;
2663 
2664  tree.set_root (node);
2665 
2666  if (!tree.write (path)) {
2667  error << string_compose (_("could not save AU cache to %1"), path) << endmsg;
2668  g_unlink (path.c_str());
2669  }
2670 }
2671 
2672 int
2674 {
2675  Glib::ustring path = au_cache_path ();
2676  XMLTree tree;
2677 
2678  if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS)) {
2679  return 0;
2680  }
2681 
2682  if ( !tree.read (path) ) {
2683  error << "au_cache is not a valid XML file. AU plugins will be re-scanned" << endmsg;
2684  return -1;
2685  }
2686 
2687  const XMLNode* root (tree.root());
2688 
2689  if (root->name() != X_("AudioUnitPluginCache")) {
2690  return -1;
2691  }
2692 
2693  //initial version has incorrectly stored i/o info, and/or garbage chars.
2694  const XMLProperty* version = root->property(X_("version"));
2695  if (! ((version != NULL) && (version->value() == X_(AU_CACHE_VERSION)))) {
2696  error << "au_cache is not correct version. AU plugins will be re-scanned" << endmsg;
2697  return -1;
2698  }
2699 
2700  cached_info.clear ();
2701 
2702  const XMLNodeList children = root->children();
2703 
2704  for (XMLNodeConstIterator iter = children.begin(); iter != children.end(); ++iter) {
2705 
2706  const XMLNode* child = *iter;
2707 
2708  if (child->name() == X_("plugin")) {
2709 
2710  const XMLNode* gchild;
2711  const XMLNodeList gchildren = child->children();
2712  const XMLProperty* prop = child->property (X_("id"));
2713 
2714  if (!prop) {
2715  continue;
2716  }
2717 
2718  string id = prop->value();
2719  string fixed;
2720  string version;
2721 
2722  string::size_type slash = id.find_last_of ('/');
2723 
2724  if (slash == string::npos) {
2725  continue;
2726  }
2727 
2728  version = id.substr (slash);
2729  id = id.substr (0, slash);
2730  fixed = AUPlugin::maybe_fix_broken_au_id (id);
2731 
2732  if (fixed.empty()) {
2733  error << string_compose (_("Your AudioUnit configuration cache contains an AU plugin whose ID cannot be understood - ignored (%1)"), id) << endmsg;
2734  continue;
2735  }
2736 
2737  id = fixed;
2738  id += version;
2739 
2740  AUPluginCachedInfo cinfo;
2741 
2742  for (XMLNodeConstIterator giter = gchildren.begin(); giter != gchildren.end(); giter++) {
2743 
2744  gchild = *giter;
2745 
2746  if (gchild->name() == X_("io")) {
2747 
2748  int in;
2749  int out;
2750  const XMLProperty* iprop;
2751  const XMLProperty* oprop;
2752 
2753  if (((iprop = gchild->property (X_("in"))) != 0) &&
2754  ((oprop = gchild->property (X_("out"))) != 0)) {
2755  in = atoi (iprop->value());
2756  out = atoi (oprop->value());
2757 
2758  cinfo.io_configs.push_back (pair<int,int> (in, out));
2759  }
2760  }
2761  }
2762 
2763  if (cinfo.io_configs.size()) {
2764  add_cached_info (id, cinfo);
2765  }
2766  }
2767  }
2768 
2769  return 0;
2770 }
2771 
2772 void
2773 AUPluginInfo::get_names (CAComponentDescription& comp_desc, std::string& name, std::string& maker)
2774 {
2775  CFStringRef itemName = NULL;
2776 
2777  // Marc Poirier-style item name
2778  CAComponent auComponent (comp_desc);
2779  if (auComponent.IsValid()) {
2780  CAComponentDescription dummydesc;
2781  Handle nameHandle = NewHandle(sizeof(void*));
2782  if (nameHandle != NULL) {
2783  OSErr err = GetComponentInfo(auComponent.Comp(), &dummydesc, nameHandle, NULL, NULL);
2784  if (err == noErr) {
2785  ConstStr255Param nameString = (ConstStr255Param) (*nameHandle);
2786  if (nameString != NULL) {
2787  itemName = CFStringCreateWithPascalString(kCFAllocatorDefault, nameString, CFStringGetSystemEncoding());
2788  }
2789  }
2790  DisposeHandle(nameHandle);
2791  }
2792  }
2793 
2794  // if Marc-style fails, do the original way
2795  if (itemName == NULL) {
2796  CFStringRef compTypeString = UTCreateStringForOSType(comp_desc.componentType);
2797  CFStringRef compSubTypeString = UTCreateStringForOSType(comp_desc.componentSubType);
2798  CFStringRef compManufacturerString = UTCreateStringForOSType(comp_desc.componentManufacturer);
2799 
2800  itemName = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ - %@ - %@"),
2801  compTypeString, compManufacturerString, compSubTypeString);
2802 
2803  if (compTypeString != NULL)
2804  CFRelease(compTypeString);
2805  if (compSubTypeString != NULL)
2806  CFRelease(compSubTypeString);
2807  if (compManufacturerString != NULL)
2808  CFRelease(compManufacturerString);
2809  }
2810 
2811  string str = CFStringRefToStdString(itemName);
2812  string::size_type colon = str.find (':');
2813 
2814  if (colon) {
2815  name = str.substr (colon+1);
2816  maker = str.substr (0, colon);
2817  strip_whitespace_edges (maker);
2818  strip_whitespace_edges (name);
2819  } else {
2820  name = str;
2821  maker = "unknown";
2822  strip_whitespace_edges (name);
2823  }
2824 }
2825 
2826 std::string
2827 AUPluginInfo::stringify_descriptor (const CAComponentDescription& desc)
2828 {
2829  stringstream s;
2830 
2831  /* note: OSType is a compiler-implemenation-defined value,
2832  historically a 32 bit integer created with a multi-character
2833  constant such as 'abcd'. It is, fundamentally, an abomination.
2834  */
2835 
2836  s << desc.Type();
2837  s << '-';
2838  s << desc.SubType();
2839  s << '-';
2840  s << desc.Manu();
2841 
2842  return s.str();
2843 }
2844 
2845 bool
2847 {
2848  return is_effect_with_midi_input () || is_instrument ();
2849 }
2850 
2851 bool
2853 {
2855 }
2856 
2857 bool
2859 {
2860  return descriptor->IsAUFX();
2861 }
2862 
2863 bool
2865 {
2866  return descriptor->IsAUFM();
2867 }
2868 
2869 bool
2871 {
2872  return descriptor->IsMusicDevice();
2873 }
2874 
2875 void
2877 {
2878  Plugin::set_info (info);
2879 
2881  _has_midi_input = pinfo->needs_midi_input ();
2882  _has_midi_output = false;
2883 }
2884 
2885 int
2886 AUPlugin::create_parameter_listener (AUEventListenerProc cb, void* arg, float interval_secs)
2887 {
2888 #ifdef WITH_CARBON
2889  CFRunLoopRef run_loop = (CFRunLoopRef) GetCFRunLoopFromEventLoop(GetCurrentEventLoop());
2890 #else
2891  CFRunLoopRef run_loop = CFRunLoopGetCurrent();
2892 #endif
2893  CFStringRef loop_mode = kCFRunLoopDefaultMode;
2894 
2895  if (AUEventListenerCreate (cb, arg, run_loop, loop_mode, interval_secs, interval_secs, &_parameter_listener) != noErr) {
2896  return -1;
2897  }
2898 
2900 
2901  return 0;
2902 }
2903 
2904 int
2906 {
2907  AudioUnitEvent event;
2908 
2909  if (!_parameter_listener || param_id >= descriptors.size()) {
2910  return -2;
2911  }
2912 
2913  event.mEventType = kAudioUnitEvent_ParameterValueChange;
2914  event.mArgument.mParameter.mAudioUnit = unit->AU();
2915  event.mArgument.mParameter.mParameterID = descriptors[param_id].id;
2916  event.mArgument.mParameter.mScope = descriptors[param_id].scope;
2917  event.mArgument.mParameter.mElement = descriptors[param_id].element;
2918 
2919  if (AUEventListenerAddEventType (_parameter_listener, _parameter_listener_arg, &event) != noErr) {
2920  return -1;
2921  }
2922 
2923  event.mEventType = kAudioUnitEvent_BeginParameterChangeGesture;
2924  event.mArgument.mParameter.mAudioUnit = unit->AU();
2925  event.mArgument.mParameter.mParameterID = descriptors[param_id].id;
2926  event.mArgument.mParameter.mScope = descriptors[param_id].scope;
2927  event.mArgument.mParameter.mElement = descriptors[param_id].element;
2928 
2929  if (AUEventListenerAddEventType (_parameter_listener, _parameter_listener_arg, &event) != noErr) {
2930  return -1;
2931  }
2932 
2933  event.mEventType = kAudioUnitEvent_EndParameterChangeGesture;
2934  event.mArgument.mParameter.mAudioUnit = unit->AU();
2935  event.mArgument.mParameter.mParameterID = descriptors[param_id].id;
2936  event.mArgument.mParameter.mScope = descriptors[param_id].scope;
2937  event.mArgument.mParameter.mElement = descriptors[param_id].element;
2938 
2939  if (AUEventListenerAddEventType (_parameter_listener, _parameter_listener_arg, &event) != noErr) {
2940  return -1;
2941  }
2942 
2943  return 0;
2944 }
2945 
2946 int
2948 {
2949  AudioUnitEvent event;
2950 
2951  if (!_parameter_listener || param_id >= descriptors.size()) {
2952  return -2;
2953  }
2954 
2955  event.mEventType = kAudioUnitEvent_ParameterValueChange;
2956  event.mArgument.mParameter.mAudioUnit = unit->AU();
2957  event.mArgument.mParameter.mParameterID = descriptors[param_id].id;
2958  event.mArgument.mParameter.mScope = descriptors[param_id].scope;
2959  event.mArgument.mParameter.mElement = descriptors[param_id].element;
2960 
2961  if (AUEventListenerRemoveEventType (_parameter_listener, _parameter_listener_arg, &event) != noErr) {
2962  return -1;
2963  }
2964 
2965  event.mEventType = kAudioUnitEvent_BeginParameterChangeGesture;
2966  event.mArgument.mParameter.mAudioUnit = unit->AU();
2967  event.mArgument.mParameter.mParameterID = descriptors[param_id].id;
2968  event.mArgument.mParameter.mScope = descriptors[param_id].scope;
2969  event.mArgument.mParameter.mElement = descriptors[param_id].element;
2970 
2971  if (AUEventListenerRemoveEventType (_parameter_listener, _parameter_listener_arg, &event) != noErr) {
2972  return -1;
2973  }
2974 
2975  event.mEventType = kAudioUnitEvent_EndParameterChangeGesture;
2976  event.mArgument.mParameter.mAudioUnit = unit->AU();
2977  event.mArgument.mParameter.mParameterID = descriptors[param_id].id;
2978  event.mArgument.mParameter.mScope = descriptors[param_id].scope;
2979  event.mArgument.mParameter.mElement = descriptors[param_id].element;
2980 
2981  if (AUEventListenerRemoveEventType (_parameter_listener, _parameter_listener_arg, &event) != noErr) {
2982  return -1;
2983  }
2984 
2985  return 0;
2986 }
2987 
2988 void
2989 AUPlugin::_parameter_change_listener (void* arg, void* src, const AudioUnitEvent* event, UInt64 host_time, Float32 new_value)
2990 {
2991  ((AUPlugin*) arg)->parameter_change_listener (arg, src, event, host_time, new_value);
2992 }
2993 
2994 void
2995 AUPlugin::parameter_change_listener (void* /*arg*/, void* /*src*/, const AudioUnitEvent* event, UInt64 /*host_time*/, Float32 new_value)
2996 {
2997  ParameterMap::iterator i;
2998 
2999  if ((i = parameter_map.find (event->mArgument.mParameter.mParameterID)) == parameter_map.end()) {
3000  return;
3001  }
3002 
3003  switch (event->mEventType) {
3004  case kAudioUnitEvent_BeginParameterChangeGesture:
3005  StartTouch (i->second);
3006  break;
3007  case kAudioUnitEvent_EndParameterChangeGesture:
3008  EndTouch (i->second);
3009  break;
3010  case kAudioUnitEvent_ParameterValueChange:
3011  ParameterChanged (i->second, new_value);
3012  break;
3013  default:
3014  break;
3015  }
3016 }
bool transport_rolling() const
Definition: session.h:592
#define AU_CACHE_VERSION
Definition: audio_unit.cc:2632
void add_state(XMLNode *) const
Definition: audio_unit.cc:1791
int set_output_format(AudioStreamBasicDescription &)
Definition: audio_unit.cc:1348
static std::string stringify_descriptor(const CAComponentDescription &)
Definition: audio_unit.cc:2827
bool parameter_is_input(uint32_t) const
Definition: audio_unit.cc:1772
bool load_preset(PresetRecord)
Definition: audio_unit.cc:1882
static void discover_music(PluginInfoList &)
Definition: audio_unit.cc:2306
int atoi(const string &s)
Definition: convert.cc:140
UserPresetMap user_preset_map
Definition: audio_unit.h:185
OSStatus get_transport_state_callback(Boolean *outIsPlaying, Boolean *outTransportStateChanged, Float64 *outCurrentSampleInTimeLine, Boolean *outIsCycling, Float64 *outCycleStartBeat, Float64 *outCycleEndBeat)
Definition: audio_unit.cc:1631
virtual int set_state(const XMLNode &, int version)
Definition: plugin.cc:369
float lower
Minimum value (in Hz, for frequencies)
MidiBuffer & get_midi(size_t i)
Definition: buffer_set.h:107
static bool au_preset_filter(const string &str, void *arg)
Definition: audio_unit.cc:2069
int set_state(const XMLNode &node, int)
Definition: audio_unit.cc:1828
int connect_and_run(BufferSet &bufs, ChanMapping in, ChanMapping out, pframes_t nframes, framecnt_t offset)
Definition: audio_unit.cc:1426
int create_parameter_listener(AUEventListenerProc callback, void *arg, float interval_secs)
Definition: audio_unit.cc:2886
Location * auto_loop_location() const
Definition: location.cc:1359
BufferSet * input_buffers
Definition: audio_unit.h:204
void bbt_time(framepos_t when, Timecode::BBT_Time &)
Definition: tempo.cc:1168
Boolean ComponentDescriptionsMatch_General(const ComponentDescription *inComponentDescription1, const ComponentDescription *inComponentDescription2, Boolean inIgnoreType)
Definition: audio_unit.cc:338
static void discover_generators(PluginInfoList &)
Definition: audio_unit.cc:2332
const std::string & value() const
Definition: xml++.h:159
uint32_t parameter_count() const
Definition: audio_unit.cc:853
const Meter & meter() const
Definition: tempo.h:196
double transport_speed() const
Definition: session.h:590
static unsigned int four_ints_to_four_byte_literal(unsigned char n[4])
Definition: audio_unit.cc:737
Boolean ComponentAndDescriptionMatch_General(Component inComponent, const ComponentDescription *inComponentDescription, Boolean inIgnoreType)
Definition: audio_unit.cc:361
bool write() const
Definition: xml++.cc:147
static OSStatus _get_beat_and_tempo_callback(void *userData, Float64 *outCurrentBeat, Float64 *outCurrentTempo)
Definition: audio_unit.cc:161
AUPluginInfo(boost::shared_ptr< CAComponentDescription >)
Definition: audio_unit.cc:2234
virtual void set_parameter(uint32_t which, float val)
Definition: plugin.cc:361
bool is_effect() const
Definition: audio_unit.cc:2852
std::vector< std::pair< int, int > > io_configs
Definition: audio_unit.h:224
static bool preset_search_path_initialized
Definition: audio_unit.cc:74
bool last_transport_rolling
Definition: audio_unit.h:214
bool is_channel_event() const
Definition: MIDIEvent.hpp:97
static std::string get_preset_name_in_plist(CFPropertyListRef plist)
Definition: audio_unit.cc:311
bool get_play_loop() const
Definition: session.h:342
shared_ptr< T > dynamic_pointer_cast(shared_ptr< U > const &r)
Definition: shared_ptr.hpp:396
const std::string & write_buffer() const
Definition: xml++.cc:198
ChanCount input_streams() const
Definition: audio_unit.cc:1065
std::string path
Definition: plugin.h:62
void discover_factory_presets()
Definition: audio_unit.cc:477
const std::string & name() const
Definition: xml++.h:104
PBD::Signal1< void, uint32_t > EndTouch
Definition: plugin.h:270
uint32_t nth_parameter(uint32_t which, bool &ok) const
Definition: audio_unit.cc:928
static std::string maybe_fix_broken_au_id(const std::string &)
Definition: audio_unit.cc:746
TempoMap & tempo_map()
Definition: session.h:596
int32_t input_channels
Definition: audio_unit.h:166
bool check_and_get_preset_name(Component component, const string &pathstr, string &preset_name)
Definition: audio_unit.cc:2108
bool _requires_fixed_size_buffers
Definition: audio_unit.h:171
uint32_t pframes_t
Definition: types.h:61
uint32_t n_audio() const
Definition: chan_count.h:63
int32_t output_channels
Definition: audio_unit.h:167
AUEventListenerRef _parameter_listener
Definition: audio_unit.h:208
XMLNode * add_child_copy(const XMLNode &)
Definition: xml++.cc:363
std::string current_preset() const
Definition: audio_unit.cc:2156
uint32_t input_maxbuf
Definition: audio_unit.h:201
framepos_t end() const
Definition: location.h:72
bool is_effect_without_midi_input() const
Definition: audio_unit.cc:2858
Definition: Beats.hpp:239
PluginInfoPtr _info
Definition: plugin.h:287
LIBPBD_API Transmitter error
LIBPBD_API Transmitter warning
const XMLNodeList & children(const std::string &str=std::string()) const
Definition: xml++.cc:329
void * _parameter_listener_arg
Definition: audio_unit.h:209
int set_stream_format(int scope, uint32_t cnt, AudioStreamBasicDescription &)
Definition: audio_unit.cc:1366
std::map< std::string, AUPluginCachedInfo > CachedInfoMap
Definition: audio_unit.h:267
const char * name() const
Definition: audio_unit.h:69
const char * maker() const
Definition: audio_unit.h:70
std::ostream & endmsg(std::ostream &ostr)
Definition: transmitter.h:71
virtual ~AUPlugin()
Definition: audio_unit.cc:459
bool is_instrument() const
Definition: audio_unit.cc:2870
framecnt_t frame_rate() const
Definition: session.h:365
LIBPBD_API void strip_whitespace_edges(std::string &str)
PBD::Signal2< void, uint32_t, float > ParameterChanged
Definition: plugin.h:214
static bool au_get_crashlog(std::string &msg)
Definition: audio_unit.cc:2359
AudioBuffer & get_audio(size_t i)
Definition: buffer_set.h:100
bool read_buffer(const std::string &)
Definition: xml++.cc:125
int listen_to_parameter(uint32_t param_id)
Definition: audio_unit.cc:2905
#define kCurrentSavedStateVersion
Definition: xml++.h:55
boost::shared_ptr< CAComponentDescription > descriptor
Definition: audio_unit.h:252
OSStatus get_musical_time_location_callback(UInt32 *outDeltaSampleOffsetToNextBeat, Float32 *outTimeSig_Numerator, UInt32 *outTimeSig_Denominator, Float64 *outCurrentMeasureDownBeat)
Definition: audio_unit.cc:1575
uint32_t n_midi() const
Definition: chan_count.h:66
framecnt_t input_offset
Definition: audio_unit.h:202
float last_transport_speed
Definition: audio_unit.h:215
static void discover_fx(PluginInfoList &)
Definition: audio_unit.cc:2319
void do_remove_preset(std::string)
Definition: audio_unit.cc:1936
UInt32 output_elements
Definition: audio_unit.h:190
static int load_cached_info()
Definition: audio_unit.cc:2673
virtual int connect_and_run(BufferSet &bufs, ChanMapping in, ChanMapping out, pframes_t nframes, framecnt_t offset)
Definition: plugin.cc:259
static int save_property_list(CFPropertyListRef propertyList, Glib::ustring path)
Definition: audio_unit.cc:208
std::vector< AUParameterDescriptor > descriptors
Definition: audio_unit.h:207
std::list< XMLNode * > XMLNodeList
Definition: xml++.h:44
void print_parameter(uint32_t, char *, uint32_t len) const
Definition: audio_unit.cc:1746
Locations * locations()
Definition: session.h:382
double frames_per_beat(framecnt_t sr) const
Definition: tempo.h:55
bool has_editor() const
Definition: audio_unit.cc:2227
#define _(Text)
Definition: i18n.h:11
void discover_parameters()
Definition: audio_unit.cc:610
int set_input_format(AudioStreamBasicDescription &)
Definition: audio_unit.cc:1342
LIBARDOUR_API std::string user_config_directory(int version=-1)
ChanCount n_outputs
Definition: plugin.h:64
static Glib::ustring au_cache_path()
Definition: audio_unit.cc:2274
boost::shared_ptr< Plugin > PluginPtr
Definition: plugin.h:50
LIBARDOUR_API uint64_t PluginManager
Definition: plugin.h:85
#define PATH_MAX
Definition: lv2_plugin.h:34
bool parameter_is_output(uint32_t) const
Definition: audio_unit.cc:1781
#define X_(Text)
Definition: i18n.h:13
static string preset_suffix
Definition: audio_unit.cc:73
int64_t framecnt_t
Definition: types.h:76
std::string state_node_name() const
Definition: audio_unit.h:89
XMLProperty * property(const char *)
Definition: xml++.cc:413
float Sample
Definition: types.h:54
static OSStatus _get_transport_state_callback(void *userData, Boolean *outIsPlaying, Boolean *outTransportStateChanged, Float64 *outCurrentSampleInTimeLine, Boolean *outIsCycling, Float64 *outCycleStartBeat, Float64 *outCycleEndBeat)
Definition: audio_unit.cc:189
float upper
Maximum value (in Hz, for frequencies)
static void au_remove_crashlog(void)
Definition: audio_unit.cc:2384
OSStatus get_beat_and_tempo_callback(Float64 *outCurrentBeat, Float64 *outCurrentTempo)
Definition: audio_unit.cc:1538
bool is_effect_with_midi_input() const
Definition: audio_unit.cc:2864
XMLNode * set_root(XMLNode *n)
Definition: xml++.h:63
float get_parameter(uint32_t which) const
Definition: audio_unit.cc:906
AudioUnitParameterUnit au_unit
Definition: audio_unit.h:57
XMLNode * root() const
Definition: xml++.h:62
framepos_t transport_frame() const
Definition: session.h:551
Definition: amp.h:29
boost::shared_ptr< Route > master_out() const
Definition: session.h:718
boost::shared_ptr< CAComponent > comp
Definition: audio_unit.h:162
virtual const char * maker() const =0
std::map< std::string, PresetRecord > _presets
Definition: plugin.h:289
const PBD::ID & id() const
Definition: stateful.h:68
framecnt_t _last_nframes
Definition: audio_unit.h:170
UInt32 input_elements
Definition: audio_unit.h:191
static void set_preset_name_in_plist(CFPropertyListRef plist, string preset_name)
Definition: audio_unit.cc:295
bool parameter_is_control(uint32_t) const
Definition: audio_unit.cc:1758
PluginPtr load(Session &session)
Definition: audio_unit.cc:2246
Time time() const
Definition: Event.hpp:132
bool configure_io(ChanCount in, ChanCount out)
Definition: audio_unit.cc:1003
bool read()
Definition: xml++.h:71
ChanCount output_streams() const
Definition: audio_unit.cc:1084
#define DEBUG_TRACE(bits, str)
Definition: debug.h:55
static string preset_search_path
Definition: audio_unit.cc:72
static void add_cached_info(const std::string &, AUPluginCachedInfo &)
Definition: audio_unit.cc:2627
float default_value(uint32_t port)
Definition: audio_unit.cc:859
static void au_crashlog(std::string)
Definition: audio_unit.cc:2397
bool can_support_io_configuration(const ChanCount &in, ChanCount &out)
Definition: audio_unit.cc:1101
double note_divisor() const
Definition: tempo.h:71
Boolean ComponentDescriptionsMatch_Loose(const ComponentDescription *inComponentDescription1, const ComponentDescription *inComponentDescription2)
Definition: audio_unit.cc:389
static void au_unblacklist(std::string id)
Definition: audio_unit.cc:91
T * get() const
Definition: shared_ptr.hpp:268
static bool cached_io_configuration(const std::string &, UInt32, CAComponent &, AUPluginCachedInfo &, const std::string &name)
Definition: audio_unit.cc:2549
LIBARDOUR_API std::string user_cache_directory()
LIBPBD_API Transmitter info
pframes_t _current_block_size
Definition: audio_unit.h:169
static void save_cached_info()
Definition: audio_unit.cc:2635
PluginInfoPtr get_info() const
Definition: plugin.h:225
double beats_per_minute() const
Definition: tempo.h:53
int set_block_size(pframes_t nframes)
Definition: audio_unit.cc:976
static CFPropertyListRef load_property_list(Glib::ustring path)
Definition: audio_unit.cc:252
std::set< Evoral::Parameter > automatable() const
Definition: audio_unit.cc:1722
ChanCount n_inputs
Definition: plugin.h:63
boost::shared_ptr< CAComponent > get_comp() const
Definition: audio_unit.h:117
bool parameter_is_audio(uint32_t) const
Definition: audio_unit.cc:1752
XMLProperty * add_property(const char *name, const std::string &value)
std::string unique_id
Definition: plugin.h:67
int get_parameter_descriptor(uint32_t which, ParameterDescriptor &) const
Definition: audio_unit.cc:918
UInt32 global_elements
Definition: audio_unit.h:189
std::string do_save_preset(std::string name)
Definition: audio_unit.cc:1941
void parameter_change_listener(void *, void *, const AudioUnitEvent *event, UInt64 host_time, Float32 new_value)
Definition: audio_unit.cc:2995
ParameterMap parameter_map
Definition: audio_unit.h:200
const char * name
void add_child_nocopy(XMLNode &)
Definition: xml++.cc:357
AudioUnitElement element
Definition: audio_unit.h:55
uint32_t id() const
Definition: Parameter.hpp:49
static CachedInfoMap cached_info
Definition: audio_unit.h:268
framecnt_t frames_processed
Definition: audio_unit.h:205
pframes_t get_block_size() const
Definition: session.h:393
static void au_blacklist(std::string id)
Definition: audio_unit.cc:78
Boolean ComponentDescriptionsMatch(const ComponentDescription *inComponentDescription1, const ComponentDescription *inComponentDescription2)
Definition: audio_unit.cc:382
bool toggled
True iff parameter is boolean.
Boolean ComponentAndDescriptionMatch(Component inComponent, const ComponentDescription *inComponentDescription)
Definition: audio_unit.cc:396
OSStatus render_callback(AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
Definition: audio_unit.cc:1391
Definition: xml++.h:95
void set_info(PluginInfoPtr)
Definition: audio_unit.cc:2876
static FILE * _crashlog_fd
Definition: audio_unit.h:254
const ChanCount & count() const
Definition: buffer_set.h:87
void set(DataType t, uint32_t count)
Definition: chan_count.h:58
LIBARDOUR_API PBD::Signal1< void, std::string > BootMessage
Definition: globals.cc:135
ARDOUR::Session & _session
Definition: plugin.h:286
const Tempo & tempo() const
Definition: tempo.h:197
virtual const char * name() const =0
uint32_t type() const
Definition: Parameter.hpp:47
Definition: debug.h:30
static SInt32 GetDictionarySInt32Value(CFDictionaryRef inAUStateDictionary, CFStringRef inDictionaryKey, Boolean *outSuccess)
Definition: audio_unit.cc:1999
PBD::Signal1< void, uint32_t > StartTouch
Definition: plugin.h:269
const ChanCount & available() const
Definition: buffer_set.h:84
double divisions_per_bar() const
Definition: tempo.h:70
boost::shared_ptr< IO > input() const
Definition: route.h:89
std::string creator
Definition: plugin.h:61
AudioBufferList * buffers
Definition: audio_unit.h:172
LIBARDOUR_API uint64_t AudioUnits
Definition: debug.cc:54
AUPlugin(AudioEngine &engine, Session &session, boost::shared_ptr< CAComponent > comp)
Definition: audio_unit.cc:409
FactoryPresetMap factory_preset_map
Definition: audio_unit.h:187
framepos_t start() const
Definition: location.h:71
void set_parameter(uint32_t which, float val)
Definition: audio_unit.cc:875
LIBARDOUR_API PBD::Signal3< void, std::string, std::string, bool > PluginScanMessage
Definition: globals.cc:136
static void au_start_crashlog(void)
Definition: audio_unit.cc:2372
const char * label() const
Definition: audio_unit.cc:847
static bool is_blacklisted(std::string id)
Definition: audio_unit.cc:124
iterator begin()
Definition: midi_buffer.h:127
std::string unique_id() const
Definition: audio_unit.cc:841
const uint8_t * buffer() const
Definition: Event.hpp:135
boost::shared_ptr< CAAudioUnit > unit
Definition: audio_unit.h:163
static OSStatus _render_callback(void *userData, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
Definition: audio_unit.cc:147
static void discover_instruments(PluginInfoList &)
Definition: audio_unit.cc:2345
std::list< PluginInfoPtr > PluginInfoList
Definition: plugin.h:90
const Sample * data(framecnt_t offset=0) const
Definition: audio_buffer.h:187
Boolean ComponentAndDescriptionMatch_Loosely(Component inComponent, const ComponentDescription *inComponentDescription)
Definition: audio_unit.cc:403
void find_files_matching_filter(vector< string > &result, const Searchpath &paths, bool(*filter)(const string &, void *), void *arg, bool pass_fullpath, bool return_fullpath, bool recurse)
Definition: file_utils.cc:271
std::vector< std::pair< int, int > > io_configs
Definition: audio_unit.h:168
XMLNodeList::const_iterator XMLNodeConstIterator
Definition: xml++.h:49
static void get_names(CAComponentDescription &, std::string &name, std::string &maker)
Definition: audio_unit.cc:2773
framecnt_t signal_latency() const
Definition: audio_unit.cc:869
AudioUnitParameterID id
Definition: audio_unit.h:53
static OSStatus _get_musical_time_location_callback(void *userData, UInt32 *outDeltaSampleOffsetToNextBeat, Float32 *outTimeSig_Numerator, UInt32 *outTimeSig_Denominator, Float64 *outCurrentMeasureDownBeat)
Definition: audio_unit.cc:173
static OSStatus GetAUComponentDescriptionFromStateData(CFPropertyListRef inAUStateData, ComponentDescription *outComponentDescription)
Definition: audio_unit.cc:2027
bool requires_fixed_size_buffers() const
Definition: audio_unit.cc:969
virtual bool load_preset(PresetRecord)
Definition: plugin.cc:340
virtual void set_info(const PluginInfoPtr inf)
Definition: plugin.cc:414
ARDOUR::PluginType type
Definition: plugin.h:65
framecnt_t cb_offset
Definition: audio_unit.h:203
std::string name
Definition: plugin.h:59
AudioEngine & engine()
Definition: session.h:546
static PluginInfoList * discover()
Definition: audio_unit.cc:2280
static void _parameter_change_listener(void *, void *, const AudioUnitEvent *event, UInt64 host_time, Float32 new_value)
Definition: audio_unit.cc:2989
std::string string_compose(const std::string &fmt, const T1 &o1)
Definition: compose.h:208
int end_listen_to_parameter(uint32_t param_id)
Definition: audio_unit.cc:2947
static void discover_by_description(PluginInfoList &, CAComponentDescription &)
Definition: audio_unit.cc:2408
std::string describe_parameter(Evoral::Parameter)
Definition: audio_unit.cc:1736