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 // EffectDefinitionInterface implementation
76 
78 {
79  return EffectTypeProcess;
80 }
81 
82 // EffectClientInterface implementation
84  S.SHUTTLE_PARAM( repeatCount, Count );
85  return true;
86 }
87 
89 {
90  parms.Write(KEY_Count, repeatCount);
91 
92  return true;
93 }
94 
96 {
97  ReadAndVerifyInt(Count);
98 
99  repeatCount = Count;
100 
101  return true;
102 }
103 
104 // Effect implementation
105 
107 {
108  // Set up mOutputTracks.
109  // This effect needs Track::All for sync-lock grouping.
111 
112  int nTrack = 0;
113  bool bGoodResult = true;
114  double maxDestLen = 0.0; // used to change selection to generated bit
115 
116  TrackListIterator iter(mOutputTracks.get());
117 
118  for (Track *t = iter.First(); t && bGoodResult; t = iter.Next())
119  {
120  if (t->GetKind() == Track::Label)
121  {
122  if (t->GetSelected() || t->IsSyncLockSelected())
123  {
124  LabelTrack* track = (LabelTrack*)t;
125 
126  if (!track->Repeat(mT0, mT1, repeatCount))
127  {
128  bGoodResult = false;
129  break;
130  }
131  }
132  }
133  else if (t->GetKind() == Track::Wave && t->GetSelected())
134  {
135  WaveTrack* track = (WaveTrack*)t;
136 
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  {
145  continue;
146  }
147 
148  auto dest = track->Copy(mT0, mT1);
149  for(int j=0; j<repeatCount; j++)
150  {
151  if (TrackProgress(nTrack, j / repeatCount)) // TrackProgress returns true on Cancel.
152  {
153  bGoodResult = false;
154  break;
155  }
156  track->Paste(tc, dest.get());
157  tc += tLen;
158  }
159  if (tc > maxDestLen)
160  maxDestLen = tc;
161  nTrack++;
162  }
163  else if (t->IsSyncLockSelected())
164  {
165  t->SyncLockAdjust(mT1, mT1 + (mT1 - mT0) * repeatCount);
166  }
167  }
168 
169  if (bGoodResult)
170  {
171  // Select the NEW bits + original bit
172  mT1 = maxDestLen;
173  }
174 
175  ReplaceProcessedTracks(bGoodResult);
176  return bGoodResult;
177 }
178 
180 {
181  S.StartHorizontalLay(wxCENTER, false);
182  {
183  IntegerValidator<int> vldRepeatCount(&repeatCount);
184  vldRepeatCount.SetRange(MIN_Count, 2147483647 / mProjectRate);
185  mRepeatCount = S.AddTextBox(_("Number of repeats to add:"), wxT(""), 12);
186  mRepeatCount->SetValidator(vldRepeatCount);
187  }
188  S.EndHorizontalLay();
189 
190  S.StartMultiColumn(1, wxCENTER);
191  {
192  mCurrentTime = S.AddVariableText(_("Current selection length: dd:hh:mm:ss"));
193  mTotalTime = S.AddVariableText(_("New selection length: dd:hh:mm:ss"));
194  }
195  S.EndMultiColumn();
196 }
197 
199 {
200  mRepeatCount->ChangeValue(wxString::Format(wxT("%d"), repeatCount));
201 
202  DisplayNewTime();
203 
204  return true;
205 }
206 
208 {
209  if (!mUIParent->Validate())
210  {
211  return false;
212  }
213 
214  long l;
215 
216  mRepeatCount->GetValue().ToLong(&l);
217 
218  repeatCount = (int) l;
219 
220  return true;
221 }
222 
224 {
225  long l;
226  wxString str;
227  mRepeatCount->GetValue().ToLong(&l);
228 
231  mT1 - mT0,
232  mProjectRate);
233 
234  str = wxString::Format( _("Current selection length: %s"), nc.GetString() );
235 
236  mCurrentTime->SetLabel(str);
237  mCurrentTime->SetName(str); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
238 
239  if (l > 0) {
240  EnableApply(true);
241  repeatCount = l;
242 
243  nc.SetValue((mT1 - mT0) * (repeatCount + 1));
244  str = wxString::Format( _("New selection length: %s"), nc.GetString() );
245  }
246  else {
247  str = _("Warning: No repeats.");
248  EnableApply(false);
249  }
250  mTotalTime->SetLabel(str);
251  mTotalTime->SetName(str); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
252 }
253 
254 void EffectRepeat::OnRepeatTextChange(wxCommandEvent & WXUNUSED(evt))
255 {
256  DisplayNewTime();
257 }
double mT1
Definition: Effect.h:461
bool DefineParams(ShuttleParams &S) override
Definition: Repeat.cpp:83
void OnRepeatTextChange(wxCommandEvent &evt)
Definition: Repeat.cpp:254
bool TrackProgress(int whichTrack, double frac, const wxString &=wxEmptyString)
Definition: Effect.cpp:1985
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
void CopyInputTracks()
Definition: Effect.cpp:2036
EffectType GetType() override
Definition: Repeat.cpp:77
bool Repeat(double t0, double t1, int n)
void ReplaceProcessedTracks(const bool bGoodResult)
Definition: Effect.cpp:2162
wxString ManualPage() override
Definition: Repeat.cpp:70
void EndMultiColumn()
Track::Holder Copy(double t0, double t1, bool forClipboard=true) const override
Definition: WaveTrack.cpp:605
bool TransferDataFromWindow() override
Definition: Repeat.cpp:207
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:60
An Effect that repeats audio several times over.
Definition: Repeat.h:25
bool Process() override
Definition: Repeat.cpp:106
#define REPEAT_PLUGIN_SYMBOL
Definition: Repeat.h:23
void EndHorizontalLay()
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:113
wxTextCtrl * mRepeatCount
Definition: Repeat.h:63
wxTextCtrl * AddTextBox(const wxString &Caption, const wxString &Value, const int nChars)
Definition: ShuttleGui.cpp:540
#define ReadAndVerifyInt(name)
Definition: Effect.h:797
bool GetAutomationParameters(CommandParameters &parms) override
Definition: Repeat.cpp:88
NumericConverter provides the advanced formatting control used in the selection bar of Audacity...
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the Shuttle cla...
wxStaticText * mCurrentTime
Definition: Repeat.h:64
bool SetAutomationParameters(CommandParameters &parms) override
Definition: Repeat.cpp:95
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
bool TransferDataToWindow() override
Definition: Repeat.cpp:198
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:101
void Paste(double t0, const Track *src) override
Definition: WaveTrack.cpp:1192
void PopulateOrExchange(ShuttleGui &S) override
Definition: Repeat.cpp:179
IdentInterfaceSymbol pairs a persistent string identifier used internally with an optional...
wxString GetDescription() override
Definition: Repeat.cpp:65
wxWindow * mUIParent
Definition: Effect.h:472
An iterator for a TrackList.
Definition: Track.h:401
double mProjectRate
Definition: Effect.h:453
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
IdentInterfaceSymbol GetSymbol() override
Definition: Repeat.cpp:60
EffectType
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: WaveTrack.cpp:1843
wxStaticText * AddVariableText(const wxString &Str, bool bCenter=false, int PositionFlags=0)
Definition: ShuttleGui.cpp:414
virtual NumericFormatId GetSelectionFormat()
Definition: Effect.cpp:737
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:1848
void DisplayNewTime()
Definition: Repeat.cpp:223
std::shared_ptr< TrackList > mOutputTracks
Definition: Effect.h:459
wxStaticText * mTotalTime
Definition: Repeat.h:65
virtual bool EnableApply(bool enable=true)
Definition: Effect.cpp:1886
double mT0
Definition: Effect.h:460
Param(Count, int, wxT("Count"), 1, 1, INT_MAX, 1)
int repeatCount
Definition: Repeat.h:61