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 Q_INVOKABLE bool isTrackPinned (const Track * track) const
66 {
67 return is_track_pinned (track->get_uuid ());
68 }
69
70 Q_INVOKABLE bool shouldBeVisible (const Track * track) const
71 {
72 return should_be_visible (track->get_uuid ());
73 }
74
75 Q_INVOKABLE bool hasChannel (const Track * track) const
76 {
77 return track->channel () != nullptr;
78 }
79
80 TrackRouting * trackRouting () const { return track_routing_.get (); }
81
82 int pinnedTracksCutoff () const { return pinned_tracks_cutoff_; }
83 void setPinnedTracksCutoff (int index)
84 {
85 if (index == pinned_tracks_cutoff_)
86 return;
87
88 pinned_tracks_cutoff_ = index;
89 Q_EMIT pinnedTracksCutoffChanged (index);
90 }
91 Q_SIGNAL void pinnedTracksCutoffChanged (int index);
92
93 // ========================================================================
94
95 friend void init_from (
96 Tracklist &obj,
97 const Tracklist &other,
98 utils::ObjectCloneType clone_type);
99
100 std::optional<TrackPtrVariant> get_track (const TrackUuid &id) const
101 {
102 auto span = collection ()->get_track_span ();
103 auto it = std::ranges::find (span, id, TrackSpan::uuid_projection);
104 if (it == span.end ()) [[unlikely]]
105 {
106 return std::nullopt;
107 }
108 return std::make_optional (*it);
109 }
110
119 std::optional<TrackPtrVariant>
120 get_visible_track_after_delta (Track::Uuid track_id, int delta) const;
128 double multiplier,
129 bool visible_only,
130 bool check_only,
131 bool fire_events);
132
136 void handle_click (TrackUuid track_id, bool ctrl, bool shift, bool dragged);
137
138 std::vector<ArrangerObjectPtrVariant> get_timeline_objects () const;
139
145 void
147
148 std::optional<TrackUuidReference>
149 get_track_for_plugin (const plugins::Plugin::Uuid &plugin_id) const;
150
156 */
157 bool should_be_visible (const Track::Uuid &track_id) const;
158
160
162 bool is_track_pinned (int index) const
163 {
164 return index < pinned_tracks_cutoff_;
165 }
166
167 bool is_track_pinned (Track::Uuid track_id) const
168 {
169 return is_track_pinned (
170 static_cast<int> (collection ()->get_track_index (track_id)));
171 }
172
173 auto get_track_route_target (const TrackUuid &source_track) const
174 {
175 return track_routing_->get_output_track (source_track);
176 }
177
187 TrackPtrVariant track_var,
188 bool bounce,
189 bool mark_regions,
190 bool mark_children,
191 bool mark_parents);
192
193private:
194 static constexpr auto kPinnedTracksCutoffKey = "pinnedTracksCutoff"sv;
195 static constexpr auto kTracksKey = "tracks"sv;
196 friend void to_json (nlohmann::json &j, const Tracklist &t);
197 friend void from_json (const nlohmann::json &j, Tracklist &t);
198
199private:
200 auto &get_track_registry () const { return track_registry_; }
201 auto &get_track_registry () { return track_registry_; }
202
203private:
204 TrackRegistry &track_registry_;
205
224
226
228
234 int pinned_tracks_cutoff_ = 0;
235};
236}
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:156
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.
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:38