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/port_base.hpp>
9#include <avnd/concepts/all.hpp>
10#include <avnd/introspection/input.hpp>
11#include <avnd/introspection/output.hpp>
12#include <avnd/wrappers/metadatas.hpp>
13
14#include <string_view>
15
16namespace oscr
17{
18template <typename Info>
19class ProcessModel;
20}
21
22inline QString fromStringView(std::string_view v)
23{
24 return QString::fromUtf8(v.data(), v.size());
25}
26
28namespace oscr
29{
30template <typename Info>
31class ProcessModel;
32}
33template <typename Info>
34 requires avnd::has_name<Info>
35struct Metadata<PrettyName_k, oscr::ProcessModel<Info>>
36{
37 static constexpr const char* get() noexcept { return avnd::get_name<Info>().data(); }
38};
39template <typename Info>
40 requires avnd::has_category<Info>
41struct Metadata<Category_k, oscr::ProcessModel<Info>>
42{
43 static constexpr const char* get() noexcept
44 {
45 return avnd::get_category<Info>().data();
46 }
47};
48template <typename Info>
49 requires(!avnd::has_category<Info>)
51{
52 static constexpr const char* get() noexcept { return ""; }
53};
54
55template <typename Info>
56struct Metadata<Tags_k, oscr::ProcessModel<Info>>
57{
58 static QStringList get() noexcept
59 {
60 QStringList lst;
61 for(std::string_view tag : avnd::get_tags<Info>())
62 lst.push_back(QString::fromUtf8(tag.data(), tag.size()));
63 return lst;
64 }
65};
66
67template <typename T>
68concept has_kind = requires { T::kind(); };
69
70template <typename T>
71auto get_kind()
72{
73 if constexpr(has_kind<T>)
74 return T::kind();
75 else
76 return Process::ProcessCategory::Other;
77}
78
80{
81 std::vector<Process::PortType> port;
82 void audio() { port.push_back(Process::PortType::Audio); }
83 void midi() { port.push_back(Process::PortType::Midi); }
84 void value() { port.push_back(Process::PortType::Message); }
85 void texture() { port.push_back(Process::PortType::Texture); }
86 void geometry() { port.push_back(Process::PortType::Geometry); }
87
88 template <std::size_t N, oscr::ossia_value_port Port>
89 void operator()(const avnd::field_reflection<N, Port>)
90 {
91 this->value();
92 }
93 template <std::size_t N, oscr::ossia_audio_port Port>
94 void operator()(const avnd::field_reflection<N, Port>)
95 {
96 this->audio();
97 }
98
99 template <std::size_t N, oscr::ossia_midi_port Port>
100 void operator()(const avnd::field_reflection<N, Port>)
101 {
102 this->midi();
103 }
104
105 template <std::size_t N, avnd::dynamic_ports_port Port>
106 void operator()(const avnd::field_reflection<N, Port>)
107 {
108 using port_type = typename decltype(std::declval<Port>().ports)::value_type;
109 (*this)(avnd::field_reflection<std::size_t{0}, port_type>{});
110 }
111
112 template <std::size_t N, avnd::audio_port Port>
113 void operator()(const avnd::field_reflection<N, Port>)
114 {
115 this->audio();
116 }
117
118 template <std::size_t N, avnd::midi_port Port>
119 void operator()(const avnd::field_reflection<N, Port>)
120 {
121 this->midi();
122 }
123
124 template <std::size_t N, avnd::parameter Port>
125 requires(!oscr::ossia_port<Port>)
126 void operator()(const avnd::field_reflection<N, Port>)
127 {
128 this->value();
129 }
130
131 template <std::size_t N, avnd::file_port Port>
132 void operator()(const avnd::field_reflection<N, Port>)
133 {
134 this->value();
135 }
136
137 template <std::size_t N, avnd::soundfile_port Port>
138 void operator()(const avnd::field_reflection<N, Port>)
139 {
140 this->value();
141 }
142
143 template <std::size_t N, avnd::midifile_port Port>
144 void operator()(const avnd::field_reflection<N, Port>)
145 {
146 this->value();
147 }
148
149 template <std::size_t N, avnd::texture_port Port>
150 void operator()(const avnd::field_reflection<N, Port>)
151 {
152 this->texture();
153 }
154 template <std::size_t N, avnd::geometry_port Port>
155 void operator()(const avnd::field_reflection<N, Port>)
156 {
157 this->geometry();
158 }
159
160 template <std::size_t N, avnd::curve_port Port>
161 void operator()(const avnd::field_reflection<N, Port>)
162 {
163 this->value();
164 }
165
166 template <std::size_t N, avnd::callback Port>
167 void operator()(const avnd::field_reflection<N, Port>)
168 {
169 this->value();
170 }
171
172 void operator()(auto&&) = delete;
173};
174
175template <typename Info>
176struct Metadata<Process::Descriptor_k, oscr::ProcessModel<Info>>
177{
178 static std::vector<Process::PortType> inletDescription()
179 {
181 avnd::input_introspection<Info>::for_all(vis);
182 return vis.port;
183 }
184 static std::vector<Process::PortType> outletDescription()
185 {
187 avnd::output_introspection<Info>::for_all(vis);
188 return vis.port;
189 }
190 static Process::ProcessCategory kind() noexcept
191 {
192 Process::ProcessCategory cat;
193 if constexpr(has_kind<Info>)
194 cat = Info::kind();
195 else
196 cat = Process::ProcessCategory::Other;
197
198 if constexpr(avnd::tag_deprecated<Info>)
199 cat = Process::ProcessCategory(cat | Process::ProcessCategory::Deprecated);
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 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::dynamic_ports_input_introspection<Info>::size > 0)
270
271 if constexpr(avnd::dynamic_ports_output_introspection<Info>::size > 0)
273
274 return flags;
275 }
276 }
277};
278template <typename Info>
279struct Metadata<ObjectKey_k, oscr::ProcessModel<Info>>
280{
281 static constexpr auto get() noexcept { return avnd::get_c_name<Info>().data(); }
282};
283template <typename Info>
284struct Metadata<ConcreteKey_k, oscr::ProcessModel<Info>>
285{
286 static Q_DECL_RELAXED_CONSTEXPR UuidKey<Process::ProcessModel> get()
287 {
288 return oscr::uuid_from_string<Info>();
289 }
290};
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:344
Definition score-plugin-avnd/Crousti/ProcessModel.hpp:86
Definition plugins/score-plugin-avnd/Crousti/Metadata.hpp:68
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
@ 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:37
Definition plugins/score-plugin-avnd/Crousti/Metadata.hpp:80