Audacity 3.2.0
Reverse.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Reverse.cpp
6
7 Mark Phillips
8
9*******************************************************************//********************************************************************/
15#include "Reverse.h"
16#include "EffectOutputTracks.h"
17#include "LoadEffects.h"
18
19#include <algorithm>
20#include <math.h>
21
22#include "../LabelTrack.h"
23#include "SyncLock.h"
24#include "WaveClip.h"
25#include "WaveTrack.h"
26#include "WaveTrackUtilities.h"
27
28//
29// EffectReverse
30//
31
33{ XO("Reverse") };
34
36
38{
39}
40
42{
43}
44
45// ComponentInterface implementation
46
48{
49 return Symbol;
50}
51
53{
54 return XO("Reverses the selected audio");
55}
56
57// EffectDefinitionInterface implementation
58
60{
61 return EffectTypeProcess;
62}
63
65{
66 return false;
67}
68
69// Effect implementation
70
72{
73 //all needed because Reverse should move the labels too
74 EffectOutputTracks outputs {
75 *mTracks, GetType(), { { mT0, mT1 } }, true, true
76 };
77 bool bGoodResult = true;
78 int count = 0;
79
80 auto trackRange =
81 outputs.Get().Any() + &SyncLock::IsSelectedOrSyncLockSelectedP;
82 trackRange.VisitWhile(bGoodResult,
83 [&](WaveTrack &track) {
84 const auto progress =
85 [&](double fraction){ return !TrackProgress(count, fraction); };
86 if (mT1 > mT0) {
87 auto start = track.TimeToLongSamples(mT0);
88 auto end = track.TimeToLongSamples(mT1);
89 auto len = end - start;
90
91 if (!WaveTrackUtilities::Reverse(track, start, len, progress))
92 bGoodResult = false;
93 }
94 count += track.NChannels();
95 },
96 [&](LabelTrack &track) {
97 track.ChangeLabelsOnReverse(mT0, mT1);
98 count++;
99 }
100 );
101
102 if (bGoodResult)
103 outputs.Commit();
104
105 return bGoodResult;
106}
EffectType
@ EffectTypeProcess
XO("Cut/Copy/Paste")
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
double mT1
Definition: EffectBase.h:114
std::shared_ptr< TrackList > mTracks
Definition: EffectBase.h:107
double mT0
Definition: EffectBase.h:113
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
Definition: Effect.cpp:343
Performs effect computation.
Use this object to copy the input tracks to tentative outputTracks.
static const ComponentInterfaceSymbol Symbol
Definition: Reverse.h:22
ComponentInterfaceSymbol GetSymbol() const override
Definition: Reverse.cpp:47
EffectType GetType() const override
Type determines how it behaves.
Definition: Reverse.cpp:59
TranslatableString GetDescription() const override
Definition: Reverse.cpp:52
virtual ~EffectReverse()
Definition: Reverse.cpp:41
bool Process(EffectInstance &instance, EffectSettings &settings) override
Definition: Reverse.cpp:71
bool IsInteractive() const override
Whether the effect needs a dialog for entry of settings.
Definition: Reverse.cpp:64
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:95
static bool IsSelectedOrSyncLockSelectedP(const Track *pTrack)
Definition: SyncLock.h:61
Holds a msgid for the translation catalog; may also bind format arguments.
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
size_t NChannels() const override
A constant property.
Definition: WaveTrack.cpp:532
sampleCount TimeToLongSamples(double t0) const
WAVE_TRACK_API bool Reverse(WaveTrack &track, sampleCount start, sampleCount len, const ProgressReport &report={})
BuiltinEffectsModule::Registration< EffectReverse > reg
Definition: Reverse.cpp:35
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
Externalized state of a plug-in.