Zrythm v2.0.0-alpha.1
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 (utils::IObjectRegistry &registry, QObject * parent = nullptr);
30 ~TrackLaneList () override;
31 Q_DISABLE_COPY_MOVE (TrackLaneList)
32
33 // ========================================================================
34 // QML Interface
35 // ========================================================================
36 QHash<int, QByteArray> roleNames () const override;
37 int rowCount (const QModelIndex &parent = QModelIndex ()) const override;
38 QVariant
39 data (const QModelIndex &index, int role = Qt::DisplayRole) const override;
40
41 Q_INVOKABLE TrackLane * getFirstLane () const
42 {
43 return lanes_.front ().get ();
44 }
45
46 bool lanesVisible () const { return lanes_visible_; }
47 void setLanesVisible (bool visible)
48 {
49 if (lanes_visible_ == visible)
50 return;
51
52 lanes_visible_ = visible;
53 Q_EMIT lanesVisibleChanged (visible);
54 }
55 Q_SIGNAL void lanesVisibleChanged (bool visible);
56
60 Q_INVOKABLE TrackLane * addLane () { return insertLane (rowCount ()); }
61 Q_INVOKABLE TrackLane * insertLane (size_t index);
62 Q_INVOKABLE void removeLane (size_t index);
63
64 Q_INVOKABLE void moveLane (size_t from_index, size_t to_index);
65
66 Q_SIGNAL void
67 laneObjectsNeedRecache (utils::ExpandableTickRange affectedRange);
68
69 Q_SIGNAL void totalHeightChanged ();
70
71 // ========================================================================
72
73 [[nodiscard]] size_t size () const noexcept { return lanes_.size (); }
74
75 [[nodiscard]] bool empty () const noexcept { return lanes_.empty (); }
76
77 TrackLane * at (size_t idx) const { return lanes_.at (idx).get (); }
81
82 void clear ();
83
84 auto &lanes () const { return lanes_; }
85
86 auto lanes_view () const
87 {
88 return lanes_
89 | std::views::transform (&utils::QObjectUniquePtr<TrackLane>::get);
90 }
91
93 * @brief Gets the total height of all visible lanes (if any).
94 */
95 double get_visible_lane_heights () const
96 {
97 if (!lanes_visible_)
98 return 0;
99
100 return std::ranges::fold_left (
101 lanes_view () | std::views::transform (&TrackLane::height), 0,
102 std::plus{});
103 }
104
108 void create_missing_lanes (size_t index);
109
114
115private:
116 static constexpr auto kLanesKey = "lanes"sv;
117 static constexpr std::string_view kLanesVisibleKey = "lanesVisible";
118 friend void to_json (nlohmann::json &j, const TrackLaneList &p);
119 friend void from_json (const nlohmann::json &j, TrackLaneList &p);
120
121 void erase (size_t pos);
122
123 void update_default_lane_names ();
124
125private:
127 std::vector<utils::QObjectUniquePtr<TrackLane>> lanes_;
128
130 bool lanes_visible_ = false;
131
132 BOOST_DESCRIBE_CLASS (TrackLaneList, (), (), (), (lanes_, lanes_visible_))
133};
134}
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:27
Abstract interface for a UUID-keyed object registry.
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:36