2#include <Process/Dataflow/WidgetInlets.hpp>
3#include <Process/ProcessFlags.hpp>
4#include <Process/ProcessMetadata.hpp>
6#include <Dataflow/CurveInlet.hpp>
7#include <Engine/Node/CommonWidgets.hpp>
9#include <score/plugins/UuidKey.hpp>
11#include <ossia/dataflow/audio_port.hpp>
12#include <ossia/dataflow/port.hpp>
13#include <ossia/dataflow/safe_nodes/tick_policies.hpp>
15#include <boost/container/vector.hpp>
17#include <avnd/binding/ossia/qt.hpp>
18#include <avnd/binding/ossia/uuid.hpp>
19#include <avnd/common/concepts_polyfill.hpp>
20#include <avnd/common/struct_reflection.hpp>
21#include <avnd/concepts/audio_port.hpp>
22#include <avnd/concepts/channels.hpp>
23#include <avnd/concepts/curve.hpp>
24#include <avnd/concepts/gfx.hpp>
25#include <avnd/concepts/midi_port.hpp>
26#include <avnd/concepts/parameter.hpp>
27#include <avnd/introspection/input.hpp>
28#include <avnd/wrappers/metadatas.hpp>
29#include <avnd/wrappers/widgets.hpp>
36#define make_uuid(text) score::uuids::string_generator::compute((text))
40template <
typename Node,
typename FieldIndex>
41struct CustomFloatControl;
44template <
typename Node,
typename FieldIndex>
45struct is_custom_serialized<
oscr::CustomFloatControl<Node, FieldIndex>> : std::true_type
54 using Process::ControlInlet::ControlInlet;
59 : ControlInlet{name, id, parent}
61 displayHandledExplicitly =
true;
64 setDomain(ossia::make_domain(min, max));
67 auto getMin()
const noexcept {
return domain().get().template convert_min<float>(); }
68 auto getMax()
const noexcept {
return domain().get().template convert_max<float>(); }
70 void setupExecution(ossia::inlet& inl, QObject* exec_context)
const noexcept override
72 auto& port = **safe_cast<ossia::value_inlet*>(&inl);
73 port.type = ossia::val_type::FLOAT;
74 port.domain = domain().get();
78template <
typename Node,
typename FieldIndex>
81 using CustomFloatControlBase::CustomFloatControlBase;
83 static key_type static_concreteKey()
noexcept
85 return make_field_uuid<Node>(
true, FieldIndex{});
87 key_type concreteKey()
const noexcept override {
return static_concreteKey(); }
89 void serialize_impl(
const VisitorVariant& vis)
const noexcept override
91 score::serialize_dyn(vis, *
this);
98template <
typename Node,
typename FieldIndex>
110template <
typename Node,
typename FieldIndex>
125template <
typename Node,
typename T, std::
size_t N>
129 using value_type = as_type(T::value);
130 constexpr auto name = avnd::get_name<T>();
131 QString qname = QString::fromUtf8(name.data(), name.size());
133 constexpr auto widg = avnd::get_widget<T>();
137 if constexpr(avnd::curve_port<T>)
141 else if constexpr(widg.widget == avnd::widget_type::bang)
143 return new Process::ImpulseButton{qname, id, parent};
145 else if constexpr(widg.widget == avnd::widget_type::button)
147 return new Process::Button{qname, id, parent};
149 else if constexpr(widg.widget == avnd::widget_type::toggle)
151 static constexpr auto c = avnd::get_range<T>();
152 if constexpr(
requires { c.values(); })
154 return new Process::ChooserToggle{
155 {c.values[0], c.values[1]}, c.init, qname, id, parent};
159 return new Process::Toggle{bool(c.init), qname, id, parent};
162 else if constexpr(widg.widget == avnd::widget_type::slider)
164 static constexpr auto c = avnd::get_range<T>();
165 if constexpr(std::is_integral_v<value_type>)
167 return new Process::IntSlider{c.min, c.max, c.init, qname, id, parent};
171 if constexpr(avnd::has_mapper<T>)
173 return new CustomFloatControl<Node, avnd::field_index<N>>{c.min, c.max, c.init,
178 return new Process::FloatSlider{c.min, c.max, c.init, qname, id, parent};
182 else if constexpr(widg.widget == avnd::widget_type::log_slider)
184 static constexpr auto c = avnd::get_range<T>();
185 return new Process::LogFloatSlider{c.min, c.max, c.init, qname, id, parent};
187 else if constexpr(widg.widget == avnd::widget_type::log_knob)
190 static constexpr auto c = avnd::get_range<T>();
191 return new Process::LogFloatSlider{c.min, c.max, c.init, qname, id, parent};
193 else if constexpr(widg.widget == avnd::widget_type::time_chooser)
195 static constexpr auto c = avnd::get_range<T>();
196 return new Process::TimeChooser{c.min, c.max, c.init, qname, id, parent};
198 else if constexpr(widg.widget == avnd::widget_type::range_slider)
200 static constexpr auto c = avnd::get_range<T>();
201 if constexpr(std::is_integral_v<value_type>)
203 auto [start, end] = c.init;
204 return new Process::IntRangeSlider{c.min, c.max, {(float)start, (
float)end},
209 auto [start, end] = c.init;
210 return new Process::FloatRangeSlider{c.min, c.max, {(float)start, (
float)end},
214 else if constexpr(widg.widget == avnd::widget_type::range_spinbox)
216 static constexpr auto c = avnd::get_range<T>();
217 if constexpr(std::is_integral_v<value_type>)
219 auto [start, end] = c.init;
220 return new Process::IntRangeSpinBox{c.min, c.max, {(float)start, (
float)end},
225 auto [start, end] = c.init;
226 return new Process::FloatRangeSpinBox{c.min, c.max, {(float)start, (
float)end},
230 else if constexpr(widg.widget == avnd::widget_type::multi_slider)
232 std::vector<ossia::value> init;
233 return new Process::MultiSlider{init, qname, id, parent};
235 else if constexpr(widg.widget == avnd::widget_type::multi_slider_xy)
237 std::vector<ossia::value> init;
238 return new Process::MultiSliderXY{init, qname, id, parent};
240 else if constexpr(widg.widget == avnd::widget_type::path_generator_xy)
242 std::vector<ossia::value> init;
243 return new Process::PathGeneratorXY{init, qname, id, parent};
245 else if constexpr(widg.widget == avnd::widget_type::spinbox)
247 static constexpr auto c = avnd::get_range<T>();
248 if constexpr(std::is_integral_v<value_type>)
250 return new Process::IntSpinBox{c.min, c.max, c.init, qname, id, parent};
254 return new Process::FloatSpinBox{c.min, c.max, c.init, qname, id, parent};
257 else if constexpr(widg.widget == avnd::widget_type::knob)
259 static constexpr auto c = avnd::get_range<T>();
260 if constexpr(std::is_integral_v<value_type>)
263 return new Process::IntSlider{c.min, c.max, c.init, qname, id, parent};
267 if constexpr(avnd::has_mapper<T>)
269 return new CustomFloatControl<Node, avnd::field_index<N>>{c.min, c.max, c.init,
274 return new Process::FloatKnob{c.min, c.max, c.init, qname, id, parent};
278 else if constexpr(widg.widget == avnd::widget_type::lineedit)
280 if constexpr(avnd::has_range<T>)
282 static constexpr auto c = avnd::get_range<T>();
283 if constexpr(avnd::program_parameter<T>)
285 auto p =
new Process::ProgramEdit{c.init.data(), qname, id, parent};
286 p->language = T::language();
290 return new Process::LineEdit{c.init.data(), qname, id, parent};
294 if constexpr(avnd::program_parameter<T>)
296 auto p =
new Process::ProgramEdit{
"", qname, id, parent};
297 p->language = T::language();
301 return new Process::LineEdit{
"", qname, id, parent};
304 else if constexpr(widg.widget == avnd::widget_type::combobox)
306 static constexpr auto c = avnd::get_range<T>();
307 return new Process::ComboBox{to_combobox_range(c.values), c.init, qname, id, parent};
309 else if constexpr(widg.widget == avnd::widget_type::choices)
311 static constexpr auto c = avnd::get_range<T>();
312 auto enums = avnd::to_enum_range(c.values);
314 std::is_integral_v<
decltype(c.init)> || std::is_enum_v<
decltype(c.init)>);
315 auto init = enums[
static_cast<int>(c.init)];
316 std::vector<QString> pixmaps;
317 if constexpr(avnd::has_pixmaps<T>)
319 for(std::string_view pix : avnd::get_pixmaps<T>())
321 pixmaps.push_back(QString::fromLatin1(pix.data(), pix.size()));
324 return new Process::Enum{
325 std::move(enums), pixmaps, std::move(init), qname, id, parent};
327 else if constexpr(widg.widget == avnd::widget_type::xy)
329 static constexpr auto c = avnd::get_range<T>();
330 if constexpr(
requires {
336 return new Process::XYSlider{
337 {c.min, c.min}, {c.max, c.max}, {c.init, c.init}, qname, id, parent};
341 auto [mx, my] = c.min;
342 auto [Mx, My] = c.max;
343 auto [ix, iy] = c.init;
344 return new Process::XYSlider{{mx, my}, {Mx, My}, {ix, iy}, qname, id, parent};
347 else if constexpr(widg.widget == avnd::widget_type::xyz)
349 static constexpr auto c = avnd::get_range<T>();
350 if constexpr(
requires {
356 return new Process::XYZSlider{
357 {c.min, c.min, c.min},
358 {c.max, c.max, c.max},
359 {c.init, c.init, c.init},
366 auto [mx, my, mz] = c.min;
367 auto [Mx, My, Mz] = c.max;
368 auto [ix, iy, iz] = c.init;
369 return new Process::XYZSlider{{mx, my, mz}, {Mx, My, Mz}, {ix, iy, iz},
373 else if constexpr(widg.widget == avnd::widget_type::xy_spinbox)
375 using data_type = std::decay_t<
decltype(value_type{}.x)>;
376 static constexpr auto c = avnd::get_range<T>();
377 if constexpr(
requires {
383 return new Process::XYSpinboxes{
387 std::is_integral_v<data_type>,
394 auto [mx, my] = c.min;
395 auto [Mx, My] = c.max;
396 auto [ix, iy] = c.init;
397 return new Process::XYSpinboxes{
398 {mx, my}, {Mx, My}, {ix, iy}, std::is_integral_v<data_type>,
402 else if constexpr(widg.widget == avnd::widget_type::xyz_spinbox)
404 static constexpr auto c = avnd::get_range<T>();
405 if constexpr(
requires {
411 return new Process::XYZSpinboxes{
412 {c.min, c.min, c.min},
413 {c.max, c.max, c.max},
414 {c.init, c.init, c.init},
422 auto [mx, my, mz] = c.min;
423 auto [Mx, My, Mz] = c.max;
424 auto [ix, iy, iz] = c.init;
425 return new Process::XYZSpinboxes{{mx, my, mz}, {Mx, My, Mz}, {ix, iy, iz},
429 else if constexpr(widg.widget == avnd::widget_type::color)
431 static constexpr auto c = avnd::get_range<T>();
432 static constexpr auto i = c.init;
433 return new Process::HSVSlider{{i.r, i.g, i.b, i.a}, qname, id, parent};
435 else if constexpr(widg.widget == avnd::widget_type::control)
439 else if constexpr(widg.widget == avnd::widget_type::no_control)
445 static_assert(T::is_not_a_valid_control);
449template <
typename T, std::
size_t N>
453 constexpr auto name = avnd::get_name<T>();
454 constexpr auto widg = avnd::get_widget<T>();
455 QString qname = QString::fromUtf8(name.data(), name.size());
459 if constexpr(widg.widget == avnd::widget_type::bargraph)
461 static constexpr auto c = avnd::get_range<T>();
462 return new Process::Bargraph{c.min, c.max, c.init, qname, id, parent};
464 else if constexpr(widg.widget == avnd::widget_type::control)
468 else if constexpr(widg.widget == avnd::widget_type::no_control)
472 else if constexpr(avnd::fp_ish<
decltype(T::value)>)
474 static constexpr auto c = avnd::get_range<T>();
475 return new Process::Bargraph{c.min, c.max, c.init, qname, id, parent};
484static inline constexpr auto make_control_out(
const T& t)
486 return make_control_out<T>();
494 ossia::audio_vector* buffer{};
498 std::span<const double> operator[](std::size_t i)
const noexcept
500 auto& chan = (*buffer)[i];
501 int64_t min_dur = std::min(int64_t(chan.size()) - offset, duration);
505 return std::span<const double>{chan.data() + offset, std::size_t(min_dur)};
508 std::size_t channels()
const noexcept {
return buffer->size(); }
509 void resize(std::size_t i)
const noexcept {
return buffer->resize(i); }
510 void reserve(std::size_t channels, std::size_t bufferSize)
513 for(
auto& vec : *buffer)
514 vec.reserve(bufferSize);
520 ossia::audio_vector* buffer{};
524 std::span<double> operator[](std::size_t i)
const noexcept
526 auto& chan = (*buffer)[i];
527 int64_t min_dur = std::min(int64_t(chan.size()) - offset, duration);
531 return std::span<double>{chan.data() + offset, std::size_t(min_dur)};
534 std::size_t channels()
const noexcept {
return buffer->size(); }
535 void resize(std::size_t channels, std::size_t samples_to_write)
const noexcept
537 buffer->resize(channels);
538 for(
auto& c : *buffer)
539 c.resize(offset + samples_to_write);
542 void reserve(std::size_t channels, std::size_t bufferSize)
544 buffer->resize(channels);
545 for(
auto& c : *buffer)
546 c.reserve(bufferSize);
Definition VisitorInterface.hpp:53
Definition DataStreamVisitor.hpp:27
Definition DataStreamVisitor.hpp:202
Definition VisitorInterface.hpp:61
Definition JSONVisitor.hpp:52
Definition JSONVisitor.hpp:423
Definition UuidKey.hpp:345
The id_base_t class.
Definition Identifier.hpp:59
Definition Factories.hpp:19
Definition CurveInlet.hpp:47
Definition VisitorInterface.hpp:13
The VisitorVariant struct.
Definition VisitorInterface.hpp:26
Definition Concepts.hpp:53
Definition Concepts.hpp:80
Definition Concepts.hpp:493
Definition Concepts.hpp:519