113 return uuid_from_string<Node>();
120 return static_key() == other || Execution::ProcessComponent::base_key_match(other);
123#if defined(SCORE_PLUGIN_GFX)
124 [[no_unique_address]] ossia::type_if<int, is_gpu<Node>> node_id = score::gfx::invalid_node_index;
129 element, ctx,
"Executor::ProcessModel<Info>", p}
134 setup_gpu(element, ctx, p);
139 setup_cpu(element, ctx, p);
142 if constexpr(avnd::tag_process_exec<Node>)
144 this->m_ossia_process = std::make_shared<CustomNodeProcess<Node>>(this->node);
148 this->m_ossia_process = std::make_shared<ossia::node_process>(this->node);
156 = *ctx.doc.findPlugin<Explorer::DeviceDocumentPlugin>()->networkContext();
160 auto st = ossia::exec_state_facade{ctx.execState.get()};
161 std::shared_ptr<safe_node<Node>> ptr;
162 auto node =
new safe_node<Node>{st.bufferSize(), (double)st.sampleRate(),
id};
163 node->root_inputs().reserve(element.inlets().size());
164 node->root_outputs().reserve(element.outlets().size());
166 node->prepare(*ctx.execState.get());
168 if_possible(node->impl.effect.ossia_state = st);
169 if_possible(node->impl.effect.io_context = &net_ctx.context);
170 if_possible(node->impl.effect.ossia_document_context = &ctx.doc);
174 if constexpr(
requires { ptr->impl.effect; })
175 if constexpr(std::is_same_v<std::decay_t<
decltype(ptr->impl.effect)>, Node>)
176 connect_message_bus(element, ctx, ptr->impl.effect);
177 connect_worker(ctx, ptr->impl);
179 node->dynamic_ports = element.dynamic_ports;
182 connect_controls(element, ctx, ptr);
183 update_controls(ptr);
185 &element, &Process::ProcessModel::inletsChanged,
this,
186 &Executor::recompute_ports);
188 &element, &Process::ProcessModel::outletsChanged,
this,
189 &Executor::recompute_ports);
192 node->audio_configuration_changed(st);
194 m_oldInlets = element.inlets();
195 m_oldOutlets = element.outlets();
211 using Gfx::gfx_exec_node::gfx_exec_node;
212 std::string label()
const noexcept override
214 return std::string(avnd::get_name<Node>());
218 auto node = std::make_shared<named_exec_node>(gfx_exec);
219 node->prepare(*ctx.execState);
226 for(
auto& ctl : element.inlets())
228 if(
auto ctrl = qobject_cast<Process::ControlInlet*>(ctl))
230 auto& p = node->add_control();
231 p->value = ctrl->value();
235 ctrl, &Process::ControlInlet::valueChanged,
this,
239 else if(
auto ctrl = qobject_cast<Process::ValueInlet*>(ctl))
241 auto& p = node->add_control();
245 else if(
auto ctrl = qobject_cast<Process::AudioInlet*>(ctl))
249 else if(
auto ctrl = qobject_cast<Gfx::TextureInlet*>(ctl))
251 ossia::texture_inlet& inl = *node->add_texture();
252 ctrl->setupExecution(inl,
this);
254 else if(
auto ctrl = qobject_cast<Gfx::GeometryInlet*>(ctl))
256 ossia::geometry_inlet& inl = *node->add_geometry();
257 ctrl->setupExecution(inl,
this);
262 for(
auto* outlet : element.outlets())
264 if(
auto ctrl = qobject_cast<Process::ControlOutlet*>(outlet))
266 node->add_control_out();
268 else if(
auto ctrl = qobject_cast<Process::ValueOutlet*>(outlet))
270 node->add_control_out();
272 else if(
auto out = qobject_cast<Gfx::TextureOutlet*>(outlet))
274 node->add_texture_out();
275 out->nodeId = node_id;
277 else if(
auto out = qobject_cast<Gfx::GeometryOutlet*>(outlet))
279 node->add_geometry_out();
284 std::weak_ptr qex_ptr = std::shared_ptr<Execution::ExecutionCommandQueue>(
285 ctx.alias.lock(), &ctx.executionQueue);
286 std::unique_ptr<score::gfx::Node> ptr;
289 auto gpu_node =
new CustomGpuNode<Node>(qex_ptr, node->control_outs,
id, ctx.doc);
294 auto gpu_node =
new GpuComputeNode<Node>(qex_ptr, node->control_outs,
id, ctx.doc);
300 =
new GfxNode<Node>(element, qex_ptr, node->control_outs,
id, ctx.doc);
305 for(
auto& ctl : element.inlets())
307 if(
auto ctrl = qobject_cast<Gfx::TextureInlet*>(ctl))
309 ossia::texture_inlet& inl
310 =
static_cast<ossia::texture_inlet&
>(*node->root_inputs()[i]);
311 ptr->process(i, inl.data);
315 node->id = gfx_exec.ui->register_node(std::move(ptr));
320 void recompute_ports()
323 auto n = std::dynamic_pointer_cast<safe_node<Node>>(this->node);
328 in_exec([dp = this->process().dynamic_ports, node = n] {
329 node->dynamic_ports = dp;
330 node->root_inputs().clear();
331 node->root_outputs().clear();
332 node->initialize_all_ports();
336 void connect_controls(
338 std::shared_ptr<safe_node<Node>>& ptr)
340 using dynamic_ports_port_type = avnd::dynamic_ports_input_introspection<Node>;
341 using control_inputs_type = avnd::control_input_introspection<Node>;
342 using curve_inputs_type = avnd::curve_input_introspection<Node>;
343 using soundfile_inputs_type = avnd::soundfile_input_introspection<Node>;
344 using midifile_inputs_type = avnd::midifile_input_introspection<Node>;
345 using raw_file_inputs_type = avnd::raw_file_input_introspection<Node>;
346 using control_outputs_type = avnd::control_output_introspection<Node>;
349 safe_node<Node>& node = *ptr;
350 avnd::effect_container<Node>& eff = node.impl;
355 if constexpr(dynamic_ports_port_type::size > 0)
357 for(
auto state : eff.full_state())
359 dynamic_ports_port_type::for_all_n2(
363 if constexpr(control_inputs_type::size > 0)
365 for(
auto state : eff.full_state())
367 control_inputs_type::for_all_n2(
371 if constexpr(curve_inputs_type::size > 0)
373 for(
auto state : eff.full_state())
375 curve_inputs_type::for_all_n2(
379 if constexpr(soundfile_inputs_type::size > 0)
381 soundfile_inputs_type::for_all_n2(
382 avnd::get_inputs<Node>(eff),
385 setup_soundfile_task_pool(element, ctx, ptr);
387 if constexpr(midifile_inputs_type::size > 0)
389 midifile_inputs_type::for_all_n2(
390 avnd::get_inputs<Node>(eff),
393 if constexpr(raw_file_inputs_type::size > 0)
395 raw_file_inputs_type::for_all_n2(
396 avnd::get_inputs<Node>(eff),
401 if constexpr(control_inputs_type::size > 0 || control_outputs_type::size > 0)
404 std::weak_ptr<safe_node<Node>> weak_node = ptr;
408 con(ctx.doc.coarseUpdateTimer, &QTimer::timeout,
this,
409 [timer_action = std::move(timer_action)] { timer_action(); },
410 Qt::QueuedConnection);
414 void setup_soundfile_task_pool(
416 std::shared_ptr<safe_node<Node>>& ptr)
418 safe_node<Node>& node = *ptr;
420 using soundfile_inputs_type = avnd::soundfile_input_introspection<Node>;
422 auto& tq = score::TaskPool::instance();
423 node.soundfiles.load_request
424 = [&tq, p = std::weak_ptr{ptr}, &ctx](std::string& str,
int idx) {
425 auto eff_ptr = p.lock();
428 tq.post([eff_ptr = std::move(eff_ptr), filename = str, &ctx, idx]()
mutable {
429 if(
auto file = loadSoundfile(filename, ctx.doc, ctx.execState))
431 ctx.executionQueue.enqueue(
432 [sf = std::move(file), p = std::weak_ptr{eff_ptr}, idx]()
mutable {
433 auto eff_ptr = p.lock();
437 avnd::effect_container<Node>& eff = eff_ptr->impl;
438 soundfile_inputs_type::for_nth_mapped_n2(
439 avnd::get_inputs<Node>(eff), idx,
440 [&]<std::size_t NField, std::size_t N>(
441 auto& field, avnd::predicate_index<N> p,
442 avnd::field_index<NField> f) {
443 eff_ptr->soundfile_loaded(sf, p, f);
451 void connect_message_bus(
455 if constexpr(avnd::has_gui_to_processor_bus<Node>)
457 element.from_ui = [qex_ptr = weak_exec, &eff](QByteArray b) {
458 auto qex = qex_ptr.lock();
462 qex->enqueue([mess = std::move(b), &eff]()
mutable {
463 using refl = avnd::function_reflection<&Node::process_message>;
464 static_assert(refl::count <= 1);
466 if constexpr(refl::count == 0)
469 eff.process_message();
471 else if constexpr(refl::count == 1)
473 using arg_type = avnd::first_argument<&Node::process_message>;
474 std::decay_t<arg_type> arg;
477 eff.process_message(std::move(arg));
483 if constexpr(avnd::has_processor_to_gui_bus<Node>)
485 if constexpr(
requires { eff.send_message = [](
auto&&) { }; })
487 eff.send_message = [proc = QPointer{&this->process()},
488 qed_ptr = weak_edit]<
typename T>(T&& b)
mutable {
489 auto qed = qed_ptr.lock();
493 sizeof(QPointer<QObject>) +
sizeof(b)
494 < Execution::ExecutionCommand::max_storage)
496 qed->enqueue([proc, bb = std::move(b)]()
mutable {
497 if(proc && proc->to_ui)
504 [proc, bb = std::make_unique<std::decay_t<T>>(std::move(b))]()
mutable {
505 if(proc && proc->to_ui)
511 else if constexpr(
requires { eff.send_message = []() { }; })
514 = [proc = QPointer{&this->process()}, qed_ptr = weak_edit]()
mutable {
517 auto qed = qed_ptr.lock();
521 qed->enqueue([proc]()
mutable {
522 if(proc && proc->to_ui)
530 void connect_worker(const ::Execution::Context& ctx, avnd::effect_container<Node>& eff)
532 if constexpr(avnd::has_worker<Node>)
535 auto& tq = score::TaskPool::instance();
536 using worker_type =
decltype(eff.effect.worker);
537 for(
auto& eff : eff.effects())
539 std::weak_ptr eff_ptr = std::shared_ptr<Node>(this->node, &eff);
540 std::weak_ptr qex_ptr = std::shared_ptr<Execution::ExecutionCommandQueue>(
541 ctx.alias.lock(), &ctx.executionQueue);
544 = [&tq, qex_ptr = std::move(qex_ptr),
545 eff_ptr = std::move(eff_ptr)]<
typename... Args>(Args&&... f)
mutable {
548 tq.post([eff_ptr, qex_ptr, ... ff = std::forward<Args>(f)]()
mutable {
556 =
decltype(worker_type::work(std::forward<
decltype(ff)>(ff)...));
557 if constexpr(std::is_void_v<type_of_result>)
559 worker_type::work(std::forward<
decltype(ff)>(ff)...);
565 auto res = worker_type::work(std::forward<
decltype(ff)>(ff)...);
571 ossia::qt::run_async(
572 qApp, [eff_ptr = std::move(eff_ptr), qex_ptr = std::move(qex_ptr),
573 res = std::move(res)]()
mutable {
575 std::shared_ptr qex = qex_ptr.lock();
580 [eff_ptr = std::move(eff_ptr), res = std::move(res)]()
mutable {
584 if(
auto p = eff_ptr.lock())
596 void update_controls(std::shared_ptr<safe_node<Node>>& ptr)
598 avnd::effect_container<Node>& eff = ptr->impl;
600 for(
auto state : eff.full_state())
602 avnd::input_introspection<Node>::for_all(
603 state.inputs, [&](
auto& field) { if_possible(field.update(state.effect)); });
608 void cleanup()
override
610 if constexpr(
requires { this->process().from_ui; })
612 this->process().from_ui = [](QByteArray arr) {};
620 auto& gfx_exec = this->system().doc.template plugin<Gfx::DocumentPlugin>().exec;
622 gfx_exec.ui->unregister_node(node_id);
626 for(
auto* outlet : this->process().outlets())
628 if(
auto out = qobject_cast<Gfx::TextureOutlet*>(outlet))
634 ::Execution::ProcessComponent::cleanup();