1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-01 08:29:27 +02:00

Another TrackShifter method eliminates a use of capturedClipArray

This commit is contained in:
Paul Licameli 2020-09-12 18:57:59 -04:00
parent c98285c544
commit 3009bdde2c
3 changed files with 49 additions and 24 deletions

View File

@ -1440,6 +1440,15 @@ public:
return true; return true;
} }
void DoHorizontalOffset( double offset ) override
{
for ( auto &interval : MovingIntervals() ) {
auto data =
static_cast<WaveTrack::IntervalData*>( interval.Extra() );
data->GetClip()->Offset( offset );
}
}
private: private:
std::shared_ptr<WaveTrack> mpTrack; std::shared_ptr<WaveTrack> mpTrack;

View File

@ -178,22 +178,17 @@ namespace
return 0; return 0;
} }
}
void DoOffset( ClipMoveState &state, Track *pTrack, double offset ) void ClipMoveState::DoHorizontalOffset( double offset )
{ {
auto &clips = state.capturedClipArray; if ( !shifters.empty() ) {
if ( !clips.empty() ) { for ( auto &pair : shifters )
for (auto &clip : clips) { pair.second->DoHorizontalOffset( offset );
if (clip.clip) }
clip.clip->Offset( offset ); else {
else for (auto channel : TrackList::Channels( mCapturedTrack.get() ))
clip.track->Offset( offset ); channel->Offset( offset );
}
}
else if ( pTrack )
// Was a shift-click
for (auto channel : TrackList::Channels( pTrack ))
channel->Offset( offset );
} }
} }
@ -206,6 +201,7 @@ void TrackShifter::UnfixIntervals(
if ( pred( *iter) ) { if ( pred( *iter) ) {
mMoving.push_back( std::move( *iter ) ); mMoving.push_back( std::move( *iter ) );
iter = mFixed.erase( iter ); iter = mFixed.erase( iter );
mAllFixed = false;
} }
else else
++iter; ++iter;
@ -216,6 +212,7 @@ void TrackShifter::UnfixAll()
{ {
std::move( mFixed.begin(), mFixed.end(), std::back_inserter(mMoving) ); std::move( mFixed.begin(), mFixed.end(), std::back_inserter(mMoving) );
mFixed = Intervals{}; mFixed = Intervals{};
mAllFixed = false;
} }
void TrackShifter::SelectInterval( const TrackInterval & ) void TrackShifter::SelectInterval( const TrackInterval & )
@ -303,6 +300,12 @@ bool TrackShifter::FinishMigration()
return true; return true;
} }
void TrackShifter::DoHorizontalOffset( double offset )
{
if (!AllFixed())
GetTrack().Offset( offset );
}
void TrackShifter::InitIntervals() void TrackShifter::InitIntervals()
{ {
mMoving.clear(); mMoving.clear();
@ -548,14 +551,12 @@ double ClipMoveState::DoSlideHorizontal( double desiredSlideAmount )
break; break;
} }
} while ( desiredSlideAmount != initialAllowed ); } while ( desiredSlideAmount != initialAllowed );
// finally, here is where clips are moved
if ( desiredSlideAmount != 0.0 )
DoOffset( state, nullptr, desiredSlideAmount );
} }
else
// Moving whole track // Whether moving intervals or a whole track,
DoOffset( state, &capturedTrack, desiredSlideAmount ); // finally, here is where clips are moved
if ( desiredSlideAmount != 0.0 )
state.DoHorizontalOffset( desiredSlideAmount );
return (state.hSlideAmount = desiredSlideAmount); return (state.hSlideAmount = desiredSlideAmount);
} }
@ -957,8 +958,7 @@ UIHandle::Result TimeShiftHandle::Drag
// 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( mClipMoveState.DoHorizontalOffset( -mClipMoveState.hSlideAmount );
mClipMoveState, mClipMoveState.mCapturedTrack.get(), -mClipMoveState.hSlideAmount );
if ( mClipMoveState.movingSelection ) { if ( mClipMoveState.movingSelection ) {
// Slide the selection, too // Slide the selection, too

View File

@ -122,6 +122,10 @@ public:
Default implementation does nothing and returns true */ Default implementation does nothing and returns true */
virtual bool FinishMigration(); virtual bool FinishMigration();
//! Shift all moving intervals horizontally
//! Default moves the whole track, provided `!AllFixed()`; else does nothing
virtual void DoHorizontalOffset( double offset );
protected: protected:
/*! Unfix any of the intervals that intersect the given one; may be useful to override `SelectInterval()` */ /*! Unfix any of the intervals that intersect the given one; may be useful to override `SelectInterval()` */
void CommonSelectInterval( const TrackInterval &interval ); void CommonSelectInterval( const TrackInterval &interval );
@ -135,8 +139,16 @@ protected:
/*! This can't be called by the base class constructor, when GetTrack() isn't yet callable */ /*! This can't be called by the base class constructor, when GetTrack() isn't yet callable */
void InitIntervals(); void InitIntervals();
bool AllFixed() const {
return mAllFixed && mMoving.empty();
}
Intervals mFixed; Intervals mFixed;
Intervals mMoving; Intervals mMoving;
private:
bool mAllFixed = true; /*!<
Becomes false after `UnfixAll()`, even if there are no intervals, or if any one interval was unfixed */
}; };
//! Used in default of other reimplementations to shift any track as a whole, invoking Track::Offset() //! Used in default of other reimplementations to shift any track as a whole, invoking Track::Offset()
@ -196,9 +208,13 @@ struct ClipMoveState {
/*! Pointer may be invalidated by operations on the associated TrackShifter */ /*! Pointer may be invalidated by operations on the associated TrackShifter */
const TrackInterval *CapturedInterval() const; const TrackInterval *CapturedInterval() const;
//! Do sliding of tracks and intervals, maybe adjusting the offset
/*! @return actual slide amount, maybe adjusted toward zero from desired */ /*! @return actual slide amount, maybe adjusted toward zero from desired */
double DoSlideHorizontal( double desiredSlideAmount ); double DoSlideHorizontal( double desiredSlideAmount );
//! Offset tracks or intervals horizontally, without adjusting the offset
void DoHorizontalOffset( double offset );
std::shared_ptr<Track> mCapturedTrack; 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: