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 
11 namespace Curve
12 {
13 class PowerSegment;
14 }
15 
16 CURVE_SEGMENT_METADATA(
17  SCORE_PLUGIN_CURVE_EXPORT, Curve::PowerSegment,
18  "1e7cb83f-4e47-4b14-814d-2242a9c75991", "Power", "Power", "")
19 
20 namespace Curve
21 {
22 struct SegmentData;
23 struct 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 
36 class SCORE_PLUGIN_CURVE_EXPORT PowerSegment final : public SegmentModel
37 {
38  W_OBJECT(PowerSegment)
39 public:
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
60 private:
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 
80 SCORE_PLUGIN_CURVE_EXPORT
81 Curve::SegmentData flatCurveSegment(double val, double min, double max);
82 }
83 
84 SCORE_SERIALIZE_DATASTREAM_DECLARE(, Curve::PowerSegmentData)
85 Q_DECLARE_METATYPE(Curve::PowerSegmentData)
86 W_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