114 return uuid_from_string<Node>();
121 return static_key() == other || Execution::ProcessComponent::base_key_match(other);
124 [[no_unique_address]] ossia::type_if<int, is_gpu<Node>> node_id = -1;
128 element, ctx,
"Executor::ProcessModel<Info>", p}
133 setup_gpu(element, ctx, p);
138 setup_cpu(element, ctx, p);
141 if constexpr(avnd::tag_process_exec<Node>)
143 this->m_ossia_process = std::make_shared<CustomNodeProcess<Node>>(this->node);
147 this->m_ossia_process = std::make_shared<ossia::node_process>(this->node);
155 = *ctx.doc.findPlugin<Explorer::DeviceDocumentPlugin>()->networkContext();
159 auto st = ossia::exec_state_facade{ctx.execState.get()};
160 std::shared_ptr<safe_node<Node>> ptr;
161 auto node =
new safe_node<Node>{st.bufferSize(), (double)st.sampleRate(),
id};
162 node->root_inputs().reserve(element.inlets().size());
163 node->root_outputs().reserve(element.outlets().size());
165 node->prepare(*ctx.execState.get());
167 if_possible(node->impl.effect.ossia_state = st);
168 if_possible(node->impl.effect.io_context = &net_ctx.context);
169 if_possible(node->impl.effect.ossia_document_context = &ctx.doc);
173 if constexpr(
requires { ptr->impl.effect; })
174 if constexpr(std::is_same_v<std::decay_t<
decltype(ptr->impl.effect)>, Node>)
175 connect_message_bus(element, ctx, ptr->impl.effect);
176 connect_worker(ctx, ptr->impl);
178 node->dynamic_ports = element.dynamic_ports;
181 connect_controls(element, ctx, ptr);
182 update_controls(ptr);
184 &element, &Process::ProcessModel::inletsChanged,
this,
185 &Executor::recompute_ports);
187 &element, &Process::ProcessModel::outletsChanged,
this,
188 &Executor::recompute_ports);
191 node->audio_configuration_changed(st);
193 m_oldInlets = element.inlets();
194 m_oldOutlets = element.outlets();
210 using Gfx::gfx_exec_node::gfx_exec_node;
211 std::string label()
const noexcept override
213 return std::string(avnd::get_name<Node>());
217 auto node = std::make_shared<named_exec_node>(gfx_exec);
218 node->prepare(*ctx.execState);
224 for(
auto& ctl : element.inlets())
226 if(
auto ctrl = qobject_cast<Process::ControlInlet*>(ctl))
228 auto& p = node->add_control();
229 p->value = ctrl->value();
233 ctrl, &Process::ControlInlet::valueChanged,
this,
237 else if(
auto ctrl = qobject_cast<Process::ValueInlet*>(ctl))
239 auto& p = node->add_control();
243 else if(
auto ctrl = qobject_cast<Process::AudioInlet*>(ctl))
247 else if(
auto ctrl = qobject_cast<Gfx::TextureInlet*>(ctl))
254 for(
auto* outlet : element.outlets())
256 if(
auto ctrl = qobject_cast<Process::ControlOutlet*>(outlet))
258 node->add_control_out();
260 else if(
auto ctrl = qobject_cast<Process::ValueOutlet*>(outlet))
262 node->add_control_out();
264 else if(
auto out = qobject_cast<Gfx::TextureOutlet*>(outlet))
266 node->add_texture_out();
267 out->nodeId = node_id;
272 std::weak_ptr qex_ptr = std::shared_ptr<Execution::ExecutionCommandQueue>(
273 ctx.alias.lock(), &ctx.executionQueue);
274 std::unique_ptr<score::gfx::Node> ptr;
277 auto gpu_node =
new CustomGpuNode<Node>(qex_ptr, node->control_outs,
id, ctx.doc);
282 auto gpu_node =
new GpuComputeNode<Node>(qex_ptr, node->control_outs,
id, ctx.doc);
288 =
new GfxNode<Node>(element, qex_ptr, node->control_outs,
id, ctx.doc);
291 node->id = gfx_exec.ui->register_node(std::move(ptr));
296 void recompute_ports()
299 auto n = std::dynamic_pointer_cast<safe_node<Node>>(this->node);
304 this->in_exec([dp = this->process().dynamic_ports, node = n] {
305 node->dynamic_ports = dp;
306 node->root_inputs().clear();
307 node->root_outputs().clear();
308 node->initialize_all_ports();
312 void connect_controls(
314 std::shared_ptr<safe_node<Node>>& ptr)
316 using dynamic_ports_port_type = avnd::dynamic_ports_input_introspection<Node>;
317 using control_inputs_type = avnd::control_input_introspection<Node>;
318 using curve_inputs_type = avnd::curve_input_introspection<Node>;
319 using soundfile_inputs_type = avnd::soundfile_input_introspection<Node>;
320 using midifile_inputs_type = avnd::midifile_input_introspection<Node>;
321 using raw_file_inputs_type = avnd::raw_file_input_introspection<Node>;
322 using control_outputs_type = avnd::control_output_introspection<Node>;
325 safe_node<Node>& node = *ptr;
326 avnd::effect_container<Node>& eff = node.impl;
331 if constexpr(dynamic_ports_port_type::size > 0)
333 for(
auto state : eff.full_state())
335 dynamic_ports_port_type::for_all_n2(
339 if constexpr(control_inputs_type::size > 0)
341 for(
auto state : eff.full_state())
343 control_inputs_type::for_all_n2(
347 if constexpr(curve_inputs_type::size > 0)
349 for(
auto state : eff.full_state())
351 curve_inputs_type::for_all_n2(
355 if constexpr(soundfile_inputs_type::size > 0)
357 soundfile_inputs_type::for_all_n2(
358 avnd::get_inputs<Node>(eff),
361 setup_soundfile_task_pool(element, ctx, ptr);
363 if constexpr(midifile_inputs_type::size > 0)
365 midifile_inputs_type::for_all_n2(
366 avnd::get_inputs<Node>(eff),
369 if constexpr(raw_file_inputs_type::size > 0)
371 raw_file_inputs_type::for_all_n2(
372 avnd::get_inputs<Node>(eff),
377 if constexpr(control_inputs_type::size > 0 || control_outputs_type::size > 0)
380 std::weak_ptr<safe_node<Node>> weak_node = ptr;
384 con(ctx.doc.coarseUpdateTimer, &QTimer::timeout,
this,
385 [timer_action = std::move(timer_action)] { timer_action(); },
386 Qt::QueuedConnection);
390 void setup_soundfile_task_pool(
392 std::shared_ptr<safe_node<Node>>& ptr)
394 safe_node<Node>& node = *ptr;
395 avnd::effect_container<Node>& eff = node.impl;
397 using soundfile_inputs_type = avnd::soundfile_input_introspection<Node>;
399 auto& tq = score::TaskPool::instance();
400 node.soundfiles.load_request
401 = [&tq, p = std::weak_ptr{ptr}, &ctx](std::string& str,
int idx) {
402 auto eff_ptr = p.lock();
405 tq.post([eff_ptr = std::move(eff_ptr), filename = str, &ctx, idx]()
mutable {
406 if(
auto file = loadSoundfile(filename, ctx.doc, ctx.execState))
408 ctx.executionQueue.enqueue(
409 [sf = std::move(file), p = std::weak_ptr{eff_ptr}, idx]()
mutable {
410 auto eff_ptr = p.lock();
414 avnd::effect_container<Node>& eff = eff_ptr->impl;
415 soundfile_inputs_type::for_nth_mapped_n2(
416 avnd::get_inputs<Node>(eff), idx,
417 [&]<std::size_t NField, std::size_t N>(
418 auto& field, avnd::predicate_index<N> p,
419 avnd::field_index<NField> f) {
420 eff_ptr->soundfile_loaded(sf, p, f);
428 void connect_message_bus(
432 if constexpr(avnd::has_gui_to_processor_bus<Node>)
434 element.from_ui = [p = QPointer{
this}, &eff](QByteArray b) {
438 p->in_exec([mess = std::move(b), &eff]()
mutable {
439 using refl = avnd::function_reflection<&Node::process_message>;
440 static_assert(refl::count <= 1);
442 if constexpr(refl::count == 0)
445 eff.process_message();
447 else if constexpr(refl::count == 1)
449 using arg_type = avnd::first_argument<&Node::process_message>;
450 std::decay_t<arg_type> arg;
453 eff.process_message(std::move(arg));
459 if constexpr(avnd::has_processor_to_gui_bus<Node>)
461 eff.send_message = [self = QPointer{
this}]<
typename T>(T&& b)
mutable {
465 sizeof(QPointer<QObject>) +
sizeof(b)
466 < Execution::ExecutionCommand::max_storage)
469 [proc = QPointer{&self->process()}, bb = std::move(b)]()
mutable {
477 [proc = QPointer{&self->process()},
478 bb = std::make_unique<std::decay_t<T>>(std::move(b))]()
mutable {
487 void connect_worker(const ::Execution::Context& ctx, avnd::effect_container<Node>& eff)
489 if constexpr(avnd::has_worker<Node>)
492 auto& tq = score::TaskPool::instance();
493 using worker_type =
decltype(eff.effect.worker);
494 for(
auto& eff : eff.effects())
496 std::weak_ptr eff_ptr = std::shared_ptr<Node>(this->node, &eff);
497 std::weak_ptr qex_ptr = std::shared_ptr<Execution::ExecutionCommandQueue>(
498 ctx.alias.lock(), &ctx.executionQueue);
501 = [&tq, qex_ptr = std::move(qex_ptr),
502 eff_ptr = std::move(eff_ptr)]<
typename... Args>(Args&&... f)
mutable {
505 tq.post([eff_ptr, qex_ptr, ... ff = std::forward<Args>(f)]()
mutable {
513 =
decltype(worker_type::work(std::forward<
decltype(ff)>(ff)...));
514 if constexpr(std::is_void_v<type_of_result>)
516 worker_type::work(std::forward<
decltype(ff)>(ff)...);
522 auto res = worker_type::work(std::forward<
decltype(ff)>(ff)...);
528 ossia::qt::run_async(
529 qApp, [eff_ptr = std::move(eff_ptr), qex_ptr = std::move(qex_ptr),
530 res = std::move(res)]()
mutable {
532 std::shared_ptr qex = qex_ptr.lock();
537 [eff_ptr = std::move(eff_ptr), res = std::move(res)]()
mutable {
541 if(
auto p = eff_ptr.lock())
553 void update_controls(std::shared_ptr<safe_node<Node>>& ptr)
555 avnd::effect_container<Node>& eff = ptr->impl;
557 for(
auto state : eff.full_state())
559 avnd::input_introspection<Node>::for_all(
560 state.inputs, [&](
auto& field) { if_possible(field.update(state.effect)); });
565 void cleanup()
override
567 if constexpr(
requires { this->process().from_ui; })
569 this->process().from_ui = [](QByteArray arr) {};
577 auto& gfx_exec = this->system().doc.template plugin<Gfx::DocumentPlugin>().exec;
579 gfx_exec.ui->unregister_node(node_id);
583 for(
auto* outlet : this->process().outlets())
585 if(
auto out = qobject_cast<Gfx::TextureOutlet*>(outlet))
591 ::Execution::ProcessComponent::cleanup();