Audacity 3.2.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
AudioUnitEffectBase Class Reference

An Effect class that handles a wide range of effects. ??Mac only?? More...

#include <AudioUnitEffectBase.h>

Inheritance diagram for AudioUnitEffectBase:
[legend]
Collaboration diagram for AudioUnitEffectBase:
[legend]

Public Types

using Parameters = PackedArray::Ptr< const AudioUnitParameterID >
 
- Public Types inherited from EffectPlugin
using EffectSettingsAccessPtr = std::shared_ptr< EffectSettingsAccess >
 
using InstancePointer = std::shared_ptr< EffectInstanceEx >
 
using InstanceFinder = std::function< std::optional< InstancePointer >(EffectSettings &settings) >
 
- Public Types inherited from EffectDefinitionInterface
enum class  RealtimeSince : unsigned { Never , After_3_1 , Always }
 In which versions of Audacity was an effect realtime capable? More...
 
- Public Types inherited from AudioUnitWrapper
using Parameters = PackedArray::Ptr< const AudioUnitParameterID >
 
using ParameterVisitor = std::function< bool(const ParameterInfo &pi, AudioUnitParameterID ID) >
 Return value: if true, continue visiting. More...
 

Public Member Functions

 AudioUnitEffectBase (const PluginPath &path, const wxString &name, AudioComponent component, Parameters *pParameters=nullptr, AudioUnitEffectBase *master=nullptr)
 
 ~AudioUnitEffectBase () override
 
PluginPath GetPath () const override
 
ComponentInterfaceSymbol GetSymbol () const override
 
VendorSymbol GetVendor () const override
 
wxString GetVersion () const override
 
TranslatableString GetDescription () const override
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
EffectFamilySymbol GetFamily () const override
 Report identifier and user-visible name of the effect protocol. More...
 
bool IsInteractive () const override
 Whether the effect needs a dialog for entry of settings. More...
 
bool IsDefault () const override
 Whether the effect sorts "above the line" in the menus. More...
 
RealtimeSince RealtimeSupport () const override
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsAutomation () const override
 Whether the effect has any automatable controls. More...
 
EffectSettings MakeSettings () const override
 
bool CopySettingsContents (const EffectSettings &src, EffectSettings &dst) const override
 Update one settings object from another. More...
 
bool SaveSettings (const EffectSettings &settings, CommandParameters &parms) const override
 Store settings as keys and values. More...
 
bool LoadSettings (const CommandParameters &parms, EffectSettings &settings) const override
 May allocate memory, so should be called only in the main thread. More...
 
OptionalMessage LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 
bool SaveUserPreset (const RegistryPath &name, const EffectSettings &settings) const override
 Save settings in the configuration file as a user-named preset. More...
 
RegistryPaths GetFactoryPresets () const override
 Report names of factory presets. More...
 
OptionalMessage LoadFactoryPreset (int id, EffectSettings &settings) const override
 
bool InitializePlugin ()
 
std::shared_ptr< EffectInstanceMakeInstance () const override
 Make an object maintaining short-term state of an Effect. More...
 
bool CanExportPresets () const override
 Whether the effect supports export of presets to files, and importing too. More...
 
bool HasOptions () const override
 
TranslatableString Export (const AudioUnitEffectSettings &settings, const wxString &path) const
 
TranslatableString Import (AudioUnitEffectSettings &settings, const wxString &path) const
 
TranslatableString SaveBlobToConfig (const RegistryPath &group, const wxString &path, const void *blob, size_t len, bool allowEmpty=true) const
 
void GetChannelCounts ()
 
bool MigrateOldConfigFile (const RegistryPath &group, EffectSettings &settings) const
 
OptionalMessage LoadPreset (const RegistryPath &group, EffectSettings &settings) const
 
bool SavePreset (const RegistryPath &group, const AudioUnitEffectSettings &settings) const
 
- Public Member Functions inherited from PerTrackEffect
 ~PerTrackEffect () override
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
PluginPath GetPath () const override
 
bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings) override
 
bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const override
 
ComponentInterfaceSymbol GetSymbol () const override
 
VendorSymbol GetVendor () const override
 
wxString GetVersion () const override
 
TranslatableString GetDescription () const override
 
EffectFamilySymbol GetFamily () const override
 Report identifier and user-visible name of the effect protocol. More...
 
bool IsInteractive () const override
 Whether the effect needs a dialog for entry of settings. More...
 
bool IsDefault () const override
 Whether the effect sorts "above the line" in the menus. More...
 
RealtimeSince RealtimeSupport () const override
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsAutomation () const override
 Whether the effect has any automatable controls. More...
 
bool SaveSettings (const EffectSettings &settings, CommandParameters &parms) const override
 Store settings as keys and values. More...
 
bool LoadSettings (const CommandParameters &parms, EffectSettings &settings) const override
 Restore settings from keys and values. More...
 
OptionalMessage LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 
bool SaveUserPreset (const RegistryPath &name, const EffectSettings &settings) const override
 Save settings in the configuration file as a user-named preset. More...
 
RegistryPaths GetFactoryPresets () const override
 Report names of factory presets. More...
 
OptionalMessage LoadFactoryPreset (int id, EffectSettings &settings) const override
 
OptionalMessage LoadFactoryDefaults (EffectSettings &settings) const override
 
virtual const EffectParameterMethodsParameters () const
 
bool CanExportPresets () const override
 Whether the effect supports export of presets to files, and importing too. More...
 
bool HasOptions () const override
 
const EffectSettingsManagerGetDefinition () const override
 
virtual NumericFormatID GetSelectionFormat ()
 
bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const override
 
OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const override
 
bool IsBatchProcessing () const override
 
void SetBatchProcessing () override
 
void UnsetBatchProcessing () override
 
unsigned TestUIFlags (unsigned mask)
 
bool Delegate (Effect &delegate, EffectSettings &settings, InstanceFinder finder={})
 Re-invoke DoEffect on another Effect object that implements the work. More...
 
- Public Member Functions inherited from EffectBase
 EffectBase ()
 
 ~EffectBase () override
 
bool IsLinearEffect () const
 
bool PreviewsFullSelection () const
 
void SetTracks (TrackList *pTracks)
 
double GetDefaultDuration ()
 
virtual std::any BeginPreview (const EffectSettings &settings)
 Called when Preview() starts, to allow temporary effect state changes. More...
 
bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess) override
 
virtual double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const =0
 
void CountWaveTracks ()
 
- Public Member Functions inherited from EffectPlugin
EffectPluginoperator= (EffectPlugin &)=delete
 
virtual ~EffectPlugin ()
 
virtual bool HasOptions () const =0
 
virtual bool CanExportPresets () const =0
 Whether the effect supports export of presets to files, and importing too. More...
 
virtual const EffectSettingsManagerGetDefinition () const =0
 
virtual bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const =0
 
virtual OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const =0
 
virtual bool IsBatchProcessing () const =0
 
virtual void SetBatchProcessing ()=0
 
virtual void UnsetBatchProcessing ()=0
 
virtual bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess=nullptr)=0
 
- Public Member Functions inherited from EffectInstanceFactory
virtual ~EffectInstanceFactory ()
 
virtual std::shared_ptr< EffectInstanceMakeInstance () const =0
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from EffectSettingsManager
virtual ~EffectSettingsManager ()
 
virtual bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings)
 
virtual bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const
 
virtual std::unique_ptr< EffectOutputsMakeOutputs () const
 Produce an object to hold values to send to effect output meters. More...
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetType () const =0
 Type determines how it behaves. More...
 
virtual EffectType GetClassification () const
 Determines which menu it appears in; default same as GetType(). More...
 
virtual EffectFamilySymbol GetFamily () const =0
 Report identifier and user-visible name of the effect protocol. More...
 
virtual bool IsInteractive () const =0
 Whether the effect needs a dialog for entry of settings. More...
 
virtual bool IsDefault () const =0
 Whether the effect sorts "above the line" in the menus. More...
 
virtual RealtimeSince RealtimeSupport () const =0
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsRealtime () const
 
virtual bool SupportsAutomation () const =0
 Whether the effect has any automatable controls. More...
 
virtual bool EnablesDebug () const
 Whether the effect dialog should have a Debug button; default, always false. More...
 
virtual ManualPageID ManualPage () const
 Name of a page in the Audacity alpha manual, default is empty. More...
 
virtual FilePath HelpPage () const
 Fully qualified local help file name, default is empty. More...
 
virtual bool IsHiddenFromMenus () const
 Default is false. More...
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
virtual PluginPath GetPath () const =0
 
virtual ComponentInterfaceSymbol GetSymbol () const =0
 
virtual VendorSymbol GetVendor () const =0
 
virtual wxString GetVersion () const =0
 
virtual TranslatableString GetDescription () const =0
 
TranslatableString GetName () const
 
- Public Member Functions inherited from AudioUnitWrapper
 AudioUnitWrapper (AudioComponent component, Parameters *pParameters)
 
template<typename T >
OSStatus GetFixedSizeProperty (AudioUnitPropertyID inID, T &property, AudioUnitScope inScope=kAudioUnitScope_Global, AudioUnitElement inElement=0) const
 
template<typename T >
OSStatus GetVariableSizeProperty (AudioUnitPropertyID inID, PackedArray::Ptr< T > &pObject, AudioUnitScope inScope=kAudioUnitScope_Global, AudioUnitElement inElement=0) const
 
template<typename T >
OSStatus SetProperty (AudioUnitPropertyID inID, const T &property, AudioUnitScope inScope=kAudioUnitScope_Global, AudioUnitElement inElement=0) const
 
void ForEachParameter (ParameterVisitor visitor) const
 
bool LoadPreset (const EffectDefinitionInterface &effect, const RegistryPath &group, EffectSettings &settings) const
 
bool LoadFactoryPreset (const EffectDefinitionInterface &effect, int id, EffectSettings *pSettings) const
 
std::pair< CF_ptr< CFDataRef >, TranslatableStringMakeBlob (const EffectDefinitionInterface &effect, const AudioUnitEffectSettings &settings, const wxCFStringRef &cfname, bool binary) const
 Obtain dump of the setting state of an AudioUnit instance. More...
 
TranslatableString InterpretBlob (AudioUnitEffectSettings &settings, const wxString &group, const wxMemoryBuffer &buf) const
 Interpret the dump made before by MakeBlob. More...
 
bool FetchSettings (AudioUnitEffectSettings &settings, bool fetchValues, bool fetchPreset=false) const
 May allocate memory, so should be called only in the main thread. More...
 
bool StoreSettings (const EffectDefinitionInterface &effect, const AudioUnitEffectSettings &settings) const
 
bool CreateAudioUnit ()
 
AudioUnit GetAudioUnit () const
 
AudioComponent GetComponent () const
 
const ParametersGetParameters () const
 
bool SetRateAndChannels (double sampleRate, const wxString &identifier)
 

Static Public Member Functions

static RegistryPath ChoosePresetKey (const EffectSettings &settings)
 
static RegistryPath FindPresetKey (const CommandParameters &parms)
 
- Static Public Member Functions inherited from Effect
static EffectFetchParameters (Effect &e, EffectSettings &)
 
- Static Public Member Functions inherited from EffectBase
static std::optional< InstancePointerFindInstance (EffectPlugin &plugin)
 
static InstanceFinder DefaultInstanceFinder (EffectPlugin &plugin)
 
- Static Public Member Functions inherited from EffectDefinitionInterface
static Identifier GetSquashedName (const Identifier &ident)
 A utility that strips spaces and CamelCases a name. More...
 
- Static Public Member Functions inherited from AudioUnitWrapper
static AudioUnitEffectSettingsGetSettings (EffectSettings &settings)
 
static const AudioUnitEffectSettingsGetSettings (const EffectSettings &settings)
 
static bool MoveSettingsContents (AudioUnitEffectSettings &&src, AudioUnitEffectSettings &dst, bool merge)
 Copy, then clear the optionals in src. More...
 

Protected Attributes

const PluginPath mPath
 
const wxString mName
 
const wxString mVendor
 
bool mInteractive { false }
 
- Protected Attributes inherited from PerTrackEffect
sampleCount mSampleCnt {}
 
- Protected Attributes inherited from EffectBase
double mF0 {}
 
double mF1 {}
 
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 
- Protected Attributes inherited from AudioUnitWrapper
const AudioComponent mComponent
 
AudioUnitCleanup< AudioUnit, AudioComponentInstanceDispose > mUnit
 
Parameters mOwnParameters
 
ParametersmParameters
 
unsigned mAudioIns { 2 }
 
unsigned mAudioOuts { 2 }
 

Additional Inherited Members

- Public Attributes inherited from EffectBase
std::shared_ptr< TrackListmTracks {}
 
int mNumTracks {}
 
BasicUI::ProgressDialogmProgress {}
 
double mProjectRate {}
 
WaveTrackFactorymFactory {}
 
double mT0 {}
 
double mT1 {}
 
bool mIsPreview { false }
 
- Static Public Attributes inherited from EffectPlugin
static const wxString kUserPresetIdent = wxT("User Preset:")
 
static const wxString kFactoryPresetIdent = wxT("Factory Preset:")
 
static const wxString kCurrentSettingsIdent = wxT("<Current Settings>")
 
static const wxString kFactoryDefaultsIdent = wxT("<Factory Defaults>")
 
- Protected Member Functions inherited from PerTrackEffect
bool DoPass1 () const
 
bool DoPass2 () const
 
bool Process (EffectInstance &instance, EffectSettings &settings) const
 
std::shared_ptr< EffectOutputTracksMakeOutputTracks ()
 
void DestroyOutputTracks () const
 
- Protected Member Functions inherited from Effect
bool CheckWhetherSkipEffect (const EffectSettings &settings) const override
 Default implementation returns false. More...
 
double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const override
 Default implementation returns previewLength More...
 
bool TotalProgress (double frac, const TranslatableString &={}) const
 
bool TrackProgress (int whichTrack, double frac, const TranslatableString &={}) const
 
bool TrackGroupProgress (int whichGroup, double frac, const TranslatableString &={}) const
 
int GetNumWaveTracks () const
 
int GetNumWaveGroups () const
 
void GetBounds (const WaveTrack &track, sampleCount *start, sampleCount *len)
 
- Protected Member Functions inherited from EffectBase
virtual bool CheckWhetherSkipEffect (const EffectSettings &settings) const =0
 After Init(), tell whether Process() should be skipped. More...
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing () const
 
const TrackListinputTracks () const
 
const AudacityProjectFindProject () const
 

Detailed Description

An Effect class that handles a wide range of effects. ??Mac only??

Definition at line 28 of file AudioUnitEffectBase.h.

Member Typedef Documentation

◆ Parameters

using AudioUnitEffectBase::Parameters = PackedArray::Ptr<const AudioUnitParameterID>

Definition at line 33 of file AudioUnitEffectBase.h.

Constructor & Destructor Documentation

◆ AudioUnitEffectBase()

AudioUnitEffectBase::AudioUnitEffectBase ( const PluginPath path,
const wxString &  name,
AudioComponent  component,
Parameters pParameters = nullptr,
AudioUnitEffectBase master = nullptr 
)

Definition at line 70 of file AudioUnitEffectBase.cpp.

73 : AudioUnitWrapper{ component, pParameters }
74 , mPath{ path }
75 , mName{ name.AfterFirst(wxT(':')).Trim(true).Trim(false) }
76 , mVendor{ name.BeforeFirst(wxT(':')).Trim(true).Trim(false) }
77{
78}
wxT("CloseDown"))
wxString name
Definition: TagsEditor.cpp:166
const PluginPath mPath
Manages and interacts with an AudioUnit, providing operations on audio effects.

◆ ~AudioUnitEffectBase()

AudioUnitEffectBase::~AudioUnitEffectBase ( )
overridedefault

Member Function Documentation

◆ CanExportPresets()

bool AudioUnitEffectBase::CanExportPresets ( ) const
overridevirtual

Whether the effect supports export of presets to files, and importing too.

Implements EffectPlugin.

Definition at line 373 of file AudioUnitEffectBase.cpp.

374{
375 return true;
376}

◆ ChoosePresetKey()

RegistryPath AudioUnitEffectBase::ChoosePresetKey ( const EffectSettings settings)
static

Definition at line 258 of file AudioUnitEffectBase.cpp.

260{
261 // Find a key to use for the preset that does not collide with any
262 // parameter name
263 wxString result = PresetStr;
264
265 // That string probably works but be sure
266 const auto &map = GetSettings(settings).values;
267 using Pair = decltype(*map.begin());
268 while (std::any_of(map.begin(), map.end(), [&](Pair &pair){
269 return pair.second && pair.second->first == result;
270 }))
271 result += "_";
272
273 return result;
274}
constexpr auto PresetStr
static Settings & settings()
Definition: TrackInfo.cpp:51
std::pair< const char *, const char * > Pair
static AudioUnitEffectSettings & GetSettings(EffectSettings &settings)

References AudioUnitWrapper::GetSettings(), PresetStr, settings(), and AudioUnitEffectSettings::values.

Referenced by SaveSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CopySettingsContents()

bool AudioUnitEffectBase::CopySettingsContents ( const EffectSettings src,
EffectSettings dst 
) const
overridevirtual

Update one settings object from another.

This may run in a worker thread, and should avoid memory allocations. Therefore do not copy the underlying std::any, but copy the contents of the contained objects.

Assume that src and dst were created and previously modified only by this

Default implementation does nothing and returns true

Parameters
srcsettings to copy from
dstsettings to copy into
copyDirectiondirection in which copy is performed
Returns
success

Reimplemented from EffectSettingsManager.

Definition at line 249 of file AudioUnitEffectBase.cpp.

251{
252 // Not needed -- rely on EffectInstance::Message instead
253 return true;
254}

◆ Export()

TranslatableString AudioUnitEffectBase::Export ( const AudioUnitEffectSettings settings,
const wxString &  path 
) const

Definition at line 436 of file AudioUnitEffectBase.cpp.

438{
439 // Create the file
440 wxFFile f(path, wxT("wb"));
441 if (!f.IsOpened())
442 return XO("Couldn't open \"%s\"").Format(path);
443
444 // First set the name of the preset
445 wxCFStringRef cfname(wxFileName(path).GetName());
446
447 const auto &[data, message] = MakeBlob(*this, settings, cfname, false);
448 if (!data || !message.empty())
449 return message;
450
451 // Write XML data
452 auto length = CFDataGetLength(data.get());
453 if (f.Write(CFDataGetBytePtr(data.get()), length) != length || f.Error())
454 return XO("Failed to write XML preset to \"%s\"").Format(path);
455
456 f.Close();
457 return {};
458}
XO("Cut/Copy/Paste")
TranslatableString GetName() const
std::pair< CF_ptr< CFDataRef >, TranslatableString > MakeBlob(const EffectDefinitionInterface &effect, const AudioUnitEffectSettings &settings, const wxCFStringRef &cfname, bool binary) const
Obtain dump of the setting state of an AudioUnit instance.

References ComponentInterface::GetName(), AudioUnitWrapper::MakeBlob(), settings(), wxT(), and XO().

Referenced by AudioUnitEffect::ExportPresets().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindPresetKey()

RegistryPath AudioUnitEffectBase::FindPresetKey ( const CommandParameters parms)
static

Definition at line 276 of file AudioUnitEffectBase.cpp.

277{
278 RegistryPath result;
279 auto len = strlen(PresetStr);
280 if (auto [index, key] = std::tuple(0L, wxString{})
281 ; parms.GetFirstEntry(key, index)
282 ) do {
283 if (key.StartsWith(PresetStr)
284 && key.Mid(len).find_first_not_of("_") == wxString::npos
285 && key.length() > result.length())
286 result = key;
287 } while(parms.GetNextEntry(key, index));
288 return result;
289}
wxString RegistryPath
Definition: Identifier.h:218
static const AudacityProject::AttachedObjects::RegisteredFactory key
constexpr size_t npos(-1)

References key, Tuple::detail::npos(), and PresetStr.

Referenced by LoadSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetChannelCounts()

void AudioUnitEffectBase::GetChannelCounts ( )

Definition at line 482 of file AudioUnitEffectBase.cpp.

483{
484 // Does AU have channel info
486 if (GetVariableSizeProperty(kAudioUnitProperty_SupportedNumChannels, info)) {
487 // None supplied. Apparently all FX type units can do any number of INs
488 // and OUTs as long as they are the same number. In this case, we'll
489 // just say stereo.
490 //
491 // We should probably check to make sure we're dealing with an FX type.
492 mAudioIns = 2;
493 mAudioOuts = 2;
494 return;
495 }
496
497 // This is where it gets weird...not sure what is the best
498 // way to do this really. If we knew how many ins/outs we
499 // really needed, we could make a better choice.
500
501 bool haven2m = false; // nothing -> mono
502 bool haven2s = false; // nothing -> stereo
503 bool havem2n = false; // mono -> nothing
504 bool haves2n = false; // stereo -> nothing
505 bool havem2m = false; // mono -> mono
506 bool haves2s = false; // stereo -> stereo
507 bool havem2s = false; // mono -> stereo
508 bool haves2m = false; // stereo -> mono
509
510 mAudioIns = 2;
511 mAudioOuts = 2;
512
513 // Look only for exact channel constraints
514 for (auto &ci : info) {
515 int ic = ci.inChannels;
516 int oc = ci.outChannels;
517
518 if (ic < 0 && oc >= 0)
519 ic = 2;
520 else if (ic >= 0 && oc < 0)
521 oc = 2;
522 else if (ic < 0 && oc < 0) {
523 ic = 2;
524 oc = 2;
525 }
526
527 if (ic == 2 && oc == 2)
528 haves2s = true;
529 else if (ic == 1 && oc == 1)
530 havem2m = true;
531 else if (ic == 1 && oc == 2)
532 havem2s = true;
533 else if (ic == 2 && oc == 1)
534 haves2m = true;
535 else if (ic == 0 && oc == 2)
536 haven2s = true;
537 else if (ic == 0 && oc == 1)
538 haven2m = true;
539 else if (ic == 1 && oc == 0)
540 havem2n = true;
541 else if (ic == 2 && oc == 0)
542 haves2n = true;
543 }
544
545 if (haves2s) {
546 mAudioIns = 2;
547 mAudioOuts = 2;
548 }
549 else if (havem2m) {
550 mAudioIns = 1;
551 mAudioOuts = 1;
552 }
553 else if (havem2s) {
554 mAudioIns = 1;
555 mAudioOuts = 2;
556 }
557 else if (haves2m) {
558 mAudioIns = 2;
559 mAudioOuts = 1;
560 }
561 else if (haven2m) {
562 mAudioIns = 0;
563 mAudioOuts = 1;
564 }
565 else if (haven2s) {
566 mAudioIns = 0;
567 mAudioOuts = 2;
568 }
569 else if (haves2n) {
570 mAudioIns = 2;
571 mAudioOuts = 0;
572 }
573 else if (havem2n) {
574 mAudioIns = 1;
575 mAudioOuts = 0;
576 }
577
578 return;
579}
OSStatus GetVariableSizeProperty(AudioUnitPropertyID inID, PackedArray::Ptr< T > &pObject, AudioUnitScope inScope=kAudioUnitScope_Global, AudioUnitElement inElement=0) const
Smart pointer type that deallocates with Deleter.
Definition: PackedArray.h:130

References AudioUnitWrapper::GetVariableSizeProperty(), AudioUnitWrapper::mAudioIns, and AudioUnitWrapper::mAudioOuts.

Referenced by InitializePlugin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDescription()

TranslatableString AudioUnitEffectBase::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 113 of file AudioUnitEffectBase.cpp.

114{
115 /* i18n-hint: Can mean "not available," "not applicable," "no answer" */
116 return XO("n/a");
117}

References XO().

Here is the call graph for this function:

◆ GetFactoryPresets()

RegistryPaths AudioUnitEffectBase::GetFactoryPresets ( ) const
overridevirtual

Report names of factory presets.

Implements EffectSettingsManager.

Definition at line 359 of file AudioUnitEffectBase.cpp.

360{
361 RegistryPaths presets;
362
363 // Retrieve the list of factory presets
364 CF_ptr<CFArrayRef> array;
365 if (!GetFixedSizeProperty(kAudioUnitProperty_FactoryPresets, array))
366 for (CFIndex i = 0, cnt = CFArrayGetCount(array.get()); i < cnt; ++i)
367 presets.push_back(wxCFStringRef::AsString(
368 static_cast<const AUPreset*>(CFArrayGetValueAtIndex(array.get(), i))
369 ->presetName));
370 return presets;
371}
std::vector< RegistryPath > RegistryPaths
Definition: Identifier.h:219
OSStatus GetFixedSizeProperty(AudioUnitPropertyID inID, T &property, AudioUnitScope inScope=kAudioUnitScope_Global, AudioUnitElement inElement=0) const

References AudioUnitWrapper::GetFixedSizeProperty().

Here is the call graph for this function:

◆ GetFamily()

EffectFamilySymbol AudioUnitEffectBase::GetFamily ( ) const
overridevirtual

Report identifier and user-visible name of the effect protocol.

Implements EffectDefinitionInterface.

Definition at line 143 of file AudioUnitEffectBase.cpp.

144{
146}
#define AUDIOUNITEFFECTS_FAMILY

References AUDIOUNITEFFECTS_FAMILY.

◆ GetPath()

PluginPath AudioUnitEffectBase::GetPath ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 86 of file AudioUnitEffectBase.cpp.

87{
88 return mPath;
89}

References mPath.

◆ GetSymbol()

ComponentInterfaceSymbol AudioUnitEffectBase::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 91 of file AudioUnitEffectBase.cpp.

92{
93 return mName;
94}

References mName.

Referenced by InitializePlugin(), and MakeInstance().

Here is the caller graph for this function:

◆ GetType()

EffectType AudioUnitEffectBase::GetType ( ) const
overridevirtual

Type determines how it behaves.

Implements EffectDefinitionInterface.

Definition at line 123 of file AudioUnitEffectBase.cpp.

124{
125 if (mAudioIns == 0 && mAudioOuts == 0)
126 {
127 return EffectTypeNone;
128 }
129
130 if (mAudioIns == 0)
131 {
132 return EffectTypeGenerate;
133 }
134
135 if (mAudioOuts == 0)
136 {
137 return EffectTypeAnalyze;
138 }
139
140 return EffectTypeProcess;
141}
@ EffectTypeAnalyze
@ EffectTypeGenerate
@ EffectTypeNone
@ EffectTypeProcess

References EffectTypeAnalyze, EffectTypeGenerate, EffectTypeNone, EffectTypeProcess, AudioUnitWrapper::mAudioIns, and AudioUnitWrapper::mAudioOuts.

Referenced by RealtimeSupport(), and AudioUnitEffect::ShowClientInterface().

Here is the caller graph for this function:

◆ GetVendor()

VendorSymbol AudioUnitEffectBase::GetVendor ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 96 of file AudioUnitEffectBase.cpp.

97{
98 return { mVendor };
99}

References mVendor.

◆ GetVersion()

wxString AudioUnitEffectBase::GetVersion ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 101 of file AudioUnitEffectBase.cpp.

102{
103 UInt32 version;
104
105 OSStatus result = AudioComponentGetVersion(mComponent, &version);
106
107 return wxString::Format(wxT("%d.%d.%d"),
108 (version >> 16) & 0xffff,
109 (version >> 8) & 0xff,
110 version & 0xff);
111}
const AudioComponent mComponent

References AudioUnitWrapper::mComponent, and wxT().

Here is the call graph for this function:

◆ HasOptions()

bool AudioUnitEffectBase::HasOptions ( ) const
overridevirtual

Whether there are preferences applying to the effect's family, for which a UI may be needed to change them

Implements EffectPlugin.

Definition at line 378 of file AudioUnitEffectBase.cpp.

379{
380 return true;
381}

◆ Import()

TranslatableString AudioUnitEffectBase::Import ( AudioUnitEffectSettings settings,
const wxString &  path 
) const

Definition at line 460 of file AudioUnitEffectBase.cpp.

462{
463 // Open the preset
464 wxFFile f(path, wxT("r"));
465 if (!f.IsOpened())
466 return XO("Couldn't open \"%s\"").Format(path);
467
468 // Load it into the buffer
469 size_t len = f.Length();
470 wxMemoryBuffer buf(len);
471 if (f.Read(buf.GetData(), len) != len || f.Error())
472 return XO("Unable to read the preset from \"%s\"").Format(path);
473 buf.SetDataLen(len);
474
475 const auto error = InterpretBlob(settings, path, buf);
476 if (!error.empty())
477 return error;
478
479 return {};
480}
TranslatableString InterpretBlob(AudioUnitEffectSettings &settings, const wxString &group, const wxMemoryBuffer &buf) const
Interpret the dump made before by MakeBlob.

References AudioUnitWrapper::InterpretBlob(), settings(), wxT(), and XO().

Referenced by AudioUnitEffect::ImportPresets().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializePlugin()

bool AudioUnitEffectBase::InitializePlugin ( )

Definition at line 188 of file AudioUnitEffectBase.cpp.

189{
190 // To implement the services of EffectPlugin -- such as, a query of the
191 // set of effect parameters, so that we can implement MakeSettings -- we
192 // also need what is called an AudioComponentInstance, also called an
193 // AudioUnit.
194 // It's not just for implementing EffectInstance. AudioUnits is unlike other
195 // third party effect families that distinguish the notions of plug-in and
196 // instance.
197
199
200 if (!CreateAudioUnit())
201 return false;
202
203 // Use an arbitrary rate while completing the discovery of channel support
204 if (!SetRateAndChannels(44100.0, GetSymbol().Internal()))
205 return false;
206
207 // Determine interactivity
209 if (!mInteractive) {
210 // Check for a Cocoa UI
211 // This could retrieve a variable-size property, but we only look at
212 // the first element.
213 AudioUnitCocoaViewInfo cocoaViewInfo;
215 !GetFixedSizeProperty(kAudioUnitProperty_CocoaUI, cocoaViewInfo);
216 if (!mInteractive) {
217 // Check for a Carbon UI
218 // This could retrieve a variable sized array but we only need the
219 // first
220 AudioComponentDescription compDesc;
222 kAudioUnitProperty_GetUIComponentList, compDesc);
223 }
224 }
225
226 return true;
227}
@ Internal
Indicates internal failure from Audacity.
ComponentInterfaceSymbol GetSymbol() const override
size_t Count(const Ptr< Type, BaseDeleter > &p)
Find out how many elements were allocated with a Ptr.
Definition: PackedArray.h:143
Parameters & mParameters
bool SetRateAndChannels(double sampleRate, const wxString &identifier)

References PackedArray::Count(), AudioUnitWrapper::CreateAudioUnit(), GetChannelCounts(), AudioUnitWrapper::GetFixedSizeProperty(), GetSymbol(), Internal, mInteractive, AudioUnitWrapper::mParameters, and AudioUnitWrapper::SetRateAndChannels().

Referenced by AudioUnitEffectsModule::DiscoverPluginsAtPath().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsDefault()

bool AudioUnitEffectBase::IsDefault ( ) const
overridevirtual

Whether the effect sorts "above the line" in the menus.

Implements EffectDefinitionInterface.

Definition at line 153 of file AudioUnitEffectBase.cpp.

154{
155 return false;
156}

◆ IsInteractive()

bool AudioUnitEffectBase::IsInteractive ( ) const
overridevirtual

Whether the effect needs a dialog for entry of settings.

Implements EffectDefinitionInterface.

Definition at line 148 of file AudioUnitEffectBase.cpp.

149{
150 return mInteractive;
151}

References mInteractive.

◆ LoadFactoryPreset()

OptionalMessage AudioUnitEffectBase::LoadFactoryPreset ( int  id,
EffectSettings settings 
) const
overridevirtual

Change settings to the preset whose name is GetFactoryPresets()[id]

Returns
nullopt for failure

Implements EffectSettingsManager.

Definition at line 352 of file AudioUnitEffectBase.cpp.

353{
355 return { nullptr };
356 return {};
357}
bool LoadFactoryPreset(const EffectDefinitionInterface &effect, int id, EffectSettings *pSettings) const

References AudioUnitWrapper::LoadFactoryPreset(), and settings().

Here is the call graph for this function:

◆ LoadPreset()

OptionalMessage AudioUnitEffectBase::LoadPreset ( const RegistryPath group,
EffectSettings settings 
) const

Definition at line 407 of file AudioUnitEffectBase.cpp.

409{
410 if (MigrateOldConfigFile(group, settings))
411 return { nullptr };
412
413 if (AudioUnitWrapper::LoadPreset(*this, group, settings))
414 return { nullptr };
415 return {};
416}
bool MigrateOldConfigFile(const RegistryPath &group, EffectSettings &settings) const
bool LoadPreset(const EffectDefinitionInterface &effect, const RegistryPath &group, EffectSettings &settings) const

References AudioUnitWrapper::LoadPreset(), MigrateOldConfigFile(), and settings().

Referenced by LoadUserPreset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadSettings()

bool AudioUnitEffectBase::LoadSettings ( const CommandParameters parms,
EffectSettings settings 
) const
overridevirtual

May allocate memory, so should be called only in the main thread.

Implements EffectSettingsManager.

Definition at line 309 of file AudioUnitEffectBase.cpp.

311{
312 // First clean all settings, in case any are not defined in parms
313 auto &mySettings = GetSettings(settings);
314 mySettings.ResetValues();
315 auto &map = mySettings.values;
316
317 // Reload preset first
318 if (auto presetKey = FindPresetKey(parms); !presetKey.empty()) {
319 SInt32 value = 0;
320 if (parms.Read(presetKey, &value))
322 }
323
324 // Load settings from CommandParameters
325 // Iterate the config only, not using any AudioUnit handles
326 if (auto [index, key, value] = std::tuple(
327 0L, wxString{}, AudioUnitParameterValue{})
328 ; parms.GetFirstEntry(key, index)
329 ) do {
330 if (auto pKey = ParameterInfo::ParseKey(key)
331 ; pKey && parms.Read(key, &value)
332 )
333 map[*pKey].emplace(mySettings.Intern(key), value);
334 } while(parms.GetNextEntry(key, index));
335 return true;
336}
static RegistryPath FindPresetKey(const CommandParameters &parms)
static std::optional< AudioUnitParameterID > ParseKey(const wxString &key)
Recover the parameter ID from the key, if well formed.

References FindPresetKey(), AudioUnitWrapper::GetSettings(), key, AudioUnitWrapper::LoadFactoryPreset(), AudioUnitWrapper::ParameterInfo::ParseKey(), and settings().

Referenced by MigrateOldConfigFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadUserPreset()

OptionalMessage AudioUnitEffectBase::LoadUserPreset ( const RegistryPath name,
EffectSettings settings 
) const
overridevirtual

Change settings to a user-named preset

Returns
nullopt for failure

Implements EffectSettingsManager.

Definition at line 338 of file AudioUnitEffectBase.cpp.

340{
341 // To do: externalize state so const_cast isn't needed
342 return const_cast<AudioUnitEffectBase*>(this)->LoadPreset(name, settings);
343}
An Effect class that handles a wide range of effects. ??Mac only??
OptionalMessage LoadPreset(const RegistryPath &group, EffectSettings &settings) const

References LoadPreset(), name, and settings().

Here is the call graph for this function:

◆ MakeInstance()

std::shared_ptr< EffectInstance > AudioUnitEffectBase::MakeInstance ( ) const
overridevirtual

Make an object maintaining short-term state of an Effect.

One effect may have multiple instances extant simultaneously. Instances have state, may be implemented in foreign code, and are temporary, whereas EffectSettings represents persistent effect state that can be saved and reloaded from files.

Parameters
settingsmay be assumed to have a lifetime enclosing the instance's
Postcondition
true (no promises that the result isn't null)

Implements EffectInstanceFactory.

Definition at line 178 of file AudioUnitEffectBase.cpp.

179{
180 bool useLatency;
182 useLatency, true);
183
184 return std::make_shared<AudioUnitInstance>(*this, mComponent, mParameters,
185 GetSymbol().Internal(), mAudioIns, mAudioOuts, useLatency);
186}
constexpr auto OptionsKey
constexpr auto UseLatencyKey
bool GetConfig(const EffectDefinitionInterface &ident, ConfigurationType type, const RegistryPath &group, const RegistryPath &key, Value &var, const Value &defval)

References PluginSettings::GetConfig(), GetSymbol(), Internal, AudioUnitWrapper::mAudioIns, AudioUnitWrapper::mAudioOuts, AudioUnitWrapper::mComponent, AudioUnitWrapper::mParameters, OptionsKey, PluginSettings::Shared, and UseLatencyKey.

Here is the call graph for this function:

◆ MakeSettings()

EffectSettings AudioUnitEffectBase::MakeSettings ( ) const
overridevirtual

Produce an object holding new, independent settings

Default implementation returns an empty any

Reimplemented from EffectSettingsManager.

Definition at line 242 of file AudioUnitEffectBase.cpp.

243{
245 FetchSettings(settings, true);
246 return EffectSettings::Make<AudioUnitEffectSettings>(std::move(settings));
247}
Represents a cached copy of the state stored in an AudioUnit, but can outlive the original AudioUnit.
bool FetchSettings(AudioUnitEffectSettings &settings, bool fetchValues, bool fetchPreset=false) const
May allocate memory, so should be called only in the main thread.

References AudioUnitWrapper::FetchSettings(), and settings().

Here is the call graph for this function:

◆ MigrateOldConfigFile()

bool AudioUnitEffectBase::MigrateOldConfigFile ( const RegistryPath group,
EffectSettings settings 
) const

Definition at line 387 of file AudioUnitEffectBase.cpp.

389{
390 // Migration of very old format configuration file, should not normally
391 // happen and perhaps this code can be abandoned
392 // Attempt to load old preset parameters and resave using new method
393 constexpr auto oldKey = L"Parameters";
394 wxString parms;
396 group, oldKey, parms, wxEmptyString)) {
398 if (eap.SetParameters(parms))
399 if (LoadSettings(eap, settings))
400 if (SavePreset(group, GetSettings(settings)))
401 RemoveConfig(*this, PluginSettings::Private, group, oldKey);
402 return true;
403 }
404 return false;
405}
bool SavePreset(const RegistryPath &group, const AudioUnitEffectSettings &settings) const
bool LoadSettings(const CommandParameters &parms, EffectSettings &settings) const override
May allocate memory, so should be called only in the main thread.
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the SettingsVis...
bool SetParameters(const wxString &parms)
bool RemoveConfig(const EffectDefinitionInterface &ident, PluginSettings::ConfigurationType type, const RegistryPath &group, const RegistryPath &key)

References PluginSettings::GetConfig(), AudioUnitWrapper::GetSettings(), LoadSettings(), PluginSettings::Private, PluginSettings::RemoveConfig(), SavePreset(), CommandParameters::SetParameters(), and settings().

Referenced by LoadPreset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RealtimeSupport()

auto AudioUnitEffectBase::RealtimeSupport ( ) const
overridevirtual

Since which version of Audacity has the effect supported realtime?

Implements EffectDefinitionInterface.

Definition at line 158 of file AudioUnitEffectBase.cpp.

References EffectDefinitionInterface::After_3_1, EffectTypeProcess, GetType(), and EffectDefinitionInterface::Never.

Here is the call graph for this function:

◆ SaveBlobToConfig()

TranslatableString AudioUnitEffectBase::SaveBlobToConfig ( const RegistryPath group,
const wxString &  path,
const void *  blob,
size_t  len,
bool  allowEmpty = true 
) const
Parameters
pathonly for formatting error messages
Returns
error message

Definition at line 49 of file AudioUnitEffectBase.cpp.

52{
53 // Base64 encode the returned binary property list
54 auto parms = wxBase64Encode(blob, len);
55 if (!allowEmpty && parms.IsEmpty())
56 return XO("Failed to encode preset from \"%s\"").Format(path);
57
58 // And write it to the config
59 if (!SetConfig(*this, PluginSettings::Private, group, PRESET_KEY, parms))
60 return XO("Unable to store preset in config file");
61 return {};
62}
#define PRESET_KEY
bool SetConfig(const EffectDefinitionInterface &ident, ConfigurationType type, const RegistryPath &group, const RegistryPath &key, const Value &value)

References PRESET_KEY, PluginSettings::Private, PluginSettings::SetConfig(), and XO().

Referenced by SavePreset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SavePreset()

bool AudioUnitEffectBase::SavePreset ( const RegistryPath group,
const AudioUnitEffectSettings settings 
) const

Definition at line 418 of file AudioUnitEffectBase.cpp.

420{
421 wxCFStringRef cfname(wxFileNameFromPath(group));
422 const auto &[data, _] = MakeBlob(*this, settings, cfname, true);
423 if (!data)
424 return false;
425
426 // Nothing to do if we don't have any data
427 if (const auto length = CFDataGetLength(data.get())) {
428 auto error =
429 SaveBlobToConfig(group, {}, CFDataGetBytePtr(data.get()), length);
430 if (!error.empty())
431 return false;
432 }
433 return true;
434}
#define _(s)
Definition: Internat.h:73
TranslatableString SaveBlobToConfig(const RegistryPath &group, const wxString &path, const void *blob, size_t len, bool allowEmpty=true) const

References _, AudioUnitWrapper::MakeBlob(), SaveBlobToConfig(), and settings().

Referenced by MigrateOldConfigFile(), and SaveUserPreset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SaveSettings()

bool AudioUnitEffectBase::SaveSettings ( const EffectSettings settings,
CommandParameters parms 
) const
overridevirtual

Store settings as keys and values.

The override may assume parms is initially empty

Returns
true on success

Implements EffectSettingsManager.

Definition at line 291 of file AudioUnitEffectBase.cpp.

293{
294 const auto &mySettings = GetSettings(settings);
295 if (mySettings.mPresetNumber) {
296 const auto key = ChoosePresetKey(settings);
297 parms.Write(key, *mySettings.mPresetNumber);
298 }
299
300 // Save settings into CommandParameters
301 // Iterate the map only, not using any AudioUnit handles
302 for (auto &[ID, pPair] : mySettings.values)
303 if (pPair)
304 // Write names, not numbers, as keys in the config file
305 parms.Write(pPair->first, pPair->second);
306 return true;
307}
static RegistryPath ChoosePresetKey(const EffectSettings &settings)

References ChoosePresetKey(), AudioUnitWrapper::GetSettings(), key, and settings().

Here is the call graph for this function:

◆ SaveUserPreset()

bool AudioUnitEffectBase::SaveUserPreset ( const RegistryPath name,
const EffectSettings settings 
) const
overridevirtual

Save settings in the configuration file as a user-named preset.

Implements EffectSettingsManager.

Definition at line 345 of file AudioUnitEffectBase.cpp.

347{
349}

References AudioUnitWrapper::GetSettings(), name, SavePreset(), and settings().

Here is the call graph for this function:

◆ SupportsAutomation()

bool AudioUnitEffectBase::SupportsAutomation ( ) const
overridevirtual

Whether the effect has any automatable controls.

Implements EffectDefinitionInterface.

Definition at line 165 of file AudioUnitEffectBase.cpp.

166{
167 bool supports = false;
169 [&supports](const ParameterInfo &pi, AudioUnitParameterID) {
170 if (pi.mInfo.flags & kAudioUnitParameterFlag_IsWritable)
171 supports = true;
172 // Search only until we find one, that's all we need to know
173 return !supports;
174 });
175 return supports;
176}
void ForEachParameter(ParameterVisitor visitor) const

References AudioUnitWrapper::ForEachParameter(), and MIR::anonymous_namespace{MirUtils.cpp}::pi.

Here is the call graph for this function:

Member Data Documentation

◆ mInteractive

bool AudioUnitEffectBase::mInteractive { false }
protected

Definition at line 120 of file AudioUnitEffectBase.h.

Referenced by InitializePlugin(), and IsInteractive().

◆ mName

const wxString AudioUnitEffectBase::mName
protected

◆ mPath

const PluginPath AudioUnitEffectBase::mPath
protected

Definition at line 116 of file AudioUnitEffectBase.h.

Referenced by GetPath().

◆ mVendor

const wxString AudioUnitEffectBase::mVendor
protected

The documentation for this class was generated from the following files: