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)
 Sets the sample rate for a track. More...
 
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 auto * GetRegistry () const
 
const auto & 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 , typename Factory >
static auto Adapt (const Factory &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
 
template<typename Ptr >
void Append (Ptr 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< PopupSubMenumTop
 
std::vector< PopupMenuGroupItem * > mStack
 
Identifier mId
 
TranslatableString mCaption
 
std::unique_ptr< PopupMenuGroupItemmRegistry
 

Detailed Description

Definition at line 307 of file WaveTrackControls.cpp.

Constructor & Destructor Documentation

◆ RateMenuTable()

RateMenuTable::RateMenuTable ( )
inline

Definition at line 309 of file WaveTrackControls.cpp.

310 : PopupMenuTable{ "SampleRate", XO("Rat&e") }
311 {}
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 373 of file WaveTrackControls.cpp.

374{
375 for (int i = 0; i<nRates; i++) {
376 if (gRates[i] == rate)
377 return i + OnRate8ID;
378 }
379 return OnRateOtherID;
380}
@ 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 334 of file WaveTrackControls.cpp.

335{
336 mpData = static_cast<PlayableTrackControls::InitMenuData*>(pUserData);
337}
PlayableTrackControls::InitMenuData * mpData

References mpData.

◆ Instance()

RateMenuTable & RateMenuTable::Instance ( )
static

Definition at line 328 of file WaveTrackControls.cpp.

329{
330 static RateMenuTable instance;
331 return instance;
332}

◆ 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 406 of file WaveTrackControls.cpp.

407{
408 int id = event.GetId();
409 wxASSERT(id >= OnRate8ID && id <= OnRate384ID);
410 const auto pTrack = static_cast<WaveTrack*>(mpData->pTrack);
411
412 SetRate(pTrack, gRates[id - OnRate8ID]);
413
414 using namespace RefreshCode;
416}
@ OnRate384ID
A Track that contains audio waveform data.
Definition: WaveTrack.h:222
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
void SetRate(WaveTrack *pTrack, double rate)
Sets the sample rate for a track.

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 418 of file WaveTrackControls.cpp.

419{
420 const auto pTrack = static_cast<WaveTrack*>(mpData->pTrack);
421
422 int newRate;
423
426 while (true)
427 {
428 wxDialogWrapper dlg(mpData->pParent, wxID_ANY, XO("Set Rate"));
429 dlg.SetName();
430 ShuttleGui S(&dlg, eIsCreating);
431 wxString rate;
432 wxComboBox *cb;
433
434 rate.Printf(wxT("%ld"), lrint(pTrack->GetRate()));
435
436 wxArrayStringEx rates{
437 wxT("8000") ,
438 wxT("11025") ,
439 wxT("16000") ,
440 wxT("22050") ,
441 wxT("44100") ,
442 wxT("48000") ,
443 wxT("88200") ,
444 wxT("96000") ,
445 wxT("176400") ,
446 wxT("192000") ,
447 wxT("352800") ,
448 wxT("384000") ,
449 };
450
451 S.StartVerticalLay(true);
452 {
453 S.SetBorder(10);
454 S.StartHorizontalLay(wxEXPAND, false);
455 {
456 cb = S.AddCombo(XXO("New sample rate (Hz):"),
457 rate,
458 rates);
459#if defined(__WXMAC__)
460 // As of wxMac-2.8.12, setting manually is required
461 // to handle rates not in the list. See: Bug #427
462 cb->SetValue(rate);
463#endif
464 }
465 S.EndHorizontalLay();
466 S.AddStandardButtons();
467 }
468 S.EndVerticalLay();
469
470 dlg.SetClientSize(dlg.GetSizer()->CalcMin());
471 dlg.Center();
472
473 if (dlg.ShowModal() != wxID_OK)
474 {
475 return; // user cancelled dialog
476 }
477
478 long lrate;
479 if (cb->GetValue().ToLong(&lrate) && lrate >= 1 && lrate <= 1000000)
480 {
481 newRate = (int)lrate;
482 break;
483 }
484
486 XO("The entered value is invalid"),
487 XO("Error"),
488 wxICON_ERROR,
489 mpData->pParent);
490 }
491
492 SetRate(pTrack, newRate);
493
494 using namespace RefreshCode;
496}
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:630
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.

Definition at line 382 of file WaveTrackControls.cpp.

383{
385 auto end1 = pTrack->GetEndTime();
386 pTrack->SetRate(rate);
387 if (SyncLockState::Get(*project).IsSyncLocked()) {
388 auto end2 = pTrack->GetEndTime();
389 for (auto pLocked : SyncLock::Group(pTrack)) {
390 if (pLocked != pTrack)
391 pLocked->SyncLockAdjust(end1, end2);
392 }
393 }
394
395 // Separate conversion of "rate" enables changing the decimals without affecting i18n
396 wxString rateString = wxString::Format(wxT("%.3f"), rate);
398 /* i18n-hint: The string names a track */
399 .PushState(XO("Changed '%s' to %s Hz")
400 .Format( pTrack->GetName(), rateString),
401 XO("Rate Change"));
402}
const auto project
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)
static TrackIterRange< Track > Group(Track *pTrack)
Definition: SyncLock.cpp:161
bool IsSyncLocked() const
Definition: SyncLock.cpp:43
static SyncLockState & Get(AudacityProject &project)
Definition: SyncLock.cpp:26
const wxString & GetName() const
Name is always the same for all channels of a group.
Definition: Track.cpp:56
void SetRate(double newRate)
Definition: WaveTrack.cpp:1090
double GetEndTime() const override
Implement WideSampleSequence.
Definition: WaveTrack.cpp:3050

References ProjectHistory::Get(), SyncLockState::Get(), WaveTrack::GetEndTime(), Track::GetName(), SyncLock::Group(), SyncLockState::IsSyncLocked(), mpData, project, CommonTrackControls::InitMenuData::project, ProjectHistory::PushState(), WaveTrack::SetRate(), 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 318 of file WaveTrackControls.cpp.

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


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