Audacity  3.2.0
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
EffectSimpleMono Class Referenceabstract

An abstract Effect class that simplifies the implementation of a basic monaural effect. Inherit from it if your effect just modifies a single track in place and doesn't care how many samples it gets at a time. More...

#include <SimpleMono.h>

Inheritance diagram for EffectSimpleMono:
Collaboration diagram for EffectSimpleMono:

Public Member Functions

bool Process () override
- Public Member Functions inherited from Effect
 Effect ()
virtual ~Effect ()
PluginPath GetPath () override
ComponentInterfaceSymbol GetSymbol () override
VendorSymbol GetVendor () override
wxString GetVersion () override
TranslatableString GetDescription () override
EffectType GetType () override
 Type determines how it behaves. More...
EffectFamilySymbol GetFamily () override
 Report identifier and user-visible name of the effect protocol. More...
bool IsInteractive () override
 Whether the effect needs a dialog for entry of settings. More...
bool IsDefault () override
 Whether the effect sorts "above the line" in the menus. More...
bool IsLegacy () override
bool SupportsRealtime () override
 Whether the effect supports realtime previewing (while audio is playing). More...
bool SupportsAutomation () override
 Whether the effect can be used without the UI, in a macro. More...
bool GetAutomationParameters (CommandParameters &parms) override
 Save current settings into parms. More...
bool SetAutomationParameters (CommandParameters &parms) override
 Change settings to those stored in parms. More...
bool LoadUserPreset (const RegistryPath &name) override
 Change settings to a user-named preset. More...
bool SaveUserPreset (const RegistryPath &name) override
 Save current settings as a user-named preset. More...
RegistryPaths GetFactoryPresets () override
 Report names of factory presets. More...
bool LoadFactoryPreset (int id) override
 Change settings to the preset whose name is GetFactoryPresets()[id] More...
bool LoadFactoryDefaults () override
 Change settings back to "factory default". More...
bool SetHost (EffectHostInterface *host) override
unsigned GetAudioInCount () override
unsigned GetAudioOutCount () override
int GetMidiInCount () override
int GetMidiOutCount () override
sampleCount GetLatency () override
 Called for destructive, non-realtime effect computation. More...
size_t GetTailSize () override
void SetSampleRate (double rate) override
size_t SetBlockSize (size_t maxBlockSize) override
size_t GetBlockSize () const override
bool ProcessInitialize (sampleCount totalLen, ChannelNames chanMap=NULL) override
 Called for destructive, non-realtime effect computation. More...
bool ProcessFinalize () override
 Called for destructive, non-realtime effect computation. More...
size_t ProcessBlock (float **inBlock, float **outBlock, size_t blockLen) override
 Called for destructive, non-realtime effect computation. More...
bool RealtimeInitialize () override
bool RealtimeAddProcessor (unsigned numChannels, float sampleRate) override
bool RealtimeFinalize () override
bool RealtimeSuspend () override
bool RealtimeResume () noexcept override
bool RealtimeProcessStart () override
size_t RealtimeProcess (int group, float **inbuf, float **outbuf, size_t numSamples) override
bool RealtimeProcessEnd () noexcept override
int ShowClientInterface (wxWindow &parent, wxDialog &dialog, bool forceModal=false) override
bool PopulateUI (ShuttleGui &S) final
 Adds controls to a panel that is given as the parent window of S More...
bool IsGraphicalUI () override
bool ValidateUI () override
bool HideUI () override
bool CloseUI () override
bool CanExportPresets () override
void ExportPresets () override
void ImportPresets () override
bool HasOptions () override
void ShowOptions () override
EffectDefinitionInterfaceGetDefinition () override
double GetDuration () override
NumericFormatSymbol GetDurationFormat () override
virtual NumericFormatSymbol GetSelectionFormat ()
void SetDuration (double duration) override
RegistryPath GetUserPresetsGroup (const RegistryPath &name) override
RegistryPath GetCurrentSettingsGroup () override
RegistryPath GetFactoryDefaultsGroup () override
virtual wxString GetSavedStateGroup ()
int ShowHostInterface (wxWindow &parent, const EffectDialogFactory &factory, bool forceModal=false) override
unsigned TestUIFlags (unsigned mask)
void SetPresetParameters (const wxArrayString *Names, const wxArrayString *Values)
virtual bool Startup (EffectUIClientInterface *client)
virtual bool GetAutomationParametersAsString (wxString &parms)
virtual bool SetAutomationParametersFromString (const wxString &parms)
virtual bool IsBatchProcessing ()
virtual void SetBatchProcessing (bool start)
bool DoEffect (double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, wxWindow *pParent=nullptr, const EffectDialogFactory &dialogFactory={})
bool Delegate (Effect &delegate, wxWindow &parent, const EffectDialogFactory &factory)
int MessageBox (const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
virtual bool Startup ()
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
- Public Member Functions inherited from EffectProcessor
virtual ~EffectProcessor ()
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
virtual EffectType GetClassification ()
 Determines which menu it appears in; default same as GetType(). More...
virtual bool EnablesDebug ()
 Whether the effect dialog should have a Debug button; default, always false. More...
virtual ManualPageID ManualPage ()
 Name of a page in the Audacity alpha manual, default is empty. More...
virtual FilePath HelpPage ()
 Fully qualified local help file name, default is empty. More...
virtual bool IsHiddenFromMenus ()
 Default is false. More...
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
TranslatableString GetName ()
virtual bool DefineParams (ShuttleParams &WXUNUSED(S))
- Public Member Functions inherited from EffectUIHostInterface
virtual ~EffectUIHostInterface ()
- Public Member Functions inherited from EffectHostInterface
virtual ~EffectHostInterface ()

Protected Member Functions

virtual bool NewTrackSimpleMono ()=0
virtual bool ProcessSimpleMono (float *buffer, size_t len)=0
- Protected Member Functions inherited from Effect
bool EnableApply (bool enable=true)
bool EnablePreview (bool enable=true)
virtual bool Init ()
virtual bool CheckWhetherSkipEffect ()
virtual bool ProcessPass ()
virtual bool InitPass1 ()
virtual bool InitPass2 ()
virtual void End ()
virtual double CalcPreviewInputLength (double previewLength)
virtual void Preview (bool dryOnly)
virtual void PopulateOrExchange (ShuttleGui &S)
virtual bool TransferDataToWindow ()
virtual bool TransferDataFromWindow ()
bool TotalProgress (double frac, const TranslatableString &={})
bool TrackProgress (int whichTrack, double frac, const TranslatableString &={})
bool TrackGroupProgress (int whichGroup, double frac, const TranslatableString &={})
int GetNumWaveTracks ()
int GetNumWaveGroups ()
void GetBounds (const WaveTrack &track, const WaveTrack *pRight, sampleCount *start, sampleCount *len)
void SetLinearEffectFlag (bool linearEffectFlag)
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
bool IsPreviewing ()
void IncludeNotSelectedPreviewTracks (bool includeNotSelected)
void CopyInputTracks (bool allSyncLockSelected=false)
std::shared_ptr< AddedAnalysisTrackAddAnalysisTrack (const wxString &name=wxString())
ModifiedAnalysisTrack ModifyAnalysisTrack (const LabelTrack *pOrigTrack, const wxString &name=wxString())
void ReplaceProcessedTracks (const bool bGoodResult)
TrackAddToOutputTracks (const std::shared_ptr< Track > &t)
const TrackListinputTracks () const
const AudacityProjectFindProject () const

Protected Attributes

int mCurTrackNum
double mCurRate
double mCurT0
double mCurT1
int mCurChannel
- Protected Attributes inherited from Effect
BasicUI::ProgressDialogmProgress = nullptr
double mProjectRate
double mSampleRate
std::shared_ptr< TrackListmOutputTracks
double mT0
double mT1
wxArrayString mPresetNames
wxArrayString mPresetValues
int mPass
wxWeakRef< wxDialog > mHostUIDialog
 This smart pointer tracks the lifetime of the dialog. More...
wxWeakRef< wxDialog > mUIDialog
 This weak pointer may be the same as the above, or null. More...
wxWindow * mUIParent
unsigned mUIFlags { 0 }
sampleCount mSampleCnt

Private Member Functions

bool ProcessOne (WaveTrack *t, sampleCount start, sampleCount end)

Additional Inherited Members

- Public Types inherited from Effect
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
- Static Public Member Functions inherited from Effect
static void IncEffectCounter ()
- Static Public Member Functions inherited from EffectDefinitionInterface
static Identifier GetSquashedName (const Identifier &ident)
 A utility that strips spaces and CamelCases a name. More...
- Static Public Attributes inherited from Effect
static const wxString kUserPresetIdent = wxT("User Preset:")
static const wxString kFactoryPresetIdent = wxT("Factory Preset:")
static const wxString kCurrentSettingsIdent = wxT("<Current Settings>")
static const wxString kFactoryDefaultsIdent = wxT("<Factory Defaults>")
- Static Protected Attributes inherited from Effect
static int nEffectsDone =0

Detailed Description

An abstract Effect class that simplifies the implementation of a basic monaural effect. Inherit from it if your effect just modifies a single track in place and doesn't care how many samples it gets at a time.

Your derived class only needs to implement GetSymbol, GetEffectAction, and ProcessSimpleMono.

Definition at line 24 of file SimpleMono.h.

Member Function Documentation

◆ NewTrackSimpleMono()

bool EffectSimpleMono::NewTrackSimpleMono ( )
protectedpure virtual

Definition at line 125 of file SimpleMono.cpp.

126 {
127  return true;
128 }

Referenced by Process().

Here is the caller graph for this function:

◆ Process()

bool EffectSimpleMono::Process ( )

If Process() is not overridden, it uses ProcessInitialize(), ProcessBlock(), and ProcessFinalize() methods of EffectProcessor, and also GetLatency() to determine how many leading output samples to discard and how many extra samples to produce.

Reimplemented from Effect.

Definition at line 29 of file SimpleMono.cpp.

30 {
31  //Iterate over each track
32  this->CopyInputTracks(); // Set up mOutputTracks.
33  bool bGoodResult = true;
35  mCurTrackNum = 0;
36  for( auto pOutWaveTrack : mOutputTracks->Selected< WaveTrack >() )
37  {
38  //Get start and end times from track
39  double trackStart = pOutWaveTrack->GetStartTime();
40  double trackEnd = pOutWaveTrack->GetEndTime();
42  //Set the current bounds to whichever left marker is
43  //greater and whichever right marker is less:
44  mCurT0 = mT0 < trackStart? trackStart: mT0;
45  mCurT1 = mT1 > trackEnd? trackEnd: mT1;
47  // Process only if the right marker is to the right of the left marker
48  if (mCurT1 > mCurT0) {
50  //Transform the marker timepoints to samples
51  auto start = pOutWaveTrack->TimeToLongSamples(mCurT0);
52  auto end = pOutWaveTrack->TimeToLongSamples(mCurT1);
54  //Get the track rate and samples
55  mCurRate = pOutWaveTrack->GetRate();
56  mCurChannel = pOutWaveTrack->GetChannel();
58  //NewTrackSimpleMono() will returns true by default
59  //ProcessOne() processes a single track
60  if (!NewTrackSimpleMono() || !ProcessOne(pOutWaveTrack, start, end))
61  {
62  bGoodResult = false;
63  break;
64  }
65  }
67  mCurTrackNum++;
68  }
70  this->ReplaceProcessedTracks(bGoodResult);
71  return bGoodResult;
72 }

References Effect::CopyInputTracks(), mCurChannel, mCurRate, mCurT0, mCurT1, mCurTrackNum, Effect::mOutputTracks, Effect::mT0, Effect::mT1, NewTrackSimpleMono(), ProcessOne(), and Effect::ReplaceProcessedTracks().

Here is the call graph for this function:

◆ ProcessOne()

bool EffectSimpleMono::ProcessOne ( WaveTrack t,
sampleCount  start,
sampleCount  end 

Definition at line 77 of file SimpleMono.cpp.

79 {
80  //Get the length of the buffer (as double). len is
81  //used simple to calculate a progress meter, so it is easier
82  //to make it a double now than it is to do it later
83  auto len = (end - start).as_double();
85  //Initiate a processing buffer. This buffer will (most likely)
86  //be shorter than the length of the track being processed.
87  Floats buffer{ track->GetMaxBlockSize() };
89  //Go through the track one buffer at a time. s counts which
90  //sample the current buffer starts at.
91  auto s = start;
92  while (s < end) {
93  //Get a block of samples (smaller than the size of the buffer)
94  //Adjust the block size if it is the final block in the track
95  const auto block =
96  limitSampleBufferSize( track->GetBestBlockSize(s), end - s );
98  //Get the samples from the track and put them in the buffer
99  track->GetFloats(buffer.get(), s, block);
101  //Process the buffer. If it fails, clean up and exit.
102  if (!ProcessSimpleMono(buffer.get(), block))
103  //Return false because the effect failed.
104  return false;
106  //Processing succeeded. copy the newly-changed samples back
107  //onto the track.
108  track->Set((samplePtr) buffer.get(), floatSample, s, block);
110  //Increment s one blockfull of samples
111  s += block;
113  //Update the Progress meter
115  (s - start).as_double() /
116  len))
117  return false;
118  }
120  //Return true because the effect processing succeeded.
121  return true;
122 }

References floatSample, WaveTrack::GetBestBlockSize(), SampleTrack::GetFloats(), WaveTrack::GetMaxBlockSize(), limitSampleBufferSize(), mCurTrackNum, ProcessSimpleMono(), WaveTrack::Set(), and Effect::TrackProgress().

Referenced by Process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProcessSimpleMono()

virtual bool EffectSimpleMono::ProcessSimpleMono ( float *  buffer,
size_t  len 
protectedpure virtual

Referenced by ProcessOne().

Here is the caller graph for this function:

Member Data Documentation

◆ mCurChannel

int EffectSimpleMono::mCurChannel

Definition at line 45 of file SimpleMono.h.

Referenced by Process().

◆ mCurRate

double EffectSimpleMono::mCurRate

Definition at line 42 of file SimpleMono.h.

Referenced by Process().

◆ mCurT0

double EffectSimpleMono::mCurT0

Definition at line 43 of file SimpleMono.h.

Referenced by Process().

◆ mCurT1

double EffectSimpleMono::mCurT1

Definition at line 44 of file SimpleMono.h.

Referenced by Process().

◆ mCurTrackNum

int EffectSimpleMono::mCurTrackNum

Definition at line 41 of file SimpleMono.h.

Referenced by Process(), and ProcessOne().

The documentation for this class was generated from the following files:
A Track that contains audio waveform data.
Definition: WaveTrack.h:75
int mCurChannel
Definition: SimpleMono.h:45
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:1834
double mT1
Definition: Effect.h:424
@ floatSample
Definition: SampleFormat.h:34
double mT0
Definition: Effect.h:423
virtual bool ProcessSimpleMono(float *buffer, size_t len)=0
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:1956
bool ProcessOne(WaveTrack *t, sampleCount start, sampleCount end)
Definition: SimpleMono.cpp:77
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:422
char * samplePtr
Definition: SampleFormat.h:49
virtual bool NewTrackSimpleMono()=0
Definition: SimpleMono.cpp:125
double mCurT0
Definition: SimpleMono.h:43
double mCurRate
Definition: SimpleMono.h:42
int mCurTrackNum
Definition: SimpleMono.h:41
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:23
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={})
Definition: Effect.cpp:1788
ArrayOf< float >
double mCurT1
Definition: SimpleMono.h:44