18class Protocol final :
public ossia::net::protocol_base
21 explicit Protocol(
const ossia::net::network_context_ptr& ctx)
22 : ossia::net::protocol_base{flags{}}
24 if_possible(this->impl.io_context = &ctx->context);
25 if_possible(this->impl.init());
28 template <
bool Input,
typename Field>
29 ossia::net::parameter_base* create_node(ossia::net::node_base& root, Field& f)
31 ossia::net::node_base* node{};
32 if constexpr(avnd::has_path<Field>)
34 static constexpr auto name = avnd::get_path<Field>();
35 node = &ossia::net::create_node(root, name);
39 static constexpr auto name = avnd::get_name<Field>();
42 node = &ossia::net::create_node(root, fmt::format(
"/in/{}", name));
46 node = &ossia::net::create_node(root, fmt::format(
"/out/{}", name));
50 using val_t = std::decay_t<
decltype(f.value)>;
51 return node->create_parameter(oscr::type_for_arg<val_t>());
54 void set_field_value(
auto& f,
const ossia::value& v)
56 oscr::from_ossia_value(f, v, f.value);
57 if_possible(f.update(impl));
61 void set_device(ossia::net::device_base& dev)
override
64 auto& root = dev.get_root_node();
65 inputs.resize(avnd::input_introspection<Node>::size);
66 avnd::input_introspection<Node>::for_all_n(
67 avnd::get_inputs(impl), [&]<std::size_t I>(
auto& f, avnd::field_index<I>) {
68 inputs[I] = create_node<true>(root, f);
69 inputs[I]->add_callback(
70 [&f,
this](
const ossia::value& v) { set_field_value(f, v); });
73 outputs.resize(avnd::output_introspection<Node>::size);
74 avnd::output_introspection<Node>::for_all_n(
75 avnd::get_outputs(impl), [&]<std::size_t I>(
auto& f, avnd::field_index<I>) {
76 outputs[I] = create_node<false>(root, f);
80 bool push(
const ossia::net::parameter_base& param,
const ossia::value& v)
override
83 for(
int i = 0; i < std::ssize(inputs); i++)
88 avnd::input_introspection<Node>::for_nth(
89 avnd::get_inputs(impl), i,
90 [
this, &v](
auto& f) { this->set_field_value(f, v); });
97 void process_on_input()
101 avnd::output_introspection<Node>::for_all_n(
102 avnd::get_outputs(impl), [&]<std::size_t I>(
auto& f, avnd::field_index<I>) {
103 SCORE_ASSERT(outputs[I]);
104 outputs[I]->set_value(oscr::to_ossia_value(f, f.value));
108 bool pull(ossia::net::parameter_base&)
override {
return false; }
109 bool push_raw(
const ossia::net::full_parameter_data&)
override {
return false; }
110 bool observe(ossia::net::parameter_base&,
bool)
override {
return false; }
111 bool update(ossia::net::node_base& node_base)
override {
return false; }
114 std::vector<ossia::net::parameter_base*> inputs;
115 std::vector<ossia::net::parameter_base*> outputs;
125 : OwningDeviceInterface{settings}
128 m_capas.canRefreshTree =
true;
129 m_capas.canAddNode =
false;
130 m_capas.canRemoveNode =
false;
131 m_capas.canRenameNode =
false;
132 m_capas.canSetProperties =
false;
133 m_capas.canSerialize =
false;
138 bool reconnect()
override
142 auto protocol = std::make_unique<Protocol<Node_T>>(this->m_ctx.networkContext());
143 auto dev = std::make_unique<ossia::net::generic_device>(
144 std::move(protocol), settings().name.toStdString());
146 m_dev = std::move(dev);
147 deviceChanged(
nullptr, m_dev.get());
151 void disconnect()
override { OwningDeviceInterface::disconnect(); }
154 const Explorer::DeviceDocumentPlugin& m_ctx;
Used to access all the application-wide state and structures.
Definition ApplicationContext.hpp:24
Definition DocumentContext.hpp:18