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

Public Member Functions

 RateMenuTable ()
void InitUserData (void *pUserData) override
 Called before the menu items are appended. More...
void SetRate (WaveTrack &track, 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 304 of file WaveTrackControls.cpp.

Constructor & Destructor Documentation

◆ RateMenuTable()

RateMenuTable::RateMenuTable ( )

Definition at line 306 of file WaveTrackControls.cpp.

307 : PopupMenuTable{ "SampleRate", XO("Rat&e") }
308 {}

Member Function Documentation


RateMenuTable::DECLARE_POPUP_MENU ( RateMenuTable  )

◆ IdOfRate()

int RateMenuTable::IdOfRate ( int  rate)

Converts a sampling rate to a wxWidgets menu item id.

Definition at line 370 of file WaveTrackControls.cpp.

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

References gRates, nRates, OnRate8ID, and OnRateOtherID.

◆ InitUserData()

void RateMenuTable::InitUserData ( void *  pUserData)

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

333 mpData = static_cast<PlayableTrackControls::InitMenuData*>(pUserData);
PlayableTrackControls::InitMenuData * mpData

References mpData.

◆ Instance()

RateMenuTable & RateMenuTable::Instance ( )

Definition at line 325 of file WaveTrackControls.cpp.

327 static RateMenuTable instance;
328 return instance;

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

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

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

Here is the call graph for this function:

◆ OnRateOther()

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

Definition at line 415 of file WaveTrackControls.cpp.

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

Here is the call graph for this function:

◆ SetRate()

void RateMenuTable::SetRate ( WaveTrack track,
double  rate 

Sets the sample rate for a track.

Definition at line 379 of file WaveTrackControls.cpp.

382 auto end1 = track.GetEndTime();
383 track.SetRate(rate);
384 if (SyncLockState::Get(*project).IsSyncLocked()) {
385 auto end2 = track.GetEndTime();
386 for (auto pLocked : SyncLock::Group(track)) {
387 if (pLocked != &track)
388 pLocked->SyncLockAdjust(end1, end2);
389 }
390 }
392 // Separate conversion of "rate" enables changing the decimals without affecting i18n
393 wxString rateString = wxString::Format(wxT("%.3f"), rate);
395 /* i18n-hint: The string names a track */
396 .PushState(XO("Changed '%s' to %s Hz")
397 .Format(track.GetName(), rateString),
398 XO("Rate Change"));
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 &track)
Definition: SyncLock.cpp:150
bool IsSyncLocked() const
Definition: SyncLock.cpp:44
static SyncLockState & Get(AudacityProject &project)
Definition: SyncLock.cpp:27
const wxString & GetName() const
Name is always the same for all channels of a group.
Definition: Track.cpp:64
void SetRate(double newRate)
!brief Sets the new rate for the track without resampling it
Definition: WaveTrack.cpp:803
double GetEndTime() const override
Implement WideSampleSequence.
Definition: WaveTrack.cpp:2586

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

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

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