Loading...
Searching...
No Matches
PowerSegment.hpp
1#pragma once
2#include <Curve/Segment/CurveSegmentModel.hpp>
3
4#include <score/model/Identifier.hpp>
6#include <score/serialization/VisitorInterface.hpp>
7#include <score/tools/std/Optional.hpp>
8
9#include <QVariant>
10
11namespace Curve
12{
13class PowerSegment;
14}
15
16CURVE_SEGMENT_METADATA(
17 SCORE_PLUGIN_CURVE_EXPORT, Curve::PowerSegment,
18 "1e7cb83f-4e47-4b14-814d-2242a9c75991", "Power", "Power", "")
19
20namespace Curve
21{
22struct SegmentData;
23struct SCORE_PLUGIN_CURVE_EXPORT PowerSegmentData
24{
25 PowerSegmentData() = default;
26 PowerSegmentData(double d)
27 : gamma{d}
28 {
29 }
30
31 // Value of gamma for which the pow will be == 1.
32 static const constexpr double linearGamma = 1;
33 double gamma = linearGamma;
34 bool operator==(const PowerSegmentData&) const noexcept = default;
35};
36
37class SCORE_PLUGIN_CURVE_EXPORT PowerSegment final : public SegmentModel
38{
39 W_OBJECT(PowerSegment)
40public:
41 MODEL_METADATA_IMPL(PowerSegment)
42 using data_type = PowerSegmentData;
43 using SegmentModel::SegmentModel;
44 PowerSegment(const SegmentData& dat, QObject* parent);
45
46 PowerSegment(const PowerSegment& other, const id_type& id, QObject* parent);
47
48 PowerSegment(DataStream::Deserializer& vis, QObject* parent)
49 : SegmentModel{vis, parent}
50 {
51 vis.writeTo(*this);
52 }
53
54 PowerSegment(JSONObject::Deserializer& vis, QObject* parent)
55 : SegmentModel{vis, parent}
56 {
57 vis.writeTo(*this);
58 }
59
60 double gamma = PowerSegmentData::linearGamma; // TODO private
61private:
62 void on_startChanged() override;
63 void on_endChanged() override;
64
65 void updateData(int numInterp) const override;
66 double valueAt(double x) const override;
67
68 void setSpecificData(const QVariant& data) override;
69 bool specificDataEquals(const QVariant& data) const noexcept override;
70
71 std::optional<double> verticalParameter() const override;
72 void setVerticalParameter(double p) override;
73
74 QVariant toSegmentSpecificData() const override;
75
76 template <typename Y>
77 ossia::curve_segment<Y> makeFunction() const;
78
79 ossia::curve_segment<double> makeDoubleFunction() const override;
80 ossia::curve_segment<float> makeFloatFunction() const override;
81 ossia::curve_segment<int> makeIntFunction() const override;
82};
83
84SCORE_PLUGIN_CURVE_EXPORT
85Curve::SegmentData flatCurveSegment(double val, double min, double max);
86}
87
88SCORE_SERIALIZE_DATASTREAM_DECLARE(SCORE_PLUGIN_CURVE_EXPORT, Curve::PowerSegmentData)
89Q_DECLARE_METATYPE(Curve::PowerSegmentData)
90W_REGISTER_ARGTYPE(Curve::PowerSegmentData)
Definition DataStreamVisitor.hpp:202
Definition JSONVisitor.hpp:423
Utilities and base classes for 1D curves.
Definition FocusDispatcher.hpp:12
Definition CurveSegmentData.hpp:66