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
16
17
18#include "Reverse.h"
19#include "EffectOutputTracks.h"
20#include "LoadEffects.h"
21
22#include <algorithm>
23#include <math.h>
24
25#include "../LabelTrack.h"
26#include "SyncLock.h"
27#include "WaveClip.h"
28#include "WaveTrack.h"
29
30//
31// EffectReverse
32//
33
35{ XO("Reverse") };
36
38
40{
41}
42
44{
45}
46
47// ComponentInterface implementation
48
50{
51 return Symbol;
52}
53
55{
56 return XO("Reverses the selected audio");
57}
58
59// EffectDefinitionInterface implementation
60
62{
63 return EffectTypeProcess;
64}
65
67{
68 return false;
69}
70
71// Effect implementation
72
74{
75 //all needed because Reverse should move the labels too
76 EffectOutputTracks outputs {
77 *mTracks, GetType(), { { mT0, mT1 } }, true, true
78 };
79 bool bGoodResult = true;
80 int count = 0;
81
82 auto trackRange =
83 outputs.Get().Any() + &SyncLock::IsSelectedOrSyncLockSelected;
84 trackRange.VisitWhile(bGoodResult,
85 [&](WaveTrack &track) {
86 const auto progress =
87 [&](double fraction){ return !TrackProgress(count, fraction); };
88 if (mT1 > mT0) {
89 auto start = track.TimeToLongSamples(mT0);
90 auto end = track.TimeToLongSamples(mT1);
91 auto len = end - start;
92
93 if (!track.Reverse(start, len, progress))
94 bGoodResult = false;
95 }
96 count += track.NChannels();
97 },
98 [&](LabelTrack &track) {
99 track.ChangeLabelsOnReverse(mT0, mT1);
100 count++;
101 }
102 );
103
104 if (bGoodResult)
105 outputs.Commit();
106
107 return bGoodResult;
108}
EffectType
@ EffectTypeProcess
XO("Cut/Copy/Paste")
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
double mT1
Definition: EffectBase.h:116
std::shared_ptr< TrackList > mTracks
Definition: EffectBase.h:109
double mT0
Definition: EffectBase.h:115
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:49
EffectType GetType() const override
Type determines how it behaves.
Definition: Reverse.cpp:61
TranslatableString GetDescription() const override
Definition: Reverse.cpp:54
virtual ~EffectReverse()
Definition: Reverse.cpp:43
bool Process(EffectInstance &instance, EffectSettings &settings) override
Definition: Reverse.cpp:73
bool IsInteractive() const override
Whether the effect needs a dialog for entry of settings.
Definition: Reverse.cpp:66
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:87
static bool IsSelectedOrSyncLockSelected(const Track *pTrack)
Definition: SyncLock.cpp:112
Holds a msgid for the translation catalog; may also bind format arguments.
A Track that contains audio waveform data.
Definition: WaveTrack.h:227
size_t NChannels() const override
May report more than one only when this is a leader track.
Definition: WaveTrack.cpp:849
bool Reverse(sampleCount start, sampleCount len, const ProgressReport &report={})
Definition: WaveTrack.cpp:4217
sampleCount TimeToLongSamples(double t0) const
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
BuiltinEffectsModule::Registration< EffectReverse > reg
Definition: Reverse.cpp:37
Externalized state of a plug-in.