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/concepts/all.hpp>
9#include <avnd/wrappers/metadatas.hpp>
10
11#include <string_view>
12
13namespace oscr
14{
15template <typename Info>
16class ProcessModel;
17}
18
19inline QString fromStringView(std::string_view v)
20{
21 return QString::fromUtf8(v.data(), v.size());
22}
23
25namespace oscr
26{
27template <typename Info>
28class ProcessModel;
29}
30template <typename Info>
31 requires avnd::has_name<Info>
32struct Metadata<PrettyName_k, oscr::ProcessModel<Info>>
33{
34 static constexpr const char* get() noexcept { return avnd::get_name<Info>().data(); }
35};
36template <typename Info>
37 requires avnd::has_category<Info>
38struct Metadata<Category_k, oscr::ProcessModel<Info>>
39{
40 static constexpr const char* get() noexcept
41 {
42 return avnd::get_category<Info>().data();
43 }
44};
45template <typename Info>
46 requires(!avnd::has_category<Info>)
48{
49 static constexpr const char* get() noexcept { return ""; }
50};
51
52template <typename Info>
53struct Metadata<Tags_k, oscr::ProcessModel<Info>>
54{
55 static QStringList get() noexcept
56 {
57 QStringList lst;
58 for(std::string_view tag : avnd::get_tags<Info>())
59 lst.push_back(QString::fromUtf8(tag.data(), tag.size()));
60 return lst;
61 }
62};
63
64template <typename T>
65concept has_kind = requires { T::kind(); };
66
67template <typename T>
68auto get_kind()
69{
70 if constexpr(has_kind<T>)
71 return T::kind();
72 else
73 return Process::ProcessCategory::Other;
74}
75
76template <typename Info>
77struct Metadata<Process::Descriptor_k, oscr::ProcessModel<Info>>
78{
79 static std::vector<Process::PortType> inletDescription()
80 {
81 std::vector<Process::PortType> port;
82 /*
83 for (std::size_t i = 0; i < info::audio_in_count; i++)
84 port.push_back(Process::PortType::Audio);
85 for (std::size_t i = 0; i < info::midi_in_count; i++)
86 port.push_back(Process::PortType::Midi);
87 for (std::size_t i = 0; i < info::value_in_count; i++)
88 port.push_back(Process::PortType::Message);
89 for (std::size_t i = 0; i < info::control_in_count; i++)
90 port.push_back(Process::PortType::Message);
91 */
92 return port;
93 }
94 static std::vector<Process::PortType> outletDescription()
95 {
96 std::vector<Process::PortType> port;
97 /*
98 for (std::size_t i = 0; i < info::audio_out_count; i++)
99 port.push_back(Process::PortType::Audio);
100 for (std::size_t i = 0; i < info::midi_out_count; i++)
101 port.push_back(Process::PortType::Midi);
102 for (std::size_t i = 0; i < info::value_out_count; i++)
103 port.push_back(Process::PortType::Message);
104 for (std::size_t i = 0; i < info::control_out_count; i++)
105 port.push_back(Process::PortType::Message);
106 */
107 return port;
108 }
109 static Process::ProcessCategory kind() noexcept
110 {
111 Process::ProcessCategory cat;
112 if constexpr(has_kind<Info>)
113 cat = Info::kind();
114 else
115 cat = Process::ProcessCategory::Other;
116
117 if constexpr(avnd::tag_deprecated<Info>)
118 cat = Process::ProcessCategory(cat | Process::ProcessCategory::Deprecated);
119 return cat;
120 }
121 static Process::Descriptor get()
122 {
123// literate programming goes brr
124#if defined(_MSC_VER)
125#define if_exists(Expr, Else) \
126 []() noexcept { \
127 if(false) \
128 { \
129 } \
130 Else; \
131 }()
132#define if_attribute(Attr) QString{}
133#else
134#define if_exists(Expr, Else) \
135 []() noexcept { \
136 if constexpr(requires { Expr; }) \
137 return Expr; \
138 Else; \
139 }()
140
141#define if_attribute(Attr) \
142 []() noexcept -> QString { \
143 if constexpr(avnd::has_##Attr<Info>) \
144 return fromStringView(avnd::get_##Attr<Info>()); \
145 else \
146 return QString{}; \
147 }()
148#endif
149 static Process::Descriptor desc{
151 kind(),
152 if_attribute(category),
153 if_attribute(description),
154 if_attribute(author),
156 inletDescription(),
157 outletDescription(),
158 if_attribute(manual_url)};
159 return desc;
160 }
161};
162template <typename Info>
164{
165 static Process::ProcessFlags get() noexcept
166 {
167 if constexpr(requires { Info::flags(); })
168 {
169 return Info::flags();
170 }
171 else
172 {
173 Process::ProcessFlags flags{};
175
176 if constexpr(avnd::tag_temporal<Info>)
178 else
179 flags |= Process::ProcessFlags::SupportsLasting;
180
181 if constexpr(avnd::tag_single_exec<Info>)
183
184 if constexpr(avnd::tag_fully_custom_item<Info>)
186
187 return flags;
188 }
189 }
190};
191template <typename Info>
192struct Metadata<ObjectKey_k, oscr::ProcessModel<Info>>
193{
194 static constexpr auto get() noexcept { return avnd::get_c_name<Info>().data(); }
195};
196template <typename Info>
197struct Metadata<ConcreteKey_k, oscr::ProcessModel<Info>>
198{
199 static Q_DECL_RELAXED_CONSTEXPR UuidKey<Process::ProcessModel> get()
200 {
201 return oscr::uuid_from_string<Info>();
202 }
203};
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:343
Definition score-plugin-avnd/Crousti/ProcessModel.hpp:77
Definition plugins/score-plugin-avnd/Crousti/Metadata.hpp:65
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1324
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
@ 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