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 // =========================================================
104 // TODO: Remove these accessors - QML should access via ControlRoom instead
105
106 dsp::Fader &monitor_fader () const;
107 dsp::Metronome &metronome () const;
108
109 // TODO: delete this getter, no one else should use factory directly
110 auto * arrangerObjectFactory () const
111 {
112 return arranger_object_factory_.get ();
113 }
114
115 friend void init_from (
116 Project &obj,
117 const Project &other,
118 utils::ObjectCloneType clone_type);
119
125 void add_default_tracks ();
126
128 get_final_track_dependencies () const;
129
130 auto &get_file_audio_source_registry () const
131 {
132 return *file_audio_source_registry_;
133 }
134 auto &get_track_registry () const { return *track_registry_; }
135 auto &get_plugin_registry () const { return *plugin_registry_; }
136 auto &get_port_registry () const { return *port_registry_; }
137 auto &get_param_registry () const { return *param_registry_; }
138 auto &get_arranger_object_registry () const
139 {
140 return *arranger_object_registry_;
142
145
150 std::optional<dsp::PortPtrVariant>
151 find_port_by_id (const dsp::Port::Uuid &id) const
152 {
153 return get_port_registry ().find_by_id (id);
154 }
155
157 find_param_by_id (const dsp::ProcessorParameter::Uuid &id) const
158 {
159 const auto opt_var = get_param_registry ().find_by_id (id);
160 if (opt_var.has_value ())
161 {
162 return std::get<dsp::ProcessorParameter *> (opt_var.value ());
163 }
164 return nullptr;
165 }
166
167 std::optional<plugins::PluginPtrVariant>
168 find_plugin_by_id (plugins::Plugin::Uuid id) const
169 {
170 return get_plugin_registry ().find_by_id (id);
171 }
172
173 std::optional<zrythm::structure::tracks::TrackPtrVariant>
174 find_track_by_id (structure::tracks::Track::Uuid id) const
175 {
176 return get_track_registry ().find_by_id (id);
177 }
178
179 std::optional<zrythm::structure::arrangement::ArrangerObjectPtrVariant>
180 find_arranger_object_by_id (
181 structure::arrangement::ArrangerObject::Uuid id) const
182 {
183 return get_arranger_object_registry ().find_by_id (id);
184 }
185
186 const auto &tempo_map () const { return tempo_map_; }
187
188private:
189 static constexpr auto kTempoMapKey = "tempoMap"sv;
190 static constexpr auto kFileAudioSourceRegistryKey =
191 "fileAudioSourceRegistry"sv;
192 static constexpr auto kPortRegistryKey = "portRegistry"sv;
193 static constexpr auto kParameterRegistryKey = "paramRegistry"sv;
194 static constexpr auto kPluginRegistryKey = "pluginRegistry"sv;
195 static constexpr auto kArrangerObjectRegistryKey = "arrangerObjectRegistry"sv;
196 static constexpr auto kTrackRegistryKey = "trackRegistry"sv;
197 static constexpr auto kTransportKey = "transport"sv;
198 static constexpr auto kAudioPoolKey = "audioPool"sv;
199 static constexpr auto kTracklistKey = "tracklist"sv;
200 static constexpr auto kRegionLinkGroupManagerKey = "regionLinkGroupManager"sv;
201 static constexpr auto kPortConnectionsManagerKey = "portConnectionsManager"sv;
202 static constexpr auto kTempoObjectManagerKey = "tempoObjectManager"sv;
203 static constexpr auto kClipLauncherKey = "clipLauncher"sv;
204 friend void to_json (nlohmann::json &j, const Project &project);
205 friend void from_json (const nlohmann::json &j, Project &project);
206
207private:
208 utils::AppSettings &app_settings_;
209 dsp::TempoMap tempo_map_;
210 utils::QObjectUniquePtr<dsp::TempoMapWrapper> tempo_map_wrapper_;
211
212 plugins::PluginHostWindowFactory plugin_host_window_provider_;
213
214 utils::QObjectUniquePtr<dsp::FileAudioSourceRegistry>
215 file_audio_source_registry_;
216 utils::QObjectUniquePtr<dsp::PortRegistry> port_registry_;
217 utils::QObjectUniquePtr<dsp::ProcessorParameterRegistry> param_registry_;
218 utils::QObjectUniquePtr<PluginRegistry> plugin_registry_;
219 utils::QObjectUniquePtr<structure::arrangement::ArrangerObjectRegistry>
220 arranger_object_registry_;
221 utils::QObjectUniquePtr<structure::tracks::TrackRegistry> track_registry_;
222
223 ProjectDirectoryPathProvider project_directory_path_provider_;
224
225 /* !!! IMPORTANT: order matters (for destruction) !!! */
227 dsp::IHardwareAudioInterface &hw_interface_;
228 std::shared_ptr<juce::AudioPluginFormatManager> plugin_format_manager_;
229
230public:
238public:
243
248
250 std::unique_ptr<dsp::AudioPool> pool_;
251
253 // structure::arrangement::RegionLinkGroupManager region_link_group_manager_;
254
261
265 boost::unordered_flat_map<
266 structure::tracks::TrackUuid,
267 structure::tracks::TrackPtrVariant>
269
270private:
273 clip_playback_service_;
274
275 std::unique_ptr<structure::arrangement::ArrangerObjectFactory>
276 arranger_object_factory_;
277
278public:
280 std::unique_ptr<structure::tracks::TrackFactory> track_factory_;
281
282private:
284 tempo_object_manager_;
285
286 dsp::Fader &monitor_fader_;
287 dsp::Metronome &metronome_;
288
295 dsp::DspGraphDispatcher graph_dispatcher_;
296};
297
298}
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:224
The Transport class represents the transport controls and state for an audio engine.
Definition transport.h:45
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:258
std::unique_ptr< dsp::AudioPool > pool_
Audio file pool.
Definition project.h:240
utils::QObjectUniquePtr< dsp::Transport > transport_
Timeline metadata like BPM, time signature, etc.
Definition project.h:232
std::optional< dsp::PortPtrVariant > find_port_by_id(const dsp::Port::Uuid &id) const
Finds the Port corresponding to the identifier.
Definition project.h:141
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:226
utils::QObjectUniquePtr< dsp::AudioEngine > audio_engine_
The audio backend.
Definition project.h:237
utils::QObjectUniquePtr< structure::tracks::Tracklist > tracklist_
Manager for region link groups.
Definition project.h:250
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