2 #include <State/Widgets/AddressFragmentLineEdit.hpp>
4 #include <Explorer/DefaultProtocolFactory.hpp>
6 #include <Crousti/Concepts.hpp>
8 #include <ossia/network/base/protocol.hpp>
9 #include <ossia/network/generic/generic_device.hpp>
11 #include <QFormLayout>
13 #include <avnd/concepts/generic.hpp>
17 template <
typename Node>
18 class 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;
118 template <
typename Node_T>
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;
157 template <
typename Node>
165 m_deviceNameEdit->setText(
"SpatGRIS");
166 auto layout =
new QFormLayout;
167 layout->addRow(tr(
"Name"), m_deviceNameEdit);
177 s.name = m_deviceNameEdit->text();
178 s.protocol = oscr::uuid_from_string<Node>();
184 m_deviceNameEdit->setText(settings.name);
188 QLineEdit* m_deviceNameEdit{};
191 template <
typename Node>
196 return oscr::uuid_from_string<Node>();
199 QString prettyName()
const noexcept
override
201 return QString::fromUtf8(avnd::get_name<Node>().data());
203 QString category()
const noexcept
override {
return StandardCategories::software; }
204 Device::DeviceEnumerators
212 const Explorer::DeviceDocumentPlugin& plugin,
222 s.protocol = concreteKey();
224 s.deviceSpecificSettings = QVariant{};
236 QVariant makeProtocolSpecificSettings(
const VisitorVariant& visitor)
const override
241 void serializeProtocolSpecificSettings(
242 const QVariant& data,
const VisitorVariant& visitor)
const override
246 bool checkCompatibility(
254 template <
typename... Nodes>
255 static void instantiate_device(
259 if(key == Device::ProtocolFactory::static_interfaceKey())
Definition: DeviceInterface.hpp:66
Definition: DeviceInterface.hpp:185
Definition: ProtocolFactoryInterface.hpp:47
Definition: DefaultProtocolFactory.hpp:10
Definition: AddressFragmentLineEdit.hpp:9
Definition: AvndDevice.hpp:120
Definition: AvndDevice.hpp:193
Definition: AvndDevice.hpp:19
Definition: Factories.hpp:19
Definition: DeviceSettings.hpp:20
The VisitorVariant struct.
Definition: VisitorInterface.hpp:26
Used to access all the application-wide state and structures.
Definition: ApplicationContext.hpp:24
Definition: DocumentContext.hpp:18