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#include "Repeat.h"
22#include "EffectEditor.h"
23
24#include <math.h>
25
26#include <wx/stattext.h>
27
28#include "../LabelTrack.h"
29#include "ShuttleGui.h"
30#include "SyncLock.h"
31#include "WaveTrack.h"
32#include "WaveClip.h"
33#include "../widgets/NumericTextCtrl.h"
34#include "../widgets/valnum.h"
35
36#include "LoadEffects.h"
37
39{
41 Count
42 > parameters;
43 return parameters;
44}
45
47{ XO("Repeat") };
48
50
51BEGIN_EVENT_TABLE(EffectRepeat, wxEvtHandler)
52 EVT_TEXT(wxID_ANY, EffectRepeat::OnRepeatTextChange)
54
56{
57 Parameters().Reset(*this);
58 SetLinearEffectFlag(true);
59}
60
62{
63}
64
65// ComponentInterface implementation
66
68{
69 return Symbol;
70}
71
73{
74 return XO("Repeats the selection the specified number of times");
75}
76
78{
79 return L"Repeat";
80}
81
82// EffectDefinitionInterface implementation
83
85{
86 return EffectTypeProcess;
87}
88
89// Effect implementation
90
92{
93 // Set up mOutputTracks.
94 // This effect needs all for sync-lock grouping.
95 CopyInputTracks(true);
96
97 int nTrack = 0;
98 bool bGoodResult = true;
99 double maxDestLen = 0.0; // used to change selection to generated bit
100
101 mOutputTracks->Any().VisitWhile( bGoodResult,
102 [&](LabelTrack *track)
103 {
105 {
106 if (!track->Repeat(mT0, mT1, repeatCount))
107 bGoodResult = false;
108 }
109 },
110 [&](WaveTrack *track, const Track::Fallthrough &fallthrough)
111 {
112 if (!track->GetSelected())
113 return fallthrough(); // Fall through to next lambda
114 auto start = track->TimeToLongSamples(mT0);
115 auto end = track->TimeToLongSamples(mT1);
116 auto len = end - start;
117 const double tLen = track->LongSamplesToTime(len);
118 const double tc = mT0 + tLen;
119
120 if (len <= 0)
121 return;
122
123 auto dest = std::dynamic_pointer_cast<WaveTrack>(track->Copy(mT0, mT1));
124 std::vector<wxString> clipNames;
125 for(auto clip : dest->SortedClipArray())
126 {
127 if(!clip->GetIsPlaceholder())
128 clipNames.push_back(clip->GetName());
129 }
130 auto t0 = tc;
131 for(int j=0; j<repeatCount; j++)
132 {
133 if (TrackProgress(nTrack, j / repeatCount)) // TrackProgress returns true on Cancel.
134 {
135 bGoodResult = false;
136 return;
137 }
138 track->Paste(t0, dest.get());
139 t0 += tLen;
140 }
141 if (t0 > maxDestLen)
142 maxDestLen = t0;
143
144 auto clips = track->SortedClipArray();
145 for(size_t i = 0; i < clips.size(); ++i)
146 {
147 const auto eps = 0.5 / track->GetRate();
148 //Find first pasted clip
149 if(std::abs(clips[i]->GetPlayStartTime() - tc) > eps)
150 continue;
151
152 //Fix pasted clips names
153 for(int j = 0; j < repeatCount; ++j)
154 {
155 for(size_t k = 0; k < clipNames.size(); ++k)
156 clips[i + k]->SetName(clipNames[k]);
157 i += clipNames.size();
158 }
159 break;
160 }
161
162 nTrack++;
163 },
164 [&](Track *t)
165 {
167 t->SyncLockAdjust(mT1, mT1 + (mT1 - mT0) * repeatCount);
168 }
169 );
170
171 if (bGoodResult)
172 {
173 // Select the NEW bits + original bit
174 mT1 = maxDestLen;
175 }
176
177 ReplaceProcessedTracks(bGoodResult);
178 return bGoodResult;
179}
180
181std::unique_ptr<EffectEditor> EffectRepeat::PopulateOrExchange(
183 const EffectOutputs *)
184{
185 mUIParent = S.GetParent();
186 S.StartHorizontalLay(wxCENTER, false);
187 {
188 mRepeatCount = S.Validator<IntegerValidator<int>>(
189 &repeatCount, NumValidatorStyle::DEFAULT,
190 Count.min, 2147483647 / mProjectRate )
191 .AddTextBox(XXO("&Number of repeats to add:"), L"", 12);
192 }
193 S.EndHorizontalLay();
194
195 S.StartMultiColumn(1, wxCENTER);
196 {
197 mCurrentTime = S.AddVariableText(
198 XO("Current selection length: dd:hh:mm:ss"));
199 mTotalTime = S.AddVariableText(XO("New selection length: dd:hh:mm:ss"));
200 }
201 S.EndMultiColumn();
202 return nullptr;
203}
204
206{
207 mRepeatCount->ChangeValue(wxString::Format(wxT("%d"), repeatCount));
208
210
211 return true;
212}
213
215{
216 if (!mUIParent->Validate())
217 {
218 return false;
219 }
220
221 long l;
222
223 mRepeatCount->GetValue().ToLong(&l);
224
225 repeatCount = (int) l;
226
227 return true;
228}
229
231{
232 long l;
233 wxString str;
234 mRepeatCount->GetValue().ToLong(&l);
235
238 mT1 - mT0,
240
241 str = wxString::Format( _("Current selection length: %s"), nc.GetString() );
242
243 mCurrentTime->SetLabel(str);
244 mCurrentTime->SetName(str); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
245
246 if (l > 0) {
248 repeatCount = l;
249
250 nc.SetValue((mT1 - mT0) * (repeatCount + 1));
251 str = wxString::Format( _("New selection length: %s"), nc.GetString() );
252 }
253 else {
254 str = _("Warning: No repeats.");
256 }
257 mTotalTime->SetLabel(str);
258 mTotalTime->SetName(str); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
259}
260
261void EffectRepeat::OnRepeatTextChange(wxCommandEvent & WXUNUSED(evt))
262{
264}
265
267{
268 return false;
269}
wxT("CloseDown"))
END_EVENT_TABLE()
#define str(a)
EffectType
@ EffectTypeProcess
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#define _(s)
Definition: Internat.h:73
#define S(N)
Definition: ToChars.cpp:64
Generates EffectParameterMethods overrides from variadic template arguments.
size_t size() const
How many attachment pointers are in the Site.
Definition: ClientData.h:251
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
double mT1
Definition: EffectBase.h:113
std::shared_ptr< TrackList > mOutputTracks
Definition: EffectBase.h:111
double mProjectRate
Definition: EffectBase.h:105
double mT0
Definition: EffectBase.h:112
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: EffectBase.cpp:232
static bool EnableApply(wxWindow *parent, bool enable=true)
Enable or disable the Apply button of the dialog that contains parent.
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:396
virtual NumericFormatSymbol GetSelectionFormat()
Definition: Effect.cpp:195
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
Definition: Effect.cpp:346
Performs effect computation.
Hold values to send to effect output meters.
Interface for manipulations of an Effect's settings.
An Effect that repeats audio several times over.
Definition: Repeat.h:24
ComponentInterfaceSymbol GetSymbol() const override
Definition: Repeat.cpp:67
wxStaticText * mTotalTime
Definition: Repeat.h:66
wxWeakRef< wxWindow > mUIParent
Definition: Repeat.h:60
int repeatCount
Definition: Repeat.h:62
bool NeedsDither() const override
Definition: Repeat.cpp:266
bool Process(EffectInstance &instance, EffectSettings &settings) override
Definition: Repeat.cpp:91
static const ComponentInterfaceSymbol Symbol
Definition: Repeat.h:28
const EffectParameterMethods & Parameters() const override
Definition: Repeat.cpp:38
wxTextCtrl * mRepeatCount
Definition: Repeat.h:64
std::unique_ptr< EffectEditor > PopulateOrExchange(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
Add controls to effect panel; always succeeds.
Definition: Repeat.cpp:181
virtual ~EffectRepeat()
Definition: Repeat.cpp:61
bool TransferDataToWindow(const EffectSettings &settings) override
Definition: Repeat.cpp:205
TranslatableString GetDescription() const override
Definition: Repeat.cpp:72
ManualPageID ManualPage() const override
Name of a page in the Audacity alpha manual, default is empty.
Definition: Repeat.cpp:77
EffectRepeat()
Definition: Repeat.cpp:55
void DisplayNewTime()
Definition: Repeat.cpp:230
void OnRepeatTextChange(wxCommandEvent &evt)
Definition: Repeat.cpp:261
static constexpr EffectParameter Count
Definition: Repeat.h:71
bool TransferDataFromWindow(EffectSettings &settings) override
Definition: Repeat.cpp:214
EffectType GetType() const override
Type determines how it behaves.
Definition: Repeat.cpp:84
wxStaticText * mCurrentTime
Definition: Repeat.h:65
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:87
bool Repeat(double t0, double t1, int n)
Definition: LabelTrack.cpp:804
void Paste(double t, const Track *src) override
Definition: LabelTrack.cpp:787
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
Definition: LabelTrack.cpp:706
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:625
static bool IsSelectedOrSyncLockSelected(const Track *pTrack)
Definition: SyncLock.cpp:112
static bool IsSyncLockSelected(const Track *pTrack)
Definition: SyncLock.cpp:82
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:226
bool GetSelected() const
Definition: Track.h:470
Continuation<> Fallthrough
Type of arguments passed as optional second parameter to TypeSwitch<void>() cases.
Definition: Track.h:542
Holds a msgid for the translation catalog; may also bind format arguments.
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
BuiltinEffectsModule::Registration< EffectRepeat > reg
Definition: Repeat.cpp:49
const Type min
Minimum value.
Externalized state of a plug-in.