1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-17 16:50:26 +02:00

TrackShifters can classify track intervals as fixed or not

This commit is contained in:
Paul Licameli 2020-09-11 11:05:07 -04:00
parent d8a894b95b
commit 8f8c20ac80
4 changed files with 57 additions and 2 deletions

View File

@ -736,7 +736,9 @@ class NoteTrackShifter final : public TrackShifter {
public:
NoteTrackShifter( NoteTrack &track )
: mpTrack{ track.SharedPointer<NoteTrack>() }
{}
{
InitIntervals();
}
~NoteTrackShifter() override {}
Track &GetTrack() const override { return *mpTrack; }

View File

@ -1307,6 +1307,7 @@ public:
WaveTrackShifter( WaveTrack &track )
: mpTrack{ track.SharedPointer<WaveTrack>() }
{
InitIntervals();
}
~WaveTrackShifter() override {}
Track &GetTrack() const override { return *mpTrack; }

View File

@ -246,9 +246,36 @@ namespace
TrackShifter::~TrackShifter() = default;
void TrackShifter::UnfixIntervals(
std::function< bool( const TrackInterval& ) > pred )
{
for ( auto iter = mFixed.begin(); iter != mFixed.end(); ) {
if ( pred( *iter) ) {
mMoving.push_back( std::move( *iter ) );
iter = mFixed.erase( iter );
}
else
++iter;
}
}
void TrackShifter::UnfixAll()
{
std::move( mFixed.begin(), mFixed.end(), std::back_inserter(mMoving) );
mFixed = Intervals{};
}
void TrackShifter::InitIntervals()
{
mMoving.clear();
mFixed = GetTrack().GetIntervals();
}
CoarseTrackShifter::CoarseTrackShifter( Track &track )
: mpTrack{ track.SharedPointer() }
{}
{
InitIntervals();
}
CoarseTrackShifter::~CoarseTrackShifter() = default;

View File

@ -11,6 +11,7 @@ Paul Licameli
#ifndef __AUDACITY_TIMESHIFT_HANDLE__
#define __AUDACITY_TIMESHIFT_HANDLE__
#include <functional>
#include <unordered_map>
#include "../../AttachedVirtualFunction.h"
@ -22,6 +23,7 @@ using TrackArray = std::vector<Track*>;
class TrackList;
class Track;
class TrackInterval;
//! Abstract base class for policies to manipulate a track type with the Time Shift tool
class TrackShifter {
@ -29,6 +31,29 @@ public:
virtual ~TrackShifter() = 0;
//! There is always an associated track
virtual Track &GetTrack() const = 0;
using Intervals = std::vector<TrackInterval>;
//! Return special intervals of the track that will not move
const Intervals &FixedIntervals() const { return mFixed; }
//! Return special intervals of the track that may move
const Intervals &MovingIntervals() const { return mMoving; }
//! Change intervals satisfying a predicate from fixed to moving
void UnfixIntervals(
std::function< bool( const TrackInterval& ) > pred );
//! Change all intervals from fixed to moving
void UnfixAll();
protected:
//! Derived class constructor can initialize all intervals reported by the track as fixed, none moving
/*! This can't be called by the base class constructor, when GetTrack() isn't yet callable */
void InitIntervals();
Intervals mFixed;
Intervals mMoving;
};
//! Used in default of other reimplementations to shift any track as a whole, invoking Track::Offset()