Skip to content

Commit 045ac1d

Browse files
committed
video: start working towards control ports in video proces
1 parent 4fd602a commit 045ac1d

File tree

3 files changed

+61
-19
lines changed

3 files changed

+61
-19
lines changed

src/plugins/score-plugin-gfx/Gfx/Video/Executor.cpp

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,32 @@ class video_node final : public gfx_exec_node
3838
exec_context->ui->unregister_node(id);
3939
}
4040

41+
void run(const ossia::token_request& tk, ossia::exec_state_facade e) noexcept override
42+
{
43+
// Consume the new value for the path input port if any
44+
auto& vp = this->m_inlets[0]->target<ossia::value_port>()->get_data();
45+
if(!vp.empty())
46+
{
47+
auto& last = *vp.back().value.target<std::string>();
48+
if(last != m_currentPath)
49+
{
50+
m_currentPath = last;
51+
52+
auto dec = Gfx::Video::makeDecoder(last);
53+
if(dec)
54+
{
55+
reload(dec, m_currentTempo);
56+
}
57+
vp.clear();
58+
}
59+
}
60+
61+
gfx_exec_node::run(tk, e);
62+
}
63+
4164
void reload(const std::shared_ptr<video_decoder>& dec, std::optional<double> tempo)
4265
{
66+
m_currentTempo = tempo;
4367
impl = nullptr;
4468

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

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

73-
private:
97+
std::string m_currentPath;
7498
std::shared_ptr<video_decoder> m_decoder;
99+
std::optional<double> m_currentTempo;
75100
};
76101

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

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

162+
auto port = n->add_value_port();
163+
/*
164+
for(std::size_t i = 0; i < 1; i++)
165+
{
166+
auto ctrl = qobject_cast<Process::ControlInlet*>(element.inlets()[i]);
167+
SCORE_ASSERT(ctrl);
168+
auto& p = n->add_control();
169+
p->value = ctrl->value();
170+
171+
QObject::connect(
172+
ctrl, &Process::ControlInlet::valueChanged, this, con_unvalidated{ctx, i, 0, n});
173+
}
174+
*/
175+
137176
for(auto* outlet : element.outlets())
138177
{
139178
if(auto out = qobject_cast<Gfx::TextureOutlet*>(outlet))
@@ -154,20 +193,22 @@ ProcessExecutorComponent::ProcessExecutorComponent(
154193
vn->impl->setScaleMode(m);
155194
}
156195
});
157-
196+
/*
158197
con(element, &Gfx::Video::Model::pathChanged, this, [this](const QString& new_path) {
159198
std::optional<double> tempo;
160199
if(!this->process().ignoreTempo())
161200
tempo = this->process().nativeTempo();
162201
163-
in_exec([node = std::weak_ptr{node}, dec = this->process().makeDecoder(),
202+
in_exec([node = std::weak_ptr{node},
203+
dec = Gfx::Video::makeDecoder(this->process().absolutePath().toStdString()),
164204
tempo]() mutable {
165205
if(auto vn = static_cast<video_node*>(node.lock().get()); vn && vn->impl)
166206
{
167207
vn->reload(std::move(dec), tempo);
168208
}
169209
});
170210
});
211+
*/
171212
}
172213

173214
void ProcessExecutorComponent::cleanup()

src/plugins/score-plugin-gfx/Gfx/Video/Process.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ static ::Video::DecoderConfiguration videoDecoderConfiguration() noexcept
9595
return conf;
9696
}
9797

98+
std::shared_ptr<video_decoder> makeDecoder(const std::string& absolutePath) noexcept
99+
try
100+
{
101+
auto dec = std::make_shared<video_decoder>(videoDecoderConfiguration());
102+
if(!dec->load(absolutePath))
103+
return {};
104+
return dec;
105+
}
106+
catch(...)
107+
{
108+
return {};
109+
}
110+
98111
Model::Model(
99112
const TimeVal& duration, const QString& path, const Id<Process::ProcessModel>& id,
100113
QObject* parent)
@@ -106,24 +119,12 @@ Model::Model(
106119
setNativeTempo(Media::tempoAtStartDate(*this));
107120
setPath(path);
108121

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

112126
Model::~Model() { }
113127

114-
std::shared_ptr<video_decoder> Model::makeDecoder() const noexcept
115-
try
116-
{
117-
auto dec = std::make_shared<video_decoder>(videoDecoderConfiguration());
118-
if(!dec->load(absolutePath().toStdString()))
119-
return {};
120-
return dec;
121-
}
122-
catch(...)
123-
{
124-
return {};
125-
}
126-
127128
QString Model::absolutePath() const noexcept
128129
{
129130
return score::locateFilePath(m_path, score::IDocument::documentContext(*this));

src/plugins/score-plugin-gfx/Gfx/Video/Process.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
namespace Gfx::Video
1414
{
1515
using video_decoder = ::Video::VideoDecoder;
16+
std::shared_ptr<video_decoder> makeDecoder(const std::string&) noexcept;
17+
1618
class Model final : public Process::ProcessModel
1719
{
1820
SCORE_SERIALIZE_FRIENDS
@@ -33,8 +35,6 @@ class Model final : public Process::ProcessModel
3335

3436
~Model() override;
3537

36-
std::shared_ptr<video_decoder> makeDecoder() const noexcept;
37-
3838
QString absolutePath() const noexcept;
3939
QString path() const noexcept { return m_path; }
4040
void setPath(const QString& f);

0 commit comments

Comments
 (0)