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/snap_grid.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#include "utils/app_settings.h"
23
24namespace zrythm::dsp
25{
26class Fader;
27}
28
29namespace zrythm::structure::project
30{
31
32#define PORT_CONNECTIONS_MGR (PROJECT->port_connections_manager_.get ())
33#define AUDIO_POOL (PROJECT->audio_pool_.get ())
34#define TRANSPORT (PROJECT->transport_)
35
36#define TRACKLIST (PROJECT->tracklist_)
37#define P_CHORD_TRACK (TRACKLIST->singletonTracks ()->chordTrack ())
38#define P_MARKER_TRACK (TRACKLIST->singletonTracks ()->markerTrack ())
39#define P_MASTER_TRACK (TRACKLIST->singletonTracks ()->masterTrack ())
40#define P_MODULATOR_TRACK (TRACKLIST->singletonTracks ()->modulatorTrack ())
41#define SNAP_GRID_TIMELINE (PROJECT->snapGridTimeline ())
42#define SNAP_GRID_EDITOR (PROJECT->snapGridEditor ())
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 Q_PROPERTY (
72 zrythm::dsp::SnapGrid * snapGridTimeline READ snapGridTimeline CONSTANT FINAL)
73 Q_PROPERTY (
74 zrythm::dsp::SnapGrid * snapGridEditor READ snapGridEditor CONSTANT FINAL)
75 QML_UNCREATABLE ("")
76
77 friend struct PluginBuilderForDeserialization;
78
79public:
80 using TrackUuid = structure::tracks::TrackUuid;
81 using PluginPtrVariant = plugins::PluginPtrVariant;
82 using PluginRegistry = plugins::PluginRegistry;
83 using ProjectDirectoryPathProvider = std::function<fs::path (bool for_backup)>;
84
85public:
86 Project (
87 utils::AppSettings &app_settings,
88 ProjectDirectoryPathProvider project_directory_path_provider,
89 dsp::IHardwareAudioInterface &hw_interface,
90 std::shared_ptr<juce::AudioPluginFormatManager> plugin_format_manager,
91 plugins::PluginHostWindowFactory plugin_host_window_provider,
92 dsp::Metronome &metronome,
93 dsp::Fader &monitor_fader,
94 QObject * parent = nullptr);
95 ~Project () override;
96 Z_DISABLE_COPY_MOVE (Project)
97
98 // =========================================================
99 // QML interface
100 // =========================================================
101
102 structure::tracks::Tracklist * tracklist () const;
103 structure::scenes::ClipLauncher * clipLauncher () const;
104 structure::scenes::ClipPlaybackService * clipPlaybackService () const;
105 dsp::Transport * getTransport () const;
106 dsp::AudioEngine * engine () const;
107 dsp::TempoMapWrapper * getTempoMap () const;
108 dsp::SnapGrid * snapGridTimeline () const;
109 dsp::SnapGrid * snapGridEditor () const;
110 structure::arrangement::TempoObjectManager * tempoObjectManager () const;
111
112 Q_SIGNAL void aboutToBeDeleted ();
113
114 // =========================================================
115 // TODO: Remove these accessors - QML should access via ControlRoom instead
116
117 dsp::Fader &monitor_fader () const;
118 dsp::Metronome &metronome () const;
119
120 // TODO: delete this getter, no one else should use factory directly
121 auto * arrangerObjectFactory () const
122 {
123 return arranger_object_factory_.get ();
125
126 friend void init_from (
127 Project &obj,
128 const Project &other,
129 utils::ObjectCloneType clone_type);
130
136 void add_default_tracks ();
137
139 get_final_track_dependencies () const;
140
141 auto &get_file_audio_source_registry () const
142 {
143 return *file_audio_source_registry_;
144 }
145 auto &get_track_registry () const { return *track_registry_; }
146 auto &get_plugin_registry () const { return *plugin_registry_; }
147 auto &get_port_registry () const { return *port_registry_; }
148 auto &get_param_registry () const { return *param_registry_; }
149 auto &get_arranger_object_registry () const
151 return *arranger_object_registry_;
152 }
153
154
161 std::optional<dsp::PortPtrVariant>
162 find_port_by_id (const dsp::Port::Uuid &id) const
163 {
164 return get_port_registry ().find_by_id (id);
165 }
166
168 find_param_by_id (const dsp::ProcessorParameter::Uuid &id) const
169 {
170 const auto opt_var = get_param_registry ().find_by_id (id);
171 if (opt_var.has_value ())
172 {
173 return std::get<dsp::ProcessorParameter *> (opt_var.value ());
174 }
175 return nullptr;
176 }
177
178 std::optional<plugins::PluginPtrVariant>
179 find_plugin_by_id (plugins::Plugin::Uuid id) const
180 {
181 return get_plugin_registry ().find_by_id (id);
182 }
183
184 std::optional<zrythm::structure::tracks::TrackPtrVariant>
185 find_track_by_id (structure::tracks::Track::Uuid id) const
186 {
187 return get_track_registry ().find_by_id (id);
188 }
189
190 std::optional<zrythm::structure::arrangement::ArrangerObjectPtrVariant>
191 find_arranger_object_by_id (
192 structure::arrangement::ArrangerObject::Uuid id) const
193 {
194 return get_arranger_object_registry ().find_by_id (id);
195 }
196
197 const auto &tempo_map () const { return tempo_map_; }
198
199private:
200 static constexpr auto kTempoMapKey = "tempoMap"sv;
201 static constexpr auto kFileAudioSourceRegistryKey =
202 "fileAudioSourceRegistry"sv;
203 static constexpr auto kPortRegistryKey = "portRegistry"sv;
204 static constexpr auto kParameterRegistryKey = "paramRegistry"sv;
205 static constexpr auto kPluginRegistryKey = "pluginRegistry"sv;
206 static constexpr auto kArrangerObjectRegistryKey = "arrangerObjectRegistry"sv;
207 static constexpr auto kTrackRegistryKey = "trackRegistry"sv;
208 static constexpr auto kSnapGridTimelineKey = "snapGridTimeline"sv;
209 static constexpr auto kSnapGridEditorKey = "snapGridEditor"sv;
210 static constexpr auto kTransportKey = "transport"sv;
211 static constexpr auto kAudioPoolKey = "audioPool"sv;
212 static constexpr auto kTracklistKey = "tracklist"sv;
213 static constexpr auto kRegionLinkGroupManagerKey = "regionLinkGroupManager"sv;
214 static constexpr auto kPortConnectionsManagerKey = "portConnectionsManager"sv;
215 static constexpr auto kTempoObjectManagerKey = "tempoObjectManager"sv;
216 static constexpr auto kClipLauncherKey = "clipLauncher"sv;
217 friend void to_json (nlohmann::json &j, const Project &project);
218 friend void from_json (const nlohmann::json &j, Project &project);
219
220private:
221 utils::AppSettings &app_settings_;
222 dsp::TempoMap tempo_map_;
223 utils::QObjectUniquePtr<dsp::TempoMapWrapper> tempo_map_wrapper_;
224
225 plugins::PluginHostWindowFactory plugin_host_window_provider_;
226
227 dsp::FileAudioSourceRegistry * file_audio_source_registry_{};
228 dsp::PortRegistry * port_registry_{};
229 dsp::ProcessorParameterRegistry * param_registry_{};
230 PluginRegistry * plugin_registry_{};
231 structure::arrangement::ArrangerObjectRegistry * arranger_object_registry_{};
232 structure::tracks::TrackRegistry * track_registry_{};
233
234 ProjectDirectoryPathProvider project_directory_path_provider_;
236 /* !!! IMPORTANT: order matters (for destruction) !!! */
237
238 dsp::IHardwareAudioInterface &hw_interface_;
239 std::shared_ptr<juce::AudioPluginFormatManager> plugin_format_manager_;
240
241public:
249private:
252
254 utils::QObjectUniquePtr<dsp::SnapGrid> snap_grid_timeline_;
255
256public:
261
268 std::unique_ptr<dsp::AudioPool> pool_;
269
271 // structure::arrangement::RegionLinkGroupManager region_link_group_manager_;
272
279
283 boost::unordered_flat_map<
284 structure::tracks::TrackUuid,
285 structure::tracks::TrackPtrVariant>
287
288private:
291 clip_playback_service_;
292
293 std::unique_ptr<structure::arrangement::ArrangerObjectFactory>
294 arranger_object_factory_;
295
296public:
298 std::unique_ptr<structure::tracks::TrackFactory> track_factory_;
299
300private:
302 tempo_object_manager_;
303
304 dsp::Fader &monitor_fader_;
305 dsp::Metronome &metronome_;
306
313 dsp::DspGraphDispatcher graph_dispatcher_;
314};
315
316}
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
Snap/grid information.
Definition snap_grid.h:22
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:51
boost::unordered_flat_map< structure::tracks::TrackUuid, structure::tracks::TrackPtrVariant > tracks_rt_
Realtime cache of tracks.
Definition project.h:274
std::unique_ptr< dsp::AudioPool > pool_
Audio file pool.
Definition project.h:256
utils::QObjectUniquePtr< dsp::Transport > transport_
Timeline metadata like BPM, time signature, etc.
Definition project.h:248
std::optional< dsp::PortPtrVariant > find_port_by_id(const dsp::Port::Uuid &id) const
Finds the Port corresponding to the identifier.
Definition project.h:150
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:235
utils::QObjectUniquePtr< dsp::AudioEngine > audio_engine_
The audio backend.
Definition project.h:253
utils::QObjectUniquePtr< structure::tracks::Tracklist > tracklist_
Manager for region link groups.
Definition project.h:266
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