Audacity  2.2.2
AudioUnitEffect.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  AudioUnitEffect.h
6 
7  Dominic Mazzoni
8  Leland Lucius
9 
10 **********************************************************************/
11 #ifndef AUDACITY_AUDIOUNIT_EFFECT_H
12 
13 #include "../../Audacity.h"
14 
15 #if USE_AUDIO_UNITS
16 
17 #include "../../MemoryX.h"
18 #include <vector>
19 #include <wx/dialog.h>
20 
21 #include <AudioToolbox/AudioUnitUtilities.h>
22 #include <AudioUnit/AudioUnit.h>
23 #include <AudioUnit/AudioUnitProperties.h>
24 
28 
29 #include "AUControl.h"
30 
31 #define AUDIOUNITEFFECTS_VERSION wxT("1.0.0.0")
32 /* 18n-hint: the name of an Apple audio software protocol */
33 #define AUDIOUNITEFFECTS_FAMILY XO("AudioUnit")
34 
35 class AudioUnitEffect;
36 
37 using AudioUnitEffectArray = std::vector<std::unique_ptr<AudioUnitEffect>>;
38 
39 class AudioUnitEffectExportDialog;
40 class AudioUnitEffectImportDialog;
41 
42 class AudioUnitEffect : public wxEvtHandler,
43  public EffectClientInterface,
45 {
46 public:
47  AudioUnitEffect(const wxString & path,
48  const wxString & name,
49  AudioComponent component,
50  AudioUnitEffect *master = NULL);
51  virtual ~AudioUnitEffect();
52 
53  // IdentInterface implementation
54 
55  wxString GetPath() override;
56  IdentInterfaceSymbol GetSymbol() override;
57  IdentInterfaceSymbol GetVendor() override;
58  wxString GetVersion() override;
59  wxString GetDescription() override;
60 
61  // EffectIdentInterface implementation
62 
63  EffectType GetType() override;
64  IdentInterfaceSymbol GetFamilyId() override;
65  bool IsInteractive() override;
66  bool IsDefault() override;
67  bool IsLegacy() override;
68  bool SupportsRealtime() override;
69  bool SupportsAutomation() override;
70 
71  // EffectClientInterface implementation
72 
73  bool SetHost(EffectHostInterface *host) override;
74 
75  unsigned GetAudioInCount() override;
76  unsigned GetAudioOutCount() override;
77 
78  int GetMidiInCount() override;
79  int GetMidiOutCount() override;
80 
81  void SetSampleRate(double rate) override;
82  size_t SetBlockSize(size_t maxBlockSize) override;
83 
84  sampleCount GetLatency() override;
85  size_t GetTailSize() override;
86 
87  bool IsReady() override;
88  bool ProcessInitialize(sampleCount totalLen, ChannelNames chanMap = NULL) override;
89  bool ProcessFinalize() override;
90  size_t ProcessBlock(float **inBlock, float **outBlock, size_t blockLen) override;
91 
92  bool RealtimeInitialize() override;
93  bool RealtimeAddProcessor(unsigned numChannels, float sampleRate) override;
94  bool RealtimeFinalize() override;
95  bool RealtimeSuspend() override;
96  bool RealtimeResume() override;
97  bool RealtimeProcessStart() override;
98  size_t RealtimeProcess(int group,
99  float **inbuf,
100  float **outbuf,
101  size_t numSamples) override;
102  bool RealtimeProcessEnd() override;
103 
104  bool ShowInterface(wxWindow *parent, bool forceModal = false) override;
105 
106  bool GetAutomationParameters(CommandParameters & parms) override;
107  bool SetAutomationParameters(CommandParameters & parms) override;
108 
109  bool LoadUserPreset(const wxString & name) override;
110  bool SaveUserPreset(const wxString & name) override;
111 
112  bool LoadFactoryPreset(int id) override;
113  bool LoadFactoryDefaults() override;
114  wxArrayString GetFactoryPresets() override;
115 
116  // EffectUIClientInterface implementation
117 
118  void SetHostUI(EffectUIHostInterface *host) override;
119  bool PopulateUI(wxWindow *parent) override;
120  bool IsGraphicalUI() override;
121  bool ValidateUI() override;
122  bool HideUI() override;
123  bool CloseUI() override;
124 
125  bool CanExportPresets() override;
126  void ExportPresets() override;
127  void ImportPresets() override;
128 
129  bool HasOptions() override;
130  void ShowOptions() override;
131 
132  // AudioUnitEffect implementation
133 
134 private:
135  bool SetRateAndChannels();
136 
137  bool CopyParameters(AudioUnit srcUnit, AudioUnit dstUnit);
138 
139  // Realtime
140  unsigned GetChannelCount();
141  void SetChannelCount(unsigned numChannels);
142 
143  static OSStatus RenderCallback(void *inRefCon,
144  AudioUnitRenderActionFlags *inActionFlags,
145  const AudioTimeStamp *inTimeStamp,
146  UInt32 inBusNumber,
147  UInt32 inNumFrames,
148  AudioBufferList *ioData);
149  OSStatus Render(AudioUnitRenderActionFlags *inActionFlags,
150  const AudioTimeStamp *inTimeStamp,
151  UInt32 inBusNumber,
152  UInt32 inNumFrames,
153  AudioBufferList *ioData);
154 
155  static void EventListenerCallback(void *inCallbackRefCon,
156  void *inObject,
157  const AudioUnitEvent *inEvent,
158  UInt64 inEventHostTime,
159  AudioUnitParameterValue inParameterValue);
160  void EventListener(const AudioUnitEvent *inEvent,
161  AudioUnitParameterValue inParameterValue);
162 
163  void GetChannelCounts();
164 
165  bool LoadParameters(const wxString & group);
166  bool SaveParameters(const wxString & group);
167 
168 
169  bool CreatePlain(wxWindow *parent);
170 
171 private:
172 
173  wxString mPath;
174  wxString mName;
175  wxString mVendor;
176  AudioComponent mComponent;
177  AudioUnit mUnit;
178  bool mUnitInitialized;
179 
180  bool mSupportsMono;
181  bool mSupportsStereo;
182 
183  EffectHostInterface *mHost;
184  unsigned mAudioIns;
185  unsigned mAudioOuts;
186  bool mInteractive;
187  bool mLatencyDone;
188  UInt32 mBlockSize;
189  double mSampleRate;
190 
191  int mBufferSize;
192  bool mUseLatency;
193 
194  AudioTimeStamp mTimeStamp;
195  bool mReady;
196 
197  ArrayOf<AudioBufferList> mInputList;
198  ArrayOf<AudioBufferList> mOutputList;
199 
200  EffectUIHostInterface *mUIHost;
201  wxWindow *mParent;
202  wxDialog *mDialog;
203  wxString mUIType;
204  bool mIsGraphical;
205 
206  AudioUnitEffect *mMaster; // non-NULL if a slave
207  AudioUnitEffectArray mSlaves;
208  unsigned mNumChannels;
209  ArraysOf<float> mMasterIn, mMasterOut;
210  size_t mNumSamples;
211 
212  AUEventListenerRef mEventListenerRef;
213 
214  AUControl *mpControl{};
215 
216  friend class AudioUnitEffectExportDialog;
217  friend class AudioUnitEffectImportDialog;
218 };
219 
221 //
222 // AudioUnitEffectsModule
223 //
225 
226 class AudioUnitEffectsModule final : public ModuleInterface
227 {
228 public:
229  AudioUnitEffectsModule(ModuleManagerInterface *moduleManager, const wxString *path);
230  virtual ~AudioUnitEffectsModule();
231 
232  // IdentInterface implementation
233 
234  wxString GetPath() override;
235  IdentInterfaceSymbol GetSymbol() override;
236  IdentInterfaceSymbol GetVendor() override;
237  wxString GetVersion() override;
238  wxString GetDescription() override;
239 
240  // ModuleInterface implementation
241 
242  bool Initialize() override;
243  void Terminate() override;
244 
245  wxArrayString FileExtensions() override;
246  wxString InstallPath() override { return {}; }
247 
248  bool AutoRegisterPlugins(PluginManagerInterface & pm) override;
249  wxArrayString FindPluginPaths(PluginManagerInterface & pm) override;
250  unsigned DiscoverPluginsAtPath(
251  const wxString & path, wxString &errMsg,
252  const RegistrationCallback &callback)
253  override;
254 
255  bool IsPluginValid(const wxString & path, bool bFast) override;
256 
257  IdentInterface *CreateInstance(const wxString & path) override;
258  void DeleteInstance(IdentInterface *instance) override;
259 
260  // AudioUnitEffectModule implementation
261 
262  void LoadAudioUnitsOfType(OSType inAUType, wxArrayString & effects);
263  AudioComponent FindAudioUnit(const wxString & path, wxString & name);
264 
265  wxString FromOSType(OSType type);
266  OSType ToOSType(const wxString & type);
267 
268 private:
269  ModuleManagerInterface *mModMan;
270  wxString mPath;
271 };
272 
273 #endif
274 
275 #endif
virtual bool IsPluginValid(const wxString &path, bool bFast)=0
virtual bool AutoRegisterPlugins(PluginManagerInterface &pluginManager)=0
EffectUIClientInterface is an abstract base class to populate a UI and validate UI values...
virtual bool Initialize()=0
virtual IdentInterfaceSymbol GetSymbol()=0
virtual wxString InstallPath()=0
virtual wxString GetDescription()=0
virtual wxString GetVersion()=0
virtual void DeleteInstance(IdentInterface *instance)=0
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the Shuttle cla...
virtual wxArrayString FindPluginPaths(PluginManagerInterface &pluginManager)=0
virtual IdentInterface * CreateInstance(const wxString &path)=0
IdentInterfaceSymbol pairs a persistent string identifier used internally with an optional...
enum ChannelName * ChannelNames
virtual wxArrayString FileExtensions()=0
EffectHostInterface is a decorator of a EffectUIClientInterface. It adds virtual (abstract) functions...
EffectType
const wxChar * name
Definition: Distortion.cpp:94
virtual IdentInterfaceSymbol GetVendor()=0
Memory.h template class for making an array of float, bool, etc.
Definition: MemoryX.h:86
EffectClientInterface provides the ident interface to Effect, and is what makes Effect into a plug-in...
An Effect class that handles a wide range of effects. ??Mac only??
virtual wxString GetPath()=0
IdentInterface provides name / vendor / version functions to identify plugins. It is what makes a cla...
virtual void Terminate()=0
virtual unsigned DiscoverPluginsAtPath(const wxString &path, wxString &errMsg, const RegistrationCallback &callback)=0
a wxControl with Cocoa/Carbon support
Definition: AUControl.h:37
EffectUIHostInterface has nothing in it. It is provided so that an Effect can call SetHostUI passing ...