Paste P267

Masterwork From Distant Lands
ActivePublic

Authored by dkazakov on Oct 12 2018, 4:56 PM.
diff --git a/libs/ui/canvas/kis_animation_player.cpp b/libs/ui/canvas/kis_animation_player.cpp
index 6be2cb4..0411f4f 100644
--- a/libs/ui/canvas/kis_animation_player.cpp
+++ b/libs/ui/canvas/kis_animation_player.cpp
@@ -63,7 +63,7 @@ public:
dropFramesMode(true),
nextFrameExpectedTime(0),
expectedInterval(0),
- expectedFrame(0),
+ currentFrame(0),
lastTimerInterval(0),
lastPaintedFrame(0),
playbackStatisticsCompressor(1000, KisSignalCompressor::FIRST_INACTIVE),
@@ -98,7 +98,7 @@ public:
QElapsedTimer playbackTime;
int nextFrameExpectedTime;
int expectedInterval;
- int expectedFrame;
+ int currentFrame;
int lastTimerInterval;
int lastPaintedFrame;
@@ -321,10 +321,10 @@ void KisAnimationPlayer::slotUpdatePlaybackTimer()
const int fps = animation->framerate();
- m_d->initialFrame = animation->currentUITime();
+ m_d->initialFrame = isPlaying() ? m_d->currentFrame : animation->currentUITime();
m_d->firstFrame = playBackRange.start();
m_d->lastFrame = playBackRange.end();
- m_d->expectedFrame = qBound(m_d->firstFrame, m_d->expectedFrame, m_d->lastFrame);
+ m_d->currentFrame = qBound(m_d->firstFrame, m_d->currentFrame, m_d->lastFrame);
m_d->expectedInterval = m_d->framesToWalltime(1, fps);
@@ -332,13 +332,18 @@ void KisAnimationPlayer::slotUpdatePlaybackTimer()
if (m_d->syncedAudio) {
m_d->syncedAudio->setSpeed(m_d->playbackSpeed);
-
- const qint64 expectedAudioTime = m_d->framesToMSec(m_d->expectedFrame, fps);
+ qDebug() << "update audio speed";
+ const qint64 expectedAudioTime = m_d->framesToMSec(m_d->currentFrame, fps);
if (qAbs(m_d->syncedAudio->position() - expectedAudioTime) > m_d->framesToMSec(1.5, fps)) {
m_d->syncedAudio->syncWithVideo(expectedAudioTime);
+ qDebug() << "reset audio position";
}
}
+ qDebug() << ppVar(fps)
+ << ppVar(m_d->currentFrame)
+ << ppVar(m_d->expectedInterval);
+
m_d->timer->start(m_d->expectedInterval);
if (m_d->playbackTime.isValid()) {
@@ -399,7 +404,7 @@ void KisAnimationPlayer::play()
m_d->playing = true;
- m_d->expectedFrame = animation->currentUITime();
+ m_d->currentFrame = animation->currentUITime();
slotUpdatePlaybackTimer();
m_d->lastPaintedFrame = -1;
@@ -407,7 +412,7 @@ void KisAnimationPlayer::play()
if (m_d->syncedAudio) {
KisImageAnimationInterface *animationInterface = m_d->canvas->image()->animationInterface();
- m_d->syncedAudio->play(m_d->framesToMSec(m_d->expectedFrame, animationInterface->framerate()));
+ m_d->syncedAudio->play(m_d->framesToMSec(m_d->currentFrame, animationInterface->framerate()));
}
emit sigPlaybackStarted();
@@ -474,24 +479,29 @@ void KisAnimationPlayer::uploadFrame(int frame, bool forceSyncAudio)
const bool syncToAudio = !forceSyncAudio && m_d->dropFramesMode && m_d->syncedAudio && m_d->syncedAudio->isPlaying();
if (frame < 0) {
- const qreal currentTimeInFrames = syncToAudio ?
+ qreal currentTimeInFrames = syncToAudio ?
m_d->msecToFrames(m_d->syncedAudio->position(), fps) :
m_d->playbackTimeInFrames(fps);
+ const int previousFrame = m_d->currentFrame;
+ const int expectedFrame = m_d->incFrame(previousFrame, 1);
+ const int currentFrame = qFloor(currentTimeInFrames);
+
// qDebug() << ppVar(framesDiff)
// << ppVar(m_d->expectedFrame)
// << ppVar(framesDiffNorm)
// << ppVar(m_d->lastTimerInterval);
if (m_d->dropFramesMode) {
- const int currentFrame = qFloor(currentTimeInFrames);
- const int framesToDrop = qMax(0, currentFrame - m_d->expectedFrame);
- frame = m_d->incFrame(m_d->expectedFrame, framesToDrop);
+ const int framesToDrop = qMax(0, currentFrame - expectedFrame);
+ frame = m_d->incFrame(expectedFrame, framesToDrop);
+ currentTimeInFrames += frame - currentFrame;
+ qDebug() << "droppping " << framesToDrop;
} else {
- frame = m_d->expectedFrame;
+ frame = expectedFrame;
}
- m_d->expectedFrame = m_d->incFrame(frame, 1);
+ const int nextFrame = m_d->incFrame(frame, 1);
if (!m_d->dropFramesMode) {
const qint64 currentTime = m_d->playbackTime.elapsed();
@@ -499,17 +509,23 @@ void KisAnimationPlayer::uploadFrame(int frame, bool forceSyncAudio)
m_d->nextFrameExpectedTime = currentTime + m_d->expectedInterval;
m_d->lastTimerInterval = qMax(0.0, m_d->lastTimerInterval - 0.5 * framesDiff);
- } else if (m_d->expectedFrame >= frame) {
- const int timeToNextFrame = m_d->framesToWalltime(m_d->expectedFrame - currentTimeInFrames, fps);
+ } else if (nextFrame >= frame) {
+ const int timeToNextFrame = m_d->framesToWalltime(nextFrame - currentTimeInFrames, fps);
m_d->lastTimerInterval = qMax(0, timeToNextFrame);
} else {
// Animation restarting
forceSyncAudio = true;
m_d->lastTimerInterval = m_d->expectedInterval;
}
-
- m_d->timer->start(m_d->lastTimerInterval);
+ qDebug() << ppVar(currentTimeInFrames)
+ << ppVar(m_d->currentFrame)
+ << ppVar(fps)
+ << ppVar(m_d->playbackSpeed)
+ << ppVar(m_d->lastTimerInterval);
+
+ m_d->currentFrame = frame;
+ m_d->timer->start(m_d->lastTimerInterval);
m_d->playbackStatisticsCompressor.start();
}
dkazakov edited the content of this paste. (Show Details)Oct 12 2018, 4:56 PM
dkazakov changed the title of this paste from untitled to Masterwork From Distant Lands.