Loading...
Searching...
No Matches
ExecutorPortSetup.hpp
1#pragma once
2#include <AvndProcesses/Utils.hpp>
3#include <Process/Process.hpp>
4
5#include <Crousti/File.hpp>
6#include <Crousti/MessageBus.hpp>
7#include <Crousti/ProcessModel.hpp>
8#include <Crousti/SoundSet.hpp>
9
10#include <ossia/detail/flat_map.hpp>
11
12#include <avnd/binding/ossia/node.hpp>
13
14#include <atomic>
15#include <cstdint>
16#include <utility>
17
18namespace oscr
19{
22template <typename Node>
23struct node_with_ui_wakeups : safe_node<Node>
24{
25 using safe_node<Node>::safe_node;
26
27 ui_wakeups wakeups;
28
29 void
30 run(const ossia::token_request& tk, ossia::exec_state_facade st) noexcept override
31 {
32 wakeups.retry();
33 safe_node<Node>::run(tk, st);
34 }
35};
36
37template <typename T>
41
46template <oscr::has_dynamic_ports T>
48{
49 Process::Inlets m_oldInlets;
50 Process::Outlets m_oldOutlets;
51 ossia::flat_map<Process::Inlet*, std::pair<int, QMetaObject::Connection>>
52 m_connectedControls;
53};
54
55// A halp::folder_port: a std::string control whose widget is a directory picker
56// (`enum widget { folder };`). Like the file ports, its value is a path and must
57// go through score::locateFilePath so that <LIBRARY>:, <PROJECT>: and
58// document-relative paths are resolved before the object reads it.
59template <typename T>
60concept folder_control_port = (requires { T::folder; } || requires { T::file; }
61 || requires { T::placeholders(); })
62 && requires(T t) {
63 { t.value } -> std::convertible_to<std::string_view>;
64 };
65
68template <typename Field>
69ossia::value resolveControlPath(const ossia::value& v, const score::DocumentContext& ctx)
70{
71 if constexpr(requires { Field::placeholders(); })
72 {
73 if(auto str = v.target<std::string>(); str && !str->empty())
74 return ossia::value{avnd_tools::filter_filename(*str, ctx).toStdString()};
75 return v;
76 }
77 else
78 return resolvePathValue(v, ctx);
79}
80
89template <typename T>
90inline constexpr bool control_value_owns_memory
91 = !std::is_trivially_destructible_v<T> || sizeof(T) > 64;
92
101{
103 const void* field{};
107 uint64_t number{};
108 const std::atomic<uint64_t>* written{};
109
111 bool stale() const noexcept
112 {
113 return written && written->load(std::memory_order_relaxed) != number;
114 }
115};
116inline thread_local processor_write_back control_written_by_processor{};
117
118template <typename Node, typename Field, std::size_t NPred, std::size_t NField>
120{
121 using ExecNode = safe_node<Node>;
122 const Execution::Context& ctx;
123 std::weak_ptr<ExecNode> weak_node;
124 Field& field;
125
126 // NPred is the index of the port in whichever list it was dispatched from in
127 // Executor::connect_controls -- the controls, but also e.g. the curve ports.
128 // control_updated_from_ui indexes the control list, so the two only coincide
129 // when the port happens to be at the same position in both. Recompute it from
130 // the field index, which is unambiguous.
131 static constexpr std::size_t control_index
132 = avnd::control_input_introspection<Node>::field_index_to_index(
133 avnd::field_index<NField>{});
134
135 void operator()(const ossia::value& val)
136 {
137 using control_value_type = std::decay_t<decltype(Field::value)>;
138
139 const auto echo = control_written_by_processor.field == &field
140 ? control_written_by_processor
142 if(auto node = weak_node.lock())
143 {
144 if constexpr(control_value_owns_memory<control_value_type>)
145 {
146 auto v = std::make_unique<control_value_type>();
147 node->from_ossia_value(field, val, *v, avnd::field_index<NField>{});
148 ctx.executionQueue.enqueue([weak_node = weak_node, gcq = ctx.weakGCQueue(),
149 v = std::move(v), echo]() mutable {
150 if(auto n = weak_node.lock(); n && !echo.stale())
151 n->template control_updated_from_ui<control_value_type, control_index>(
152 std::move(*v));
153 free_on_main_thread(gcq, v);
154 });
155 }
156 else
157 {
158 control_value_type v;
159 node->from_ossia_value(field, val, v, avnd::field_index<NField>{});
160 ctx.executionQueue.enqueue([weak_node = weak_node, v = std::move(v), echo]() mutable {
161 if(auto n = weak_node.lock(); n && !echo.stale())
162 {
163 n->template control_updated_from_ui<control_value_type, control_index>(
164 std::move(v));
165 }
166 });
167 }
168 }
169 }
170};
171
175template <typename Node, typename Field, std::size_t NPred, std::size_t NField>
177{
178 using ExecNode = safe_node<Node>;
179 const Execution::Context& ctx;
180 std::weak_ptr<ExecNode> weak_node;
181 int port_index;
182
183 void operator()(const ossia::value& val)
184 {
185 using control_type = avnd::dynamic_port_type<Field>;
186 using control_value_type = std::decay_t<decltype(control_type::value)>;
187
188 if(auto node = weak_node.lock())
189 {
190 // The group's port vector belongs to the execution thread, which resizes
191 // it: it must not be read from here, not even to look up the port. The
192 // conversion only depends on the port type, so it is done against a
193 // local instance; the bounds check happens in the execution thread,
194 // in control_updated_from_ui.
195 control_type witness{};
196 if constexpr(control_value_owns_memory<control_value_type>)
197 {
198 auto v = std::make_unique<control_value_type>();
199 node->from_ossia_value(witness, val, *v, avnd::field_index<NField>{});
200 ctx.executionQueue.enqueue([weak_node = weak_node, port_index = port_index,
201 gcq = ctx.weakGCQueue(), v = std::move(v)]() mutable {
202 if(auto n = weak_node.lock())
203 n->template control_updated_from_ui<control_value_type, NPred>(
204 std::move(*v), port_index);
205 free_on_main_thread(gcq, v);
206 });
207 }
208 else
209 {
210 control_value_type v;
211 node->from_ossia_value(witness, val, v, avnd::field_index<NField>{});
212 ctx.executionQueue.enqueue([weak_node = weak_node, port_index = port_index,
213 v = std::move(v)]() mutable {
214 if(auto n = weak_node.lock())
215 {
216 n->template control_updated_from_ui<control_value_type, NPred>(
217 std::move(v), port_index);
218 }
219 });
220 }
221 }
222 }
223};
224
225template <typename Node, typename Field>
227{
228 using ExecNode = safe_node<Node>;
230
231 Model& element;
232 const Execution::Context& ctx;
233 const std::shared_ptr<ExecNode>& node_ptr;
234 QObject* parent;
235
236 void invoke_update(Field& param, int k)
237 {
238 avnd::effect_container<Node>& eff = node_ptr->impl;
239 {
240 for(auto state : eff.full_state())
241 {
242 if constexpr(avnd::dynamic_ports_port<Field>)
243 {
244 avnd::update_if_holding_value(state, param.ports[k]);
245 }
246 else
247 {
248 avnd::update_if_holding_value(state, param);
249 }
250 }
251 }
252 }
253};
254template <typename Node, typename Field, std::size_t N, std::size_t NField>
256
257template <typename Node, typename Field, std::size_t N, std::size_t NField>
259{
260 using ExecNode = safe_node<Node>;
262
263 void initialize_control(Field& param, Process::ControlInlet* inlet, int k)
264 {
265 // Initialize the control with the current value of the inlet if it is not an optional
266 if constexpr(avnd::dynamic_ports_port<Field>)
267 {
268 using port_type = avnd::dynamic_port_type<Field>;
269 if constexpr(avnd::parameter_port<port_type>)
270 {
271 if constexpr(!requires { param.ports[0].value.reset(); })
272 {
273 this->node_ptr->from_ossia_value(
274 param, inlet->value(), param.ports[k].value, avnd::field_index<NField>{});
275 }
276 }
277 }
278 else
279 {
280 if constexpr(!requires { param.value.reset(); })
281 {
282 this->node_ptr->from_ossia_value(
283 param, inlet->value(), param.value, avnd::field_index<NField>{});
284 }
285 }
286 }
287
298 void update_controller(Field& param, Process::ControlInlet* inlet)
299 {
300 if constexpr(requires { param.update_controller; })
301 {
302 using function_type = std::remove_cvref_t<decltype(param.update_controller)>;
303 using arg_type
304 = std::remove_cvref_t<typename function_argument<function_type>::type>;
305 static constexpr bool is_text = std::is_same_v<arg_type, std::string_view>;
306 using value_type = std::conditional_t<is_text, std::string, arg_type>;
307
308 std::size_t capacity = 0;
309 if constexpr(is_text)
310 {
311 capacity = 4096;
312 if constexpr(requires { Field::max_length(); })
313 capacity = Field::max_length();
314 }
315
316 // Each value goes with the number of the write it is.
317 using written_value = std::pair<value_type, uint64_t>;
318 auto box = std::make_shared<latest_value<written_value>>();
319 if constexpr(is_text)
320 box->for_each_slot([capacity](written_value& s) { s.first.reserve(capacity); });
321 auto written = std::make_shared<std::atomic<uint64_t>>(0);
322
323 // Sends the wake-up the box requested; false when the queue is full.
324 const void* field = &param;
325 auto wake = [inlet = QPointer{inlet}, self = QPointer{&this->element},
326 qed_ptr = this->ctx.weakEditionQueue(), box, field, written] {
327 auto qed = qed_ptr.lock();
328 if(!qed)
329 {
330 box->cancel();
331 return true;
332 }
333 if(qed->try_enqueue([inlet, self, box, field, written] {
334 auto v = box->take();
335 if(!v || !self || !inlet)
336 return;
337 const auto previous = std::exchange(
338 control_written_by_processor,
339 processor_write_back{field, v->second, written.get()});
340 if constexpr(requires { Field::controller_value(v->first); })
341 inlet->setValue(oscr::to_ossia_value(Field::controller_value(v->first)));
342 else
343 inlet->setValue(v->first);
344 control_written_by_processor = previous;
345 }))
346 return true;
347 box->park();
348 return false;
349 };
350
351 // A value written once, then never again, still reaches the UI when
352 // the queue was full: the node sends its wake-up on a later tick.
353 auto* wakeups = [&]() -> ui_wakeups* {
354 if(auto n = dynamic_cast<node_with_ui_wakeups<Node>*>(this->node_ptr.get()))
355 return &n->wakeups;
356 return nullptr;
357 }();
358 if(wakeups)
359 {
360 wakeups->add([box, wake] {
361 if(!box->unpark() || !box->request())
362 return true;
363 return wake();
364 });
365 }
366
367 param.update_controller
368 = [box, capacity, wake, wakeups, written](arg_type value) {
369 auto& slot = box->back();
370 if constexpr(is_text)
371 slot.first.assign(value.substr(0, std::min(value.size(), capacity)));
372 else
373 slot.first = std::move(value);
374 slot.second = written->fetch_add(1, std::memory_order_relaxed) + 1;
375 box->publish();
376
377 if(!box->request())
378 return;
379 if(!wake() && wakeups)
380 wakeups->park();
381 };
382 }
383 }
384
389 dynamic_ports_component_data<Node>& control_data, Field& param,
390 Process::ControlInlet* inlet, int k)
391 {
392 if constexpr(requires { control_data.m_connectedControls; })
393 {
394 auto it = control_data.m_connectedControls.find(inlet);
395 if(it != control_data.m_connectedControls.end())
396 {
397 if constexpr(!avnd::dynamic_ports_port<Field>)
398 return false;
399 if(it->second.first == k)
400 return false;
401 QObject::disconnect(it->second.second);
402 control_data.m_connectedControls.erase(it);
403 }
404 }
405
406 // Connect to changes
407 std::weak_ptr<ExecNode> weak_node = this->node_ptr;
408 QMetaObject::Connection connection;
409 if constexpr(avnd::dynamic_ports_port<Field>)
410 {
411 connection = QObject::connect(
412 inlet, &Process::ControlInlet::valueChanged, this->parent,
414 }
415 else
416 {
417 connection = QObject::connect(
418 inlet, &Process::ControlInlet::valueChanged, this->parent,
419 con_unvalidated<Node, Field, N, NField>{this->ctx, weak_node, param});
420 }
421
422 if constexpr(requires { control_data.m_connectedControls; })
423 control_data.m_connectedControls.emplace(inlet, std::pair{k, connection});
424 return true;
425 }
426
430 void push_current_value(Field& param, Process::ControlInlet* inlet, int k)
431 {
432 std::weak_ptr<ExecNode> weak_node = this->node_ptr;
433 if constexpr(avnd::dynamic_ports_port<Field>)
434 {
436 inlet->value());
437 }
438 else
439 {
440 con_unvalidated<Node, Field, N, NField>{this->ctx, weak_node, param}(
441 inlet->value());
442 }
443 }
444
445 // Used on initial creation
446 void connect_control_to_ui(
447 dynamic_ports_component_data<Node>& control_data, Field& param,
448 Process::ControlInlet* inlet, int k)
449 {
450 reconnect_control_to_ui(control_data, param, inlet, k);
451 this->update_controller(param, inlet);
452 }
453};
454
455template <typename Node, avnd::soundfile_port Field, std::size_t N, std::size_t NField>
456struct setup_control_for_exec<Node, Field, N, NField>
457 : setup_control_for_exec_base<Node, Field>
458{
459 using ExecNode = safe_node<Node>;
461
462 void initialize_control(Field& param, Process::ControlInlet* inlet, int k)
463 {
464 // FIXME handle dynamic ports correctly
465 // First we can load it directly since execution hasn't started yet
466 if(auto hdl = loadSoundfile(inlet->value(), this->ctx.doc, this->ctx.execState))
467 this->node_ptr->soundfile_loaded(
468 hdl, avnd::predicate_index<N>{}, avnd::field_index<NField>{});
469 }
470
471 void connect_control_to_ui(
473 int k)
474 {
475 // Connect to changes
476 std::weak_ptr<ExecNode> weak_node = this->node_ptr;
477 std::weak_ptr<ossia::execution_state> weak_st = this->ctx.execState;
478 QObject::connect(
479 inlet, &Process::ControlInlet::valueChanged, this->parent,
480 [&ctx = this->ctx, weak_node = std::move(weak_node),
481 weak_st = std::move(weak_st)](const ossia::value& v) {
482 if(auto n = weak_node.lock())
483 if(auto st = weak_st.lock())
484 if(auto file = loadSoundfile(v, ctx.doc, st))
485 {
486 ctx.executionQueue.enqueue([f = std::move(file), weak_node,
487 gcq = ctx.weakGCQueue()]() mutable {
488 // f becomes the file the port held before
489 if(auto n = weak_node.lock())
490 f = n->soundfile_loaded(
491 f, avnd::predicate_index<N>{}, avnd::field_index<NField>{});
492 free_on_main_thread(gcq, f);
493 });
494 }
495 });
496 }
497};
498
499template <typename Node, avnd::midifile_port Field, std::size_t N, std::size_t NField>
500struct setup_control_for_exec<Node, Field, N, NField>
501 : setup_control_for_exec_base<Node, Field>
502{
503 using ExecNode = safe_node<Node>;
504 using Model = ProcessModel<Node>;
505
506 void initialize_control(Field& param, Process::ControlInlet* inlet, int k)
507 {
508 // FIXME handle dynamic ports correctly
509
510 // First we can load it directly since execution hasn't started yet
511 if(auto hdl = loadMidifile(inlet->value(), this->ctx.doc))
512 this->node_ptr->midifile_loaded(
513 hdl, avnd::predicate_index<N>{}, avnd::field_index<NField>{});
514 }
515
516 void connect_control_to_ui(
517 dynamic_ports_component_data<Node>&, Field& param, Process::ControlInlet* inlet,
518 int k)
519 {
520 // Connect to changes
521 std::weak_ptr<ExecNode> weak_node = this->node_ptr;
522 std::weak_ptr<ossia::execution_state> weak_st = this->ctx.execState;
523 QObject::connect(
524 inlet, &Process::ControlInlet::valueChanged, this->parent,
525 [inlet, &ctx = this->ctx,
526 weak_node = std::move(weak_node)](const ossia::value& v) {
527 if(auto n = weak_node.lock())
528 if(auto file = loadMidifile(v, ctx.doc))
529 {
530 ctx.executionQueue.enqueue([f = std::move(file), weak_node,
531 gcq = ctx.weakGCQueue()]() mutable {
532 // f becomes the file the port held before
533 if(auto n = weak_node.lock())
534 f = n->midifile_loaded(
535 f, avnd::predicate_index<N>{}, avnd::field_index<NField>{});
536 free_on_main_thread(gcq, f);
537 });
538 }
539 });
540 }
541};
542
543template <typename Node, avnd::raw_file_port Field, std::size_t N, std::size_t NField>
544struct setup_control_for_exec<Node, Field, N, NField>
545 : setup_control_for_exec_base<Node, Field>
546{
547 using ExecNode = safe_node<Node>;
548 using Model = ProcessModel<Node>;
549
550 static constexpr bool has_text = requires { decltype(Field::file)::text; };
551 static constexpr bool has_mmap = requires { decltype(Field::file)::mmap; };
552
553 void initialize_control(Field& param, Process::ControlInlet* inlet, int k)
554 {
555 // FIXME handle dynamic ports correctly
556
557 // First we can load it directly since execution hasn't started yet
558 if(auto hdl = loadRawfile(inlet->value(), this->ctx.doc, has_text, has_mmap))
559 {
560 if constexpr(avnd::port_can_process<Field>)
561 {
562 // FIXME also do it when we get a run-time message from the exec engine,
563 // OSC, etc
564 auto func = executePortPreprocess<Field>(*hdl);
565 this->node_ptr->file_loaded(
566 hdl, avnd::predicate_index<N>{}, avnd::field_index<NField>{});
567 if(func)
568 func(this->node_ptr->impl.effect);
569 }
570 else
571 {
572 this->node_ptr->file_loaded(
573 hdl, avnd::predicate_index<N>{}, avnd::field_index<NField>{});
574 }
575 }
576 }
577
578 void connect_control_to_ui(
579 dynamic_ports_component_data<Node>&, Field& param, Process::ControlInlet* inlet,
580 int k)
581 {
582 // Connect to changes
583 std::weak_ptr<ExecNode> weak_node = this->node_ptr;
584 std::weak_ptr<ossia::execution_state> weak_st = this->ctx.execState;
585 QObject::connect(
586 inlet, &Process::ControlInlet::valueChanged, this->parent,
587 [inlet, &ctx = this->ctx, weak_node = std::move(weak_node)] {
588 if(auto n = weak_node.lock())
589 if(auto file = loadRawfile(inlet->value(), ctx.doc, has_text, has_mmap))
590 {
591 if constexpr(avnd::port_can_process<Field>)
592 {
593 auto func = executePortPreprocess<Field>(*file);
594 ctx.executionQueue.enqueue([f = std::move(file), weak_node,
595 gcq = ctx.weakGCQueue(),
596 ff = std::move(func)]() mutable {
597 // f becomes the file the port held before
598 if(auto n = weak_node.lock())
599 {
600 f = n->file_loaded(
601 f, avnd::predicate_index<N>{}, avnd::field_index<NField>{});
602 if(ff)
603 ff(n->impl.effect);
604 }
605 free_on_main_thread(gcq, f, ff);
606 });
607 }
608 else
609 {
610 ctx.executionQueue.enqueue([f = std::move(file), weak_node,
611 gcq = ctx.weakGCQueue()]() mutable {
612 // f becomes the file the port held before
613 if(auto n = weak_node.lock())
614 f = n->file_loaded(
615 f, avnd::predicate_index<N>{}, avnd::field_index<NField>{});
616 free_on_main_thread(gcq, f);
617 });
618 }
619 }
620 });
621 }
622};
623
624// folder_port: a path-valued string control. Resolve <LIBRARY>: / <PROJECT>: /
625// document-relative paths through score::locateFilePath before the object reads
626// them -- exactly like the file ports above -- otherwise the object receives the
627// raw library-relative string and cannot find the directory.
628template <typename Node, folder_control_port Field, std::size_t N, std::size_t NField>
629struct setup_control_for_exec<Node, Field, N, NField>
630 : setup_control_for_exec_base<Node, Field>
631{
632 using ExecNode = safe_node<Node>;
633 using Model = ProcessModel<Node>;
634
635 void initialize_control(Field& param, Process::ControlInlet* inlet, int k)
636 {
637 if constexpr(!requires { param.value.reset(); })
638 {
639 this->node_ptr->from_ossia_value(
640 param, resolveControlPath<Field>(inlet->value(), this->ctx.doc), param.value,
641 avnd::field_index<NField>{});
642 }
643 }
644
645 void connect_control_to_ui(
646 dynamic_ports_component_data<Node>&, Field& param, Process::ControlInlet* inlet,
647 int k)
648 {
649 std::weak_ptr<ExecNode> weak_node = this->node_ptr;
650 QObject::connect(
651 inlet, &Process::ControlInlet::valueChanged, this->parent,
652 [&ctx = this->ctx, weak_node = std::move(weak_node),
653 field = &param](const ossia::value& val) {
654 // Resolve the path on every change, then run the normal control-update
655 // path (from_ossia_value + control_updated_from_ui) via con_unvalidated.
656 con_unvalidated<Node, Field, N, NField>{ctx, weak_node, *field}(
657 resolveControlPath<Field>(val, ctx.doc));
658 });
659 }
660};
661
662// halp::sound_set: a folder_port whose files the host lists, decodes and
663// watches. A SoundSetLoader does it on the UI side and the task pool, and
664// publishes each new set into the port between two ticks.
665template <typename T>
666concept sound_set_control_port = folder_control_port<T> && avnd::sound_set_port<T>;
667
668template <typename Node, sound_set_control_port Field, std::size_t N, std::size_t NField>
669struct setup_control_for_exec<Node, Field, N, NField>
670 : setup_control_for_exec_base<Node, Field>
671{
672 using ExecNode = safe_node<Node>;
673
674 void initialize_control(Field& param, Process::ControlInlet* inlet, int k)
675 {
676 this->node_ptr->from_ossia_value(
677 param, resolveControlPath<Field>(inlet->value(), this->ctx.doc), param.value,
678 avnd::field_index<NField>{});
679 }
680
681 void connect_control_to_ui(
682 dynamic_ports_component_data<Node>&, Field& param, Process::ControlInlet* inlet,
683 int k)
684 {
685 auto& ctx = this->ctx;
686 std::weak_ptr<ExecNode> weak_node = this->node_ptr;
687
688 SoundSetOptions opts;
689 opts.extensions = soundSetExtensions(Field::extensions());
690 opts.recursive = Field::recursive();
691 opts.decoding = Field::decoding();
692 opts.rate = int(ossia::exec_state_facade{ctx.execState.get()}.sampleRate());
693
694 // The command keeps the snapshot alive while it is in flight; it is retired
695 // to the UI thread with it. The loader keeps its own reference.
696 auto publish = [&ctx, weak_node](
697 std::shared_ptr<SoundSetSnapshot> next,
698 SoundSetSnapshot* previous) {
699 ctx.executionQueue.enqueue(
700 [weak_node, next = std::move(next), previous]() mutable {
701 if(auto n = weak_node.lock())
702 for(auto state : n->impl.full_state())
703 avnd::pfr::get<NField>(state.inputs).files = next->view();
704 if(previous)
705 previous->superseded.store(true, std::memory_order_release);
706 });
707 };
708 // When the loader goes, the node is being removed: what it may still read
709 // is freed with a command, which runs after the node's last tick.
710 auto dispose = [&ctx](std::vector<std::shared_ptr<SoundSetSnapshot>> snaps) {
711 ctx.executionQueue.enqueue([snaps = std::move(snaps)] {});
712 };
713
714 auto loader = new SoundSetLoader{
715 std::move(opts), std::move(publish), std::move(dispose), this->parent};
716 loader->setPath(QString::fromStdString(ossia::convert<std::string>(
717 resolveControlPath<Field>(inlet->value(), ctx.doc))));
718
719 QObject::connect(
720 inlet, &Process::ControlInlet::valueChanged, loader,
721 [&ctx, weak_node, field = &param, loader](const ossia::value& val) {
722 const auto resolved = resolveControlPath<Field>(val, ctx.doc);
723 con_unvalidated<Node, Field, N, NField>{ctx, weak_node, *field}(resolved);
724 loader->setPath(QString::fromStdString(ossia::convert<std::string>(resolved)));
725 });
726 }
727};
728
732template <typename Field>
734 = !ossia_port<avnd::concrete_port_type<Field>>
735 && (!avnd::dynamic_ports_port<Field>
736 || avnd::parameter_port<avnd::concrete_port_type<Field>>);
737
738template <typename Node>
740{
741 using ExecNode = safe_node<Node>;
743
744 Model& element;
745 const Execution::Context& ctx;
746 const std::shared_ptr<ExecNode>& node_ptr;
748 QObject* parent;
749
750 // Main function being invoked, which dispatches to all the actual implementations
751 template <typename Field, std::size_t N, std::size_t NField>
752 constexpr void
753 operator()(Field& param, avnd::predicate_index<N> np, avnd::field_index<NField> nf)
754 {
755 const auto ports = element.avnd_input_idx_to_model_ports(NField);
756
757 if constexpr(avnd::dynamic_ports_port<Field>)
758 {
759 param.ports.resize(ports.size());
760 }
761
762 if constexpr(field_has_ui_controls<Field>)
763 {
764 int k = 0;
765 for(auto p : ports)
766 {
767 if(auto inlet = qobject_cast<Process::ControlInlet*>(p))
768 {
770 element, ctx, node_ptr, parent};
771
772 setup.initialize_control(param, inlet, k);
773
774 setup.invoke_update(param, k);
775
776 setup.connect_control_to_ui(control_data, param, inlet, k);
777 }
778 k++;
779 // Else it's an unhandled value inlet
780 }
781 }
782 }
783};
784
785// Only used when dynamic ports are added
786template <typename Node>
788{
789 using ExecNode = safe_node<Node>;
791
792 Model& element;
793 const Execution::Context& ctx;
794 const std::shared_ptr<ExecNode>& node_ptr;
796 QObject* parent;
797
798 // Main function being invoked, which dispatches to all the actual implementations
799 template <typename Field, std::size_t N, std::size_t NField>
800 constexpr void
801 operator()(Field& param, avnd::predicate_index<N> np, avnd::field_index<NField> nf)
802 {
803 if constexpr(field_has_ui_controls<Field>)
804 {
805 const auto ports = element.avnd_input_idx_to_model_ports(NField);
806 int k = 0;
807 for(auto p : ports)
808 {
809 if(auto inlet = qobject_cast<Process::ControlInlet*>(p))
810 {
812 element, ctx, node_ptr, parent};
813
814 // A port that was just added: connect it and give the exec side its
815 // current value. Ports that were already there keep their connection
816 // and their value.
817 if(setup.reconnect_control_to_ui(control_data, param, inlet, k))
818 setup.push_current_value(param, inlet, k);
819 }
820 k++;
821 // Else it's an unhandled value inlet
822 }
823 }
824 }
825};
826}
Definition Port.hpp:247
Definition score-plugin-avnd/Crousti/ProcessModel.hpp:123
Definition ExecutorPortSetup.hpp:60
Definition ExecutorPortSetup.hpp:666
TreeNode< DeviceExplorerNode > Node
Definition DeviceNode.hpp:74
Definition Controls.hpp:30
constexpr bool control_value_owns_memory
Definition ExecutorPortSetup.hpp:91
ossia::value resolveControlPath(const ossia::value &v, const score::DocumentContext &ctx)
Definition ExecutorPortSetup.hpp:69
QStringList soundSetExtensions(std::string_view exts)
The extensions a sound_set port lists, from its extensions() string.
Definition SoundSet.cpp:138
constexpr bool field_has_ui_controls
Definition ExecutorPortSetup.hpp:734
Definition ExecutionContext.hpp:208
Definition PortForward.hpp:23
Definition PortForward.hpp:27
Definition ExecutorPortSetup.hpp:177
Definition ExecutorPortSetup.hpp:120
Definition ExecutorPortSetup.hpp:788
Definition ExecutorPortSetup.hpp:740
Definition ExecutorPortSetup.hpp:39
Definition ExecutorPortSetup.hpp:24
Definition ExecutorPortSetup.hpp:101
const void * field
The control, only compared with.
Definition ExecutorPortSetup.hpp:103
bool stale() const noexcept
Audio thread.
Definition ExecutorPortSetup.hpp:111
uint64_t number
Definition ExecutorPortSetup.hpp:107
Definition ExecutorPortSetup.hpp:227
Definition ExecutorPortSetup.hpp:259
void update_controller(Field &param, Process::ControlInlet *inlet)
Definition ExecutorPortSetup.hpp:298
bool reconnect_control_to_ui(dynamic_ports_component_data< Node > &control_data, Field &param, Process::ControlInlet *inlet, int k)
Definition ExecutorPortSetup.hpp:388
void push_current_value(Field &param, Process::ControlInlet *inlet, int k)
Definition ExecutorPortSetup.hpp:430
Definition MessageBus.hpp:75
void retry() noexcept
Writer's thread, at each tick.
Definition MessageBus.hpp:83
Definition DocumentContext.hpp:18