Audacity 3.2.0
EffectBase.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 EffectBase.h
6
7 Dominic Mazzoni
8 Vaughan Johnson
9
10 Paul Licameli split from Effect.h
11
12**********************************************************************/
13
14#ifndef __AUDACITY_EFFECT_BASE__
15#define __AUDACITY_EFFECT_BASE__
16
17#include "EffectPlugin.h" // to inherit
18
19#include <any>
20
21namespace BasicUI { class ProgressDialog; }
22
23class AudacityProject;
24class Track;
25
26class EFFECTS_API EffectBase /* not final */
27 : public EffectPlugin
28{
29public:
30 EffectBase();
31 ~EffectBase() override;
32
33 bool IsLinearEffect() const { return mIsLinearEffect; }
34 bool PreviewsFullSelection() const { return mPreviewFullSelection; }
35
36 void SetTracks(TrackList *pTracks) { mTracks = pTracks; }
37
39
43 virtual std::any BeginPreview(const EffectSettings &settings);
44
46 const InstanceFinder &finder,
47 double projectRate, TrackList *list,
49 unsigned flags,
50 const EffectSettingsAccessPtr &pAccess
51 ) override;
52
53 static std::optional<InstancePointer> FindInstance(EffectPlugin &plugin);
54 static InstanceFinder DefaultInstanceFinder(EffectPlugin &plugin);
55
56protected:
58 /*
59 Typically this is only useful in automation, for example
60 detecting that zero noise reduction is to be done,
61 or that normalisation is being done without Dc bias shift
62 or amplitude modification.
63 */
65 = 0;
66
67public:
68 // Determine duration of effect preview, given a suggested value
69 /*
70 Most effects just use the previewLength, but time-stretching/compressing
71 effects need to use a different input length, so override this method.
72
73 @return seconds
74 */
75 virtual double CalcPreviewInputLength(
76 const EffectSettings &settings, double previewLength) const = 0;
77
78protected:
79 // Previewing linear effect can be optimised by pre-mixing. However this
80 // should not be used for non-linear effects such as dynamic processors
81 // To allow pre-mixing before Preview, set linearEffectFlag to true.
82 void SetLinearEffectFlag(bool linearEffectFlag);
83
84 // Most effects only need to preview a short selection. However some
85 // (such as fade effects) need to know the full selection length.
86 void SetPreviewFullSelectionFlag(bool previewDurationFlag);
87
88 // Use this if the effect needs to know if it is previewing
89 bool IsPreviewing() const { return mIsPreview; }
90
91 // A global counter of all the successful Effect invocations.
92 static int nEffectsDone;
93
94 const TrackList *inputTracks() const { return mTracks; }
95 const AudacityProject *FindProject() const;
96 // used only if CopyInputTracks() is called.
97 std::shared_ptr<TrackList> mOutputTracks;
98#ifdef EXPERIMENTAL_SPECTRAL_EDITING
99 double mF0{};
100 double mF1{};
101#endif
102 wxArrayString mPresetNames;
103 unsigned mUIFlags{ 0 };
104
105private:
106 friend class Effect;
107
108 double GetDefaultDuration();
109
110public:
111 // Public until we can move these fields out of here into EffectContext
112 TrackList *mTracks{}; // the complete list of all tracks
113 int mNumTracks{}; // This is really mNumWaveTracks, per CountWaveTracks() and GetNumWaveTracks().
114 BasicUI::ProgressDialog *mProgress{}; // Temporary pointer, NOT deleted in destructor.
115 double mProjectRate{}; // Sample rate of the project - NEW tracks should
116 // be created with this rate...
118 double mT0{};
119 double mT1{};
120 bool mIsPreview{ false };
121
122 // Some public members that only change "context" fields
123
124 // If bGoodResult, replace mWaveTracks tracks in mTracks with successfully processed
125 // mOutputTracks copies, get rid of old mWaveTracks, and set mWaveTracks to mOutputTracks.
126 // Else clear and DELETE mOutputTracks copies.
127 void ReplaceProcessedTracks(const bool bGoodResult);
128
129 void CountWaveTracks();
130
131private:
132 bool mIsLinearEffect{ false };
134
135 std::vector<Track*> mIMap;
136 std::vector<Track*> mOMap;
137
139};
140
141/* i18n-hint: "Nyquist" is an embedded interpreted programming language in
142 Audacity, named in honor of the Swedish-American Harry Nyquist (or Nyqvist).
143 In the translations of this and other strings, you may transliterate the
144 name into another alphabet. */
145#define NYQUISTEFFECTS_FAMILY ( EffectFamilySymbol{ XO("Nyquist") } )
146
147#endif
static Settings & settings()
Definition: TrackInfo.cpp:83
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
Abstraction of a progress dialog with well defined time-to-completion estimate.
Definition: BasicUI.h:156
Base class for many of the effects in Audacity.
Definition: EffectBase.h:28
int mNumTracks
Definition: EffectBase.h:113
double mT1
Definition: EffectBase.h:119
std::shared_ptr< TrackList > mOutputTracks
Definition: EffectBase.h:97
WaveTrackFactory * mFactory
Definition: EffectBase.h:117
~EffectBase() override
TrackList * mTracks
Definition: EffectBase.h:112
void CountWaveTracks()
Definition: EffectBase.cpp:310
std::vector< Track * > mOMap
Definition: EffectBase.h:136
bool IsPreviewing() const
Definition: EffectBase.h:89
bool PreviewsFullSelection() const
Definition: EffectBase.h:34
const TrackList * inputTracks() const
Definition: EffectBase.h:94
virtual bool CheckWhetherSkipEffect(const EffectSettings &settings) const =0
After Init(), tell whether Process() should be skipped.
double mProjectRate
Definition: EffectBase.h:115
bool mIsPreview
Definition: EffectBase.h:120
bool IsLinearEffect() const
Definition: EffectBase.h:33
BasicUI::ProgressDialog * mProgress
Definition: EffectBase.h:114
int mNumGroups
Definition: EffectBase.h:138
bool mPreviewFullSelection
Definition: EffectBase.h:133
virtual double CalcPreviewInputLength(const EffectSettings &settings, double previewLength) const =0
std::vector< Track * > mIMap
Definition: EffectBase.h:135
wxArrayString mPresetNames
Definition: EffectBase.h:102
double GetDefaultDuration()
Definition: EffectBase.cpp:45
double mT0
Definition: EffectBase.h:118
void SetTracks(TrackList *pTracks)
Definition: EffectBase.h:36
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: EffectBase.cpp:224
bool mIsLinearEffect
Definition: EffectBase.h:132
static int nEffectsDone
Definition: EffectBase.h:92
Base class for many of the effects in Audacity.
Definition: Effect.h:26
Factory of instances of an effect.
Definition: EffectPlugin.h:36
virtual bool DoEffect(EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess=nullptr)=0
ProgressDialog Class.
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:161
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1201
Used to create or clone a WaveTrack, with appropriate context from the project that will own the trac...
Definition: WaveTrack.h:558
static RegisteredToolbarFactory factory
Externalized state of a plug-in.