Loading...
Searching...
No Matches
plugins/score-plugin-avnd/Crousti/Metadata.hpp
1#pragma once
2#include <Process/ProcessMetadata.hpp>
3
4#include <Crousti/Concepts.hpp>
5#include <Crousti/SceneConcepts.hpp>
6
7#include <QString>
8
9#include <avnd/binding/ossia/metadatas.hpp>
10#include <avnd/binding/ossia/port_base.hpp>
11#include <avnd/concepts/all.hpp>
12#include <avnd/introspection/input.hpp>
13#include <avnd/introspection/output.hpp>
14#include <avnd/wrappers/metadatas.hpp>
15
16#include <string_view>
17
18namespace oscr
19{
20template <typename Info>
21class ProcessModel;
22}
24namespace oscr
25{
26template <typename Info>
27class ProcessModel;
28}
29template <typename Info>
30 requires avnd::has_name<Info>
31struct Metadata<PrettyName_k, oscr::ProcessModel<Info>>
32{
33 static constexpr const char* get() noexcept { return avnd::get_name<Info>().data(); }
34};
35template <typename Info>
36 requires avnd::has_category<Info>
37struct Metadata<Category_k, oscr::ProcessModel<Info>>
38{
39 static constexpr const char* get() noexcept
40 {
41 return avnd::get_category<Info>().data();
42 }
43};
44template <typename Info>
45 requires(!avnd::has_category<Info>)
47{
48 static constexpr const char* get() noexcept { return ""; }
49};
50
51template <typename Info>
52struct Metadata<Tags_k, oscr::ProcessModel<Info>>
53{
54 static QStringList get() noexcept
55 {
56 QStringList lst;
57 for(std::string_view tag : avnd::get_tags<Info>())
58 lst.push_back(QString::fromUtf8(tag.data(), tag.size()));
59 return lst;
60 }
61};
62
63template <typename T>
64concept has_kind = requires { T::kind(); };
65
66template <typename T>
67auto get_kind()
68{
69 if constexpr(has_kind<T>)
70 return T::kind();
71 else
72 return Process::ProcessCategory::Other;
73}
74
76{
77 std::vector<Process::PortType> port;
78 void audio() { port.push_back(Process::PortType::Audio); }
79 void midi() { port.push_back(Process::PortType::Midi); }
80 void value() { port.push_back(Process::PortType::Message); }
81 void buffer() { port.push_back(Process::PortType::Texture); }
82 void texture() { port.push_back(Process::PortType::Texture); }
83 void geometry() { port.push_back(Process::PortType::Geometry); }
84
85 template <std::size_t N, oscr::ossia_value_port Port>
86 void operator()(const avnd::field_reflection<N, Port>)
87 {
88 this->value();
89 }
90 template <std::size_t N, oscr::ossia_audio_port Port>
91 void operator()(const avnd::field_reflection<N, Port>)
92 {
93 this->audio();
94 }
95
96 template <std::size_t N, oscr::ossia_midi_port Port>
97 void operator()(const avnd::field_reflection<N, Port>)
98 {
99 this->midi();
100 }
101
102 template <std::size_t N, avnd::dynamic_ports_port Port>
103 void operator()(const avnd::field_reflection<N, Port>)
104 {
105 using port_type = typename decltype(std::declval<Port>().ports)::value_type;
106 (*this)(avnd::field_reflection<std::size_t{0}, port_type>{});
107 }
108
109 template <std::size_t N, avnd::audio_port Port>
110 void operator()(const avnd::field_reflection<N, Port>)
111 {
112 this->audio();
113 }
114
115 template <std::size_t N, avnd::midi_port Port>
116 void operator()(const avnd::field_reflection<N, Port>)
117 {
118 this->midi();
119 }
120
121 template <std::size_t N, avnd::parameter_port Port>
122 requires(!oscr::ossia_port<Port> && !avnd::curve_port<Port>)
123 void operator()(const avnd::field_reflection<N, Port>)
124 {
125 this->value();
126 }
127
128 template <std::size_t N, avnd::file_port Port>
129 void operator()(const avnd::field_reflection<N, Port>)
130 {
131 this->value();
132 }
133
134 template <std::size_t N, avnd::soundfile_port Port>
135 void operator()(const avnd::field_reflection<N, Port>)
136 {
137 this->value();
138 }
139
140 template <std::size_t N, avnd::midifile_port Port>
141 void operator()(const avnd::field_reflection<N, Port>)
142 {
143 this->value();
144 }
145
146 template <std::size_t N, avnd::buffer_port Port>
147 void operator()(const avnd::field_reflection<N, Port>)
148 {
149 this->buffer();
150 }
151
152 template <std::size_t N, avnd::texture_port Port>
153 void operator()(const avnd::field_reflection<N, Port>)
154 {
155 this->texture();
156 }
157
158 template <std::size_t N, avnd::gpu_render_target_output_port Port>
159 void operator()(const avnd::field_reflection<N, Port>)
160 {
161 this->texture();
162 }
163 template <std::size_t N, avnd::geometry_port Port>
164 void operator()(const avnd::field_reflection<N, Port>)
165 {
166 this->geometry();
167 }
168
169 // Scene ports travel through the same Process::PortType::Geometry slot.
170 template <std::size_t N, oscr::scene_port Port>
171 requires(!avnd::geometry_port<Port>)
172 void operator()(const avnd::field_reflection<N, Port>)
173 {
174 this->geometry();
175 }
176
177 template <std::size_t N, avnd::curve_port Port>
178 void operator()(const avnd::field_reflection<N, Port>)
179 {
180 this->value();
181 }
182
183 template <std::size_t N, avnd::callback Port>
184 void operator()(const avnd::field_reflection<N, Port>)
185 {
186 this->value();
187 }
188
189 void operator()(auto&&) = delete;
190};
191
192template <typename Info>
193struct Metadata<Process::Descriptor_k, oscr::ProcessModel<Info>>
194{
195 static std::vector<Process::PortType> inletDescription()
196 {
198 avnd::input_introspection<Info>::for_all(vis);
199 return vis.port;
200 }
201 static std::vector<Process::PortType> outletDescription()
202 {
204 avnd::output_introspection<Info>::for_all(vis);
205 return vis.port;
206 }
207 static Process::ProcessCategory kind() noexcept
208 {
209 Process::ProcessCategory cat;
210 if constexpr(has_kind<Info>)
211 cat = Info::kind();
212 else
213 cat = Process::ProcessCategory::Other;
214 return cat;
215 }
216 static Process::Descriptor get()
217 {
218// literate programming goes brr
219#if defined(_MSC_VER)
220#define if_exists(Expr, Else) \
221 []() noexcept { \
222 if(false) \
223 { \
224 } \
225 Else; \
226 }()
227#define if_attribute(Attr) QString{}
228#else
229#define if_exists(Expr, Else) \
230 []() noexcept { \
231 if constexpr(requires { Expr; }) \
232 return Expr; \
233 Else; \
234 }()
235
236#define if_attribute(Attr) \
237 []() noexcept -> QString { \
238 if constexpr(avnd::has_##Attr<Info>) \
239 return oscr::fromStringView(avnd::get_##Attr<Info>()); \
240 else \
241 return QString{}; \
242 }()
243#endif
244 static Process::Descriptor desc{
246 kind(),
247 if_attribute(category),
248 if_attribute(description),
249 if_attribute(author),
251 inletDescription(),
252 outletDescription(),
253 if_attribute(manual_url)};
254 return desc;
255 }
256};
257template <typename Info>
259{
260 static Process::ProcessFlags get() noexcept
261 {
262 if constexpr(requires { Info::flags(); })
263 {
264 return Info::flags();
265 }
266 else
267 {
268 Process::ProcessFlags flags{};
270
271 if constexpr(avnd::tag_temporal<Info>)
273 else
274 flags |= Process::ProcessFlags::SupportsLasting;
275
276 if constexpr(avnd::tag_single_exec<Info>)
278
279 if constexpr(avnd::tag_fully_custom_item<Info>)
281
282 if constexpr(avnd::tag_no_background<Info>)
284
285 if constexpr(avnd::has_dynamic_ports<Info>)
287
288 if constexpr(avnd::tag_deprecated<Info>)
290 return flags;
291 }
292 }
293};
294template <typename Info>
295struct Metadata<ObjectKey_k, oscr::ProcessModel<Info>>
296{
297 static constexpr auto get() noexcept { return avnd::get_c_name<Info>().data(); }
298};
299template <typename Info>
300struct Metadata<ConcreteKey_k, oscr::ProcessModel<Info>>
301{
302 static Q_DECL_RELAXED_CONSTEXPR UuidKey<Process::ProcessModel> get()
303 {
304 return oscr::uuid_from_string<Info>();
305 }
306};
Metadata to categorize objects: curves, audio, etc.
Metadata to get the key part of ObjectIdentifier.
Metadata to get the name that will be shown in the user interface.
Metadata to retrieve the ProcessFlags of a process.
Metadata to associate tags to objects.
Definition UuidKey.hpp:345
Definition score-plugin-avnd/Crousti/ProcessModel.hpp:88
Definition plugins/score-plugin-avnd/Crousti/Metadata.hpp:64
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1115
ProcessFlags
Various settings for processes.
Definition ProcessFlags.hpp:17
@ ControlSurface
The process supports being exposed to the ControlSurface.
Definition ProcessFlags.hpp:37
@ SupportsState
Can be loaded in a state.
Definition ProcessFlags.hpp:25
@ SupportsTemporal
Can be loaded as a process of an interval.
Definition ProcessFlags.hpp:19
@ NodeHasNoBackground
No background will be drawn for the node.
Definition ProcessFlags.hpp:80
@ Deprecated
Process kind is deprecated.
Definition ProcessFlags.hpp:83
@ DynamicPorts
The process has a variable structure, e.g. its ports can change dynamically.
Definition ProcessFlags.hpp:59
@ FullyCustomItem
The process's item handles all the decoration (won't be title, etc)
Definition ProcessFlags.hpp:40
Definition Controls.hpp:27
Static metadata implementation.
Definition lib/score/tools/Metadata.hpp:36
Definition score-lib-process/Process/ProcessMetadata.hpp:36
Definition plugins/score-plugin-avnd/Crousti/Metadata.hpp:76