1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-15 15:49:36 +02:00

Lower mCapturedTrack into ClipMoveState, simplify one member function

This commit is contained in:
Paul Licameli 2020-09-12 15:48:53 -04:00
parent 329221b392
commit bc7f527a3b
3 changed files with 19 additions and 18 deletions

View File

@ -671,8 +671,8 @@ double DoClipMove
if (!right) if (!right)
desiredSlideAmount *= -1; desiredSlideAmount *= -1;
auto hSlideAmount = state.DoSlideHorizontal( auto hSlideAmount =
desiredSlideAmount, trackList, *track ); state.DoSlideHorizontal( desiredSlideAmount, trackList );
// update t0 and t1. There is the possibility that the updated // update t0 and t1. There is the possibility that the updated
// t0 may no longer be within the clip due to rounding errors, // t0 may no longer be within the clip due to rounding errors,

View File

@ -45,9 +45,9 @@ TrackClip::~TrackClip()
TimeShiftHandle::TimeShiftHandle TimeShiftHandle::TimeShiftHandle
( const std::shared_ptr<Track> &pTrack, bool gripHit ) ( const std::shared_ptr<Track> &pTrack, bool gripHit )
: mCapturedTrack{ pTrack } : mGripHit{ gripHit }
, mGripHit{ gripHit }
{ {
mClipMoveState.mCapturedTrack = pTrack;
} }
void TimeShiftHandle::Enter(bool, AudacityProject *) void TimeShiftHandle::Enter(bool, AudacityProject *)
@ -320,6 +320,7 @@ void ClipMoveState::Init(
}); });
auto &state = *this; auto &state = *this;
state.mCapturedTrack = capturedTrack.SharedPointer();
state.movingSelection = capturedTrack.IsSelected() && state.movingSelection = capturedTrack.IsSelected() &&
clickTime >= viewInfo.selectedRegion.t0() && clickTime >= viewInfo.selectedRegion.t0() &&
@ -474,9 +475,10 @@ void ClipMoveState::Init(
} }
double ClipMoveState::DoSlideHorizontal( double ClipMoveState::DoSlideHorizontal(
double desiredSlideAmount, TrackList &trackList, Track &capturedTrack ) double desiredSlideAmount, TrackList &trackList )
{ {
auto &state = *this; auto &state = *this;
auto &capturedTrack = *state.mCapturedTrack;
state.hSlideAmount = desiredSlideAmount; state.hSlideAmount = desiredSlideAmount;
// Given a signed slide distance, move clips, but subject to constraint of // Given a signed slide distance, move clips, but subject to constraint of
@ -896,7 +898,7 @@ UIHandle::Result TimeShiftHandle::Drag
// within the bounds of the tracks area. // within the bounds of the tracks area.
if (event.m_x >= mRect.GetX() && if (event.m_x >= mRect.GetX() &&
event.m_x < mRect.GetX() + mRect.GetWidth()) event.m_x < mRect.GetX() + mRect.GetWidth())
track = mCapturedTrack.get(); track = mClipMoveState.mCapturedTrack.get();
} }
// May need a shared_ptr to reassign mCapturedTrack below // May need a shared_ptr to reassign mCapturedTrack below
@ -907,14 +909,14 @@ UIHandle::Result TimeShiftHandle::Drag
auto &trackList = TrackList::Get( *pProject ); auto &trackList = TrackList::Get( *pProject );
// GM: DoSlide now implementing snap-to // GM: slide now implementing snap-to
// samples functionality based on sample rate. // samples functionality based on sample rate.
// Start by undoing the current slide amount; everything // Start by undoing the current slide amount; everything
// happens relative to the original horizontal position of // happens relative to the original horizontal position of
// each clip... // each clip...
DoOffset( DoOffset(
mClipMoveState, mCapturedTrack.get(), -mClipMoveState.hSlideAmount ); mClipMoveState, mClipMoveState.mCapturedTrack.get(), -mClipMoveState.hSlideAmount );
if ( mClipMoveState.movingSelection ) { if ( mClipMoveState.movingSelection ) {
// Slide the selection, too // Slide the selection, too
@ -925,7 +927,7 @@ UIHandle::Result TimeShiftHandle::Drag
double desiredSlideAmount = double desiredSlideAmount =
FindDesiredSlideAmount( viewInfo, mRect.x, event, mSnapManager.get(), FindDesiredSlideAmount( viewInfo, mRect.x, event, mSnapManager.get(),
mSlideUpDownOnly, mSnapPreferRightEdge, mClipMoveState, mSlideUpDownOnly, mSnapPreferRightEdge, mClipMoveState,
*mCapturedTrack, *pTrack ); *mClipMoveState.mCapturedTrack, *pTrack );
// Scroll during vertical drag. // Scroll during vertical drag.
// EnsureVisible(pTrack); //vvv Gale says this has problems on Linux, per bug 393 thread. Revert for 2.0.2. // EnsureVisible(pTrack); //vvv Gale says this has problems on Linux, per bug 393 thread. Revert for 2.0.2.
@ -935,12 +937,12 @@ UIHandle::Result TimeShiftHandle::Drag
// decide which tracks the captured clips should go to. // decide which tracks the captured clips should go to.
bool fail = ( bool fail = (
mClipMoveState.capturedClip && mClipMoveState.capturedClip &&
pTrack != mCapturedTrack pTrack != mClipMoveState.mCapturedTrack
/* && !mCapturedClipIsSelection*/ /* && !mCapturedClipIsSelection*/
&& pTrack->TypeSwitch<bool>( [&] (WaveTrack *) { && pTrack->TypeSwitch<bool>( [&] (WaveTrack *) {
if ( DoSlideVertical( viewInfo, event.m_x, mClipMoveState, if ( DoSlideVertical( viewInfo, event.m_x, mClipMoveState,
trackList, *mCapturedTrack, *pTrack, desiredSlideAmount ) ) { trackList, *mClipMoveState.mCapturedTrack, *pTrack, desiredSlideAmount ) ) {
mCapturedTrack = pTrack; mClipMoveState.mCapturedTrack = pTrack;
mDidSlideVertically = true; mDidSlideVertically = true;
} }
else else
@ -958,8 +960,7 @@ UIHandle::Result TimeShiftHandle::Drag
if (desiredSlideAmount == 0.0) if (desiredSlideAmount == 0.0)
return RefreshAll; return RefreshAll;
mClipMoveState.DoSlideHorizontal( mClipMoveState.DoSlideHorizontal( desiredSlideAmount, trackList );
desiredSlideAmount, trackList, *mCapturedTrack );
if (mClipMoveState.movingSelection) { if (mClipMoveState.movingSelection) {
// Slide the selection, too // Slide the selection, too

View File

@ -132,8 +132,9 @@ struct ClipMoveState {
TrackList &trackList, bool syncLocked ); TrackList &trackList, bool syncLocked );
/*! @return actual slide amount, maybe adjusted toward zero from desired */ /*! @return actual slide amount, maybe adjusted toward zero from desired */
double DoSlideHorizontal( double DoSlideHorizontal( double desiredSlideAmount, TrackList &trackList );
double desiredSlideAmount, TrackList &trackList, Track &capturedTrack );
std::shared_ptr<Track> mCapturedTrack;
// non-NULL only if click was in a WaveTrack and without Shift key: // non-NULL only if click was in a WaveTrack and without Shift key:
WaveClip *capturedClip {}; WaveClip *capturedClip {};
@ -171,7 +172,7 @@ public:
TimeShiftHandle &operator=(TimeShiftHandle&&) = default; TimeShiftHandle &operator=(TimeShiftHandle&&) = default;
bool IsGripHit() const { return mGripHit; } bool IsGripHit() const { return mGripHit; }
std::shared_ptr<Track> GetTrack() const { return mCapturedTrack; } std::shared_ptr<Track> GetTrack() const = delete;
// Try to move clips from one WaveTrack to another, before also moving // Try to move clips from one WaveTrack to another, before also moving
// by some horizontal amount, which may be slightly adjusted to fit the // by some horizontal amount, which may be slightly adjusted to fit the
@ -221,7 +222,6 @@ private:
TrackPanelDrawingContext &, TrackPanelDrawingContext &,
const wxRect &rect, const wxRect &panelRect, unsigned iPass ) override; const wxRect &rect, const wxRect &panelRect, unsigned iPass ) override;
std::shared_ptr<Track> mCapturedTrack;
wxRect mRect{}; wxRect mRect{};
bool mDidSlideVertically{}; bool mDidSlideVertically{};