From cc72907777af0a879dbbc820687658605066f939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Tue, 5 Dec 2023 19:58:51 -0500 Subject: [PATCH] [gfx] wip on live changing of video files --- .../score-plugin-gfx/Gfx/GfxExecNode.cpp | 1 + .../score-plugin-gfx/Gfx/GfxExecNode.hpp | 1 + .../score-plugin-gfx/Gfx/Video/Executor.cpp | 74 +++++++++++++------ 3 files changed, 54 insertions(+), 22 deletions(-) diff --git a/src/plugins/score-plugin-gfx/Gfx/GfxExecNode.cpp b/src/plugins/score-plugin-gfx/Gfx/GfxExecNode.cpp index 585f2e2f0b..e4473730ac 100644 --- a/src/plugins/score-plugin-gfx/Gfx/GfxExecNode.cpp +++ b/src/plugins/score-plugin-gfx/Gfx/GfxExecNode.cpp @@ -17,6 +17,7 @@ gfx_exec_node::~gfx_exec_node() void gfx_exec_node::run( const ossia::token_request& tk, ossia::exec_state_facade) noexcept { + m_last_flicks = tk.date; { // Copy all the UI controls const int n = std::ssize(controls); diff --git a/src/plugins/score-plugin-gfx/Gfx/GfxExecNode.hpp b/src/plugins/score-plugin-gfx/Gfx/GfxExecNode.hpp index 40f560b109..6fdc8446d3 100644 --- a/src/plugins/score-plugin-gfx/Gfx/GfxExecNode.hpp +++ b/src/plugins/score-plugin-gfx/Gfx/GfxExecNode.hpp @@ -98,6 +98,7 @@ class SCORE_PLUGIN_GFX_EXPORT gfx_exec_node : public ossia::graph_node int32_t id{-1}; std::atomic_int32_t script_index{0}; + ossia::time_value m_last_flicks{}; void run(const ossia::token_request& tk, ossia::exec_state_facade) noexcept override; }; diff --git a/src/plugins/score-plugin-gfx/Gfx/Video/Executor.cpp b/src/plugins/score-plugin-gfx/Gfx/Video/Executor.cpp index ec0a6b21fe..20087feebd 100644 --- a/src/plugins/score-plugin-gfx/Gfx/Video/Executor.cpp +++ b/src/plugins/score-plugin-gfx/Gfx/Video/Executor.cpp @@ -38,6 +38,21 @@ class video_node final : public gfx_exec_node exec_context->ui->unregister_node(id); } + void reload(const std::shared_ptr& dec, std::optional tempo) + { + impl = nullptr; + + if(id >= 0) + exec_context->ui->unregister_node(id); + + m_decoder = dec; + m_decoder->seek(m_last_flicks.impl); + + auto n = std::make_unique(m_decoder, tempo); + impl = n.get(); + id = exec_context->ui->register_node(std::move(n)); + } + std::string label() const noexcept override { if(this->m_decoder) @@ -109,37 +124,52 @@ ProcessExecutorComponent::ProcessExecutorComponent( Gfx::Video::Model& element, const Execution::Context& ctx, QObject* parent) : ProcessComponent_T{element, ctx, "VideoExecutorComponent", parent} { - if(auto dec = element.makeDecoder()) - { - std::optional tempo; - if(!element.ignoreTempo()) - tempo = element.nativeTempo(); - auto n = ossia::make_node( - *ctx.execState, dec, tempo, ctx.doc.plugin().exec); + auto dec = element.makeDecoder(); + if(!dec) + dec = std::make_shared(::Video::DecoderConfiguration{}); + + std::optional tempo; + if(!element.ignoreTempo()) + tempo = element.nativeTempo(); + auto n = ossia::make_node( + *ctx.execState, std::move(dec), tempo, ctx.doc.plugin().exec); - for(auto* outlet : element.outlets()) + for(auto* outlet : element.outlets()) + { + if(auto out = qobject_cast(outlet)) { - if(auto out = qobject_cast(outlet)) - { - out->nodeId = n->id; - } + out->nodeId = n->id; } + } - n->root_outputs().push_back(new ossia::texture_outlet); + n->root_outputs().push_back(new ossia::texture_outlet); - this->node = n; - m_ossia_process = std::make_shared(n); + this->node = n; + m_ossia_process = std::make_shared(n); - ::bind( - element, Gfx::Video::Model::p_scaleMode{}, this, - [this](score::gfx::ScaleMode m) { - if(auto vn = static_cast(this->node.get()); vn && vn->impl) + ::bind( + element, Gfx::Video::Model::p_scaleMode{}, this, [this](score::gfx::ScaleMode m) { + if(auto vn = static_cast(this->node.get()); vn && vn->impl) + { + vn->impl->setScaleMode(m); + } + }); + + con(element, &Gfx::Video::Model::pathChanged, this, [this](const QString& new_path) { + std::optional tempo; + if(!this->process().ignoreTempo()) + tempo = this->process().nativeTempo(); + + in_exec([node = std::weak_ptr{node}, dec = this->process().makeDecoder(), + tempo]() mutable { + if(auto vn = static_cast(node.lock().get()); vn && vn->impl) { - vn->impl->setScaleMode(m); + vn->reload(std::move(dec), tempo); } - }); - } + }); + }); } + void ProcessExecutorComponent::cleanup() { for(auto* outlet : this->process().outlets())