Move interval timer logic out of gui

This commit is contained in:
Jeremy Bullock 2020-04-24 17:44:28 -06:00
parent e98e169066
commit f151216159
4 changed files with 175 additions and 48 deletions

View file

@ -328,6 +328,13 @@ StopMotion::StopMotion() {
m_timer = new QTimer(this);
m_reviewTimer = new QTimer(this);
m_reviewTimer->setSingleShot(true);
m_intervalTimer = new QTimer(this);
m_countdownTimer = new QTimer(this);
// Make the interval timer single-shot. When the capture finished, restart
// timer for next frame.
// This is because capturing and saving the image needs some time.
m_intervalTimer->setSingleShot(true);
m_fullScreen1 = new QDialog();
m_fullScreen1->setModal(false);
@ -361,6 +368,8 @@ StopMotion::StopMotion() {
SLOT(onSceneSwitched()));
ret = ret && connect(frameHandle, SIGNAL(isPlayingStatusChanged()), this,
SLOT(onPlaybackChanged()));
ret = ret && connect(m_intervalTimer, SIGNAL(timeout()), this,
SLOT(onIntervalCaptureTimerTimeout()));
assert(ret);
ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene();
@ -455,6 +464,13 @@ void StopMotion::disconnectAllCameras() {
}
m_liveViewStatus = LiveViewClosed;
setTEnvCameraName("");
m_isTimeLapse = false;
m_intervalStarted = false;
m_intervalTimer->stop();
m_countdownTimer->stop();
emit(intervalToggled(false));
emit(liveViewChanged(false));
emit(liveViewStopped());
emit(newCameraSelected(0, false));
@ -643,6 +659,70 @@ void StopMotion::setDrawBeneathLevels(bool on) {
//-----------------------------------------------------------------
void StopMotion::toggleInterval(bool on) {
m_isTimeLapse = on;
emit(intervalToggled(on));
}
//-----------------------------------------------------------------
void StopMotion::startInterval() {
if (m_liveViewStatus > 1) {
m_intervalTimer->start(m_intervalTime * 1000);
if (m_intervalTime != 0) m_countdownTimer->start(100);
m_intervalStarted = true;
emit(intervalStarted());
}
else {
DVGui::warning(tr("Please start live view before using time lapse."));
m_intervalStarted = false;
emit(intervalStopped());
}
}
//-----------------------------------------------------------------
void StopMotion::stopInterval() {
m_intervalTimer->stop();
m_countdownTimer->stop();
m_intervalStarted = false;
emit(intervalStopped());
}
//-----------------------------------------------------------------
void StopMotion::setIntervalAmount(int value) {
m_intervalTime = value;
emit(intervalAmountChanged(value));
}
//-----------------------------------------------------------------
void StopMotion::onIntervalCaptureTimerTimeout() {
if (m_liveViewStatus > 0) {
captureImage();
}
else {
DVGui::warning(tr("Please start live view before using time lapse."));
m_intervalStarted = false;
emit(intervalStopped());
}
}
//-----------------------------------------------------------------
void StopMotion::restartInterval() {
// restart interval timer for capturing next frame (it is single shot)
if (m_isTimeLapse && m_intervalStarted) {
m_intervalTimer->start(m_intervalTime * 1000);
// restart the count down as well (for aligning the timing. It is not
// single shot)
if (m_intervalTime != 0) m_countdownTimer->start(100);
}
}
//-----------------------------------------------------------------
void StopMotion::toggleNumpadShortcuts(bool on) {
// can't just return if this feature is off
// it could have been toggled while the camera was active
@ -1840,6 +1920,9 @@ void StopMotion::postImportProcess() {
emit(frameNumberChanged(m_frameNumber));
/* notify */
refreshFrameInfo();
if (m_isTimeLapse && m_intervalStarted) restartInterval();
TApp::instance()->getCurrentScene()->notifySceneChanged();
TApp::instance()->getCurrentScene()->notifyCastChange();
TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
@ -2554,6 +2637,7 @@ void StopMotion::changeCameras(int index) {
// if selected the non-connected state, then disconnect the current camera
if (index == 0) {
disconnectAllCameras();
stopInterval();
return;
}
@ -2651,6 +2735,7 @@ void StopMotion::changeCameras(int index) {
m_liveViewDpi = TPointD(0.0, 0.0);
m_hasLineUpImage = false;
m_hasLiveViewImage = false;
stopInterval();
emit(liveViewStopped());
emit(liveViewChanged(false));
refreshFrameInfo();

View file

@ -99,6 +99,7 @@ private:
bool m_turnOnRewind = false;
QTimer* m_reviewTimer;
std::map<std::string, QAction*> m_oldActionMap;
// Webcam Properties
@ -161,6 +162,9 @@ public:
QString m_tempFile;
QTimer* m_timer;
QList<QSize> m_webcamResolutions;
int m_intervalTime = 10;
bool m_intervalStarted = false;
QTimer* m_intervalTimer, * m_countdownTimer;
// Canon Public Properties
bool m_pickLiveViewZoom = false;
@ -237,6 +241,11 @@ public:
QStringList getAvailableSerialPorts();
bool setSerialPort(QString port);
void sendSerialData();
void toggleInterval(bool on);
void startInterval();
void stopInterval();
void setIntervalAmount(int value);
void restartInterval();
QString getFrameInfoText() { return m_frameInfoText; }
QString getInfoColorName() { return m_infoColorName; }
@ -360,6 +369,7 @@ public slots:
bool importImage();
void onSceneSwitched();
void onPlaybackChanged();
void onIntervalCaptureTimerTimeout();
signals:
void newLiveViewImageReady();
@ -412,6 +422,10 @@ signals:
void useDirectShowSignal(bool);
void reviewTimeChangedSignal(int);
void updateCameraList(QString);
void intervalToggled(bool);
void intervalStarted();
void intervalStopped();
void intervalAmountChanged(int);
};
#endif // STOPMOTION_H

View file

@ -557,18 +557,11 @@ StopMotionController::StopMotionController(QWidget *parent) : QWidget(parent) {
QGroupBox *timerFrame = new QGroupBox(tr("Time Lapse"), this);
m_timerCB = new QCheckBox(tr("Use time lapse"), this);
m_timerIntervalFld = new DVGui::IntField(this);
m_captureTimer = new QTimer(this);
timerFrame->setObjectName("CleanupSettingsFrame");
m_timerCB->setChecked(false);
m_timerIntervalFld->setRange(0, 60);
m_timerIntervalFld->setValue(10);
m_timerIntervalFld->setDisabled(true);
m_countdownTimer = new QTimer(this);
// Make the interval timer single-shot. When the capture finished, restart
// timer for next frame.
// This is because capturing and saving the image needs some time.
m_captureTimer->setSingleShot(true);
m_postCaptureReviewFld = new DVGui::IntField(this);
m_postCaptureReviewFld->setRange(0, 10);
@ -965,11 +958,21 @@ StopMotionController::StopMotionController(QWidget *parent) : QWidget(parent) {
// Time Lapse
ret = ret && connect(m_timerCB, SIGNAL(toggled(bool)), this,
SLOT(onTimerCBToggled(bool)));
ret = ret && connect(m_captureTimer, SIGNAL(timeout()), this,
SLOT(onCaptureTimerTimeout()));
SLOT(onIntervalTimerCBToggled(bool)));
ret = ret && connect(m_timerIntervalFld, SIGNAL(valueChanged(bool)), this,
SLOT(onIntervalSliderValueChanged(bool)));
ret = ret && connect(m_stopMotion, SIGNAL(intervalAmountChanged(int)), this,
SLOT(onIntervalAmountChanged(int)));
ret = ret && connect(m_stopMotion, SIGNAL(intervalToggled(bool)), this,
SLOT(onIntervalToggled(bool)));
ret = ret && connect(m_stopMotion, SIGNAL(intervalStarted()), this,
SLOT(onIntervalStarted()));
ret = ret && connect(m_stopMotion, SIGNAL(intervalStopped()), this,
SLOT(onIntervalStopped()));
ret = ret && connect(m_stopMotion->m_intervalTimer, SIGNAL(timeout()), this,
SLOT(onIntervalCaptureTimerTimeout()));
ret = ret &&
connect(m_countdownTimer, SIGNAL(timeout()), this, SLOT(onCountDown()));
connect(m_stopMotion->m_countdownTimer, SIGNAL(timeout()), this, SLOT(onIntervalCountDownTimeout()));
assert(ret);
@ -2091,23 +2094,13 @@ void StopMotionController::onOpacityChanged(int opacity) {
void StopMotionController::onCaptureButtonClicked(bool on) {
if (m_timerCB->isChecked()) {
m_timerCB->setDisabled(on);
m_timerIntervalFld->setDisabled(on);
// start interval capturing
if (on) {
if (m_stopMotion->m_liveViewStatus > 1) {
m_captureButton->setText(tr("Stop Capturing"));
m_captureTimer->start(m_timerIntervalFld->getValue() * 1000);
if (m_timerIntervalFld->getValue() != 0) m_countdownTimer->start(100);
}
m_stopMotion->startInterval();
}
// stop interval capturing
else {
m_captureButton->setText(tr("Start Capturing"));
m_captureTimer->stop();
m_countdownTimer->stop();
// hide the count down text
// m_videoWidget->showCountDownTime(0);
m_stopMotion->stopInterval();
}
}
// capture immediately
@ -2118,40 +2111,71 @@ void StopMotionController::onCaptureButtonClicked(bool on) {
//-----------------------------------------------------------------------------
void StopMotionController::onTimerCBToggled(bool on) {
m_timerIntervalFld->setEnabled(on);
m_captureButton->setCheckable(on);
m_stopMotion->m_isTimeLapse = on;
if (on)
m_captureButton->setText(tr("Start Capturing"));
else
m_captureButton->setText(tr("Capture"));
void StopMotionController::onIntervalTimerCBToggled(bool on) {
m_stopMotion->toggleInterval(on);
}
//-----------------------------------------------------------------------------
void StopMotionController::onCaptureTimerTimeout() {
if (m_stopMotion->m_liveViewStatus > 0) {
m_stopMotion->captureImage();
// restart interval timer for capturing next frame (it is single shot)
if (m_timerCB->isChecked() && m_captureButton->isChecked()) {
m_captureTimer->start(m_timerIntervalFld->getValue() * 1000);
// restart the count down as well (for aligning the timing. It is not
// single shot)
if (m_timerIntervalFld->getValue() != 0) m_countdownTimer->start(100);
}
} else
void StopMotionController::onIntervalSliderValueChanged(bool on) {
m_stopMotion->setIntervalAmount(m_timerIntervalFld->getValue());
}
//-----------------------------------------------------------------------------
void StopMotionController::onIntervalCaptureTimerTimeout() {
if (m_stopMotion->m_liveViewStatus < 1) {
onCaptureButtonClicked(false);
}
}
//-----------------------------------------------------------------------------
void StopMotionController::onCountDown() {
void StopMotionController::onIntervalCountDownTimeout() {
m_captureButton->setText(QString::number(
m_captureTimer->isActive() ? (m_captureTimer->remainingTime() / 1000 + 1)
m_stopMotion->m_intervalTimer->isActive() ? (m_stopMotion->m_intervalTimer->remainingTime() / 1000 + 1)
: 0));
}
//-----------------------------------------------------------------------------
void StopMotionController::onIntervalAmountChanged(int value) {
m_timerIntervalFld->blockSignals(true);
m_timerIntervalFld->setValue(value);
m_timerIntervalFld->blockSignals(false);
}
//-----------------------------------------------------------------------------
void StopMotionController::onIntervalToggled(bool on) {
m_timerCB->blockSignals(true);
m_timerIntervalFld->setEnabled(on);
m_captureButton->setCheckable(on);
if (on)
m_captureButton->setText(tr("Start Capturing"));
else
m_captureButton->setText(tr("Capture"));
m_timerCB->blockSignals(false);
}
//-----------------------------------------------------------------------------
void StopMotionController::onIntervalStarted() {
m_captureButton->setText(tr("Stop Capturing"));
m_timerCB->setDisabled(true);
m_timerIntervalFld->setDisabled(true);
m_captureButton->blockSignals(true);
m_captureButton->setChecked(true);
m_captureButton->blockSignals(false);
}
//-----------------------------------------------------------------------------
void StopMotionController::onIntervalStopped() {
m_captureButton->setText(tr("Start Capturing"));
m_timerCB->setDisabled(false);
m_timerIntervalFld->setDisabled(false);
m_captureButton->blockSignals(true);
m_captureButton->setChecked(false);
m_captureButton->blockSignals(false);
}
//-----------------------------------------------------------------------------
void StopMotionController::openSaveInFolderPopup() {

View file

@ -95,7 +95,6 @@ class StopMotionController final : public QWidget {
*m_subsamplingFld;
PencilTestSaveInFolderPopup *m_saveInFolderPopup;
DVGui::IntField *m_timerIntervalFld;
QTimer *m_captureTimer, *m_countdownTimer;
public:
StopMotionController(QWidget *parent = 0);
@ -149,9 +148,14 @@ protected slots:
void onNextXSheetFrame();
void setToCurrentXSheetFrame();
void serialPortChanged(int);
void onTimerCBToggled(bool);
void onCaptureTimerTimeout();
void onCountDown();
void onIntervalTimerCBToggled(bool);
void onIntervalSliderValueChanged(bool);
void onIntervalCaptureTimerTimeout();
void onIntervalCountDownTimeout();
void onIntervalAmountChanged(int);
void onIntervalToggled(bool);
void onIntervalStarted();
void onIntervalStopped();
// canon stuff
void onApertureChanged(int index);