Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
automation_point.h
1// SPDX-FileCopyrightText: © 2018-2022, 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "dsp/curve.h"
7#include "structure/arrangement/arranger_object.h"
8#include "utils/icloneable.h"
9
10namespace zrythm::structure::arrangement
11{
15class AutomationPoint final : public ArrangerObject
16{
17 Q_OBJECT
18 Q_PROPERTY (float value READ value WRITE setValue NOTIFY valueChanged)
19 Q_PROPERTY (dsp::CurveOptionsQmlAdapter * curveOpts READ curveOpts CONSTANT)
20 QML_ELEMENT
21 QML_UNCREATABLE ("")
22
23public:
24 AutomationPoint (const dsp::TempoMap &tempo_map, QObject * parent = nullptr);
25 Z_DISABLE_COPY_MOVE (AutomationPoint)
26 ~AutomationPoint () override;
27
28 // ========================================================================
29 // QML Interface
30 // ========================================================================
31
32 float value () const { return normalized_value_; }
33 void setValue (float dval)
34 {
35 const auto val = dval;
36 if (qFuzzyCompare (normalized_value_, val))
37 return;
38
39 normalized_value_ = val;
40 Q_EMIT valueChanged (dval);
41 }
42 Q_SIGNAL void valueChanged (float);
43
44 dsp::CurveOptionsQmlAdapter * curveOpts () const
45 {
46 return curve_opts_adapter_.get ();
47 }
48
49 // ========================================================================
50
51private:
52 friend void init_from (
53 AutomationPoint &obj,
54 const AutomationPoint &other,
55 utils::ObjectCloneType clone_type);
56
57 static constexpr auto kNormalizedValueKey = "normalized_value"sv;
58 static constexpr auto kCurveOptionsKey = "curve_options"sv;
59 friend void to_json (nlohmann::json &j, const AutomationPoint &point)
60 {
61 to_json (j, static_cast<const ArrangerObject &> (point));
62 j[kNormalizedValueKey] = point.normalized_value_;
63 j[kCurveOptionsKey] = point.curve_opts_;
64 }
65 friend void from_json (const nlohmann::json &j, AutomationPoint &point)
66 {
67 from_json (j, static_cast<ArrangerObject &> (point));
68 j.at (kNormalizedValueKey).get_to (point.normalized_value_);
69 j.at (kCurveOptionsKey).get_to (point.curve_opts_);
70 }
71
72private:
74 float normalized_value_ = 0.f;
75
76 dsp::CurveOptions curve_opts_;
78
79 BOOST_DESCRIBE_CLASS (
80 AutomationPoint,
82 (),
83 (),
84 (normalized_value_, curve_opts_))
85};
86
87} // namespace zrythm::structure::arrangement
QML adapter for CurveOptions.
Definition curve.h:125
Curve options.
Definition curve.h:22
ArrangerObject(Type type, const dsp::TempoMap &tempo_map, ArrangerObjectFeatures features, QObject *parent=nullptr) noexcept
Construct a new ArrangerObject.
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:38