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>
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
201 if constexpr(avnd::tag_deprecated<Info>)
202 cat = Process::ProcessCategory(cat | Process::ProcessCategory::Deprecated);
203 return cat;
204 }
205 static Process::Descriptor get()
206 {
207// literate programming goes brr
208#if defined(_MSC_VER)
209#define if_exists(Expr, Else) \
210 []() noexcept { \
211 if(false) \
212 { \
213 } \
214 Else; \
215 }()
216#define if_attribute(Attr) QString{}
217#else
218#define if_exists(Expr, Else) \
219 []() noexcept { \
220 if constexpr(requires { Expr; }) \
221 return Expr; \
222 Else; \
223 }()
224
225#define if_attribute(Attr) \
226 []() noexcept -> QString { \
227 if constexpr(avnd::has_##Attr<Info>) \
228 return oscr::fromStringView(avnd::get_##Attr<Info>()); \
229 else \
230 return QString{}; \
231 }()
232#endif
233 static Process::Descriptor desc{
235 kind(),
236 if_attribute(category),
237 if_attribute(description),
238 if_attribute(author),
240 inletDescription(),
241 outletDescription(),
242 if_attribute(manual_url)};
243 return desc;
244 }
245};
246template <typename Info>
248{
249 static Process::ProcessFlags get() noexcept
250 {
251 if constexpr(requires { Info::flags(); })
252 {
253 return Info::flags();
254 }
255 else
256 {
257 Process::ProcessFlags flags{};
259
260 if constexpr(avnd::tag_temporal<Info>)
262 else
263 flags |= Process::ProcessFlags::SupportsLasting;
264
265 if constexpr(avnd::tag_single_exec<Info>)
267
268 if constexpr(avnd::tag_fully_custom_item<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 return flags;
278 }
279 }
280};
281template <typename Info>
282struct Metadata<ObjectKey_k, oscr::ProcessModel<Info>>
283{
284 static constexpr auto get() noexcept { return avnd::get_c_name<Info>().data(); }
285};
286template <typename Info>
287struct Metadata<ConcreteKey_k, oscr::ProcessModel<Info>>
288{
289 static Q_DECL_RELAXED_CONSTEXPR UuidKey<Process::ProcessModel> get()
290 {
291 return oscr::uuid_from_string<Info>();
292 }
293};
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
@ 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:75