1 /**********************************************************************
2 
3   Audacity: A Digital Audio Editor
4 
5   EffectUI.h
6 
7   Leland Lucius
8 
9   Audacity(R) is copyright (c) 1999-2008 Audacity Team.
10   License: GPL v2.  See License.txt.
11 
12 **********************************************************************/
13 
14 #ifndef __AUDACITY_EFFECTUI_H__
15 #define __AUDACITY_EFFECTUI_H__
16 
17 #include <wx/bitmap.h> // member variables
18 
19 #include "Identifier.h"
20 #include "PluginInterface.h"
21 
22 #if defined(EXPERIMENTAL_EFFECTS_RACK)
23 
24 #include <vector>
25 
26 #include <wx/defs.h>
27 #include <wx/frame.h> // to inherit
28 #include <wx/timer.h> // member variable
29 
30 class wxFlexGridSizer;
31 class wxPanel;
32 class wxStaticText;
33 
34 class AudacityProject;
35 
36 class Effect;
37 using EffectArray = std::vector<Effect*>;
38 
39 class EffectRack final : public wxFrame
40 {
41 public:
42    EffectRack( AudacityProject &project );
43    virtual ~EffectRack();
44 
45    void Add(Effect *effect, bool active = false, bool favorite = false);
46 
47    static EffectRack &Get( AudacityProject &project );
48 
49 private:
50 
51    wxBitmap CreateBitmap(const char *const xpm[], bool up, bool pusher);
52    int GetEffectIndex(wxWindow *win);
53    void MoveRowUp(int row);
54    void UpdateActive();
55 
56    void OnClose(wxCloseEvent & evt);
57    void OnTimer(wxTimerEvent & evt);
58    void OnApply(wxCommandEvent & evt);
59    void OnBypass(wxCommandEvent & evt);
60 
61    void OnPower(wxCommandEvent & evt);
62    void OnEditor(wxCommandEvent & evt);
63    void OnUp(wxCommandEvent & evt);
64    void OnDown(wxCommandEvent & evt);
65    void OnFav(wxCommandEvent & evt);
66    void OnRemove(wxCommandEvent & evt);
67 
68 private:
69    AudacityProject &mProject;
70 
71    wxStaticText *mLatency;
72    int mLastLatency;
73 
74    wxBitmap mPowerPushed;
75    wxBitmap mPowerRaised;
76    wxBitmap mSettingsPushed;
77    wxBitmap mSettingsRaised;
78    wxBitmap mUpPushed;
79    wxBitmap mUpRaised;
80    wxBitmap mUpDisabled;
81    wxBitmap mDownPushed;
82    wxBitmap mDownRaised;
83    wxBitmap mDownDisabled;
84    wxBitmap mFavPushed;
85    wxBitmap mFavRaised;
86    wxBitmap mRemovePushed;
87    wxBitmap mRemoveRaised;
88 
89    std::vector<int> mPowerState;
90    std::vector<int> mFavState;
91 
92    int mNumEffects;
93 
94    wxTimer mTimer;
95 
96    wxPanel *mPanel;
97    wxFlexGridSizer *mMainSizer;
98 
99    EffectArray mEffects;
100    EffectArray mActive;
101    bool mBypassing;
102 
103    DECLARE_EVENT_TABLE()
104 };
105 
106 #endif
107 
108 #include "EffectInterface.h"
109 #include "widgets/wxPanelWrapper.h" // to inherit
110 
111 #include "SelectedRegion.h"
112 
113 class AudacityCommand;
114 class AudacityProject;
115 class Effect;
116 
117 class wxCheckBox;
118 
119 //
120 class EffectUIHost final : public wxDialogWrapper,
121                      public EffectUIHostInterface
122 {
123 public:
124    // constructors and destructors
125    EffectUIHost(wxWindow *parent,
126                 AudacityProject &project,
127                 Effect *effect,
128                 EffectUIClientInterface *client);
129    EffectUIHost(wxWindow *parent,
130                 AudacityProject &project,
131                 AudacityCommand *command,
132                 EffectUIClientInterface *client);
133    virtual ~EffectUIHost();
134 
135    bool TransferDataToWindow() override;
136    bool TransferDataFromWindow() override;
137 
138    int ShowModal() override;
139 
140    bool Initialize();
141 
142 private:
143    wxPanel *BuildButtonBar( wxWindow *parent );
144 
145    void OnInitDialog(wxInitDialogEvent & evt);
146    void OnErase(wxEraseEvent & evt);
147    void OnPaint(wxPaintEvent & evt);
148    void OnClose(wxCloseEvent & evt);
149    void OnApply(wxCommandEvent & evt);
150    void DoCancel();
151    void OnCancel(wxCommandEvent & evt);
152    void OnHelp(wxCommandEvent & evt);
153    void OnDebug(wxCommandEvent & evt);
154    void OnMenu(wxCommandEvent & evt);
155    void OnEnable(wxCommandEvent & evt);
156    void OnPlay(wxCommandEvent & evt);
157    void OnRewind(wxCommandEvent & evt);
158    void OnFFwd(wxCommandEvent & evt);
159    void OnPlayback(wxCommandEvent & evt);
160    void OnCapture(wxCommandEvent & evt);
161    void OnUserPreset(wxCommandEvent & evt);
162    void OnFactoryPreset(wxCommandEvent & evt);
163    void OnDeletePreset(wxCommandEvent & evt);
164    void OnSaveAs(wxCommandEvent & evt);
165    void OnImport(wxCommandEvent & evt);
166    void OnExport(wxCommandEvent & evt);
167    void OnOptions(wxCommandEvent & evt);
168    void OnDefaults(wxCommandEvent & evt);
169 
170    void UpdateControls();
171    wxBitmap CreateBitmap(const char * const xpm[], bool up, bool pusher);
172    void LoadUserPresets();
173 
174    void InitializeRealtime();
175    void CleanupRealtime();
176    void Resume();
177 
178 private:
179    AudacityProject *mProject;
180    wxWindow *mParent;
181    Effect *mEffect;
182    AudacityCommand * mCommand;
183    EffectUIClientInterface *mClient;
184 
185    RegistryPaths mUserPresets;
186    bool mInitialized;
187    bool mSupportsRealtime;
188    bool mIsGUI;
189    bool mIsBatch;
190 
191    wxButton *mApplyBtn;
192    wxButton *mCloseBtn;
193    wxButton *mMenuBtn;
194    wxButton *mPlayBtn;
195    wxButton *mRewindBtn;
196    wxButton *mFFwdBtn;
197    wxCheckBox *mEnableCb;
198 
199    wxButton *mEnableToggleBtn;
200    wxButton *mPlayToggleBtn;
201 
202    wxBitmap mPlayBM;
203    wxBitmap mPlayDisabledBM;
204    wxBitmap mStopBM;
205    wxBitmap mStopDisabledBM;
206 
207    bool mEnabled;
208 
209    bool mDisableTransport;
210    bool mPlaying;
211    bool mCapturing;
212 
213    SelectedRegion mRegion;
214    double mPlayPos;
215 
216    bool mDismissed{};
217    bool mNeedsResume{};
218 
219    DECLARE_EVENT_TABLE()
220 };
221 
222 class CommandContext;
223 
224 namespace  EffectUI {
225 
226    AUDACITY_DLL_API
227    wxDialog *DialogFactory( wxWindow &parent, EffectHostInterface *pHost,
228       EffectUIClientInterface *client);
229 
230    /** Run an effect given the plugin ID */
231    // Returns true on success.  Will only operate on tracks that
232    // have the "selected" flag set to true, which is consistent with
233    // Audacity's standard UI.
234    AUDACITY_DLL_API bool DoEffect(
235       const PluginID & ID, const CommandContext &context, unsigned flags );
236 
237 }
238 
239 class ShuttleGui;
240 
241 // Obsolescent dialog still used only in Noise Reduction/Removal
242 class AUDACITY_DLL_API EffectDialog /* not final */ : public wxDialogWrapper
243 {
244 public:
245    // constructors and destructors
246    EffectDialog(wxWindow * parent,
247                 const TranslatableString & title,
248                 int type = 0,
249                 int flags = wxDEFAULT_DIALOG_STYLE,
250                 int additionalButtons = 0);
251 
252    void Init();
253 
254    bool TransferDataToWindow() override;
255    bool TransferDataFromWindow() override;
256    bool Validate() override;
257 
258    // NEW virtuals:
259    virtual void PopulateOrExchange(ShuttleGui & S);
260    virtual void OnPreview(wxCommandEvent & evt);
261    virtual void OnOk(wxCommandEvent & evt);
262 
263 private:
264    int mType;
265    int mAdditionalButtons;
266 
267    DECLARE_EVENT_TABLE()
268    wxDECLARE_NO_COPY_CLASS(EffectDialog);
269 };
270 
271 #endif // __AUDACITY_EFFECTUI_H__
272