Audacity  2.2.2
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 #include "../Audacity.h"
24 
25 
26 #include <math.h>
27 
28 #include <wx/intl.h>
29 
30 #include "../LabelTrack.h"
31 #include "../ShuttleGui.h"
32 #include "../WaveTrack.h"
33 #include "../widgets/NumericTextCtrl.h"
34 #include "../widgets/valnum.h"
35 
36 #include "Repeat.h"
37 
38 // Define keys, defaults, minimums, and maximums for the effect parameters
39 //
40 // Name Type Key Def Min Max Scale
41 Param( Count, int, wxT("Count"), 1, 1, INT_MAX, 1 );
42 
43 BEGIN_EVENT_TABLE(EffectRepeat, wxEvtHandler)
44  EVT_TEXT(wxID_ANY, EffectRepeat::OnRepeatTextChange)
46 
48 {
49  repeatCount = DEF_Count;
50 
51  SetLinearEffectFlag(true);
52 }
53 
55 {
56 }
57 
58 // IdentInterface implementation
59 
61 {
62  return REPEAT_PLUGIN_SYMBOL;
63 }
64 
66 {
67  return _("Repeats the selection the specified number of times");
68 }
69 
71 {
72  return wxT("Repeat");
73 }
74 
75 // EffectIdentInterface implementation
76 
78 {
79  return EffectTypeProcess;
80 }
81 
82 // EffectClientInterface implementation
83 
84 bool EffectRepeat::GetAutomationParameters(EffectAutomationParameters & parms)
85 {
86  parms.Write(KEY_Count, repeatCount);
87 
88  return true;
89 }
90 
91 bool EffectRepeat::SetAutomationParameters(EffectAutomationParameters & parms)
92 {
93  ReadAndVerifyInt(Count);
94 
95  repeatCount = Count;
96 
97  return true;
98 }
99 
100 // Effect implementation
101 
103 {
104  // Set up mOutputTracks.
105  // This effect needs Track::All for sync-lock grouping.
107 
108  int nTrack = 0;
109  bool bGoodResult = true;
110  double maxDestLen = 0.0; // used to change selection to generated bit
111 
112  TrackListIterator iter(mOutputTracks.get());
113 
114  for (Track *t = iter.First(); t && bGoodResult; t = iter.Next())
115  {
116  if (t->GetKind() == Track::Label)
117  {
118  if (t->GetSelected() || t->IsSyncLockSelected())
119  {
120  LabelTrack* track = (LabelTrack*)t;
121 
122  if (!track->Repeat(mT0, mT1, repeatCount))
123  {
124  bGoodResult = false;
125  break;
126  }
127  }
128  }
129  else if (t->GetKind() == Track::Wave && t->GetSelected())
130  {
131  WaveTrack* track = (WaveTrack*)t;
132 
133  auto start = track->TimeToLongSamples(mT0);
134  auto end = track->TimeToLongSamples(mT1);
135  auto len = end - start;
136  double tLen = track->LongSamplesToTime(len);
137  double tc = mT0 + tLen;
138 
139  if (len <= 0)
140  {
141  continue;
142  }
143 
144  auto dest = track->Copy(mT0, mT1);
145  for(int j=0; j<repeatCount; j++)
146  {
147  if (TrackProgress(nTrack, j / repeatCount)) // TrackProgress returns true on Cancel.
148  {
149  bGoodResult = false;
150  break;
151  }
152  track->Paste(tc, dest.get());
153  tc += tLen;
154  }
155  if (tc > maxDestLen)
156  maxDestLen = tc;
157  nTrack++;
158  }
159  else if (t->IsSyncLockSelected())
160  {
161  t->SyncLockAdjust(mT1, mT1 + (mT1 - mT0) * repeatCount);
162  }
163  }
164 
165  if (bGoodResult)
166  {
167  // Select the NEW bits + original bit
168  mT1 = maxDestLen;
169  }
170 
171  ReplaceProcessedTracks(bGoodResult);
172  return bGoodResult;
173 }
174 
176 {
177  S.StartHorizontalLay(wxCENTER, false);
178  {
179  IntegerValidator<int> vldRepeatCount(&repeatCount);
180  vldRepeatCount.SetRange(MIN_Count, 2147483647 / mProjectRate);
181  mRepeatCount = S.AddTextBox(_("Number of repeats to add:"), wxT(""), 12);
182  mRepeatCount->SetValidator(vldRepeatCount);
183  }
184  S.EndHorizontalLay();
185 
186  S.StartMultiColumn(1, wxCENTER);
187  {
188  mCurrentTime = S.AddVariableText(_("Current selection length: dd:hh:mm:ss"));
189  mTotalTime = S.AddVariableText(_("New selection length: dd:hh:mm:ss"));
190  }
191  S.EndMultiColumn();
192 }
193 
195 {
196  mRepeatCount->ChangeValue(wxString::Format(wxT("%d"), repeatCount));
197 
198  DisplayNewTime();
199 
200  return true;
201 }
202 
204 {
205  if (!mUIParent->Validate())
206  {
207  return false;
208  }
209 
210  long l;
211 
212  mRepeatCount->GetValue().ToLong(&l);
213 
214  repeatCount = (int) l;
215 
216  return true;
217 }
218 
220 {
221  long l;
222  wxString str;
223  mRepeatCount->GetValue().ToLong(&l);
224 
227  mT1 - mT0,
228  mProjectRate);
229 
230  str = wxString::Format( _("Current selection length: %s"), nc.GetString() );
231 
232  mCurrentTime->SetLabel(str);
233  mCurrentTime->SetName(str); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
234 
235  if (l > 0) {
236  EnableApply(true);
237  repeatCount = l;
238 
239  nc.SetValue((mT1 - mT0) * (repeatCount + 1));
240  str = wxString::Format( _("New selection length: %s"), nc.GetString() );
241  }
242  else {
243  str = _("Warning: No repeats.");
244  EnableApply(false);
245  }
246  mTotalTime->SetLabel(str);
247  mTotalTime->SetName(str); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
248 }
249 
250 void EffectRepeat::OnRepeatTextChange(wxCommandEvent & WXUNUSED(evt))
251 {
252  DisplayNewTime();
253 }
double mT1
Definition: Effect.h:464
void OnRepeatTextChange(wxCommandEvent &evt)
Definition: Repeat.cpp:250
bool TrackProgress(int whichTrack, double frac, const wxString &=wxEmptyString)
Definition: Effect.cpp:1988
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:366
wxString GetSymbol() override
Definition: Repeat.cpp:60
void CopyInputTracks()
Definition: Effect.cpp:2039
EffectType GetType() override
Definition: Repeat.cpp:77
bool Repeat(double t0, double t1, int n)
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:2170
wxString ManualPage() override
Definition: Repeat.cpp:70
void EndMultiColumn()
bool SetAutomationParameters(EffectAutomationParameters &parms) override
Definition: Repeat.cpp:91
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
Definition: WaveTrack.cpp:626
bool TransferDataFromWindow() override
Definition: Repeat.cpp:203
An Effect that repeats audio several times over.
Definition: Repeat.h:25
bool Process() override
Definition: Repeat.cpp:102
#define REPEAT_PLUGIN_SYMBOL
Definition: Repeat.h:23
void EndHorizontalLay()
Definition: ShuttleGui.cpp:975
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:113
wxTextCtrl * mRepeatCount
Definition: Repeat.h:62
bool GetAutomationParameters(EffectAutomationParameters &parms) override
Definition: Repeat.cpp:84
wxTextCtrl * AddTextBox(const wxString &Caption, const wxString &Value, const int nChars)
Definition: ShuttleGui.cpp:493
#define ReadAndVerifyInt(name)
Definition: Effect.h:790
NumericConverter provides the advanced formatting control used in the selection bar of Audacity...
virtual wxString GetSelectionFormat()
Definition: Effect.cpp:762
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
Definition: ShuttleGui.cpp:966
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:998
wxStaticText * mCurrentTime
Definition: Repeat.h:63
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
bool TransferDataToWindow() override
Definition: Repeat.cpp:194
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:94
void Paste(double t0, const Track *src) override
Definition: WaveTrack.cpp:1197
void PopulateOrExchange(ShuttleGui &S) override
Definition: Repeat.cpp:175
wxString GetDescription() override
Definition: Repeat.cpp:65
wxWindow * mUIParent
Definition: Effect.h:475
An iterator for a TrackList.
Definition: Track.h:394
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
double mProjectRate
Definition: Effect.h:456
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: WaveTrack.cpp:1849
wxStaticText * AddVariableText(const wxString &Str, bool bCenter=false, int PositionFlags=0)
Definition: ShuttleGui.cpp:373
virtual ~EffectRepeat()
Definition: Repeat.cpp:54
END_EVENT_TABLE()
void SetValue(double newValue)
double LongSamplesToTime(sampleCount pos) const
Convert correctly between an number of samples and an (absolute) time in seconds. ...
Definition: WaveTrack.cpp:1854
void DisplayNewTime()
Definition: Repeat.cpp:219
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:462
wxStaticText * mTotalTime
Definition: Repeat.h:64
virtual bool EnableApply(bool enable=true)
Definition: Effect.cpp:1889
double mT0
Definition: Effect.h:463
Param(Count, int, wxT("Count"), 1, 1, INT_MAX, 1)
int repeatCount
Definition: Repeat.h:60