Audacity 3.2.0
Repeat.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Repeat.cpp
6
7 Dominic Mazzoni
8 Vaughan Johnson
9
10*******************************************************************//****************************************************************//*******************************************************************/
21
22
23
24#include "Repeat.h"
25
26
27#include <math.h>
28
29#include <wx/intl.h>
30#include <wx/stattext.h>
31
32#include "../LabelTrack.h"
33#include "../ShuttleGui.h"
34#include "../SyncLock.h"
35#include "../WaveTrack.h"
36#include "../widgets/NumericTextCtrl.h"
37#include "../widgets/valnum.h"
38
39#include "LoadEffects.h"
40
42{
44 Count
45 > parameters;
46 return parameters;
47}
48
50{ XO("Repeat") };
51
53
54BEGIN_EVENT_TABLE(EffectRepeat, wxEvtHandler)
55 EVT_TEXT(wxID_ANY, EffectRepeat::OnRepeatTextChange)
57
59{
60 Parameters().Reset(*this);
61 SetLinearEffectFlag(true);
62}
63
65{
66}
67
68// ComponentInterface implementation
69
71{
72 return Symbol;
73}
74
76{
77 return XO("Repeats the selection the specified number of times");
78}
79
81{
82 return L"Repeat";
83}
84
85// EffectDefinitionInterface implementation
86
88{
89 return EffectTypeProcess;
90}
91
92// Effect implementation
93
95{
96 // Set up mOutputTracks.
97 // This effect needs all for sync-lock grouping.
98 CopyInputTracks(true);
99
100 int nTrack = 0;
101 bool bGoodResult = true;
102 double maxDestLen = 0.0; // used to change selection to generated bit
103
104 mOutputTracks->Any().VisitWhile( bGoodResult,
105 [&](LabelTrack *track)
106 {
108 {
109 if (!track->Repeat(mT0, mT1, repeatCount))
110 bGoodResult = false;
111 }
112 },
113 [&](WaveTrack *track, const Track::Fallthrough &fallthrough)
114 {
115 if (!track->GetSelected())
116 return fallthrough(); // Fall through to next lambda
117 auto start = track->TimeToLongSamples(mT0);
118 auto end = track->TimeToLongSamples(mT1);
119 auto len = end - start;
120 double tLen = track->LongSamplesToTime(len);
121 double tc = mT0 + tLen;
122
123 if (len <= 0)
124 return;
125
126 auto dest = track->Copy(mT0, mT1);
127 for(int j=0; j<repeatCount; j++)
128 {
129 if (TrackProgress(nTrack, j / repeatCount)) // TrackProgress returns true on Cancel.
130 {
131 bGoodResult = false;
132 return;
133 }
134 track->Paste(tc, dest.get());
135 tc += tLen;
136 }
137 if (tc > maxDestLen)
138 maxDestLen = tc;
139 nTrack++;
140 },
141 [&](Track *t)
142 {
144 t->SyncLockAdjust(mT1, mT1 + (mT1 - mT0) * repeatCount);
145 }
146 );
147
148 if (bGoodResult)
149 {
150 // Select the NEW bits + original bit
151 mT1 = maxDestLen;
152 }
153
154 ReplaceProcessedTracks(bGoodResult);
155 return bGoodResult;
156}
157
158std::unique_ptr<EffectUIValidator> EffectRepeat::PopulateOrExchange(
160{
161 S.StartHorizontalLay(wxCENTER, false);
162 {
163 mRepeatCount = S.Validator<IntegerValidator<int>>(
164 &repeatCount, NumValidatorStyle::DEFAULT,
165 Count.min, 2147483647 / mProjectRate )
166 .AddTextBox(XXO("&Number of repeats to add:"), L"", 12);
167 }
168 S.EndHorizontalLay();
169
170 S.StartMultiColumn(1, wxCENTER);
171 {
172 mCurrentTime = S.AddVariableText(
173 XO("Current selection length: dd:hh:mm:ss"));
174 mTotalTime = S.AddVariableText(XO("New selection length: dd:hh:mm:ss"));
175 }
176 S.EndMultiColumn();
177 return nullptr;
178}
179
181{
182 mRepeatCount->ChangeValue(wxString::Format(wxT("%d"), repeatCount));
183
185
186 return true;
187}
188
190{
191 long l;
192
193 mRepeatCount->GetValue().ToLong(&l);
194
195 repeatCount = (int) l;
196
197 return true;
198}
199
201{
202 long l;
203 wxString str;
204 mRepeatCount->GetValue().ToLong(&l);
205
208 mT1 - mT0,
210
211 str = wxString::Format( _("Current selection length: %s"), nc.GetString() );
212
213 mCurrentTime->SetLabel(str);
214 mCurrentTime->SetName(str); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
215
216 if (l > 0) {
217 EnableApply(true);
218 repeatCount = l;
219
220 nc.SetValue((mT1 - mT0) * (repeatCount + 1));
221 str = wxString::Format( _("New selection length: %s"), nc.GetString() );
222 }
223 else {
224 str = _("Warning: No repeats.");
225 EnableApply(false);
226 }
227 mTotalTime->SetLabel(str);
228 mTotalTime->SetName(str); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
229}
230
231void EffectRepeat::OnRepeatTextChange(wxCommandEvent & WXUNUSED(evt))
232{
234}
END_EVENT_TABLE()
#define str(a)
EffectType
@ EffectTypeProcess
#define XXO(s)
Definition: Internat.h:44
#define XO(s)
Definition: Internat.h:31
#define _(s)
Definition: Internat.h:75
#define S(N)
Definition: ToChars.cpp:64
Generates EffectParameterMethods overrides from variadic template arguments.
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
double mT1
Definition: EffectBase.h:107
std::shared_ptr< TrackList > mOutputTracks
Definition: EffectBase.h:105
double mProjectRate
Definition: EffectBase.h:99
double mT0
Definition: EffectBase.h:106
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: EffectBase.cpp:236
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:739
bool EnableApply(bool enable=true)
Definition: Effect.cpp:613
virtual NumericFormatSymbol GetSelectionFormat()
Definition: Effect.cpp:458
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
Definition: Effect.cpp:691
Performs effect computation.
Interface for manipulations of an Effect's settings.
An Effect that repeats audio several times over.
Definition: Repeat.h:23
ComponentInterfaceSymbol GetSymbol() const override
Definition: Repeat.cpp:70
std::unique_ptr< EffectUIValidator > PopulateOrExchange(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access) override
Add controls to effect panel; always succeeds.
Definition: Repeat.cpp:158
wxStaticText * mTotalTime
Definition: Repeat.h:61
int repeatCount
Definition: Repeat.h:57
bool Process(EffectInstance &instance, EffectSettings &settings) override
Actually do the effect here.
Definition: Repeat.cpp:94
static const ComponentInterfaceSymbol Symbol
Definition: Repeat.h:27
const EffectParameterMethods & Parameters() const override
Definition: Repeat.cpp:41
wxTextCtrl * mRepeatCount
Definition: Repeat.h:59
virtual ~EffectRepeat()
Definition: Repeat.cpp:64
bool TransferDataToWindow(const EffectSettings &settings) override
Update controls for the settings.
Definition: Repeat.cpp:180
TranslatableString GetDescription() const override
Definition: Repeat.cpp:75
ManualPageID ManualPage() const override
Name of a page in the Audacity alpha manual, default is empty.
Definition: Repeat.cpp:80
EffectRepeat()
Definition: Repeat.cpp:58
void DisplayNewTime()
Definition: Repeat.cpp:200
void OnRepeatTextChange(wxCommandEvent &evt)
Definition: Repeat.cpp:231
static constexpr EffectParameter Count
Definition: Repeat.h:66
bool TransferDataFromWindow(EffectSettings &settings) override
Update the given settings from controls.
Definition: Repeat.cpp:189
EffectType GetType() const override
Type determines how it behaves.
Definition: Repeat.cpp:87
wxStaticText * mCurrentTime
Definition: Repeat.h:60
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:89
bool Repeat(double t0, double t1, int n)
Definition: LabelTrack.cpp:810
void Paste(double t, const Track *src) override
Definition: LabelTrack.cpp:793
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
Definition: LabelTrack.cpp:712
NumericConverter provides the advanced formatting control used in the selection bar of Audacity.
void SetValue(double newValue)
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:628
static bool IsSelectedOrSyncLockSelected(const Track *pTrack)
Definition: SyncLock.cpp:73
static bool IsSyncLockSelected(const Track *pTrack)
Definition: SyncLock.cpp:43
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
bool GetSelected() const
Definition: Track.h:461
Continuation<> Fallthrough
Type of arguments passed as optional second parameter to TypeSwitch<void>() cases.
Definition: Track.h:533
Holds a msgid for the translation catalog; may also bind format arguments.
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
BuiltinEffectsModule::Registration< EffectRepeat > reg
Definition: Repeat.cpp:52
const Type min
Minimum value.
Definition: Shuttle.h:30
Externalized state of a plug-in.