CurveSegmentModel.hpp
1 #pragma once
2 #include <Curve/Palette/CurvePoint.hpp>
3 #include <Curve/Segment/CurveSegmentData.hpp>
4 
5 #include <score/model/IdentifiedObject.hpp>
6 #include <score/model/Identifier.hpp>
7 #include <score/plugins/SerializableInterface.hpp>
8 #include <score/selection/Selectable.hpp>
9 #include <score/serialization/VisitorInterface.hpp>
10 #include <score/tools/std/Optional.hpp>
11 
12 #include <ossia/editor/curve/curve_segment.hpp>
13 
14 #include <boost/align/aligned_allocator_adaptor.hpp>
15 
16 #include <QPoint>
17 #include <QVariant>
18 
19 #include <score_plugin_curve_export.h>
20 
21 #include <functional>
22 #include <vector>
23 #include <verdigris>
24 
25 class QObject;
26 namespace Curve
27 {
28 // Gives the data.
29 class SCORE_PLUGIN_CURVE_EXPORT SegmentModel
30  : public IdentifiedObject<SegmentModel>
31  , public score::SerializableInterface<SegmentFactory>
32 {
33  W_OBJECT(SegmentModel)
34 
35  SCORE_SERIALIZE_FRIENDS
36 public:
37  using data_vector = std::vector<
38  QPointF, boost::alignment::aligned_allocator_adaptor<std::allocator<QPointF>, 32>>;
39  Selectable selection{this};
40  SegmentModel(const Id<SegmentModel>& id, QObject* parent);
41  SegmentModel(const SegmentData& id, QObject* parent);
42 
43  // Used for cloning :
44  // Previous and following shall be set afterwards by the cloner.
46  Curve::Point s, Curve::Point e, const Id<SegmentModel>& id, QObject* parent);
47 
48  SegmentModel(DataStream::Deserializer& vis, QObject* parent);
49  SegmentModel(JSONObject::Deserializer& vis, QObject* parent);
50 
51  virtual ~SegmentModel();
52 
53  virtual void updateData(int numInterp) const = 0; // Will interpolate.
54  virtual double valueAt(double x) const = 0;
55 
56  const data_vector& data() const { return m_data; }
57 
58  void setStart(const Curve::Point& pt);
59  Curve::Point start() const { return m_start; }
60 
61  void setEnd(const Curve::Point& pt);
62  Curve::Point end() const { return m_end; }
63 
64  void setPrevious(const OptionalId<SegmentModel>& previous);
65  const OptionalId<SegmentModel>& previous() const { return m_previous; }
66 
67  void setFollowing(const OptionalId<SegmentModel>& following);
68  const OptionalId<SegmentModel>& following() const { return m_following; }
69 
70  // Between -1 and 1, to map to the real parameter.
71  virtual void setVerticalParameter(double p);
72  virtual void setHorizontalParameter(double p);
73  virtual std::optional<double> verticalParameter() const;
74  virtual std::optional<double> horizontalParameter() const;
75 
76  virtual ossia::curve_segment<double> makeDoubleFunction() const = 0;
77  virtual ossia::curve_segment<float> makeFloatFunction() const = 0;
78  virtual ossia::curve_segment<int> makeIntFunction() const = 0;
79 
80  SegmentData toSegmentData() const
81  {
82  return {id(),
83  start(),
84  end(),
85  previous(),
86  following(),
87  concreteKey(),
88  toSegmentSpecificData()};
89  }
90 
91 public:
92  void dataChanged() E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, dataChanged)
93  void previousChanged() E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, previousChanged)
94  void followingChanged() E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, followingChanged)
95  void startChanged() E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, startChanged)
96  void endChanged() E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, endChanged)
97 
98 protected:
99  virtual void on_startChanged() = 0;
100  virtual void on_endChanged() = 0;
101 
102  virtual QVariant toSegmentSpecificData() const = 0;
103 
104  mutable data_vector m_data; // A data cache.
105  mutable bool m_valid{}; // Used to perform caching.
106  // TODO it seems that m_valid is never true.
107 
108  Curve::Point m_start, m_end;
109 
110 private:
111  OptionalId<SegmentModel> m_previous, m_following;
112 };
113 
114 class PowerSegment;
115 struct PowerSegmentData;
116 
117 using DefaultCurveSegmentModel = PowerSegment;
118 using DefaultCurveSegmentData = PowerSegmentData;
119 }
120 
121 OBJECTKEY_METADATA(SCORE_PLUGIN_CURVE_EXPORT, Curve::SegmentModel, "CurveSegmentModel")
122 
123 // extern template class SCORE_PLUGIN_CURVE_EXPORT
124 // IdContainer<Curve::SegmentModel>;
125 
126 W_REGISTER_ARGTYPE(const Curve::SegmentModel*)
127 W_REGISTER_ARGTYPE(Id<Curve::SegmentModel>)
Definition: CurveSegmentModel.hpp:32
Definition: DataStreamVisitor.hpp:202
The IdentifiedObject class.
Definition: IdentifiedObject.hpp:19
Definition: JSONVisitor.hpp:423
The Selectable class.
Definition: Selectable.hpp:14
The id_base_t class.
Definition: Identifier.hpp:57
Generic serialization method for abstract classes.
Definition: SerializableInterface.hpp:21
Utilities and base classes for 1D curves.
Definition: FocusDispatcher.hpp:12
Definition: CurveSegmentData.hpp:63