Audacity 3.2.0
Public Member Functions | Static Public Attributes | Private Member Functions | List of all members
EffectReverse Class Referencefinal

An Effect that reverses the selected audio. More...

#include <Reverse.h>

Inheritance diagram for EffectReverse:
[legend]
Collaboration diagram for EffectReverse:
[legend]

Public Member Functions

 EffectReverse ()
 
virtual ~EffectReverse ()
 
ComponentInterfaceSymbol GetSymbol () const override
 
TranslatableString GetDescription () const override
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
bool IsInteractive () const override
 Whether the effect needs a dialog for entry of settings. More...
 
bool Process (EffectInstance &instance, EffectSettings &settings) override
 Actually do the effect here. More...
 
- Public Member Functions inherited from StatefulEffect
std::shared_ptr< EffectInstanceMakeInstance () const override
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from StatefulEffectBase
virtual bool Init ()
 Call once to set up state for whole list of tracks to be processed. More...
 
virtual bool Process (EffectInstance &instance, EffectSettings &settings)=0
 Actually do the effect here. More...
 
virtual bool RealtimeInitialize (EffectSettings &settings, double sampleRate)
 
virtual bool RealtimeAddProcessor (EffectSettings &settings, EffectOutputs *pOutputs, unsigned numChannels, float sampleRate)
 
virtual bool RealtimeSuspend ()
 
virtual bool RealtimeResume ()
 
virtual bool RealtimeProcessStart (MessagePackage &package)
 settings are possibly changed, since last call, by an asynchronous dialog More...
 
virtual size_t RealtimeProcess (size_t group, EffectSettings &settings, const float *const *inBuf, float *const *outBuf, size_t numSamples)
 
virtual bool RealtimeProcessEnd (EffectSettings &settings) noexcept
 settings can be updated to let a dialog change appearance at idle More...
 
virtual bool RealtimeFinalize (EffectSettings &settings) noexcept
 
virtual size_t SetBlockSize (size_t maxBlockSize)
 
virtual size_t GetBlockSize () const
 
virtual unsigned GetAudioInCount () const
 How many input buffers to allocate at once. More...
 
virtual unsigned GetAudioOutCount () const
 How many output buffers to allocate at once. More...
 
virtual sampleCount GetLatency () const
 
- Public Member Functions inherited from Effect
 Effect ()
 
virtual ~Effect ()
 
PluginPath GetPath () const override
 
bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings) override
 
bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const override
 
ComponentInterfaceSymbol GetSymbol () const override
 
VendorSymbol GetVendor () const override
 
wxString GetVersion () const override
 
TranslatableString GetDescription () const override
 
EffectType GetType () const override
 Type determines how it behaves. More...
 
EffectFamilySymbol GetFamily () const override
 Report identifier and user-visible name of the effect protocol. More...
 
bool IsInteractive () const override
 Whether the effect needs a dialog for entry of settings. More...
 
bool IsDefault () const override
 Whether the effect sorts "above the line" in the menus. More...
 
RealtimeSince RealtimeSupport () const override
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsAutomation () const override
 Whether the effect has any automatable controls. More...
 
bool SaveSettings (const EffectSettings &settings, CommandParameters &parms) const override
 Store settings as keys and values. More...
 
bool LoadSettings (const CommandParameters &parms, EffectSettings &settings) const override
 Restore settings from keys and values. More...
 
OptionalMessage LoadUserPreset (const RegistryPath &name, EffectSettings &settings) const override
 
bool SaveUserPreset (const RegistryPath &name, const EffectSettings &settings) const override
 Save settings in the configuration file as a user-named preset. More...
 
RegistryPaths GetFactoryPresets () const override
 Report names of factory presets. More...
 
OptionalMessage LoadFactoryPreset (int id, EffectSettings &settings) const override
 
OptionalMessage LoadFactoryDefaults (EffectSettings &settings) const override
 
virtual const EffectParameterMethodsParameters () const
 
int ShowClientInterface (wxWindow &parent, wxDialog &dialog, EffectUIValidator *pValidator, bool forceModal) override
 
EffectUIClientInterfaceGetEffectUIClientInterface () override
 Returns the EffectUIClientInterface instance for this effect. More...
 
std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
 Adds controls to a panel that is given as the parent window of S More...
 
bool IsGraphicalUI () override
 
bool ValidateUI (EffectSettings &) override
 
bool CloseUI () override
 
bool CanExportPresets () override
 
void ExportPresets (const EffectSettings &settings) const override
 
OptionalMessage ImportPresets (EffectSettings &settings) override
 
bool HasOptions () override
 
void ShowOptions () override
 
const EffectSettingsManagerGetDefinition () const override
 
virtual NumericFormatSymbol GetSelectionFormat ()
 
int ShowHostInterface (wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false) override
 Usually applies factory to self and given access. More...
 
bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const override
 
OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const override
 
bool IsBatchProcessing () const override
 
void SetBatchProcessing () override
 
void UnsetBatchProcessing () override
 
bool TransferDataToWindow (const EffectSettings &settings) override
 Update controls for the settings. More...
 
bool TransferDataFromWindow (EffectSettings &settings) override
 Update the given settings from controls. More...
 
unsigned TestUIFlags (unsigned mask)
 
bool Delegate (Effect &delegate, EffectSettings &settings)
 Re-invoke DoEffect on another Effect object that implements the work. More...
 
int MessageBox (const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={}) const
 
bool EnableApply (bool enable=true)
 
wxWindow * GetUIParent ()
 
- Public Member Functions inherited from EffectBase
 EffectBase ()
 
 ~EffectBase () override
 
void SetTracks (TrackList *pTracks)
 
- Public Member Functions inherited from EffectUIClientInterface
virtual ~EffectUIClientInterface ()
 
virtual int ShowClientInterface (wxWindow &parent, wxDialog &dialog, EffectUIValidator *pValidator, bool forceModal=false)=0
 
virtual bool IsGraphicalUI ()=0
 
virtual std::unique_ptr< EffectUIValidatorPopulateUI (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs)=0
 Adds controls to a panel that is given as the parent window of S More...
 
virtual bool CanExportPresets ()=0
 
virtual void ExportPresets (const EffectSettings &settings) const =0
 
virtual OptionalMessage ImportPresets (EffectSettings &settings)=0
 
virtual bool HasOptions ()=0
 
virtual void ShowOptions ()=0
 
virtual bool ValidateUI (EffectSettings &settings)=0
 
virtual bool CloseUI ()=0
 
- Public Member Functions inherited from EffectPlugin
EffectPluginoperator= (EffectPlugin &)=delete
 
virtual ~EffectPlugin ()
 
virtual const EffectSettingsManagerGetDefinition () const =0
 
virtual int ShowHostInterface (wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false)=0
 Usually applies factory to self and given access. More...
 
virtual EffectUIClientInterfaceGetEffectUIClientInterface ()=0
 Returns the EffectUIClientInterface instance for this effect. More...
 
virtual void Preview (EffectSettingsAccess &access, bool dryOnly)=0
 
virtual bool SaveSettingsAsString (const EffectSettings &settings, wxString &parms) const =0
 
virtual OptionalMessage LoadSettingsFromString (const wxString &parms, EffectSettings &settings) const =0
 
virtual bool IsBatchProcessing () const =0
 
virtual void SetBatchProcessing ()=0
 
virtual void UnsetBatchProcessing ()=0
 
virtual bool DoEffect (EffectSettings &settings, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, wxWindow *pParent=nullptr, const EffectDialogFactory &dialogFactory={}, const EffectSettingsAccessPtr &pAccess=nullptr)=0
 Unfortunately complicated dual-use function. More...
 
virtual bool TransferDataToWindow (const EffectSettings &settings)=0
 Update controls for the settings. More...
 
virtual bool TransferDataFromWindow (EffectSettings &settings)=0
 Update the given settings from controls. More...
 
- Public Member Functions inherited from EffectInstanceFactory
virtual ~EffectInstanceFactory ()
 
virtual std::shared_ptr< EffectInstanceMakeInstance () const =0
 Make an object maintaining short-term state of an Effect. More...
 
- Public Member Functions inherited from EffectSettingsManager
virtual ~EffectSettingsManager ()
 
virtual bool VisitSettings (SettingsVisitor &visitor, EffectSettings &settings)
 
virtual bool VisitSettings (ConstSettingsVisitor &visitor, const EffectSettings &settings) const
 
virtual EffectSettings MakeSettings () const
 
virtual bool CopySettingsContents (const EffectSettings &src, EffectSettings &dst) const
 Update one settings object from another. More...
 
virtual std::unique_ptr< EffectOutputsMakeOutputs () const
 Produce an object to hold values to send to effect output meters. More...
 
- Public Member Functions inherited from EffectDefinitionInterface
virtual ~EffectDefinitionInterface ()
 
virtual EffectType GetType () const =0
 Type determines how it behaves. More...
 
virtual EffectType GetClassification () const
 Determines which menu it appears in; default same as GetType(). More...
 
virtual EffectFamilySymbol GetFamily () const =0
 Report identifier and user-visible name of the effect protocol. More...
 
virtual bool IsInteractive () const =0
 Whether the effect needs a dialog for entry of settings. More...
 
virtual bool IsDefault () const =0
 Whether the effect sorts "above the line" in the menus. More...
 
virtual RealtimeSince RealtimeSupport () const =0
 Since which version of Audacity has the effect supported realtime? More...
 
bool SupportsRealtime () const
 
virtual bool SupportsAutomation () const =0
 Whether the effect has any automatable controls. More...
 
virtual bool EnablesDebug () const
 Whether the effect dialog should have a Debug button; default, always false. More...
 
virtual ManualPageID ManualPage () const
 Name of a page in the Audacity alpha manual, default is empty. More...
 
virtual FilePath HelpPage () const
 Fully qualified local help file name, default is empty. More...
 
virtual bool IsHiddenFromMenus () const
 Default is false. More...
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
virtual PluginPath GetPath () const =0
 
virtual ComponentInterfaceSymbol GetSymbol () const =0
 
virtual VendorSymbol GetVendor () const =0
 
virtual wxString GetVersion () const =0
 
virtual TranslatableString GetDescription () const =0
 
TranslatableString GetName () const
 

Static Public Attributes

static const ComponentInterfaceSymbol Symbol { XO("Reverse") }
 
- Static Public Attributes inherited from EffectPlugin
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>")
 

Private Member Functions

bool ProcessOneClip (int count, WaveTrack *track, sampleCount start, sampleCount len, sampleCount originalStart, sampleCount originalEnd)
 
bool ProcessOneWave (int count, WaveTrack *track, sampleCount start, sampleCount len)
 

Additional Inherited Members

- Public Types inherited from StatefulEffectBase
using MessagePackage = EffectInstance::MessagePackage
 
- Public Types inherited from Effect
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Public Types inherited from EffectPlugin
using EffectSettingsAccessPtr = std::shared_ptr< EffectSettingsAccess >
 
- Public Types inherited from EffectDefinitionInterface
enum class  RealtimeSince : unsigned { Never , Since_3_2 , Always }
 In which versions of Audacity was an effect realtime capable? More...
 
- Static Public Member Functions inherited from Effect
static EffectFetchParameters (Effect &e, EffectSettings &)
 
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...
 
- Protected Member Functions inherited from Effect
bool EnablePreview (bool enable=true)
 
bool CheckWhetherSkipEffect (const EffectSettings &settings) const override
 Default implementation returns false. More...
 
double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const override
 Default implementation returns previewLength More...
 
virtual std::unique_ptr< EffectUIValidatorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs)
 Add controls to effect panel; always succeeds. More...
 
bool TotalProgress (double frac, const TranslatableString &={}) const
 
bool TrackProgress (int whichTrack, double frac, const TranslatableString &={}) const
 
bool TrackGroupProgress (int whichGroup, double frac, const TranslatableString &={}) const
 
int GetNumWaveTracks () const
 
int GetNumWaveGroups () const
 
void GetBounds (const WaveTrack &track, const WaveTrack *pRight, sampleCount *start, sampleCount *len)
 
void CopyInputTracks (bool allSyncLockSelected=false)
 
std::shared_ptr< AddedAnalysisTrackAddAnalysisTrack (const wxString &name=wxString())
 
ModifiedAnalysisTrack ModifyAnalysisTrack (const LabelTrack *pOrigTrack, const wxString &name=wxString())
 
TrackAddToOutputTracks (const std::shared_ptr< Track > &t)
 
- Protected Member Functions inherited from EffectBase
void Preview (EffectSettingsAccess &access, bool dryOnly) override
 
bool DoEffect (EffectSettings &settings, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, wxWindow *pParent, const EffectDialogFactory &dialogFactory, const EffectSettingsAccessPtr &pAccess) override
 Unfortunately complicated dual-use function. More...
 
virtual bool CheckWhetherSkipEffect (const EffectSettings &settings) const =0
 After Init(), tell whether Process() should be skipped. More...
 
virtual double CalcPreviewInputLength (const EffectSettings &settings, double previewLength) const =0
 
void SetLinearEffectFlag (bool linearEffectFlag)
 
void SetPreviewFullSelectionFlag (bool previewDurationFlag)
 
bool IsPreviewing () const
 
void IncludeNotSelectedPreviewTracks (bool includeNotSelected)
 
void ReplaceProcessedTracks (const bool bGoodResult)
 
const TrackListinputTracks () const
 
const AudacityProjectFindProject () const
 
- Protected Attributes inherited from Effect
wxWeakRef< wxDialog > mHostUIDialog
 This smart pointer tracks the lifetime of the dialog. More...
 
wxWindow * mUIParent {}
 
- Protected Attributes inherited from EffectBase
BasicUI::ProgressDialogmProgress {}
 
double mProjectRate {}
 
WaveTrackFactorymFactory {}
 
std::shared_ptr< TrackListmOutputTracks
 
double mT0 {}
 
double mT1 {}
 
wxArrayString mPresetNames
 
unsigned mUIFlags { 0 }
 
- Static Protected Attributes inherited from EffectBase
static int nEffectsDone = 0
 

Detailed Description

An Effect that reverses the selected audio.

Definition at line 18 of file Reverse.h.

Constructor & Destructor Documentation

◆ EffectReverse()

EffectReverse::EffectReverse ( )

Definition at line 39 of file Reverse.cpp.

40{
41}

◆ ~EffectReverse()

EffectReverse::~EffectReverse ( )
virtual

Definition at line 43 of file Reverse.cpp.

44{
45}

Member Function Documentation

◆ GetDescription()

TranslatableString EffectReverse::GetDescription ( ) const
overridevirtual

Reimplemented from Effect.

Definition at line 54 of file Reverse.cpp.

55{
56 return XO("Reverses the selected audio");
57}
#define XO(s)
Definition: Internat.h:31

References XO.

◆ GetSymbol()

ComponentInterfaceSymbol EffectReverse::GetSymbol ( ) const
overridevirtual

Reimplemented from Effect.

Definition at line 49 of file Reverse.cpp.

50{
51 return Symbol;
52}
static const ComponentInterfaceSymbol Symbol
Definition: Reverse.h:21

References Symbol.

◆ GetType()

EffectType EffectReverse::GetType ( ) const
overridevirtual

Type determines how it behaves.

Reimplemented from Effect.

Definition at line 61 of file Reverse.cpp.

62{
63 return EffectTypeProcess;
64}
@ EffectTypeProcess

References EffectTypeProcess.

◆ IsInteractive()

bool EffectReverse::IsInteractive ( ) const
overridevirtual

Whether the effect needs a dialog for entry of settings.

Reimplemented from Effect.

Definition at line 66 of file Reverse.cpp.

67{
68 return false;
69}

◆ Process()

bool EffectReverse::Process ( EffectInstance instance,
EffectSettings settings 
)
overridevirtual

Actually do the effect here.

Returns
success

Implements StatefulEffectBase.

Definition at line 73 of file Reverse.cpp.

74{
75 //all needed because Reverse should move the labels too
76 this->CopyInputTracks(true); // Set up mOutputTracks.
77 bool bGoodResult = true;
78 int count = 0;
79
80 auto trackRange =
82 trackRange.VisitWhile( bGoodResult,
83 [&](WaveTrack * track) {
84 if (mT1 > mT0) {
85 auto start = track->TimeToLongSamples(mT0);
86 auto end = track->TimeToLongSamples(mT1);
87 auto len = end - start;
88
89 if (!ProcessOneWave(count, track, start, len))
90 bGoodResult = false;
91 }
92 count++;
93 },
94 [&](LabelTrack * track) {
95 track->ChangeLabelsOnReverse(mT0, mT1);
96 count++;
97 }
98 );
99
100 this->ReplaceProcessedTracks(bGoodResult);
101 return bGoodResult;
102}
double mT1
Definition: EffectBase.h:109
std::shared_ptr< TrackList > mOutputTracks
Definition: EffectBase.h:107
double mT0
Definition: EffectBase.h:108
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: EffectBase.cpp:240
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:733
bool ProcessOneWave(int count, WaveTrack *track, sampleCount start, sampleCount len)
Definition: Reverse.cpp:104
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:89
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: SampleTrack.cpp:42
static bool IsSelectedOrSyncLockSelected(const Track *pTrack)
Definition: SyncLock.cpp:73
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References Effect::CopyInputTracks(), PackedArray::end(), SyncLock::IsSelectedOrSyncLockSelected(), EffectBase::mOutputTracks, EffectBase::mT0, EffectBase::mT1, ProcessOneWave(), EffectBase::ReplaceProcessedTracks(), and SampleTrack::TimeToLongSamples().

Here is the call graph for this function:

◆ ProcessOneClip()

bool EffectReverse::ProcessOneClip ( int  count,
WaveTrack track,
sampleCount  start,
sampleCount  len,
sampleCount  originalStart,
sampleCount  originalEnd 
)
private

Definition at line 216 of file Reverse.cpp.

219{
220 bool rc = true;
221 // keep track of two blocks whose data we will swap
222 auto first = start;
223
224 auto blockSize = track->GetMaxBlockSize();
225 float tmp;
226 Floats buffer1{ blockSize };
227 Floats buffer2{ blockSize };
228
229 auto originalLen = originalEnd - originalStart;
230
231 while (len > 1) {
232 auto block =
233 limitSampleBufferSize( track->GetBestBlockSize(first), len / 2 );
234 auto second = first + (len - block);
235
236 track->GetFloats(buffer1.get(), first, block);
237 track->GetFloats(buffer2.get(), second, block);
238 for (decltype(block) i = 0; i < block; i++) {
239 tmp = buffer1[i];
240 buffer1[i] = buffer2[block-i-1];
241 buffer2[block-i-1] = tmp;
242 }
243 track->Set((samplePtr)buffer1.get(), floatSample, first, block);
244 track->Set((samplePtr)buffer2.get(), floatSample, second, block);
245
246 len -= 2 * block;
247 first += block;
248
249 if( TrackProgress(count, 2 * ( first - originalStart ).as_double() /
250 originalLen.as_double() ) ) {
251 rc = false;
252 break;
253 }
254 }
255
256 return rc;
257}
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
@ floatSample
Definition: SampleFormat.h:34
char * samplePtr
Definition: SampleFormat.h:49
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
Definition: Effect.cpp:683
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
Retrieve samples from a track in floating-point format, regardless of the storage format.
Definition: SampleTrack.h:67
size_t GetMaxBlockSize() const override
This returns a nonnegative number of samples meant to size a memory buffer.
Definition: WaveTrack.cpp:1816
size_t GetBestBlockSize(sampleCount t) const override
This returns a nonnegative number of samples meant to size a memory buffer.
Definition: WaveTrack.cpp:1798
void Set(constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len)
Definition: WaveTrack.cpp:2205

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

Referenced by ProcessOneWave().

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

◆ ProcessOneWave()

bool EffectReverse::ProcessOneWave ( int  count,
WaveTrack track,
sampleCount  start,
sampleCount  len 
)
private

Definition at line 104 of file Reverse.cpp.

105{
106 bool rValue = true; // return value
107
108 auto end = start + len; // start, end, len refer to the selected reverse region
109
110 // STEP 1:
111 // If a reverse selection begins and/or ends at the inside of a clip
112 // perform a split at the start and/or end of the reverse selection
113 const auto &clips = track->GetClips();
114 // Beware, the array grows as we loop over it. Use integer subscripts, not iterators.
115 for (size_t ii = 0; ii < clips.size(); ++ii) {
116 const auto &clip = clips[ii].get();
117 auto clipStart = clip->GetPlayStartSample();
118 auto clipEnd = clip->GetPlayEndSample();
119 if (clipStart < start && clipEnd > start && clipEnd <= end) { // the reverse selection begins at the inside of a clip
120 double splitTime = track->LongSamplesToTime(start);
121 track->SplitAt(splitTime);
122 }
123 else if (clipStart >= start && clipStart < end && clipEnd > end) { // the reverse selection ends at the inside of a clip
124 double splitTime = track->LongSamplesToTime(end);
125 track->SplitAt(splitTime);
126 }
127 else if (clipStart < start && clipEnd > end) { // the selection begins AND ends at the inside of a clip
128 double splitTime = track->LongSamplesToTime(start);
129 track->SplitAt(splitTime);
130 splitTime = track->LongSamplesToTime(end);
131 track->SplitAt(splitTime);
132 }
133 }
134
135 //STEP 2:
136 // Individually reverse each clip inside the selected region
137 // and apply the appropriate offset after detaching them from the track
138
139 bool checkedFirstClip = false;
140
141 // used in calculating the offset of clips to rearrange
142 // holds the NEW end position of the current clip
143 auto currentEnd = end;
144
145 WaveClipHolders revClips; // holds the reversed clips
146 WaveClipHolders otherClips; // holds the clips that appear after the reverse selection region
147 auto clipArray = track->SortedClipArray();
148 size_t i;
149 for (i=0; i < clipArray.size(); i++) {
150
151 WaveClip *clip = clipArray[i];
152 auto clipStart = clip->GetPlayStartSample();
153 auto clipEnd = clip->GetPlayEndSample();
154
155 if (clipStart >= start && clipEnd <= end) { // if the clip is inside the selected region
156
157 // this is used to check if the selected region begins with a whitespace.
158 // if yes then clipStart (of the first clip) and start are not the same.
159 // adjust currentEnd accordingly and set endMerge to false
160 if(checkedFirstClip == false && clipStart > start) {
161 checkedFirstClip = true;
162 if(i > 0) {
163 if (clipArray[i-1]->GetPlayEndSample() <= start) {
164 currentEnd -= (clipStart - start);
165 }
166 }
167 else {
168 currentEnd -= (clipStart - start);
169 }
170 }
171
172 auto revStart = (clipStart >= start)? clipStart: start;
173 auto revEnd = (clipEnd >= end)? end: clipEnd;
174 auto revLen = revEnd - revStart;
175 if (revEnd >= revStart) {
176 if(!ProcessOneClip(count, track, revStart, revLen, start, end)) // reverse the clip
177 {
178 rValue = false;
179 break;
180 }
181
182 auto clipOffsetStart = currentEnd - (clipEnd - clipStart); // calculate the offset required
183 double offsetStartTime = track->LongSamplesToTime(clipOffsetStart);
184 if(i+1 < clipArray.size()) // update currentEnd if there is a clip to process next
185 {
186 auto nextClipStart = clipArray[i+1]->GetPlayStartSample();
187 currentEnd = currentEnd - (clipEnd - clipStart) - (nextClipStart - clipEnd);
188 }
189
190 revClips.push_back(track->RemoveAndReturnClip(clip)); // detach the clip from track
191 revClips.back()->SetPlayStartTime(track->LongSamplesToTime(track->TimeToLongSamples(offsetStartTime))); // align time to a sample and set offset
192 }
193 }
194 else if (clipStart >= end) { // clip is after the selection region
195 otherClips.push_back(track->RemoveAndReturnClip(clip)); // simply remove and append to otherClips
196 }
197 }
198
199 // STEP 3: Append the clips from
200 // revClips and otherClips back to the track
201 // the last clip of revClips is appended to the track first
202 // PRL: I don't think that matters, the sequence of storage of clips in the track
203 // is not elsewhere assumed to be by time
204 {
205 for (auto it = revClips.rbegin(), revEnd = revClips.rend(); rValue && it != revEnd; ++it)
206 rValue = track->AddClip(*it);
207 }
208
209 for (auto &clip : otherClips)
210 if (!(rValue = track->AddClip(clip)))
211 break;
212
213 return rValue;
214}
std::vector< WaveClipHolder > WaveClipHolders
Definition: WaveClip.h:42
bool ProcessOneClip(int count, WaveTrack *track, sampleCount start, sampleCount len, sampleCount originalStart, sampleCount originalEnd)
Definition: Reverse.cpp:216
double LongSamplesToTime(sampleCount pos) const
Convert correctly between a number of samples and an (absolute) time in seconds.
Definition: SampleTrack.cpp:47
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:101
sampleCount GetPlayEndSample() const
Definition: WaveClip.cpp:927
sampleCount GetPlayStartSample() const
Definition: WaveClip.cpp:922
void SplitAt(double t)
Definition: WaveTrack.cpp:2535
bool AddClip(const std::shared_ptr< WaveClip > &clip)
Append a clip to the track; which must have the same block factory as this track; return success.
Definition: WaveTrack.cpp:1230
WaveClipPointers SortedClipArray()
Definition: WaveTrack.cpp:2733
std::shared_ptr< WaveClip > RemoveAndReturnClip(WaveClip *clip)
Definition: WaveTrack.cpp:1217
WaveClipHolders & GetClips()
Definition: WaveTrack.h:329

References WaveTrack::AddClip(), PackedArray::end(), WaveTrack::GetClips(), WaveClip::GetPlayEndSample(), WaveClip::GetPlayStartSample(), SampleTrack::LongSamplesToTime(), ProcessOneClip(), WaveTrack::RemoveAndReturnClip(), WaveTrack::SortedClipArray(), WaveTrack::SplitAt(), and SampleTrack::TimeToLongSamples().

Referenced by Process().

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

Member Data Documentation

◆ Symbol

const ComponentInterfaceSymbol EffectReverse::Symbol { XO("Reverse") }
static

Definition at line 21 of file Reverse.h.

Referenced by GetSymbol().


The documentation for this class was generated from the following files: