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-2026 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
15namespace zrythm::structure::project
16{
17
21class ClipEditor : public QObject
22{
23 Q_OBJECT
24 Q_PROPERTY (QVariant region READ region NOTIFY regionChanged)
25 Q_PROPERTY (QVariant track READ track NOTIFY regionChanged)
26 Q_PROPERTY (
27 zrythm::structure::arrangement::PianoRoll * pianoRoll READ getPianoRoll
28 CONSTANT FINAL)
29 Q_PROPERTY (
31 getChordEditor CONSTANT FINAL)
32 Q_PROPERTY (
34 getAudioClipEditor CONSTANT FINAL)
35 Q_PROPERTY (
37 getAutomationEditor CONSTANT FINAL)
38 QML_ELEMENT
39 QML_UNCREATABLE ("")
40
41 using ArrangerObjectRegistry = structure::arrangement::ArrangerObjectRegistry;
42 using TrackResolver = structure::tracks::TrackResolver;
43 using TrackPtrVariant = structure::tracks::TrackPtrVariant;
44 using TrackUuid = structure::tracks::TrackUuid;
45 using ArrangerObject = structure::arrangement::ArrangerObject;
46 using ArrangerObjectPtrVariant =
47 structure::arrangement::ArrangerObjectPtrVariant;
48
49public:
50 ClipEditor (
51 ArrangerObjectRegistry &reg,
52 TrackResolver track_resolver,
53 QObject * parent = nullptr);
54
55 // ============================================================================
56 // QML Interface
57 // ============================================================================
58
59 structure::arrangement::PianoRoll * getPianoRoll () const
60 {
61 return piano_roll_.get ();
62 }
63 structure::arrangement::ChordEditor * getChordEditor () const
64 {
65 return chord_editor_.get ();
66 }
67 structure::arrangement::AudioClipEditor * getAudioClipEditor () const
68 {
69 return audio_clip_editor_.get ();
70 }
71 structure::arrangement::AutomationEditor * getAutomationEditor () const
72 {
73 return automation_editor_.get ();
74 }
75
76 QVariant region () const;
77 QVariant track () const;
78 Q_INVOKABLE void setRegion (QVariant region, QVariant track);
79 Q_INVOKABLE void unsetRegion ();
80 Q_SIGNAL void regionChanged (QVariant region);
81
82 // ============================================================================
83
87 void init_loaded ();
88
89 /**
90 * Inits the clip editor.
91 */
92 void init ();
93
97 void set_region (ArrangerObject::Uuid region_id, TrackUuid track_id)
98 {
99 if (region_id_.has_value () && region_id_.value ().first == region_id)
100 return;
101
102 region_id_ = { region_id, track_id };
103 Q_EMIT regionChanged (
104 QVariant::fromStdVariant (get_region_and_track ().value ().first));
105 };
106
107 bool has_region () const { return region_id_.has_value (); }
108
109 std::optional<std::pair<ArrangerObjectPtrVariant, TrackPtrVariant>>
110 get_region_and_track () const;
111
112 friend void init_from (
113 ClipEditor &obj,
114 const ClipEditor &other,
115 utils::ObjectCloneType clone_type);
116
117private:
118 static constexpr auto kRegionIdKey = "regionId"sv;
119 static constexpr auto kPianoRollKey = "pianoRoll"sv;
120 static constexpr auto kAutomationEditorKey = "automationEditor"sv;
121 static constexpr auto kChordEditorKey = "chordEditor"sv;
122 static constexpr auto kAudioClipEditorKey = "audioClipEditor"sv;
123 friend void to_json (nlohmann::json &j, const ClipEditor &editor);
124 friend void from_json (const nlohmann::json &j, ClipEditor &editor);
125
126private:
127 ArrangerObjectRegistry &object_registry_;
128 TrackResolver track_resolver_;
129
131 std::optional<std::pair<ArrangerObject::Uuid, TrackUuid>> region_id_;
132
135 audio_clip_editor_;
137 automation_editor_;
139};
140
141} // namespace zrythm::structure::project
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
void set_region(ArrangerObject::Uuid region_id, TrackUuid track_id)
Sets the track and refreshes the piano roll widgets.
Definition clip_editor.h:89
void init()
Inits the clip editor.
void init_loaded()
Inits the ClipEditor after a Project is loaded.
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:38