1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-23 17:30:17 +01:00

split out function AdvancedTrackTime; more caution about termination

This commit is contained in:
Paul Licameli
2018-08-11 23:41:45 -04:00
parent 84c8aa0fcc
commit 67a9823434
2 changed files with 29 additions and 14 deletions

View File

@@ -5646,23 +5646,18 @@ bool AudioIO::PlaybackSchedule::Overruns( double trackTime ) const
return (ReversedTime() ? trackTime <= mT1 : trackTime >= mT1);
}
void AudioIO::PlaybackSchedule::TrackTimeUpdate(double realElapsed)
double AudioIO::PlaybackSchedule::AdvancedTrackTime(
double time, double realElapsed, double speed ) const
{
// Update mTime within the PortAudio callback
if (Interactive())
return;
if (ReversedTime())
realElapsed *= -1.0;
auto time = GetTrackTime();
// Defense against cases that might cause loops not to terminate
if ( fabs(mT0 - mT1) < 1e-9 )
return mT0;
if (mTimeTrack) {
// Defense against a case that might cause the do-loop not to terminate
if ( fabs(mT0 - mT1) < 1e-9 ) {
SetTrackTime( mT0 );
return;
}
wxASSERT( speed == 1.0 );
double total;
bool foundTotal = false;
@@ -5693,7 +5688,7 @@ void AudioIO::PlaybackSchedule::TrackTimeUpdate(double realElapsed)
} while ( true );
}
else {
time += realElapsed;
time += realElapsed * speed;
// Wrap to start if looping
if (Looping()) {
@@ -5705,7 +5700,20 @@ void AudioIO::PlaybackSchedule::TrackTimeUpdate(double realElapsed)
}
}
}
SetTrackTime( time );
return time;
}
void AudioIO::PlaybackSchedule::TrackTimeUpdate(double realElapsed)
{
// Update mTime within the PortAudio callback
if (Interactive())
return;
auto time = GetTrackTime();
auto newTime = AdvancedTrackTime( time, realElapsed, 1.0 );
SetTrackTime( newTime );
}
double AudioIO::PlaybackSchedule::TrackDuration(double realElapsed) const