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 
13 namespace oscr
14 {
15 template <typename Info>
16 class ProcessModel;
17 }
18 
19 inline QString fromStringView(std::string_view v)
20 {
21  return QString::fromUtf8(v.data(), v.size());
22 }
23 
25 namespace oscr
26 {
27 template <typename Info>
28 class ProcessModel;
29 }
30 template <typename Info>
31  requires avnd::has_name<Info>
32 struct Metadata<PrettyName_k, oscr::ProcessModel<Info>>
33 {
34  static constexpr const char* get() noexcept { return avnd::get_name<Info>().data(); }
35 };
36 template <typename Info>
37  requires avnd::has_category<Info>
38 struct Metadata<Category_k, oscr::ProcessModel<Info>>
39 {
40  static constexpr const char* get() noexcept
41  {
42  return avnd::get_category<Info>().data();
43  }
44 };
45 template <typename Info>
46  requires(!avnd::has_category<Info>)
47 struct Metadata<Category_k, oscr::ProcessModel<Info>>
48 {
49  static constexpr const char* get() noexcept { return ""; }
50 };
51 
52 template <typename Info>
53 struct 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 
64 template <typename T>
65 concept has_kind = requires { T::kind(); };
66 
67 template <typename T>
68 auto get_kind()
69 {
70  if constexpr(has_kind<T>)
71  return T::kind();
72  else
73  return Process::ProcessCategory::Other;
74 }
75 
76 template <typename Info>
77 struct 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 };
162 template <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{};
174  flags |= Process::ProcessFlags::ControlSurface;
175 
176  if constexpr(avnd::tag_temporal<Info>)
177  flags |= Process::ProcessFlags::SupportsTemporal;
178  else
179  flags |= Process::ProcessFlags::SupportsLasting;
180 
181  if constexpr(avnd::tag_single_exec<Info>)
182  flags |= Process::ProcessFlags::SupportsState;
183 
184  if constexpr(avnd::tag_fully_custom_item<Info>)
185  flags |= Process::ProcessFlags::FullyCustomItem;
186 
187  return flags;
188  }
189  }
190 };
191 template <typename Info>
192 struct Metadata<ObjectKey_k, oscr::ProcessModel<Info>>
193 {
194  static constexpr auto get() noexcept { return avnd::get_c_name<Info>().data(); }
195 };
196 template <typename Info>
197 struct 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.
Definition: lib/score/tools/Metadata.hpp:61
Metadata to get the key part of ObjectIdentifier.
Definition: lib/score/tools/Metadata.hpp:36
Metadata to get the name that will be shown in the user interface.
Definition: lib/score/tools/Metadata.hpp:42
Metadata to retrieve the ProcessFlags of a process.
Metadata to associate tags to objects.
Definition: lib/score/tools/Metadata.hpp:67
Definition: score-plugin-avnd/Crousti/ProcessModel.hpp:77
Base classes and tools to implement processes and layers.
Definition: JSONVisitor.hpp:1324
ProcessFlags
Various settings for processes.
Definition: ProcessFlags.hpp:17
Definition: Factories.hpp:19
Static metadata implementation.
Definition: lib/score/tools/Metadata.hpp:36
Definition: score-lib-process/Process/ProcessMetadata.hpp:37