Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
project.h
1// SPDX-FileCopyrightText: © 2018-2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "dsp/audio_pool.h"
7#include "dsp/engine.h"
8#include "dsp/hardware_audio_interface.h"
9#include "dsp/metronome.h"
10#include "dsp/port_connections_manager.h"
11#include "dsp/tempo_map_qml_adapter.h"
12#include "dsp/transport.h"
13#include "plugins/plugin.h"
14#include "plugins/plugin_factory.h"
15#include "structure/arrangement/arranger_object_factory.h"
16#include "structure/arrangement/tempo_object_manager.h"
17#include "structure/scenes/clip_launcher.h"
18#include "structure/scenes/clip_playback_service.h"
19#include "structure/tracks/track_factory.h"
20#include "structure/tracks/tracklist.h"
21#include "utils/app_settings.h"
22
23namespace zrythm::dsp
24{
25class Fader;
26}
27
28namespace zrythm::structure::project
29{
30
31#define PORT_CONNECTIONS_MGR (PROJECT->port_connections_manager_.get ())
32#define AUDIO_POOL (PROJECT->audio_pool_.get ())
33#define TRANSPORT (PROJECT->transport_)
34
35#define TRACKLIST (PROJECT->tracklist_)
36#define P_CHORD_TRACK (TRACKLIST->singletonTracks ()->chordTrack ())
37#define P_MARKER_TRACK (TRACKLIST->singletonTracks ()->markerTrack ())
38#define P_MASTER_TRACK (TRACKLIST->singletonTracks ()->masterTrack ())
39#define P_MODULATOR_TRACK (TRACKLIST->singletonTracks ()->modulatorTrack ())
40#define MONITOR_FADER (PROJECT->controlRoom ()->monitor_fader_)
41#define ROUTER (&PROJECT->engine ()->graph_dispatcher ())
42#define AUDIO_ENGINE (PROJECT->engine ())
43
47class Project final : public QObject
48{
49 Q_OBJECT
50 QML_ELEMENT
51 Q_PROPERTY (
52 zrythm::structure::tracks::Tracklist * tracklist READ tracklist CONSTANT
53 FINAL)
54 Q_PROPERTY (
55 zrythm::structure::scenes::ClipLauncher * clipLauncher READ clipLauncher
56 CONSTANT FINAL)
57 Q_PROPERTY (
58 zrythm::structure::scenes::ClipPlaybackService * clipPlaybackService READ
59 clipPlaybackService CONSTANT FINAL)
60 Q_PROPERTY (zrythm::dsp::AudioEngine * engine READ engine CONSTANT FINAL)
61 Q_PROPERTY (
62 zrythm::dsp::Transport * transport READ getTransport CONSTANT FINAL)
63 Q_PROPERTY (
64 zrythm::dsp::TempoMapWrapper * tempoMap READ getTempoMap CONSTANT FINAL)
65 Q_PROPERTY (
67 tempoObjectManager CONSTANT FINAL)
68 QML_UNCREATABLE ("")
69
70 friend struct PluginBuilderForDeserialization;
71
72public:
73 using TrackUuid = structure::tracks::TrackUuid;
74 using PluginPtrVariant = plugins::PluginPtrVariant;
75 using PluginRegistry = plugins::PluginRegistry;
76 using ProjectDirectoryPathProvider = std::function<fs::path (bool for_backup)>;
77
78public:
79 Project (
80 utils::AppSettings &app_settings,
81 ProjectDirectoryPathProvider project_directory_path_provider,
82 dsp::IHardwareAudioInterface &hw_interface,
83 std::shared_ptr<juce::AudioPluginFormatManager> plugin_format_manager,
84 plugins::PluginHostWindowFactory plugin_host_window_provider,
85 dsp::Metronome &metronome,
86 dsp::Fader &monitor_fader,
87 QObject * parent = nullptr);
88 ~Project () override;
89 Z_DISABLE_COPY_MOVE (Project)
90
91 // =========================================================
92 // QML interface
93 // =========================================================
94
95 structure::tracks::Tracklist * tracklist () const;
96 structure::scenes::ClipLauncher * clipLauncher () const;
97 structure::scenes::ClipPlaybackService * clipPlaybackService () const;
98 dsp::Transport * getTransport () const;
99 dsp::AudioEngine * engine () const;
100 dsp::TempoMapWrapper * getTempoMap () const;
101 structure::arrangement::TempoObjectManager * tempoObjectManager () const;
102
103 Q_SIGNAL void aboutToBeDeleted ();
104
105 // =========================================================
106 // TODO: Remove these accessors - QML should access via ControlRoom instead
107
108 dsp::Fader &monitor_fader () const;
109 dsp::Metronome &metronome () const;
110
111 // TODO: delete this getter, no one else should use factory directly
112 auto * arrangerObjectFactory () const
113 {
114 return arranger_object_factory_.get ();
115 }
116
117 friend void init_from (
118 Project &obj,
119 const Project &other,
120 utils::ObjectCloneType clone_type);
121
127 void add_default_tracks ();
128
130 get_final_track_dependencies () const;
131
132 auto &get_file_audio_source_registry () const
133 {
134 return *file_audio_source_registry_;
135 }
136 auto &get_track_registry () const { return *track_registry_; }
137 auto &get_plugin_registry () const { return *plugin_registry_; }
138 auto &get_port_registry () const { return *port_registry_; }
139 auto &get_param_registry () const { return *param_registry_; }
140 auto &get_arranger_object_registry () const
141 {
142 return *arranger_object_registry_;
144
147
152 std::optional<dsp::PortPtrVariant>
153 find_port_by_id (const dsp::Port::Uuid &id) const
154 {
155 return get_port_registry ().find_by_id (id);
156 }
157
159 find_param_by_id (const dsp::ProcessorParameter::Uuid &id) const
160 {
161 const auto opt_var = get_param_registry ().find_by_id (id);
162 if (opt_var.has_value ())
163 {
164 return std::get<dsp::ProcessorParameter *> (opt_var.value ());
165 }
166 return nullptr;
167 }
168
169 std::optional<plugins::PluginPtrVariant>
170 find_plugin_by_id (plugins::Plugin::Uuid id) const
171 {
172 return get_plugin_registry ().find_by_id (id);
173 }
174
175 std::optional<zrythm::structure::tracks::TrackPtrVariant>
176 find_track_by_id (structure::tracks::Track::Uuid id) const
177 {
178 return get_track_registry ().find_by_id (id);
179 }
180
181 std::optional<zrythm::structure::arrangement::ArrangerObjectPtrVariant>
182 find_arranger_object_by_id (
183 structure::arrangement::ArrangerObject::Uuid id) const
184 {
185 return get_arranger_object_registry ().find_by_id (id);
186 }
187
188 const auto &tempo_map () const { return tempo_map_; }
189
190private:
191 static constexpr auto kTempoMapKey = "tempoMap"sv;
192 static constexpr auto kFileAudioSourceRegistryKey =
193 "fileAudioSourceRegistry"sv;
194 static constexpr auto kPortRegistryKey = "portRegistry"sv;
195 static constexpr auto kParameterRegistryKey = "paramRegistry"sv;
196 static constexpr auto kPluginRegistryKey = "pluginRegistry"sv;
197 static constexpr auto kArrangerObjectRegistryKey = "arrangerObjectRegistry"sv;
198 static constexpr auto kTrackRegistryKey = "trackRegistry"sv;
199 static constexpr auto kTransportKey = "transport"sv;
200 static constexpr auto kAudioPoolKey = "audioPool"sv;
201 static constexpr auto kTracklistKey = "tracklist"sv;
202 static constexpr auto kRegionLinkGroupManagerKey = "regionLinkGroupManager"sv;
203 static constexpr auto kPortConnectionsManagerKey = "portConnectionsManager"sv;
204 static constexpr auto kTempoObjectManagerKey = "tempoObjectManager"sv;
205 static constexpr auto kClipLauncherKey = "clipLauncher"sv;
206 friend void to_json (nlohmann::json &j, const Project &project);
207 friend void from_json (const nlohmann::json &j, Project &project);
208
209private:
210 utils::AppSettings &app_settings_;
211 dsp::TempoMap tempo_map_;
212 utils::QObjectUniquePtr<dsp::TempoMapWrapper> tempo_map_wrapper_;
213
214 plugins::PluginHostWindowFactory plugin_host_window_provider_;
215
216 utils::QObjectUniquePtr<dsp::FileAudioSourceRegistry>
217 file_audio_source_registry_;
218 utils::QObjectUniquePtr<dsp::PortRegistry> port_registry_;
219 utils::QObjectUniquePtr<dsp::ProcessorParameterRegistry> param_registry_;
220 utils::QObjectUniquePtr<PluginRegistry> plugin_registry_;
221 utils::QObjectUniquePtr<structure::arrangement::ArrangerObjectRegistry>
222 arranger_object_registry_;
223 utils::QObjectUniquePtr<structure::tracks::TrackRegistry> track_registry_;
224
225 ProjectDirectoryPathProvider project_directory_path_provider_;
226
227 /* !!! IMPORTANT: order matters (for destruction) !!! */
229 dsp::IHardwareAudioInterface &hw_interface_;
230 std::shared_ptr<juce::AudioPluginFormatManager> plugin_format_manager_;
231
232public:
240public:
245
250
252 std::unique_ptr<dsp::AudioPool> pool_;
253
255 // structure::arrangement::RegionLinkGroupManager region_link_group_manager_;
256
263
267 boost::unordered_flat_map<
268 structure::tracks::TrackUuid,
269 structure::tracks::TrackPtrVariant>
271
272private:
275 clip_playback_service_;
276
277 std::unique_ptr<structure::arrangement::ArrangerObjectFactory>
278 arranger_object_factory_;
279
280public:
282 std::unique_ptr<structure::tracks::TrackFactory> track_factory_;
283
284private:
286 tempo_object_manager_;
287
288 dsp::Fader &monitor_fader_;
289 dsp::Metronome &metronome_;
290
297 dsp::DspGraphDispatcher graph_dispatcher_;
298};
299
300}
The audio engine.
Definition engine.h:23
The DspGraphDispatcher class manages the processing graph for the audio engine.
A Fader is a processor that is used for volume controls and pan.
Definition fader.h:21
Abstraction for hardware audio interface.
Metronome processor.
Definition metronome.h:20
Processor parameter that accepts automation and modulation sources and integrates with QML and the DS...
Definition parameter.h:220
The Transport class represents the transport controls and state for an audio engine.
Definition transport.h:44
Manages tempo and time signature objects for a project.
boost::unordered_flat_map< structure::tracks::TrackUuid, structure::tracks::TrackPtrVariant > tracks_rt_
Realtime cache of tracks.
Definition project.h:260
std::unique_ptr< dsp::AudioPool > pool_
Audio file pool.
Definition project.h:242
utils::QObjectUniquePtr< dsp::Transport > transport_
Timeline metadata like BPM, time signature, etc.
Definition project.h:234
std::optional< dsp::PortPtrVariant > find_port_by_id(const dsp::Port::Uuid &id) const
Finds the Port corresponding to the identifier.
Definition project.h:143
void add_default_tracks()
Adds the default undeletable tracks to the project.
utils::QObjectUniquePtr< dsp::PortConnectionsManager > port_connections_manager_
Must be free'd after engine.
Definition project.h:228
utils::QObjectUniquePtr< dsp::AudioEngine > audio_engine_
The audio backend.
Definition project.h:239
utils::QObjectUniquePtr< structure::tracks::Tracklist > tracklist_
Manager for region link groups.
Definition project.h:252
Service for managing clip playback operations.
A higher level wrapper over a track collection that serves as the project's only tracklist.
Definition tracklist.h:23
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:38