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

Another method of TrackShifter to test before attachment of intervals

This commit is contained in:
Paul Licameli 2020-09-18 09:42:15 -04:00
parent 716008e293
commit 32c0d462b7
5 changed files with 56 additions and 16 deletions

View File

@ -2259,7 +2259,8 @@ bool WaveTrack::CanOffsetClip(WaveClip* clip, double amount,
return true;
}
bool WaveTrack::CanInsertClip(WaveClip* clip, double &slideBy, double &tolerance)
bool WaveTrack::CanInsertClip(
WaveClip* clip, double &slideBy, double &tolerance) const
{
for (const auto &c : mClips)
{

View File

@ -474,7 +474,7 @@ private:
// Before moving a clip into a track (or inserting a clip), use this
// function to see if the times are valid (i.e. don't overlap with
// existing clips).
bool CanInsertClip(WaveClip* clip, double &slideBy, double &tolerance);
bool CanInsertClip(WaveClip* clip, double &slideBy, double &tolerance) const;
// Remove the clip from the track and return a SMART pointer to it.
// You assume responsibility for its memory!

View File

@ -1377,6 +1377,24 @@ public:
return std::move( mMoving );
}
bool AdjustFit(
const Track &otherTrack, const Intervals &intervals,
double &desiredOffset, double tolerance) override
{
bool ok = true;
auto pOtherWaveTrack = static_cast<const WaveTrack*>(&otherTrack);
for ( auto &interval: intervals ) {
auto pData =
static_cast<WaveTrack::IntervalData*>( interval.Extra() );
auto pClip = pData->GetClip().get();
ok = pOtherWaveTrack->CanInsertClip(
pClip, desiredOffset, tolerance );
if( !ok )
break;
}
return ok;
}
bool Attach( Intervals intervals ) override
{
for (auto &interval : intervals) {

View File

@ -280,6 +280,12 @@ auto TrackShifter::Detach() -> Intervals
return {};
}
bool TrackShifter::AdjustFit(
const Track &, const Intervals&, double &, double)
{
return false;
}
bool TrackShifter::Attach( Intervals )
{
return true;
@ -794,26 +800,30 @@ namespace {
return true;
}
using DetachedIntervals =
std::unordered_map<Track*, TrackShifter::Intervals>;
bool CheckFit(
const ViewInfo &viewInfo, wxCoord xx, ClipMoveState &state,
ClipMoveState &state, const Correspondence &correspondence,
const DetachedIntervals &intervals,
double tolerance, double &desiredSlideAmount )
{
(void)xx;// Compiler food
(void)viewInfo;// Compiler food
bool ok = true;
double firstTolerance = tolerance;
// The desiredSlideAmount may change and the tolerance may get used up.
for ( unsigned iPass = 0; iPass < 2 && ok; ++iPass ) {
for ( auto &trackClip : state.capturedClipArray ) {
WaveClip *const pSrcClip = trackClip.clip;
if (pSrcClip) {
ok = trackClip.dstTrack->CanInsertClip(
pSrcClip, desiredSlideAmount, tolerance );
if( !ok )
break;
}
for ( auto &pair : state.shifters ) {
auto *pSrcTrack = pair.first;
auto iter = correspondence.find( pSrcTrack );
if ( iter != correspondence.end() )
if( auto *pOtherTrack = iter->second )
if ( !(ok = pair.second->AdjustFit(
*pOtherTrack, intervals.at(pSrcTrack),
desiredSlideAmount /*in,out*/, tolerance)) )
break;
}
// If it fits ok, desiredSlideAmount could have been updated to get
// the clip to fit.
// Check again, in the new position, this time with zero tolerance.
@ -875,7 +885,7 @@ namespace {
}
ClipMoveState &state;
std::unordered_map<Track*, TrackShifter::Intervals> detached;
DetachedIntervals detached;
bool failed = false;
};
}
@ -901,7 +911,8 @@ bool TimeShiftHandle::DoSlideVertical
// i.e. one pixel tolerance at current zoom.
double tolerance =
viewInfo.PositionToTime(xx + 1) - viewInfo.PositionToTime(xx);
bool ok = CheckFit( viewInfo, xx, state, tolerance, desiredSlideAmount );
bool ok = CheckFit( state, correspondence, remover.detached,
tolerance, desiredSlideAmount /*in,out*/ );
if (!ok) {
// Failure, even with using tolerance.

View File

@ -83,6 +83,16 @@ public:
/*! Default implementation does nothing */
virtual Intervals Detach();
//! Test whether intervals can fit into another track, maybe adjusting the offset slightly
/*! Default implementation does nothing and returns false */
virtual bool AdjustFit(
const Track &otherTrack,
const Intervals &intervals, /*!<
Assume these came from Detach() and only after MayMigrateTo returned true for otherTrack */
double &desiredOffset, //!< [in,out]
double tolerance //! Nonnegative ceiling for allowed changes in fabs(desiredOffset)
);
//! Put moving intervals into the track, which may have migrated from another
/*! @return success