Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

video: start working towards control ports in video proces #1636

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 45 additions & 4 deletions src/plugins/score-plugin-gfx/Gfx/Video/Executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,32 @@ class video_node final : public gfx_exec_node
exec_context->ui->unregister_node(id);
}

void run(const ossia::token_request& tk, ossia::exec_state_facade e) noexcept override
{
// Consume the new value for the path input port if any
auto& vp = this->m_inlets[0]->target<ossia::value_port>()->get_data();
if(!vp.empty())
{
auto& last = *vp.back().value.target<std::string>();
if(last != m_currentPath)
{
m_currentPath = last;

auto dec = Gfx::Video::makeDecoder(last);
if(dec)
{
reload(dec, m_currentTempo);
}
vp.clear();
}
}

gfx_exec_node::run(tk, e);
}

void reload(const std::shared_ptr<video_decoder>& dec, std::optional<double> tempo)
{
m_currentTempo = tempo;
impl = nullptr;

if(id >= 0)
Expand Down Expand Up @@ -70,8 +94,9 @@ class video_node final : public gfx_exec_node

score::gfx::VideoNode* impl{};

private:
std::string m_currentPath;
std::shared_ptr<video_decoder> m_decoder;
std::optional<double> m_currentTempo;
};

class video_process final : public ossia::node_process
Expand Down Expand Up @@ -124,7 +149,7 @@ ProcessExecutorComponent::ProcessExecutorComponent(
Gfx::Video::Model& element, const Execution::Context& ctx, QObject* parent)
: ProcessComponent_T{element, ctx, "VideoExecutorComponent", parent}
{
auto dec = element.makeDecoder();
auto dec = makeDecoder(element.absolutePath().toStdString());
if(!dec)
dec = std::make_shared<Video::video_decoder>(::Video::DecoderConfiguration{});

Expand All @@ -134,6 +159,20 @@ ProcessExecutorComponent::ProcessExecutorComponent(
auto n = ossia::make_node<video_node>(
*ctx.execState, std::move(dec), tempo, ctx.doc.plugin<DocumentPlugin>().exec);

auto port = n->add_value_port();
/*
for(std::size_t i = 0; i < 1; i++)
{
auto ctrl = qobject_cast<Process::ControlInlet*>(element.inlets()[i]);
SCORE_ASSERT(ctrl);
auto& p = n->add_control();
p->value = ctrl->value();

QObject::connect(
ctrl, &Process::ControlInlet::valueChanged, this, con_unvalidated{ctx, i, 0, n});
}
*/

for(auto* outlet : element.outlets())
{
if(auto out = qobject_cast<Gfx::TextureOutlet*>(outlet))
Expand All @@ -154,20 +193,22 @@ ProcessExecutorComponent::ProcessExecutorComponent(
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(),
in_exec([node = std::weak_ptr{node},
dec = Gfx::Video::makeDecoder(this->process().absolutePath().toStdString()),
tempo]() mutable {
if(auto vn = static_cast<video_node*>(node.lock().get()); vn && vn->impl)
{
vn->reload(std::move(dec), tempo);
}
});
});
*/
}

void ProcessExecutorComponent::cleanup()
Expand Down
27 changes: 14 additions & 13 deletions src/plugins/score-plugin-gfx/Gfx/Video/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ static ::Video::DecoderConfiguration videoDecoderConfiguration() noexcept
return conf;
}

std::shared_ptr<video_decoder> makeDecoder(const std::string& absolutePath) noexcept
try
{
auto dec = std::make_shared<video_decoder>(videoDecoderConfiguration());
if(!dec->load(absolutePath))
return {};
return dec;
}
catch(...)
{
return {};
}

Model::Model(
const TimeVal& duration, const QString& path, const Id<Process::ProcessModel>& id,
QObject* parent)
Expand All @@ -106,24 +119,12 @@ Model::Model(
setNativeTempo(Media::tempoAtStartDate(*this));
setPath(path);

m_inlets.push_back(new Process::VideoFileChooser{Id<Process::Port>(0), this});
m_outlets.push_back(new TextureOutlet{Id<Process::Port>(0), this});
}

Model::~Model() { }

std::shared_ptr<video_decoder> Model::makeDecoder() const noexcept
try
{
auto dec = std::make_shared<video_decoder>(videoDecoderConfiguration());
if(!dec->load(absolutePath().toStdString()))
return {};
return dec;
}
catch(...)
{
return {};
}

QString Model::absolutePath() const noexcept
{
return score::locateFilePath(m_path, score::IDocument::documentContext(*this));
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/score-plugin-gfx/Gfx/Video/Process.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
namespace Gfx::Video
{
using video_decoder = ::Video::VideoDecoder;
std::shared_ptr<video_decoder> makeDecoder(const std::string&) noexcept;

class Model final : public Process::ProcessModel
{
SCORE_SERIALIZE_FRIENDS
Expand All @@ -33,8 +35,6 @@ class Model final : public Process::ProcessModel

~Model() override;

std::shared_ptr<video_decoder> makeDecoder() const noexcept;

QString absolutePath() const noexcept;
QString path() const noexcept { return m_path; }
void setPath(const QString& f);
Expand Down
Loading