Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
scene.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.h"
7#include "structure/scenes/clip_slot.h"
8#include "structure/tracks/track_collection.h"
9
10#include <QtQmlIntegration/qqmlintegration.h>
11
12#include <nlohmann/json_fwd.hpp>
13
14namespace zrythm::structure::scenes
15{
16
17class Scene : public QObject
18{
19 Q_OBJECT
20 Q_PROPERTY (QString name READ name WRITE setName NOTIFY nameChanged)
21 Q_PROPERTY (QColor color READ color WRITE setColor NOTIFY colorChanged)
22 Q_PROPERTY (
23 zrythm::structure::scenes::ClipSlotList * clipSlots READ clipSlots CONSTANT)
24 QML_ELEMENT
25 QML_UNCREATABLE ("")
26
27public:
28 Scene (
29 arrangement::ArrangerObjectRegistry &object_registry,
30 const tracks::TrackCollection &track_collection,
31 QObject * parent = nullptr)
32 : QObject (parent),
33 clip_slot_list_ (
34 utils::make_qobject_unique<
35 ClipSlotList> (object_registry, track_collection, this))
36 {
37 }
38
39 ClipSlotList * clipSlots () const { return clip_slot_list_.get (); }
40
41 // Name property
42 QString name () const { return name_; }
43 void setName (const QString &name);
44 Q_SIGNAL void nameChanged (const QString &name);
45
46 // Color property
47 QColor color () const { return color_; }
48 void setColor (const QColor &color);
49 Q_SIGNAL void colorChanged (const QColor &color);
50
51 // Access to clip slots
52 auto &clip_slots () const { return clip_slot_list_->clip_slots (); }
53
54private:
55 static constexpr auto kNameKey = "name"sv;
56 static constexpr auto kColorKey = "color"sv;
57 static constexpr auto kClipSlotsKey = "clipSlots"sv;
58 friend void to_json (nlohmann::json &j, const Scene &scene);
59 friend void from_json (const nlohmann::json &j, Scene &scene);
60
61private:
62 QString name_;
63 QColor color_;
65};
66
67class SceneList : public QAbstractListModel
68{
69 Q_OBJECT
70 QML_ELEMENT
71 QML_UNCREATABLE ("")
72
73public:
74 SceneList (
75 arrangement::ArrangerObjectRegistry &object_registry,
76 const tracks::TrackCollection &track_collection,
77 QObject * parent = nullptr);
78
79 enum SceneListRoles
80 {
81 ScenePtrRole = Qt::UserRole + 1,
82 };
83
84 // Scene management
85 void insert_scene (utils::QObjectUniquePtr<Scene> scene, int index);
86 Q_INVOKABLE void removeScene (int index);
87 Q_INVOKABLE void moveScene (int fromIndex, int toIndex);
88
89 auto &scenes () const { return scenes_; }
90
91 // ========================================================================
92 // QML Interface
93 // ========================================================================
94
95 QHash<int, QByteArray> roleNames () const override
96 {
97 QHash<int, QByteArray> roles;
98 roles[ScenePtrRole] = "scene";
99 return roles;
100 }
101 int rowCount (const QModelIndex &parent = QModelIndex ()) const override
102 {
103 if (parent.isValid ())
104 return 0;
105 return static_cast<int> (scenes_.size ());
106 }
107 QVariant
108 data (const QModelIndex &index, int role = Qt::DisplayRole) const override
109 {
110 const auto index_int = index.row ();
111 if (!index.isValid () || index_int >= static_cast<int> (scenes_.size ()))
112 return {};
113
114 if (role == ScenePtrRole)
115 {
116 return QVariant::fromValue (scenes_.at (index_int).get ());
117 }
118
119 return {};
120 }
121 // ========================================================================
122
123private:
124 friend void to_json (nlohmann::json &j, const SceneList &list);
125 friend void from_json (const nlohmann::json &j, SceneList &list);
126
127private:
128 std::vector<utils::QObjectUniquePtr<Scene>> scenes_;
129 arrangement::ArrangerObjectRegistry &object_registry_;
130 const tracks::TrackCollection &track_collection_;
131};
132}
A collection of tracks that provides a QAbstractListModel interface.
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:38