OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
execution_state.hpp
1#pragma once
2#include <ossia/dataflow/dataflow_fwd.hpp>
3#include <ossia/dataflow/graph/graph_interface.hpp>
4#include <ossia/dataflow/value_vector.hpp>
5#include <ossia/detail/lockfree_queue.hpp>
6#include <ossia/detail/ptr_set.hpp>
7#include <ossia/network/base/device.hpp>
8#if defined(OSSIA_SMALL_VECTOR)
9#include <libremidi/message.hpp>
10#else
11namespace libremidi
12{
13struct message;
14}
15#endif
16namespace ossia
17{
18namespace net::midi
19{
20class midi_protocol;
21class midi_parameter;
22}
23class state;
24class message_queue;
25class audio_parameter;
26struct typed_value;
27struct timed_value;
28struct local_pull_visitor;
29struct global_pull_visitor;
30struct state_exec_visitor;
31struct execution_state_policy;
32struct OSSIA_EXPORT execution_state : public Nano::Observer
33{
34 execution_state();
35 execution_state(const execution_state&) = delete;
36 execution_state(execution_state&&) = delete;
37 execution_state& operator=(const execution_state&) = delete;
38 execution_state& operator=(execution_state&&) = delete;
39 ~execution_state();
40
41 void set_policy(const tick_setup_options&);
42
44 void register_device(ossia::net::device_base* d);
45 void unregister_device(net::device_base* d);
46
47 const ossia::small_vector<ossia::net::device_base*, 4>& edit_devices() const noexcept
48 {
49 return m_devices_edit;
50 }
51
53 void register_port(const ossia::inlet& port);
54 void register_port(const ossia::outlet& port);
55 void unregister_port(const ossia::inlet& port);
56 void unregister_port(const ossia::outlet& port);
57
58 const ossia::small_vector<ossia::net::device_base*, 4>& exec_devices() const noexcept
59 {
60 return m_devices_exec;
61 }
62
63 ossia::net::node_base* find_node(std::string_view name) const noexcept
64 {
65 for(auto dev : m_devices_exec)
66 {
67 if(auto res = ossia::net::find_node(dev->get_root_node(), name))
68 return res;
69 }
70 return nullptr;
71 }
72
73 template <typename T>
74 auto get_value_or(std::string_view v, const T& val) noexcept
75 {
76 if(auto node = find_node(v))
77 return ossia::convert<T>(node->get_parameter()->value());
78 return val;
79 }
80
81 void begin_tick();
82
83 void clear_devices();
84 void reset();
85
86 void advance_tick(std::size_t);
87 void apply_device_changes();
88
89 void find_and_copy(ossia::net::parameter_base& addr, inlet& in);
90 void copy_from_global(ossia::net::parameter_base& addr, inlet& in);
91 void copy_from_global_node(ossia::net::node_base& addr, inlet& in);
92
93 void insert(ossia::net::parameter_base& dest, const ossia::value_port& v);
94 void insert(ossia::audio_parameter& dest, const audio_port& v);
95 void insert(ossia::net::midi::midi_parameter& dest, const midi_port& v);
96
97 void commit();
98
99 bool in_local_scope(ossia::net::parameter_base& other) const;
100
101 int sampleRate{44100};
102 int bufferSize{64};
103 double modelToSamplesRatio{1.};
104 double samplesToModelRatio{1.};
105 int64_t samples_since_start{};
106 double start_date{}; // in ns, for vst
107 double cur_date{};
108
109#if !defined(OSSIA_TESTING)
110private:
111#endif
112 void init_midi_timings();
113 void get_new_values();
114
115 void register_parameter(ossia::net::parameter_base& p);
116 void unregister_parameter(ossia::net::parameter_base& p);
117 void register_midi_parameter(net::midi::midi_protocol& p);
118 void unregister_midi_parameter(net::midi::midi_protocol& p);
119 ossia::small_vector<ossia::net::device_base*, 4> m_devices_edit;
120 ossia::small_vector<ossia::net::device_base*, 4> m_devices_exec;
121 struct device_operation
122 {
123 enum
124 {
125 REGISTER,
126 UNREGISTER
127 } operation{};
128 ossia::net::device_base* device{};
129 };
130 ossia::spsc_queue<device_operation> m_device_change_queue;
131
132 std::list<message_queue> m_valueQueues;
133
134 ossia::ptr_map<ossia::net::parameter_base*, value_vector<ossia::value>>
135 m_receivedValues;
136
137 struct received_midi_state
138 {
139 value_vector<libremidi::ump> messages;
140 int64_t last_buffer_start{};
141 int64_t current_buffer_start{};
142 int count{};
143 };
144
145 ossia::ptr_map<ossia::net::midi::midi_protocol*, received_midi_state> m_receivedMidi;
146
147 friend struct local_pull_visitor;
148 friend struct global_pull_visitor;
149 friend struct global_pull_node_visitor;
150 friend struct state_exec_visitor;
151
152 std::unique_ptr<execution_state_policy> m_policy;
153};
154}
Root of a device tree.
Definition ossia/network/base/device.hpp:58
The node_base class.
Definition node.hpp:48
The parameter_base class.
Definition ossia/network/base/parameter.hpp:48
Definition git_info.h:7