diff --git a/app/config/config.cpp b/app/config/config.cpp index d96619dd8..d2c2b0866 100644 --- a/app/config/config.cpp +++ b/app/config/config.cpp @@ -82,8 +82,7 @@ void Config::SetDefaults() config_map_["DropWithoutSequenceBehavior"] = TimelineWidget::kDWSAsk; config_map_["Loop"] = false; - config_map_["AutoCache"] = true; - config_map_["AutoCacheInterval"] = 1000; + config_map_["AutoCacheInterval"] = 250; config_map_["NodeCatColor0"] = QVariant::fromValue(Color(0.75f, 0.75f, 0.75f)); config_map_["NodeCatColor1"] = QVariant::fromValue(Color(0.25f, 0.25f, 0.25f)); diff --git a/app/panel/footageviewer/footageviewer.cpp b/app/panel/footageviewer/footageviewer.cpp index 61c77a3d1..073177d46 100644 --- a/app/panel/footageviewer/footageviewer.cpp +++ b/app/panel/footageviewer/footageviewer.cpp @@ -29,6 +29,7 @@ FootageViewerPanel::FootageViewerPanel(QWidget *parent) : { // Set ViewerWidget as the central widget FootageViewerWidget* fvw = new FootageViewerWidget(); + fvw->SetAutoCacheEnabled(false); connect(fvw, &FootageViewerWidget::RequestScopePanel, this, &FootageViewerPanel::CreateScopePanel); SetTimeBasedWidget(fvw); diff --git a/app/widget/viewer/viewer.cpp b/app/widget/viewer/viewer.cpp index 1e846d429..e91de8b03 100644 --- a/app/widget/viewer/viewer.cpp +++ b/app/widget/viewer/viewer.cpp @@ -58,7 +58,8 @@ ViewerWidget::ViewerWidget(QWidget *parent) : time_changed_from_timer_(false), prequeuing_(false), busy_(false), - our_cache_background_task_(nullptr) + our_cache_background_task_(nullptr), + autocache_(true) { // Set up main layout QVBoxLayout* layout = new QVBoxLayout(this); @@ -114,7 +115,7 @@ ViewerWidget::ViewerWidget(QWidget *parent) : renderer_->SetRenderMode(RenderMode::kOffline); // Setup cache wait timer (waits a few seconds of inactivity before caching) - cache_wait_timer_.setInterval(250); + cache_wait_timer_.setInterval(Config::Current()["AutoCacheInterval"].toInt()); cache_wait_timer_.setSingleShot(true); connect(&cache_wait_timer_, &QTimer::timeout, this, &ViewerWidget::StartBackgroundCaching); @@ -369,6 +370,18 @@ void ViewerWidget::ForceUpdate() UpdateTextureFromNode(GetTime()); } +void ViewerWidget::SetAutoCacheEnabled(bool e) +{ + autocache_ = e; + + if (autocache_) { + StartBackgroundCaching(); + } else if (cache_background_task_ == our_cache_background_task_) { + StopAllBackgroundCacheTasks(false); + cache_background_task_ = nullptr; + } +} + void ViewerWidget::SetGizmos(Node *node) { display_widget_->SetTimeTarget(GetConnectedNode()); @@ -865,10 +878,10 @@ void ViewerWidget::StartBackgroundCaching() } #endif - if (GetConnectedNode() + if (autocache_ + && GetConnectedNode() && (GetConnectedNode()->video_frame_cache()->HasInvalidatedRanges() - || GetConnectedNode()->audio_playback_cache()->HasInvalidatedRanges()) - && Config::Current()["AutoCache"].toBool()) { + || GetConnectedNode()->audio_playback_cache()->HasInvalidatedRanges())) { if (cache_background_task_ || busy_viewers_) { // Something else is caching right now, we don't want to do multiple at once so we'll check @@ -987,6 +1000,16 @@ void ViewerWidget::ShowContextMenu(const QPoint &pos) menu.addSeparator(); + { + // Auto-cache + QAction* autocache_action = menu.addAction(tr("Auto-Cache")); + autocache_action->setCheckable(true); + autocache_action->setChecked(autocache_); + connect(autocache_action, &QAction::triggered, this, &ViewerWidget::SetAutoCacheEnabled); + } + + menu.addSeparator(); + { // Safe Margins Menu* safe_margin_menu = new Menu(tr("Safe Margins"), &menu); diff --git a/app/widget/viewer/viewer.h b/app/widget/viewer/viewer.h index 220a73161..64f892611 100644 --- a/app/widget/viewer/viewer.h +++ b/app/widget/viewer/viewer.h @@ -122,6 +122,8 @@ public slots: void ForceUpdate(); + void SetAutoCacheEnabled(bool e); + signals: /** * @brief Wrapper for ViewerGLWidget::CursorColor() @@ -249,6 +251,8 @@ private: int prequeue_length_; + bool autocache_; + static CacheTask* cache_background_task_; static int busy_viewers_;