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

Public Member Functions

 WaveTrackMenuTable ()
 
void InitUserData (void *pUserData) override
 Called before the menu items are appended. More...
 
 DECLARE_POPUP_MENU (WaveTrackMenuTable)
 
void OnMultiView (wxCommandEvent &event)
 
void OnSetDisplay (wxCommandEvent &event)
 Set the Display mode based on the menu choice in the Track Menu. More...
 
void OnMergeStereo (wxCommandEvent &event)
 Merge two tracks into one stereo track ?? More...
 
void SplitStereo (bool stereo)
 Splits stereo track into two mono tracks, preserving panning if stereo is set. More...
 
void OnSwapChannels (wxCommandEvent &event)
 Swap the left and right channels of a stero track... More...
 
void OnSplitStereo (wxCommandEvent &event)
 Split a stereo track into two tracks... More...
 
void OnSplitStereoMono (wxCommandEvent &event)
 Split a stereo track into two mono tracks... More...
 
- Public Member Functions inherited from WaveTrackPopupMenuTable
WaveTrackFindWaveTrack () const
 
int ReserveId ()
 
 PopupMenuTable (const Identifier &id, const TranslatableString &caption={})
 
- 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 WaveTrackMenuTableInstance ()
 
- 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)
 

Additional Inherited Members

- Public Types inherited from PopupMenuTable
using Entry = PopupMenuTableEntry
 
- Public Attributes inherited from WaveTrackPopupMenuTable
PlayableTrackControls::InitMenuDatampData {}
 
- 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 WaveTrackPopupMenuTable
int mNextId = 0
 
- 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 499 of file WaveTrackControls.cpp.

Constructor & Destructor Documentation

◆ WaveTrackMenuTable()

WaveTrackMenuTable::WaveTrackMenuTable ( )
inline

Member Function Documentation

◆ DECLARE_POPUP_MENU()

WaveTrackMenuTable::DECLARE_POPUP_MENU ( WaveTrackMenuTable  )

◆ InitUserData()

void WaveTrackMenuTable::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 535 of file WaveTrackControls.cpp.

536{
537 mpData = static_cast<PlayableTrackControls::InitMenuData*>(pUserData);
538}
PlayableTrackControls::InitMenuData * mpData

References WaveTrackPopupMenuTable::mpData.

◆ Instance()

WaveTrackMenuTable & WaveTrackMenuTable::Instance ( )
static

Definition at line 529 of file WaveTrackControls.cpp.

530{
531 static WaveTrackMenuTable instance;
532 return instance;
533}

Referenced by WaveTrackControls::GetMenuExtension(), and GetWaveTrackMenuTable().

Here is the caller graph for this function:

◆ OnMergeStereo()

void WaveTrackMenuTable::OnMergeStereo ( wxCommandEvent &  event)

Merge two tracks into one stereo track ??

Definition at line 746 of file WaveTrackControls.cpp.

747{
749 auto &tracks = TrackList::Get( *project );
750
751 const auto first = tracks.Any<WaveTrack>().find(&mpData->track);
752 const auto left = *first;
753 const auto right = *std::next(first);
754
755 const auto checkAligned = [](const WaveTrack& left, const WaveTrack& right)
756 {
757 auto eqTrims = [](double a, double b)
758 {
759 return std::abs(a - b) <=
760 std::numeric_limits<double>::epsilon() * std::max(a, b);
761 };
762 const auto eps = 0.5 / left.GetRate();
763 const auto &rightIntervals = right.Intervals();
764 for (const auto &a : left.Intervals()) {
765 auto it = std::find_if(
766 rightIntervals.begin(),
767 rightIntervals.end(),
768 [&](const auto& b)
769 {
770 //Start() and End() are always snapped to a sample grid
771 return std::abs(a->Start() - b->Start()) < eps &&
772 std::abs(a->End() - b->End()) < eps &&
773 eqTrims(a->GetTrimLeft(), b->GetTrimLeft()) &&
774 eqTrims(a->GetTrimRight(), b->GetTrimRight()) &&
775 a->HasEqualPitchAndSpeed(*b);
776 });
777 if(it == rightIntervals.end())
778 return false;
779 }
780 return true;
781 };
782
783 if(RealtimeEffectList::Get(*left).GetStatesCount() != 0 ||
785 !checkAligned(*left, *right))
786 {
787 const auto answer = BasicUI::ShowMessageBox(
788 XO(
789"The tracks you are attempting to merge to stereo contain clips at\n"
790"different positions, or otherwise mismatching clips. Merging them\n"
791"will render the tracks.\n\n"
792"This causes any realtime effects to be applied to the waveform and\n"
793"hidden data to be removed. Additionally, the entire track will\n"
794"become one large clip.\n\n"
795"Do you wish to continue?"
796 ),
799 .Caption(XO("Combine mono to stereo")));
801 return;
802 }
803
804 const auto viewMinimized =
806 ChannelView::Get(*right->GetChannel(0)).GetMinimized();
807 const auto averageViewHeight =
810
811 left->SetPan(-1.0f);
812 right->SetPan(1.0f);
813 auto mix = MixAndRender(
815 tracks.Any<const WaveTrack>().find(left),
816 ++tracks.Any<const WaveTrack>().find(right)
817 },
818 Mixer::WarpOptions{ tracks.GetOwner() },
819 (*first)->GetName(),
821 //use highest sample rate
822 std::max(left->GetRate(), right->GetRate()),
823 //use widest sample format
824 std::max(left->GetSampleFormat(), right->GetSampleFormat()),
825 0.0, 0.0);
826
827 tracks.Insert(*first, mix);
828 tracks.Remove(*left);
829 tracks.Remove(*right);
830
831 for(const auto& channel : mix->Channels())
832 {
833 // Set NEW track heights and minimized state
834 auto& view = ChannelView::Get(*channel);
835 view.SetMinimized(viewMinimized);
836 view.SetExpandedHeight(averageViewHeight);
837 }
838 ProjectHistory::Get( *project ).PushState(
839 /* i18n-hint: The string names a track */
840 XO("Made '%s' a stereo track").Format(mix->GetName()),
841 XO("Make Stereo"));
842
843 using namespace RefreshCode;
845}
XO("Cut/Copy/Paste")
Track::Holder MixAndRender(const TrackIterRange< const WaveTrack > &trackRange, const Mixer::WarpOptions &warpOptions, const wxString &newTrackName, WaveTrackFactory *trackFactory, double rate, sampleFormat format, double startTime, double endTime)
Mixes together all input tracks, applying any envelopes, amplitude gain, panning, and real-time effec...
const auto tracks
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
static ChannelView & Get(Channel &channel)
bool GetMinimized() const
Definition: ChannelView.h:69
int GetHeight() const
Abstract base class used in importing a file.
const TranslatableString & Caption() const
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
static RealtimeEffectList & Get(AudacityProject &project)
size_t GetStatesCount() const noexcept
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
static WaveChannelView & GetFirst(WaveTrack &wt)
Get the view of the first channel.
static WaveTrackFactory & Get(AudacityProject &project)
Definition: WaveTrack.cpp:3349
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
sampleFormat GetSampleFormat() const override
Definition: WaveTrack.cpp:895
void SetPan(float newPan)
Definition: WaveTrack.cpp:847
double GetRate() const override
Definition: WaveTrack.cpp:798
auto Intervals()
Definition: WaveTrack.h:670
auto GetChannel(size_t iChannel)
Definition: WaveTrack.h:258
@ YesNo
Two buttons.
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
Definition: BasicUI.h:279
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
MessageBoxOptions && ButtonStyle(Button style) &&
Definition: BasicUI.h:107
Immutable structure is an argument to Mixer's constructor.
Definition: MixerOptions.h:56
Range between two TrackIters, usable in range-for statements, and with Visit member functions.
Definition: Track.h:682

References BasicUI::MessageBoxOptions::ButtonStyle(), PopupMenuTable::Caption(), RefreshCode::FixScrollbars, ProjectHistory::Get(), RealtimeEffectList::Get(), TrackList::Get(), WaveTrackFactory::Get(), ChannelView::Get(), WaveTrack::GetChannel(), WaveChannelView::GetFirst(), ChannelView::GetHeight(), ChannelView::GetMinimized(), WaveTrack::GetRate(), WaveTrack::GetSampleFormat(), RealtimeEffectList::GetStatesCount(), WaveTrack::Intervals(), MixAndRender(), WaveTrackPopupMenuTable::mpData, project, CommonTrackControls::InitMenuData::project, ProjectHistory::PushState(), RefreshCode::RefreshAll, CommonTrackControls::InitMenuData::result, WaveTrack::SetPan(), BasicUI::ShowMessageBox(), CommonTrackControls::InitMenuData::track, tracks, XO(), BasicUI::Yes, and BasicUI::YesNo.

Here is the call graph for this function:

◆ OnMultiView()

void WaveTrackMenuTable::OnMultiView ( wxCommandEvent &  event)

Definition at line 692 of file WaveTrackControls.cpp.

693{
694 auto &track = static_cast<WaveTrack&>(mpData->track);
695 auto &view = WaveChannelView::GetFirst(track);
696 bool multi = !view.GetMultiView();
697 const auto &displays = view.GetDisplays();
698 const auto display = displays.empty()
699 ? WaveChannelViewConstants::Waveform : displays.begin()->id;
700 view.SetMultiView(multi);
701
702 // Whichever sub-view was on top stays on top
703 // If going into Multi-view, it will be 1/nth the height.
704 // If exiting multi-view, it will be full height.
705 view.SetDisplay(display, !multi);
706}

References WaveChannelView::GetFirst(), and WaveChannelViewConstants::Waveform.

Here is the call graph for this function:

◆ OnSetDisplay()

void WaveTrackMenuTable::OnSetDisplay ( wxCommandEvent &  event)

Set the Display mode based on the menu choice in the Track Menu.

Definition at line 709 of file WaveTrackControls.cpp.

710{
711 int idInt = event.GetId();
712 wxASSERT(idInt >= OnSetDisplayId &&
713 idInt <= lastDisplayId);
714 auto &track = static_cast<WaveTrack&>(mpData->track);
715
716 auto id = AllTypes()[ idInt - OnSetDisplayId ].id;
717
718 auto &view = WaveChannelView::GetFirst(track);
719 if (view.GetMultiView()) {
720 if (!WaveChannelView::GetFirst(track)
721 .ToggleSubView(WaveChannelView::Display{ id } )) {
722 // Trying to toggle off the last sub-view. It was refused.
723 // Decide what to do here. Turn off multi-view instead?
724 // PRL: I don't agree that it makes sense
725 }
726 else
728 }
729 else {
730 const auto displays = view.GetDisplays();
731 const bool wrongType =
732 !(displays.size() == 1 && displays[0].id == id);
733 if (wrongType) {
735
737 ProjectHistory::Get( *project ).ModifyState(true);
738
739 using namespace RefreshCode;
741 }
742 }
743}
static std::vector< WaveChannelSubViewType > AllTypes()
int id
@ lastDisplayId
@ OnSetDisplayId
void ModifyState(bool bWantsAutoSave)
void SetDisplay(Display display, bool exclusive=true)

References AllTypes(), ProjectHistory::Get(), WaveChannelView::GetFirst(), id, lastDisplayId, ProjectHistory::ModifyState(), WaveTrackPopupMenuTable::mpData, OnSetDisplayId, project, CommonTrackControls::InitMenuData::project, RefreshCode::RefreshAll, CommonTrackControls::InitMenuData::result, WaveChannelView::SetDisplay(), CommonTrackControls::InitMenuData::track, and RefreshCode::UpdateVRuler.

Here is the call graph for this function:

◆ OnSplitStereo()

void WaveTrackMenuTable::OnSplitStereo ( wxCommandEvent &  event)

Split a stereo track into two tracks...

Definition at line 896 of file WaveTrackControls.cpp.

897{
898 SplitStereo(true);
899 auto &track = static_cast<WaveTrack&>(mpData->track);
901 ProjectHistory::Get( *project ).PushState(
902 /* i18n-hint: The string names a track */
903 XO("Split stereo track '%s'").Format(track.GetName()),
904 XO("Split"));
905
906 using namespace RefreshCode;
908}
void SplitStereo(bool stereo)
Splits stereo track into two mono tracks, preserving panning if stereo is set.

References RefreshCode::FixScrollbars, ProjectHistory::Get(), Track::GetName(), WaveTrackPopupMenuTable::mpData, project, CommonTrackControls::InitMenuData::project, ProjectHistory::PushState(), RefreshCode::RefreshAll, CommonTrackControls::InitMenuData::result, SplitStereo(), CommonTrackControls::InitMenuData::track, and XO().

Here is the call graph for this function:

◆ OnSplitStereoMono()

void WaveTrackMenuTable::OnSplitStereoMono ( wxCommandEvent &  event)

Split a stereo track into two mono tracks...

Definition at line 911 of file WaveTrackControls.cpp.

912{
913 SplitStereo(false);
914 auto &track = static_cast<WaveTrack&>(mpData->track);
916 ProjectHistory::Get( *project ).PushState(
917 /* i18n-hint: The string names a track */
918 XO("Split Stereo to Mono '%s'").Format(track.GetName()),
919 XO("Split to Mono"));
920
921 using namespace RefreshCode;
923}

References RefreshCode::FixScrollbars, ProjectHistory::Get(), Track::GetName(), WaveTrackPopupMenuTable::mpData, project, CommonTrackControls::InitMenuData::project, ProjectHistory::PushState(), RefreshCode::RefreshAll, CommonTrackControls::InitMenuData::result, SplitStereo(), CommonTrackControls::InitMenuData::track, and XO().

Here is the call graph for this function:

◆ OnSwapChannels()

void WaveTrackMenuTable::OnSwapChannels ( wxCommandEvent &  event)

Swap the left and right channels of a stero track...

Definition at line 880 of file WaveTrackControls.cpp.

881{
883
884 auto &trackFocus = TrackFocus::Get( *project );
885 auto &track = static_cast<WaveTrack&>(mpData->track);
886 track.SwapChannels();
887 ProjectHistory::Get( *project ).PushState(
888 /* i18n-hint: The string names a track */
889 XO("Swapped Channels in '%s'").Format(track.GetName()),
890 XO("Swap Channels"));
891
893}
Track * Get()
Definition: TrackFocus.cpp:156
void SwapChannels()
Definition: WaveTrack.cpp:1060

References TrackFocus::Get(), ProjectHistory::Get(), Track::GetName(), WaveTrackPopupMenuTable::mpData, project, CommonTrackControls::InitMenuData::project, ProjectHistory::PushState(), RefreshCode::RefreshAll, CommonTrackControls::InitMenuData::result, WaveTrack::SwapChannels(), CommonTrackControls::InitMenuData::track, and XO().

Here is the call graph for this function:

◆ SplitStereo()

void WaveTrackMenuTable::SplitStereo ( bool  stereo)

Splits stereo track into two mono tracks, preserving panning if stereo is set.

Split a stereo track (or more-than-stereo?) into two (or more) tracks...

Definition at line 848 of file WaveTrackControls.cpp.

849{
851
852 int totalHeight = 0;
853 int nChannels = 0;
854
855 auto &track = static_cast<WaveTrack&>(mpData->track);
856 const std::vector<WaveTrack::Holder> unlinkedTracks = track.SplitChannels();
857 if (stereo) {
858 unlinkedTracks[0]->SetPan(-1.0f);
859 unlinkedTracks[1]->SetPan(1.0f);
860 }
861
862 for (const auto track : unlinkedTracks) {
863 auto &view = ChannelView::Get(*track->GetChannel(0));
864
865 //make sure no channel is smaller than its minimum height
866 if (view.GetHeight() < view.GetMinimizedHeight())
867 view.SetExpandedHeight(view.GetMinimizedHeight());
868 totalHeight += view.GetHeight();
869 ++nChannels;
870 }
871
872 int averageHeight = totalHeight / nChannels;
873
874 for (const auto track : unlinkedTracks)
875 // Make tracks the same height
876 ChannelView::Get(*track->GetChannel(0)).SetExpandedHeight(averageHeight);
877}
void SetExpandedHeight(int height)
std::vector< Holder > SplitChannels()
Definition: WaveTrack.cpp:1041

References ChannelView::Get(), WaveTrack::GetChannel(), WaveTrackPopupMenuTable::mpData, project, CommonTrackControls::InitMenuData::project, ChannelView::SetExpandedHeight(), WaveTrack::SplitChannels(), and CommonTrackControls::InitMenuData::track.

Referenced by OnSplitStereo(), and OnSplitStereoMono().

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

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