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
 
- Public Member Functions inherited from StatefulEffect
 ~StatefulEffect () override
 
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 ()
 
virtual bool Process (EffectInstance &instance, EffectSettings &settings)=0
 
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
 
virtual bool NeedsDither () const
 
virtual bool ProcessInitialize (EffectSettings &settings, double sampleRate, ChannelNames chanMap=nullptr)
 
virtual bool ProcessFinalize () noexcept
 
- 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
 
bool CanExportPresets () const override
 Whether the effect supports export of presets to files, and importing too. More...
 
bool HasOptions () const override
 
const EffectSettingsManagerGetDefinition () const override
 
virtual NumericFormatSymbol GetSelectionFormat ()
 
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
 
unsigned TestUIFlags (unsigned mask)
 
bool Delegate (Effect &delegate, EffectSettings &settings)
 Re-invoke DoEffect on another Effect object that implements the work. More...
 
- Public Member Functions inherited from EffectBase
 EffectBase ()
 
 ~EffectBase () override
 
void SetTracks (TrackList *pTracks)
 
bool DoEffect (EffectSettings &settings, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess) override
 
- Public Member Functions inherited from EffectPlugin
EffectPluginoperator= (EffectPlugin &)=delete
 
virtual ~EffectPlugin ()
 
virtual bool HasOptions () const =0
 
virtual bool CanExportPresets () const =0
 Whether the effect supports export of presets to files, and importing too. More...
 
virtual const EffectSettingsManagerGetDefinition () const =0
 
virtual void Preview (EffectSettingsAccess &access, std::function< void()> updateUI, bool dryOnly)=0
 Calculate temporary tracks of limited length with effect applied and play. More...
 
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, const InstanceFinder &finder, double projectRate, TrackList *list, WaveTrackFactory *factory, NotifyingSelectedRegion &selectedRegion, unsigned flags, const EffectSettingsAccessPtr &pAccess=nullptr)=0
 
- 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
 
- Public Member Functions inherited from StatefulEffectUIServices
 ~StatefulEffectUIServices () override
 
std::unique_ptr< EffectEditorPopulateUI (const EffectPlugin &plugin, ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) const override
 Allows PopulateOrExchange to return null. More...
 
virtual std::unique_ptr< EffectEditorPopulateOrExchange (ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs)
 Add controls to effect panel; always succeeds. More...
 
virtual bool TransferDataToWindow (const EffectSettings &settings)
 
virtual bool TransferDataFromWindow (EffectSettings &settings)
 
- Public Member Functions inherited from BasicEffectUIServices
int ShowClientInterface (const EffectPlugin &plugin, wxWindow &parent, wxDialog &dialog, EffectEditor *pEditor, bool forceModal) const override
 
void ExportPresets (const EffectPlugin &plugin, const EffectSettings &settings) const override
 
OptionalMessage ImportPresets (const EffectPlugin &plugin, EffectSettings &settings) const override
 
void ShowOptions (const EffectPlugin &plugin) const override
 
bool ValidateUI (const EffectPlugin &context, EffectSettings &) const override
 
bool CloseUI () const override
 
- Public Member Functions inherited from EffectUIServices
virtual ~EffectUIServices ()
 
virtual int ShowHostInterface (EffectPlugin &plugin, wxWindow &parent, const EffectDialogFactory &factory, std::shared_ptr< EffectInstance > &pInstance, EffectSettingsAccess &access, bool forceModal=false)
 
virtual int ShowClientInterface (const EffectPlugin &plugin, wxWindow &parent, wxDialog &dialog, EffectEditor *pEditor, bool forceModal=false) const =0
 
virtual std::unique_ptr< EffectEditorPopulateUI (const EffectPlugin &plugin, ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) const =0
 Adds controls to a panel that is given as the parent window of S More...
 
virtual void ExportPresets (const EffectPlugin &plugin, const EffectSettings &settings) const =0
 
virtual OptionalMessage ImportPresets (const EffectPlugin &plugin, EffectSettings &settings) const =0
 
virtual void ShowOptions (const EffectPlugin &plugin) const =0
 
virtual bool ValidateUI (const EffectPlugin &context, EffectSettings &settings) const =0
 
virtual bool CloseUI () const =0
 

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 EffectPlugin
using EffectSettingsAccessPtr = std::shared_ptr< EffectSettingsAccess >
 
using InstancePointer = std::shared_ptr< EffectInstanceEx >
 
using InstanceFinder = std::function< std::optional< InstancePointer >(EffectSettings &settings) >
 
- Public Types inherited from EffectDefinitionInterface
enum class  RealtimeSince : unsigned { Never , After_3_1 , Always }
 In which versions of Audacity was an effect realtime capable? More...
 
- Public Types inherited from EffectUIServices
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- 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...
 
- Static Public Member Functions inherited from EffectUIServices
static int DoMessageBox (const EffectPlugin &plugin, const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
 
- Public Attributes inherited from EffectBase
TrackListmTracks {}
 
- Protected Member Functions inherited from Effect
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...
 
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)
 
TrackAddToOutputTracks (const std::shared_ptr< Track > &t)
 
- Protected Member Functions inherited from EffectBase
virtual std::any BeginPreview (const EffectSettings &settings)
 Called when Preview() starts, to allow temporary effect state changes. More...
 
void Preview (EffectSettingsAccess &access, std::function< void()> updateUI, bool dryOnly) final
 Calculate temporary tracks of limited length with effect applied and play. 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 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 37 of file Reverse.cpp.

38{
39}

◆ ~EffectReverse()

EffectReverse::~EffectReverse ( )
virtual

Definition at line 41 of file Reverse.cpp.

42{
43}

Member Function Documentation

◆ GetDescription()

TranslatableString EffectReverse::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 52 of file Reverse.cpp.

53{
54 return XO("Reverses the selected audio");
55}
XO("Cut/Copy/Paste")

References XO().

Here is the call graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol EffectReverse::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 47 of file Reverse.cpp.

48{
49 return Symbol;
50}
static const ComponentInterfaceSymbol Symbol
Definition: Reverse.h:21

References Symbol.

◆ GetType()

EffectType EffectReverse::GetType ( ) const
overridevirtual

Type determines how it behaves.

Implements EffectDefinitionInterface.

Definition at line 59 of file Reverse.cpp.

60{
61 return EffectTypeProcess;
62}
@ EffectTypeProcess

References EffectTypeProcess.

◆ IsInteractive()

bool EffectReverse::IsInteractive ( ) const
overridevirtual

Whether the effect needs a dialog for entry of settings.

Implements EffectDefinitionInterface.

Definition at line 64 of file Reverse.cpp.

65{
66 return false;
67}

◆ Process()

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

Implements StatefulEffectBase.

Definition at line 71 of file Reverse.cpp.

72{
73 //all needed because Reverse should move the labels too
74 this->CopyInputTracks(true); // Set up mOutputTracks.
75 bool bGoodResult = true;
76 int count = 0;
77
78 auto trackRange =
80 trackRange.VisitWhile( bGoodResult,
81 [&](WaveTrack * track) {
82 if (mT1 > mT0) {
83 auto start = track->TimeToLongSamples(mT0);
84 auto end = track->TimeToLongSamples(mT1);
85 auto len = end - start;
86
87 if (!ProcessOneWave(count, track, start, len))
88 bGoodResult = false;
89 }
90 count++;
91 },
92 [&](LabelTrack * track) {
93 track->ChangeLabelsOnReverse(mT0, mT1);
94 count++;
95 }
96 );
97
98 this->ReplaceProcessedTracks(bGoodResult);
99 return bGoodResult;
100}
double mT1
Definition: EffectBase.h:113
std::shared_ptr< TrackList > mOutputTracks
Definition: EffectBase.h:111
double mT0
Definition: EffectBase.h:112
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: EffectBase.cpp:232
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:396
bool ProcessOneWave(int count, WaveTrack *track, sampleCount start, sampleCount len)
Definition: Reverse.cpp:102
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:87
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: SampleTrack.cpp:43
static bool IsSelectedOrSyncLockSelected(const Track *pTrack)
Definition: SyncLock.cpp:112
A Track that contains audio waveform data.
Definition: WaveTrack.h:51
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 214 of file Reverse.cpp.

217{
218 bool rc = true;
219 // keep track of two blocks whose data we will swap
220 auto first = start;
221
222 auto blockSize = track->GetMaxBlockSize();
223 float tmp;
224 Floats buffer1{ blockSize };
225 Floats buffer2{ blockSize };
226
227 auto originalLen = originalEnd - originalStart;
228
229 while (len > 1) {
230 auto block =
231 limitSampleBufferSize( track->GetBestBlockSize(first), len / 2 );
232 auto second = first + (len - block);
233
234 track->GetFloats(buffer1.get(), first, block);
235 track->GetFloats(buffer2.get(), second, block);
236 for (decltype(block) i = 0; i < block; i++) {
237 tmp = buffer1[i];
238 buffer1[i] = buffer2[block-i-1];
239 buffer2[block-i-1] = tmp;
240 }
241 // Don't dither on later rendering if only reversing samples
242 track->Set((samplePtr)buffer1.get(), floatSample, first, block,
244 track->Set((samplePtr)buffer2.get(), floatSample, second, block,
246
247 len -= 2 * block;
248 first += block;
249
250 if( TrackProgress(count, 2 * ( first - originalStart ).as_double() /
251 originalLen.as_double() ) ) {
252 rc = false;
253 break;
254 }
255 }
256
257 return rc;
258}
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
@ narrowestSampleFormat
Two synonyms for previous values that might change if more values were added.
char * samplePtr
Definition: SampleFormat.h:55
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
Definition: Effect.cpp:346
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:82
size_t GetMaxBlockSize() const override
This returns a nonnegative number of samples meant to size a memory buffer.
Definition: WaveTrack.cpp:1611
size_t GetBestBlockSize(sampleCount t) const override
This returns a nonnegative number of samples meant to size a memory buffer.
Definition: WaveTrack.cpp:1593
void Set(constSamplePtr buffer, sampleFormat format, sampleCount start, size_t len, sampleFormat effectiveFormat=widestSampleFormat)
Definition: WaveTrack.cpp:2002

References floatSample, WaveTrack::GetBestBlockSize(), SampleTrack::GetFloats(), WaveTrack::GetMaxBlockSize(), limitSampleBufferSize(), narrowestSampleFormat, 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 102 of file Reverse.cpp.

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

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: