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 This class reverses the selected audio.
10
11**********************************************************************/
12#include "Reverse.h"
13#include "EffectOutputTracks.h"
14#include "LabelTrack.h"
15#include "SyncLock.h"
16#include "WaveTrack.h"
17#include "WaveTrackUtilities.h"
18#include <algorithm>
19#include <cmath>
20
22{
23}
24
26{
27}
28
30
32{
33 return Symbol;
34}
35
37{
38 return XO("Reverses the selected audio");
39}
40
41// EffectDefinitionInterface implementation
42
44{
45 return EffectTypeProcess;
46}
47
49{
50 return false;
51}
52
53// Effect implementation
54
56{
57 // all needed because Reverse should move the labels too
58 EffectOutputTracks outputs {
59 *mTracks, GetType(), { { mT0, mT1 } }, true, true
60 };
61 bool bGoodResult = true;
62 int count = 0;
63
64 auto trackRange =
65 outputs.Get().Any() + &SyncLock::IsSelectedOrSyncLockSelectedP;
66 trackRange.VisitWhile(
67 bGoodResult,
68 [&](WaveTrack& track) {
69 const auto progress = [&](double fraction) {
70 return !TrackProgress(count, fraction);
71 };
72 if (mT1 > mT0)
73 {
74 auto start = track.TimeToLongSamples(mT0);
75 auto end = track.TimeToLongSamples(mT1);
76 auto len = end - start;
77
78 if (!WaveTrackUtilities::Reverse(track, start, len, progress))
79 bGoodResult = false;
80 }
81 count += track.NChannels();
82 },
83 [&](LabelTrack& track) {
84 track.ChangeLabelsOnReverse(mT0, mT1);
85 count++;
86 });
87
88 if (bGoodResult)
89 outputs.Commit();
90
91 return bGoodResult;
92}
EffectType
@ EffectTypeProcess
XO("Cut/Copy/Paste")
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
double mT1
Definition: EffectBase.h:123
std::shared_ptr< TrackList > mTracks
Definition: EffectBase.h:116
double mT0
Definition: EffectBase.h:122
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.
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:98
ComponentInterfaceSymbol GetSymbol() const override
Definition: Reverse.cpp:31
EffectType GetType() const override
Type determines how it behaves.
Definition: Reverse.cpp:43
bool IsInteractive() const override
Whether the effect needs a dialog for entry of settings.
Definition: Reverse.cpp:48
virtual ~Reverse()
Definition: Reverse.cpp:25
static const ComponentInterfaceSymbol Symbol
Definition: Reverse.h:22
bool Process(EffectInstance &instance, EffectSettings &settings) override
Definition: Reverse.cpp:55
Reverse()
Definition: Reverse.cpp:21
TranslatableString GetDescription() const override
Definition: Reverse.cpp:36
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:530
sampleCount TimeToLongSamples(double t0) const
WAVE_TRACK_API bool Reverse(WaveTrack &track, sampleCount start, sampleCount len, const ProgressReport &report={})
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
Externalized state of a plug-in.