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/wrappers/metadatas.hpp>
11
12#include <string_view>
13
14namespace oscr
15{
16template <typename Info>
17class ProcessModel;
18}
19
20inline QString fromStringView(std::string_view v)
21{
22 return QString::fromUtf8(v.data(), v.size());
23}
24
26namespace oscr
27{
28template <typename Info>
29class ProcessModel;
30}
31template <typename Info>
32 requires avnd::has_name<Info>
33struct Metadata<PrettyName_k, oscr::ProcessModel<Info>>
34{
35 static constexpr const char* get() noexcept { return avnd::get_name<Info>().data(); }
36};
37template <typename Info>
38 requires avnd::has_category<Info>
39struct Metadata<Category_k, oscr::ProcessModel<Info>>
40{
41 static constexpr const char* get() noexcept
42 {
43 return avnd::get_category<Info>().data();
44 }
45};
46template <typename Info>
47 requires(!avnd::has_category<Info>)
49{
50 static constexpr const char* get() noexcept { return ""; }
51};
52
53template <typename Info>
54struct Metadata<Tags_k, oscr::ProcessModel<Info>>
55{
56 static QStringList get() noexcept
57 {
58 QStringList lst;
59 for(std::string_view tag : avnd::get_tags<Info>())
60 lst.push_back(QString::fromUtf8(tag.data(), tag.size()));
61 return lst;
62 }
63};
64
65template <typename T>
66concept has_kind = requires { T::kind(); };
67
68template <typename T>
69auto get_kind()
70{
71 if constexpr(has_kind<T>)
72 return T::kind();
73 else
74 return Process::ProcessCategory::Other;
75}
76
78{
79 std::vector<Process::PortType> port;
80 void audio() { port.push_back(Process::PortType::Audio); }
81 void midi() { port.push_back(Process::PortType::Midi); }
82 void value() { port.push_back(Process::PortType::Message); }
83 void texture() { port.push_back(Process::PortType::Texture); }
84 void geometry() { port.push_back(Process::PortType::Geometry); }
85
86 template <std::size_t N, oscr::ossia_value_port Port>
87 void operator()(const avnd::field_reflection<N, Port>)
88 {
89 this->value();
90 }
91 template <std::size_t N, oscr::ossia_audio_port Port>
92 void operator()(const avnd::field_reflection<N, Port>)
93 {
94 this->audio();
95 }
96
97 template <std::size_t N, oscr::ossia_midi_port Port>
98 void operator()(const avnd::field_reflection<N, Port>)
99 {
100 this->midi();
101 }
102
103 template <std::size_t N, avnd::dynamic_ports_port Port>
104 void operator()(const avnd::field_reflection<N, Port>)
105 {
106 using port_type = typename decltype(std::declval<Port>().ports)::value_type;
107 (*this)(avnd::field_reflection<std::size_t{0}, port_type>{});
108 }
109
110 template <std::size_t N, avnd::audio_port Port>
111 void operator()(const avnd::field_reflection<N, Port>)
112 {
113 this->audio();
114 }
115
116 template <std::size_t N, avnd::midi_port Port>
117 void operator()(const avnd::field_reflection<N, Port>)
118 {
119 this->midi();
120 }
121
122 template <std::size_t N, avnd::parameter Port>
123 requires(!oscr::ossia_port<Port>)
124 void operator()(const avnd::field_reflection<N, Port>)
125 {
126 this->value();
127 }
128
129 template <std::size_t N, avnd::file_port Port>
130 void operator()(const avnd::field_reflection<N, Port>)
131 {
132 this->value();
133 }
134
135 template <std::size_t N, avnd::soundfile_port Port>
136 void operator()(const avnd::field_reflection<N, Port>)
137 {
138 this->value();
139 }
140
141 template <std::size_t N, avnd::midifile_port Port>
142 void operator()(const avnd::field_reflection<N, Port>)
143 {
144 this->value();
145 }
146
147#if SCORE_PLUGIN_GFX
148 template <std::size_t N, avnd::texture_port Port>
149 void operator()(const avnd::field_reflection<N, Port>)
150 {
151 this->texture();
152 }
153 template <std::size_t N, avnd::geometry_port Port>
154 void operator()(const avnd::field_reflection<N, Port>)
155 {
156 this->geometry();
157 }
158#endif
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:79
Definition plugins/score-plugin-avnd/Crousti/Metadata.hpp:66
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:78