Audacity  2.2.2
Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
RateMenuTable Class Reference
Inheritance diagram for RateMenuTable:
PopupMenuTable TranslatableArray< std::vector< PopupMenuTableEntry > >

Static Public Member Functions

static RateMenuTableInstance ()
 
- Static Public Member Functions inherited from PopupMenuTable
static std::unique_ptr< MenuBuildMenu (wxEvtHandler *pParent, PopupMenuTable *pTable, void *pUserData=NULL)
 

Private Member Functions

 RateMenuTable ()
 
 DECLARE_POPUP_MENU (RateMenuTable)
 
void InitMenu (Menu *pMenu, void *pUserData) override
 
void DestroyMenu () override
 
int IdOfRate (int rate)
 Converts a sampling rate to a wxWidgets menu item id. More...
 
void SetRate (WaveTrack *pTrack, double rate)
 
void OnRateChange (wxCommandEvent &event)
 
void OnRateOther (wxCommandEvent &event)
 

Private Attributes

TrackControls::InitMenuDatampData
 

Additional Inherited Members

- Public Types inherited from PopupMenuTable
typedef PopupMenuTableEntry Entry
 
- Public Member Functions inherited from TranslatableArray< std::vector< PopupMenuTableEntry > >
 TranslatableArray ()
 
const std::vector
< PopupMenuTableEntry > & 
Get ()
 
- Protected Member Functions inherited from TranslatableArray< std::vector< PopupMenuTableEntry > >
virtual void Populate ()=0
 
void Invalidate (wxCommandEvent &evt)
 
- Protected Attributes inherited from TranslatableArray< std::vector< PopupMenuTableEntry > >
std::vector< PopupMenuTableEntrymContents
 

Detailed Description

Definition at line 359 of file WaveTrackControls.cpp.

Constructor & Destructor Documentation

RateMenuTable::RateMenuTable ( )
inlineprivate

Definition at line 361 of file WaveTrackControls.cpp.

361 : mpData(NULL) {}
TrackControls::InitMenuData * mpData

Member Function Documentation

RateMenuTable::DECLARE_POPUP_MENU ( RateMenuTable  )
private
void RateMenuTable::DestroyMenu ( )
inlineoverrideprivatevirtual

Implements PopupMenuTable.

Definition at line 370 of file WaveTrackControls.cpp.

References WaveColorMenuTable::mpData.

371  {
372  mpData = NULL;
373  }
TrackControls::InitMenuData * mpData
int RateMenuTable::IdOfRate ( int  rate)
private

Converts a sampling rate to a wxWidgets menu item id.

Definition at line 428 of file WaveTrackControls.cpp.

References gRates, nRates, OnRate8ID, and OnRateOtherID.

429 {
430  for (int i = 0; i<nRates; i++) {
431  if (gRates[i] == rate)
432  return i + OnRate8ID;
433  }
434  return OnRateOtherID;
435 }
static int gRates[nRates]
const int nRates
void RateMenuTable::InitMenu ( Menu pMenu,
void *  pUserData 
)
overrideprivatevirtual

Implements PopupMenuTable.

Definition at line 390 of file WaveTrackControls.cpp.

References GetActiveProject(), WaveTrack::GetRate(), WaveColorMenuTable::mpData, OnRate8ID, OnRateOtherID, and TrackControls::InitMenuData::pTrack.

391 {
392  mpData = static_cast<TrackControls::InitMenuData*>(pUserData);
393  WaveTrack *const pTrack = static_cast<WaveTrack*>(mpData->pTrack);
394  const auto rateId = IdOfRate((int)pTrack->GetRate());
395  SetMenuChecks(*pMenu, [=](int id){ return id == rateId; });
396 
397  AudacityProject *const project = ::GetActiveProject();
398  bool unsafe = project->IsAudioActive();
399  for (int i = OnRate8ID; i <= OnRateOtherID; i++) {
400  pMenu->Enable(i, !unsafe);
401  }
402 }
int IdOfRate(int rate)
Converts a sampling rate to a wxWidgets menu item id.
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
TrackControls::InitMenuData * mpData
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
double GetRate() const
Definition: WaveTrack.cpp:398
RateMenuTable & RateMenuTable::Instance ( )
static

Definition at line 384 of file WaveTrackControls.cpp.

385 {
386  static RateMenuTable instance;
387  return instance;
388 }
void RateMenuTable::OnRateChange ( wxCommandEvent &  event)
private

This method handles the selection from the Rate submenu of the track menu, except for "Other" (/see OnRateOther).

Definition at line 457 of file WaveTrackControls.cpp.

References RefreshCode::FixScrollbars, WaveTrack::GetKind(), gRates, WaveColorMenuTable::mpData, OnRate384ID, OnRate8ID, TrackControls::InitMenuData::pTrack, RefreshCode::RefreshAll, TrackControls::InitMenuData::result, and Track::Wave.

458 {
459  int id = event.GetId();
460  wxASSERT(id >= OnRate8ID && id <= OnRate384ID);
461  WaveTrack *const pTrack = static_cast<WaveTrack*>(mpData->pTrack);
462  wxASSERT(pTrack->GetKind() == Track::Wave);
463 
464  SetRate(pTrack, gRates[id - OnRate8ID]);
465 
466  using namespace RefreshCode;
468 }
int GetKind() const override
Definition: WaveTrack.h:121
TrackControls::InitMenuData * mpData
static int gRates[nRates]
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
void SetRate(WaveTrack *pTrack, double rate)
void RateMenuTable::OnRateOther ( wxCommandEvent &  event)
private
Todo:
Remove artificial constants!!
Todo:
Make a real dialog box out of this!!

Definition at line 470 of file WaveTrackControls.cpp.

References _(), ShuttleGuiBase::AddCombo(), ShuttleGui::AddStandardButtons(), AudacityMessageBox(), eIsCreating, ShuttleGuiBase::EndHorizontalLay(), ShuttleGuiBase::EndVerticalLay(), RefreshCode::FixScrollbars, WaveTrack::GetKind(), WaveTrack::GetRate(), lrint, WaveColorMenuTable::mpData, TrackControls::InitMenuData::pParent, TrackControls::InitMenuData::pTrack, RefreshCode::RefreshAll, TrackControls::InitMenuData::result, ShuttleGuiBase::SetBorder(), ShuttleGuiBase::StartHorizontalLay(), ShuttleGuiBase::StartVerticalLay(), and Track::Wave.

471 {
472  WaveTrack *const pTrack = static_cast<WaveTrack*>(mpData->pTrack);
473  wxASSERT(pTrack && pTrack->GetKind() == Track::Wave);
474 
475  int newRate;
476 
479  while (true)
480  {
481  wxDialogWrapper dlg(mpData->pParent, wxID_ANY, wxString(_("Set Rate")));
482  dlg.SetName(dlg.GetTitle());
483  ShuttleGui S(&dlg, eIsCreating);
484  wxString rate;
485  wxArrayString rates;
486  wxComboBox *cb;
487 
488  rate.Printf(wxT("%ld"), lrint(pTrack->GetRate()));
489 
490  rates.Add(wxT("8000"));
491  rates.Add(wxT("11025"));
492  rates.Add(wxT("16000"));
493  rates.Add(wxT("22050"));
494  rates.Add(wxT("44100"));
495  rates.Add(wxT("48000"));
496  rates.Add(wxT("88200"));
497  rates.Add(wxT("96000"));
498  rates.Add(wxT("176400"));
499  rates.Add(wxT("192000"));
500  rates.Add(wxT("352800"));
501  rates.Add(wxT("384000"));
502 
503  S.StartVerticalLay(true);
504  {
505  S.SetBorder(10);
506  S.StartHorizontalLay(wxEXPAND, false);
507  {
508  cb = S.AddCombo(_("New sample rate (Hz):"),
509  rate,
510  &rates);
511 #if defined(__WXMAC__)
512  // As of wxMac-2.8.12, setting manually is required
513  // to handle rates not in the list. See: Bug #427
514  cb->SetValue(rate);
515 #endif
516  }
517  S.EndHorizontalLay();
518  S.AddStandardButtons();
519  }
520  S.EndVerticalLay();
521 
522  dlg.SetClientSize(dlg.GetSizer()->CalcMin());
523  dlg.Center();
524 
525  if (dlg.ShowModal() != wxID_OK)
526  {
527  return; // user cancelled dialog
528  }
529 
530  long lrate;
531  if (cb->GetValue().ToLong(&lrate) && lrate >= 1 && lrate <= 1000000)
532  {
533  newRate = (int)lrate;
534  break;
535  }
536 
537  AudacityMessageBox(_("The entered value is invalid"), _("Error"),
538  wxICON_ERROR, mpData->pParent);
539  }
540 
541  SetRate(pTrack, newRate);
542 
543  using namespace RefreshCode;
545 }
int GetKind() const override
Definition: WaveTrack.h:121
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
TrackControls::InitMenuData * mpData
#define lrint(dbl)
Definition: float_cast.h:136
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
_("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
double GetRate() const
Definition: WaveTrack.cpp:398
void SetRate(WaveTrack *pTrack, double rate)
void RateMenuTable::SetRate ( WaveTrack pTrack,
double  rate 
)
private

Sets the sample rate for a track, and if it is linked to another track, that one as well.

Definition at line 439 of file WaveTrackControls.cpp.

References _(), GetActiveProject(), Track::GetLink(), Track::GetName(), AudacityProject::PushState(), and WaveTrack::SetRate().

440 {
441  AudacityProject *const project = ::GetActiveProject();
442  pTrack->SetRate(rate);
443  // Assume linked track is wave or null
444  const auto partner = static_cast<WaveTrack*>(pTrack->GetLink());
445  if (partner)
446  partner->SetRate(rate);
447  // Separate conversion of "rate" enables changing the decimals without affecting i18n
448  wxString rateString = wxString::Format(wxT("%.3f"), rate);
449  /* i18n-hint: The string names a track */
450  project->PushState(wxString::Format(_("Changed '%s' to %s Hz"),
451  pTrack->GetName(), rateString),
452  _("Rate Change"));
453 }
void SetRate(double newRate)
Definition: WaveTrack.cpp:403
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
wxString GetName() const
Definition: Track.h:271
_("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
void PushState(const wxString &desc, const wxString &shortDesc)
Definition: Project.cpp:4702
Track * GetLink() const
Definition: Track.cpp:269
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308

Member Data Documentation

TrackControls::InitMenuData* RateMenuTable::mpData
private

Definition at line 375 of file WaveTrackControls.cpp.


The documentation for this class was generated from the following file: