Zrythm v2.0.0-alpha.1
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/scenes/clip_slot.h"
7#include "structure/tracks/track_collection.h"
8#include "utils/iobject_registry.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 utils::IObjectRegistry &registry,
30 const tracks::TrackCollection &track_collection,
31 QObject * parent = nullptr);
32
33 ClipSlotList * clipSlots () const { return clip_slot_list_.get (); }
34
35 // Name property
36 QString name () const { return name_; }
37 void setName (const QString &name);
38 Q_SIGNAL void nameChanged (const QString &name);
39
40 // Color property
41 QColor color () const { return color_; }
42 void setColor (const QColor &color);
43 Q_SIGNAL void colorChanged (const QColor &color);
44
45 // Access to clip slots
46 auto &clip_slots () const { return clip_slot_list_->clip_slots (); }
47
48private:
49 static constexpr auto kNameKey = "name"sv;
50 static constexpr auto kColorKey = "color"sv;
51 static constexpr auto kClipSlotsKey = "clipSlots"sv;
52 friend void to_json (nlohmann::json &j, const Scene &scene);
53 friend void from_json (const nlohmann::json &j, Scene &scene);
54
55private:
56 QString name_;
57 QColor color_;
59};
60
61class SceneList : public QAbstractListModel
62{
63 Q_OBJECT
64 QML_ELEMENT
65 QML_UNCREATABLE ("")
66
67public:
68 SceneList (
69 utils::IObjectRegistry &registry,
70 const tracks::TrackCollection &track_collection,
71 QObject * parent = nullptr);
72
73 enum SceneListRoles
74 {
75 ScenePtrRole = Qt::UserRole + 1,
76 };
77
78 // Scene management
79 void insert_scene (utils::QObjectUniquePtr<Scene> scene, int index);
80 Q_INVOKABLE void removeScene (int index);
81 Q_INVOKABLE void moveScene (int fromIndex, int toIndex);
82
83 auto &scenes () const { return scenes_; }
84
85 // ========================================================================
86 // QML Interface
87 // ========================================================================
88
89 QHash<int, QByteArray> roleNames () const override
90 {
91 QHash<int, QByteArray> roles;
92 roles[ScenePtrRole] = "scene";
93 return roles;
94 }
95 int rowCount (const QModelIndex &parent = QModelIndex ()) const override
96 {
97 if (parent.isValid ())
98 return 0;
99 return static_cast<int> (scenes_.size ());
100 }
101 QVariant
102 data (const QModelIndex &index, int role = Qt::DisplayRole) const override
103 {
104 const auto index_int = index.row ();
105 if (!index.isValid () || index_int >= static_cast<int> (scenes_.size ()))
106 return {};
107
108 if (role == ScenePtrRole)
109 {
110 return QVariant::fromValue (scenes_.at (index_int).get ());
111 }
112
113 return {};
114 }
115 // ========================================================================
116
117private:
118 friend void to_json (nlohmann::json &j, const SceneList &list);
119 friend void from_json (const nlohmann::json &j, SceneList &list);
120
121private:
122 std::vector<utils::QObjectUniquePtr<Scene>> scenes_;
123 utils::IObjectRegistry &registry_;
124 const tracks::TrackCollection &track_collection_;
125};
126}
A collection of tracks that provides a QAbstractListModel interface.
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