AddressSettings.hpp
1 #pragma once
2 #include <State/Domain.hpp>
3 #include <State/Message.hpp>
4 #include <State/Unit.hpp>
5 
6 #include <Device/Address/ClipMode.hpp>
7 #include <Device/Address/IOType.hpp>
8 
9 #include <score/tools/Metadata.hpp>
10 
11 #include <ossia/detail/any_map.hpp>
12 //#include <ossia/network/base/node_attributes.hpp>
13 #include <ossia/network/common/parameter_properties.hpp>
14 
15 #include <QString>
16 
17 #include <score_lib_device_export.h>
18 
19 namespace Device
20 {
21 
22 using RepetitionFilter = bool;
23 struct SCORE_LIB_DEVICE_EXPORT AddressSettingsCommon
24 {
25  AddressSettingsCommon() noexcept;
28  AddressSettingsCommon& operator=(const AddressSettingsCommon&) noexcept;
29  AddressSettingsCommon& operator=(AddressSettingsCommon&&) noexcept;
30  ~AddressSettingsCommon() noexcept;
31 
32  ossia::value value;
33  State::Domain domain;
34 
35  State::Unit unit;
36 
37  std::optional<ossia::access_mode> ioType;
38  ossia::bounding_mode clipMode{};
39  ossia::repetition_filter repetitionFilter{};
40 
41  ossia::extended_attributes extendedAttributes;
42 
43  operator const ossia::extended_attributes&() const { return extendedAttributes; }
44  operator ossia::extended_attributes&() { return extendedAttributes; }
45 };
46 
47 // this one has only the name of the current node (e.g. 'a' for dev:/azazd/a)
48 struct SCORE_LIB_DEVICE_EXPORT AddressSettings : public Device::AddressSettingsCommon
49 {
50  AddressSettings() noexcept;
51  AddressSettings(const AddressSettings&) noexcept;
52  AddressSettings(AddressSettings&&) noexcept;
53  AddressSettings& operator=(const AddressSettings&) noexcept;
54  AddressSettings& operator=(AddressSettings&&) noexcept;
55  ~AddressSettings() noexcept;
56 
57  QString name;
58 };
59 
60 // This one has the whole path of the node in address
61 struct SCORE_LIB_DEVICE_EXPORT FullAddressSettings : public Device::AddressSettingsCommon
62 {
63  FullAddressSettings() noexcept;
66  FullAddressSettings& operator=(const FullAddressSettings&) noexcept;
67  FullAddressSettings& operator=(FullAddressSettings&&) noexcept;
68  ~FullAddressSettings() noexcept;
69 
70  // Maybe we should just use FullAddressSettings behind a flyweight
71  // pattern everywhere... (see mnmlstc/flyweight)
72  struct as_parent;
73  struct as_child;
74  State::Address address;
75 
76  template <typename T>
77  SCORE_LIB_DEVICE_EXPORT static FullAddressSettings
78  make(const Device::AddressSettings& other, const State::Address& addr) noexcept;
79  template <typename T>
80  static FullAddressSettings
81  make(const Device::AddressSettings& other, const State::AddressAccessor& addr) noexcept
82  {
83  return make<T>(other, addr.address);
84  }
85 
86  static FullAddressSettings make(const State::Message& mess) noexcept;
87 
88  // Specializations are in FullAddressSettings.cpp
89 };
90 
91 SCORE_LIB_DEVICE_EXPORT bool operator==(
93  const Device::AddressSettingsCommon& rhs) noexcept;
94 
95 inline bool operator!=(
97  const Device::AddressSettingsCommon& rhs) noexcept
98 {
99  return !(lhs == rhs);
100 }
101 inline bool operator==(
102  const Device::AddressSettings& lhs, const Device::AddressSettings& rhs) noexcept
103 {
104  return static_cast<const Device::AddressSettingsCommon&>(lhs)
105  == static_cast<const Device::AddressSettingsCommon&>(rhs)
106  && lhs.name == rhs.name;
107 }
108 
109 inline bool operator!=(
110  const Device::AddressSettings& lhs, const Device::AddressSettings& rhs) noexcept
111 {
112  return !(lhs == rhs);
113 }
114 inline bool operator==(
115  const Device::FullAddressSettings& lhs,
116  const Device::FullAddressSettings& rhs) noexcept
117 {
118  return static_cast<const Device::AddressSettingsCommon&>(lhs)
119  == static_cast<const Device::AddressSettingsCommon&>(rhs)
120  && lhs.address == rhs.address;
121 }
122 
123 inline bool operator!=(
124  const Device::FullAddressSettings& lhs,
125  const Device::FullAddressSettings& rhs) noexcept
126 {
127  return !(lhs == rhs);
128 }
129 
130 struct SCORE_LIB_DEVICE_EXPORT FullAddressAccessorSettings
131 {
132  FullAddressAccessorSettings() noexcept;
135  FullAddressAccessorSettings& operator=(const FullAddressAccessorSettings&) noexcept;
137  ~FullAddressAccessorSettings() noexcept;
138 
140  const State::AddressAccessor& addr, const AddressSettingsCommon& f) noexcept;
141 
142  explicit FullAddressAccessorSettings(FullAddressSettings&& f) noexcept;
143 
145  State::AddressAccessor&& addr, AddressSettingsCommon&& f) noexcept;
146 
148  const State::AddressAccessor& addr, const ossia::value& min,
149  const ossia::value& max) noexcept;
150 
151  ossia::value value;
152  State::Domain domain;
153 
154  std::optional<ossia::access_mode> ioType;
155  ossia::bounding_mode clipMode{};
156  ossia::repetition_filter repetitionFilter{};
157 
158  ossia::any_map extendedAttributes;
159 
160  State::AddressAccessor address;
161 };
162 }
163 
164 // Important: keep in sync with strings.Address / strings.Device in score::Strings
165 // as it is used with a manual switch in DeviceNodeSerialization and with the variant-based
166 // switch in DeviceDocumentPluginSerialization (the node.impl() case).
167 JSON_METADATA(Device::AddressSettings, "Address")
168 
169 SCORE_SERIALIZE_DATASTREAM_DECLARE(SCORE_LIB_DEVICE_EXPORT, Device::AddressSettings);
170 SCORE_SERIALIZE_DATASTREAM_DECLARE(SCORE_LIB_DEVICE_EXPORT, Device::FullAddressSettings);
171 SCORE_SERIALIZE_DATASTREAM_DECLARE(
172  SCORE_LIB_DEVICE_EXPORT, Device::FullAddressAccessorSettings);
173 
174 Q_DECLARE_METATYPE(Device::AddressSettings)
175 Q_DECLARE_METATYPE(Device::FullAddressSettings)
176 Q_DECLARE_METATYPE(Device::FullAddressAccessorSettings)
177 
178 W_REGISTER_ARGTYPE(Device::AddressSettings)
179 W_REGISTER_ARGTYPE(Device::FullAddressSettings)
180 W_REGISTER_ARGTYPE(Device::FullAddressAccessorSettings)
Manipulation of Devices from Qt.
Definition: AddressSettings.cpp:14
Definition: AddressSettings.hpp:24
Definition: AddressSettings.hpp:49
Definition: AddressSettings.hpp:131
Definition: AddressSettings.hpp:62
Definition: Address.hpp:108
The Address struct.
Definition: Address.hpp:58
Definition: Domain.hpp:17
The Message struct.
Definition: Message.hpp:15
Definition: Unit.hpp:18