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 **********************************************************************/
11 
12 #ifndef __AUDACITY_EFFECTMANAGER__
13 #define __AUDACITY_EFFECTMANAGER__
14 
15 #include "../Experimental.h"
16 
17 #include <vector>
18 #include <wx/choice.h>
19 #include <wx/dialog.h>
20 #include <wx/event.h>
21 #include <wx/listbox.h>
22 #include <wx/string.h>
23 
25 #include "../PluginManager.h"
26 #include "Effect.h"
27 
28 #include <unordered_map>
29 
30 class AudacityCommand;
31 class CommandContext;
33 
34 using EffectArray = std::vector <Effect*> ;
35 using EffectMap = std::unordered_map<wxString, Effect *>;
36 using AudacityCommandMap = std::unordered_map<wxString, AudacityCommand *>;
37 using EffectOwnerMap = std::unordered_map< wxString, std::shared_ptr<Effect> >;
38 
39 #if defined(EXPERIMENTAL_EFFECTS_RACK)
40 class EffectRack;
41 #endif
42 class AudacityCommand;
43 
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 GetEffectFamilyName(const PluginID & ID);
82  wxString GetVendorName(const PluginID & ID);
83 
85  // Returns true on success.
86  bool DoAudacityCommand(const PluginID & ID,
87  const CommandContext &,
88  wxWindow *parent,
89  bool shouldPrompt = true );
90 
91  // Renamed from 'Effect' to 'Command' prior to moving out of this class.
92  IdentInterfaceSymbol GetCommandSymbol(const PluginID & ID);
93  wxString GetCommandName(const PluginID & ID); // translated
94  wxString GetCommandIdentifier(const PluginID & ID);
95  wxString GetCommandDescription(const PluginID & ID);
96  wxString GetCommandUrl(const PluginID & ID);
97  wxString GetCommandTip(const PluginID & ID);
98  // flags control which commands are included.
99  void GetCommandDefinition(const PluginID & ID, const CommandContext & context, int flags);
100  bool IsHidden(const PluginID & ID);
101 
103  bool SupportsAutomation(const PluginID & ID);
104  wxString GetEffectParameters(const PluginID & ID);
105  bool SetEffectParameters(const PluginID & ID, const wxString & params);
106  bool PromptUser(const PluginID & ID, wxWindow *parent);
107  bool HasPresets(const PluginID & ID);
108  wxString GetPreset(const PluginID & ID, const wxString & params, wxWindow * parent);
109  wxString GetDefaultPreset(const PluginID & ID);
110 
111 private:
112  void SetBatchProcessing(const PluginID & ID, bool start);
115  void operator () (EffectManager *p) const
116  { if(p) p->SetBatchProcessing(mID, false); }
117  };
118  using BatchProcessingScope =
119  std::unique_ptr< EffectManager, UnsetBatchProcessing >;
120 public:
121  // RAII for the function above
123  {
124  SetBatchProcessing(ID, true); return BatchProcessingScope{ this, {ID} };
125  }
126 
128  void SetSkipStateFlag(bool flag);
129  bool GetSkipStateFlag();
130 
131  // Realtime effect processing
132  bool RealtimeIsActive();
133  bool RealtimeIsSuspended();
134  void RealtimeAddEffect(Effect *effect);
135  void RealtimeRemoveEffect(Effect *effect);
136  void RealtimeSetEffects(const EffectArray & mActive);
137  void RealtimeInitialize(double rate);
138  void RealtimeAddProcessor(int group, unsigned chans, float rate);
139  void RealtimeFinalize();
140  void RealtimeSuspend();
141  void RealtimeResume();
142  void RealtimeProcessStart();
143  size_t RealtimeProcess(int group, unsigned chans, float **buffers, size_t numSamples);
144  void RealtimeProcessEnd();
145  int GetRealtimeLatency();
146 
147 #if defined(EXPERIMENTAL_EFFECTS_RACK)
148  void ShowRack();
149 #endif
150 
151  const PluginID & GetEffectByIdentifier(const wxString & strTarget);
152 
153 private:
155  Effect *GetEffect(const PluginID & ID);
156  AudacityCommand *GetAudacityCommand(const PluginID & ID);
157 
158 #if defined(EXPERIMENTAL_EFFECTS_RACK)
159  EffectRack *GetRack();
160 #endif
161 
162 private:
166 
168 
169  wxCriticalSection mRealtimeLock;
174  std::vector<unsigned> mRealtimeChans;
175  std::vector<double> mRealtimeRates;
176 
177  // Set true if we want to skip pushing state
178  // after processing at effect run time.
180 
181 #if defined(EXPERIMENTAL_EFFECTS_RACK)
182  EffectRack *mRack;
183 
184  friend class EffectRack;
185 #endif
186 
187 };
188 
189 
190 #endif
std::unordered_map< wxString, std::shared_ptr< Effect > > EffectOwnerMap
Definition: EffectManager.h:37
A list of TrackListNode items.
Definition: Track.h:618
std::unordered_map< wxString, Effect * > EffectMap
Definition: EffectManager.h:35
EffectMap mEffects
wxString PluginID
Definition: Types.h:209
Base class for many of the effects in Audacity.
Definition: Effect.h:62
bool DoAudacityCommand(const PluginID &ID, const CommandContext &, int flags)
CommandContext provides addiitonal information to an 'Apply()' command. It provides the project...
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:862
wxCriticalSection mRealtimeLock
std::unique_ptr< EffectManager, UnsetBatchProcessing > BatchProcessingScope
AudacityCommandMap mCommands
Defines a selected portion of a project.
EffectManager is the class that handles effects and effect categories.
Definition: EffectManager.h:45
Interface for objects that can receive (string) messages from a command.
bool DoEffect(const PluginID &ID, const CommandContext &context, int flags)
IdentInterfaceSymbol pairs a persistent string identifier used internally with an optional...
Base class for command in Audacity.
std::unordered_map< wxString, AudacityCommand * > AudacityCommandMap
Definition: EffectManager.h:36
std::vector< Effect * > EffectArray
Definition: EffectManager.h:34
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)