Skip to content

Commit 9a15ada

Browse files
committed
ysfx: make ui -> exec thread communication safer
1 parent a50f8d1 commit 9a15ada

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/plugins/score-plugin-ysfx/YSFX/Executor/Component.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ class ysfx_node final : public ossia::graph_node
5151
}
5252

5353
void all_notes_off() noexcept override;
54+
void clear() noexcept override
55+
{
56+
graph_node::clear();
57+
generation = -1;
58+
}
5459

5560
std::shared_ptr<ysfx_t> fx;
5661
ossia::execution_state& m_st;
@@ -60,6 +65,7 @@ class ysfx_node final : public ossia::graph_node
6065
ossia::midi_outlet* midi_out{};
6166
ossia::audio_outlet* audio_out{};
6267
std::vector<ossia::value_port*> sliders;
68+
int generation = 0;
6369
};
6470

6571
Component::Component(
@@ -103,10 +109,14 @@ Component::Component(
103109
inlet->setupExecution(*node->root_inputs()[i], this);
104110
connect(
105111
inlet, &Process::ControlInlet::valueChanged, this,
106-
[this, inl](const ossia::value& v) {
107-
system().executionQueue.enqueue(
108-
[inl, val = v]() mutable { inl->write_value(std::move(val), 0); });
112+
[this, inl, weak_node = std::weak_ptr{node}](const ossia::value& v) {
113+
// FIXME the day we allow live-coding JSFX script we will have to do the same "generation" fix than with faust
114+
if(auto node = weak_node.lock())
115+
system().executionQueue.enqueue([inl, val = v, weak_node]() mutable {
116+
if(auto node = weak_node.lock(); node && node->generation >= 0)
117+
inl->write_value(std::move(val), 0);
109118
});
119+
});
110120
}
111121

112122
auto c = con(

0 commit comments

Comments
 (0)