Audacity  2.2.0
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 GetFamily() 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(EffectAutomationParameters & parms) override;
107  bool SetAutomationParameters(EffectAutomationParameters & 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  wxString GetSymbol() override;
236  wxString GetName() override;
237  wxString GetVendor() override;
238  wxString GetVersion() override;
239  wxString GetDescription() override;
240 
241  // ModuleInterface implementation
242 
243  bool Initialize() override;
244  void Terminate() override;
245 
246  bool AutoRegisterPlugins(PluginManagerInterface & pm) override;
247  wxArrayString FindPlugins(PluginManagerInterface & pm) override;
248  bool RegisterPlugin(PluginManagerInterface & pm, const wxString & path) override;
249 
250  bool IsPluginValid(const wxString & path, bool bFast) override;
251 
252  IdentInterface *CreateInstance(const wxString & path) override;
253  void DeleteInstance(IdentInterface *instance) override;
254 
255  // AudioUnitEffectModule implementation
256 
257  void LoadAudioUnitsOfType(OSType inAUType, wxArrayString & effects);
258  AudioComponent FindAudioUnit(const wxString & path, wxString & name);
259 
260  wxString FromOSType(OSType type);
261  OSType ToOSType(const wxString & type);
262 
263 private:
264  ModuleManagerInterface *mModMan;
265  wxString mPath;
266 };
267 
268 #endif
269 
270 #endif
const wxChar * name
Definition: Distortion.cpp:94
Memory.h template class for making an array of float, bool, etc.
Definition: MemoryX.h:439
An Effect class that handles a wide range of effects. ??Mac only??
a wxControl with Cocoa/Carbon support
Definition: AUControl.h:37