Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
arranger_object.h
1// SPDX-FileCopyrightText: © 2019-2022, 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/tempo_map.h"
8#include "structure/arrangement/arranger_object_fwd.h"
9#include "structure/arrangement/bounded_object.h"
10#include "structure/arrangement/colored_object.h"
11#include "structure/arrangement/fadeable_object.h"
12#include "structure/arrangement/loopable_object.h"
13#include "structure/arrangement/muteable_object.h"
14#include "structure/arrangement/named_object.h"
15#include "utils/units.h"
16
17#include <QtQmlIntegration/qqmlintegration.h>
18
19namespace zrythm::structure::arrangement
20{
30 : public QObject,
31 public utils::UuidIdentifiableObject<ArrangerObject>
32{
33 Q_OBJECT
34 QML_ELEMENT
35 Q_PROPERTY (
37 parentObject WRITE setParentObject NOTIFY parentObjectChanged)
38 Q_PROPERTY (
40 Q_PROPERTY (
41 zrythm::dsp::AtomicPositionQmlAdapter * position READ position CONSTANT)
42 Q_PROPERTY (
44 CONSTANT)
45 Q_PROPERTY (
47 loopRange CONSTANT)
48 Q_PROPERTY (
50 Q_PROPERTY (
52 CONSTANT)
53 Q_PROPERTY (
55 mute CONSTANT)
56 Q_PROPERTY (
58 fadeRange CONSTANT)
59 QML_UNCREATABLE ("")
60
61public:
65 enum class Type : std::uint8_t
66 {
74 Marker,
79 };
80 Q_ENUM (Type)
81
82public:
83 ~ArrangerObject () noexcept override;
84 Q_DISABLE_COPY_MOVE (ArrangerObject)
85
88
90 const units::sample_t frames_start,
91 const units::sample_t frames_end,
92 bool range_start_inclusive = true,
93 bool range_end_inclusive = false) const
94 {
95 const auto pos_samples = position_.get_samples ();
96 return (range_start_inclusive
97 ? (pos_samples >= frames_start)
98 : (pos_samples > frames_start))
99 && (range_end_inclusive ? (pos_samples <= frames_end) : (pos_samples < frames_end));
100 }
101
102 // ========================================================================
103 // QML Interface
104 // ========================================================================
105
106 auto type () const { return type_; }
107
108 dsp::AtomicPositionQmlAdapter * position () const
109 {
110 return position_adapter_.get ();
111 }
112
113 ArrangerObjectBounds * bounds () const { return bounds_.get (); }
114 ArrangerObjectLoopRange * loopRange () const { return loop_range_.get (); }
115 ArrangerObjectName * name () const { return name_.get (); }
116 ArrangerObjectColor * color () const { return color_.get (); }
117 ArrangerObjectMuteFunctionality * mute () const { return mute_.get (); }
118 ArrangerObjectFadeRange * fadeRange () const { return fade_range_.get (); }
119
123 Q_SIGNAL void propertiesChanged ();
124
125 ArrangerObject * parentObject () const { return parent_object_; }
126 void setParentObject (ArrangerObject * object);
127 Q_SIGNAL void parentObjectChanged (QObject * parentObject);
128
129 // ========================================================================
130
131 // Convenience getter
132 auto &get_tempo_map () const { return tempo_map_; }
133
134protected:
135 enum class ArrangerObjectFeatures : std::uint8_t
136 {
137 // individual bit positions
138 Bounds = 1 << 0,
139 LoopingBit = 1 << 1,
140 Name = 1 << 2,
141 Color = 1 << 3,
142 Mute = 1 << 4,
143 Fading = 1 << 5,
145 // convenience masks
146 Looping = LoopingBit | Bounds,
147 Region = Looping | Name | Color | Mute,
148 };
149
158 Type type,
159 const dsp::TempoMap &tempo_map,
160 ArrangerObjectFeatures features,
161 QObject * parent = nullptr) noexcept;
162
163 friend void init_from (
164 ArrangerObject &obj,
165 const ArrangerObject &other,
166 utils::ObjectCloneType clone_type);
167
168private:
169 static constexpr auto kPositionKey = "position"sv;
170 static constexpr auto kBoundsKey = "bounds"sv;
171 static constexpr auto kLoopRangeKey = "loop_range"sv;
172 static constexpr auto kFadeRangeKey = "fadeRange"sv;
173 static constexpr auto kNameKey = "name"sv;
174 static constexpr auto kColorKey = "color"sv;
175 static constexpr auto kMuteKey = "mute"sv;
176 friend void
177 to_json (nlohmann::json &j, const ArrangerObject &arranger_object);
178 friend void
179 from_json (const nlohmann::json &j, ArrangerObject &arranger_object);
180
181private:
182 Type type_;
183
184 const dsp::TempoMap &tempo_map_;
185
193 std::unique_ptr<dsp::AtomicPosition::TimeConversionFunctions>
194 time_conversion_funcs_;
195
197 dsp::AtomicPosition position_;
198 utils::QObjectUniquePtr<dsp::AtomicPositionQmlAdapter> position_adapter_;
199
200 utils::QObjectUniquePtr<ArrangerObjectBounds> bounds_;
201 utils::QObjectUniquePtr<ArrangerObjectLoopRange> loop_range_;
202 utils::QObjectUniquePtr<ArrangerObjectName> name_;
203 utils::QObjectUniquePtr<ArrangerObjectColor> color_;
204 utils::QObjectUniquePtr<ArrangerObjectMuteFunctionality> mute_;
205 utils::QObjectUniquePtr<ArrangerObjectFadeRange> fade_range_;
206
214 QPointer<ArrangerObject> parent_object_;
215
216 BOOST_DESCRIBE_CLASS (
218 (UuidIdentifiableObject<ArrangerObject>),
219 (),
220 (),
221 (type_, position_, bounds_, loop_range_, fade_range_, mute_, color_, name_))
222};
223
224using ArrangerObjectRegistry =
225 utils::OwningObjectRegistry<ArrangerObjectPtrVariant, ArrangerObject>;
226using ArrangerObjectUuidReference = utils::UuidReference<ArrangerObjectRegistry>;
227
228template <typename T>
230 std::derived_from<T, ArrangerObject> && CompleteType<T>;
231}
units::sample_t get_samples() const
Helper method to get the position as samples.
Adds length functionality to arranger objects.
Name functionality for arranger objects.
Base class for all objects in the arranger.
ArrangerObject(Type type, const dsp::TempoMap &tempo_map, ArrangerObjectFeatures features, QObject *parent=nullptr) noexcept
Construct a new ArrangerObject.
bool is_start_hit_by_range(const units::sample_t frames_start, const units::sample_t frames_end, bool range_start_inclusive=true, bool range_end_inclusive=false) const
Q_SIGNAL void propertiesChanged()
Emitted when any of the properties of the object changed.
A region for playing back audio samples.
An automation point inside an AutomationTrack.
Represents an automation region, which contains a collection of automation points.
The ChordObject class represents a chord inside the chord editor.
Marker for the MarkerTrack.
Definition marker.h:16
A MIDI note inside a Region shown in the piano roll.
Definition midi_note.h:21
A Region containing MIDI events.
Definition midi_region.h:20
Base class for objects that need to be uniquely identified by UUID.
String utilities.