OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
ossia-pd.hpp
1#pragma once
2#include "ZeroconfMinuitListener.hpp"
3#include "ZeroconfOscqueryListener.hpp"
4
5#include <ossia/detail/safe_vec.hpp>
6#include <ossia/network/common/websocket_log_sink.hpp>
7#include <ossia/network/generic/generic_device.hpp>
8
9#include <ossia-pd/src/attribute.hpp>
10#include <ossia-pd/src/client.hpp>
11#include <ossia-pd/src/device.hpp>
12#include <ossia-pd/src/model.hpp>
13#include <ossia-pd/src/parameter.hpp>
14#include <ossia-pd/src/remote.hpp>
15#include <ossia-pd/src/view.hpp>
16
17extern "C" {
18#include <cicm_wrapper.h>
19}
20
21namespace ossia
22{
23struct websocket_threaded_connection;
24namespace pd
25{
26
27struct pd_log_sink final : public spdlog::sinks::sink
28{
29 void log(const spdlog::details::log_msg& msg) override
30 {
31 std::string s(msg.payload.data(), msg.payload.size());
32 switch(msg.level)
33 {
34 case spdlog::level::warn:
35 case spdlog::level::err: {
36 error("%s", s.c_str());
37 break;
38 }
39
40 default:
41 post("%s", s.c_str());
42 break;
43 }
44 }
45
46 void flush() override { }
47
48 void set_pattern(const std::string& pattern) override { }
49 void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override { }
50};
51
52extern "C" void setup_ossia0x2eassert(void);
53extern "C" void setup_ossia0x2eattribute(void);
54extern "C" void setup_ossia0x2eclient(void);
55extern "C" void setup_ossia0x2edevice(void);
56extern "C" void setup_ossia0x2eexplorer(void);
57extern "C" void setup_ossia0x2elogger(void);
58extern "C" void setup_ossia0x2emodel(void);
59extern "C" void setup_ossia0x2eparam(void);
60extern "C" void setup_ossia0x2eremote(void);
61extern "C" void setup_ossia0x2eview(void);
62
63class ossia_pd
64{
65public:
66 static ossia_pd& instance();
67 static ossia::net::generic_device* get_default_device()
68 {
69 return &instance().m_device;
70 }
71 static void register_nodes(void* x);
72 static void discover_network_devices(ossia_pd* x);
73
74 void set_log_level(t_symbol* log_sym)
75 {
76 std::vector<spdlog::string_view_t> vec = SPDLOG_LEVEL_NAMES;
77 auto it = std::find(vec.begin(), vec.end(), log_sym->s_name);
78 if(it != vec.end())
79 {
80 int level = it - vec.begin();
81 m_log_sink.get()->set_level(static_cast<spdlog::level::level_enum>(level));
82 }
83 else
84 {
85 error("Unknown log level : %s", log_sym->s_name);
86 }
87 }
88
89 static t_eclass* attribute_class;
90 static t_eclass* client_class;
91 static t_eclass* device_class;
92 static t_eclass* explorer_class;
93 static t_eclass* logger_class;
94 static t_eclass* model_class;
95 static t_eclass* param_class;
96 static t_eclass* remote_class;
97 static t_eclass* view_class;
98 static t_eclass* ossia_class;
99
100 static t_symbol* o_sym_attribute;
101 static t_symbol* o_sym_client;
102 static t_symbol* o_sym_device;
103 static t_symbol* o_sym_logger;
104 static t_symbol* o_sym_model;
105 static t_symbol* o_sym_param;
106 static t_symbol* o_sym_remote;
107 static t_symbol* o_sym_view;
108 static t_symbol* o_sym_ossia;
109 static t_symbol* o_sym_set;
110 static t_symbol* o_sym_address;
111
112 ossia::safe_vector<attribute*> attributes;
113 ossia::safe_vector<parameter*> parameters;
114 ossia::safe_vector<remote*> remotes;
115 ossia::safe_vector<model*> models;
116 ossia::safe_vector<view*> views;
117 ossia::safe_vector<device*> devices;
118 ossia::safe_vector<client*> clients;
119
120 ossia::safe_vector<t_select_clock*> select_clocks;
121
122 ossia::safe_set<attribute*> attribute_quarantine;
123 ossia::safe_set<model*> model_quarantine;
124 ossia::safe_set<view*> view_quarantine;
125 ossia::safe_set<parameter*> parameter_quarantine;
126 ossia::safe_set<remote*> remote_quarantine;
127
128 // this is used at loadbang to mark a patcher loaded
129 // and trigger its registration
130 struct root_descriptor
131 {
132 bool is_loadbanged{};
133 unsigned long count{}; // number of object under this root
134
135 unsigned long inc() { return ++count; }
136 unsigned long dec() { return --count; }
137 };
138
139 typedef std::map<t_canvas*, root_descriptor> RootMap;
140
141 RootMap m_root_patcher{};
142 t_clock* m_reg_clock{};
143 static t_clock* browse_clock;
144
145 bool m_testing{};
146
147 static ZeroconfOscqueryListener zeroconf_oscq_listener;
148 static ZeroconfMinuitListener zeroconf_minuit_listener;
149
150private:
151 ossia_pd(); // constructor
152 ~ossia_pd(); // destructor
153
154 ossia::net::local_protocol* m_localProtocol{};
155 ossia::net::generic_device m_device;
156 string_map<std::shared_ptr<ossia::websocket_threaded_connection>> m_connections;
157 std::shared_ptr<pd_log_sink> m_log_sink;
158};
159
160}
161} // namespace
A protocol used to expose a local application's data through multiple other protocols.
Definition local.hpp:22
Definition git_info.h:7