Loading...
Searching...
No Matches
CurveModel.hpp
1#pragma once
2#include <Curve/Segment/CurveSegmentModel.hpp>
3
4#include <score/model/IdentifiedObject.hpp>
5#include <score/model/IdentifiedObjectMap.hpp>
6#include <score/model/Identifier.hpp>
7#include <score/serialization/VisitorInterface.hpp>
8
9#include <score_plugin_curve_export.h>
10
11#include <span>
12#include <vector>
13#include <verdigris>
14
15class Selection;
16namespace ossia
17{
18struct domain;
19class value;
20}
21namespace Curve
22{
23class PointModel;
24struct SegmentData;
25class SCORE_PLUGIN_CURVE_EXPORT Model final : public IdentifiedObject<Model>
26{
27 SCORE_SERIALIZE_FRIENDS
28 W_OBJECT(Model)
29public:
30 Model(const Id<Model>&, QObject* parent);
31 ~Model();
32
33 template <typename Impl>
34 Model(Impl& vis, QObject* parent)
35 : IdentifiedObject{vis, parent}
36 {
37 vis.writeTo(*this);
38 }
39
42 void addSegment(SegmentModel* m);
43 void insertSegment(SegmentModel*);
44 void removeSegment(SegmentModel* m);
45
47 void loadSegments(const std::vector<SegmentModel*>& models);
48
50 const std::vector<SegmentModel*>& sortedSegments() const noexcept;
51
52 std::vector<SegmentData> toCurveData() const;
54 void toCurveData(std::vector<SegmentData>& out) const;
55
58 void fromCurveData(const std::vector<SegmentData>& curve);
59
63 void applyChanges(
64 std::span<const Id<SegmentModel>> removed,
65 std::span<const SegmentData* const> upserted);
66
67 Selection selectedChildren() const;
68 void setSelection(const Selection& s);
69
70 void clear();
71
72 const auto& segments() const { return m_segments; }
73 auto& segments() { return m_segments; }
74
76 const std::vector<PointModel*>& points() const;
77 std::vector<PointModel*>& points() { return m_points; }
78
79 double lastPointPos() const;
80
81 std::optional<double> valueAt(double x) const noexcept;
82
83public:
84 void segmentAdded(const SegmentModel* arg_1)
85 E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, segmentAdded, arg_1)
86 void segmentRemoved(const Id<SegmentModel>& arg_1) E_SIGNAL(
87 SCORE_PLUGIN_CURVE_EXPORT, segmentRemoved,
88 arg_1) // dangerous if async
89
90 // This signal has to be emitted after big modifications.
91 // (it's an optimization to prevent updating the OSSIA API each time a
92 // segment moves).
93 void changed() E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, changed)
94 void curveReset() E_SIGNAL(
95 SCORE_PLUGIN_CURVE_EXPORT,
96 curveReset) // like changed() but for the presenter
97 void cleared() E_SIGNAL(SCORE_PLUGIN_CURVE_EXPORT, cleared)
98
99private:
101 void relink();
104 void relinkAfterChanges(std::span<SegmentModel* const> added);
105 bool spliceOrder(std::span<SegmentModel* const> added);
106 bool rebuildOrder();
107 void relinkPoints();
108 void unlinkPoints(SegmentModel& m) noexcept;
109
110 IdContainer<SegmentModel> m_segments;
111 std::vector<PointModel*> m_points;
112 std::vector<SegmentModel*> m_sorted;
113 int32_t m_nextPointId{};
114 uint32_t m_relinkPass{};
115};
116
117SCORE_PLUGIN_CURVE_EXPORT
118std::vector<SegmentData> orderedSegments(const Model& curve);
119
122SCORE_PLUGIN_CURVE_EXPORT
123bool isValidCurve(std::span<const SegmentData> curve) noexcept;
124
125struct SCORE_PLUGIN_CURVE_EXPORT CurveDomain
126{
127 CurveDomain() = default;
128 CurveDomain(const CurveDomain&) = default;
129 CurveDomain(CurveDomain&&) = default;
130 CurveDomain& operator=(const CurveDomain&) = default;
131 CurveDomain& operator=(CurveDomain&&) = default;
132 CurveDomain(const ossia::domain& dom);
133 CurveDomain(const ossia::domain& dom, const ossia::value&);
134 CurveDomain(const ossia::domain& dom, double start, double end);
135 CurveDomain(double start, double end)
136 : min{std::min(start, end)}
137 , max{std::max(start, end)}
138 , start{start}
139 , end{end}
140 {
141 }
142
143 void refine(const ossia::domain&);
144 void ensureValid();
145
146 double min = 0;
147 double max = 1;
148 double start = 0;
149 double end = 1;
150};
151}
Definition CurveModel.hpp:26
Definition CurveSegmentModel.hpp:32
A map to access child objects through their id.
Definition IdentifiedObjectMap.hpp:17
The IdentifiedObject class.
Definition IdentifiedObject.hpp:19
Definition Selection.hpp:12
The id_base_t class.
Definition Identifier.hpp:59
Utilities and base classes for 1D curves.
Definition FocusDispatcher.hpp:12
bool isValidCurve(std::span< const SegmentData > curve) noexcept
Definition CurveModel.cpp:186
Definition CurveModel.hpp:126