Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
clip_editor.h
1// SPDX-FileCopyrightText: © 2019-2021, 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "structure/arrangement/audio_clip_editor.h"
7#include "structure/arrangement/automation_editor.h"
8#include "structure/arrangement/chord_editor.h"
9#include "structure/arrangement/piano_roll.h"
10#include "structure/tracks/track.h"
11#include "structure/tracks/track_fwd.h"
12
13class ArrangerSelections;
14
20
21#define CLIP_EDITOR (PROJECT->clip_editor_)
22
26class ClipEditor : public QObject
27{
28 Q_OBJECT
29 Q_PROPERTY (QVariant region READ region NOTIFY regionChanged)
30 Q_PROPERTY (QVariant track READ track NOTIFY regionChanged)
31 Q_PROPERTY (
32 zrythm::structure::arrangement::PianoRoll * pianoRoll READ getPianoRoll
33 CONSTANT FINAL)
34 Q_PROPERTY (
36 getChordEditor CONSTANT FINAL)
37 Q_PROPERTY (
39 getAudioClipEditor CONSTANT FINAL)
40 Q_PROPERTY (
42 getAutomationEditor CONSTANT FINAL)
43 QML_ELEMENT
44 QML_UNCREATABLE ("")
45
46 using ArrangerObjectRegistry = structure::arrangement::ArrangerObjectRegistry;
47 using TrackResolver = structure::tracks::TrackResolver;
48 using TrackPtrVariant = structure::tracks::TrackPtrVariant;
49 using TrackUuid = structure::tracks::TrackUuid;
50 using ArrangerObject = structure::arrangement::ArrangerObject;
51 using ArrangerObjectPtrVariant =
52 structure::arrangement::ArrangerObjectPtrVariant;
53
54public:
55 ClipEditor (
56 ArrangerObjectRegistry &reg,
57 TrackResolver track_resolver,
58 QObject * parent = nullptr);
59
60 // ============================================================================
61 // QML Interface
62 // ============================================================================
63
64 structure::arrangement::PianoRoll * getPianoRoll () const
65 {
66 return piano_roll_.get ();
67 }
68 structure::arrangement::ChordEditor * getChordEditor () const
69 {
70 return chord_editor_.get ();
71 }
72 structure::arrangement::AudioClipEditor * getAudioClipEditor () const
73 {
74 return audio_clip_editor_.get ();
75 }
76 structure::arrangement::AutomationEditor * getAutomationEditor () const
77 {
78 return automation_editor_.get ();
79 }
80
81 QVariant region () const
82 {
83 if (has_region ())
84 {
85 return QVariant::fromStdVariant (get_region_and_track ()->first);
86 }
87
88 return {};
89 }
90 QVariant track () const
91 {
92 if (has_region ())
93 {
94 return QVariant::fromStdVariant (get_region_and_track ()->second);
95 }
96
97 return {};
98 }
99 Q_INVOKABLE void setRegion (QVariant region, QVariant track);
100 Q_INVOKABLE void unsetRegion ();
101 Q_SIGNAL void regionChanged (QVariant region);
102
103 // ============================================================================
104
108 void init_loaded ();
109
110 /**
111 * Inits the clip editor.
112 */
113 void init ();
114
118 void set_region (ArrangerObject::Uuid region_id, TrackUuid track_id)
119 {
120 if (region_id_.has_value () && region_id_.value ().first == region_id)
121 return;
122
123 region_id_ = { region_id, track_id };
124 Q_EMIT regionChanged (
125 QVariant::fromStdVariant (get_region_and_track ().value ().first));
126 };
127
128 bool has_region () const { return region_id_.has_value (); }
129
130 std::optional<std::pair<ArrangerObjectPtrVariant, TrackPtrVariant>>
131 get_region_and_track () const;
132
133 friend void init_from (
134 ClipEditor &obj,
135 const ClipEditor &other,
136 utils::ObjectCloneType clone_type)
137
138 {
139 obj.region_id_ = other.region_id_;
140 init_from (*obj.audio_clip_editor_, *other.audio_clip_editor_, clone_type);
141 init_from (*obj.automation_editor_, *other.automation_editor_, clone_type);
142 init_from (*obj.chord_editor_, *other.chord_editor_, clone_type);
143 init_from (*obj.piano_roll_, *other.piano_roll_, clone_type);
144 }
145
146private:
147 static constexpr auto kRegionIdKey = "regionId"sv;
148 static constexpr auto kPianoRollKey = "pianoRoll"sv;
149 static constexpr auto kAutomationEditorKey = "automationEditor"sv;
150 static constexpr auto kChordEditorKey = "chordEditor"sv;
151 static constexpr auto kAudioClipEditorKey = "audioClipEditor"sv;
152 friend void to_json (nlohmann::json &j, const ClipEditor &editor)
153 {
154 j[kRegionIdKey] = editor.region_id_;
155 j[kPianoRollKey] = editor.piano_roll_;
156 j[kAutomationEditorKey] = editor.automation_editor_;
157 j[kChordEditorKey] = editor.chord_editor_;
158 j[kAudioClipEditorKey] = editor.audio_clip_editor_;
159 }
160 friend void from_json (const nlohmann::json &j, ClipEditor &editor)
161 {
162 j.at (kRegionIdKey).get_to (editor.region_id_);
163 j.at (kPianoRollKey).get_to (*editor.piano_roll_);
164 j.at (kAutomationEditorKey).get_to (*editor.automation_editor_);
165 j.at (kChordEditorKey).get_to (*editor.chord_editor_);
166 j.at (kAudioClipEditorKey).get_to (*editor.audio_clip_editor_);
167 }
168
169public:
170 ArrangerObjectRegistry &object_registry_;
171 TrackResolver track_resolver_;
172
174 std::optional<std::pair<ArrangerObject::Uuid, TrackUuid>> region_id_;
175
176 utils::QObjectUniquePtr<structure::arrangement::PianoRoll> piano_roll_;
177 utils::QObjectUniquePtr<structure::arrangement::AudioClipEditor>
178 audio_clip_editor_;
179 utils::QObjectUniquePtr<structure::arrangement::AutomationEditor>
180 automation_editor_;
181 utils::QObjectUniquePtr<structure::arrangement::ChordEditor> chord_editor_;
182};
183
void set_region(ArrangerObject::Uuid region_id, TrackUuid track_id)
Sets the track and refreshes the piano roll widgets.
void init()
Inits the clip editor.
std::optional< std::pair< ArrangerObject::Uuid, TrackUuid > > region_id_
Region currently attached to the clip editor.
void init_loaded()
Inits the ClipEditor after a Project is loaded.
Base class for all objects in the arranger.
Audio clip editor serializable backend.
Backend for the chord editor.
Piano roll serializable backend.
Definition piano_roll.h:75