Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
fadeable_object.h
1// SPDX-FileCopyrightText: © 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "dsp/atomic_position_qml_adapter.h"
7#include "dsp/curve.h"
8#include "utils/icloneable.h"
9
10#include <nlohmann/json_fwd.hpp>
11
12namespace zrythm::structure::arrangement
13{
14class ArrangerObjectFadeRange : public QObject
15{
16 Q_OBJECT
17 Q_PROPERTY (
18 zrythm::dsp::AtomicPositionQmlAdapter * startOffset READ startOffset CONSTANT)
19 Q_PROPERTY (
20 zrythm::dsp::AtomicPositionQmlAdapter * endOffset READ endOffset CONSTANT)
21 Q_PROPERTY (
22 zrythm::dsp::CurveOptionsQmlAdapter * fadeInCurveOpts READ fadeInCurveOpts
23 CONSTANT)
24 Q_PROPERTY (
25 zrythm::dsp::CurveOptionsQmlAdapter * fadeOutCurveOpts READ fadeOutCurveOpts
26 CONSTANT)
27 QML_ELEMENT
28 QML_UNCREATABLE ("")
29
30public:
31 ArrangerObjectFadeRange (
32 const dsp::AtomicPosition::TimeConversionFunctions &time_conversion_funcs,
33 QObject * parent = nullptr);
34
35 // ========================================================================
36 // QML Interface
37 // ========================================================================
38
39 dsp::AtomicPositionQmlAdapter * startOffset () const
40 {
41 return start_offset_adapter_.get ();
42 }
43 dsp::AtomicPositionQmlAdapter * endOffset () const
44 {
45 return end_offset_adapter_.get ();
46 }
47 dsp::CurveOptionsQmlAdapter * fadeInCurveOpts () const
48 {
49 return fade_in_opts_adapter_.get ();
50 }
51 dsp::CurveOptionsQmlAdapter * fadeOutCurveOpts () const
52 {
53 return fade_out_opts_adapter_.get ();
54 }
55
56 Q_SIGNAL void fadePropertiesChanged ();
57
58 // ========================================================================
59
62 *
63 * @param x Normalized x.
64 * @param fade_in True for in, false for out.
65 */
66 double get_normalized_y_for_fade (double x, bool fade_in) const
67 {
68 if (fade_in)
69 {
70 return fadeInCurveOpts ()->normalizedY (x, false);
71 }
72
73 return fadeOutCurveOpts ()->normalizedY (x, true);
74 }
75
76protected:
77 friend void init_from (
79 const ArrangerObjectFadeRange &other,
80 utils::ObjectCloneType clone_type)
81 {
82 obj.start_offset_adapter_->setTicks (other.start_offset_adapter_->ticks ());
83 obj.end_offset_adapter_->setTicks (other.end_offset_adapter_->ticks ());
84 obj.fade_in_opts_ = other.fade_in_opts_;
85 obj.fade_out_opts_ = other.fade_out_opts_;
86 }
87
88private:
89 static constexpr auto kFadeInOffsetKey = "fadeInOffset"sv;
90 static constexpr auto kFadeOutOffsetKey = "fadeOutOffset"sv;
91 static constexpr auto kFadeInOptsKey = "fadeInOpts"sv;
92 static constexpr auto kFadeOutOptsKey = "fadeOutOpts"sv;
93 friend void
94 to_json (nlohmann::json &j, const ArrangerObjectFadeRange &object);
95 friend void
96 from_json (const nlohmann::json &j, ArrangerObjectFadeRange &object);
97
98 BOOST_DESCRIBE_CLASS (
99 ArrangerObjectFadeRange,
100 (),
101 (),
102 (),
103 (start_offset_, end_offset_, fade_in_opts_, fade_out_opts_))
104
105private:
107 dsp::AtomicPosition start_offset_;
109
113 dsp::AtomicPosition end_offset_;
115
117 dsp::CurveOptions fade_in_opts_;
119
121 dsp::CurveOptions fade_out_opts_;
123};
124} // namespace zrythm::structure::arrangement
Thread-safe position storage with automatic musical/absolute time conversion.
QML adapter for CurveOptions.
Definition curve.h:130
Curve options.
Definition curve.h:23
double get_normalized_y_for_fade(double x, bool fade_in) const
Gets the normalized Y (ie, gain from 0-1) for a normalized X, for a fade.
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:36