Audacity  2.2.0
EffectManager.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  EffectManager.h
6 
7  Audacity(R) is copyright (c) 1999-2008 Audacity Team.
8  License: GPL v2. See License.txt.
9 
10 ******************************************************************//*******************************************************************/
20 
21 #ifndef __AUDACITY_EFFECTMANAGER__
22 #define __AUDACITY_EFFECTMANAGER__
23 
24 #include "../Experimental.h"
25 
26 #include <vector>
27 #include <wx/choice.h>
28 #include <wx/dialog.h>
29 #include <wx/event.h>
30 #include <wx/listbox.h>
31 #include <wx/string.h>
32 
33 #include "audacity/EffectInterface.h"
34 #include "../PluginManager.h"
35 #include "Effect.h"
36 
37 using EffectArray = std::vector <Effect*> ;
38 WX_DECLARE_STRING_HASH_MAP_WITH_DECL(Effect *, EffectMap, class AUDACITY_DLL_API);
39 WX_DECLARE_STRING_HASH_MAP_WITH_DECL(std::shared_ptr<Effect>, EffectOwnerMap, class AUDACITY_DLL_API);
40 
41 #if defined(EXPERIMENTAL_EFFECTS_RACK)
42 class EffectRack;
43 #endif
44 
45 class AUDACITY_DLL_API EffectManager
46 {
47 public:
48 
51  static EffectManager & Get();
52 
53 //
54 // public methods
55 //
56 // Used by the outside program to register the list of effects and retrieve
57 // them by index number, usually when the user selects one from a menu.
58 //
59 public:
60  EffectManager();
61  virtual ~EffectManager();
62 
64  // Here solely for the purpose of Nyquist Workbench until
65  // a better solution is devised.
66  const PluginID & RegisterEffect(Effect *f);
67  void UnregisterEffect(const PluginID & ID);
68 
70  // Returns true on success. Will only operate on tracks that
71  // have the "selected" flag set to true, which is consistent with
72  // Audacity's standard UI.
73  bool DoEffect(const PluginID & ID,
74  wxWindow *parent,
75  double projectRate,
76  TrackList *list,
77  TrackFactory *factory,
78  SelectedRegion *selectedRegion,
79  bool shouldPrompt = true);
80 
81  wxString GetEffectName(const PluginID & ID);
82  wxString GetEffectIdentifier(const PluginID & ID);
83  wxString GetEffectDescription(const PluginID & ID);
84  bool IsHidden(const PluginID & ID);
85 
87  bool SupportsAutomation(const PluginID & ID);
88  wxString GetEffectParameters(const PluginID & ID);
89  bool SetEffectParameters(const PluginID & ID, const wxString & params);
90  bool PromptUser(const PluginID & ID, wxWindow *parent);
91  bool HasPresets(const PluginID & ID);
92  wxString GetPreset(const PluginID & ID, const wxString & params, wxWindow * parent);
93  wxString GetDefaultPreset(const PluginID & ID);
94 
95 private:
96  void SetBatchProcessing(const PluginID & ID, bool start);
99  void operator () (EffectManager *p) const
100  { if(p) p->SetBatchProcessing(mID, false); }
101  };
102  using BatchProcessingScope =
103  std::unique_ptr< EffectManager, UnsetBatchProcessing >;
104 public:
105  // RAII for the function above
107  {
108  SetBatchProcessing(ID, true); return BatchProcessingScope{ this, {ID} };
109  }
110 
112  void SetSkipStateFlag(bool flag);
113  bool GetSkipStateFlag();
114 
115  // Realtime effect processing
116  bool RealtimeIsActive();
117  bool RealtimeIsSuspended();
118  void RealtimeAddEffect(Effect *effect);
119  void RealtimeRemoveEffect(Effect *effect);
120  void RealtimeSetEffects(const EffectArray & mActive);
121  void RealtimeInitialize(double rate);
122  void RealtimeAddProcessor(int group, unsigned chans, float rate);
123  void RealtimeFinalize();
124  void RealtimeSuspend();
125  void RealtimeResume();
126  void RealtimeProcessStart();
127  size_t RealtimeProcess(int group, unsigned chans, float **buffers, size_t numSamples);
128  void RealtimeProcessEnd();
129  int GetRealtimeLatency();
130 
131 #if defined(EXPERIMENTAL_EFFECTS_RACK)
132  void ShowRack();
133 #endif
134 
135  const PluginID & GetEffectByIdentifier(const wxString & strTarget);
136 
137 private:
139  Effect *GetEffect(const PluginID & ID);
140 
141 #if defined(EXPERIMENTAL_EFFECTS_RACK)
142  EffectRack *GetRack();
143 #endif
144 
145 private:
146  EffectMap mEffects;
147  EffectOwnerMap mHostEffects;
148 
150 
151  wxCriticalSection mRealtimeLock;
156  std::vector<unsigned> mRealtimeChans;
157  wxArrayDouble mRealtimeRates;
158 
159  // Set true if we want to skip pushing state
160  // after processing at effect run time.
162 
163 #if defined(EXPERIMENTAL_EFFECTS_RACK)
164  EffectRack *mRack;
165 
166  friend class EffectRack;
167 #endif
168 
169 };
170 
171 
172 #endif
A list of TrackListNode items.
Definition: Track.h:532
PluginID mID
Definition: EffectManager.h:98
bool mRealtimeActive
Definition: EffectManager.h:155
wxString PluginID
Definition: CommandFunctors.h:16
EffectMap mEffects
Definition: EffectManager.h:146
int mRealtimeLatency
Definition: EffectManager.h:153
int mNumEffects
Definition: EffectManager.h:149
Base class for many of the effects in Audacity.
Definition: Effect.h:62
EffectArray mRealtimeEffects
Definition: EffectManager.h:152
Definition: EffectManager.h:97
Used to create a WaveTrack, or a LabelTrack.. Implementation of the functions of this class are dispe...
Definition: Track.h:676
wxCriticalSection mRealtimeLock
Definition: EffectManager.h:151
std::unique_ptr< EffectManager, UnsetBatchProcessing > BatchProcessingScope
Definition: EffectManager.h:103
Defines a selected portion of a project.
Definition: SelectedRegion.h:37
WX_DECLARE_STRING_HASH_MAP_WITH_DECL(Effect *, EffectMap, class AUDACITY_DLL_API)
EffectManager is the class that handles effects and effect categories.
Definition: EffectManager.h:45
std::vector< Effect * > EffectArray
Definition: EffectManager.h:37
bool mSkipStateFlag
Definition: EffectManager.h:161
EffectOwnerMap mHostEffects
Definition: EffectManager.h:147
wxArrayDouble mRealtimeRates
Definition: EffectManager.h:157
bool mRealtimeSuspended
Definition: EffectManager.h:154
BatchProcessingScope SetBatchProcessing(const PluginID &ID)
Definition: EffectManager.h:106
EffectDistortion::Params params
Definition: Distortion.cpp:94
std::vector< unsigned > mRealtimeChans
Definition: EffectManager.h:156
void SetBatchProcessing(const PluginID &ID, bool start)
Definition: EffectManager.cpp:322