Loading...
Searching...
No Matches
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.hpp>
15
16#include <QPoint>
17#include <QVariant>
18
19#include <score_plugin_curve_export.h>
20
21#include <vector>
22#include <verdigris>
23
24class QObject;
25namespace Curve
26{
27class PointModel;
28// Gives the data.
29class SCORE_PLUGIN_CURVE_EXPORT SegmentModel
30 : public IdentifiedObject<SegmentModel>
31 , public score::SerializableInterface<SegmentFactory>
32{
33 W_OBJECT(SegmentModel)
34
35 SCORE_SERIALIZE_FRIENDS
36public:
37 using data_vector
38 = std::vector<QPointF, boost::alignment::aligned_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
72 virtual void setSpecificData(const QVariant& data);
73 virtual bool specificDataEquals(const QVariant& data) const noexcept;
74
75 // Between -1 and 1, to map to the real parameter.
76 virtual void setVerticalParameter(double p);
77 virtual void setHorizontalParameter(double p);
78 virtual std::optional<double> verticalParameter() const;
79 virtual std::optional<double> horizontalParameter() const;
80
81 virtual ossia::curve_segment<double> makeDoubleFunction() const = 0;
82 virtual ossia::curve_segment<float> makeFloatFunction() const = 0;
83 virtual ossia::curve_segment<int> makeIntFunction() const = 0;
84
87 virtual ossia::curve_segment<double>
88 makeScaledDoubleFunction(double offset, double factor) const;
89 virtual ossia::curve_segment<float>
90 makeScaledFloatFunction(double offset, double factor) const;
91 virtual ossia::curve_segment<int>
92 makeScaledIntFunction(double offset, double factor) const;
93
94 SegmentData toSegmentData() const
95 {
96 return {id(),
97 start(),
98 end(),
99 previous(),
100 following(),
101 concreteKey(),
102 toSegmentSpecificData()};
103 }
104
105public:
106 void dataChanged() E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, dataChanged)
107 void previousChanged() E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, previousChanged)
108 void followingChanged() E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, followingChanged)
109 void startChanged() E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, startChanged)
110 void endChanged() E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, endChanged)
111
112protected:
113 virtual void on_startChanged() = 0;
114 virtual void on_endChanged() = 0;
115
116 virtual QVariant toSegmentSpecificData() const = 0;
117
118 mutable data_vector m_data; // A data cache.
119 mutable bool m_valid{}; // Used to perform caching.
120 // TODO it seems that m_valid is never true.
121
122 Curve::Point m_start, m_end;
123
124private:
125 friend class Model;
126 OptionalId<SegmentModel> m_previous, m_following;
127 // Kept by Model: the points that setStart / setEnd move along.
128 PointModel* m_startPoint{};
129 PointModel* m_endPoint{};
130};
131
132class PowerSegment;
133struct PowerSegmentData;
134
135using DefaultCurveSegmentModel = PowerSegment;
136using DefaultCurveSegmentData = PowerSegmentData;
137}
138
139OBJECTKEY_METADATA(SCORE_PLUGIN_CURVE_EXPORT, Curve::SegmentModel, "CurveSegmentModel")
140
141// extern template class SCORE_PLUGIN_CURVE_EXPORT
142// IdContainer<Curve::SegmentModel>;
143
144W_REGISTER_ARGTYPE(const Curve::SegmentModel*)
145W_REGISTER_ARGTYPE(Id<Curve::SegmentModel>)
Definition CurveModel.hpp:26
Definition CurvePointModel.hpp:18
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:59
Generic serialization method for abstract classes.
Definition SerializableInterface.hpp:21
Utilities and base classes for 1D curves.
Definition FocusDispatcher.hpp:12
Definition CurveSegmentData.hpp:66