Zrythm v2.0.0-alpha.1
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
clip_slot.h
1// SPDX-FileCopyrightText: © 2025-2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "structure/arrangement/arranger_object_all.h"
7#include "structure/tracks/track_collection.h"
8
9#include <QtQmlIntegration/qqmlintegration.h>
10
11#include <nlohmann/json_fwd.hpp>
12
13namespace zrythm::structure::scenes
14{
15
16class ClipSlot : public QObject
17{
18 Q_OBJECT
19 Q_PROPERTY (
20 zrythm::structure::arrangement::ArrangerObject * region READ region WRITE
21 setRegion NOTIFY regionChanged)
22 Q_PROPERTY (ClipState state READ state WRITE setState NOTIFY stateChanged)
23 QML_ELEMENT
24 QML_UNCREATABLE ("")
25 QML_EXTENDED_NAMESPACE (zrythm::structure::tracks)
26
27public:
28 enum class ClipState
29 {
30 Stopped,
31 PlayQueued,
32 Playing,
33 StopQueued,
34 };
35 Q_ENUM (ClipState)
36
37 ClipSlot (utils::IObjectRegistry &registry, QObject * parent = nullptr);
38
39 arrangement::ArrangerObject * region () const
40 {
41 if (region_ref_.has_value ())
42 {
43 return region_ref_->get ();
44 }
45 return nullptr;
46 }
47 void setRegion (arrangement::ArrangerObject * region);
48 Q_SIGNAL void regionChanged (arrangement::ArrangerObject * region);
49
50 // Region management
51 Q_INVOKABLE void clearRegion ()
52 {
53 if (!region_ref_.has_value ())
54 {
55 return;
56 }
57
58 region_ref_.reset ();
59 Q_EMIT regionChanged (nullptr);
60 }
61
62 ClipState state () const { return state_.load (); }
63 void setState (ClipState state);
64 Q_SIGNAL void stateChanged (ClipState state);
65
66private:
67 static constexpr auto kRegionIdKey = "regionId"sv;
68 friend void to_json (nlohmann::json &j, const ClipSlot &slot);
69 friend void from_json (const nlohmann::json &j, ClipSlot &slot);
70
71private:
72 std::optional<arrangement::ArrangerObjectUuidReference> region_ref_;
73 utils::IObjectRegistry &registry_;
74 std::atomic<ClipState> state_{ ClipState::Stopped };
75};
76
77class ClipSlotList : public QAbstractListModel
78{
79 Q_OBJECT
80 QML_ELEMENT
81 QML_UNCREATABLE ("")
82
83public:
84 ClipSlotList (
85 utils::IObjectRegistry &registry,
86 const tracks::TrackCollection &track_collection,
87 QObject * parent = nullptr);
88 Q_DISABLE_COPY_MOVE (ClipSlotList)
89
90 enum ClipSlotListRoles
91 {
92 ClipSlotPtrRole = Qt::UserRole + 1,
93 };
94 Q_ENUM (ClipSlotListRoles)
95
96 // ========================================================================
97 // QML Interface
98 // ========================================================================
99
100 Q_INVOKABLE ClipSlot * clipSlotForTrack (const tracks::Track * track) const
101 {
102 return clip_slots_
103 .at (track_collection_.get_track_index (track->get_uuid ()))
104 .get ();
105 }
106
107 QHash<int, QByteArray> roleNames () const override
108 {
109 QHash<int, QByteArray> roles;
110 roles[ClipSlotPtrRole] = "clipSlot";
111 return roles;
112 }
113 int rowCount (const QModelIndex &parent = QModelIndex ()) const override
114 {
115 if (parent.isValid ())
116 return 0;
117 return static_cast<int> (clip_slots_.size ());
118 }
119 QVariant
120 data (const QModelIndex &index, int role = Qt::DisplayRole) const override
121 {
122 const auto index_int = index.row ();
123 if (!index.isValid () || index_int >= static_cast<int> (clip_slots_.size ()))
124 return {};
125
126 if (role == ClipSlotPtrRole)
127 {
128 return QVariant::fromValue (clip_slots_.at (index_int).get ());
129 }
130
131 return {};
132 }
133
134 // ========================================================================
135
136 auto &clip_slots () const { return clip_slots_; }
137
138private:
139 friend void to_json (nlohmann::json &j, const ClipSlotList &list);
140 friend void from_json (const nlohmann::json &j, ClipSlotList &list);
141
142private:
143 // These must be in the order of tracks in the tracklist.
144 std::vector<utils::QObjectUniquePtr<ClipSlot>> clip_slots_;
145
146 utils::IObjectRegistry &registry_;
147 const tracks::TrackCollection &track_collection_;
148};
149}
Base class for all objects in the arranger.
A collection of tracks that provides a QAbstractListModel interface.
Represents a track in the project.
Definition track.h:60
Abstract interface for a UUID-keyed object registry.