Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
TrackFocus Class Referencefinal

#include <TrackFocus.h>

Inheritance diagram for TrackFocus:
[legend]
Collaboration diagram for TrackFocus:
[legend]

Public Member Functions

 TrackFocus (AudacityProject &project)
 
 ~TrackFocus () final
 
 TrackFocus (const TrackFocus &)=delete
 
TrackFocusoperator= (const TrackFocus &)=delete
 
void SetCallbacks (std::unique_ptr< TrackFocusCallbacks > pCallbacks)
 
TrackGet ()
 
void Set (Track *pTrack, bool focusPanel=false)
 Set the track focus to a given track or to null. More...
 
void MessageForScreenReader (const TranslatableString &message)
 
void UpdateAccessibility ()
 Called to signal changes to a track. More...
 
std::shared_ptr< TrackPeekFocus () const
 
int TrackNum (const std::shared_ptr< Track > &track) const
 
int NumFocusedTrack () const
 
std::shared_ptr< TrackGetFocus ()
 
const TrackListGetTracks () const
 
std::shared_ptr< TrackFindTrack (int num) const
 
std::shared_ptr< TrackSetFocus (std::shared_ptr< Track > track={}, bool focusPanel=false)
 
- Public Member Functions inherited from ClientData::Base
virtual ~Base ()
 
- Public Member Functions inherited from Observer::Publisher< TrackFocusChangeMessage >
 Publisher (ExceptionPolicy *pPolicy=nullptr, Alloc a={})
 Constructor supporting type-erased custom allocation/deletion. More...
 
 Publisher (Publisher &&)=default
 
Publisheroperator= (Publisher &&)=default
 
Subscription Subscribe (Callback callback)
 Connect a callback to the Publisher; later-connected are called earlier. More...
 
Subscription Subscribe (Object &obj, Return(Object::*callback)(Args...))
 Overload of Subscribe takes an object and pointer-to-member-function. More...
 

Static Public Member Functions

static TrackFocusGet (AudacityProject &project)
 
static const TrackFocusGet (const AudacityProject &project)
 

Private Member Functions

TrackListGetTracks ()
 

Private Attributes

AudacityProjectmProject
 
std::unique_ptr< TrackFocusCallbacksmpCallbacks
 
std::weak_ptr< TrackmFocusedTrack
 
int mNumFocusedTrack { 0 }
 

Additional Inherited Members

- Public Types inherited from Observer::Publisher< TrackFocusChangeMessage >
using message_type = TrackFocusChangeMessage
 
using CallbackReturn = std::conditional_t< true, void, bool >
 
using Callback = std::function< CallbackReturn(const TrackFocusChangeMessage &) >
 Type of functions that can be connected to the Publisher. More...
 
- Static Public Attributes inherited from Observer::Publisher< TrackFocusChangeMessage >
static constexpr bool notifies_all
 
- Protected Member Functions inherited from Observer::Publisher< TrackFocusChangeMessage >
CallbackReturn Publish (const TrackFocusChangeMessage &message)
 Send a message to connected callbacks. More...
 

Detailed Description

Definition at line 38 of file TrackFocus.h.

Constructor & Destructor Documentation

◆ TrackFocus() [1/2]

TrackFocus::TrackFocus ( AudacityProject project)
explicit

Definition at line 142 of file TrackFocus.cpp.

143 : mProject{ project }
144{
145}
const auto project
AudacityProject & mProject
Definition: TrackFocus.h:98

◆ ~TrackFocus()

TrackFocus::~TrackFocus ( )
final

Definition at line 147 of file TrackFocus.cpp.

148{
149}

◆ TrackFocus() [2/2]

TrackFocus::TrackFocus ( const TrackFocus )
delete

Member Function Documentation

◆ FindTrack()

std::shared_ptr< Track > TrackFocus::FindTrack ( int  num) const

Definition at line 113 of file TrackFocus.cpp.

114{
115 int ndx = 0;
116
117 for (auto t : TrackList::Get(mProject)) {
118 ndx++;
119 if( ndx == num )
120 return t->SharedPointer();
121 }
122
123 return {};
124}
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314

References TrackList::Get(), and mProject.

Referenced by GetFocus().

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

◆ Get() [1/3]

Track * TrackFocus::Get ( )
Returns
the currently focused track, which may be null

This function is not const, because it may have a side effect of setting a focus if none was already set

Definition at line 156 of file TrackFocus.cpp.

157{
158 return GetFocus().get();
159}
std::shared_ptr< Track > GetFocus()
Definition: TrackFocus.cpp:33

References GetFocus().

Referenced by SetTrackStatusCommand::ApplyInner(), SelectHandle::Click(), LabelTrackView::DialogForLabelName(), anonymous_namespace{LabelMenus.cpp}::DoAddLabel(), anonymous_namespace{ClipMenus.cpp}::DoClipLeftOrRight(), anonymous_namespace{ClipMenus.cpp}::DoClipMove(), anonymous_namespace{ClipMenus.cpp}::DoCursorClipBoundary(), EffectUI::DoEffect(), LabelTrackView::DoKeyDown(), SelectUtilities::DoListSelection(), anonymous_namespace{PluginMenus.cpp}::DoManageRealtimeEffectsSidePanel(), anonymous_namespace{TrackMenus.cpp}::DoMixAndRender(), anonymous_namespace{TransportMenus.cpp}::DoMoveToLabel(), anonymous_namespace{NavigationMenus.cpp}::DoNextTrack(), anonymous_namespace{EditMenus.cpp}::DoPasteNothingSelected(), anonymous_namespace{NavigationMenus.cpp}::DoPrevTrack(), ProjectAudioManager::DoRecord(), TrackUtilities::DoRemoveTrack(), TrackUtilities::DoRemoveTracks(), anonymous_namespace{ClipMenus.cpp}::DoSelectClip(), anonymous_namespace{ClipMenus.cpp}::DoSelectClipBoundary(), TrackUtilities::DoTrackMute(), TrackUtilities::DoTrackSolo(), anonymous_namespace{TrackPanel.cpp}::LabeledChannelGroup::Draw(), Get(), TrackPanel::GetFocusedCell(), anonymous_namespace{PluginMenus.cpp}::HasTrackFocusFlag(), LabelTrackView::IsValidIndex(), SelectHandle::MoveSnappingFreqSelection(), anonymous_namespace{WaveTrackAffordanceControls.cpp}::OnChangePitchAndSpeed(), anonymous_namespace{WaveTrackAffordanceControls.cpp}::OnEditClipName(), NavigationActions::Handler::OnFirstTrack(), NavigationActions::Handler::OnLastTrack(), TrackPanel::OnMouseEvent(), anonymous_namespace{LabelMenus.cpp}::OnNewLabelTrack(), anonymous_namespace{WaveTrackMenuItems.cpp}::OnNewStereoTrack(), anonymous_namespace{TimeTrackMenuItems.cpp}::OnNewTimeTrack(), anonymous_namespace{WaveTrackMenuItems.cpp}::OnNewWaveTrack(), anonymous_namespace{EditMenus.cpp}::OnPaste(), anonymous_namespace{LabelMenus.cpp}::OnPasteNewLabel(), anonymous_namespace{EditMenus.cpp}::OnRedo(), anonymous_namespace{WaveTrackAffordanceControls.cpp}::OnRenderClipStretching(), WaveTrackMenuTable::OnSwapChannels(), NavigationActions::Handler::OnToggle(), anonymous_namespace{TrackMenus.cpp}::OnTrackClose(), anonymous_namespace{TrackMenus.cpp}::OnTrackGain(), anonymous_namespace{TrackMenus.cpp}::OnTrackGainDec(), anonymous_namespace{TrackMenus.cpp}::OnTrackGainInc(), anonymous_namespace{TrackMenus.cpp}::OnTrackMoveBottom(), anonymous_namespace{TrackMenus.cpp}::OnTrackMoveDown(), anonymous_namespace{TrackMenus.cpp}::OnTrackMoveTop(), anonymous_namespace{TrackMenus.cpp}::OnTrackMoveUp(), anonymous_namespace{TrackMenus.cpp}::OnTrackMute(), anonymous_namespace{TrackMenus.cpp}::OnTrackPan(), anonymous_namespace{TrackMenus.cpp}::OnTrackPanLeft(), anonymous_namespace{TrackMenus.cpp}::OnTrackPanRight(), anonymous_namespace{TrackMenus.cpp}::OnTrackSolo(), anonymous_namespace{EditMenus.cpp}::OnUndo(), TrackPanel::OnUndoReset(), ProjectFileManager::OpenProjectFile(), TrackPanel::ProcessUIHandleResult(), RealtimeEffectPanel::RealtimeEffectPanel(), anonymous_namespace{WaveTrackAffordanceControls.cpp}::SelectedIntervalOfFocusedTrack(), WaveChannelView::SelectNextClip(), GetInfoCommand::SendTracks(), TrackPanel::SetFocusedCell(), MuteButtonHandle::Tip(), SoloButtonHandle::Tip(), EffectsButtonHandle::Tip(), MenuButtonHandle::Tip(), CloseButtonHandle::Tip(), TrackPanel::TrackPanel(), and Viewport::ZoomFitHorizontallyAndShowTrack().

Here is the call graph for this function:

◆ Get() [2/3]

TrackFocus & TrackFocus::Get ( AudacityProject project)
static

Definition at line 132 of file TrackFocus.cpp.

133{
134 return project.AttachedObjects::Get< TrackFocus >( key );
135}
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: TrackFocus.cpp:126

References key, and project.

Referenced by TrackPanel::OnTrackListDeletion().

Here is the caller graph for this function:

◆ Get() [3/3]

const TrackFocus & TrackFocus::Get ( const AudacityProject project)
static

Definition at line 137 of file TrackFocus.cpp.

138{
139 return Get( const_cast< AudacityProject & >( project ) );
140}
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
Track * Get()
Definition: TrackFocus.cpp:156

References Get(), and project.

Here is the call graph for this function:

◆ GetFocus()

std::shared_ptr< Track > TrackFocus::GetFocus ( )

Definition at line 33 of file TrackFocus.cpp.

34{
35 auto focusedTrack = mFocusedTrack.lock();
36 if( !focusedTrack ) {
37 if (mNumFocusedTrack >=1) {
38 // This prevents the focus from being unnecessarily set to track 1
39 // when effects are applied. (Applying an effect can change
40 // the pointers of the selected tracks.)
41 focusedTrack = FindTrack(mNumFocusedTrack);
42 }
43 if (!focusedTrack) {
44 focusedTrack =
45 Track::SharedPointer(*GetTracks().Any().first);
46 // only call SetFocus if the focus has changed to avoid
47 // unnecessary focus events
48 if (focusedTrack)
49 focusedTrack = SetFocus();
50 }
51 }
52
53 if( !TrackNum( focusedTrack ) )
54 {
55 mFocusedTrack.reset();
56 return {};
57 }
58
59 return( focusedTrack );
60}
int TrackNum(const std::shared_ptr< Track > &track) const
Definition: TrackFocus.cpp:96
std::weak_ptr< Track > mFocusedTrack
Definition: TrackFocus.h:100
int mNumFocusedTrack
Definition: TrackFocus.h:101
std::shared_ptr< Track > FindTrack(int num) const
Definition: TrackFocus.cpp:113
const TrackList & GetTracks() const
Definition: TrackFocus.cpp:24
std::shared_ptr< Track > SetFocus(std::shared_ptr< Track > track={}, bool focusPanel=false)
Definition: TrackFocus.cpp:68
std::shared_ptr< Subclass > SharedPointer()
Definition: Track.h:146

References FindTrack(), GetTracks(), mFocusedTrack, mNumFocusedTrack, SetFocus(), Track::SharedPointer(), and TrackNum().

Referenced by Get().

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

◆ GetTracks() [1/2]

TrackList & TrackFocus::GetTracks ( )
private

Definition at line 19 of file TrackFocus.cpp.

20{
21 return TrackList::Get( mProject );
22}

References TrackList::Get(), and mProject.

Here is the call graph for this function:

◆ GetTracks() [2/2]

const TrackList & TrackFocus::GetTracks ( ) const

Definition at line 24 of file TrackFocus.cpp.

25{
26 return TrackList::Get( mProject );
27}

References TrackList::Get(), and mProject.

Referenced by GetFocus(), SetFocus(), and TrackNum().

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

◆ MessageForScreenReader()

void TrackFocus::MessageForScreenReader ( const TranslatableString message)

Definition at line 166 of file TrackFocus.cpp.

167{
168 if (mpCallbacks)
169 mpCallbacks->MessageForScreenReader(message);
170}
std::unique_ptr< TrackFocusCallbacks > mpCallbacks
Definition: TrackFocus.h:99

References mpCallbacks.

◆ NumFocusedTrack()

int TrackFocus::NumFocusedTrack ( ) const
inline

Definition at line 80 of file TrackFocus.h.

80{ return mNumFocusedTrack; }

◆ operator=()

TrackFocus & TrackFocus::operator= ( const TrackFocus )
delete

◆ PeekFocus()

std::shared_ptr< Track > TrackFocus::PeekFocus ( ) const

Definition at line 62 of file TrackFocus.cpp.

63{
64 return mFocusedTrack.lock();
65}

References mFocusedTrack.

Referenced by SetFocus().

Here is the caller graph for this function:

◆ Set()

void TrackFocus::Set ( Track pTrack,
bool  focusPanel = false 
)

Set the track focus to a given track or to null.

Parameters
focusPanelwhether also to focus the window that shows tracks

Definition at line 161 of file TrackFocus.cpp.

162{
163 SetFocus(Track::SharedPointer(pTrack), focusPanel);
164}

References SetFocus(), and Track::SharedPointer().

Here is the call graph for this function:

◆ SetCallbacks()

void TrackFocus::SetCallbacks ( std::unique_ptr< TrackFocusCallbacks pCallbacks)

Definition at line 151 of file TrackFocus.cpp.

152{
153 mpCallbacks = move(pCallbacks);
154}

References mpCallbacks.

◆ SetFocus()

std::shared_ptr< Track > TrackFocus::SetFocus ( std::shared_ptr< Track track = {},
bool  focusPanel = false 
)

Definition at line 68 of file TrackFocus.cpp.

70{
71 if (mpCallbacks)
72 mpCallbacks->BeginChangeFocus();
73
74 if (!track)
76
77 const bool focusChanged = (PeekFocus() != track);
78 if (focusChanged) {
79 mFocusedTrack = track;
80 }
81 if (focusChanged || focusPanel)
83 wFocus = weak_from_this(), focusPanel
84 ]{
85 if (auto pFocus = wFocus.lock())
86 pFocus->Publish({ focusPanel });
87 });
89
90 if (mpCallbacks)
91 mpCallbacks->EndChangeFocus(track);
92
93 return track;
94}
std::shared_ptr< Track > PeekFocus() const
Definition: TrackFocus.cpp:62
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
Definition: BasicUI.cpp:213
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101

References details::begin(), BasicUI::CallAfter(), GetTracks(), mFocusedTrack, mNumFocusedTrack, mpCallbacks, PeekFocus(), Track::SharedPointer(), and TrackNum().

Referenced by GetFocus(), and Set().

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

◆ TrackNum()

int TrackFocus::TrackNum ( const std::shared_ptr< Track > &  track) const

Definition at line 96 of file TrackFocus.cpp.

97{
98 // Find 1-based position of the target in the visible tracks, or 0 if not
99 // found
100 int ndx = 0;
101
102 for (auto t : GetTracks()) {
103 ndx++;
104 if( t == target.get() )
105 {
106 return ndx;
107 }
108 }
109
110 return 0;
111}

References GetTracks().

Referenced by GetFocus(), and SetFocus().

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

◆ UpdateAccessibility()

void TrackFocus::UpdateAccessibility ( )

Called to signal changes to a track.

Definition at line 172 of file TrackFocus.cpp.

173{
174 if (mpCallbacks)
175 mpCallbacks->UpdateAccessibility();
176}

References mpCallbacks.

Member Data Documentation

◆ mFocusedTrack

std::weak_ptr<Track> TrackFocus::mFocusedTrack
private

Definition at line 100 of file TrackFocus.h.

Referenced by GetFocus(), PeekFocus(), and SetFocus().

◆ mNumFocusedTrack

int TrackFocus::mNumFocusedTrack { 0 }
private

Definition at line 101 of file TrackFocus.h.

Referenced by GetFocus(), and SetFocus().

◆ mpCallbacks

std::unique_ptr<TrackFocusCallbacks> TrackFocus::mpCallbacks
private

Definition at line 99 of file TrackFocus.h.

Referenced by MessageForScreenReader(), SetCallbacks(), SetFocus(), and UpdateAccessibility().

◆ mProject

AudacityProject& TrackFocus::mProject
private

Definition at line 98 of file TrackFocus.h.

Referenced by FindTrack(), and GetTracks().


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