ExecutorUpdateControlValueInUi.hpp
1 #pragma once
2 #include <Process/Process.hpp>
3 
4 #include <Crousti/ProcessModel.hpp>
5 
6 #include <avnd/binding/ossia/node.hpp>
7 
8 namespace oscr
9 {
10 template <typename Node>
12 {
13  using ExecNode = safe_node<Node>;
14  using Model = ProcessModel<Node>;
15 
16  typename ExecNode::control_input_values_type& arr;
17  Model& element;
18 
19  template <avnd::dynamic_ports_port Field, std::size_t N, std::size_t NField>
20  void operator()(Field& field, avnd::predicate_index<N>, avnd::field_index<NField>)
21  {
22  for(auto p : element.avnd_input_idx_to_model_ports(NField))
23  {
24  if(auto inlet = qobject_cast<Process::ControlInlet*>(p))
25  {
26  using namespace std;
27  // FIXME handle dynamic ports correctly
28  // inlet->setExecutionValue(oscr::to_ossia_value(field, get<N>(arr)));
29  }
30  }
31  }
32 
33  template <typename Field, std::size_t N, std::size_t NField>
34  void operator()(Field& field, avnd::predicate_index<N>, avnd::field_index<NField>)
35  {
36  auto p = element.avnd_input_idx_to_model_ports(NField)[0];
37  if(auto inlet = qobject_cast<Process::ControlInlet*>(p))
38  {
39  using namespace std;
40  inlet->setExecutionValue(oscr::to_ossia_value(field, get<N>(arr)));
41  }
42  }
43 };
44 
45 template <typename Node>
47 {
48  using ExecNode = safe_node<Node>;
49  using Model = ProcessModel<Node>;
50  typename ExecNode::control_output_values_type& arr;
51  Model& element;
52 
53  template <typename Field, std::size_t N, std::size_t NField>
54  void operator()(Field& field, avnd::predicate_index<N>, avnd::field_index<NField>)
55  {
56  using namespace std;
57  auto ports = element.avnd_output_idx_to_model_ports(NField);
58  SCORE_ASSERT(!ports.empty());
59  auto outlet = safe_cast<Process::ControlOutlet*>(ports[0]);
60  outlet->setValue(oscr::to_ossia_value(field, get<N>(arr)));
61  }
62 
63  template <avnd::dynamic_ports_port Field, std::size_t N, std::size_t NField>
64  void operator()(Field& field, avnd::predicate_index<N>, avnd::field_index<NField>)
65  {
66  using namespace std;
67  // FIXME handle dynamic ports correctly
68  // auto outlet
69  // = safe_cast<Process::ControlOutlet*>(modelPort<Node>(element.outlets(), NField));
70  // outlet->setValue(oscr::to_ossia_value(field, get<N>(arr)));
71  }
72 };
73 
74 template <typename Node>
76 {
77  using ExecNode = safe_node<Node>;
78  using Model = ProcessModel<Node>;
79  std::weak_ptr<ExecNode> weak_node;
80  Model& element;
81 
82  void handle_controls(ExecNode& node) const noexcept
83  {
84  using namespace ossia::safe_nodes;
85  // TODO disconnect the connection ? it will be disconnected shortly
86  // after...
87 
88  typename ExecNode::control_input_values_type arr;
89  bool ok = false;
90  while(node.control.ins_queue.try_dequeue(arr))
91  {
92  ok = true;
93  }
94  if(ok)
95  {
96  for(auto state : node.impl.full_state())
97  {
98  avnd::control_input_introspection<Node>::for_all_n2(
99  state.inputs, update_control_in_value_in_ui<Node>{arr, element});
100  }
101  }
102  }
103 
104  void handle_control_outs(ExecNode& node) const noexcept
105  {
106  using namespace ossia::safe_nodes;
107  // TODO disconnect the connection ? it will be disconnected shortly
108  // after...
109  typename ExecNode::control_output_values_type arr;
110  bool ok = false;
111  while(node.control.outs_queue.try_dequeue(arr))
112  {
113  ok = true;
114  }
115  if(ok)
116  {
117  // FIXME not thread safe?
118  avnd::control_output_introspection<Node>::for_all_n2(
119  avnd::get_outputs<Node>(node.impl),
121  }
122  }
123 
124  void operator()() const noexcept
125  {
126  if(auto node = weak_node.lock())
127  {
128  static constexpr const auto control_count
129  = avnd::control_input_introspection<Node>::size;
130  static constexpr const auto control_out_count
131  = avnd::control_output_introspection<Node>::size;
132  if constexpr(control_count > 0)
133  handle_controls(*node);
134 
135  if constexpr(control_out_count > 0)
136  handle_control_outs(*node);
137  }
138  }
139 };
140 }
Definition: score-plugin-avnd/Crousti/ProcessModel.hpp:77
Definition: Factories.hpp:19
Definition: ExecutorUpdateControlValueInUi.hpp:12
Definition: ExecutorUpdateControlValueInUi.hpp:47
Definition: ExecutorUpdateControlValueInUi.hpp:76