Audacity  3.0.3
SelectionBar.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  SelectionBar.cpp
6 
7  Copyright 2005 Dominic Mazzoni
8 
9  This program is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13 
14 *******************************************************************//****************************************************************//*******************************************************************/
27 
28 
29 
30 #include "SelectionBar.h"
31 
32 #include "SelectionBarListener.h"
33 #include "ToolManager.h"
34 
35 // For compilers that support precompilation, includes "wx/wx.h".
36 #include <wx/wxprec.h>
37 
38 #include <wx/setup.h> // for wxUSE_* macros
39 
40 #ifndef WX_PRECOMP
41 #include <wx/button.h>
42 #include <wx/checkbox.h>
43 #include <wx/combobox.h>
44 #include <wx/intl.h>
45 #include <wx/radiobut.h>
46 #include <wx/settings.h>
47 #include <wx/sizer.h>
48 #include <wx/valtext.h>
49 #include <wx/stattext.h>
50 #endif
51 #include <wx/statline.h>
52 
53 
54 #include "../AudioIO.h"
55 #include "../AColor.h"
56 #include "../KeyboardCapture.h"
57 #include "Prefs.h"
58 #include "Project.h"
59 #include "../ProjectAudioIO.h"
60 #include "../ProjectSettings.h"
61 #include "../Snap.h"
62 #include "ViewInfo.h"
63 #include "QualitySettings.h"
64 #include "../AllThemeResources.h"
65 
66 #if wxUSE_ACCESSIBILITY
67 #include "../widgets/WindowAccessible.h"
68 #endif
69 
71 
72 const static wxChar *numbers[] =
73 {
74  wxT("0"), wxT("1"), wxT("2"), wxT("3"), wxT("4"),
75  wxT("5"), wxT("6"), wxT("7"), wxT("8"), wxT("9")
76 };
77 
78 enum {
83 
85 
90 
92 };
93 
94 BEGIN_EVENT_TABLE(SelectionBar, ToolBar)
95  EVT_SIZE(SelectionBar::OnSize)
100  EVT_CHOICE(SnapToID, SelectionBar::OnSnapTo)
101  EVT_CHOICE(ChoiceID, SelectionBar::OnChoice )
102  EVT_IDLE( SelectionBar::OnIdle )
103  EVT_COMBOBOX(RateID, SelectionBar::OnRate)
104  EVT_TEXT(RateID, SelectionBar::OnRate)
105 
106  EVT_COMMAND(wxID_ANY, EVT_TIMETEXTCTRL_UPDATED, SelectionBar::OnUpdate)
107  EVT_COMMAND(wxID_ANY, EVT_CAPTURE_KEY, SelectionBar::OnCaptureKey)
109 
111 : ToolBar(project, SelectionBarID, XO("Selection"), wxT("Selection")),
112  mListener(NULL), mRate(0.0),
113  mStart(0.0), mEnd(0.0), mLength(0.0), mCenter(0.0), mAudio(0.0),
114  mDrive1( StartTimeID), mDrive2( EndTimeID ),
115  mSelectionMode(0),
116  mStartTime(NULL), mCenterTime(NULL), mLengthTime(NULL), mEndTime(NULL),
117  mAudioTime(NULL),
118  mChoice(NULL)
119 {
120  // Make sure we have a valid rate as the NumericTextCtrl()s
121  // created in Populate()
122  // depend on it. Otherwise, division-by-zero floating point exceptions
123  // will occur.
124  // Refer to bug #462 for a scenario where the division-by-zero causes
125  // Audacity to fail.
126  // We expect mRate to be set from the project later.
127  mRate = (double) QualitySettings::DefaultSampleRate.Read();
128 
129  // Selection mode of 0 means showing 'start' and 'end' only.
130  mSelectionMode = gPrefs->ReadLong(wxT("/SelectionToolbarMode"), 0);
131 }
132 
134 {
135 }
136 
138 {
139  auto &toolManager = ToolManager::Get( project );
140  return *static_cast<SelectionBar*>( toolManager.GetToolBar(SelectionBarID) );
141 }
142 
144 {
145  return Get( const_cast<AudacityProject&>( project )) ;
146 }
147 
148 void SelectionBar::Create(wxWindow * parent)
149 {
150  ToolBar::Create(parent);
151  UpdatePrefs();
152 }
153 
154 
156  const TranslatableString & Title, wxSizer * pSizer ){
157  const auto translated = Title.Translation();
158  auStaticText * pTitle = safenew auStaticText(this, translated );
159  pTitle->SetBackgroundColour( theTheme.Colour( clrMedium ));
160  pTitle->SetForegroundColour( theTheme.Colour( clrTrackPanelText ) );
161  pSizer->Add( pTitle, 0, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxRIGHT, 5 );
162 
163  return pTitle;
164 }
165 
166 
168  const TranslatableString &Name, int id, wxSizer * pSizer ){
169  auto formatName = mListener ? mListener->AS_GetSelectionFormat()
171  auto pCtrl = safenew NumericTextCtrl(
172  this, id, NumericConverter::TIME, formatName, 0.0, mRate);
173  pCtrl->SetName( Name );
174  pSizer->Add(pCtrl, 0, wxALIGN_TOP | wxRIGHT, 5);
175  return pCtrl;
176 }
177 
178 void SelectionBar::AddVLine( wxSizer * pSizer ){
179  pSizer->Add(safenew wxStaticLine(this, -1, wxDefaultPosition,
180  wxSize(1, toolbarSingle-10),
181  wxLI_VERTICAL),
182  0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
183 }
184 
186 {
187  SetBackgroundColour( theTheme.Colour( clrMedium ) );
188 
190 
191  // Outer sizer has space top and left.
192  // Inner sizers have space on right only.
193  // This choice makes for a nice border and internal spacing and places clear responsibility
194  // on each sizer as to what spacings it creates.
195  wxFlexGridSizer *mainSizer = safenew wxFlexGridSizer(SIZER_COLS, 1, 1);
196  Add(mainSizer, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5);
197 
198  // Top row (mostly labels)
199  wxColour clrText = theTheme.Colour( clrTrackPanelText );
200  wxColour clrText2 = *wxBLUE;
201  auStaticText *rateLabel = AddTitle( XO("Project Rate (Hz)"), mainSizer );
202  AddVLine( mainSizer );
203  auStaticText *snapLabel = AddTitle( XO("Snap-To"), mainSizer );
204  AddVLine( mainSizer );
205 #ifdef TIME_IN_SELECT_TOOLBAR
206  AddTitle( XO("Audio Position"), mainSizer );
207  AddVLine( mainSizer );
208 #endif
209 
210  {
211  const wxString choices[4] = {
212  _("Start and End of Selection"),
213  _("Start and Length of Selection"),
214  _("Length and End of Selection"),
215  _("Length and Center of Selection"),
216  };
217  mChoice = safenew wxChoice
218  (this, ChoiceID, wxDefaultPosition, wxDefaultSize, 4, choices,
219  0, wxDefaultValidator, _("Show"));
220  mChoice->SetSelection(0);
221 #if wxUSE_ACCESSIBILITY
222  // so that name can be set on a standard control
223  mChoice->SetAccessible(safenew WindowAccessible(mChoice));
224 #endif
225  mainSizer->Add(mChoice, 0, wxEXPAND | wxALIGN_TOP | wxRIGHT, 6);
226  }
227 
228  // Bottom row, (mostly time controls)
229  mRateBox = safenew wxComboBox(this, RateID,
230  wxT(""),
231  wxDefaultPosition, wxDefaultSize);
232 #if wxUSE_ACCESSIBILITY
233  // so that name can be set on a standard control
234  mRateBox->SetAccessible(safenew WindowAccessible(mRateBox));
235 #endif
236  mRateBox->SetName(_("Project Rate (Hz)"));
237  //mRateBox->SetForegroundColour( clrText2 );
238  wxTextValidator vld(wxFILTER_INCLUDE_CHAR_LIST);
239  vld.SetIncludes(wxArrayString(10, numbers));
240  mRateBox->SetValidator(vld);
241  mRateBox->SetValue(wxString::Format(wxT("%d"), (int)mRate));
242  UpdateRates(); // Must be done _after_ setting value on mRateBox!
243 
244  // We need to capture the SetFocus and KillFocus events to set up
245  // for keyboard capture. On Windows and GTK it's easy since the
246  // combobox is presented as one control to hook into.
248 
249 #if defined(__WXMAC__)
250  // The Mac uses a standard wxTextCtrl for the edit portion and that's
251  // the control that gets the focus events. So we have to find the
252  // textctrl.
253  wxWindowList kids = mRateBox->GetChildren();
254  for (unsigned int i = 0; i < kids.size(); i++) {
255  wxClassInfo *ci = kids[i]->GetClassInfo();
256  if (ci->IsKindOf(CLASSINFO(wxTextCtrl))) {
257  mRateText = kids[i];
258  break;
259  }
260  }
261 #endif
262 
263  mRateText->Bind(wxEVT_SET_FOCUS,
265  this);
266  mRateText->Bind(wxEVT_KILL_FOCUS,
268  this);
269 
270  mainSizer->Add(mRateBox, 0, wxEXPAND | wxALIGN_TOP | wxRIGHT, 5);
271 
272  AddVLine( mainSizer );
273 
274  mSnapTo = safenew wxChoice(this, SnapToID,
275  wxDefaultPosition, wxDefaultSize,
276  transform_container< wxArrayStringEx >(
278  std::mem_fn( &TranslatableString::Translation ) ) );
279 
280 #if wxUSE_ACCESSIBILITY
281  // so that name can be set on a standard control
282  mSnapTo->SetAccessible(safenew WindowAccessible(mSnapTo));
283 #endif
284  mSnapTo->SetName(_("Snap To"));
285  //mSnapTo->SetForegroundColour( clrText2 );
286  mSnapTo->SetSelection(mListener ? mListener->AS_GetSnapTo() : SNAP_OFF);
287 
288  mSnapTo->Bind(wxEVT_SET_FOCUS,
290  this);
291  mSnapTo->Bind(wxEVT_KILL_FOCUS,
293  this);
294 
295  mainSizer->Add(mSnapTo, 0, wxEXPAND | wxALIGN_TOP | wxRIGHT, 5);
296 
297  AddVLine( mainSizer );
298 
299 #ifdef TIME_IN_SELECT_TOOLBAR
300  mAudioTime = AddTime( XO("Audio Position"), AudioTimeID, mainSizer );
301  // This vertical line is NOT just for decoration!
302  // It works around a wxWidgets-on-Windows RadioButton bug, where tabbing
303  // into the radiobutton group jumps to selecting the first item in the
304  // group even if some other item had been selected.
305  // It is an important bug to work around for screen reader users, who use TAB
306  // a lot in navigation.
307  // More about the bug here:
308  // https://forums.wxwidgets.org/viewtopic.php?t=41120
309  AddVLine( mainSizer );
310 #endif
311 
312  {
313  auto hSizer = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
314 
315  mStartTime = AddTime( XO("Start"), StartTimeID, hSizer.get() );
316  mLengthTime = AddTime( XO("Length"), LengthTimeID, hSizer.get() );
317  mCenterTime = AddTime( XO("Center"), CenterTimeID, hSizer.get() );
318  mEndTime = AddTime( XO("End"), EndTimeID, hSizer.get() );
319  mainSizer->Add(hSizer.release(), 0, wxALIGN_TOP | wxRIGHT, 0);
320  }
321 
322 #if defined(__WXGTK3__)
323  // Nothing special
324 #elif defined(__WXGTK__)
325  // Ensure the font fits inside (hopefully)
326  wxFont font = mChoice->GetFont();
327  font.Scale((double) toolbarSingle / mChoice->GetSize().GetHeight());
328 
329  rateLabel->SetFont(font);
330  snapLabel->SetFont(font);
331  mChoice->SetFont(font);
332  mRateBox->SetFont(font);
333  mRateText->SetFont(font);
334  mSnapTo->SetFont(font);
335 #endif
336 
337  // Make sure they are fully expanded to the longest item
338  mChoice->SetMinSize(wxSize(mChoice->GetBestSize().x, toolbarSingle));
339  mRateBox->SetMinSize(wxSize(mRateBox->GetBestSize().x, toolbarSingle));
340  mSnapTo->SetMinSize(wxSize(mSnapTo->GetBestSize().x, toolbarSingle));
341 
342  mChoice->MoveBeforeInTabOrder( mStartTime );
343  // This shows/hides controls.
344  // Do this before layout so that we are sized right.
346  mainSizer->Layout();
348  Layout();
349 }
350 
352 {
353  // The project rate is no longer driven from here.
354  // When preferences change, the Project learns about it too.
355  // If necessary we can drive the SelectionBar mRate via the Project
356  // calling our SetRate().
357  // As of 13-Sep-2018, changes to the sample rate pref will only affect
358  // creation of new projects, not the sample rate in existing ones.
359 
360  // This will only change the selection mode during a "Reset Configuration"
361  // action since the read value will be the same during a normal preferences
362  // update.
363  mSelectionMode = gPrefs->ReadLong(wxT("/SelectionToolbarMode"), 0);
364 
365  // This will only change the time format during a "Reset Configuration"
366  // action since the read value will be the same during a normal preferences
367  // update.
368  wxCommandEvent e;
369  e.SetString(NumericTextCtrl::LookupFormat(
371  gPrefs->Read(wxT("/SelectionFormat"), wxT(""))).Internal());
372  OnUpdate(e);
373 
374  // Set label to pull in language change
375  SetLabel(XO("Selection"));
376 
378  // Give base class a chance
380 }
381 
383 {
384  mListener = l;
388 };
389 
391 {
392 #if wxUSE_TOOLTIPS
393  auto formatName =
394  mListener
397  mSnapTo->SetToolTip(
398  wxString::Format(
399  _("Snap Clicks/Selections to %s"), formatName.Translation() ));
400 #endif
401 }
402 
403 void SelectionBar::OnSize(wxSizeEvent &evt)
404 {
405  Refresh( true );
406 
407  evt.Skip();
408 }
409 
410 // When a control value is changed, this function is called.
411 // It determines the values for the other controls.
412 void SelectionBar::ModifySelection(int newDriver, bool done)
413 {
414  // If the user moved to a different control, then update which
415  // two controls drive the others.
416  if( newDriver != mDrive2 )
417  SetDrivers( mDrive2, newDriver);
418 
419  // Only update a value if user typed something in.
420  // The reason is the controls may be less accurate than
421  // the values.
422  if( newDriver == StartTimeID )
424  if( newDriver == EndTimeID )
425  mEnd = mEndTime->GetValue();
426  if( newDriver == LengthTimeID )
428  if( newDriver == CenterTimeID )
430 
431  // There are four controls, and two constraints, which are:
432  // mid = (start+end)/2
433  // length = (end-start)
434  // Therefore we can select any two controls as 'drivers' of
435  // the other two.
436  // Here we compute 'i' which combines the identity of the two
437  // driving controls, to use it as an index.
438  // The order of the two drivers generally does not matter much,
439  // except that we want:
440  // start < end
441  // and preserve that by adjusting the least dominant driving
442  // control.
443  int i = mDrive1 + 4 * mDrive2;
444  switch(i) {
445  case StartTimeID + 4 * EndTimeID:
446  if( mEnd < mStart )
447  mStart = mEnd;
448  case StartTimeID * 4 + EndTimeID:
449  if( mStart > mEnd )
450  mEnd = mStart;
451  mLength = mEnd - mStart;
452  mCenter = (mStart+mEnd)/2.0;
453  break;
454 
455  case StartTimeID + 4 * LengthTimeID:
456  case StartTimeID * 4 + LengthTimeID:
457  mEnd = mStart+mLength;
458  mCenter = (mStart+mEnd)/2.0;
459  break;
460 
461  case EndTimeID + 4 * LengthTimeID:
462  if( mEnd - mLength < 0 )
463  mEnd += (mLength - mEnd);
464  case EndTimeID * 4 + LengthTimeID:
465  if( mEnd - mLength < 0)
466  mLength -= (mLength - mEnd);
467  mStart = mEnd - mLength;
468  mCenter = (mStart+mEnd)/2.0;
469  break;
470 
471  case LengthTimeID + 4 * CenterTimeID:
472  if( mCenter - (mLength / 2) < 0 )
473  mLength = (mCenter * 2);
474  case LengthTimeID * 4 + CenterTimeID:
475  if( mCenter - (mLength / 2) < 0 )
476  mCenter = (mLength / 2);
477  mStart = mCenter - mLength/2.0;
478  mEnd = mCenter + mLength/2.0;
479  break;
480 
481  default:
482  // The above should cover all legal combinations of two distinct controls.
483  wxFAIL_MSG( "Illegal sequence of selection changes");
484  }
485 
486  // Refresh the controls now
488 
489  // Places the start-end markers on the track panel.
491 }
492 
493 void SelectionBar::OnChangedTime(wxCommandEvent & event)
494 {
495  ModifySelection(event.GetId(), event.GetInt() != 0);
496 }
497 
498 // Called when one of the format drop downs is changed.
499 void SelectionBar::OnUpdate(wxCommandEvent &evt)
500 {
501  wxWindow *w = FindFocus();
503  int i;
504  int iFocus = -1;
505  for(i=0;i<5;i++)
506  if( w == *Ctrls[i] )
507  iFocus = i;
508 
509  evt.Skip(false);
510 
512 
513  // Save format name before recreating the controls so they resize properly
514  if (mStartTime)
515  {
516  if (mListener)
518  }
519 
520  // ReCreateButtons() will get rid of our sizers and controls
521  // so reset pointers first.
522  for( i=0;i<5;i++)
523  *Ctrls[i]=NULL;
524 
525  mChoice = NULL;
526  mRateBox = NULL;
527  mRateText = NULL;
528  mSnapTo = NULL;
529 
531 
533 
534  for( i=0;i<5;i++)
535  if( *Ctrls[i] )
536  (*Ctrls[i])->SetFormatName( format );
537 
538  if( iFocus >=0 )
539  if( *Ctrls[iFocus] )
540  (*Ctrls[iFocus])->SetFocus();
541 
543 
544  Updated();
545 }
546 
547 // The two drivers are the numbers of the two controls which drive the other ones.
548 // The user gets to see which controls are drivers and which driven.
549 void SelectionBar::SetDrivers( int driver1, int driver2 )
550 {
551  mDrive1 = driver1;
552  mDrive2 = driver2;
553 
555  static TranslatableString Text[4] = {
556  /* i18n-hint noun */
557  XO("Start"),
558  XO("Center"),
559  XO("Length"),
560  /* i18n-hint noun */
561  XO("End")
562  };
563 
564  for(int i=0;i<4;i++){
565  int id = i + StartTimeID;
566  int fixed = (( id == mDrive2 )?mDrive1:mDrive2)-StartTimeID;
567 
568  const auto &Temp = Text[i];
569  auto Title = ( (id!=mDrive1) && (id!=mDrive2 ) )
570  /* i18n-hint: %s is replaced e.g by one of 'Length', 'Center',
571  'Start', or 'End' (translated), to indicate that it will be
572  calculated from other parameters. */
573  ? XO("%s - driven").Format( Temp )
574  : Temp ;
575  auto VoiceOverText =
576  /* i18n-hint: each string is replaced by one of 'Length', 'Center',
577  'Start', or 'End' (translated) */
578  XO("Selection %s. %s won't change.").Format( Temp, Text[fixed] );
579  if( *Ctrls[i] ){
580  (*Ctrls[i])->SetName( Temp );
581  }
582  }
583 }
584 
585 void SelectionBar::OnChoice(wxCommandEvent & WXUNUSED(event))
586 {
587  int mode = mChoice->GetSelection();
588  SetSelectionMode( mode );
590 }
591 
592 void SelectionBar::OnIdle( wxIdleEvent &evt )
593 {
594  evt.Skip();
595  auto &project = mProject;
596  const auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
597 
598  double audioTime;
599 
600  auto &projectAudioIO = ProjectAudioIO::Get( project );
601  if ( projectAudioIO.IsAudioActive() ){
602  auto gAudioIO = AudioIO::Get();
603  audioTime = gAudioIO->GetStreamTime();
604  }
605  else {
606  const auto &playRegion = ViewInfo::Get( project ).playRegion;
607  audioTime = playRegion.GetStart();
608  }
609 
610  SetTimes(selectedRegion.t0(), selectedRegion.t1(), audioTime);
611 }
612 
614 {
615  // We just changed the mode. Remember it.
616  gPrefs->Write(wxT("/SelectionToolbarMode"), mSelectionMode);
617  gPrefs->Flush();
618 
619  wxSize sz = GetMinSize();
620  sz.SetWidth( 10 );
621  SetMinSize( sz );
622  Fit();
623  Layout();
624  Updated();
625 }
626 
627 // We used to have 8 modes which showed different combinations of the
628 // length, start, end, center controls.
629 // Mode 7 for example showed all four at the same time.
631 {
632  // Only modes 0 to 3 are now supported,
633  // so fix up a mode that could have come from the config.
634  const int maxMode = 3;
635 
636  if( mode > maxMode )
637  mode = 0;
638  if( mode < 0 )
639  mode = 0;
640  mSelectionMode = mode;
641  mChoice->SetSelection( mode );
642 
643  // First decide which two controls drive the others...
644  // For example the last option is with all controls shown, and in that mode we
645  // initially have start and end driving.
646  int Drive2[] = { StartTimeID, StartTimeID, LengthTimeID, LengthTimeID,
648  int Drive1[] = { EndTimeID, LengthTimeID, EndTimeID, CenterTimeID,
650 
651  SetDrivers( Drive1[mode], Drive2[mode] );
652  // Then show/hide the relevant controls.
653  ShowHideControls( mode );
654 }
655 
656 // Our mode determines which controls are visible.
658 {
659  // The bits in these say which controls are visible.
660  int masks[8]= {
661  9, 5, 12, 6, // 2 items shown
662  13, 7, 11,// 3 items shown
663  15};
664  int mask = masks[mode];
665 
667  for(int i=0;i<4;i++){
668  if( *Ctrls[i]){
669  (*Ctrls[i])->Show( (mask & (1<<i))!=0 );
670  (*Ctrls[i])->Refresh();
671  }
672  }
673 }
674 
676 {
678  double Values[5] = {mStart, mEnd, mLength, mCenter, mAudio };
679  int i;
680  for(i=0;i<5;i++)
681  if( *Ctrls[i] )
682  (*Ctrls[i])->SetValue( Values[i] );
683 }
684 
685 // A time has been set. Update the control values.
686 void SelectionBar::SetTimes(double start, double end, double audio)
687 {
688  if ( start != mStart || end != mEnd || audio != mAudio
690  ) {
691  mStart = start;
692  mEnd = end;
693  mLength = end-start;
694  mCenter = (end+start)/2.0;
695  mAudio = audio;
697 
699  }
700 }
701 
703 {
704  mSnapTo->SetSelection(snap);
705 }
706 
708 {
709  bool changed =
711 
712  // Test first whether changed, to avoid infinite recursion from OnUpdate
713  if ( changed ) {
714  wxCommandEvent e;
715  e.SetString(format.Internal());
716  OnUpdate(e);
717  }
718 }
719 
720 void SelectionBar::SetRate(double rate)
721 {
722  if (rate != mRate) {
723  // if the rate is actually being changed
724  mRate = rate; // update the stored rate
725  mRateBox->SetValue(wxString::Format(wxT("%d"), (int)rate));
726 
727  // update the TimeTextCtrls if they exist
729  int i;
730  for(i=0;i<5;i++)
731  if( *Ctrls[i] )
732  (*Ctrls[i])->SetSampleRate( rate );
733  }
734 }
735 
736 void SelectionBar::OnRate(wxCommandEvent & WXUNUSED(event))
737 {
738  auto value = mRateBox->GetValue();
739 
740  if (value.ToDouble(&mRate) && // is a numeric value
741  (mRate != 0.0))
742  {
744  int i;
745  for(i=0;i<5;i++)
746  if( *Ctrls[i] )
747  (*Ctrls[i])->SetSampleRate( mRate );
749 
750  mLastValidText = value;
751  }
752  else
753  {
754  // Bug 2497 - Undo paste into text box if it's not numeric
755  mRateBox->SetValue(mLastValidText);
756  }
757 }
758 
760 {
761  wxString oldValue = mRateBox->GetValue();
762  mRateBox->Clear();
763  for (int i = 0; i < AudioIOBase::NumStandardRates; i++) {
764  mRateBox->Append(
765  wxString::Format(wxT("%d"), AudioIOBase::StandardRates[i]));
766  }
767  mRateBox->SetValue(oldValue);
768 }
769 
770 void SelectionBar::OnFocus(wxFocusEvent &event)
771 {
772  KeyboardCapture::OnFocus( *this, event );
773 }
774 
775 void SelectionBar::OnCaptureKey(wxCommandEvent &event)
776 {
777  wxKeyEvent *kevent = (wxKeyEvent *)event.GetEventObject();
778  wxWindow *w = FindFocus();
779  int keyCode = kevent->GetKeyCode();
780 
781  // Convert numeric keypad entries.
782  if ((keyCode >= WXK_NUMPAD0) && (keyCode <= WXK_NUMPAD9)) {
783  keyCode -= WXK_NUMPAD0 - '0';
784  }
785 
786  if (keyCode >= '0' && keyCode <= '9') {
787  return;
788  }
789 
790  // UP/DOWN/LEFT/RIGHT for mRateText
791  if (w == mRateText) {
792  switch (keyCode)
793  {
794  case WXK_LEFT:
795  case WXK_RIGHT:
796  case WXK_UP:
797  case WXK_DOWN:
798  case WXK_DELETE:
799  case WXK_BACK:
800  return;
801  }
802  }
803 
804  event.Skip();
805 }
806 
807 void SelectionBar::OnSnapTo(wxCommandEvent & WXUNUSED(event))
808 {
809  mListener->AS_SetSnapTo(mSnapTo->GetSelection());
810 }
811 
813  []( AudacityProject &project ){
814  return ToolBar::Holder{ safenew SelectionBar{ project } }; }
815 };
816 
817 namespace {
819  /* i18n-hint: Clicking this menu item shows the toolbar
820  for selecting a time range of audio */
821  SelectionBarID, wxT("ShowSelectionTB"), XXO("&Selection Toolbar")
822 };
823 }
824 
SelectionBar::mAudioTime
NumericTextCtrl * mAudioTime
Definition: SelectionBar.h:109
SelectionBar::Get
static SelectionBar & Get(AudacityProject &project)
Definition: SelectionBar.cpp:137
SelectionBar::mCenter
double mCenter
Definition: SelectionBar.h:95
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
ViewInfo::Get
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:161
StartTimeID
@ StartTimeID
Definition: SelectionBar.cpp:86
SNAP_OFF
@ SNAP_OFF
Definition: ProjectSettings.h:29
ToolManager.h
SelectionBar::mDrive2
int mDrive2
Definition: SelectionBar.h:100
AudioIOBase::StandardRates
static const int StandardRates[]
Array of common audio sample rates.
Definition: AudioIOBase.h:201
SelectionBar::mListener
SelectionBarListener * mListener
Definition: SelectionBar.h:93
SelectionBar.h
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
EVT_COMMAND
EVT_COMMAND(wxID_ANY, EVT_FREQUENCYTEXTCTRL_UPDATED, LabelDialog::OnFreqUpdate) LabelDialog
Definition: LabelDialog.cpp:92
SelectionBarListener::AS_ModifySelection
virtual void AS_ModifySelection(double &start, double &end, bool done)=0
Project.h
SelectionBar::mEnd
double mEnd
Definition: SelectionBar.h:95
factory
static RegisteredToolbarFactory factory
Definition: SelectionBar.cpp:812
ViewInfo::playRegion
PlayRegion playRegion
Definition: ViewInfo.h:197
SelectionBar::mLength
double mLength
Definition: SelectionBar.h:95
NumericTextCtrl::SetFormatString
bool SetFormatString(const FormatStrings &formatString)
Definition: NumericTextCtrl.cpp:1449
ToolBar::mProject
AudacityProject & mProject
Definition: ToolBar.h:235
ToolBar::SetLabel
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:398
SelectionBar::mRate
double mRate
Definition: SelectionBar.h:94
SelectionBarListener::AS_GetSnapTo
virtual int AS_GetSnapTo()=0
SelectionBar::SetRate
void SetRate(double rate)
Definition: SelectionBar.cpp:720
ToolManager::Get
static ToolManager & Get(AudacityProject &project)
Definition: ToolManager.cpp:356
SelectionBar::mDrive1
int mDrive1
Definition: SelectionBar.h:99
SelectionBar::OnCaptureKey
void OnCaptureKey(wxCommandEvent &event)
Definition: SelectionBar.cpp:775
PlayRegion::GetStart
double GetStart() const
Definition: ViewInfo.h:134
SelectionBar::OnSnapTo
void OnSnapTo(wxCommandEvent &event)
Definition: SelectionBar.cpp:807
SelectionBar::AddVLine
void AddVLine(wxSizer *pSizer)
Definition: SelectionBar.cpp:178
SelectionBar::mStartTime
NumericTextCtrl * mStartTime
Definition: SelectionBar.h:105
XO
#define XO(s)
Definition: Internat.h:31
SelectionBar::mStart
double mStart
Definition: SelectionBar.h:95
SelectionBar::mEndTime
NumericTextCtrl * mEndTime
Definition: SelectionBar.h:108
ToolBar::Holder
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:102
AudioIOBase::NumStandardRates
static const int NumStandardRates
How many standard sample rates there are.
Definition: AudioIOBase.h:203
ToolBar::ReCreateButtons
virtual void ReCreateButtons()
Definition: ToolBar.cpp:516
SelectionBar::Populate
void Populate() override
Definition: SelectionBar.cpp:185
LengthTimeID
@ LengthTimeID
Definition: SelectionBar.cpp:87
ProjectAudioIO::Get
static ProjectAudioIO & Get(AudacityProject &project)
Definition: ProjectAudioIO.cpp:22
SelectionBar::AddTitle
auStaticText * AddTitle(const TranslatableString &Title, wxSizer *pSizer)
Definition: SelectionBar.cpp:155
SelectionBar::mLastSelectionMode
int mLastSelectionMode
Definition: SelectionBar.h:103
SelectionBar::SetTimes
void SetTimes(double start, double end, double audio)
Definition: SelectionBar.cpp:686
SelectionBar::~SelectionBar
virtual ~SelectionBar()
Definition: SelectionBar.cpp:133
NumericTextCtrl
Definition: NumericTextCtrl.h:172
AttachedToolBarMenuItem
Definition: ToolManager.h:224
numbers
static const wxChar * numbers[]
Definition: SelectionBar.cpp:72
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
SelectionBarListener::AS_SetRate
virtual void AS_SetRate(double rate)=0
SelectionBar::OnUpdate
void OnUpdate(wxCommandEvent &evt)
Definition: SelectionBar.cpp:499
anonymous_namespace{SelectionBar.cpp}::sAttachment
AttachedToolBarMenuItem sAttachment
Definition: SelectionBar.cpp:818
SelectionBar::mLengthTime
NumericTextCtrl * mLengthTime
Definition: SelectionBar.h:107
EndTimeID
@ EndTimeID
Definition: SelectionBar.cpp:89
SelectionBar::mCenterTime
NumericTextCtrl * mCenterTime
Definition: SelectionBar.h:106
SelectionBar::SetDrivers
void SetDrivers(int driver1, int driver2)
Definition: SelectionBar.cpp:549
SelectionBar::SetSelectionMode
void SetSelectionMode(int mode)
Definition: SelectionBar.cpp:630
AudioTimeID
@ AudioTimeID
Definition: SelectionBar.cpp:91
SelectionBar::OnSize
void OnSize(wxSizeEvent &evt)
Definition: SelectionBar.cpp:403
NumericConverter::LookupFormat
static NumericFormatSymbol LookupFormat(Type type, const wxString &id)
Definition: NumericTextCtrl.cpp:702
SelectionBarListener::AS_GetSelectionFormat
virtual const NumericFormatSymbol & AS_GetSelectionFormat()=0
ViewInfo::selectedRegion
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:196
XXO
#define XXO(s)
Definition: Internat.h:44
SelectionBarListener::AS_SetSelectionFormat
virtual void AS_SetSelectionFormat(const NumericFormatSymbol &format)=0
NumericConverter::GetBuiltinFormat
FormatStrings GetBuiltinFormat(const int index)
Definition: NumericTextCtrl.cpp:1207
SelectionBar::OnIdle
void OnIdle(wxIdleEvent &evt)
Definition: SelectionBar.cpp:592
SelectionBar::mSnapTo
wxChoice * mSnapTo
Definition: SelectionBar.h:113
SelectionBar::mRateText
wxWindow * mRateText
Definition: SelectionBar.h:114
SelectionBar::UpdateRates
void UpdateRates()
Definition: SelectionBar.cpp:759
ToolBar::UpdatePrefs
void UpdatePrefs() override
Definition: ToolBar.cpp:605
SelectionBar::ValuesToControls
void ValuesToControls()
Definition: SelectionBar.cpp:675
SelectionBar::Create
void Create(wxWindow *parent) override
Definition: SelectionBar.cpp:148
NumericConverter::TIME
@ TIME
Definition: NumericTextCtrl.h:52
SelectionBar::SetSelectionFormat
void SetSelectionFormat(const NumericFormatSymbol &format)
Definition: SelectionBar.cpp:707
SelectionBar::mAudio
double mAudio
Definition: SelectionBar.h:95
SelectionBarListener.h
format
int format
Definition: ExportPCM.cpp:56
QualitySettings::DefaultSampleRate
PROJECT_RATE_API IntSetting DefaultSampleRate
Definition: QualitySettings.cpp:15
SelectionBarFirstID
@ SelectionBarFirstID
Definition: SelectionBar.cpp:79
OnMenuID
@ OnMenuID
Definition: SelectionBar.cpp:82
WindowAccessible
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...
SelectionBar::AddTime
NumericTextCtrl * AddTime(const TranslatableString &Name, int id, wxSizer *pSizer)
Definition: SelectionBar.cpp:167
SelectionBar::mSelectionMode
int mSelectionMode
Definition: SelectionBar.h:102
SelectionBar::OnFocus
void OnFocus(wxFocusEvent &event)
Definition: SelectionBar.cpp:770
ToolBar::Create
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:475
SelectionBar::mChoice
wxChoice * mChoice
Definition: SelectionBar.h:110
SelectionBar::mRateBox
wxComboBox * mRateBox
Definition: SelectionBar.h:112
ViewInfo.h
SelectionBar::ModifySelection
void ModifySelection(int newDriver, bool done=false)
Definition: SelectionBar.cpp:412
SelectionBar::UpdatePrefs
void UpdatePrefs() override
Definition: SelectionBar.cpp:351
SelectionBarListener
A parent class of SelectionBar, used to forward events to do with changes in the SelectionBar.
Definition: SelectionBarListener.h:19
SelectionBarID
@ SelectionBarID
Definition: ToolBar.h:82
RegisteredToolbarFactory
Definition: ToolBar.h:261
wxPanelWrapper::SetName
void SetName()
Definition: wxPanelWrapper.cpp:61
SelectionBar::SetListener
void SetListener(SelectionBarListener *l)
Definition: SelectionBar.cpp:382
SelectionBar::OnChangedTime
void OnChangedTime(wxCommandEvent &evt)
Definition: SelectionBar.cpp:493
SelectionBar
(not quite a Toolbar) at foot of screen for setting and viewing the selection range.
Definition: SelectionBar.h:45
auStaticText
is like wxStaticText, except it can be themed. wxStaticText can't be.
Definition: Theme.h:183
SnapToID
@ SnapToID
Definition: SelectionBar.cpp:81
FileConfig::Flush
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
QualitySettings.h
Read
gPrefs Read(wxT("/GUI/VerticalZooming"), &bVZoom, false)
SnapManager::GetSnapLabels
static const TranslatableStrings & GetSnapLabels()
Definition: Snap.cpp:315
_
#define _(s)
Definition: Internat.h:75
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
SelectionBar::mLastValidText
wxString mLastValidText
Definition: SelectionBar.h:116
SelectionBar::RegenerateTooltips
void RegenerateTooltips() override
Definition: SelectionBar.cpp:390
SelectionBarListener::AS_GetRate
virtual double AS_GetRate()=0
IMPLEMENT_CLASS
IMPLEMENT_CLASS(SelectionBar, ToolBar)
SelectionBar::ShowHideControls
void ShowHideControls(int mode)
Definition: SelectionBar.cpp:657
KeyboardCapture::OnFocus
void OnFocus(wxWindow &window, wxFocusEvent &event)
a function useful to implement a focus event handler The window releases the keyboard if the event is...
Definition: KeyboardCapture.cpp:95
ToolBar
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:98
ExceptionType::Internal
@ Internal
Indicates internal failure from Audacity.
ThemeBase::Colour
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1197
theTheme
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:203
Prefs.h
TranslatableString::Translation
wxString Translation() const
Definition: TranslatableString.h:79
ToolBar::Updated
void Updated()
Definition: ToolBar.cpp:661
ChoiceID
@ ChoiceID
Definition: SelectionBar.cpp:84
AudioIO::Get
static AudioIO * Get()
Definition: AudioIO.cpp:606
safenew
#define safenew
Definition: MemoryX.h:10
RateID
@ RateID
Definition: SelectionBar.cpp:80
toolbarSingle
#define toolbarSingle
Definition: ToolBar.h:59
SelectionBar::SelectionModeUpdated
void SelectionModeUpdated()
Definition: SelectionBar.cpp:613
CenterTimeID
@ CenterTimeID
Definition: SelectionBar.cpp:88
NumericConverter::GetValue
double GetValue()
Definition: NumericTextCtrl.cpp:1172
END_EVENT_TABLE
END_EVENT_TABLE()
SelectionBar::OnChoice
void OnChoice(wxCommandEvent &event)
Definition: SelectionBar.cpp:585
SelectionBar::SetSnapTo
void SetSnapTo(int)
Definition: SelectionBar.cpp:702
SIZER_COLS
#define SIZER_COLS
Definition: SelectionBar.h:30
ToolBar::Add
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:686
SelectionBar::OnRate
void OnRate(wxCommandEvent &event)
Definition: SelectionBar.cpp:736
SelectionBarListener::AS_SetSnapTo
virtual void AS_SetSnapTo(int snap)=0