Audacity  2.3.1
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 349 of file WaveTrackControls.cpp.

Constructor & Destructor Documentation

RateMenuTable::RateMenuTable ( )
inlineprivate

Definition at line 351 of file WaveTrackControls.cpp.

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

Member Function Documentation

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

Implements PopupMenuTable.

Definition at line 360 of file WaveTrackControls.cpp.

References WaveColorMenuTable::mpData.

361  {
362  mpData = NULL;
363  }
TrackControls::InitMenuData * mpData
int RateMenuTable::IdOfRate ( int  rate)
private

Converts a sampling rate to a wxWidgets menu item id.

Definition at line 418 of file WaveTrackControls.cpp.

References gRates, nRates, OnRate8ID, and OnRateOtherID.

419 {
420  for (int i = 0; i<nRates; i++) {
421  if (gRates[i] == rate)
422  return i + OnRate8ID;
423  }
424  return OnRateOtherID;
425 }
static int gRates[nRates]
const int nRates
void RateMenuTable::InitMenu ( Menu pMenu,
void *  pUserData 
)
overrideprivatevirtual

Implements PopupMenuTable.

Definition at line 380 of file WaveTrackControls.cpp.

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

381 {
382  mpData = static_cast<TrackControls::InitMenuData*>(pUserData);
383  WaveTrack *const pTrack = static_cast<WaveTrack*>(mpData->pTrack);
384  const auto rateId = IdOfRate((int)pTrack->GetRate());
385  SetMenuChecks(*pMenu, [=](int id){ return id == rateId; });
386 
387  AudacityProject *const project = ::GetActiveProject();
388  bool unsafe = project->IsAudioActive();
389  for (int i = OnRate8ID; i <= OnRateOtherID; i++) {
390  pMenu->Enable(i, !unsafe);
391  }
392 }
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:174
TrackControls::InitMenuData * mpData
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
double GetRate() const
Definition: WaveTrack.cpp:401
RateMenuTable & RateMenuTable::Instance ( )
static

Definition at line 374 of file WaveTrackControls.cpp.

375 {
376  static RateMenuTable instance;
377  return instance;
378 }
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 445 of file WaveTrackControls.cpp.

References RefreshCode::FixScrollbars, gRates, WaveColorMenuTable::mpData, OnRate384ID, OnRate8ID, TrackControls::InitMenuData::pTrack, RefreshCode::RefreshAll, and TrackControls::InitMenuData::result.

446 {
447  int id = event.GetId();
448  wxASSERT(id >= OnRate8ID && id <= OnRate384ID);
449  const auto pTrack = static_cast<WaveTrack*>(mpData->pTrack);
450 
451  SetRate(pTrack, gRates[id - OnRate8ID]);
452 
453  using namespace RefreshCode;
455 }
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 457 of file WaveTrackControls.cpp.

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

458 {
459  const auto pTrack = static_cast<WaveTrack*>(mpData->pTrack);
460 
461  int newRate;
462 
465  while (true)
466  {
467  wxDialogWrapper dlg(mpData->pParent, wxID_ANY, wxString(_("Set Rate")));
468  dlg.SetName(dlg.GetTitle());
469  ShuttleGui S(&dlg, eIsCreating);
470  wxString rate;
471  wxArrayString rates;
472  wxComboBox *cb;
473 
474  rate.Printf(wxT("%ld"), lrint(pTrack->GetRate()));
475 
476  rates.Add(wxT("8000"));
477  rates.Add(wxT("11025"));
478  rates.Add(wxT("16000"));
479  rates.Add(wxT("22050"));
480  rates.Add(wxT("44100"));
481  rates.Add(wxT("48000"));
482  rates.Add(wxT("88200"));
483  rates.Add(wxT("96000"));
484  rates.Add(wxT("176400"));
485  rates.Add(wxT("192000"));
486  rates.Add(wxT("352800"));
487  rates.Add(wxT("384000"));
488 
489  S.StartVerticalLay(true);
490  {
491  S.SetBorder(10);
492  S.StartHorizontalLay(wxEXPAND, false);
493  {
494  cb = S.AddCombo(_("New sample rate (Hz):"),
495  rate,
496  &rates);
497 #if defined(__WXMAC__)
498  // As of wxMac-2.8.12, setting manually is required
499  // to handle rates not in the list. See: Bug #427
500  cb->SetValue(rate);
501 #endif
502  }
503  S.EndHorizontalLay();
504  S.AddStandardButtons();
505  }
506  S.EndVerticalLay();
507 
508  dlg.SetClientSize(dlg.GetSizer()->CalcMin());
509  dlg.Center();
510 
511  if (dlg.ShowModal() != wxID_OK)
512  {
513  return; // user cancelled dialog
514  }
515 
516  long lrate;
517  if (cb->GetValue().ToLong(&lrate) && lrate >= 1 && lrate <= 1000000)
518  {
519  newRate = (int)lrate;
520  break;
521  }
522 
523  AudacityMessageBox(_("The entered value is invalid"), _("Error"),
524  wxICON_ERROR, mpData->pParent);
525  }
526 
527  SetRate(pTrack, newRate);
528 
529  using namespace RefreshCode;
531 }
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
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 429 of file WaveTrackControls.cpp.

References _(), TrackList::Channels(), GetActiveProject(), Track::GetName(), and AudacityProject::PushState().

430 {
431  AudacityProject *const project = ::GetActiveProject();
432  for (auto channel : TrackList::Channels(pTrack))
433  channel->SetRate(rate);
434 
435  // Separate conversion of "rate" enables changing the decimals without affecting i18n
436  wxString rateString = wxString::Format(wxT("%.3f"), rate);
437  /* i18n-hint: The string names a track */
438  project->PushState(wxString::Format(_("Changed '%s' to %s Hz"),
439  pTrack->GetName(), rateString),
440  _("Rate Change"));
441 }
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
wxString GetName() const
Definition: Track.h:376
_("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:4629
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1356

Member Data Documentation

TrackControls::InitMenuData* RateMenuTable::mpData
private

Definition at line 365 of file WaveTrackControls.cpp.


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