Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
track_lane_list.h
1// SPDX-FileCopyrightText: © 2024-2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "structure/tracks/track_lane.h"
7#include "utils/expandable_tick_range.h"
8#include "utils/qt.h"
9
10namespace zrythm::structure::tracks
11{
12class TrackLaneList : public QAbstractListModel
13{
14 Q_OBJECT
15 Q_PROPERTY (
16 bool lanesVisible READ lanesVisible WRITE setLanesVisible NOTIFY
17 lanesVisibleChanged)
18 QML_ELEMENT
19 QML_UNCREATABLE ("")
20
21public:
22 enum Roles
23 {
24 TrackLanePtrRole = Qt::UserRole + 1,
25 };
26 Q_ENUM (Roles)
27
28public:
29 TrackLaneList (
30 structure::arrangement::ArrangerObjectRegistry &obj_registry,
31 dsp::FileAudioSourceRegistry &file_audio_source_registry,
32 QObject * parent = nullptr);
33 ~TrackLaneList () override;
34 Q_DISABLE_COPY_MOVE (TrackLaneList)
35
36 // ========================================================================
37 // QML Interface
38 // ========================================================================
39 QHash<int, QByteArray> roleNames () const override;
40 int rowCount (const QModelIndex &parent = QModelIndex ()) const override;
41 QVariant
42 data (const QModelIndex &index, int role = Qt::DisplayRole) const override;
43
44 Q_INVOKABLE TrackLane * getFirstLane () const
45 {
46 return lanes_.front ().get ();
47 }
48
49 bool lanesVisible () const { return lanes_visible_; }
50 void setLanesVisible (bool visible)
51 {
52 if (lanes_visible_ == visible)
53 return;
54
55 lanes_visible_ = visible;
56 Q_EMIT lanesVisibleChanged (visible);
57 }
58 Q_SIGNAL void lanesVisibleChanged (bool visible);
59
63 Q_INVOKABLE TrackLane * addLane () { return insertLane (rowCount ()); }
64 Q_INVOKABLE TrackLane * insertLane (size_t index);
65 Q_INVOKABLE void removeLane (size_t index);
66
67 Q_INVOKABLE void moveLane (size_t from_index, size_t to_index);
68
69 Q_SIGNAL void
70 laneObjectsNeedRecache (utils::ExpandableTickRange affectedRange);
71
72 Q_SIGNAL void totalHeightChanged ();
73
74 // ========================================================================
75
76 [[nodiscard]] size_t size () const noexcept { return lanes_.size (); }
77
78 [[nodiscard]] bool empty () const noexcept { return lanes_.empty (); }
79
80 TrackLane * at (size_t idx) const { return lanes_.at (idx).get (); }
84
85 void clear ();
86
87 auto &lanes () const { return lanes_; }
88
89 auto lanes_view () const
90 {
91 return lanes_
92 | std::views::transform (&utils::QObjectUniquePtr<TrackLane>::get);
93 }
94
96 * @brief Gets the total height of all visible lanes (if any).
97 */
98 double get_visible_lane_heights () const
99 {
100 if (!lanes_visible_)
101 return 0;
102
103 return std::ranges::fold_left (
104 lanes_view () | std::views::transform (&TrackLane::height), 0,
105 std::plus{});
106 }
107
111 void create_missing_lanes (size_t index);
112
117
118private:
119 static constexpr auto kLanesKey = "lanes"sv;
120 static constexpr std::string_view kLanesVisibleKey = "lanesVisible";
121 friend void to_json (nlohmann::json &j, const TrackLaneList &p);
122 friend void from_json (const nlohmann::json &j, TrackLaneList &p);
123
124 void erase (size_t pos);
125
126 void update_default_lane_names ();
127
128private:
130 std::vector<utils::QObjectUniquePtr<TrackLane>> lanes_;
131
133 bool lanes_visible_ = false;
134
135 BOOST_DESCRIBE_CLASS (TrackLaneList, (), (), (), (lanes_, lanes_visible_))
136};
137}
double get_visible_lane_heights() const
Gets the total height of all visible lanes (if any).
void create_missing_lanes(size_t index)
Creates missing TrackLane's until index.
void remove_empty_last_lanes()
Removes the empty last lanes of the Track (except the last one).
Q_INVOKABLE TrackLane * addLane()
Adds a lane to the end of the list with default settings.
utils::QObjectUniquePtr< TrackLane > pop_back()
Removes last lane.
A container of MIDI or Audio regions.
Definition track_lane.h:28
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:36