mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-04 16:14:00 +01:00
More factoring of TimeShiftHandle::Drag
This commit is contained in:
@@ -524,6 +524,36 @@ namespace {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CheckFit(
|
||||||
|
const ViewInfo &viewInfo, wxCoord xx, ClipMoveState &state,
|
||||||
|
double tolerance, double &desiredSlideAmount )
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 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.
|
||||||
|
if (firstTolerance == 0)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
tolerance = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
struct TemporaryClipRemover {
|
struct TemporaryClipRemover {
|
||||||
TemporaryClipRemover( ClipMoveState &clipMoveState )
|
TemporaryClipRemover( ClipMoveState &clipMoveState )
|
||||||
: state( clipMoveState )
|
: state( clipMoveState )
|
||||||
@@ -641,56 +671,23 @@ UIHandle::Result TimeShiftHandle::Drag
|
|||||||
TemporaryClipRemover remover( mClipMoveState );
|
TemporaryClipRemover remover( mClipMoveState );
|
||||||
|
|
||||||
// Now check that the move is possible
|
// Now check that the move is possible
|
||||||
bool ok = true;
|
double slide = desiredSlideAmount; // remember amount requested.
|
||||||
// The test for tolerance will need review with FishEye!
|
// The test for tolerance will need review with FishEye!
|
||||||
// The tolerance is supposed to be the time for one pixel, i.e. one pixel tolerance
|
// The tolerance is supposed to be the time for one pixel, i.e. one pixel tolerance
|
||||||
// at current zoom.
|
// at current zoom.
|
||||||
double slide = desiredSlideAmount; // remember amount requested.
|
double tolerance =
|
||||||
double tolerance = viewInfo.PositionToTime(event.m_x+1) - viewInfo.PositionToTime(event.m_x);
|
viewInfo.PositionToTime(event.m_x+1) - viewInfo.PositionToTime(event.m_x);
|
||||||
|
bool ok = CheckFit( viewInfo, event.m_x, mClipMoveState, tolerance, desiredSlideAmount );
|
||||||
// The desiredSlideAmount may change and the tolerance may get used up.
|
|
||||||
for ( auto &trackClip : mClipMoveState.capturedClipArray ) {
|
|
||||||
WaveClip *const pSrcClip = trackClip.clip;
|
|
||||||
if (pSrcClip) {
|
|
||||||
ok = trackClip.dstTrack->CanInsertClip(
|
|
||||||
pSrcClip, desiredSlideAmount, tolerance );
|
|
||||||
if( !ok )
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( ok ) {
|
|
||||||
// fits ok, but desiredSlideAmount could have been updated to get the clip to fit.
|
|
||||||
// Check again, in the new position, this time with zero tolerance.
|
|
||||||
tolerance = 0.0;
|
|
||||||
for ( auto &trackClip : mClipMoveState.capturedClipArray ) {
|
|
||||||
WaveClip *const pSrcClip = trackClip.clip;
|
|
||||||
if (pSrcClip) {
|
|
||||||
ok = trackClip.dstTrack->CanInsertClip(
|
|
||||||
pSrcClip, desiredSlideAmount, tolerance);
|
|
||||||
if ( !ok )
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
// Failure, even with using tolerance.
|
// Failure, even with using tolerance.
|
||||||
remover.Fail();
|
remover.Fail();
|
||||||
|
|
||||||
// Failure -- we'll put clips back where they were
|
// Failure -- we'll put clips back where they were
|
||||||
// ok will next indicate if a horizontal slide is OK.
|
// ok will next indicate if a horizontal slide is OK.
|
||||||
ok = true; // assume slide is OK.
|
|
||||||
tolerance = 0.0;
|
tolerance = 0.0;
|
||||||
desiredSlideAmount = slide;
|
desiredSlideAmount = slide;
|
||||||
for ( auto &trackClip : mClipMoveState.capturedClipArray ) {
|
ok = CheckFit( viewInfo, event.m_x, mClipMoveState, tolerance, desiredSlideAmount );
|
||||||
WaveClip *const pSrcClip = trackClip.clip;
|
|
||||||
if (pSrcClip){
|
|
||||||
// back to the track it came from...
|
|
||||||
trackClip.dstTrack = static_cast<WaveTrack*>(trackClip.track);
|
|
||||||
ok = ok && trackClip.dstTrack->CanInsertClip(pSrcClip, desiredSlideAmount, tolerance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for ( auto &trackClip : mClipMoveState.capturedClipArray) {
|
for ( auto &trackClip : mClipMoveState.capturedClipArray) {
|
||||||
WaveClip *const pSrcClip = trackClip.clip;
|
WaveClip *const pSrcClip = trackClip.clip;
|
||||||
if (pSrcClip){
|
if (pSrcClip){
|
||||||
|
|||||||
Reference in New Issue
Block a user