Zrythm v2.0.0-alpha.1
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
arranger_object.h
1// SPDX-FileCopyrightText: © 2019-2022, 2024-2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <vector>
7
8#include "dsp/atomic_position_qml_adapter.h"
9#include "dsp/tempo_map.h"
10#include "structure/arrangement/arranger_object_fwd.h"
11#include "structure/arrangement/bounded_object.h"
12#include "structure/arrangement/colored_object.h"
13#include "structure/arrangement/fadeable_object.h"
14#include "structure/arrangement/loopable_object.h"
15#include "structure/arrangement/muteable_object.h"
16#include "structure/arrangement/named_object.h"
17#include "utils/typed_uuid_reference.h"
18#include "utils/units.h"
19
20#include <QtQmlIntegration/qqmlintegration.h>
21
22namespace zrythm::structure::arrangement
23{
24
34class ArrangerObject : public utils::UuidIdentifiableObject<ArrangerObject>
35{
36 Q_OBJECT
37 QML_ELEMENT
38 Q_PROPERTY (
40 parentObject WRITE setParentObject NOTIFY parentObjectChanged)
41 Q_PROPERTY (
43 Q_PROPERTY (
44 zrythm::dsp::AtomicPositionQmlAdapter * position READ position CONSTANT)
45 Q_PROPERTY (
47 CONSTANT)
48 Q_PROPERTY (
50 loopRange CONSTANT)
51 Q_PROPERTY (
53 Q_PROPERTY (
55 CONSTANT)
56 Q_PROPERTY (
58 mute CONSTANT)
59 Q_PROPERTY (
61 fadeRange CONSTANT)
62 QML_UNCREATABLE ("")
63
64public:
68 enum class Type : std::uint8_t
69 {
78 Marker,
83 };
84 Q_ENUM (Type)
85
86public:
87 ~ArrangerObject () noexcept override;
88 Q_DISABLE_COPY_MOVE (ArrangerObject)
89
92
94 const units::sample_t frames_start,
95 const units::sample_t frames_end,
96 bool range_start_inclusive = true,
97 bool range_end_inclusive = false) const
98 {
99 const auto pos_samples = position_.get_samples ();
100 return (range_start_inclusive
101 ? (pos_samples >= frames_start)
102 : (pos_samples > frames_start))
103 && (range_end_inclusive ? (pos_samples <= frames_end) : (pos_samples < frames_end));
104 }
105
106 // ========================================================================
107 // QML Interface
108 // ========================================================================
109
110 auto type () const { return type_; }
111
112 dsp::AtomicPositionQmlAdapter * position () const
113 {
114 return position_adapter_.get ();
115 }
116
117 ArrangerObjectBounds * bounds () const { return bounds_.get (); }
118 ArrangerObjectLoopRange * loopRange () const { return loop_range_.get (); }
119 ArrangerObjectName * name () const { return name_.get (); }
120 ArrangerObjectColor * color () const { return color_.get (); }
121 ArrangerObjectMuteFunctionality * mute () const { return mute_.get (); }
122 ArrangerObjectFadeRange * fadeRange () const { return fade_range_.get (); }
123
127 Q_SIGNAL void propertiesChanged ();
128
129 ArrangerObject * parentObject () const { return parent_object_; }
130 void setParentObject (ArrangerObject * object);
131 Q_SIGNAL void parentObjectChanged (QObject * parentObject);
132
133 // ========================================================================
134
135 // Convenience getter
136 auto &get_tempo_map () const { return tempo_map_; }
137
138 virtual std::vector<ArrangerObjectListModel *> get_child_list_models () const
139 {
140 return {};
141 }
142
143protected:
144 enum class ArrangerObjectFeatures : std::uint8_t
145 {
146 // individual bit positions
147 Bounds = 1 << 0,
148 LoopingBit = 1 << 1,
149 Name = 1 << 2,
150 Color = 1 << 3,
151 Mute = 1 << 4,
152 Fading = 1 << 5,
154 // convenience masks
155 Looping = LoopingBit | Bounds,
156 Region = Looping | Name | Color | Mute,
157 };
158
167 Type type,
168 const dsp::TempoMap &tempo_map,
169 ArrangerObjectFeatures features,
170 QObject * parent = nullptr) noexcept;
171
172 friend void init_from (
173 ArrangerObject &obj,
174 const ArrangerObject &other,
175 utils::ObjectCloneType clone_type);
176
177private:
178 static constexpr auto kPositionKey = "position"sv;
179 static constexpr auto kBoundsKey = "bounds"sv;
180 static constexpr auto kLoopRangeKey = "loop_range"sv;
181 static constexpr auto kFadeRangeKey = "fadeRange"sv;
182 static constexpr auto kNameKey = "name"sv;
183 static constexpr auto kColorKey = "color"sv;
184 static constexpr auto kMuteKey = "mute"sv;
185 friend void
186 to_json (nlohmann::json &j, const ArrangerObject &arranger_object);
187 friend void
188 from_json (const nlohmann::json &j, ArrangerObject &arranger_object);
189
190private:
191 Type type_;
192
193 const dsp::TempoMap &tempo_map_;
194
202 std::unique_ptr<dsp::AtomicPosition::TimeConversionFunctions>
203 time_conversion_funcs_;
204
206 dsp::AtomicPosition position_;
207 utils::QObjectUniquePtr<dsp::AtomicPositionQmlAdapter> position_adapter_;
208
209 utils::QObjectUniquePtr<ArrangerObjectBounds> bounds_;
210 utils::QObjectUniquePtr<ArrangerObjectLoopRange> loop_range_;
211 utils::QObjectUniquePtr<ArrangerObjectName> name_;
212 utils::QObjectUniquePtr<ArrangerObjectColor> color_;
213 utils::QObjectUniquePtr<ArrangerObjectMuteFunctionality> mute_;
214 utils::QObjectUniquePtr<ArrangerObjectFadeRange> fade_range_;
215
223 QPointer<ArrangerObject> parent_object_;
224
225 BOOST_DESCRIBE_CLASS (
227 (UuidIdentifiableObject<ArrangerObject>),
228 (),
229 (),
230 (type_, position_, bounds_, loop_range_, fade_range_, mute_, color_, name_))
231};
232
233using ArrangerObjectUuidReference = utils::TypedUuidReference<ArrangerObject>;
234
235template <typename T>
237 std::derived_from<T, ArrangerObject> && utils::CompleteType<T>;
238}
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:18
A MIDI note inside a Region shown in the piano roll.
Definition midi_note.h:23
A Region containing MIDI events.
Definition midi_region.h:24
CRTP base that adds a typed UUID strong-typedef to a class hierarchy.
String utilities.