diff --git a/app/config/config.cpp b/app/config/config.cpp index d5803a32d..5b6118de7 100644 --- a/app/config/config.cpp +++ b/app/config/config.cpp @@ -96,7 +96,6 @@ void Config::SetDefaults() SetEntryInternal(QStringLiteral("AutoMergeTracks"), NodeValue::kBoolean, true); SetEntryInternal(QStringLiteral("UseSliderLadders"), NodeValue::kBoolean, true); - SetEntryInternal(QStringLiteral("AutoCacheEnabled"), NodeValue::kBoolean, true); SetEntryInternal(QStringLiteral("AutoCacheDelay"), NodeValue::kInt, 1000); SetEntryInternal(QStringLiteral("CatColor0"), NodeValue::kInt, 0); @@ -123,6 +122,7 @@ void Config::SetDefaults() SetEntryInternal(QStringLiteral("DefaultSequencePixelAspect"), NodeValue::kRational, QVariant::fromValue(rational(1))); SetEntryInternal(QStringLiteral("DefaultSequenceFrameRate"), NodeValue::kRational, QVariant::fromValue(rational(1001, 30000))); SetEntryInternal(QStringLiteral("DefaultSequenceInterlacing"), NodeValue::kInt, VideoParams::kInterlaceNone); + SetEntryInternal(QStringLiteral("DefaultSequenceAutoCache"), NodeValue::kBoolean, true); SetEntryInternal(QStringLiteral("DefaultSequenceAudioFrequency"), NodeValue::kInt, 48000); SetEntryInternal(QStringLiteral("DefaultSequenceAudioLayout"), NodeValue::kInt, QVariant::fromValue(static_cast(AV_CH_LAYOUT_STEREO))); diff --git a/app/dialog/sequence/sequence.cpp b/app/dialog/sequence/sequence.cpp index e7a33d97a..e7570e690 100644 --- a/app/dialog/sequence/sequence.cpp +++ b/app/dialog/sequence/sequence.cpp @@ -126,7 +126,8 @@ void SequenceDialog::accept() SequenceParamCommand* param_command = new SequenceParamCommand(sequence_, video_params, audio_params, - name_field_->text()); + name_field_->text(), + parameter_tab_->GetSelectedPreviewAutoCache()); Core::instance()->undo_stack()->push(param_command); @@ -153,20 +154,23 @@ void SequenceDialog::SetAsDefaultClicked() Config::Current()[QStringLiteral("DefaultSequenceInterlacing")] = parameter_tab_->GetSelectedVideoInterlacingMode(); Config::Current()[QStringLiteral("DefaultSequenceAudioFrequency")] = parameter_tab_->GetSelectedAudioSampleRate(); Config::Current()[QStringLiteral("DefaultSequenceAudioLayout")] = QVariant::fromValue(parameter_tab_->GetSelectedAudioChannelLayout()); + Config::Current()[QStringLiteral("DefaultSequenceAutoCache")] = QVariant::fromValue(parameter_tab_->GetSelectedPreviewAutoCache()); } } SequenceDialog::SequenceParamCommand::SequenceParamCommand(Sequence* s, const VideoParams& video_params, const AudioParams &audio_params, - const QString& name) : + const QString& name, bool autocache) : sequence_(s), new_video_params_(video_params), new_audio_params_(audio_params), new_name_(name), + new_autocache_(autocache), old_video_params_(s->GetVideoParams()), old_audio_params_(s->GetAudioParams()), - old_name_(s->GetLabel()) + old_name_(s->GetLabel()), + old_autocache_(s->GetAutoCacheEnabled()) { } @@ -177,16 +181,26 @@ Project *SequenceDialog::SequenceParamCommand::GetRelevantProject() const void SequenceDialog::SequenceParamCommand::redo() { - sequence_->SetVideoParams(new_video_params_); - sequence_->SetAudioParams(new_audio_params_); + if (sequence_->GetVideoParams() != new_video_params_) { + sequence_->SetVideoParams(new_video_params_); + } + if (sequence_->GetAudioParams() != new_audio_params_) { + sequence_->SetAudioParams(new_audio_params_); + } sequence_->SetLabel(new_name_); + sequence_->SetAutoCacheEnabled(new_autocache_); } void SequenceDialog::SequenceParamCommand::undo() { - sequence_->SetVideoParams(old_video_params_); - sequence_->SetAudioParams(old_audio_params_); + if (sequence_->GetVideoParams() != old_video_params_) { + sequence_->SetVideoParams(old_video_params_); + } + if (sequence_->GetAudioParams() != old_audio_params_) { + sequence_->SetAudioParams(old_audio_params_); + } sequence_->SetLabel(old_name_); + sequence_->SetAutoCacheEnabled(old_autocache_); } } diff --git a/app/dialog/sequence/sequence.h b/app/dialog/sequence/sequence.h index ad9036be4..b12d1fcb3 100644 --- a/app/dialog/sequence/sequence.h +++ b/app/dialog/sequence/sequence.h @@ -111,7 +111,8 @@ private: SequenceParamCommand(Sequence* s, const VideoParams& video_params, const AudioParams& audio_params, - const QString& name); + const QString& name, + bool autocache); virtual Project* GetRelevantProject() const override; @@ -125,10 +126,12 @@ private: VideoParams new_video_params_; AudioParams new_audio_params_; QString new_name_; + bool new_autocache_; VideoParams old_video_params_; AudioParams old_audio_params_; QString old_name_; + bool old_autocache_; }; private slots: diff --git a/app/dialog/sequence/sequencedialogparametertab.cpp b/app/dialog/sequence/sequencedialogparametertab.cpp index 2a60df4f1..674467f7f 100644 --- a/app/dialog/sequence/sequencedialogparametertab.cpp +++ b/app/dialog/sequence/sequencedialogparametertab.cpp @@ -56,6 +56,10 @@ SequenceDialogParameterTab::SequenceDialogParameterTab(Sequence* sequence, QWidg preview_layout->addWidget(new QLabel(tr("Quality:")), row, 0); preview_format_field_ = new PixelFormatComboBox(false); preview_layout->addWidget(preview_format_field_, row, 1, 1, 2); + row++; + preview_layout->addWidget(new QLabel(tr("Auto-Cache:")), row, 0); + preview_autocache_field_ = new QCheckBox(); + preview_layout->addWidget(preview_autocache_field_, row, 1); layout->addWidget(preview_group); // Set values based on input sequence @@ -64,6 +68,7 @@ SequenceDialogParameterTab::SequenceDialogParameterTab(Sequence* sequence, QWidg video_section_->SetVideoParams(vp); preview_resolution_field_->SetDivider(vp.divider()); preview_format_field_->SetPixelFormat(vp.format()); + preview_autocache_field_->setChecked(sequence->GetAutoCacheEnabled()); audio_sample_rate_field_->SetSampleRate(ap.sample_rate()); audio_channels_field_->SetChannelLayout(ap.channel_layout()); @@ -90,6 +95,7 @@ void SequenceDialogParameterTab::PresetChanged(const SequencePreset &preset) audio_channels_field_->SetChannelLayout(preset.channel_layout()); preview_resolution_field_->SetDivider(preset.preview_divider()); preview_format_field_->SetPixelFormat(preset.preview_format()); + preview_autocache_field_->setChecked(preset.preview_autocache()); } void SequenceDialogParameterTab::SavePresetClicked() @@ -103,7 +109,8 @@ void SequenceDialogParameterTab::SavePresetClicked() GetSelectedAudioSampleRate(), GetSelectedAudioChannelLayout(), GetSelectedPreviewResolution(), - GetSelectedPreviewFormat()}); + GetSelectedPreviewFormat(), + GetSelectedPreviewAutoCache()}); } void SequenceDialogParameterTab::UpdatePreviewResolutionLabel() diff --git a/app/dialog/sequence/sequencedialogparametertab.h b/app/dialog/sequence/sequencedialogparametertab.h index a107a12b1..6d4d3bf08 100644 --- a/app/dialog/sequence/sequencedialogparametertab.h +++ b/app/dialog/sequence/sequencedialogparametertab.h @@ -64,6 +64,11 @@ public: return preview_format_field_->GetPixelFormat(); } + bool GetSelectedPreviewAutoCache() const + { + return preview_autocache_field_->isChecked(); + } + public slots: void PresetChanged(const SequencePreset& preset); @@ -83,6 +88,8 @@ private: PixelFormatComboBox* preview_format_field_; + QCheckBox *preview_autocache_field_; + private slots: void SavePresetClicked(); diff --git a/app/dialog/sequence/sequencedialogpresettab.cpp b/app/dialog/sequence/sequencedialogpresettab.cpp index 6054ae080..756607115 100644 --- a/app/dialog/sequence/sequencedialogpresettab.cpp +++ b/app/dialog/sequence/sequencedialogpresettab.cpp @@ -105,86 +105,95 @@ QTreeWidgetItem* SequenceDialogPresetTab::CreateFolder(const QString &name) QTreeWidgetItem *SequenceDialogPresetTab::CreateHDPresetFolder(const QString &name, int width, int height, int divider) { - VideoParams::Format default_format = static_cast(Config::Current()["OfflinePixelFormat"].toInt()); + const VideoParams::Format default_format = static_cast(Config::Current()["OfflinePixelFormat"].toInt()); + const bool default_autocache = true; QTreeWidgetItem* parent = CreateFolder(name); - AddStandardItem(parent, SequencePreset::Create(tr("%1 23.976 FPS").arg(name), - width, - height, - rational(24000, 1001), - VideoParams::kPixelAspectSquare, - VideoParams::kInterlaceNone, - 48000, - AV_CH_LAYOUT_STEREO, - divider, - default_format)); - AddStandardItem(parent, SequencePreset::Create(tr("%1 25 FPS").arg(name), - width, - height, - rational(25, 1), - VideoParams::kPixelAspectSquare, - VideoParams::kInterlaceNone, - 48000, - AV_CH_LAYOUT_STEREO, - divider, - default_format)); - AddStandardItem(parent, SequencePreset::Create(tr("%1 29.97 FPS").arg(name), - width, - height, - rational(30000, 1001), - VideoParams::kPixelAspectSquare, - VideoParams::kInterlaceNone, - 48000, - AV_CH_LAYOUT_STEREO, - divider, - default_format)); - AddStandardItem(parent, SequencePreset::Create(tr("%1 50 FPS").arg(name), - width, - height, - rational(50, 1), - VideoParams::kPixelAspectSquare, - VideoParams::kInterlaceNone, - 48000, - AV_CH_LAYOUT_STEREO, - divider, - default_format)); - AddStandardItem(parent, SequencePreset::Create(tr("%1 59.94 FPS").arg(name), - width, - height, - rational(60000, 1001), - VideoParams::kPixelAspectSquare, - VideoParams::kInterlaceNone, - 48000, - AV_CH_LAYOUT_STEREO, - divider, - default_format)); + AddStandardItem(parent, new SequencePreset(tr("%1 23.976 FPS").arg(name), + width, + height, + rational(24000, 1001), + VideoParams::kPixelAspectSquare, + VideoParams::kInterlaceNone, + 48000, + AV_CH_LAYOUT_STEREO, + divider, + default_format, + default_autocache)); + AddStandardItem(parent, new SequencePreset(tr("%1 25 FPS").arg(name), + width, + height, + rational(25, 1), + VideoParams::kPixelAspectSquare, + VideoParams::kInterlaceNone, + 48000, + AV_CH_LAYOUT_STEREO, + divider, + default_format, + default_autocache)); + AddStandardItem(parent, new SequencePreset(tr("%1 29.97 FPS").arg(name), + width, + height, + rational(30000, 1001), + VideoParams::kPixelAspectSquare, + VideoParams::kInterlaceNone, + 48000, + AV_CH_LAYOUT_STEREO, + divider, + default_format, + default_autocache)); + AddStandardItem(parent, new SequencePreset(tr("%1 50 FPS").arg(name), + width, + height, + rational(50, 1), + VideoParams::kPixelAspectSquare, + VideoParams::kInterlaceNone, + 48000, + AV_CH_LAYOUT_STEREO, + divider, + default_format, + default_autocache)); + AddStandardItem(parent, new SequencePreset(tr("%1 59.94 FPS").arg(name), + width, + height, + rational(60000, 1001), + VideoParams::kPixelAspectSquare, + VideoParams::kInterlaceNone, + 48000, + AV_CH_LAYOUT_STEREO, + divider, + default_format, + default_autocache)); return parent; } QTreeWidgetItem *SequenceDialogPresetTab::CreateSDPresetFolder(const QString &name, int width, int height, const rational& frame_rate, const rational &standard_par, const rational &wide_par, int divider) { - VideoParams::Format default_format = static_cast(Config::Current()["OfflinePixelFormat"].toInt()); + const VideoParams::Format default_format = static_cast(Config::Current()["OfflinePixelFormat"].toInt()); + const bool default_autocache = true; QTreeWidgetItem* parent = CreateFolder(name); preset_tree_->addTopLevelItem(parent); - AddStandardItem(parent, SequencePreset::Create(tr("%1 Standard").arg(name), - width, - height, - frame_rate, - standard_par, - VideoParams::kInterlacedBottomFirst, - 48000, - AV_CH_LAYOUT_STEREO, - divider, - default_format)); - AddStandardItem(parent, SequencePreset::Create(tr("%1 Widescreen").arg(name), - width, - height, - frame_rate, - wide_par, - VideoParams::kInterlacedBottomFirst, - 48000, - AV_CH_LAYOUT_STEREO, - divider, - default_format)); + AddStandardItem(parent, new SequencePreset(tr("%1 Standard").arg(name), + width, + height, + frame_rate, + standard_par, + VideoParams::kInterlacedBottomFirst, + 48000, + AV_CH_LAYOUT_STEREO, + divider, + default_format, + default_autocache)); + AddStandardItem(parent, new SequencePreset(tr("%1 Widescreen").arg(name), + width, + height, + frame_rate, + wide_par, + VideoParams::kInterlacedBottomFirst, + 48000, + AV_CH_LAYOUT_STEREO, + divider, + default_format, + default_autocache)); return parent; } diff --git a/app/dialog/sequence/sequencepreset.h b/app/dialog/sequence/sequencepreset.h index 6ae3ec603..0d2a12fa2 100644 --- a/app/dialog/sequence/sequencepreset.h +++ b/app/dialog/sequence/sequencepreset.h @@ -43,7 +43,8 @@ public: int sample_rate, uint64_t channel_layout, int preview_divider, - VideoParams::Format preview_format) : + VideoParams::Format preview_format, + bool preview_autocache) : width_(width), height_(height), frame_rate_(frame_rate), @@ -52,27 +53,12 @@ public: sample_rate_(sample_rate), channel_layout_(channel_layout), preview_divider_(preview_divider), - preview_format_(preview_format) + preview_format_(preview_format), + preview_autocache_(preview_autocache) { SetName(name); } - static Preset* Create(const QString& name, - int width, - int height, - const rational& frame_rate, - const rational& pixel_aspect, - VideoParams::Interlacing interlacing, - int sample_rate, - uint64_t channel_layout, - int preview_divider, - VideoParams::Format preview_format) - { - return new SequencePreset(name, width, height, frame_rate, pixel_aspect, - interlacing, sample_rate, channel_layout, - preview_divider, preview_format); - } - virtual void Load(QXmlStreamReader* reader) override { while (XMLReadNextStartElement(reader)) { @@ -96,6 +82,8 @@ public: preview_divider_ = reader->readElementText().toInt(); } else if (reader->name() == QStringLiteral("format")) { preview_format_ = static_cast(reader->readElementText().toInt()); + } else if (reader->name() == QStringLiteral("autocache")) { + preview_autocache_ = reader->readElementText().toInt(); } else { reader->skipCurrentElement(); } @@ -114,6 +102,7 @@ public: writer->writeTextElement(QStringLiteral("chlayout"), QString::number(channel_layout_)); writer->writeTextElement(QStringLiteral("divider"), QString::number(preview_divider_)); writer->writeTextElement(QStringLiteral("format"), QString::number(preview_format_)); + writer->writeTextElement(QStringLiteral("autocache"), QString::number(preview_autocache_)); } int width() const @@ -161,6 +150,11 @@ public: return preview_format_; } + bool preview_autocache() const + { + return preview_autocache_; + } + private: int width_; int height_; @@ -171,6 +165,7 @@ private: uint64_t channel_layout_; int preview_divider_; VideoParams::Format preview_format_; + bool preview_autocache_; }; diff --git a/app/node/output/viewer/viewer.cpp b/app/node/output/viewer/viewer.cpp index a92d90584..f58eb3eec 100644 --- a/app/node/output/viewer/viewer.cpp +++ b/app/node/output/viewer/viewer.cpp @@ -31,6 +31,7 @@ const QString ViewerOutput::kVideoParamsInput = QStringLiteral("video_param_in") const QString ViewerOutput::kAudioParamsInput = QStringLiteral("audio_param_in"); const QString ViewerOutput::kTextureInput = QStringLiteral("tex_in"); const QString ViewerOutput::kSamplesInput = QStringLiteral("samples_in"); +const QString ViewerOutput::kAutoCacheInput = QStringLiteral("autocache_in"); const uint64_t ViewerOutput::kVideoParamEditMask = VideoParamEdit::kWidthHeight | VideoParamEdit::kInterlacing | VideoParamEdit::kFrameRate | VideoParamEdit::kPixelAspect; @@ -55,6 +56,10 @@ ViewerOutput::ViewerOutput(bool create_buffer_inputs, bool create_default_stream if (create_buffer_inputs) { AddInput(kTextureInput, NodeValue::kTexture, InputFlags(kInputFlagNotKeyframable)); AddInput(kSamplesInput, NodeValue::kSamples, InputFlags(kInputFlagNotKeyframable)); + + AddInput(kAutoCacheInput, NodeValue::kBoolean, true, InputFlags(kInputFlagNotKeyframable | kInputFlagNotConnectable)); + IgnoreHashingFrom(kAutoCacheInput); + IgnoreInvalidationsFrom(kAutoCacheInput); } if (create_default_streams) { @@ -198,6 +203,8 @@ void ViewerOutput::set_default_parameters() Config::Current()["DefaultSequenceAudioLayout"].toULongLong(), AudioParams::kInternalFormat )); + + SetAutoCacheEnabled(Config::Current()["DefaultSequenceAutoCache"].toBool()); } void ViewerOutput::ShiftVideoCache(const rational &from, const rational &to) @@ -382,7 +389,9 @@ NodeOutput ViewerOutput::GetConnectedSampleOutput() void ViewerOutput::InputValueChangedEvent(const QString &input, int element) { - if (element == 0) { + if (input == kAutoCacheInput) { + emit AutoCacheChanged(GetAutoCacheEnabled()); + } else if (element == 0) { if (input == kVideoParamsInput) { VideoParams new_video_params = GetVideoParams(); diff --git a/app/node/output/viewer/viewer.h b/app/node/output/viewer/viewer.h index 072310680..13798cd98 100644 --- a/app/node/output/viewer/viewer.h +++ b/app/node/output/viewer/viewer.h @@ -157,12 +157,30 @@ public: void SetViewerVideoCacheEnabled(bool e) { video_cache_enabled_ = e; } void SetViewerAudioCacheEnabled(bool e) { audio_cache_enabled_ = e; } + bool GetAutoCacheEnabled() const + { + if (HasInputWithID(kAutoCacheInput)) { + return GetStandardValue(kAutoCacheInput).toBool(); + } else { + return false; + } + } + + void SetAutoCacheEnabled(bool e) + { + if (HasInputWithID(kAutoCacheInput)) { + return SetStandardValue(kAutoCacheInput, e); + } + } + static const QString kVideoParamsInput; static const QString kAudioParamsInput; static const QString kTextureInput; static const QString kSamplesInput; + static const QString kAutoCacheInput; + static const uint64_t kVideoParamEditMask; signals: @@ -176,6 +194,8 @@ signals: void InterlacingChanged(VideoParams::Interlacing mode); + void AutoCacheChanged(bool e); + void VideoParamsChanged(); void AudioParamsChanged(); diff --git a/app/panel/footageviewer/footageviewer.cpp b/app/panel/footageviewer/footageviewer.cpp index 189e8b70c..368820910 100644 --- a/app/panel/footageviewer/footageviewer.cpp +++ b/app/panel/footageviewer/footageviewer.cpp @@ -29,7 +29,6 @@ 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/render/previewautocacher.cpp b/app/render/previewautocacher.cpp index 1517fc9ca..fa54b5c53 100644 --- a/app/render/previewautocacher.cpp +++ b/app/render/previewautocacher.cpp @@ -13,12 +13,11 @@ namespace olive { PreviewAutoCacher::PreviewAutoCacher() : viewer_node_(nullptr), + paused_(false), has_changed_(false), use_custom_range_(false), single_frame_render_(nullptr) { - paused_ = !Config::Current()[QStringLiteral("AutoCacheEnabled")].toBool(), - SetPlayhead(0); delayed_requeue_timer_.setInterval(Config::Current()[QStringLiteral("AutoCacheDelay")].toInt()); diff --git a/app/widget/viewer/viewer.cpp b/app/widget/viewer/viewer.cpp index bcfa27815..697ad204b 100644 --- a/app/widget/viewer/viewer.cpp +++ b/app/widget/viewer/viewer.cpp @@ -193,6 +193,7 @@ void ViewerWidget::ConnectNodeEvent(ViewerOutput *n) connect(n, &ViewerOutput::PixelAspectChanged, this, &ViewerWidget::SetViewerPixelAspect); connect(n, &ViewerOutput::LengthChanged, this, &ViewerWidget::LengthChangedSlot); connect(n, &ViewerOutput::InterlacingChanged, this, &ViewerWidget::InterlacingChangedSlot); + connect(n, &ViewerOutput::AutoCacheChanged, this, &ViewerWidget::SetAutoCacheEnabled); connect(n, &ViewerOutput::VideoParamsChanged, this, &ViewerWidget::UpdateRendererVideoParameters); connect(n, &ViewerOutput::AudioParamsChanged, this, &ViewerWidget::UpdateRendererAudioParameters); connect(n->video_frame_cache(), &FrameHashCache::Invalidated, this, &ViewerWidget::ViewerInvalidatedVideoRange); @@ -203,6 +204,8 @@ void ViewerWidget::ConnectNodeEvent(ViewerOutput *n) VideoParams vp = n->GetVideoParams(); + SetAutoCacheEnabled(n->GetAutoCacheEnabled()); + InterlacingChangedSlot(vp.interlacing()); ruler()->SetPlaybackCache(n->video_frame_cache()); @@ -239,6 +242,7 @@ void ViewerWidget::DisconnectNodeEvent(ViewerOutput *n) disconnect(n, &ViewerOutput::PixelAspectChanged, this, &ViewerWidget::SetViewerPixelAspect); disconnect(n, &ViewerOutput::LengthChanged, this, &ViewerWidget::LengthChangedSlot); disconnect(n, &ViewerOutput::InterlacingChanged, this, &ViewerWidget::InterlacingChangedSlot); + disconnect(n, &ViewerOutput::AutoCacheChanged, this, &ViewerWidget::SetAutoCacheEnabled); disconnect(n, &ViewerOutput::VideoParamsChanged, this, &ViewerWidget::UpdateRendererVideoParameters); disconnect(n, &ViewerOutput::AudioParamsChanged, this, &ViewerWidget::UpdateRendererAudioParameters); disconnect(n->video_frame_cache(), &FrameHashCache::Invalidated, this, &ViewerWidget::ViewerInvalidatedVideoRange); @@ -999,14 +1003,6 @@ void ViewerWidget::ShowContextMenu(const QPoint &pos) Menu* cache_menu = new Menu(tr("Cache"), &menu); menu.addMenu(cache_menu); - // Auto-cache - QAction* autocache_action = cache_menu->addAction(tr("Auto-Cache")); - autocache_action->setCheckable(true); - autocache_action->setChecked(!auto_cacher_.IsPaused()); - connect(autocache_action, &QAction::triggered, this, &ViewerWidget::SetAutoCacheEnabled); - - cache_menu->addSeparator(); - // Cache Entire Sequence QAction* cache_entire_sequence = cache_menu->addAction(tr("Cache Entire Sequence")); connect(cache_entire_sequence, &QAction::triggered, this, &ViewerWidget::CacheEntireSequence);