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 
25 #include "audacity/EffectInterface.h"
26 #include "audacity/ModuleInterface.h"
27 #include "audacity/PluginInterface.h"
28 
29 #include "AUControl.h"
30 
31 #define AUDIOUNITEFFECTS_VERSION wxT("1.0.0.0")
32 #define AUDIOUNITEFFECTS_FAMILY wxT("AudioUnit")
33 
34 class AudioUnitEffect;
35 
36 using AudioUnitEffectArray = std::vector<movable_ptr<AudioUnitEffect>>;
37 
38 class AudioUnitEffectExportDialog;
39 class AudioUnitEffectImportDialog;
40 
41 class AudioUnitEffect : public wxEvtHandler,
42  public EffectClientInterface,
43  public EffectUIClientInterface
44 {
45 public:
46  AudioUnitEffect(const wxString & path,
47  const wxString & name,
48  AudioComponent component,
49  AudioUnitEffect *master = NULL);
50  virtual ~AudioUnitEffect();
51 
52  // IdentInterface implementation
53 
54  wxString GetPath() override;
55  wxString GetSymbol() override;
56  wxString GetName() override;
57  wxString GetVendor() override;
58  wxString GetVersion() override;
59  wxString GetDescription() override;
60 
61  // EffectIdentInterface implementation
62 
63  EffectType GetType() override;
64  wxString GetFamilyId() override;
65  wxString GetFamilyName() override;
66  bool IsInteractive() override;
67  bool IsDefault() override;
68  bool IsLegacy() override;
69  bool SupportsRealtime() override;
70  bool SupportsAutomation() override;
71 
72  // EffectClientInterface implementation
73 
74  bool SetHost(EffectHostInterface *host) override;
75 
76  unsigned GetAudioInCount() override;
77  unsigned GetAudioOutCount() override;
78 
79  int GetMidiInCount() override;
80  int GetMidiOutCount() override;
81 
82  void SetSampleRate(double rate) override;
83  size_t SetBlockSize(size_t maxBlockSize) override;
84 
85  sampleCount GetLatency() override;
86  size_t GetTailSize() override;
87 
88  bool IsReady() override;
89  bool ProcessInitialize(sampleCount totalLen, ChannelNames chanMap = NULL) override;
90  bool ProcessFinalize() override;
91  size_t ProcessBlock(float **inBlock, float **outBlock, size_t blockLen) override;
92 
93  bool RealtimeInitialize() override;
94  bool RealtimeAddProcessor(unsigned numChannels, float sampleRate) override;
95  bool RealtimeFinalize() override;
96  bool RealtimeSuspend() override;
97  bool RealtimeResume() override;
98  bool RealtimeProcessStart() override;
99  size_t RealtimeProcess(int group,
100  float **inbuf,
101  float **outbuf,
102  size_t numSamples) override;
103  bool RealtimeProcessEnd() override;
104 
105  bool ShowInterface(wxWindow *parent, bool forceModal = false) override;
106 
107  bool GetAutomationParameters(EffectAutomationParameters & parms) override;
108  bool SetAutomationParameters(EffectAutomationParameters & parms) override;
109 
110  bool LoadUserPreset(const wxString & name) override;
111  bool SaveUserPreset(const wxString & name) override;
112 
113  bool LoadFactoryPreset(int id) override;
114  bool LoadFactoryDefaults() override;
115  wxArrayString GetFactoryPresets() override;
116 
117  // EffectUIClientInterface implementation
118 
119  void SetHostUI(EffectUIHostInterface *host) override;
120  bool PopulateUI(wxWindow *parent) override;
121  bool IsGraphicalUI() override;
122  bool ValidateUI() override;
123  bool HideUI() override;
124  bool CloseUI() override;
125 
126  bool CanExportPresets() override;
127  void ExportPresets() override;
128  void ImportPresets() override;
129 
130  bool HasOptions() override;
131  void ShowOptions() override;
132 
133  // AudioUnitEffect implementation
134 
135 private:
136  bool SetRateAndChannels();
137 
138  bool CopyParameters(AudioUnit srcUnit, AudioUnit dstUnit);
139 
140  // Realtime
141  unsigned GetChannelCount();
142  void SetChannelCount(unsigned numChannels);
143 
144  static OSStatus RenderCallback(void *inRefCon,
145  AudioUnitRenderActionFlags *inActionFlags,
146  const AudioTimeStamp *inTimeStamp,
147  UInt32 inBusNumber,
148  UInt32 inNumFrames,
149  AudioBufferList *ioData);
150  OSStatus Render(AudioUnitRenderActionFlags *inActionFlags,
151  const AudioTimeStamp *inTimeStamp,
152  UInt32 inBusNumber,
153  UInt32 inNumFrames,
154  AudioBufferList *ioData);
155 
156  static void EventListenerCallback(void *inCallbackRefCon,
157  void *inObject,
158  const AudioUnitEvent *inEvent,
159  UInt64 inEventHostTime,
160  AudioUnitParameterValue inParameterValue);
161  void EventListener(const AudioUnitEvent *inEvent,
162  AudioUnitParameterValue inParameterValue);
163 
164  void GetChannelCounts();
165 
166  bool LoadParameters(const wxString & group);
167  bool SaveParameters(const wxString & group);
168 
169 
170  bool CreatePlain(wxWindow *parent);
171 
172 private:
173 
174  wxString mPath;
175  wxString mName;
176  wxString mVendor;
177  AudioComponent mComponent;
178  AudioUnit mUnit;
179  bool mUnitInitialized;
180 
181  bool mSupportsMono;
182  bool mSupportsStereo;
183 
184  EffectHostInterface *mHost;
185  unsigned mAudioIns;
186  unsigned mAudioOuts;
187  bool mInteractive;
188  bool mLatencyDone;
189  UInt32 mBlockSize;
190  double mSampleRate;
191 
192  int mBufferSize;
193  bool mUseLatency;
194 
195  AudioTimeStamp mTimeStamp;
196  bool mReady;
197 
198  ArrayOf<AudioBufferList> mInputList;
199  ArrayOf<AudioBufferList> mOutputList;
200 
201  EffectUIHostInterface *mUIHost;
202  wxWindow *mParent;
203  wxDialog *mDialog;
204  wxString mUIType;
205  bool mIsGraphical;
206 
207  AudioUnitEffect *mMaster; // non-NULL if a slave
208  AudioUnitEffectArray mSlaves;
209  unsigned mNumChannels;
210  ArraysOf<float> mMasterIn, mMasterOut;
211  size_t mNumSamples;
212 
213  AUEventListenerRef mEventListenerRef;
214 
215  AUControl *mpControl{};
216 
217  friend class AudioUnitEffectExportDialog;
218  friend class AudioUnitEffectImportDialog;
219 };
220 
222 //
223 // AudioUnitEffectsModule
224 //
226 
227 class AudioUnitEffectsModule final : public ModuleInterface
228 {
229 public:
230  AudioUnitEffectsModule(ModuleManagerInterface *moduleManager, const wxString *path);
231  virtual ~AudioUnitEffectsModule();
232 
233  // IdentInterface implementation
234 
235  wxString GetPath() override;
236  wxString GetSymbol() override;
237  wxString GetName() override;
238  wxString GetVendor() override;
239  wxString GetVersion() override;
240  wxString GetDescription() override;
241 
242  // ModuleInterface implementation
243 
244  bool Initialize() override;
245  void Terminate() override;
246 
247  wxArrayString FileExtensions() override;
248  wxString InstallPath() override { return {}; }
249 
250  bool AutoRegisterPlugins(PluginManagerInterface & pm) override;
251  wxArrayString FindPluginPaths(PluginManagerInterface & pm) override;
252  unsigned DiscoverPluginsAtPath(
253  const wxString & path, wxString &errMsg,
254  const RegistrationCallback &callback)
255  override;
256 
257  bool IsPluginValid(const wxString & path, bool bFast) override;
258 
259  IdentInterface *CreateInstance(const wxString & path) override;
260  void DeleteInstance(IdentInterface *instance) override;
261 
262  // AudioUnitEffectModule implementation
263 
264  void LoadAudioUnitsOfType(OSType inAUType, wxArrayString & effects);
265  AudioComponent FindAudioUnit(const wxString & path, wxString & name);
266 
267  wxString FromOSType(OSType type);
268  OSType ToOSType(const wxString & type);
269 
270 private:
271  ModuleManagerInterface *mModMan;
272  wxString mPath;
273 };
274 
275 #endif
276 
277 #endif
const wxChar * name
Definition: Distortion.cpp:94
Memory.h template class for making an array of float, bool, etc.
Definition: MemoryX.h:469
An Effect class that handles a wide range of effects. ??Mac only??
a wxControl with Cocoa/Carbon support
Definition: AUControl.h:37