Audacity  3.0.3
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 "../Shuttle.h"
34 #include "../ShuttleGui.h"
35 #include "../WaveTrack.h"
36 #include "../widgets/NumericTextCtrl.h"
37 #include "../widgets/valnum.h"
38 
39 #include "LoadEffects.h"
40 
41 // Define keys, defaults, minimums, and maximums for the effect parameters
42 //
43 // Name Type Key Def Min Max Scale
44 Param( Count, int, wxT("Count"), 1, 1, INT_MAX, 1 );
45 
47 { XO("Repeat") };
48 
50 
51 BEGIN_EVENT_TABLE(EffectRepeat, wxEvtHandler)
52  EVT_TEXT(wxID_ANY, EffectRepeat::OnRepeatTextChange)
54 
56 {
57  repeatCount = DEF_Count;
58 
59  SetLinearEffectFlag(true);
60 }
61 
63 {
64 }
65 
66 // ComponentInterface implementation
67 
69 {
70  return Symbol;
71 }
72 
74 {
75  return XO("Repeats the selection the specified number of times");
76 }
77 
79 {
80  return L"Repeat";
81 }
82 
83 // EffectDefinitionInterface implementation
84 
86 {
87  return EffectTypeProcess;
88 }
89 
90 // EffectClientInterface implementation
92  S.SHUTTLE_PARAM( repeatCount, Count );
93  return true;
94 }
95 
97 {
98  parms.Write(KEY_Count, repeatCount);
99 
100  return true;
101 }
102 
104 {
105  ReadAndVerifyInt(Count);
106 
107  repeatCount = Count;
108 
109  return true;
110 }
111 
112 // Effect implementation
113 
115 {
116  // Set up mOutputTracks.
117  // This effect needs all for sync-lock grouping.
118  CopyInputTracks(true);
119 
120  int nTrack = 0;
121  bool bGoodResult = true;
122  double maxDestLen = 0.0; // used to change selection to generated bit
123 
124  mOutputTracks->Any().VisitWhile( bGoodResult,
125  [&](LabelTrack *track)
126  {
127  if (track->GetSelected() || track->IsSyncLockSelected())
128  {
129  if (!track->Repeat(mT0, mT1, repeatCount))
130  bGoodResult = false;
131  }
132  },
133  [&](WaveTrack *track, const Track::Fallthrough &fallthrough)
134  {
135  if (!track->GetSelected())
136  return fallthrough(); // Fall through to next lambda
137  auto start = track->TimeToLongSamples(mT0);
138  auto end = track->TimeToLongSamples(mT1);
139  auto len = end - start;
140  double tLen = track->LongSamplesToTime(len);
141  double tc = mT0 + tLen;
142 
143  if (len <= 0)
144  return;
145 
146  auto dest = track->Copy(mT0, mT1);
147  for(int j=0; j<repeatCount; j++)
148  {
149  if (TrackProgress(nTrack, j / repeatCount)) // TrackProgress returns true on Cancel.
150  {
151  bGoodResult = false;
152  return;
153  }
154  track->Paste(tc, dest.get());
155  tc += tLen;
156  }
157  if (tc > maxDestLen)
158  maxDestLen = tc;
159  nTrack++;
160  },
161  [&](Track *t)
162  {
163  if( t->IsSyncLockSelected() )
164  t->SyncLockAdjust(mT1, mT1 + (mT1 - mT0) * repeatCount);
165  }
166  );
167 
168  if (bGoodResult)
169  {
170  // Select the NEW bits + original bit
171  mT1 = maxDestLen;
172  }
173 
174  ReplaceProcessedTracks(bGoodResult);
175  return bGoodResult;
176 }
177 
179 {
180  S.StartHorizontalLay(wxCENTER, false);
181  {
182  mRepeatCount = S.Validator<IntegerValidator<int>>(
183  &repeatCount, NumValidatorStyle::DEFAULT,
184  MIN_Count, 2147483647 / mProjectRate
185  )
186  .AddTextBox(XXO("&Number of repeats to add:"), wxT(""), 12);
187  }
188  S.EndHorizontalLay();
189 
190  S.StartMultiColumn(1, wxCENTER);
191  {
193  XO("Current selection length: dd:hh:mm:ss"));
194  mTotalTime = S.AddVariableText(XO("New selection length: dd:hh:mm:ss"));
195  }
196  S.EndMultiColumn();
197 }
198 
200 {
201  mRepeatCount->ChangeValue(wxString::Format(wxT("%d"), repeatCount));
202 
203  DisplayNewTime();
204 
205  return true;
206 }
207 
209 {
210  if (!mUIParent->Validate())
211  {
212  return false;
213  }
214 
215  long l;
216 
217  mRepeatCount->GetValue().ToLong(&l);
218 
219  repeatCount = (int) l;
220 
221  return true;
222 }
223 
225 {
226  long l;
227  wxString str;
228  mRepeatCount->GetValue().ToLong(&l);
229 
232  mT1 - mT0,
233  mProjectRate);
234 
235  str = wxString::Format( _("Current selection length: %s"), nc.GetString() );
236 
237  mCurrentTime->SetLabel(str);
238  mCurrentTime->SetName(str); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
239 
240  if (l > 0) {
241  EnableApply(true);
242  repeatCount = l;
243 
244  nc.SetValue((mT1 - mT0) * (repeatCount + 1));
245  str = wxString::Format( _("New selection length: %s"), nc.GetString() );
246  }
247  else {
248  str = _("Warning: No repeats.");
249  EnableApply(false);
250  }
251  mTotalTime->SetLabel(str);
252  mTotalTime->SetName(str); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
253 }
254 
255 void EffectRepeat::OnRepeatTextChange(wxCommandEvent & WXUNUSED(evt))
256 {
257  DisplayNewTime();
258 }
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
CommandParameters
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the Shuttle cla...
Definition: EffectAutomationParameters.h:67
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
EffectTypeProcess
@ EffectTypeProcess
Definition: EffectInterface.h:59
Effect::EnableApply
virtual bool EnableApply(bool enable=true)
Definition: Effect.cpp:1926
Effect::GetSelectionFormat
virtual NumericFormatSymbol GetSelectionFormat()
Definition: Effect.cpp:831
EffectRepeat::DisplayNewTime
void DisplayNewTime()
Definition: Repeat.cpp:224
Effect::CopyInputTracks
void CopyInputTracks(bool allSyncLockSelected=false)
Definition: Effect.cpp:2071
str
#define str(a)
Definition: DBConnection.cpp:30
Effect::mT1
double mT1
Definition: Effect.h:467
EffectRepeat::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: Repeat.h:24
XO
#define XO(s)
Definition: Internat.h:31
ShuttleParams
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:62
LabelTrack
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:88
EffectRepeat::Process
bool Process() override
Definition: Repeat.cpp:114
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1238
EffectRepeat::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: Repeat.cpp:91
WaveTrack::Copy
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
Definition: WaveTrack.cpp:680
Track::IsSyncLockSelected
bool IsSyncLockSelected() const
Definition: Track.cpp:254
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
EffectRepeat::SetAutomationParameters
bool SetAutomationParameters(CommandParameters &parms) override
Definition: Repeat.cpp:103
Effect::mProjectRate
double mProjectRate
Definition: Effect.h:458
ReadAndVerifyInt
#define ReadAndVerifyInt(name)
Definition: Effect.h:632
XXO
#define XXO(s)
Definition: Internat.h:44
ShuttleGuiBase::EndHorizontalLay
void EndHorizontalLay()
Definition: ShuttleGui.cpp:1177
Effect::mT0
double mT0
Definition: Effect.h:466
ShuttleGuiBase::StartHorizontalLay
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
Definition: ShuttleGui.cpp:1167
WaveTrack::LongSamplesToTime
double LongSamplesToTime(sampleCount pos) const
Convert correctly between a number of samples and an (absolute) time in seconds.
Definition: WaveTrack.cpp:1862
EffectRepeat::TransferDataFromWindow
bool TransferDataFromWindow() override
Definition: Repeat.cpp:208
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1229
Effect::ReplaceProcessedTracks
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:2193
WaveTrack::Paste
void Paste(double t0, const Track *src) override
Definition: WaveTrack.cpp:1413
NumericConverter::TIME
@ TIME
Definition: NumericTextCtrl.h:52
Track::Fallthrough
Continuation<> Fallthrough
Type of arguments passed as optional second parameter to TypeSwitch<void>() cases.
Definition: Track.h:504
EffectRepeat::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: Repeat.cpp:178
ShuttleGui::Validator
ShuttleGui & Validator(const Factory &f)
Definition: ShuttleGui.h:678
Effect::mOutputTracks
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:465
Track::GetSelected
bool GetSelected() const
Definition: Track.h:431
EffectRepeat::GetAutomationParameters
bool GetAutomationParameters(CommandParameters &parms) override
Definition: Repeat.cpp:96
LoadEffects.h
NumericConverter::GetString
wxString GetString()
Definition: NumericTextCtrl.cpp:1230
NumericConverter
NumericConverter provides the advanced formatting control used in the selection bar of Audacity.
Definition: NumericTextCtrl.h:48
EffectRepeat::GetDescription
TranslatableString GetDescription() override
Definition: Repeat.cpp:73
WaveTrack::TimeToLongSamples
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: WaveTrack.cpp:1857
BuiltinEffectsModule::Registration
Definition: LoadEffects.h:40
EffectRepeat::mRepeatCount
wxTextCtrl * mRepeatCount
Definition: Repeat.h:61
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:239
Effect::mUIParent
wxWindow * mUIParent
Definition: Effect.h:478
EffectRepeat::mCurrentTime
wxStaticText * mCurrentTime
Definition: Repeat.h:62
TaggedIdentifier< ManualPageIDTag >
NumericConverter::SetValue
void SetValue(double newValue)
Definition: NumericTextCtrl.cpp:1138
_
#define _(s)
Definition: Internat.h:75
EffectRepeat::~EffectRepeat
virtual ~EffectRepeat()
Definition: Repeat.cpp:62
EffectRepeat::OnRepeatTextChange
void OnRepeatTextChange(wxCommandEvent &evt)
Definition: Repeat.cpp:255
EffectRepeat::mTotalTime
wxStaticText * mTotalTime
Definition: Repeat.h:63
EffectRepeat::TransferDataToWindow
bool TransferDataToWindow() override
Definition: Repeat.cpp:199
Param
Param(Count, int, wxT("Count"), 1, 1, INT_MAX, 1)
EffectRepeat::repeatCount
int repeatCount
Definition: Repeat.h:59
EffectRepeat::ManualPage
ManualPageID ManualPage() override
Definition: Repeat.cpp:78
EffectRepeat
An Effect that repeats audio several times over.
Definition: Repeat.h:22
ShuttleGuiBase::AddVariableText
wxStaticText * AddVariableText(const TranslatableString &Str, bool bCenter=false, int PositionFlags=0, int wrapWidth=0)
Definition: ShuttleGui.cpp:463
EffectType
EffectType
Definition: EffectInterface.h:55
END_EVENT_TABLE
END_EVENT_TABLE()
Effect::TrackProgress
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={})
Definition: Effect.cpp:2025
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631
Repeat.h
EffectRepeat::GetType
EffectType GetType() override
Definition: Repeat.cpp:85
anonymous_namespace{Repeat.cpp}::reg
BuiltinEffectsModule::Registration< EffectRepeat > reg
Definition: Repeat.cpp:49
EffectRepeat::GetSymbol
ComponentInterfaceSymbol GetSymbol() override
Definition: Repeat.cpp:68