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
22namespace zrythm::dsp
23{
24class Fader;
25}
26namespace zrythm::utils
27{
28class AppSettings;
29}
30
31namespace zrythm::structure::project
32{
33
34#define PORT_CONNECTIONS_MGR (PROJECT->port_connections_manager_.get ())
35#define AUDIO_POOL (PROJECT->audio_pool_.get ())
36#define TRANSPORT (PROJECT->transport_)
37
38#define TRACKLIST (PROJECT->tracklist_)
39#define P_CHORD_TRACK (TRACKLIST->singletonTracks ()->chordTrack ())
40#define P_MARKER_TRACK (TRACKLIST->singletonTracks ()->markerTrack ())
41#define P_MASTER_TRACK (TRACKLIST->singletonTracks ()->masterTrack ())
42#define P_MODULATOR_TRACK (TRACKLIST->singletonTracks ()->modulatorTrack ())
43#define MONITOR_FADER (PROJECT->controlRoom ()->monitor_fader_)
44#define ROUTER (&PROJECT->engine ()->graph_dispatcher ())
45#define AUDIO_ENGINE (PROJECT->engine ())
46
50class Project final : public QObject
51{
52 Q_OBJECT
53 QML_ELEMENT
54 Q_PROPERTY (
55 zrythm::structure::tracks::Tracklist * tracklist READ tracklist CONSTANT
56 FINAL)
57 Q_PROPERTY (
58 zrythm::structure::scenes::ClipLauncher * clipLauncher READ clipLauncher
59 CONSTANT FINAL)
60 Q_PROPERTY (
61 zrythm::structure::scenes::ClipPlaybackService * clipPlaybackService READ
62 clipPlaybackService CONSTANT FINAL)
63 Q_PROPERTY (zrythm::dsp::AudioEngine * engine READ engine CONSTANT FINAL)
64 Q_PROPERTY (
65 zrythm::dsp::Transport * transport READ getTransport CONSTANT FINAL)
66 Q_PROPERTY (
67 zrythm::dsp::TempoMapWrapper * tempoMap READ getTempoMap CONSTANT FINAL)
68 Q_PROPERTY (
70 tempoObjectManager CONSTANT FINAL)
71 QML_UNCREATABLE ("")
72
73 friend struct PluginBuilderForDeserialization;
74
75public:
76 using TrackUuid = structure::tracks::TrackUuid;
77 using PluginPtrVariant = plugins::PluginPtrVariant;
78 using PluginRegistry = plugins::PluginRegistry;
79 using ProjectDirectoryPathProvider =
80 std::function<std::filesystem::path (bool for_backup)>;
81
82public:
83 Project (
84 utils::AppSettings &app_settings,
85 ProjectDirectoryPathProvider project_directory_path_provider,
86 dsp::IHardwareAudioInterface &hw_interface,
87 std::shared_ptr<juce::AudioPluginFormatManager> plugin_format_manager,
88 plugins::PluginHostWindowFactory plugin_host_window_provider,
89 dsp::Metronome &metronome,
90 dsp::Fader &monitor_fader,
91 QObject * parent = nullptr);
92 ~Project () override;
93 Q_DISABLE_COPY_MOVE (Project)
94
95 // =========================================================
96 // QML interface
97 // =========================================================
98
99 structure::tracks::Tracklist * tracklist () const;
100 structure::scenes::ClipLauncher * clipLauncher () const;
101 structure::scenes::ClipPlaybackService * clipPlaybackService () const;
102 dsp::Transport * getTransport () const;
103 dsp::AudioEngine * engine () const;
104 dsp::TempoMapWrapper * getTempoMap () const;
105 structure::arrangement::TempoObjectManager * tempoObjectManager () const;
106
107 // =========================================================
108 // TODO: Remove these accessors - QML should access via ControlRoom instead
109
110 dsp::Fader &monitor_fader () const;
111 dsp::Metronome &metronome () const;
112
113 // TODO: delete this getter, no one else should use factory directly
114 auto * arrangerObjectFactory () const
115 {
116 return arranger_object_factory_.get ();
117 }
118
119 friend void init_from (
120 Project &obj,
121 const Project &other,
122 utils::ObjectCloneType clone_type);
123
129 void add_default_tracks ();
130
132 get_final_track_dependencies () const;
133
134 auto &get_file_audio_source_registry () const
135 {
136 return *file_audio_source_registry_;
137 }
138 auto &get_track_registry () const { return *track_registry_; }
139 auto &get_plugin_registry () const { return *plugin_registry_; }
140 auto &get_port_registry () const { return *port_registry_; }
141 auto &get_param_registry () const { return *param_registry_; }
142 auto &get_arranger_object_registry () const
143 {
144 return *arranger_object_registry_;
146
149
154 std::optional<dsp::PortPtrVariant>
155 find_port_by_id (const dsp::Port::Uuid &id) const
156 {
157 return get_port_registry ().find_by_id (id);
158 }
159
161 find_param_by_id (const dsp::ProcessorParameter::Uuid &id) const
162 {
163 const auto opt_var = get_param_registry ().find_by_id (id);
164 if (opt_var.has_value ())
165 {
166 return std::get<dsp::ProcessorParameter *> (opt_var.value ());
167 }
168 return nullptr;
169 }
170
171 std::optional<plugins::PluginPtrVariant>
172 find_plugin_by_id (plugins::Plugin::Uuid id) const
173 {
174 return get_plugin_registry ().find_by_id (id);
175 }
176
177 std::optional<zrythm::structure::tracks::TrackPtrVariant>
178 find_track_by_id (structure::tracks::Track::Uuid id) const
179 {
180 return get_track_registry ().find_by_id (id);
181 }
182
183 std::optional<zrythm::structure::arrangement::ArrangerObjectPtrVariant>
184 find_arranger_object_by_id (
185 structure::arrangement::ArrangerObject::Uuid id) const
186 {
187 return get_arranger_object_registry ().find_by_id (id);
188 }
189
190 const auto &tempo_map () const { return tempo_map_; }
191
192private:
193 static constexpr auto kTempoMapKey = "tempoMap"sv;
194 static constexpr auto kFileAudioSourceRegistryKey =
195 "fileAudioSourceRegistry"sv;
196 static constexpr auto kPortRegistryKey = "portRegistry"sv;
197 static constexpr auto kParameterRegistryKey = "paramRegistry"sv;
198 static constexpr auto kPluginRegistryKey = "pluginRegistry"sv;
199 static constexpr auto kArrangerObjectRegistryKey = "arrangerObjectRegistry"sv;
200 static constexpr auto kTrackRegistryKey = "trackRegistry"sv;
201 static constexpr auto kTransportKey = "transport"sv;
202 static constexpr auto kAudioPoolKey = "audioPool"sv;
203 static constexpr auto kTracklistKey = "tracklist"sv;
204 static constexpr auto kRegionLinkGroupManagerKey = "regionLinkGroupManager"sv;
205 static constexpr auto kPortConnectionsManagerKey = "portConnectionsManager"sv;
206 static constexpr auto kTempoObjectManagerKey = "tempoObjectManager"sv;
207 static constexpr auto kClipLauncherKey = "clipLauncher"sv;
208 friend void to_json (nlohmann::json &j, const Project &project);
209 friend void from_json (const nlohmann::json &j, Project &project);
210
211private:
212 utils::AppSettings &app_settings_;
213 dsp::TempoMap tempo_map_;
214 utils::QObjectUniquePtr<dsp::TempoMapWrapper> tempo_map_wrapper_;
215
216 plugins::PluginHostWindowFactory plugin_host_window_provider_;
217
218 utils::QObjectUniquePtr<dsp::FileAudioSourceRegistry>
219 file_audio_source_registry_;
220 utils::QObjectUniquePtr<dsp::PortRegistry> port_registry_;
221 utils::QObjectUniquePtr<dsp::ProcessorParameterRegistry> param_registry_;
222 utils::QObjectUniquePtr<PluginRegistry> plugin_registry_;
223 utils::QObjectUniquePtr<structure::arrangement::ArrangerObjectRegistry>
224 arranger_object_registry_;
225 utils::QObjectUniquePtr<structure::tracks::TrackRegistry> track_registry_;
226
227 ProjectDirectoryPathProvider project_directory_path_provider_;
228
229 /* !!! IMPORTANT: order matters (for destruction) !!! */
231 dsp::IHardwareAudioInterface &hw_interface_;
232 std::shared_ptr<juce::AudioPluginFormatManager> plugin_format_manager_;
233
234public:
242public:
247
252
254 std::unique_ptr<dsp::AudioPool> pool_;
255
257 // structure::arrangement::RegionLinkGroupManager region_link_group_manager_;
258
265
269 boost::unordered_flat_map<
270 structure::tracks::TrackUuid,
271 structure::tracks::TrackPtrVariant>
273
274private:
277 clip_playback_service_;
278
279 std::unique_ptr<structure::arrangement::ArrangerObjectFactory>
280 arranger_object_factory_;
281
282public:
284 std::unique_ptr<structure::tracks::TrackFactory> track_factory_;
285
286private:
288 tempo_object_manager_;
289
290 dsp::Fader &monitor_fader_;
291 dsp::Metronome &metronome_;
292
299 dsp::DspGraphDispatcher graph_dispatcher_;
300};
301
302}
The audio engine.
Definition engine.h:22
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:15
Abstraction for hardware audio interface.
Metronome processor.
Definition metronome.h:19
Processor parameter that accepts automation and modulation sources and integrates with QML and the DS...
Definition parameter.h:167
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:262
std::unique_ptr< dsp::AudioPool > pool_
Audio file pool.
Definition project.h:244
utils::QObjectUniquePtr< dsp::Transport > transport_
Timeline metadata like BPM, time signature, etc.
Definition project.h:236
std::optional< dsp::PortPtrVariant > find_port_by_id(const dsp::Port::Uuid &id) const
Finds the Port corresponding to the identifier.
Definition project.h:145
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:230
utils::QObjectUniquePtr< dsp::AudioEngine > audio_engine_
The audio backend.
Definition project.h:241
utils::QObjectUniquePtr< structure::tracks::Tracklist > tracklist_
Manager for region link groups.
Definition project.h:254
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:36
String utilities.