2#include <ossia/dataflow/audio_port.hpp>
3#include <ossia/dataflow/dataflow_fwd.hpp>
4#include <ossia/dataflow/geometry_port.hpp>
5#include <ossia/dataflow/midi_port.hpp>
6#include <ossia/dataflow/texture_port.hpp>
7#include <ossia/dataflow/value_port.hpp>
9#include <ossia/network/common/path.hpp>
13struct OSSIA_EXPORT port
15 enum scope_t : uint8_t
23 scope_t scope{scope_t::both};
27 port(
const port&) =
delete;
28 port(port&&) =
delete;
29 port& operator=(
const port&) =
delete;
30 port& operator=(port&&) =
delete;
34struct OSSIA_EXPORT inlet :
public port
37 inlet() noexcept = default;
39 inlet(destination_t dest) noexcept
40 : address{std::move(dest)}
49 inlet(graph_edge& edge)
noexcept { sources.push_back(&edge); }
54 void connect(graph_edge* e)
noexcept
56 auto it = ossia::find(sources, e);
57 if(it == sources.end())
61 void disconnect(graph_edge* e)
noexcept { ossia::remove_erase(sources, e); }
63 [[nodiscard]]
virtual std::size_t which() const noexcept = 0;
68 const T* target() const noexcept;
72 const T& cast() const noexcept;
74 auto visit(const T& t);
76 auto visit(const T& t) const;
78 auto& cables() noexcept {
return sources; }
79 [[nodiscard]]
auto& cables() const noexcept {
return sources; }
81 virtual void pre_process();
82 virtual void post_process();
84 destination_t address;
85 ossia::small_vector<graph_edge*, 2> sources;
86 ossia::small_vector<value_inlet*, 2> child_inlets;
88 friend struct audio_inlet;
89 friend struct value_inlet;
90 friend struct midi_inlet;
93struct OSSIA_EXPORT outlet :
public port
96 outlet() noexcept = default;
97 outlet(destination_t dest) noexcept
98 : address{std::move(dest)}
107 outlet(graph_edge& edge)
noexcept { targets.push_back(&edge); }
112 void connect(graph_edge* e)
noexcept
114 auto it = ossia::find(targets, e);
115 if(it == targets.end())
116 targets.push_back(e);
119 void disconnect(graph_edge* e)
noexcept { ossia::remove_erase(targets, e); }
121 void write(execution_state& e);
123 [[nodiscard]]
virtual std::size_t which() const noexcept = 0;
125 template <typename T>
126 T* target() noexcept;
127 template <typename T>
128 const T* target() const noexcept;
129 template <typename T>
131 template <typename T>
132 const T& cast() const noexcept;
133 template <typename T>
134 auto visit(const T& t);
135 template <typename T>
136 auto visit(const T& t) const;
138 virtual
void pre_process();
139 virtual
void post_process();
141 auto& cables() noexcept {
return targets; }
142 [[nodiscard]]
auto& cables() const noexcept {
return targets; }
144 destination_t address;
145 ossia::small_vector<graph_edge*, 2> targets;
146 ossia::small_vector<value_inlet*, 2> child_inlets;
148 friend struct audio_outlet;
149 friend struct value_outlet;
150 friend struct midi_outlet;
153struct OSSIA_EXPORT audio_inlet :
public ossia::inlet
155 audio_inlet() noexcept = default;
157 audio_inlet(destination_t dest) noexcept
158 : inlet{std::move(dest)}
167 audio_inlet(graph_edge& edge)
noexcept { sources.push_back(&edge); }
171 const ossia::audio_port& operator*() const noexcept {
return data; }
172 const ossia::audio_port* operator->() const noexcept {
return &data; }
173 ossia::audio_port& operator*() noexcept {
return data; }
174 ossia::audio_port* operator->() noexcept {
return &data; }
176 [[nodiscard]] std::size_t which() const noexcept final
override
178 return audio_port::which;
181 ossia::audio_port data;
184struct OSSIA_EXPORT midi_inlet :
public ossia::inlet
186 midi_inlet() noexcept = default;
188 midi_inlet(destination_t dest) noexcept
189 : inlet{std::move(dest)}
198 midi_inlet(graph_edge& edge)
noexcept { sources.push_back(&edge); }
202 const ossia::midi_port& operator*() const noexcept {
return data; }
203 const ossia::midi_port* operator->() const noexcept {
return &data; }
204 ossia::midi_port& operator*() noexcept {
return data; }
205 ossia::midi_port* operator->() noexcept {
return &data; }
207 [[nodiscard]] std::size_t which() const noexcept final
override
209 return midi_port::which;
212 ossia::midi_port data;
215struct OSSIA_EXPORT value_inlet :
public ossia::inlet
217 value_inlet() noexcept = default;
219 value_inlet(destination_t dest) noexcept
220 : inlet{std::move(dest)}
229 value_inlet(graph_edge& edge)
noexcept { sources.push_back(&edge); }
233 const ossia::value_port& operator*() const noexcept {
return data; }
234 const ossia::value_port* operator->() const noexcept {
return &data; }
235 ossia::value_port& operator*() noexcept {
return data; }
236 ossia::value_port* operator->() noexcept {
return &data; }
238 [[nodiscard]] std::size_t which() const noexcept final
override
240 return value_port::which;
243 ossia::value_port data;
249void process_audio_out_mono(ossia::audio_outlet& audio_out);
252void process_audio_out_general(ossia::audio_outlet& audio_out);
255void process_audio_out_mono(ossia::audio_port& i, ossia::audio_outlet& audio_out);
258void process_audio_out_general(ossia::audio_port& i, ossia::audio_outlet& audio_out);
260struct OSSIA_EXPORT audio_outlet :
public ossia::outlet
262 audio_outlet() noexcept { init(); }
264 audio_outlet(destination_t dest) noexcept
265 : outlet{std::move(dest)}
276 audio_outlet(graph_edge& edge)
noexcept
278 targets.push_back(&edge);
284 const ossia::audio_port& operator*() const noexcept {
return data; }
285 const ossia::audio_port* operator->() const noexcept {
return &data; }
286 ossia::audio_port& operator*() noexcept {
return data; }
287 ossia::audio_port* operator->() noexcept {
return &data; }
289 [[nodiscard]] std::size_t which() const noexcept final
override
291 return audio_port::which;
294 void post_process()
override;
297 pan_weight pan{1., 1.};
299 ossia::value_inlet gain_inlet;
300 ossia::value_inlet pan_inlet;
302 ossia::audio_port data;
308 this->child_inlets.resize(2);
309 this->child_inlets[0] = &gain_inlet;
310 this->child_inlets[1] = &pan_inlet;
314#if BOOST_VERSION >= 107200
315static_assert(
noexcept(pan_weight{}));
316static_assert(
noexcept(value_inlet{}));
317static_assert(
noexcept(std::allocator<ossia::outlet>{}));
318static_assert(
noexcept(audio_outlet{}));
321struct OSSIA_EXPORT midi_outlet :
public ossia::outlet
323 midi_outlet() noexcept = default;
325 midi_outlet(destination_t dest) noexcept
326 : outlet{std::move(dest)}
335 midi_outlet(graph_edge& edge)
noexcept { targets.push_back(&edge); }
338 const ossia::midi_port& operator*() const noexcept {
return data; }
339 const ossia::midi_port* operator->() const noexcept {
return &data; }
340 ossia::midi_port& operator*() noexcept {
return data; }
341 ossia::midi_port* operator->() noexcept {
return &data; }
343 [[nodiscard]] std::size_t which() const noexcept final
override
345 return midi_port::which;
348 ossia::midi_port data;
351struct OSSIA_EXPORT value_outlet :
public ossia::outlet
353 value_outlet() noexcept = default;
355 value_outlet(destination_t dest) noexcept
356 : outlet{std::move(dest)}
365 value_outlet(graph_edge& edge)
noexcept { targets.push_back(&edge); }
368 const ossia::value_port& operator*() const noexcept {
return data; }
369 const ossia::value_port* operator->() const noexcept {
return &data; }
370 ossia::value_port& operator*() noexcept {
return data; }
371 ossia::value_port* operator->() noexcept {
return &data; }
373 [[nodiscard]] std::size_t which() const noexcept final
override
375 return value_port::which;
378 ossia::value_port data;
383 static const constexpr int which = 3;
386struct OSSIA_EXPORT texture_inlet :
public ossia::inlet
388 texture_inlet() noexcept = default;
390 texture_inlet(destination_t dest) noexcept
391 : inlet{std::move(dest)}
400 texture_inlet(graph_edge& edge)
noexcept { sources.push_back(&edge); }
404 [[nodiscard]] std::size_t which() const noexcept final
override
406 return texture_port::which;
409 render_target_spec data;
412struct OSSIA_EXPORT texture_outlet :
public ossia::outlet
414 texture_outlet() noexcept = default;
416 texture_outlet(destination_t dest) noexcept
417 : outlet{std::move(dest)}
426 texture_outlet(graph_edge& edge)
noexcept { targets.push_back(&edge); }
429 [[nodiscard]] std::size_t which() const noexcept final
override
431 return texture_port::which;
435struct OSSIA_EXPORT geometry_inlet :
public ossia::inlet
437 geometry_inlet() noexcept = default;
439 geometry_inlet(destination_t dest) noexcept
440 : inlet{std::move(dest)}
449 geometry_inlet(graph_edge& edge)
noexcept { sources.push_back(&edge); }
453 [[nodiscard]] std::size_t which() const noexcept final
override
455 return geometry_port::which;
461struct OSSIA_EXPORT geometry_outlet :
public ossia::outlet
463 geometry_outlet() noexcept = default;
465 geometry_outlet(destination_t dest) noexcept
466 : outlet{std::move(dest)}
475 geometry_outlet(graph_edge& edge)
noexcept { targets.push_back(&edge); }
478 [[nodiscard]] std::size_t which() const noexcept final
override
480 return geometry_port::which;
487inline T* inlet::target() noexcept
489 if constexpr(std::is_same_v<T, audio_port>)
493 return &
static_cast<audio_inlet*
>(
this)->data;
497 return (audio_port*)
nullptr;
500 else if constexpr(std::is_same_v<T, midi_port>)
504 return &
static_cast<midi_inlet*
>(
this)->data;
508 return (midi_port*)
nullptr;
511 else if constexpr(std::is_same_v<T, value_port>)
515 return &
static_cast<value_inlet*
>(
this)->data;
519 return (value_port*)
nullptr;
522 else if constexpr(std::is_same_v<T, texture_inlet>)
526 return static_cast<texture_inlet*
>(
this);
530 return (texture_inlet*)
nullptr;
533 else if constexpr(std::is_same_v<T, geometry_port>)
537 return &
static_cast<geometry_inlet*
>(
this)->data;
541 return (geometry_port*)
nullptr;
546 static_assert(std::is_same_v<T, struct _>,
"Invalid type requested");
551inline T* outlet::target() noexcept
553 if constexpr(std::is_same_v<T, audio_port>)
557 return &
static_cast<audio_outlet*
>(
this)->data;
561 return (audio_port*)
nullptr;
564 else if constexpr(std::is_same_v<T, midi_port>)
568 return &
static_cast<midi_outlet*
>(
this)->data;
572 return (midi_port*)
nullptr;
575 else if constexpr(std::is_same_v<T, value_port>)
579 return &
static_cast<value_outlet*
>(
this)->data;
583 return (value_port*)
nullptr;
586 else if constexpr(std::is_same_v<T, texture_outlet>)
590 return static_cast<texture_outlet*
>(
this);
594 return (texture_outlet*)
nullptr;
597 else if constexpr(std::is_same_v<T, geometry_port>)
601 return &
static_cast<geometry_outlet*
>(
this)->data;
605 return (geometry_port*)
nullptr;
610 static_assert(std::is_same_v<T, struct _>,
"Invalid type requested");
614inline const T* inlet::target() const noexcept
616 if constexpr(std::is_same_v<T, audio_port>)
620 return &
static_cast<const audio_inlet*
>(
this)->data;
624 return (
const audio_port*)
nullptr;
627 else if constexpr(std::is_same_v<T, midi_port>)
631 return &
static_cast<const midi_inlet*
>(
this)->data;
635 return (
const midi_port*)
nullptr;
638 else if constexpr(std::is_same_v<T, value_port>)
642 return &
static_cast<const value_inlet*
>(
this)->data;
646 return (
const value_port*)
nullptr;
649 else if constexpr(std::is_same_v<T, texture_inlet>)
653 return static_cast<const texture_inlet*
>(
this);
657 return (
const texture_inlet*)
nullptr;
660 else if constexpr(std::is_same_v<T, geometry_port>)
664 return &
static_cast<const geometry_inlet*
>(
this)->data;
668 return (
const geometry_port*)
nullptr;
673 static_assert(std::is_same_v<T, struct _>,
"Invalid type requested");
678inline const T* outlet::target() const noexcept
680 if constexpr(std::is_same_v<T, audio_port>)
684 return &
static_cast<const audio_outlet*
>(
this)->data;
688 return (
const audio_port*)
nullptr;
691 else if constexpr(std::is_same_v<T, midi_port>)
695 return &
static_cast<const midi_outlet*
>(
this)->data;
699 return (
const midi_port*)
nullptr;
702 else if constexpr(std::is_same_v<T, value_port>)
706 return &
static_cast<const value_outlet*
>(
this)->data;
710 return (
const value_port*)
nullptr;
713 else if constexpr(std::is_same_v<T, texture_outlet>)
717 return static_cast<const texture_outlet*
>(
this);
721 return (
const texture_outlet*)
nullptr;
724 else if constexpr(std::is_same_v<T, geometry_port>)
728 return &
static_cast<const geometry_outlet*
>(
this)->data;
732 return (
const geometry_port*)
nullptr;
737 static_assert(std::is_same_v<T, struct _>,
"Invalid type requested");
742inline T& inlet::cast() noexcept
744 if constexpr(std::is_same_v<T, audio_port>)
746 return static_cast<audio_inlet*
>(
this)->data;
748 else if constexpr(std::is_same_v<T, midi_port>)
750 return static_cast<midi_inlet*
>(
this)->data;
752 else if constexpr(std::is_same_v<T, value_port>)
754 return static_cast<value_inlet*
>(
this)->data;
756 else if constexpr(std::is_same_v<T, texture_inlet>)
758 return static_cast<texture_inlet&
>(*this);
760 else if constexpr(std::is_same_v<T, geometry_port>)
762 return static_cast<geometry_inlet*
>(
this)->data;
766 static_assert(std::is_same_v<T, struct _>,
"Invalid type requested");
771inline T& outlet::cast() noexcept
773 if constexpr(std::is_same_v<T, audio_port>)
775 return static_cast<audio_outlet*
>(
this)->data;
777 else if constexpr(std::is_same_v<T, midi_port>)
779 return static_cast<midi_outlet*
>(
this)->data;
781 else if constexpr(std::is_same_v<T, value_port>)
783 return static_cast<value_outlet*
>(
this)->data;
785 else if constexpr(std::is_same_v<T, texture_outlet>)
787 return static_cast<texture_outlet&
>(*this);
789 else if constexpr(std::is_same_v<T, geometry_port>)
791 return static_cast<geometry_outlet*
>(
this)->data;
795 static_assert(std::is_same_v<T, struct _>,
"Invalid type requested");
799inline const T& inlet::cast() const noexcept
801 if constexpr(std::is_same_v<T, audio_port>)
803 return static_cast<const audio_inlet*
>(
this)->data;
805 else if constexpr(std::is_same_v<T, midi_port>)
807 return static_cast<const midi_inlet*
>(
this)->data;
809 else if constexpr(std::is_same_v<T, value_port>)
811 return static_cast<const value_inlet*
>(
this)->data;
813 else if constexpr(std::is_same_v<T, texture_inlet>)
815 return static_cast<const texture_inlet&
>(*this);
817 else if constexpr(std::is_same_v<T, geometry_port>)
819 return static_cast<const geometry_inlet*
>(
this)->data;
823 static_assert(std::is_same_v<T, struct _>,
"Invalid type requested");
828inline const T& outlet::cast() const noexcept
830 if constexpr(std::is_same_v<T, audio_port>)
832 return static_cast<const audio_outlet*
>(
this)->data;
834 else if constexpr(std::is_same_v<T, midi_port>)
836 return static_cast<const midi_outlet*
>(
this)->data;
838 else if constexpr(std::is_same_v<T, value_port>)
840 return static_cast<const value_outlet*
>(
this)->data;
842 else if constexpr(std::is_same_v<T, texture_outlet>)
844 return static_cast<const texture_outlet&
>(*this);
846 else if constexpr(std::is_same_v<T, geometry_port>)
848 return static_cast<const geometry_outlet*
>(
this)->data;
852 static_assert(std::is_same_v<T, struct _>,
"Invalid type requested");
857inline auto inlet::visit(
const T& t)
862 return t(
static_cast<audio_inlet*
>(
this)->data);
864 return t(
static_cast<midi_inlet*
>(
this)->data);
866 return t(
static_cast<value_inlet*
>(
this)->data);
869 return t(
static_cast<geometry_inlet*
>(
this)->data);
872 if constexpr(std::is_invocable_v<T>)
877inline auto outlet::visit(
const T& t)
882 return t(
static_cast<audio_outlet*
>(
this)->data);
884 return t(
static_cast<midi_outlet*
>(
this)->data);
886 return t(
static_cast<value_outlet*
>(
this)->data);
889 return t(
static_cast<geometry_outlet*
>(
this)->data);
892 if constexpr(std::is_invocable_v<T>)
896inline auto inlet::visit(
const T& t)
const
901 return t(
static_cast<const audio_inlet*
>(
this)->data);
903 return t(
static_cast<const midi_inlet*
>(
this)->data);
905 return t(
static_cast<const value_inlet*
>(
this)->data);
908 return t(
static_cast<const geometry_inlet*
>(
this)->data);
911 if constexpr(std::is_invocable_v<T>)
915inline auto outlet::visit(
const T& t)
const
920 return t(
static_cast<const audio_outlet*
>(
this)->data);
922 return t(
static_cast<const midi_outlet*
>(
this)->data);
924 return t(
static_cast<const value_outlet*
>(
this)->data);
927 return t(
static_cast<const geometry_outlet*
>(
this)->data);
930 if constexpr(std::is_invocable_v<T>)
The parameter_base class.
Definition ossia/network/base/parameter.hpp:48