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/types.h"
16#include "utils/units.h"
17
18#include <QtQmlIntegration>
19
20namespace zrythm::structure::arrangement
21{
31 : public QObject,
32 public utils::UuidIdentifiableObject<ArrangerObject>
33{
34 Q_OBJECT
35 QML_ELEMENT
36 Q_PROPERTY (
38 parentObject WRITE setParentObject NOTIFY parentObjectChanged)
39 Q_PROPERTY (
41 Q_PROPERTY (
42 zrythm::dsp::AtomicPositionQmlAdapter * position READ position CONSTANT)
43 Q_PROPERTY (
45 CONSTANT)
46 Q_PROPERTY (
48 loopRange CONSTANT)
49 Q_PROPERTY (
51 Q_PROPERTY (
53 CONSTANT)
54 Q_PROPERTY (
56 mute CONSTANT)
57 Q_PROPERTY (
59 fadeRange CONSTANT)
60 QML_UNCREATABLE ("")
61
62public:
66 enum class Type : basic_enum_base_type_t
67 {
75 Marker,
80 };
81 Q_ENUM (Type)
82
83public:
84 ~ArrangerObject () noexcept override;
85 Z_DISABLE_COPY_MOVE (ArrangerObject)
86
89
91 const units::sample_t frames_start,
92 const units::sample_t frames_end,
93 bool range_start_inclusive = true,
94 bool range_end_inclusive = false) const
95 {
96 const auto pos_samples = position_.get_samples ();
97 return (range_start_inclusive
98 ? (pos_samples >= frames_start)
99 : (pos_samples > frames_start))
100 && (range_end_inclusive ? (pos_samples <= frames_end) : (pos_samples < frames_end));
101 }
102
103 // ========================================================================
104 // QML Interface
105 // ========================================================================
106
107 auto type () const { return type_; }
108
109 dsp::AtomicPositionQmlAdapter * position () const
110 {
111 return position_adapter_.get ();
112 }
113
114 ArrangerObjectBounds * bounds () const { return bounds_.get (); }
115 ArrangerObjectLoopRange * loopRange () const { return loop_range_.get (); }
116 ArrangerObjectName * name () const { return name_.get (); }
117 ArrangerObjectColor * color () const { return color_.get (); }
118 ArrangerObjectMuteFunctionality * mute () const { return mute_.get (); }
119 ArrangerObjectFadeRange * fadeRange () const { return fade_range_.get (); }
120
124 Q_SIGNAL void propertiesChanged ();
125
126 ArrangerObject * parentObject () const { return parent_object_; }
127 void setParentObject (ArrangerObject * object);
128 Q_SIGNAL void parentObjectChanged (QObject * parentObject);
129
130 // ========================================================================
131
132 // Convenience getter
133 auto &get_tempo_map () const { return tempo_map_; }
134
135protected:
136 enum class ArrangerObjectFeatures : std::uint8_t
137 {
138 // individual bit positions
139 Bounds = 1 << 0,
140 LoopingBit = 1 << 1,
141 Name = 1 << 2,
142 Color = 1 << 3,
143 Mute = 1 << 4,
144 Fading = 1 << 5,
146 // convenience masks
147 Looping = LoopingBit | Bounds,
148 Region = Looping | Name | Color | Mute,
149 };
150
159 Type type,
160 const dsp::TempoMap &tempo_map,
161 ArrangerObjectFeatures features,
162 QObject * parent = nullptr) noexcept;
163
164 friend void init_from (
165 ArrangerObject &obj,
166 const ArrangerObject &other,
167 utils::ObjectCloneType clone_type);
168
169private:
170 static constexpr auto kPositionKey = "position"sv;
171 static constexpr auto kBoundsKey = "bounds"sv;
172 static constexpr auto kLoopRangeKey = "loop_range"sv;
173 static constexpr auto kFadeRangeKey = "fadeRange"sv;
174 static constexpr auto kNameKey = "name"sv;
175 static constexpr auto kColorKey = "color"sv;
176 static constexpr auto kMuteKey = "mute"sv;
177 friend void
178 to_json (nlohmann::json &j, const ArrangerObject &arranger_object);
179 friend void
180 from_json (const nlohmann::json &j, ArrangerObject &arranger_object);
181
182private:
183 Type type_;
184
185 const dsp::TempoMap &tempo_map_;
186
194 std::unique_ptr<dsp::AtomicPosition::TimeConversionFunctions>
195 time_conversion_funcs_;
196
198 dsp::AtomicPosition position_;
199 utils::QObjectUniquePtr<dsp::AtomicPositionQmlAdapter> position_adapter_;
200
201 utils::QObjectUniquePtr<ArrangerObjectBounds> bounds_;
202 utils::QObjectUniquePtr<ArrangerObjectLoopRange> loop_range_;
203 utils::QObjectUniquePtr<ArrangerObjectName> name_;
204 utils::QObjectUniquePtr<ArrangerObjectColor> color_;
205 utils::QObjectUniquePtr<ArrangerObjectMuteFunctionality> mute_;
206 utils::QObjectUniquePtr<ArrangerObjectFadeRange> fade_range_;
207
215 QPointer<ArrangerObject> parent_object_;
216
217 BOOST_DESCRIBE_CLASS (
219 (UuidIdentifiableObject<ArrangerObject>),
220 (),
221 (),
222 (type_, position_, bounds_, loop_range_, fade_range_, mute_, color_, name_))
223};
224
225using ArrangerObjectRegistry =
226 utils::OwningObjectRegistry<ArrangerObjectPtrVariant, ArrangerObject>;
227using ArrangerObjectUuidReference = utils::UuidReference<ArrangerObjectRegistry>;
228
229template <typename T>
231 std::derived_from<T, ArrangerObject> && CompleteType<T>;
232}
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:20
A Region containing MIDI events.
Definition midi_region.h:20
Base class for objects that need to be uniquely identified by UUID.
String utilities.
Definition algorithms.h:12