File: EffectManager.h

package info (click to toggle)
audacity 3.7.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 134,800 kB
  • sloc: cpp: 366,277; ansic: 198,323; lisp: 7,761; sh: 3,414; python: 1,501; xml: 1,385; perl: 854; makefile: 125
file content (136 lines) | stat: -rw-r--r-- 3,951 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/**********************************************************************

  Audacity: A Digital Audio Editor

  EffectManager.h

  Audacity(R) is copyright (c) 1999-2008 Audacity Team.
  License: GPL v2 or later.  See License.txt.

**********************************************************************/

#ifndef __AUDACITY_EFFECTMANAGER__
#define __AUDACITY_EFFECTMANAGER__

#include "EffectInterface.h"
#include "Identifier.h"

#include <functional>
#include <memory>
#include <unordered_map>
#include <variant>
#include <vector>

class AudacityProject;
class CommandContext;
class ComponentInterfaceSymbol;
class wxString;
typedef wxString PluginID;
class Effect;
class EffectPlugin;
class EffectSettings;
class EffectInstance;

struct EffectAndDefaultSettings{
   EffectPlugin *effect{};
   EffectSettings settings{};
};

using EffectMap = std::unordered_map<wxString, EffectAndDefaultSettings>;
using EffectOwnerMap = std::unordered_map< wxString, std::shared_ptr<EffectPlugin> >;

EFFECTS_API
RegistryPaths GetUserPresets(EffectPlugin& host);

EFFECTS_API
bool HasCurrentSettings(EffectPlugin& host);

EFFECTS_API
bool HasFactoryDefaults(EffectPlugin& host);

class EFFECTS_API EffectManager
{
public:

   enum : unsigned {
      // No flags specified
      kNone = 0x00,
      // Flag used to disable prompting for configuration parameteres.
      kConfigured = 0x01,
      // Flag used to disable saving the state after processing.
      kSkipState = 0x02,
      // Flag used to disable "Repeat Last Effect"
      kDontRepeatLast = 0x04,
      // Flag used to disable "Select All during Repeat Generator Effect"
      kRepeatGen = 0x08,
      // Flag used for repeating Nyquist Prompt
      kRepeatNyquistPrompt = 0x10,
   };

   /*! Find the singleton EffectInstanceFactory for ID. */
   static const EffectInstanceFactory*
   GetInstanceFactory(const PluginID& ID);

   /** Get the singleton instance of the EffectManager. Probably not safe
       for multi-thread use. */
   static EffectManager& Get();

   //
   // public methods
   //
   // Used by the outside program to register the list of effects and retrieve
   // them by index number, usually when the user selects one from a menu.
   //
public:
   using EffectPresetDialog = std::function<std::optional<wxString>(
      EffectPlugin&, const wxString& preset)>;

   //! Here solely for the purpose of Nyquist Workbench until a better solution is devised.
   /** Register an effect so it can be executed.
     uEffect is expected to be a self-hosting Nyquist effect */
   const PluginID & RegisterEffect(std::unique_ptr<EffectPlugin> uEffect);
   //! Used only by Nyquist Workbench module
   void UnregisterEffect(const PluginID & ID);

   TranslatableString GetEffectFamilyName(const PluginID & ID);
   TranslatableString GetVendorName(const PluginID & ID);

   bool IsHidden(const PluginID & ID);

   bool HasPresets(const PluginID & ID);
   wxString
   GetPreset(const PluginID& ID, const wxString& params, EffectPresetDialog);
   wxString GetDefaultPreset(const PluginID & ID);

   /** Allow effects to disable saving the state at run time */
   void SetSkipStateFlag(bool flag);
   bool GetSkipStateFlag();

   /*! Return an effect by its ID. */
   EffectPlugin* GetEffect(const PluginID& ID);

   /*! Get default settings by effect ID.  May return nullptr */
   EffectSettings* GetDefaultSettings(const PluginID& ID);

   /*! Get effect and default settings by effect ID. */
   /*!
    @post `result: !result.first || result.second`
    (if first member is not null, then the second is not null)
    */
   std::pair<EffectPlugin*, EffectSettings*>
   GetEffectAndDefaultSettings(const PluginID& ID);

private:
   EffectAndDefaultSettings& DoGetEffect(const PluginID& ID);

   EffectMap mEffects;
   EffectOwnerMap mHostEffects;

   int mNumEffects;

   // Set true if we want to skip pushing state
   // after processing at effect run time.
   bool mSkipStateFlag;
};

#endif