Audacity  2.2.2
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 #ifndef __AUDACITY_OLD_STD__
38 #include <unordered_map>
39 #endif
40 
41 using EffectArray = std::vector <Effect*> ;
42 using EffectMap = std::unordered_map<wxString, Effect *>;
43 using EffectOwnerMap = std::unordered_map< wxString, std::shared_ptr<Effect> >;
44 
45 #if defined(EXPERIMENTAL_EFFECTS_RACK)
46 class EffectRack;
47 #endif
48 
49 class AUDACITY_DLL_API EffectManager
50 {
51 public:
52 
55  static EffectManager & Get();
56 
57 //
58 // public methods
59 //
60 // Used by the outside program to register the list of effects and retrieve
61 // them by index number, usually when the user selects one from a menu.
62 //
63 public:
64  EffectManager();
65  virtual ~EffectManager();
66 
68  // Here solely for the purpose of Nyquist Workbench until
69  // a better solution is devised.
70  const PluginID & RegisterEffect(Effect *f);
71  void UnregisterEffect(const PluginID & ID);
72 
74  // Returns true on success. Will only operate on tracks that
75  // have the "selected" flag set to true, which is consistent with
76  // Audacity's standard UI.
77  bool DoEffect(const PluginID & ID,
78  wxWindow *parent,
79  double projectRate,
80  TrackList *list,
81  TrackFactory *factory,
82  SelectedRegion *selectedRegion,
83  bool shouldPrompt = true);
84 
85  wxString GetEffectName(const PluginID & ID);
86  wxString GetEffectFamilyName(const PluginID & ID);
87  wxString GetEffectIdentifier(const PluginID & ID);
88  wxString GetEffectDescription(const PluginID & ID);
89  bool IsHidden(const PluginID & ID);
90 
92  bool SupportsAutomation(const PluginID & ID);
93  wxString GetEffectParameters(const PluginID & ID);
94  bool SetEffectParameters(const PluginID & ID, const wxString & params);
95  bool PromptUser(const PluginID & ID, wxWindow *parent);
96  bool HasPresets(const PluginID & ID);
97  wxString GetPreset(const PluginID & ID, const wxString & params, wxWindow * parent);
98  wxString GetDefaultPreset(const PluginID & ID);
99 
100 private:
101  void SetBatchProcessing(const PluginID & ID, bool start);
103  PluginID mID;
104  void operator () (EffectManager *p) const
105  { if(p) p->SetBatchProcessing(mID, false); }
106  };
107  using BatchProcessingScope =
108  std::unique_ptr< EffectManager, UnsetBatchProcessing >;
109 public:
110  // RAII for the function above
112  {
113  SetBatchProcessing(ID, true); return BatchProcessingScope{ this, {ID} };
114  }
115 
117  void SetSkipStateFlag(bool flag);
118  bool GetSkipStateFlag();
119 
120  // Realtime effect processing
121  bool RealtimeIsActive();
122  bool RealtimeIsSuspended();
123  void RealtimeAddEffect(Effect *effect);
124  void RealtimeRemoveEffect(Effect *effect);
125  void RealtimeSetEffects(const EffectArray & mActive);
126  void RealtimeInitialize(double rate);
127  void RealtimeAddProcessor(int group, unsigned chans, float rate);
128  void RealtimeFinalize();
129  void RealtimeSuspend();
130  void RealtimeResume();
131  void RealtimeProcessStart();
132  size_t RealtimeProcess(int group, unsigned chans, float **buffers, size_t numSamples);
133  void RealtimeProcessEnd();
134  int GetRealtimeLatency();
135 
136 #if defined(EXPERIMENTAL_EFFECTS_RACK)
137  void ShowRack();
138 #endif
139 
140  const PluginID & GetEffectByIdentifier(const wxString & strTarget);
141 
142 private:
144  Effect *GetEffect(const PluginID & ID);
145 
146 #if defined(EXPERIMENTAL_EFFECTS_RACK)
147  EffectRack *GetRack();
148 #endif
149 
150 private:
153 
155 
156  wxCriticalSection mRealtimeLock;
161  std::vector<unsigned> mRealtimeChans;
162  std::vector<double> mRealtimeRates;
163 
164  // Set true if we want to skip pushing state
165  // after processing at effect run time.
167 
168 #if defined(EXPERIMENTAL_EFFECTS_RACK)
169  EffectRack *mRack;
170 
171  friend class EffectRack;
172 #endif
173 
174 };
175 
176 
177 #endif
std::unordered_map< wxString, std::shared_ptr< Effect > > EffectOwnerMap
Definition: EffectManager.h:43
A list of TrackListNode items.
Definition: Track.h:612
std::unordered_map< wxString, Effect * > EffectMap
Definition: EffectManager.h:42
EffectMap mEffects
Base class for many of the effects in Audacity.
Definition: Effect.h:61
EffectArray mRealtimeEffects
std::vector< double > mRealtimeRates
Used to create a WaveTrack, or a LabelTrack.. Implementation of the functions of this class are dispe...
Definition: Track.h:856
wxCriticalSection mRealtimeLock
std::unique_ptr< EffectManager, UnsetBatchProcessing > BatchProcessingScope
Defines a selected portion of a project.
EffectManager is the class that handles effects and effect categories.
Definition: EffectManager.h:49
std::vector< Effect * > EffectArray
Definition: EffectManager.h:41
EffectOwnerMap mHostEffects
bool mRealtimeSuspended
BatchProcessingScope SetBatchProcessing(const PluginID &ID)
EffectDistortion::Params params
Definition: Distortion.cpp:95
std::vector< unsigned > mRealtimeChans
void SetBatchProcessing(const PluginID &ID, bool start)
bool DoEffect(const PluginID &ID, int flags)