16 halp_meta(name,
"Teleplot")
17 halp_meta(author,
"ossia team")
18 halp_meta(category,
"Monitoring")
19 halp_meta(description,
"Forwards a set of device explorer messages to ")
20 halp_meta(c_name,
"avnd_teleplot")
21 halp_meta(manual_url,
"https://ossia.io/score-docs/processes/teleplot.html")
22 halp_meta(uuid,
"e1d5b9a0-4df9-4281-87a6-9f427dfb6e31")
25 boost::asio::io_context* io_context{};
30 struct : halp::lineedit<
"Host",
"">
32 void update(
Teleplot& self) { self.update(); }
42 std::pair<std::string, uint16_t> resolve_ip(
const std::string& host)
46 std::string m_queryPort;
47 auto m_queryHost = host;
48 auto port_idx = m_queryHost.find_last_of(
':');
49 if(port_idx != std::string::npos)
51 m_queryPort = m_queryHost.substr(port_idx + 1);
52 m_queryHost = m_queryHost.substr(0, port_idx);
57 boost::asio::io_context io_service;
58 boost::asio::ip::udp::resolver resolver(io_service);
60 auto results = resolver.resolve(
61 boost::asio::ip::udp::v4(), m_queryHost, m_queryPort,
62 boost::asio::ip::resolver_base::numeric_service);
66 auto addr = results.begin()->endpoint().address().to_string();
68 return {addr, std::stoi(m_queryPort)};
75 catch(
const std::exception& e)
86 for(
auto& [param, cb] : params)
88 param->remove_callback(cb);
101 auto [ip, port] = resolve_ip(inputs.host.value);
102 if(!ip.empty() && port > 1)
104 socket = std::make_shared<ossia::net::udp_send_socket>(
105 ossia::net::outbound_socket_configuration{.host = ip, .port = port},
112 for(
auto nodes : this->roots)
114 if(
auto p = nodes->get_parameter(); p && !params.contains(p))
116 auto it = p->add_callback(
117 [p, socket = socket](
const ossia::value& v) { push(*socket, *p, v); });
118 params.emplace(p, it);
125 ossia::net::udp_send_socket& socket,
const ossia::net::parameter_base& param,
126 const ossia::value& v)
128 using clk = std::chrono::system_clock;
130 thread_local fmt::memory_buffer buf;
136 const std::string& addr;
137 int64_t t = std::chrono::duration_cast<std::chrono::milliseconds>(
138 clk::now().time_since_epoch())
141 void operator()(ossia::impulse v)
143 fmt::format_to(fmt::appender(buf),
"{}:{}:1\n", addr, t);
145 void operator()(
int v)
147 fmt::format_to(fmt::appender(buf),
"{}:{}:{}\n", addr, t, v);
149 void operator()(
float v)
151 fmt::format_to(fmt::appender(buf),
"{}:{}:{}\n", addr, t, v);
153 void operator()(std::string v)
155 fmt::format_to(fmt::appender(buf),
"{}:{}:{}\n", addr, t, v);
157 void operator()(
bool v)
159 fmt::format_to(fmt::appender(buf),
"{}:{}:{}\n", addr, t, v ? 1 : 0);
161 void operator()(ossia::vec2f v)
164 fmt::appender(buf),
"{}.x:{}:{}\n{}.y:{}:{}\n", addr, t, v[0], addr, t,
167 void operator()(ossia::vec3f v)
170 fmt::appender(buf),
"{}.x:{}:{}\n{}.y:{}:{}\n{}.z:{}:{}\n", addr, t, v[0],
171 addr, t, v[1], addr, t, v[2]);
173 void operator()(ossia::vec4f v)
176 fmt::appender(buf),
"{}.x:{}:{}\n{}.y:{}:{}\n{}.z:{}:{}\n{}.w:{}:{}\n", addr,
177 t, v[0], addr, t, v[1], addr, t, v[2], addr, t, v[3]);
179 void operator()(
const std::vector<ossia::value>& v)
186 fmt::appender(buf),
"{}[{}]:{}:{}\n", addr, i, t,
187 ossia::convert<double>(val));
191 void operator()(
const ossia::value_map_type& v)
193 for(
auto& [k, val] : v)
197 fmt::appender(buf),
"{}[{}]:{}:{}\n", addr, k, t,
198 ossia::convert<double>(val));
201 void operator()() { }
203 } vis{.addr = param.get_node().osc_address()};
206 socket.write(buf.begin(), buf.size());
213 socket = std::make_shared<ossia::net::udp_send_socket>(
214 ossia::net::outbound_socket_configuration{.host =
"127.0.0.1", .port = 47269},
224 for(
auto nodes : this->roots)
226 if(
auto p = nodes->get_parameter(); p && !params.contains(p))
228 auto it = p->add_callback(
229 [p, socket = socket](
const ossia::value& v) { push(*socket, *p, v); });
230 params.emplace(p, it);
235 for(
auto it = params.begin(); it != params.end();)
237 if(!ossia::contains(this->roots, &(it->first)->get_node()))
239 it->first->remove_callback(it->second);
240 it = params.erase(it);
249 boost::container::flat_map<
250 ossia::net::parameter_base*,
251 ossia::callback_container<ossia::value_callback>::iterator>
253 std::shared_ptr<ossia::net::udp_send_socket> socket;