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
6#include <QString>
7
8#include <avnd/binding/ossia/metadatas.hpp>
9#include <avnd/binding/ossia/port_base.hpp>
10#include <avnd/concepts/all.hpp>
11#include <avnd/introspection/input.hpp>
12#include <avnd/introspection/output.hpp>
13#include <avnd/wrappers/metadatas.hpp>
14
15#include <string_view>
16
17namespace oscr
18{
19template <typename Info>
20class ProcessModel;
21}
23namespace oscr
24{
25template <typename Info>
26class ProcessModel;
27}
28template <typename Info>
29 requires avnd::has_name<Info>
30struct Metadata<PrettyName_k, oscr::ProcessModel<Info>>
31{
32 static constexpr const char* get() noexcept { return avnd::get_name<Info>().data(); }
33};
34template <typename Info>
35 requires avnd::has_category<Info>
36struct Metadata<Category_k, oscr::ProcessModel<Info>>
37{
38 static constexpr const char* get() noexcept
39 {
40 return avnd::get_category<Info>().data();
41 }
42};
43template <typename Info>
44 requires(!avnd::has_category<Info>)
46{
47 static constexpr const char* get() noexcept { return ""; }
48};
49
50template <typename Info>
51struct Metadata<Tags_k, oscr::ProcessModel<Info>>
52{
53 static QStringList get() noexcept
54 {
55 QStringList lst;
56 for(std::string_view tag : avnd::get_tags<Info>())
57 lst.push_back(QString::fromUtf8(tag.data(), tag.size()));
58 return lst;
59 }
60};
61
62template <typename T>
63concept has_kind = requires { T::kind(); };
64
65template <typename T>
66auto get_kind()
67{
68 if constexpr(has_kind<T>)
69 return T::kind();
70 else
71 return Process::ProcessCategory::Other;
72}
73
75{
76 std::vector<Process::PortType> port;
77 void audio() { port.push_back(Process::PortType::Audio); }
78 void midi() { port.push_back(Process::PortType::Midi); }
79 void value() { port.push_back(Process::PortType::Message); }
80 void buffer() { port.push_back(Process::PortType::Texture); }
81 void texture() { port.push_back(Process::PortType::Texture); }
82 void geometry() { port.push_back(Process::PortType::Geometry); }
83
84 template <std::size_t N, oscr::ossia_value_port Port>
85 void operator()(const avnd::field_reflection<N, Port>)
86 {
87 this->value();
88 }
89 template <std::size_t N, oscr::ossia_audio_port Port>
90 void operator()(const avnd::field_reflection<N, Port>)
91 {
92 this->audio();
93 }
94
95 template <std::size_t N, oscr::ossia_midi_port Port>
96 void operator()(const avnd::field_reflection<N, Port>)
97 {
98 this->midi();
99 }
100
101 template <std::size_t N, avnd::dynamic_ports_port Port>
102 void operator()(const avnd::field_reflection<N, Port>)
103 {
104 using port_type = typename decltype(std::declval<Port>().ports)::value_type;
105 (*this)(avnd::field_reflection<std::size_t{0}, port_type>{});
106 }
107
108 template <std::size_t N, avnd::audio_port Port>
109 void operator()(const avnd::field_reflection<N, Port>)
110 {
111 this->audio();
112 }
113
114 template <std::size_t N, avnd::midi_port Port>
115 void operator()(const avnd::field_reflection<N, Port>)
116 {
117 this->midi();
118 }
119
120 template <std::size_t N, avnd::parameter_port Port>
121 requires(!oscr::ossia_port<Port> && !avnd::curve_port<Port>)
122 void operator()(const avnd::field_reflection<N, Port>)
123 {
124 this->value();
125 }
126
127 template <std::size_t N, avnd::file_port Port>
128 void operator()(const avnd::field_reflection<N, Port>)
129 {
130 this->value();
131 }
132
133 template <std::size_t N, avnd::soundfile_port Port>
134 void operator()(const avnd::field_reflection<N, Port>)
135 {
136 this->value();
137 }
138
139 template <std::size_t N, avnd::midifile_port Port>
140 void operator()(const avnd::field_reflection<N, Port>)
141 {
142 this->value();
143 }
144
145 template <std::size_t N, avnd::buffer_port Port>
146 void operator()(const avnd::field_reflection<N, Port>)
147 {
148 this->buffer();
149 }
150
151 template <std::size_t N, avnd::texture_port Port>
152 void operator()(const avnd::field_reflection<N, Port>)
153 {
154 this->texture();
155 }
156
157 template <std::size_t N, avnd::geometry_port Port>
158 void operator()(const avnd::field_reflection<N, Port>)
159 {
160 this->geometry();
161 }
162
163 template <std::size_t N, avnd::curve_port Port>
164 void operator()(const avnd::field_reflection<N, Port>)
165 {
166 this->value();
167 }
168
169 template <std::size_t N, avnd::callback Port>
170 void operator()(const avnd::field_reflection<N, Port>)
171 {
172 this->value();
173 }
174
175 void operator()(auto&&) = delete;
176};
177
178template <typename Info>
179struct Metadata<Process::Descriptor_k, oscr::ProcessModel<Info>>
180{
181 static std::vector<Process::PortType> inletDescription()
182 {
184 avnd::input_introspection<Info>::for_all(vis);
185 return vis.port;
186 }
187 static std::vector<Process::PortType> outletDescription()
188 {
190 avnd::output_introspection<Info>::for_all(vis);
191 return vis.port;
192 }
193 static Process::ProcessCategory kind() noexcept
194 {
195 Process::ProcessCategory cat;
196 if constexpr(has_kind<Info>)
197 cat = Info::kind();
198 else
199 cat = Process::ProcessCategory::Other;
200 return cat;
201 }
202 static Process::Descriptor get()
203 {
204// literate programming goes brr
205#if defined(_MSC_VER)
206#define if_exists(Expr, Else) \
207 []() noexcept { \
208 if(false) \
209 { \
210 } \
211 Else; \
212 }()
213#define if_attribute(Attr) QString{}
214#else
215#define if_exists(Expr, Else) \
216 []() noexcept { \
217 if constexpr(requires { Expr; }) \
218 return Expr; \
219 Else; \
220 }()
221
222#define if_attribute(Attr) \
223 []() noexcept -> QString { \
224 if constexpr(avnd::has_##Attr<Info>) \
225 return oscr::fromStringView(avnd::get_##Attr<Info>()); \
226 else \
227 return QString{}; \
228 }()
229#endif
230 static Process::Descriptor desc{
232 kind(),
233 if_attribute(category),
234 if_attribute(description),
235 if_attribute(author),
237 inletDescription(),
238 outletDescription(),
239 if_attribute(manual_url)};
240 return desc;
241 }
242};
243template <typename Info>
245{
246 static Process::ProcessFlags get() noexcept
247 {
248 if constexpr(requires { Info::flags(); })
249 {
250 return Info::flags();
251 }
252 else
253 {
254 Process::ProcessFlags flags{};
256
257 if constexpr(avnd::tag_temporal<Info>)
259 else
260 flags |= Process::ProcessFlags::SupportsLasting;
261
262 if constexpr(avnd::tag_single_exec<Info>)
264
265 if constexpr(avnd::tag_fully_custom_item<Info>)
267
268 if constexpr(avnd::tag_no_background<Info>)
270
271 if constexpr(avnd::dynamic_ports_input_introspection<Info>::size > 0)
273
274 if constexpr(avnd::dynamic_ports_output_introspection<Info>::size > 0)
276
277 if constexpr(avnd::tag_deprecated<Info>)
279 return flags;
280 }
281 }
282};
283template <typename Info>
284struct Metadata<ObjectKey_k, oscr::ProcessModel<Info>>
285{
286 static constexpr auto get() noexcept { return avnd::get_c_name<Info>().data(); }
287};
288template <typename Info>
289struct Metadata<ConcreteKey_k, oscr::ProcessModel<Info>>
290{
291 static Q_DECL_RELAXED_CONSTEXPR UuidKey<Process::ProcessModel> get()
292 {
293 return oscr::uuid_from_string<Info>();
294 }
295};
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:86
Definition plugins/score-plugin-avnd/Crousti/Metadata.hpp:63
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 Factories.hpp:19
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:75