2#include <ossia/detail/apply.hpp>
6#include <ossia/misc_visitors.hpp>
10struct mapper_compute_visitor
12 ossia::value operator()(
float driver,
const std::shared_ptr<curve_abstract>& c)
14 auto base_curve = c.get();
15 auto t = base_curve->get_type();
19 case ossia::curve_segment_type::FLOAT: {
20 auto c =
static_cast<curve<float, float>*
>(base_curve);
21 return float{c->value_at(driver)};
23 case ossia::curve_segment_type::INT: {
24 auto c =
static_cast<curve<float, int>*
>(base_curve);
25 return int32_t{c->value_at(driver)};
27 case ossia::curve_segment_type::BOOL: {
28 auto c =
static_cast<curve<float, bool>*
>(base_curve);
29 return bool{c->value_at(driver)};
31 case ossia::curve_segment_type::DOUBLE:
32 case ossia::curve_segment_type::ANY:
38 ossia::value operator()(int32_t driver,
const std::shared_ptr<curve_abstract>& c)
40 auto base_curve = c.get();
41 auto t = base_curve->get_type();
45 case ossia::curve_segment_type::FLOAT: {
46 auto c =
static_cast<curve<float, float>*
>(base_curve);
47 return float{c->value_at(driver)};
49 case ossia::curve_segment_type::INT: {
50 auto c =
static_cast<curve<float, int>*
>(base_curve);
51 return int32_t{c->value_at(driver)};
53 case ossia::curve_segment_type::BOOL: {
54 auto c =
static_cast<curve<float, bool>*
>(base_curve);
55 return bool{c->value_at(driver)};
57 case ossia::curve_segment_type::DOUBLE:
58 case ossia::curve_segment_type::ANY:
64 ossia::value operator()(
bool driver,
const std::shared_ptr<curve_abstract>& c)
66 auto base_curve = c.get();
67 auto t = base_curve->get_type();
71 case ossia::curve_segment_type::FLOAT: {
72 auto c =
static_cast<curve<bool, float>*
>(base_curve);
73 return float{c->value_at(driver)};
75 case ossia::curve_segment_type::INT: {
76 auto c =
static_cast<curve<bool, int>*
>(base_curve);
77 return int32_t{c->value_at(driver)};
79 case ossia::curve_segment_type::BOOL: {
80 auto c =
static_cast<curve<bool, bool>*
>(base_curve);
81 return bool{c->value_at(driver)};
83 case ossia::curve_segment_type::DOUBLE:
84 case ossia::curve_segment_type::ANY:
91 const std::vector<ossia::value>& t_driver,
92 const std::shared_ptr<curve_abstract>& c)
94 std::vector<ossia::value> t_value = t_driver;
95 for(
auto& v : t_value)
99 v = ossia::apply_nonnull(
100 [&](
const auto& e) {
return this->operator()(e, c); }, std::move(v.v));
107 template <std::
size_t N>
109 operator()(std::array<float, N> driver,
const std::shared_ptr<curve_abstract>& c)
111 auto base_curve = c.get();
112 auto t = base_curve->get_type();
113 if(t.first == ossia::curve_segment_type::FLOAT
114 && t.second == ossia::curve_segment_type::FLOAT)
116 auto c =
static_cast<curve<float, float>*
>(base_curve);
117 for(std::size_t i = 0; i < N; i++)
119 driver[i] = c->value_at(driver[i]);
129 template <std::
size_t N>
131 operator()(std::array<float, N> driver,
const std::vector<ossia::behavior>& t_drive)
133 if(t_drive.size() != N)
136 for(std::size_t i = 0; i < N; i++)
138 auto curve_p = t_drive[i].target<std::shared_ptr<curve_abstract>>();
142 auto c = curve_p->get();
146 auto t = c->get_type();
147 if(t.first == ossia::curve_segment_type::FLOAT
148 && t.second == ossia::curve_segment_type::FLOAT)
149 driver[i] =
static_cast<curve<float, float>*
>(c)->value_at(driver[i]);
158 const std::vector<ossia::value>& t_driver,
159 const std::vector<ossia::behavior>& t_drive)
161 std::vector<ossia::value> t_value;
162 t_value.reserve(t_drive.size());
163 auto it_driver = t_driver.begin();
165 for(
const auto& e_drive : t_drive)
167 if(it_driver == t_driver.end())
170 if(it_driver->valid() && e_drive)
172 t_value.push_back(ossia::apply(*
this, it_driver->v, e_drive.v));
176 t_value.emplace_back();
184 template <
typename T,
typename U>
185 ossia::value operator()(
const T& driver,
const U& t_drive)
187 throw invalid_value_type_error(
188 "mapper_compute_visitor_2: "
The value class.
Definition value.hpp:173
Definition transitive_closure.hpp:27