ExecutionSetup.hpp
1 #pragma once
2 #include <Process/Dataflow/Cable.hpp>
3 #include <Process/Dataflow/PortForward.hpp>
4 #include <Process/ExecutionContext.hpp>
5 
6 #include <score/tools/std/HashMap.hpp>
7 
8 #include <ossia/detail/flat_map.hpp>
9 #include <ossia/detail/small_vector.hpp>
10 
11 #include <QMetaObject>
12 
13 #include <nano_observer.hpp>
14 
15 namespace ossia
16 {
17 class time_process;
18 }
19 
20 namespace Process
21 {
22 class ProcessModel;
23 class ProcessModel;
24 class Cable;
25 }
26 
27 namespace State
28 {
29 struct AddressAccessor;
30 }
31 
32 namespace Execution
33 {
34 struct Transaction;
35 struct SCORE_LIB_PROCESS_EXPORT SetupContext final
36  : public QObject
37  , public Nano::Observer
38 {
39  explicit SetupContext(Context& other) noexcept;
40  ~SetupContext();
41  Context& context;
42  void register_node(
43  const Process::ProcessModel& proc, const std::shared_ptr<ossia::graph_node>& node);
44  void unregister_node(
45  const Process::ProcessModel& proc, const std::shared_ptr<ossia::graph_node>& node);
46  void register_node(
47  const Process::Inlets& inlets, const Process::Outlets& outlets,
48  const std::shared_ptr<ossia::graph_node>& node);
49  void unregister_node(
50  const Process::Inlets& inlets, const Process::Outlets& outlets,
51  const std::shared_ptr<ossia::graph_node>& node);
52  void unregister_node_soft(
53  const Process::Inlets& inlets, const Process::Outlets& outlets,
54  const std::shared_ptr<ossia::graph_node>& node, Transaction& vec);
55 
56  void set_destination(const State::AddressAccessor& address, const ossia::inlet_ptr&);
57  void set_destination(const State::AddressAccessor& address, const ossia::outlet_ptr&);
58 
59  void register_inlet(
60  Process::Inlet& inlet, const ossia::inlet_ptr& exec,
61  const std::shared_ptr<ossia::graph_node>& node);
62  void register_outlet(
63  Process::Outlet& outlet, const ossia::outlet_ptr& exec,
64  const std::shared_ptr<ossia::graph_node>& node);
65 
66  void unregister_inlet(
67  const Process::Inlet& inlet, const std::shared_ptr<ossia::graph_node>& node);
68  void unregister_outlet(
69  const Process::Outlet& outlet, const std::shared_ptr<ossia::graph_node>& node);
70 
71  // Deferred versions, stored in a vec
72  void register_node(
73  const Process::Inlets& inlets, const Process::Outlets& outlets,
74  const std::shared_ptr<ossia::graph_node>& node, Transaction& vec);
75  void unregister_node(
76  const Process::Inlets& inlets, const Process::Outlets& outlets,
77  const std::shared_ptr<ossia::graph_node>& node, Transaction& vec);
78  void register_node(
79  const Process::ProcessModel& proc, const std::shared_ptr<ossia::graph_node>& node,
80  Transaction& vec);
81  void unregister_node(
82  const Process::ProcessModel& proc, const std::shared_ptr<ossia::graph_node>& node,
83  Transaction& vec);
84 
85  void register_inlet(
86  Process::Inlet& inlet, const ossia::inlet_ptr& exec,
87  const std::shared_ptr<ossia::graph_node>& node, Transaction& vec);
88  void register_outlet(
89  Process::Outlet& outlet, const ossia::outlet_ptr& exec,
90  const std::shared_ptr<ossia::graph_node>& node, Transaction& vec);
91 
92  void unregister_inlet(
93  const Process::Inlet& inlet, const std::shared_ptr<ossia::graph_node>& node,
94  Transaction& vec);
95  void unregister_outlet(
96  const Process::Outlet& outlet, const std::shared_ptr<ossia::graph_node>& node,
97  Transaction& vec);
98 
99  void replace_node(
100  const std::shared_ptr<ossia::time_process>& process,
101  const std::shared_ptr<ossia::graph_node>& node, Transaction& commands);
102 
103  void on_cableCreated(Process::Cable& c);
104  void on_cableRemoved(const Process::Cable& c);
105  void connectCable(Process::Cable& cable);
106 
107  score::hash_map<Process::Outlet*, std::pair<ossia::node_ptr, ossia::outlet_ptr>>
108  outlets;
109  score::hash_map<Process::Inlet*, std::pair<ossia::node_ptr, ossia::inlet_ptr>> inlets;
110  score::hash_map<Id<Process::Cable>, std::shared_ptr<ossia::graph_edge>> m_cables;
111 
113  {
114  ossia::flat_map<Id<Process::Port>, QMetaObject::Connection> inlets;
115  ossia::flat_map<Id<Process::Port>, QMetaObject::Connection> outlets;
116  void clear() const noexcept
117  {
118  for(auto& con : inlets)
119  QObject::disconnect(con.second);
120  for(auto& con : outlets)
121  QObject::disconnect(con.second);
122  }
123  };
124 
125  score::hash_map<std::shared_ptr<ossia::graph_node>, RegisteredPorts>
126  runtime_connections;
127  score::hash_map<const ossia::graph_node*, const Process::ProcessModel*> proc_map;
128 
129 private:
130  template <typename Impl>
131  void register_node_impl(
132  const Process::Inlets& inlets, const Process::Outlets& outlets,
133  const std::shared_ptr<ossia::graph_node>& node, Impl&&);
134 
135  template <typename Impl>
136  void register_inlet_impl(
137  Process::Inlet& inlet, const ossia::inlet_ptr& exec,
138  const std::shared_ptr<ossia::graph_node>& node, Impl&&);
139 
140  template <typename Impl>
141  void register_outlet_impl(
142  Process::Outlet& outlet, const ossia::outlet_ptr& exec,
143  const std::shared_ptr<ossia::graph_node>& node, Impl&&);
144 };
145 }
Definition: Cable.hpp:38
Definition: Port.hpp:177
Definition: Port.hpp:273
The Process class.
Definition: score-lib-process/Process/Process.hpp:61
Components used for the execution of a score.
Definition: ProcessComponent.cpp:12
Base classes and tools to implement processes and layers.
Definition: JSONVisitor.hpp:1324
Utilities for OSSIA data structures.
Definition: DeviceInterface.hpp:33
Definition: ExecutionContext.hpp:76
Definition: ExecutionSetup.hpp:113
Definition: ExecutionSetup.hpp:38
Definition: ExecutionTransaction.hpp:18
Definition: PortForward.hpp:23
Definition: PortForward.hpp:27
Definition: Address.hpp:108