Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
laned_track.h
1// SPDX-FileCopyrightText: © 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "structure/arrangement/audio_region.h"
7#include "structure/arrangement/midi_region.h"
8#include "structure/tracks/track.h"
9#include "structure/tracks/track_lane.h"
10#include "structure/tracks/track_lane_list.h"
11
12#define DEFINE_LANED_TRACK_QML_PROPERTIES(ClassType) \
13public: \
14 /* ================================================================ */ \
15 /* lanesVisible */ \
16 /* ================================================================ */ \
17 Q_PROPERTY ( \
18 bool lanesVisible READ getLanesVisible WRITE setLanesVisible NOTIFY \
19 lanesVisibleChanged) \
20 bool getLanesVisible () const \
21 { \
22 return lanes_visible_; \
23 } \
24 void setLanesVisible (bool visible) \
25 { \
26 if (lanes_visible_ == visible) \
27 return; \
28\
29 lanes_visible_ = visible; \
30 Q_EMIT lanesVisibleChanged (visible); \
31 } \
32\
33 Q_SIGNAL void lanesVisibleChanged (bool visible); \
34\
35 /* ================================================================ */ \
36 /* lanes */ \
37 /* ================================================================ */ \
38 Q_PROPERTY (TrackLaneList * lanes READ getLanes CONSTANT) \
39 TrackLaneList * getLanes () const \
40 { \
41 return const_cast<TrackLaneList *> (&lanes_); \
42 }
43
44namespace zrythm::structure::tracks
45{
49class LanedTrack : virtual public Track
50{
51public:
52 ~LanedTrack () noexcept override = default;
53
57 void set_lanes_visible (bool visible);
58
59protected:
60 LanedTrack () noexcept { }
61
62public:
64 bool lanes_visible_ = false;
65
68
80
83};
84
88template <typename TrackLaneT> class LanedTrackImpl : public LanedTrack
89{
90public:
91 using RegionT = typename TrackLaneT::RegionT;
92 using TrackLaneType = TrackLaneT;
93
94 LanedTrackImpl ();
95
96 ~LanedTrackImpl () override = default;
97
103 bool create_missing_lanes (int pos);
104
109
113 bool has_soloed_lanes () const
114 {
115 return std::ranges::any_of (lanes_, [] (const auto &lane) {
116 return std::get<TrackLaneT *> (lane)->get_soloed ();
117 });
118 }
119
124
130 void generate_lanes () { add_lane (); }
131
132 void clear_objects () override;
133
135 std::vector<arrangement::ArrangerObjectUuidReference> &regions,
136 std::optional<signed_frame_t> p1,
137 std::optional<signed_frame_t> p2) override;
138
139 int get_lane_index (const TrackLaneT &lane) const
140 {
141 return std::ranges::find_if (
142 lanes_.lanes_,
143 [&] (const auto &lane_var) {
144 return std::get<TrackLaneT *> (lane_var) == std::addressof (lane);
145 })
146 - lanes_.begin ();
147 }
148
149 TrackLaneT &get_lane_at (const size_t index)
150 {
151 return *std::get<TrackLaneT *> (lanes_.at (index));
152 }
153
154protected:
155 friend void init_from (
156 LanedTrackImpl &obj,
157 const LanedTrackImpl &other,
158 utils::ObjectCloneType clone_type)
159 {
160 init_from (obj.lanes_, other.lanes_, clone_type);
161 for (auto &lane_var : obj.lanes_)
162 {
163 auto lane = std::get<TrackLaneT *> (lane_var);
164 lane->track_ = &obj;
165 }
166 obj.lanes_visible_ = other.lanes_visible_;
167 }
168
169 void set_playback_caches () override;
170
171private:
172 static constexpr std::string_view kLanesVisibleKey = "lanesVisible";
173 static constexpr std::string_view kLanesListKey = "lanesList";
174 friend void to_json (nlohmann::json &j, const LanedTrackImpl &track)
175 {
176 j[kLanesVisibleKey] = track.lanes_visible_;
177 j[kLanesListKey] = track.lanes_;
178 }
179 friend void from_json (const nlohmann::json &j, LanedTrackImpl &track)
180 {
181 j.at (kLanesVisibleKey).get_to (track.lanes_visible_);
182 j.at (kLanesListKey).get_to (track.lanes_);
183 }
184
185 void add_lane ();
186
187public:
190
192 std::vector<std::unique_ptr<TrackLaneT>> lane_snapshots_;
193
194 static_assert (TrackLaneSubclass<TrackLaneT>);
195};
196
197using LanedTrackVariant = std::variant<MidiTrack, InstrumentTrack, AudioTrack>;
198using LanedTrackPtrVariant = to_pointer_variant<LanedTrackVariant>;
199
200extern template class LanedTrackImpl<MidiLane>;
201extern template class LanedTrackImpl<AudioLane>;
202
203}
Interface for a track that has lanes.
Definition laned_track.h:89
void get_regions_in_range(std::vector< arrangement::ArrangerObjectUuidReference > &regions, std::optional< signed_frame_t > p1, std::optional< signed_frame_t > p2) override
Returns all the regions inside the given range, or all the regions if both p1 and p2 are NULL.
void generate_lanes()
Generates lanes for the track.
bool has_soloed_lanes() const
Returns whether the track has any soloed lanes.
void clear_objects() override
Removes all objects recursively from the track.
void remove_empty_last_lanes()
Removes the empty last lanes of the Track (except the last one).
bool create_missing_lanes(int pos)
Creates missing TrackLane's until pos.
double get_visible_lane_heights() const
Gets the total height of all visible lanes (if any).
TrackLaneList lanes_
Lanes in this track containing Regions.
std::vector< std::unique_ptr< TrackLaneT > > lane_snapshots_
Snapshots used during playback.
void set_playback_caches() override
Set the playback caches for a track.
void set_lanes_visible(bool visible)
Set lanes visible and fire events.
int last_lane_created_
Last lane created during this drag.
Definition laned_track.h:79
bool lanes_visible_
Flag to set lanes visible or not.
Definition laned_track.h:64
bool block_auto_creation_and_deletion_
Block auto-creating or deleting lanes.
Definition laned_track.h:82
int last_lane_idx_
Lane index of region before recording paused.
Definition laned_track.h:67
Track(Type type, PortType in_signal_type, PortType out_signal_type, BaseTrackDependencies dependencies)
Constructor to be used by subclasses.