Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
RateMenuTable Struct Reference
Inheritance diagram for RateMenuTable:
[legend]
Collaboration diagram for RateMenuTable:
[legend]

Public Member Functions

 RateMenuTable ()
 
 DECLARE_POPUP_MENU (RateMenuTable)
 
void InitUserData (void *pUserData) override
 Called before the menu items are appended. More...
 
void SetRate (WaveTrack *pTrack, double rate)
 
void OnRateChange (wxCommandEvent &event)
 
void OnRateOther (wxCommandEvent &event)
 
- Public Member Functions inherited from PopupMenuTable
 PopupMenuTable (const Identifier &id, const TranslatableString &caption={})
 
const IdentifierId () const
 
const TranslatableStringCaption () const
 
const Registry::GroupItemGetRegistry () const
 
const std::shared_ptr< Registry::GroupItem > & Get (void *pUserData)
 
void Clear ()
 
- Public Member Functions inherited from PopupMenuHandler
 PopupMenuHandler ()=default
 
 PopupMenuHandler (const PopupMenuHandler &)=delete
 
PopupMenuHandleroperator= (const PopupMenuHandler &)=delete
 
virtual void InitUserData (void *pUserData)=0
 Called before the menu items are appended. More...
 

Static Public Member Functions

static RateMenuTableInstance ()
 
static int IdOfRate (int rate)
 Converts a sampling rate to a wxWidgets menu item id. More...
 
- Static Public Member Functions inherited from PopupMenuTable
static std::unique_ptr< PopupMenuBuildMenu (PopupMenuTable *pTable, void *pUserData=NULL)
 
static void ExtendMenu (PopupMenu &menu, PopupMenuTable &otherTable)
 
template<typename Table >
static Registry::BaseItemPtr Computed (const std::function< Registry::BaseItemPtr(Table &) > &factory)
 

Public Attributes

PlayableTrackControls::InitMenuDatampData {}
 

Additional Inherited Members

- Public Types inherited from PopupMenuTable
using Entry = PopupMenuTableEntry
 
- Protected Member Functions inherited from PopupMenuTable
virtual void Populate ()=0
 
void Append (Registry::BaseItemPtr pItem)
 
void Append (const Identifier &stringId, PopupMenuTableEntry::Type type, int id, const TranslatableString &string, wxCommandEventFunction memFn, const PopupMenuTableEntry::InitFunction &init)
 
void AppendItem (const Identifier &stringId, int id, const TranslatableString &string, wxCommandEventFunction memFn, const PopupMenuTableEntry::InitFunction &init={})
 
void AppendRadioItem (const Identifier &stringId, int id, const TranslatableString &string, wxCommandEventFunction memFn, const PopupMenuTableEntry::InitFunction &init={})
 
void AppendCheckItem (const Identifier &stringId, int id, const TranslatableString &string, wxCommandEventFunction memFn, const PopupMenuTableEntry::InitFunction &init={})
 
void BeginSection (const Identifier &name)
 
void EndSection ()
 
- Static Protected Member Functions inherited from PopupMenuTable
static TranslatableString MakeLabel (const TranslatableString &label, bool useExtra, const TranslatableString &extra)
 
- Protected Attributes inherited from PopupMenuTable
std::shared_ptr< Registry::GroupItemmTop
 
std::vector< Registry::GroupItem * > mStack
 
Identifier mId
 
TranslatableString mCaption
 
std::unique_ptr< Registry::GroupItemmRegistry
 

Detailed Description

Definition at line 303 of file WaveTrackControls.cpp.

Constructor & Destructor Documentation

◆ RateMenuTable()

RateMenuTable::RateMenuTable ( )
inline

Definition at line 305 of file WaveTrackControls.cpp.

306 : PopupMenuTable{ "SampleRate", XO("Rat&e") }
307 {}
XO("Cut/Copy/Paste")

Member Function Documentation

◆ DECLARE_POPUP_MENU()

RateMenuTable::DECLARE_POPUP_MENU ( RateMenuTable  )

◆ IdOfRate()

int RateMenuTable::IdOfRate ( int  rate)
static

Converts a sampling rate to a wxWidgets menu item id.

Definition at line 368 of file WaveTrackControls.cpp.

369{
370 for (int i = 0; i<nRates; i++) {
371 if (gRates[i] == rate)
372 return i + OnRate8ID;
373 }
374 return OnRateOtherID;
375}
@ OnRateOtherID
@ OnRate8ID
const int nRates
static int gRates[nRates]

References gRates, nRates, OnRate8ID, and OnRateOtherID.

◆ InitUserData()

void RateMenuTable::InitUserData ( void *  pUserData)
overridevirtual

Called before the menu items are appended.

Store context data, if needed. May be called more than once before the menu opens. Pointer remains valid for the duration of any callback, if PopupMenuTable::BuildMenu() is called and the result's Popup() is called before any other menus are built.

Implements PopupMenuHandler.

Definition at line 329 of file WaveTrackControls.cpp.

330{
331 mpData = static_cast<PlayableTrackControls::InitMenuData*>(pUserData);
332}
PlayableTrackControls::InitMenuData * mpData

References mpData.

◆ Instance()

RateMenuTable & RateMenuTable::Instance ( )
static

Definition at line 323 of file WaveTrackControls.cpp.

324{
325 static RateMenuTable instance;
326 return instance;
327}

◆ OnRateChange()

void RateMenuTable::OnRateChange ( wxCommandEvent &  event)

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

Definition at line 396 of file WaveTrackControls.cpp.

397{
398 int id = event.GetId();
399 wxASSERT(id >= OnRate8ID && id <= OnRate384ID);
400 const auto pTrack = static_cast<WaveTrack*>(mpData->pTrack);
401
402 SetRate(pTrack, gRates[id - OnRate8ID]);
403
404 using namespace RefreshCode;
406}
@ OnRate384ID
A Track that contains audio waveform data.
Definition: WaveTrack.h:51
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
void SetRate(WaveTrack *pTrack, double rate)

References RefreshCode::FixScrollbars, gRates, mpData, OnRate384ID, OnRate8ID, CommonTrackControls::InitMenuData::pTrack, RefreshCode::RefreshAll, CommonTrackControls::InitMenuData::result, and SetRate().

Here is the call graph for this function:

◆ OnRateOther()

void RateMenuTable::OnRateOther ( wxCommandEvent &  event)
Todo:
Remove artificial constants!!
Todo:
Todo:
Make a real dialog box out of this!!

Definition at line 408 of file WaveTrackControls.cpp.

409{
410 const auto pTrack = static_cast<WaveTrack*>(mpData->pTrack);
411
412 int newRate;
413
416 while (true)
417 {
418 wxDialogWrapper dlg(mpData->pParent, wxID_ANY, XO("Set Rate"));
419 dlg.SetName();
420 ShuttleGui S(&dlg, eIsCreating);
421 wxString rate;
422 wxComboBox *cb;
423
424 rate.Printf(wxT("%ld"), lrint(pTrack->GetRate()));
425
426 wxArrayStringEx rates{
427 wxT("8000") ,
428 wxT("11025") ,
429 wxT("16000") ,
430 wxT("22050") ,
431 wxT("44100") ,
432 wxT("48000") ,
433 wxT("88200") ,
434 wxT("96000") ,
435 wxT("176400") ,
436 wxT("192000") ,
437 wxT("352800") ,
438 wxT("384000") ,
439 };
440
441 S.StartVerticalLay(true);
442 {
443 S.SetBorder(10);
444 S.StartHorizontalLay(wxEXPAND, false);
445 {
446 cb = S.AddCombo(XXO("New sample rate (Hz):"),
447 rate,
448 rates);
449#if defined(__WXMAC__)
450 // As of wxMac-2.8.12, setting manually is required
451 // to handle rates not in the list. See: Bug #427
452 cb->SetValue(rate);
453#endif
454 }
455 S.EndHorizontalLay();
456 S.AddStandardButtons();
457 }
458 S.EndVerticalLay();
459
460 dlg.SetClientSize(dlg.GetSizer()->CalcMin());
461 dlg.Center();
462
463 if (dlg.ShowModal() != wxID_OK)
464 {
465 return; // user cancelled dialog
466 }
467
468 long lrate;
469 if (cb->GetValue().ToLong(&lrate) && lrate >= 1 && lrate <= 1000000)
470 {
471 newRate = (int)lrate;
472 break;
473 }
474
476 XO("The entered value is invalid"),
477 XO("Error"),
478 wxICON_ERROR,
479 mpData->pParent);
480 }
481
482 SetRate(pTrack, newRate);
483
484 using namespace RefreshCode;
486}
wxT("CloseDown"))
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
XXO("&Cut/Copy/Paste Toolbar")
@ eIsCreating
Definition: ShuttleGui.h:37
#define S(N)
Definition: ToChars.cpp:64
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:625
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
#define lrint(dbl)
Definition: float_cast.h:169

References AudacityMessageBox(), eIsCreating, RefreshCode::FixScrollbars, lrint, mpData, CommonTrackControls::InitMenuData::pParent, CommonTrackControls::InitMenuData::pTrack, RefreshCode::RefreshAll, CommonTrackControls::InitMenuData::result, S, wxDialogWrapper::SetName(), SetRate(), wxT(), XO(), and XXO().

Here is the call graph for this function:

◆ SetRate()

void RateMenuTable::SetRate ( WaveTrack pTrack,
double  rate 
)

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

Definition at line 379 of file WaveTrackControls.cpp.

380{
381 AudacityProject *const project = &mpData->project;
382 for (auto channel : TrackList::Channels(pTrack))
383 channel->SetRate(rate);
384
385 // Separate conversion of "rate" enables changing the decimals without affecting i18n
386 wxString rateString = wxString::Format(wxT("%.3f"), rate);
387 ProjectHistory::Get( *project )
388 /* i18n-hint: The string names a track */
389 .PushState(XO("Changed '%s' to %s Hz")
390 .Format( pTrack->GetName(), rateString),
391 XO("Rate Change"));
392}
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
Abstract base class used in importing a file.
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
wxString GetName() const
Definition: Track.h:467
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1544

References TrackList::Channels(), ProjectHistory::Get(), Track::GetName(), mpData, CommonTrackControls::InitMenuData::project, ProjectHistory::PushState(), wxT(), and XO().

Referenced by OnRateChange(), and OnRateOther().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mpData

PlayableTrackControls::InitMenuData* RateMenuTable::mpData {}

Definition at line 314 of file WaveTrackControls.cpp.

Referenced by InitUserData(), OnRateChange(), OnRateOther(), and SetRate().


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