Loading...
Searching...
No Matches
InterpolateStates.hpp
1#pragma once
2#include <State/Address.hpp>
3
4#include <Device/Address/AddressSettings.hpp>
5#include <Device/Node/DeviceNode.hpp>
6
7#include <Curve/CurveModel.hpp>
8
9#include <ossia/network/domain/domain.hpp>
10#include <ossia/network/value/value_conversion.hpp>
11
12#include <QList>
13
14namespace score
15{
16class CommandStackFacade;
17struct DocumentContext;
18}
19
20namespace Scenario
21{
22class IntervalModel;
23namespace Command
24{
25void InterpolateStates(
26 const std::vector<const IntervalModel*>&, const score::CommandStackFacade&);
27}
28
30{
31 template <std::size_t N>
32 std::size_t operator()(const std::array<float, N>& arr)
33 {
34 return N;
35 }
36
37 std::size_t operator()(const std::vector<ossia::value>& arr) { return arr.size(); }
38
39 std::size_t operator()() { return 0; }
40
41 template <typename T>
42 std::size_t operator()(const T& other)
43 {
44 throw std::runtime_error("invalid type, should not happen");
45 }
46};
47
49{
50 const State::AddressAccessor& address;
51 const ossia::destination_index& idx;
52 const Device::Node& rootNode;
53
54 template <std::size_t N>
56 operator()(const std::array<float, N>& start, const std::array<float, N>& end)
57 {
58 SCORE_ASSERT(!idx.empty());
59 const auto i = idx[0];
60 Curve::CurveDomain d{start[i], end[i]};
61
62 if(auto node = Device::try_getNodeFromAddress(rootNode, address.address))
63 {
64 const Device::AddressSettings& as = node->get<Device::AddressSettings>();
65
66 if(auto dom = as.domain.get().v.target<ossia::vecf_domain<N>>())
67 {
68 if(auto min_v = dom->min[i])
69 d.min = std::min(d.min, (double)*min_v);
70 if(auto max_v = dom->max[i])
71 d.max = std::max(d.max, (double)*max_v);
72 }
73 }
74
75 return d;
76 }
77
78 Curve::CurveDomain operator()(
79 const std::vector<ossia::value>& start, const std::vector<ossia::value>& end)
80 {
81 SCORE_ASSERT(!idx.empty());
82 const auto i = (std::size_t)idx[0];
84 ossia::convert<double>(start[i]), ossia::convert<double>(end[i])};
85
86 if(auto node = Device::try_getNodeFromAddress(rootNode, address.address))
87 {
88 const Device::AddressSettings& as = node->get<Device::AddressSettings>();
89
90 if(auto dom = as.domain.get().v.target<ossia::vector_domain>())
91 {
92 if(dom->min.size() > i)
93 d.min = std::min(d.min, ossia::convert<double>(dom->min[i]));
94 if(dom->max.size() > i)
95 d.max = std::max(d.max, ossia::convert<double>(dom->max[i]));
96 }
97 }
98
99 return d;
100 }
101
103 operator()(const ossia::value_map_type& start, const ossia::value_map_type& end)
104 {
105 return {};
106 }
107
108 template <typename T>
109 Curve::CurveDomain operator()(const T& start, const T& end)
110 {
111 Curve::CurveDomain d{(double)start, (double)end};
112
113 if(auto node = Device::try_getNodeFromAddress(rootNode, address.address))
114 {
115 const Device::AddressSettings& as = node->get<Device::AddressSettings>();
116
117 d.refine(as.domain.get());
118 }
119
120 return d;
121 }
122
123 Curve::CurveDomain operator()(ossia::impulse start, ossia::impulse end) { return {}; }
124
125 Curve::CurveDomain operator()(const std::string& start, const std::string& end)
126 {
127 return {};
128 }
129
130 template <typename T, typename U>
131 Curve::CurveDomain operator()(const T& start, const U& end)
132 {
133 return {};
134 }
135};
136
138{
139 const ossia::destination_index& idx;
140
141 template <std::size_t N>
142 std::pair<double, double>
143 operator()(const std::array<float, N>& start, const std::array<float, N>& end)
144 {
145 SCORE_ASSERT(!idx.empty());
146 const auto i = idx[0];
147 return {(double)start[i], (double)end[i]};
148 }
149
150 std::pair<double, double> operator()(
151 const std::vector<ossia::value>& start, const std::vector<ossia::value>& end)
152 {
153 SCORE_ASSERT(!idx.empty());
154 const auto i = idx[0];
155 return {ossia::convert<double>(start[i]), ossia::convert<double>(end[i])};
156 }
157
158 template <typename T>
159 std::pair<double, double> operator()(const T& start, const T& end)
160 {
161 return {(double)start, (double)end};
162 }
163
164 std::pair<double, double> operator()(ossia::impulse start, ossia::impulse end)
165 {
166 return {0., 1.};
167 }
168
169 std::pair<double, double> operator()(const std::string& start, const std::string& end)
170 {
171 return {0., 1.};
172 }
173
174 template <typename T, typename U>
175 std::pair<double, double> operator()(const T& start, const U& end)
176 {
177 return {0., 1.};
178 }
179};
180}
A small abstraction layer over the score::CommandStack.
Definition CommandStackFacade.hpp:20
Main plug-in of score.
Definition score-plugin-dataflow/Dataflow/PortItem.hpp:13
Base toolkit upon which the software is built.
Definition Application.cpp:90
Definition CurveModel.hpp:104
Definition AddressSettings.hpp:49
Definition InterpolateStates.hpp:49
Definition InterpolateStates.hpp:138
Definition InterpolateStates.hpp:30
Definition Address.hpp:108