diff --git a/src/core/MM.h b/src/core/MM.h index 926f3c6..a28f6b6 100644 --- a/src/core/MM.h +++ b/src/core/MM.h @@ -86,6 +86,8 @@ public: static const bool SHOW_OUTPUT_RESOLUTION = true; static const QString DEFAULT_LANGUAGE; static const bool SHOW_OUTPUT_ON_MOUSE_HOVER = true; + static const bool OSC_SAME_MEDIA_SOURCE = false; + static const bool PLAY_IN_LOOP = true; // Style. static const QColor WHITE; diff --git a/src/core/VideoImpl.cpp b/src/core/VideoImpl.cpp index c71a04c..2845827 100644 --- a/src/core/VideoImpl.cpp +++ b/src/core/VideoImpl.cpp @@ -226,6 +226,9 @@ _playState(false), _uri("") { _mutexLocker = new QMutexLocker(&_mutex); + + QSettings settings; + _playInLoop = settings.value("playInLoop", MM::PLAY_IN_LOOP).toBool(); } void VideoImpl::unloadMovie() @@ -428,7 +431,8 @@ void VideoImpl::update() if (_eos() || _terminate) { _setFinished(true); - resetMovie(); + if (_playInLoop) // Check if repeat mode is on + resetMovie(); } else { @@ -596,38 +600,39 @@ void VideoImpl::_checkMessages() switch (GST_MESSAGE_TYPE (msg)) { - // Error //////////////////////////////////////////////// - case GST_MESSAGE_ERROR: - gst_message_parse_error(msg, &err, &debug_info); - qWarning() << "Error received from element " << GST_OBJECT_NAME (msg->src) << ": " << err->message << endl; - qDebug() << "Debugging information: " << (debug_info ? debug_info : "none") << "." << endl; - g_clear_error(&err); - g_free(debug_info); + // Error //////////////////////////////////////////////// + case GST_MESSAGE_ERROR: + gst_message_parse_error(msg, &err, &debug_info); + qWarning() << "Error received from element " << GST_OBJECT_NAME (msg->src) << ": " << err->message << endl; + qDebug() << "Debugging information: " << (debug_info ? debug_info : "none") << "." << endl; + g_clear_error(&err); + g_free(debug_info); - if (!isLive()) - { - _terminate = true; - } - else - { - gst_element_set_state (_pipeline, GST_STATE_PAUSED); - gst_element_set_state (_pipeline, GST_STATE_NULL); - gst_element_set_state (_pipeline, GST_STATE_READY); - } -// _finish(); - break; + if (!isLive()) + { + _terminate = true; + } + else + { + gst_element_set_state (_pipeline, GST_STATE_PAUSED); + gst_element_set_state (_pipeline, GST_STATE_NULL); + gst_element_set_state (_pipeline, GST_STATE_READY); + } + // _finish(); + break; - // End-of-stream //////////////////////////////////////// - case GST_MESSAGE_EOS: - // Automatically loop back. - resetMovie(); -// _terminate = true; -// _finish(); - break; + // End-of-stream //////////////////////////////////////// + case GST_MESSAGE_EOS: + // Automatically loop back. + if (_playInLoop) // Check if repeat mode is on + resetMovie(); + // _terminate = true; + // _finish(); + break; - // Pipeline has prerolled/ready to play /////////////// - case GST_MESSAGE_ASYNC_DONE: - if (!_isMovieReady()) + // Pipeline has prerolled/ready to play /////////////// + case GST_MESSAGE_ASYNC_DONE: + if (!_isMovieReady()) { // Check if seeking is allowed. gint64 start, end; diff --git a/src/core/VideoImpl.h b/src/core/VideoImpl.h index 1df147c..de660ca 100644 --- a/src/core/VideoImpl.h +++ b/src/core/VideoImpl.h @@ -113,7 +113,7 @@ public: bool videoIsConnected() const { return _videoIsConnected; } void videoConnect() { _videoIsConnected = true; } bool videoIsSupported() const { return _queue0 != NULL; } - + bool audioIsConnected() const { return _audioIsConnected; } void audioConnect() { _audioIsConnected = true; } bool audioIsSupported() const { return _audioqueue0 != NULL; } @@ -274,6 +274,8 @@ private: QString _uri; static const int MAX_SAMPLES_IN_BUFFER_QUEUES = 30; + + bool _playInLoop; }; } diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index e643da0..4f2d460 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -357,6 +357,7 @@ void MainWindow::closeEvent(QCloseEvent *event) { // Save settings writeSettings(); + _preferenceDialog->saveSettings(); // Close all top level widgets for (QWidget *widget: QApplication::topLevelWidgets()) { if (widget != this) { // Avoid recursion @@ -3289,7 +3290,7 @@ void MainWindow::connectProjectWidgets() connect(mappingItemDelegate, SIGNAL(itemRemoved(uid)), this, SLOT(deleteMapping(uid))); - connect(_preferenceDialog, SIGNAL(settingSaved()), this, SLOT(applySettings())); + connect(_preferenceDialog, SIGNAL(settingSaved()), this, SLOT(updateSettings())); } void MainWindow::disconnectProjectWidgets() @@ -3318,7 +3319,7 @@ void MainWindow::disconnectProjectWidgets() disconnect(mappingItemDelegate, SIGNAL(itemRemoved(uid)), this, SLOT(deleteMapping(uid))); - disconnect(_preferenceDialog, SIGNAL(settingSaved()), this, SLOT(applySettings())); + disconnect(_preferenceDialog, SIGNAL(settingSaved()), this, SLOT(updateSettings())); } uid MainWindow::getItemId(const QListWidgetItem& item) @@ -3483,7 +3484,7 @@ void MainWindow::exitFullScreen() displayTestSignalAction->setChecked(false); } -void MainWindow::applySettings() +void MainWindow::updateSettings() { stickyVerticesAction->setChecked(settings.value("stickyVertices").toBool()); } diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index 2ff004c..4d09cd0 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -163,7 +163,7 @@ private slots: QDesktopServices::openUrl(QUrl("https://github.com/mapmapteam/mapmap/issues/new")); } - void applySettings(); + void updateSettings(); public slots: diff --git a/src/gui/PreferenceDialog.cpp b/src/gui/PreferenceDialog.cpp index 46507f9..ffaab35 100644 --- a/src/gui/PreferenceDialog.cpp +++ b/src/gui/PreferenceDialog.cpp @@ -121,7 +121,9 @@ bool PreferenceDialog::loadSettings() _languageBox->setCurrentIndex(_languageBox->findData(settings.value("language", MM::DEFAULT_LANGUAGE))); // Allow OSC message with same media source - _oscSameMediaSourceBox->setChecked(settings.value("oscSameMediaSource").toBool()); + _oscSameMediaSourceBox->setChecked(settings.value("oscSameMediaSource", MM::OSC_SAME_MEDIA_SOURCE).toBool()); + // Play in loop + _playInLoopBox->setChecked(settings.value("playInLoop", MM::PLAY_IN_LOOP).toBool()); return true; } @@ -154,6 +156,8 @@ void PreferenceDialog::applySettings() settings.setValue("language", _languageBox->currentData()); // Allow OSC message with same media source settings.setValue("oscSameMediaSource", _oscSameMediaSourceBox->isChecked()); + // Play in loop + settings.setValue("playInLoop", _playInLoopBox->isChecked()); } void PreferenceDialog::refreshCurrentIP() @@ -337,7 +341,7 @@ void PreferenceDialog::createControlsPage() _listenPortNumber->setRange(1024, 65534); _listenPortNumber->setFixedWidth(120); - _oscSameMediaSourceBox = new QCheckBox("Allow message with existing media source"); + _oscSameMediaSourceBox = new QCheckBox(tr("Allow message with existing media source")); _oscSameMediaSourceBox->setChecked(false); QFormLayout *listenPortForm = new QFormLayout; @@ -375,6 +379,20 @@ void PreferenceDialog::createControlsPage() void PreferenceDialog::createAdvancedPage() { _advancedPage = new QTabWidget; + + // Playback tab + _playbackWidget = new QWidget; + + // Play in loop + _playInLoopBox = new QCheckBox(tr("Play in loop (requires restart)")); + _playInLoopBox->setChecked(true); // Loop by default + + QVBoxLayout *playbackLayout = new QVBoxLayout; + playbackLayout->addWidget(_playInLoopBox, 1, Qt::AlignTop); + + _playbackWidget->setLayout(playbackLayout); + + _advancedPage->addTab(_playbackWidget, tr("Playback")); } void PreferenceDialog::createPreferencesList() diff --git a/src/gui/PreferenceDialog.h b/src/gui/PreferenceDialog.h index 0012782..1c40b16 100644 --- a/src/gui/PreferenceDialog.h +++ b/src/gui/PreferenceDialog.h @@ -39,6 +39,7 @@ public: ~PreferenceDialog(); void showDialog(); + void saveSettings() { applySettings(); } protected: void closeEvent(QCloseEvent* event); @@ -74,7 +75,7 @@ private: QWidget *_mappingPage; QWidget *_outputPage; QTabWidget *_controlsPage; - QWidget *_advancedPage; + QTabWidget *_advancedPage; // Interface widgets QComboBox *_languageBox; @@ -110,6 +111,10 @@ private: QCheckBox *_oscSameMediaSourceBox; // Advanced widgets + // Playback + QWidget *_playbackWidget; + QCheckBox *_playInLoopBox; + // Common widgets QListWidget *_listWidget;