Zrythm v2.0.0-alpha.1
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
track_lane.h
1// SPDX-FileCopyrightText: © 2019-2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <utility>
7
8#include "structure/arrangement/arranger_object_all.h"
9#include "structure/arrangement/arranger_object_owner.h"
10
11namespace zrythm::structure::tracks
12{
13
23class TrackLane
24 : public utils::UuidIdentifiableObject<TrackLane>,
25 public arrangement::ArrangerObjectOwner<arrangement::MidiRegion>,
26 public arrangement::ArrangerObjectOwner<arrangement::AudioRegion>
27{
28 Q_OBJECT
29 DEFINE_ARRANGER_OBJECT_OWNER_QML_PROPERTIES (
30 TrackLane,
31 midiRegions,
33 DEFINE_ARRANGER_OBJECT_OWNER_QML_PROPERTIES (
34 TrackLane,
35 audioRegions,
37 Q_PROPERTY (QString name READ name WRITE setName NOTIFY nameChanged)
38 Q_PROPERTY (double height READ height WRITE setHeight NOTIFY heightChanged)
39 Q_PROPERTY (bool muted READ muted WRITE setMuted NOTIFY muteChanged)
40 Q_PROPERTY (bool soloed READ soloed WRITE setSoloed NOTIFY soloChanged)
41 Q_PROPERTY (
42 std::uint8_t midiChannel READ midiChannel WRITE setMidiChannel NOTIFY
43 midiChannelChanged)
44 QML_ELEMENT
45 QML_UNCREATABLE ("")
46
47 static constexpr double DEFAULT_HEIGHT = 48;
48
49public:
53 using SoloedLanesExistFunc = std::function<bool ()>;
54
55 static constexpr auto default_format_str = QT_TR_NOOP_UTF8 ("Lane {}");
56
58 {
59 utils::IObjectRegistry &registry_;
60 SoloedLanesExistFunc soloed_lanes_exist_func_;
61 };
62
63 TrackLane (TrackLaneDependencies dependencies, QObject * parent = nullptr)
64 : utils::UuidIdentifiableObject<TrackLane> (parent),
65 arrangement::ArrangerObjectOwner<
66 arrangement::MidiRegion> (dependencies.registry_, *this),
67 arrangement::ArrangerObjectOwner<
68 arrangement::AudioRegion> (dependencies.registry_, *this),
69 soloed_lanes_exist_func_ (
70 std::move (dependencies.soloed_lanes_exist_func_))
71 {
72 }
73 Q_DISABLE_COPY_MOVE (TrackLane)
74 ~TrackLane () override;
75
76 // ========================================================================
77 // QML Interface
78 // ========================================================================
79
80 QString name () const { return name_.to_qstring (); }
81 void setName (const QString &name)
82 {
83 const auto std_name = utils::Utf8String::from_qstring (name);
84 if (name_ == std_name)
85 return;
86
87 name_ = std_name;
88 Q_EMIT nameChanged (name);
89 }
90 Q_SIGNAL void nameChanged (const QString &name);
91
92 double height () const { return height_; }
93 void setHeight (const double height)
94 {
95 if (qFuzzyCompare (height_, height))
96 return;
97
98 height_ = height;
99 Q_EMIT heightChanged (height);
100 }
101 Q_SIGNAL void heightChanged (double height);
102
103 bool soloed () const { return solo_; }
104 void setSoloed (bool solo)
105 {
106 if (solo_ == solo)
107 return;
108
109 solo_ = solo;
110 Q_EMIT soloChanged (solo);
111 }
112 Q_SIGNAL void soloChanged (bool solo);
113
114 bool muted () const { return mute_; }
115 void setMuted (bool mute)
116 {
117 if (mute_ == mute)
118 return;
119
120 mute_ = mute;
121 Q_EMIT muteChanged (mute);
122 }
123 Q_SIGNAL void muteChanged (bool mute);
124
127 * muted).
128 */
129 Q_INVOKABLE bool effectivelyMuted () const
130 {
131 if (muted ())
132 return true;
133
134 /* if lane is non-soloed while other soloed lanes exist, this should
135 * be muted */
136 if (soloed_lanes_exist_func_ () && !soloed ())
137 return true;
138
139 return false;
140 }
141
142 std::uint8_t midiChannel () const { return midi_ch_; }
143 void setMidiChannel (std::uint8_t midi_ch)
144 {
145 if (midi_ch_ == midi_ch)
146 return;
147
148 midi_ch_ = midi_ch;
149 Q_EMIT midiChannelChanged (midi_ch);
150 }
151 Q_SIGNAL void midiChannelChanged (std::uint8_t midi_ch);
152
153 // ========================================================================
154
160 void generate_name (size_t index);
161
167 // std::unique_ptr<TrackLaneT> gen_snapshot () const;
168
170 const arrangement::MidiRegion * _) const override
171 {
172 return "midiRegions";
173 }
175 const arrangement::AudioRegion * _) const override
176 {
177 return "audioRegions";
178 }
179
180private:
181 static constexpr std::string_view kNameKey = "name";
182 static constexpr std::string_view kHeightKey = "height";
183 static constexpr std::string_view kMuteKey = "mute";
184 static constexpr std::string_view kSoloKey = "solo";
185 static constexpr std::string_view kMidiChannelKey = "midiChannel";
186 friend void to_json (nlohmann::json &j, const TrackLane &lane);
187 friend void from_json (const nlohmann::json &j, TrackLane &lane);
188
189 friend void init_from (
190 TrackLane &obj,
191 const TrackLane &other,
192 utils::ObjectCloneType clone_type);
193
194private:
195 SoloedLanesExistFunc soloed_lanes_exist_func_;
196
198 utils::Utf8String name_;
199
201 double height_{ DEFAULT_HEIGHT };
202
204 bool mute_{};
205
207 bool solo_{};
208
214 uint8_t midi_ch_ = 0;
215
216 BOOST_DESCRIBE_CLASS (
217 TrackLane,
218 (utils::UuidIdentifiableObject<TrackLane>),
219 (),
220 (),
221 (name_, height_, mute_, solo_, midi_ch_))
222};
223}
A region for playing back audio samples.
A Region containing MIDI events.
Definition midi_region.h:24
A container of MIDI or Audio regions.
Definition track_lane.h:27
Q_INVOKABLE bool effectivelyMuted() const
Returns if the lane is effectively muted (explicitly or implicitly muted).
Definition track_lane.h:127
void generate_name(size_t index)
Generates a default name for the lane at the given index.
std::string get_field_name_for_serialization(const arrangement::MidiRegion *_) const override
Generate a snapshot for playback.
Definition track_lane.h:167
std::function< bool()> SoloedLanesExistFunc
Function to check if other soloed lanes exist in the owner.
Definition track_lane.h:51
Abstract interface for a UUID-keyed object registry.
Lightweight UTF-8 string wrapper with safe conversions.
Definition utf8_string.h:37
CRTP base that adds a typed UUID strong-typedef to a class hierarchy.
String utilities.