OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
libmapper_protocol.hpp
1#pragma once
2
3#include <ossia/detail/hash_map.hpp>
4#include <ossia/detail/variant.hpp>
5#include <ossia/network/base/protocol.hpp>
6#include <ossia/network/common/complex_type.hpp>
7#include <ossia/network/common/device_parameter.hpp>
8#include <ossia/network/domain/domain.hpp>
9#include <ossia/network/oscquery/oscquery_server.hpp>
10
11#include <concurrentqueue.h>
12
13#include <vector>
14
15typedef void* mpr_graph;
16typedef void* mpr_device;
17typedef void* mpr_signal;
18typedef void* mpr_link;
19typedef void* mpr_map;
20typedef void* mpr_slot;
21typedef void* mpr_network;
22typedef void* mpr_database;
23typedef void* mpr_queue;
24typedef int mpr_signal_group;
25
26namespace ossia::net
27{
28
29class OSSIA_EXPORT libmapper_server_protocol final : public ossia::net::protocol_base
30{
31public:
32 libmapper_server_protocol();
33 libmapper_server_protocol(const libmapper_server_protocol&) = delete;
34 libmapper_server_protocol(libmapper_server_protocol&&) = delete;
35 libmapper_server_protocol& operator=(const libmapper_server_protocol&) = delete;
36 libmapper_server_protocol& operator=(libmapper_server_protocol&&) = delete;
37 ~libmapper_server_protocol() override;
38
39 void set_device(ossia::net::device_base& dev) override;
40
41 bool pull(ossia::net::parameter_base& param) override;
42 bool push(const ossia::net::parameter_base& param, const ossia::value& v) override;
43 bool push_raw(const ossia::net::full_parameter_data&) override;
44 bool observe(ossia::net::parameter_base& param, bool enable) override;
45
46 bool update(ossia::net::node_base&) override;
47 void stop() override;
48
49private:
50 template <typename OssiaType, typename LibmapperType>
51 void create_1d_parameter(const parameter_base& p);
52 template <std::size_t N>
53 void create_array_parameter(const parameter_base& p);
54 void create_vector_parameter(const parameter_base& p);
55 friend struct libmapper_create_param;
56 friend struct libmapper_apply_control;
57
58 void on_nodeCreated(const ossia::net::node_base&);
59 void on_nodeRemoved(const ossia::net::node_base&);
60 void on_parameterCreated(const ossia::net::parameter_base&);
61 void on_parameterRemoved(const ossia::net::parameter_base&);
62 void on_parameterChanged(const ossia::net::parameter_base&);
63 void on_attributeChanged(const ossia::net::node_base&, std::string_view attr);
64 void on_nodeRenamed(const ossia::net::node_base& n, std::string oldname);
65
66 void execThread();
67
68 ossia::net::device_base* m_device{};
69
70 mpr_device m_mapper_dev{};
71
72 ossia::hash_map<const ossia::net::parameter_base*, mpr_signal> m_inputMap;
73 ossia::hash_map<const ossia::net::parameter_base*, mpr_signal> m_outputMap;
74
75 std::thread m_thread;
76 std::atomic_bool m_running{};
77
78 struct Message
79 {
80 mpr_signal sig;
81 ossia::value value;
82 };
83
84 moodycamel::ConcurrentQueue<Message> m_sendQueue;
85
86 struct CreateSignal
87 {
88 const ossia::net::parameter_base* param;
89 };
90 struct RemoveSignal
91 {
92 mpr_signal sig;
93 };
94 using ControlMessage = ossia::variant<CreateSignal, RemoveSignal>;
95 moodycamel::ConcurrentQueue<ControlMessage> m_ctlQueue;
96
97 std::atomic_int m_editSemaphore{};
98};
99
100class OSSIA_EXPORT libmapper_client_protocol final : public ossia::net::protocol_base
101{
102public:
103 explicit libmapper_client_protocol(std::string device);
104 libmapper_client_protocol(const libmapper_client_protocol&) = delete;
105 libmapper_client_protocol(libmapper_client_protocol&&) = delete;
106 libmapper_client_protocol& operator=(const libmapper_client_protocol&) = delete;
107 libmapper_client_protocol& operator=(libmapper_client_protocol&&) = delete;
108 ~libmapper_client_protocol() override;
109
110 void set_device(ossia::net::device_base& dev) override;
111
112 bool pull(ossia::net::parameter_base& param) override;
113 bool push(const ossia::net::parameter_base& param, const ossia::value& v) override;
114 bool push_raw(const ossia::net::full_parameter_data&) override;
115 bool observe(ossia::net::parameter_base& param, bool enable) override;
116
117 bool update();
118 bool update(ossia::net::node_base&) override;
119 void stop() override;
120
121 void poll(int);
122
123private:
124 ossia::net::device_base* m_device{};
125
126 std::string m_mapper_dev_name;
127
128 mpr_graph m_db{};
129 mpr_device m_mapper_dev{};
130
131 ossia::hash_map<const ossia::net::parameter_base*, mpr_signal> m_inputMap;
132 ossia::hash_map<const ossia::net::parameter_base*, mpr_signal> m_outputMap;
133};
134}
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
The protocol_base class.
Definition protocol.hpp:40
The value class.
Definition value.hpp:173
Full information about a parameter.
Definition parameter_data.hpp:61