mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-26 00:58:37 +02:00
static overloads of Track::SharedPointer when null check is needed...
... Some optimizing compilers don't let us get away with null check on this in a nonstatic member function.
This commit is contained in:
parent
1af342ff64
commit
bb634614e6
@ -97,7 +97,7 @@ void SelectionState::ChangeSelectionOnShiftClick
|
|||||||
|
|
||||||
// Our track was earlier than the first. Extend from the last.
|
// Our track was earlier than the first. Extend from the last.
|
||||||
if( !pExtendFrom )
|
if( !pExtendFrom )
|
||||||
pExtendFrom = (*trackRange.rbegin())->SharedPointer();
|
pExtendFrom = Track::SharedPointer( *trackRange.rbegin() );
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectNone( tracks );
|
SelectNone( tracks );
|
||||||
|
11
src/Track.h
11
src/Track.h
@ -238,7 +238,6 @@ class AUDACITY_DLL_API Track /* not final */
|
|||||||
{
|
{
|
||||||
// shared_from_this is injected into class scope by base class
|
// shared_from_this is injected into class scope by base class
|
||||||
// std::enable_shared_from_this<Track>
|
// std::enable_shared_from_this<Track>
|
||||||
if (!this) return {};
|
|
||||||
return std::static_pointer_cast<Subclass>( shared_from_this() );
|
return std::static_pointer_cast<Subclass>( shared_from_this() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,10 +249,18 @@ class AUDACITY_DLL_API Track /* not final */
|
|||||||
{
|
{
|
||||||
// shared_from_this is injected into class scope by base class
|
// shared_from_this is injected into class scope by base class
|
||||||
// std::enable_shared_from_this<Track>
|
// std::enable_shared_from_this<Track>
|
||||||
if (!this) return {};
|
|
||||||
return std::static_pointer_cast<Subclass>( shared_from_this() );
|
return std::static_pointer_cast<Subclass>( shared_from_this() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Static overloads of SharedPointer for when the pointer may be null
|
||||||
|
template<typename Subclass = Track>
|
||||||
|
static inline std::shared_ptr<Subclass> SharedPointer( Track *pTrack )
|
||||||
|
{ return pTrack ? pTrack->SharedPointer<Subclass>() : nullptr; }
|
||||||
|
|
||||||
|
template<typename Subclass = const Track>
|
||||||
|
static inline std::shared_ptr<Subclass> SharedPointer( const Track *pTrack )
|
||||||
|
{ return pTrack ? pTrack->SharedPointer<Subclass>() : nullptr; }
|
||||||
|
|
||||||
// Find anything registered with TrackList::RegisterPendingChangedTrack and
|
// Find anything registered with TrackList::RegisterPendingChangedTrack and
|
||||||
// not yet cleared or applied; if no such exists, return this track
|
// not yet cleared or applied; if no such exists, return this track
|
||||||
std::shared_ptr<const Track> SubstitutePendingChangedTrack() const;
|
std::shared_ptr<const Track> SubstitutePendingChangedTrack() const;
|
||||||
|
@ -2247,7 +2247,7 @@ void TrackPanel::SetFocusedTrack( Track *t )
|
|||||||
// Make sure we always have the first linked track of a stereo track
|
// Make sure we always have the first linked track of a stereo track
|
||||||
t = *GetTracks()->FindLeader(t);
|
t = *GetTracks()->FindLeader(t);
|
||||||
|
|
||||||
auto cell = mAx->SetFocus( t->SharedPointer() ).get();
|
auto cell = mAx->SetFocus( Track::SharedPointer( t ) ).get();
|
||||||
|
|
||||||
if (cell) {
|
if (cell) {
|
||||||
AudacityProject::CaptureKeyboard(this);
|
AudacityProject::CaptureKeyboard(this);
|
||||||
|
@ -64,7 +64,7 @@ std::shared_ptr<Track> TrackPanelAx::GetFocus()
|
|||||||
}
|
}
|
||||||
if (!focusedTrack) {
|
if (!focusedTrack) {
|
||||||
focusedTrack =
|
focusedTrack =
|
||||||
(*mTrackPanel->GetTracks()->Any().first)->SharedPointer();
|
Track::SharedPointer( *mTrackPanel->GetTracks()->Any().first );
|
||||||
// only call SetFocus if the focus has changed to avoid
|
// only call SetFocus if the focus has changed to avoid
|
||||||
// unnecessary focus events
|
// unnecessary focus events
|
||||||
if (focusedTrack)
|
if (focusedTrack)
|
||||||
@ -99,7 +99,7 @@ std::shared_ptr<Track> TrackPanelAx::SetFocus( std::shared_ptr<Track> track )
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( !track )
|
if( !track )
|
||||||
track = (*mTrackPanel->GetTracks()->Any().begin())->SharedPointer();
|
track = Track::SharedPointer( *mTrackPanel->GetTracks()->Any().begin() );
|
||||||
|
|
||||||
mFocusedTrack = track;
|
mFocusedTrack = track;
|
||||||
mNumFocusedTrack = TrackNum(track);
|
mNumFocusedTrack = TrackNum(track);
|
||||||
|
@ -1144,7 +1144,7 @@ void SelectHandle::AdjustSelection
|
|||||||
std::max(0.0, viewInfo.PositionToTime(mouseXCoordinate, trackLeftEdge));
|
std::max(0.0, viewInfo.PositionToTime(mouseXCoordinate, trackLeftEdge));
|
||||||
double origSelend = selend;
|
double origSelend = selend;
|
||||||
|
|
||||||
auto pTrack = track->SharedPointer();
|
auto pTrack = Track::SharedPointer( track );
|
||||||
if (!pTrack)
|
if (!pTrack)
|
||||||
pTrack = pProject->GetTracks()->Lock(mpTrack);
|
pTrack = pProject->GetTracks()->Lock(mpTrack);
|
||||||
|
|
||||||
|
@ -695,7 +695,7 @@ UIHandle::Result TimeShiftHandle::Drag
|
|||||||
}
|
}
|
||||||
|
|
||||||
// May need a shared_ptr to reassign mCapturedTrack below
|
// May need a shared_ptr to reassign mCapturedTrack below
|
||||||
auto pTrack = track->SharedPointer();
|
auto pTrack = Track::SharedPointer( track );
|
||||||
if (!pTrack)
|
if (!pTrack)
|
||||||
return RefreshCode::RefreshNone;
|
return RefreshCode::RefreshNone;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user