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_input_selection.h"
7#include "dsp/audio_pool.h"
8#include "dsp/engine.h"
9#include "dsp/hardware_audio_interface.h"
10#include "dsp/metronome.h"
11#include "dsp/port_connections_manager.h"
12#include "dsp/tempo_map_qml_adapter.h"
13#include "dsp/transport.h"
14#include "plugins/plugin.h"
15#include "plugins/plugin_factory.h"
16#include "structure/arrangement/arranger_object_factory.h"
17#include "structure/arrangement/tempo_object_manager.h"
18#include "structure/scenes/clip_launcher.h"
19#include "structure/scenes/clip_playback_service.h"
20#include "structure/tracks/track_factory.h"
21#include "structure/tracks/tracklist.h"
22
23namespace zrythm::dsp
24{
25class Fader;
26}
27namespace zrythm::utils
28{
29class AppSettings;
30}
31
32namespace zrythm::structure::project
33{
34
35#define PORT_CONNECTIONS_MGR (PROJECT->port_connections_manager_.get ())
36#define AUDIO_POOL (PROJECT->audio_pool_.get ())
37#define TRANSPORT (PROJECT->transport_)
38
39#define TRACKLIST (PROJECT->tracklist_)
40#define P_CHORD_TRACK (TRACKLIST->singletonTracks ()->chordTrack ())
41#define P_MARKER_TRACK (TRACKLIST->singletonTracks ()->markerTrack ())
42#define P_MASTER_TRACK (TRACKLIST->singletonTracks ()->masterTrack ())
43#define P_MODULATOR_TRACK (TRACKLIST->singletonTracks ()->modulatorTrack ())
44#define MONITOR_FADER (PROJECT->controlRoom ()->monitor_fader_)
45#define ROUTER (&PROJECT->engine ()->graph_dispatcher ())
46#define AUDIO_ENGINE (PROJECT->engine ())
47
51class Project final : public QObject
52{
53 Q_OBJECT
54 QML_ELEMENT
55 Q_PROPERTY (
56 zrythm::structure::tracks::Tracklist * tracklist READ tracklist CONSTANT
57 FINAL)
58 Q_PROPERTY (
59 zrythm::structure::scenes::ClipLauncher * clipLauncher READ clipLauncher
60 CONSTANT FINAL)
61 Q_PROPERTY (
62 zrythm::structure::scenes::ClipPlaybackService * clipPlaybackService READ
63 clipPlaybackService CONSTANT FINAL)
64 Q_PROPERTY (zrythm::dsp::AudioEngine * engine READ engine CONSTANT FINAL)
65 Q_PROPERTY (
66 zrythm::dsp::Transport * transport READ getTransport CONSTANT FINAL)
67 Q_PROPERTY (
68 zrythm::dsp::TempoMapWrapper * tempoMap READ getTempoMap CONSTANT FINAL)
69 Q_PROPERTY (
71 tempoObjectManager CONSTANT FINAL)
72 QML_UNCREATABLE ("")
73
74 friend struct PluginBuilderForDeserialization;
75
76public:
77 using TrackUuid = structure::tracks::TrackUuid;
78 using PluginPtrVariant = plugins::PluginPtrVariant;
79 using PluginRegistry = plugins::PluginRegistry;
80 using ProjectDirectoryPathProvider =
81 std::function<std::filesystem::path (bool for_backup)>;
82
91
92public:
93 Project (
94 utils::AppSettings &app_settings,
95 ProjectDirectoryPathProvider project_directory_path_provider,
96 dsp::IHardwareAudioInterface &hw_interface,
97 std::shared_ptr<juce::AudioPluginFormatManager> plugin_format_manager,
98 plugins::PluginHostWindowFactory plugin_host_window_provider,
99 dsp::Metronome &metronome,
100 dsp::Fader &monitor_fader,
101 QObject * parent = nullptr);
102 ~Project () override;
103 Q_DISABLE_COPY_MOVE (Project)
104
105 // =========================================================
106 // QML interface
107 // =========================================================
108
109 structure::tracks::Tracklist * tracklist () const;
110 structure::scenes::ClipLauncher * clipLauncher () const;
111 structure::scenes::ClipPlaybackService * clipPlaybackService () const;
112 dsp::Transport * getTransport () const;
113 dsp::AudioEngine * engine () const;
114 dsp::TempoMapWrapper * getTempoMap () const;
115 structure::arrangement::TempoObjectManager * tempoObjectManager () const;
116
117 // =========================================================
118 // TODO: Remove these accessors - QML should access via ControlRoom instead
119
120 dsp::Fader &monitor_fader () const;
121 dsp::Metronome &metronome () const;
122
123 // TODO: delete this getter, no one else should use factory directly
124 auto * arrangerObjectFactory () const
125 {
126 return arranger_object_factory_.get ();
127 }
128
129 friend void init_from (
130 Project &obj,
131 const Project &other,
132 utils::ObjectCloneType clone_type);
133
139 void add_default_tracks ();
140
142 get_final_track_dependencies () const;
143
144 auto &get_file_audio_source_registry () const
145 {
146 return *file_audio_source_registry_;
147 }
148 auto &get_track_registry () const { return *track_registry_; }
149 auto &get_plugin_registry () const { return *plugin_registry_; }
150 auto &get_port_registry () const { return *port_registry_; }
151 auto &get_param_registry () const { return *param_registry_; }
152 auto &get_arranger_object_registry () const
153 {
154 return *arranger_object_registry_;
156
159
164 std::optional<dsp::PortPtrVariant>
165 find_port_by_id (const dsp::Port::Uuid &id) const
166 {
167 return get_port_registry ().find_by_id (id);
168 }
169
171 find_param_by_id (const dsp::ProcessorParameter::Uuid &id) const
172 {
173 const auto opt_var = get_param_registry ().find_by_id (id);
174 if (opt_var.has_value ())
175 {
176 return std::get<dsp::ProcessorParameter *> (opt_var.value ());
177 }
178 return nullptr;
179 }
180
181 std::optional<plugins::PluginPtrVariant>
182 find_plugin_by_id (plugins::Plugin::Uuid id) const
183 {
184 return get_plugin_registry ().find_by_id (id);
185 }
186
187 std::optional<zrythm::structure::tracks::TrackPtrVariant>
188 find_track_by_id (structure::tracks::Track::Uuid id) const
189 {
190 return get_track_registry ().find_by_id (id);
191 }
192
193 std::optional<zrythm::structure::arrangement::ArrangerObjectPtrVariant>
194 find_arranger_object_by_id (
195 structure::arrangement::ArrangerObject::Uuid id) const
196 {
197 return get_arranger_object_registry ().find_by_id (id);
198 }
199
200 const auto &tempo_map () const { return tempo_map_; }
201
202 void set_audio_input_selection_provider (AudioInputSelectionProvider provider)
203 {
204 audio_input_selection_provider_ = std::move (provider);
205 }
206
207 const auto &audio_input_selection_provider () const
209 return audio_input_selection_provider_;
210 }
211
219 structure::tracks::TrackRecordingCallback callback);
220
221private:
222 static constexpr auto kTempoMapKey = "tempoMap"sv;
223 static constexpr auto kFileAudioSourceRegistryKey =
224 "fileAudioSourceRegistry"sv;
225 static constexpr auto kPortRegistryKey = "portRegistry"sv;
226 static constexpr auto kParameterRegistryKey = "paramRegistry"sv;
227 static constexpr auto kPluginRegistryKey = "pluginRegistry"sv;
228 static constexpr auto kArrangerObjectRegistryKey = "arrangerObjectRegistry"sv;
229 static constexpr auto kTrackRegistryKey = "trackRegistry"sv;
230 static constexpr auto kTransportKey = "transport"sv;
231 static constexpr auto kAudioPoolKey = "audioPool"sv;
232 static constexpr auto kTracklistKey = "tracklist"sv;
233 static constexpr auto kRegionLinkGroupManagerKey = "regionLinkGroupManager"sv;
234 static constexpr auto kPortConnectionsManagerKey = "portConnectionsManager"sv;
235 static constexpr auto kTempoObjectManagerKey = "tempoObjectManager"sv;
236 static constexpr auto kClipLauncherKey = "clipLauncher"sv;
237 friend void to_json (nlohmann::json &j, const Project &project);
238 friend void from_json (const nlohmann::json &j, Project &project);
239
240private:
241 utils::AppSettings &app_settings_;
242 dsp::TempoMap tempo_map_;
244
245 plugins::PluginHostWindowFactory plugin_host_window_provider_;
246
248 file_audio_source_registry_;
253 arranger_object_registry_;
255
256 ProjectDirectoryPathProvider project_directory_path_provider_;
257
258 /* !!! IMPORTANT: order matters (for destruction) !!! */
260 dsp::IHardwareAudioInterface &hw_interface_;
261 std::shared_ptr<juce::AudioPluginFormatManager> plugin_format_manager_;
262
263public:
271public:
276
281
283 std::unique_ptr<dsp::AudioPool> pool_;
284
286 // structure::arrangement::RegionLinkGroupManager region_link_group_manager_;
287
294
298 boost::unordered_flat_map<
299 structure::tracks::TrackUuid,
300 structure::tracks::TrackPtrVariant>
302
303private:
306 clip_playback_service_;
307
308 std::unique_ptr<structure::arrangement::ArrangerObjectFactory>
309 arranger_object_factory_;
310
311public:
313 std::unique_ptr<structure::tracks::TrackFactory> track_factory_;
314
315private:
317 tempo_object_manager_;
318
319 dsp::Fader &monitor_fader_;
320 dsp::Metronome &metronome_;
321
322 AudioInputSelectionProvider audio_input_selection_provider_;
323
324 structure::tracks::TrackRecordingCallback track_recording_callback_;
325
332 dsp::DspGraphDispatcher graph_dispatcher_;
333};
334
335}
The audio engine.
Definition engine.h:25
Audio hardware input selection for a track.
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:252
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.
Core functionality of a Zrythm project.
Definition project.h:52
boost::unordered_flat_map< structure::tracks::TrackUuid, structure::tracks::TrackPtrVariant > tracks_rt_
Realtime cache of tracks.
Definition project.h:291
std::unique_ptr< dsp::AudioPool > pool_
Audio file pool.
Definition project.h:273
utils::QObjectUniquePtr< dsp::Transport > transport_
Timeline metadata like BPM, time signature, etc.
Definition project.h:265
std::optional< dsp::PortPtrVariant > find_port_by_id(const dsp::Port::Uuid &id) const
Finds the Port corresponding to the identifier.
Definition project.h:155
void add_default_tracks()
Adds the default undeletable tracks to the project.
void install_recording_callback(structure::tracks::TrackRecordingCallback callback)
Installs the recording callback used by all tracks.
utils::QObjectUniquePtr< dsp::PortConnectionsManager > port_connections_manager_
Must be free'd after engine.
Definition project.h:259
utils::QObjectUniquePtr< dsp::AudioEngine > audio_engine_
The audio backend.
Definition project.h:270
utils::QObjectUniquePtr< structure::tracks::Tracklist > tracklist_
Manager for region link groups.
Definition project.h:283
std::function< dsp::AudioInputSelection *( const structure::tracks::Track::Uuid &)> AudioInputSelectionProvider
Callback to look up audio input selection for a track.
Definition project.h:79
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.