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{
27// Gives the data.
28class SCORE_PLUGIN_CURVE_EXPORT SegmentModel
29 : public IdentifiedObject<SegmentModel>
30 , public score::SerializableInterface<SegmentFactory>
31{
32 W_OBJECT(SegmentModel)
33
34 SCORE_SERIALIZE_FRIENDS
35public:
36 using data_vector
37 = std::vector<QPointF, boost::alignment::aligned_allocator<QPointF, 32>>;
38 Selectable selection{this};
39 SegmentModel(const Id<SegmentModel>& id, QObject* parent);
40 SegmentModel(const SegmentData& id, QObject* parent);
41
42 // Used for cloning :
43 // Previous and following shall be set afterwards by the cloner.
45 Curve::Point s, Curve::Point e, const Id<SegmentModel>& id, QObject* parent);
46
47 SegmentModel(DataStream::Deserializer& vis, QObject* parent);
48 SegmentModel(JSONObject::Deserializer& vis, QObject* parent);
49
50 virtual ~SegmentModel();
51
52 virtual void updateData(int numInterp) const = 0; // Will interpolate.
53 virtual double valueAt(double x) const = 0;
54
55 const data_vector& data() const { return m_data; }
56
57 void setStart(const Curve::Point& pt);
58 Curve::Point start() const { return m_start; }
59
60 void setEnd(const Curve::Point& pt);
61 Curve::Point end() const { return m_end; }
62
63 void setPrevious(const OptionalId<SegmentModel>& previous);
64 const OptionalId<SegmentModel>& previous() const { return m_previous; }
65
66 void setFollowing(const OptionalId<SegmentModel>& following);
67 const OptionalId<SegmentModel>& following() const { return m_following; }
68
69 // Between -1 and 1, to map to the real parameter.
70 virtual void setVerticalParameter(double p);
71 virtual void setHorizontalParameter(double p);
72 virtual std::optional<double> verticalParameter() const;
73 virtual std::optional<double> horizontalParameter() const;
74
75 virtual ossia::curve_segment<double> makeDoubleFunction() const = 0;
76 virtual ossia::curve_segment<float> makeFloatFunction() const = 0;
77 virtual ossia::curve_segment<int> makeIntFunction() const = 0;
78
79 SegmentData toSegmentData() const
80 {
81 return {id(),
82 start(),
83 end(),
84 previous(),
85 following(),
86 concreteKey(),
87 toSegmentSpecificData()};
88 }
89
90public:
91 void dataChanged() E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, dataChanged)
92 void previousChanged() E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, previousChanged)
93 void followingChanged() E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, followingChanged)
94 void startChanged() E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, startChanged)
95 void endChanged() E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, endChanged)
96
97protected:
98 virtual void on_startChanged() = 0;
99 virtual void on_endChanged() = 0;
100
101 virtual QVariant toSegmentSpecificData() const = 0;
102
103 mutable data_vector m_data; // A data cache.
104 mutable bool m_valid{}; // Used to perform caching.
105 // TODO it seems that m_valid is never true.
106
107 Curve::Point m_start, m_end;
108
109private:
110 OptionalId<SegmentModel> m_previous, m_following;
111};
112
113class PowerSegment;
114struct PowerSegmentData;
115
116using DefaultCurveSegmentModel = PowerSegment;
117using DefaultCurveSegmentData = PowerSegmentData;
118}
119
120OBJECTKEY_METADATA(SCORE_PLUGIN_CURVE_EXPORT, Curve::SegmentModel, "CurveSegmentModel")
121
122// extern template class SCORE_PLUGIN_CURVE_EXPORT
123// IdContainer<Curve::SegmentModel>;
124
125W_REGISTER_ARGTYPE(const Curve::SegmentModel*)
126W_REGISTER_ARGTYPE(Id<Curve::SegmentModel>)
Definition CurveSegmentModel.hpp:31
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:63