Skip to content

Commit

Permalink
[gfx] wip on live changing of video files
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Dec 6, 2023
1 parent eb6f239 commit cc72907
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/plugins/score-plugin-gfx/Gfx/GfxExecNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/plugins/score-plugin-gfx/Gfx/GfxExecNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
74 changes: 52 additions & 22 deletions src/plugins/score-plugin-gfx/Gfx/Video/Executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ class video_node final : public gfx_exec_node
exec_context->ui->unregister_node(id);
}

void reload(const std::shared_ptr<video_decoder>& dec, std::optional<double> 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<score::gfx::VideoNode>(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)
Expand Down Expand Up @@ -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<double> tempo;
if(!element.ignoreTempo())
tempo = element.nativeTempo();
auto n = ossia::make_node<video_node>(
*ctx.execState, dec, tempo, ctx.doc.plugin<DocumentPlugin>().exec);
auto dec = element.makeDecoder();
if(!dec)
dec = std::make_shared<Video::video_decoder>(::Video::DecoderConfiguration{});

std::optional<double> tempo;
if(!element.ignoreTempo())
tempo = element.nativeTempo();
auto n = ossia::make_node<video_node>(
*ctx.execState, std::move(dec), tempo, ctx.doc.plugin<DocumentPlugin>().exec);

for(auto* outlet : element.outlets())
for(auto* outlet : element.outlets())
{
if(auto out = qobject_cast<Gfx::TextureOutlet*>(outlet))
{
if(auto out = qobject_cast<Gfx::TextureOutlet*>(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<video_process>(n);
this->node = n;
m_ossia_process = std::make_shared<video_process>(n);

::bind(
element, Gfx::Video::Model::p_scaleMode{}, this,
[this](score::gfx::ScaleMode m) {
if(auto vn = static_cast<video_node*>(this->node.get()); vn && vn->impl)
::bind(
element, Gfx::Video::Model::p_scaleMode{}, this, [this](score::gfx::ScaleMode m) {
if(auto vn = static_cast<video_node*>(this->node.get()); vn && vn->impl)
{
vn->impl->setScaleMode(m);
}
});

con(element, &Gfx::Video::Model::pathChanged, this, [this](const QString& new_path) {
std::optional<double> 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<video_node*>(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())
Expand Down

0 comments on commit cc72907

Please sign in to comment.