2#include <ossia/detail/fmt.hpp>
4#include <ossia/network/base/device.hpp>
5#include <ossia/network/base/listening.hpp>
6#include <ossia/network/base/message_origin_identifier.hpp>
7#include <ossia/network/base/parameter.hpp>
8#include <ossia/network/common/network_logger.hpp>
9#include <ossia/network/osc/detail/osc.hpp>
11#include <oscpack/osc/OscPrintReceivedElements.h>
12#include <oscpack/osc/OscReceivedElements.h>
14#if defined(OSSIA_HAS_FMT)
18struct formatter<oscpack::ReceivedMessage>
20 template <
typename ParseContext>
21 constexpr auto parse(ParseContext& ctx)
26 template <
typename FormatContext>
27 auto format(
const oscpack::ReceivedMessage& m, FormatContext& ctx)
const
30 out = fmt::format_to(out,
"{}", m.AddressPattern());
31 if(m.ArgumentCount() > 0)
33 out = fmt::format_to(out,
": ");
34 auto buf = fmt::basic_memory_buffer<char>();
35 for(
auto it = m.ArgumentsBegin(); it != m.ArgumentsEnd(); ++it)
37 using namespace detail;
40 formatbuf<std::basic_streambuf<char>> format_buf{buf};
41 std::basic_ostream<char> output{&format_buf};
44 out = fmt::format_to(out,
"{} ", std::string_view{buf.data(), buf.size()});
56struct osc_message_applier
58 message_origin_identifier id;
59 const oscpack::ReceivedMessage& m;
60 void on_listened_value(
64 if(
auto v = net::get_filtered_value(the_addr, m); v.valid())
66 dev.apply_incoming_message(
id, the_addr, std::move(v));
69 if(
logger.inbound_listened_logger)
70 logger.inbound_listened_logger->info(
"[input] {}", m);
75 if(
auto v = net::get_filtered_value(the_addr, m); v.valid())
77 dev.apply_incoming_message(
id, the_addr, std::move(v));
83 if(
auto v = net::get_filtered_value(the_addr, m); v.valid())
85 dev.apply_incoming_message_quiet(
id, the_addr, std::move(v));
91 dev.on_unhandled_message(
93 net::osc_utilities::create_any(
94 m.ArgumentsBegin(), m.ArgumentsEnd(), m.ArgumentCount()));
97 void log(network_logger&
logger)
100 logger.inbound_logger->info(
"[input] {}", m);
104template <
bool SilentUpdate,
typename F>
105void on_input_message(
106 std::string_view addr_txt, F&& f,
const ossia::net::listened_parameters& listening,
109 auto addr = listening.find(addr_txt);
113 f.on_listened_value(**addr, dev,
logger);
118 if(
auto n = find_node(dev.get_root_node(), addr_txt))
120 if(
auto base_addr = n->get_parameter())
122 if constexpr(!SilentUpdate)
123 f.on_value(*base_addr, dev);
125 f.on_value_quiet(*base_addr, dev);
131 auto nodes = find_nodes(dev.get_root_node(), addr_txt);
134 if(
auto addr = n->get_parameter())
136 if(!SilentUpdate || listening.find(n->osc_address()))
137 f.on_value(*addr, dev);
139 f.on_value_quiet(*addr, dev);
Root of a device tree.
Definition ossia/network/base/device.hpp:58
The parameter_base class.
Definition ossia/network/base/parameter.hpp:48
spdlog::logger & logger() noexcept
Where the errors will be logged. Default is stderr.
Definition context.cpp:118