Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
clip_slot.h
1// SPDX-FileCopyrightText: © 2025 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>
10
11namespace zrythm::structure::scenes
12{
13
14class ClipSlot : public QObject
15{
16 Q_OBJECT
17 Q_PROPERTY (
18 zrythm::structure::arrangement::ArrangerObject * region READ region WRITE
19 setRegion NOTIFY regionChanged)
20 Q_PROPERTY (ClipState state READ state WRITE setState NOTIFY stateChanged)
21 QML_ELEMENT
22 QML_UNCREATABLE ("")
23 QML_EXTENDED_NAMESPACE (zrythm::structure::tracks)
24
25public:
26 enum class ClipState
27 {
28 Stopped,
29 PlayQueued,
30 Playing,
31 StopQueued,
32 };
33 Q_ENUM (ClipState)
34
35 ClipSlot (
36 arrangement::ArrangerObjectRegistry &object_registry,
37 QObject * parent = nullptr);
38
39 arrangement::ArrangerObject * region () const
40 {
41 if (region_ref_.has_value ())
42 {
43 return region_ref_->get_object_base ();
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 std::optional<arrangement::ArrangerObjectUuidReference> region_ref_;
68 arrangement::ArrangerObjectRegistry &object_registry_;
69 std::atomic<ClipState> state_{ ClipState::Stopped };
70};
71
72class ClipSlotList : public QAbstractListModel
73{
74 Q_OBJECT
75 QML_ELEMENT
76 QML_UNCREATABLE ("")
77
78public:
79 ClipSlotList (
80 arrangement::ArrangerObjectRegistry &object_registry,
81 const tracks::TrackCollection &track_collection,
82 QObject * parent = nullptr);
83 Z_DISABLE_COPY_MOVE (ClipSlotList)
84
85 enum ClipSlotListRoles
86 {
87 ClipSlotPtrRole = Qt::UserRole + 1,
88 };
89 Q_ENUM (ClipSlotListRoles)
90
91 // ========================================================================
92 // QML Interface
93 // ========================================================================
94
95 Q_INVOKABLE ClipSlot * clipSlotForTrack (const tracks::Track * track) const
96 {
97 return clip_slots_
98 .at (track_collection_.get_track_index (track->get_uuid ()))
99 .get ();
100 }
101
102 QHash<int, QByteArray> roleNames () const override
103 {
104 QHash<int, QByteArray> roles;
105 roles[ClipSlotPtrRole] = "clipSlot";
106 return roles;
107 }
108 int rowCount (const QModelIndex &parent = QModelIndex ()) const override
109 {
110 if (parent.isValid ())
111 return 0;
112 return static_cast<int> (clip_slots_.size ());
113 }
114 QVariant
115 data (const QModelIndex &index, int role = Qt::DisplayRole) const override
116 {
117 const auto index_int = index.row ();
118 if (!index.isValid () || index_int >= static_cast<int> (clip_slots_.size ()))
119 return {};
120
121 if (role == ClipSlotPtrRole)
122 {
123 return QVariant::fromValue (clip_slots_.at (index_int).get ());
124 }
125
126 return {};
127 }
128
129 // ========================================================================
130
131 auto &clip_slots () const { return clip_slots_; }
132
133private:
134 // These must be in the order of tracks in the tracklist.
135 std::vector<utils::QObjectUniquePtr<ClipSlot>> clip_slots_;
136
137 arrangement::ArrangerObjectRegistry &object_registry_;
138 const tracks::TrackCollection &track_collection_;
139};
140}
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:54