EasingSegment.hpp
1 #pragma once
2 #include <Curve/Segment/CurveSegmentFactory.hpp>
3 #include <Curve/Segment/CurveSegmentModel.hpp>
4 
5 #include <ossia/editor/curve/curve_segment/easing.hpp>
6 
7 namespace Curve
8 {
9 struct EasingData
10 {
11 };
12 
13 template <typename Easing_T>
15 {
16 public:
17  key_type concreteKey() const noexcept final override
18  {
20  }
21 
22  void serialize_impl(const VisitorVariant& vis) const override { }
23 
24  using data_type = EasingData;
25  EasingSegment(const Id<SegmentModel>& id, QObject* parent)
26  : Curve::SegmentModel{id, parent}
27  {
28  }
29  EasingSegment(const Curve::SegmentData& dat, QObject* parent)
30  : Curve::SegmentModel{dat, parent}
31  {
32  }
33 
35  const EasingSegment& other, const Curve::SegmentModel::id_type& id,
36  QObject* parent)
37  : Curve::SegmentModel{other.start(), other.end(), id, parent}
38  {
39  }
40 
41  EasingSegment(DataStream::Deserializer& vis, QObject* parent)
42  : Curve::SegmentModel{vis, parent}
43  {
44  }
45  EasingSegment(JSONObject::Deserializer& vis, QObject* parent)
46  : Curve::SegmentModel{vis, parent}
47  {
48  }
49 
50  void on_startChanged() override { dataChanged(); }
51  void on_endChanged() override { dataChanged(); }
52 
53  void updateData(int numInterp) const override
54  {
55  if(std::size_t(numInterp + 1) != m_data.size())
56  m_valid = false;
57  if(!m_valid)
58  {
59  m_data.resize(numInterp + 1);
60 
61  double start_x = start().x();
62  double end_x = end().x();
63 
64  double start_y = start().y();
65  double end_y = end().y();
66  for(int j = 0; j <= numInterp; j++)
67  {
68  QPointF& pt = m_data[j];
69  pt.setX(start_x + (double(j) / numInterp) * (end_x - start_x));
70  pt.setY(start_y + (end_y - start_y) * Easing_T{}(double(j) / numInterp));
71  }
72  }
73  }
74 
75  double valueAt(double x) const override
76  {
77  return start().y()
78  + (end().y() - start().y()) * (Easing_T{}(x)-start().x())
79  / (end().x() - start().x());
80  }
81 
82  std::optional<double> verticalParameter() const override { return {}; }
83  std::optional<double> horizontalParameter() const override { return {}; }
84  void setVerticalParameter(double p) override { }
85  void setHorizontalParameter(double p) override { }
86 
87  QVariant toSegmentSpecificData() const override
88  {
89  return QVariant::fromValue(EasingData{});
90  }
91 
92  template <typename Y>
93  ossia::curve_segment<Y> makeFunction() const
94  {
95  return ossia::curve_segment_ease<Y, Easing_T>{};
96  }
97  ossia::curve_segment<double> makeDoubleFunction() const override
98  {
99  return makeFunction<double>();
100  }
101  ossia::curve_segment<float> makeFloatFunction() const override
102  {
103  return makeFunction<float>();
104  }
105  ossia::curve_segment<int> makeIntFunction() const override
106  {
107  return makeFunction<int>();
108  }
109 };
141 }
142 
143 template <>
144 inline void DataStreamReader::read(const Curve::EasingData& segmt)
145 {
146 }
147 
148 template <>
149 inline void DataStreamWriter::write(Curve::EasingData& segmt)
150 {
151 }
152 
153 template <>
154 inline void JSONReader::read(const Curve::EasingData& segmt)
155 {
156 }
157 
158 template <>
159 inline void JSONWriter::write(Curve::EasingData& segmt)
160 {
161 }
162 
163 SCORE_SERIALIZE_DATASTREAM_DECLARE(, Curve::EasingData)
164 Q_DECLARE_METATYPE(Curve::EasingData)
165 W_REGISTER_ARGTYPE(Curve::EasingData)
166 
167 // cat easings | xargs -L1 bash -c 'echo $(uuidgen)' | paste - easings | sed
168 // 's/\t/ /' > easings2
169 // cat easings2 | awk '{ print
170 // "CURVE_SEGMENT_METADATA(,
171 // Curve::Segment_" $2 ">, \"" $1 "\", \"" $2 "\", \"" $2 "\")";}
172 // '
173 
174 CURVE_SEGMENT_METADATA(
175  , Curve::Segment_backIn, "fb5cb6c1-47fd-497c-9d69-7a87adbaf3b3", "backIn", "backIn",
176  "Easing")
177 CURVE_SEGMENT_METADATA(
178  , Curve::Segment_backOut, "0edbd8f5-67c2-41f2-ae80-f014e5c24aa6", "backOut",
179  "backOut", "Easing")
180 CURVE_SEGMENT_METADATA(
181  , Curve::Segment_backInOut, "3825c351-698d-4930-9862-28c5f7f51c61", "backInOut",
182  "backInOut", "Easing")
183 CURVE_SEGMENT_METADATA(
184  , Curve::Segment_bounceIn, "51fafa98-aa8e-48f0-adae-c21c3eeb63ca", "bounceIn",
185  "bounceIn", "Easing")
186 CURVE_SEGMENT_METADATA(
187  , Curve::Segment_bounceOut, "75ce6961-22b3-4a9e-b989-3131098bd092", "bounceOut",
188  "bounceOut", "Easing")
189 CURVE_SEGMENT_METADATA(
190  , Curve::Segment_bounceInOut, "30d5c3dc-5a8c-44a8-95b4-67ca3ff5088b", "bounceInOut",
191  "bounceInOut", "Easing")
192 CURVE_SEGMENT_METADATA(
193  , Curve::Segment_quadraticIn, "a2f38b24-f2c9-42d7-bb5e-a51a821d2ffd", "quadraticIn",
194  "quadraticIn", "Easing")
195 CURVE_SEGMENT_METADATA(
196  , Curve::Segment_quadraticOut, "9717560b-fae1-4035-afbf-031f3581d132",
197  "quadraticOut", "quadraticOut", "Easing")
198 CURVE_SEGMENT_METADATA(
199  , Curve::Segment_quadraticInOut, "fc333d55-064a-4af8-b4a8-23fe16e80ecc",
200  "quadraticInOut", "quadraticInOut", "Easing")
201 CURVE_SEGMENT_METADATA(
202  , Curve::Segment_cubicIn, "b6bddf8b-b2cb-46d6-8d90-31b3029317e8", "cubicIn",
203  "cubicIn", "Easing")
204 CURVE_SEGMENT_METADATA(
205  , Curve::Segment_cubicOut, "ff9a7726-2d8f-43f2-a95c-e395fdbd5aa9", "cubicOut",
206  "cubicOut", "Easing")
207 CURVE_SEGMENT_METADATA(
208  , Curve::Segment_cubicInOut, "21556d2a-ac8a-4acf-bf42-5eca9795047c", "cubicInOut",
209  "cubicInOut", "Easing")
210 CURVE_SEGMENT_METADATA(
211  , Curve::Segment_quarticIn, "72678775-535f-438e-b4bb-1077af3fab99", "quarticIn",
212  "quarticIn", "Easing")
213 CURVE_SEGMENT_METADATA(
214  , Curve::Segment_quarticOut, "bd6f4867-2c30-4267-aa97-0ed767883d22", "quarticOut",
215  "quarticOut", "Easing")
216 CURVE_SEGMENT_METADATA(
217  , Curve::Segment_quarticInOut, "93cac01a-dedc-4cb4-ad2d-d81b31e6187c",
218  "quarticInOut", "quarticInOut", "Easing")
219 CURVE_SEGMENT_METADATA(
220  , Curve::Segment_quinticIn, "cd08eabe-51a4-429e-8740-c097c1b34b83", "quinticIn",
221  "quinticIn", "Easing")
222 CURVE_SEGMENT_METADATA(
223  , Curve::Segment_quinticOut, "cb6e340b-faee-440c-8ef5-05ec6f7f4791", "quinticOut",
224  "quinticOut", "Easing")
225 CURVE_SEGMENT_METADATA(
226  , Curve::Segment_quinticInOut, "b2cce6a7-c651-429f-ae46-d322991e92d4",
227  "quinticInOut", "quinticInOut", "Easing")
228 CURVE_SEGMENT_METADATA(
229  , Curve::Segment_sineIn, "e8a44b49-4d91-4066-8e25-7669d8927792", "sineIn", "sineIn",
230  "Easing")
231 CURVE_SEGMENT_METADATA(
232  , Curve::Segment_sineOut, "e5d2dea4-061e-4139-8da2-1d21b0414273", "sineOut",
233  "sineOut", "Easing")
234 CURVE_SEGMENT_METADATA(
235  , Curve::Segment_sineInOut, "61bd1bb4-353b-435f-8b4c-ed61ed43bcf9", "sineInOut",
236  "sineInOut", "Easing")
237 CURVE_SEGMENT_METADATA(
238  , Curve::Segment_circularIn, "45b06858-2e16-4cdc-82cc-70f8545bab03", "circularIn",
239  "circularIn", "Easing")
240 CURVE_SEGMENT_METADATA(
241  , Curve::Segment_circularOut, "32a67b2a-61f5-49cd-b1c4-37419350fca8", "circularOut",
242  "circularOut", "Easing")
243 CURVE_SEGMENT_METADATA(
244  , Curve::Segment_circularInOut, "b70a58f2-2fff-4fda-b1fa-cad6c7c11b88",
245  "circularInOut", "circularInOut", "Easing")
246 CURVE_SEGMENT_METADATA(
247  , Curve::Segment_exponentialIn, "8db88491-bed5-4a0d-bcb6-45811c5a7722",
248  "exponentialIn", "exponentialIn", "Easing")
249 CURVE_SEGMENT_METADATA(
250  , Curve::Segment_exponentialOut, "40f17c1a-9611-4468-b114-c6338fb0fbb7",
251  "exponentialOut", "exponentialOut", "Easing")
252 CURVE_SEGMENT_METADATA(
253  , Curve::Segment_exponentialInOut, "46224c2f-f60d-4f60-93b8-a0ebe6931d00",
254  "exponentialInOut", "exponentialInOut", "Easing")
255 CURVE_SEGMENT_METADATA(
256  , Curve::Segment_elasticIn, "6e301164-e079-466b-a518-12fe89048283", "elasticIn",
257  "elasticIn", "Easing")
258 CURVE_SEGMENT_METADATA(
259  , Curve::Segment_elasticOut, "1f1fddd4-7a23-4c15-a3ec-6e88e9787a97", "elasticOut",
260  "elasticOut", "Easing")
261 CURVE_SEGMENT_METADATA(
262  , Curve::Segment_elasticInOut, "8bad1486-b616-4ebe-aa5e-844162545f8b",
263  "elasticInOut", "elasticInOut", "Easing")
264 CURVE_SEGMENT_METADATA(
265  , Curve::Segment_perlinInOut, "66cf32a5-86c5-4747-89d4-523e26dcc1fc", "perlinInOut",
266  "perlinInOut", "Easing")
Definition: EasingSegment.hpp:15
Definition: CurveSegmentModel.hpp:32
void read(const T &)
Definition: DataStreamVisitor.hpp:202
Definition: JSONVisitor.hpp:423
Definition: UuidKey.hpp:343
The id_base_t class.
Definition: Identifier.hpp:57
Utilities and base classes for 1D curves.
Definition: FocusDispatcher.hpp:12
Definition: EasingSegment.hpp:10
Definition: CurveSegmentData.hpp:63
Static metadata implementation.
Definition: lib/score/tools/Metadata.hpp:36
The VisitorVariant struct.
Definition: VisitorInterface.hpp:26