Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
tracklist.h
1// SPDX-FileCopyrightText: © 2018-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "structure/arrangement/arranger_object.h"
7#include "structure/tracks/singleton_tracks.h"
8#include "structure/tracks/track.h"
9#include "structure/tracks/track_collection.h"
10#include "structure/tracks/track_routing.h"
11#include "structure/tracks/track_span.h"
12
13#include <QtQmlIntegration/qqmlintegration.h>
14
15namespace zrythm::structure::tracks
16{
17
22class Tracklist : public QObject
23{
24 Q_OBJECT
25 QML_ELEMENT
26 Q_PROPERTY (
27 zrythm::structure::tracks::TrackRouting * trackRouting READ trackRouting
28 CONSTANT)
29 Q_PROPERTY (
31 singletonTracks CONSTANT)
32 Q_PROPERTY (
33 zrythm::structure::tracks::TrackCollection * collection READ collection
34 CONSTANT)
35 Q_PROPERTY (
36 int pinnedTracksCutoff READ pinnedTracksCutoff WRITE setPinnedTracksCutoff
37 NOTIFY pinnedTracksCutoffChanged)
38 QML_UNCREATABLE ("")
39
40public:
41 using ArrangerObjectPtrVariant = arrangement::ArrangerObjectPtrVariant;
42 using ArrangerObject = arrangement::ArrangerObject;
43
44public:
45 explicit Tracklist (TrackRegistry &track_registry, QObject * parent = nullptr);
46 Z_DISABLE_COPY_MOVE (Tracklist)
47 ~Tracklist () override;
48
49 // ========================================================================
50 // QML Interface
51 // ========================================================================
52
53 TrackCollection * collection () const { return track_collection_.get (); }
54
55 SingletonTracks * singletonTracks () const
56 {
57 return singleton_tracks_.get ();
58 }
59
60 Q_INVOKABLE Track * getTrackForTimelineObject (
61 const arrangement::ArrangerObject * timelineObject) const;
62 Q_INVOKABLE TrackLane * getTrackLaneForObject (
63 const arrangement::ArrangerObject * timelineObject) const;
64
65 TrackRouting * trackRouting () const { return track_routing_.get (); }
66
67 int pinnedTracksCutoff () const { return pinned_tracks_cutoff_; }
68 void setPinnedTracksCutoff (int index)
69 {
70 if (index == pinned_tracks_cutoff_)
71 return;
72
73 pinned_tracks_cutoff_ = index;
74 Q_EMIT pinnedTracksCutoffChanged (index);
75 }
76 Q_SIGNAL void pinnedTracksCutoffChanged (int index);
77
78 // ========================================================================
79
80 friend void init_from (
81 Tracklist &obj,
82 const Tracklist &other,
83 utils::ObjectCloneType clone_type);
84
85 std::optional<TrackPtrVariant> get_track (const TrackUuid &id) const
86 {
87 auto span = collection ()->get_track_span ();
88 auto it = std::ranges::find (span, id, TrackSpan::uuid_projection);
89 if (it == span.end ()) [[unlikely]]
90 {
91 return std::nullopt;
92 }
93 return std::make_optional (*it);
94 }
95
104 std::optional<TrackPtrVariant>
105 get_visible_track_after_delta (Track::Uuid track_id, int delta) const;
113 double multiplier,
114 bool visible_only,
115 bool check_only,
116 bool fire_events);
117
121 void handle_click (TrackUuid track_id, bool ctrl, bool shift, bool dragged);
122
123 std::vector<ArrangerObjectPtrVariant> get_timeline_objects () const;
124
130 void
132
133 std::optional<TrackUuidReference>
134 get_track_for_plugin (const plugins::Plugin::Uuid &plugin_id) const;
135
141 */
142 bool should_be_visible (const Track::Uuid &track_id) const;
143
145
147 bool is_track_pinned (int index) const
148 {
149 return index < pinned_tracks_cutoff_;
150 }
151
152 bool is_track_pinned (Track::Uuid track_id) const
153 {
154 return is_track_pinned (
155 static_cast<int> (collection ()->get_track_index (track_id)));
156 }
157
158 auto get_track_route_target (const TrackUuid &source_track) const
159 {
160 return track_routing_->get_output_track (source_track);
161 }
162
172 TrackPtrVariant track_var,
173 bool bounce,
174 bool mark_regions,
175 bool mark_children,
176 bool mark_parents);
177
178private:
179 static constexpr auto kPinnedTracksCutoffKey = "pinnedTracksCutoff"sv;
180 static constexpr auto kTracksKey = "tracks"sv;
181 friend void to_json (nlohmann::json &j, const Tracklist &t)
182 {
183 j = nlohmann::json{
184 { kPinnedTracksCutoffKey, t.pinned_tracks_cutoff_ },
185 { kTracksKey, t.track_collection_ },
186 };
187 }
188 friend void from_json (const nlohmann::json &j, Tracklist &t);
189
190private:
191 auto &get_track_registry () const { return track_registry_; }
192 auto &get_track_registry () { return track_registry_; }
193
194private:
195 TrackRegistry &track_registry_;
196
214 utils::QObjectUniquePtr<TrackCollection> track_collection_;
215
216 utils::QObjectUniquePtr<TrackRouting> track_routing_;
217
218 utils::QObjectUniquePtr<SingletonTracks> singleton_tracks_;
219
225 int pinned_tracks_cutoff_ = 0;
226};
227}
Base class for all objects in the arranger.
References to tracks that are singletons.
A collection of tracks that provides a QAbstractListModel interface.
A container of MIDI or Audio regions.
Definition track_lane.h:28
Management of track-to-track connections.
Represents a track in the project.
Definition track.h:54
bool is_track_pinned(int index) const
Returns whether the track at index is pinned.
Definition tracklist.h:141
bool should_be_visible(const Track::Uuid &track_id) const
Returns whether the track should be visible.
void clear_selections_for_object_siblings(const ArrangerObject::Uuid &object_id)
Clears either the timeline selections or the clip editor selections.
std::optional< TrackPtrVariant > get_visible_track_after_delta(Track::Uuid track_id, int delta) const
Returns the Track after delta visible Track's.
bool multiply_track_heights(double multiplier, bool visible_only, bool check_only, bool fire_events)
Multiplies all tracks' heights and returns if the operation was valid.
void handle_click(TrackUuid track_id, bool ctrl, bool shift, bool dragged)
Handle a click selection.
void mark_track_for_bounce(TrackPtrVariant track_var, bool bounce, bool mark_regions, bool mark_children, bool mark_parents)
Marks the track for bouncing.