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};
35
36class SCORE_PLUGIN_CURVE_EXPORT PowerSegment final : public SegmentModel
37{
38 W_OBJECT(PowerSegment)
39public:
40 MODEL_METADATA_IMPL(PowerSegment)
41 using data_type = PowerSegmentData;
42 using SegmentModel::SegmentModel;
43 PowerSegment(const SegmentData& dat, QObject* parent);
44
45 PowerSegment(const PowerSegment& other, const id_type& id, QObject* parent);
46
47 PowerSegment(DataStream::Deserializer& vis, QObject* parent)
48 : SegmentModel{vis, parent}
49 {
50 vis.writeTo(*this);
51 }
52
53 PowerSegment(JSONObject::Deserializer& vis, QObject* parent)
54 : SegmentModel{vis, parent}
55 {
56 vis.writeTo(*this);
57 }
58
59 double gamma = PowerSegmentData::linearGamma; // TODO private
60private:
61 void on_startChanged() override;
62 void on_endChanged() override;
63
64 void updateData(int numInterp) const override;
65 double valueAt(double x) const override;
66
67 std::optional<double> verticalParameter() const override;
68 void setVerticalParameter(double p) override;
69
70 QVariant toSegmentSpecificData() const override;
71
72 template <typename Y>
73 ossia::curve_segment<Y> makeFunction() const;
74
75 ossia::curve_segment<double> makeDoubleFunction() const override;
76 ossia::curve_segment<float> makeFloatFunction() const override;
77 ossia::curve_segment<int> makeIntFunction() const override;
78};
79
80SCORE_PLUGIN_CURVE_EXPORT
81Curve::SegmentData flatCurveSegment(double val, double min, double max);
82}
83
84SCORE_SERIALIZE_DATASTREAM_DECLARE(, Curve::PowerSegmentData)
85Q_DECLARE_METATYPE(Curve::PowerSegmentData)
86W_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:63