Zrythm v2.0.0-alpha.1+31.4967fd053471
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/midi_input_selection.h"
12#include "dsp/port_connections_manager.h"
13#include "dsp/port_observation_manager.h"
14#include "dsp/tempo_map_qml_adapter.h"
15#include "dsp/transport.h"
16#include "plugins/plugin.h"
17#include "plugins/plugin_factory.h"
18#include "structure/arrangement/arranger_object_factory.h"
19#include "structure/arrangement/tempo_object_manager.h"
20#include "structure/project/project_registry.h"
21#include "structure/scenes/clip_launcher.h"
22#include "structure/scenes/clip_playback_service.h"
23#include "structure/tracks/track_factory.h"
24#include "structure/tracks/tracklist.h"
25
26namespace zrythm::dsp
27{
28class Fader;
29}
30namespace zrythm::utils
31{
32class AppSettings;
33}
34
35namespace zrythm::structure::project
36{
37
38#define PORT_CONNECTIONS_MGR (PROJECT->port_connections_manager_.get ())
39#define AUDIO_POOL (PROJECT->audio_pool_.get ())
40#define TRANSPORT (PROJECT->transport_)
41
42#define TRACKLIST (PROJECT->tracklist_)
43#define P_CHORD_TRACK (TRACKLIST->singletonTracks ()->chordTrack ())
44#define P_MARKER_TRACK (TRACKLIST->singletonTracks ()->markerTrack ())
45#define P_MASTER_TRACK (TRACKLIST->singletonTracks ()->masterTrack ())
46#define P_MODULATOR_TRACK (TRACKLIST->singletonTracks ()->modulatorTrack ())
47#define MONITOR_FADER (PROJECT->controlRoom ()->monitor_fader_)
48#define ROUTER (&PROJECT->engine ()->graph_dispatcher ())
49#define AUDIO_ENGINE (PROJECT->engine ())
50
54class Project final : public QObject
55{
56 Q_OBJECT
57 QML_ELEMENT
58 Q_PROPERTY (
59 zrythm::structure::tracks::Tracklist * tracklist READ tracklist CONSTANT
60 FINAL)
61 Q_PROPERTY (
62 zrythm::structure::scenes::ClipLauncher * clipLauncher READ clipLauncher
63 CONSTANT FINAL)
64 Q_PROPERTY (
65 zrythm::structure::scenes::ClipPlaybackService * clipPlaybackService READ
66 clipPlaybackService CONSTANT FINAL)
67 Q_PROPERTY (zrythm::dsp::AudioEngine * engine READ engine CONSTANT FINAL)
68 Q_PROPERTY (
69 zrythm::dsp::Transport * transport READ getTransport CONSTANT FINAL)
70 Q_PROPERTY (
71 zrythm::dsp::TempoMapWrapper * tempoMap READ getTempoMap CONSTANT FINAL)
72 Q_PROPERTY (
73 zrythm::dsp::PortObservationManager * portObservationManager READ
74 portObservationManager CONSTANT FINAL)
75 Q_PROPERTY (
77 tempoObjectManager CONSTANT FINAL)
78 QML_UNCREATABLE ("")
79
80public:
81 using TrackUuid = structure::tracks::TrackUuid;
82 using PluginPtrVariant = plugins::PluginPtrVariant;
83 using ProjectDirectoryPathProvider =
84 std::function<std::filesystem::path (bool for_backup)>;
85
92 using AudioInputSelectionProvider = std::function<dsp::AudioInputSelection *(
93 const structure::tracks::Track::Uuid &)>;
94
95 using MidiInputSelectionProvider = std::function<dsp::MidiInputSelection *(
96 const structure::tracks::Track::Uuid &)>;
97
98public:
99 Project (
100 utils::AppSettings &app_settings,
101 ProjectDirectoryPathProvider project_directory_path_provider,
102 dsp::IHardwareAudioInterface &hw_interface,
103 dsp::IHardwareMidiInterface &midi_interface,
104 std::shared_ptr<juce::AudioPluginFormatManager> plugin_format_manager,
105 plugins::PluginHostWindowFactory plugin_host_window_provider,
106 dsp::Metronome &metronome,
107 dsp::Fader &monitor_fader,
108 QObject * parent = nullptr);
109 ~Project () override;
110 Q_DISABLE_COPY_MOVE (Project)
111
112 // =========================================================
113 // QML interface
114 // =========================================================
115
116 structure::tracks::Tracklist * tracklist () const;
117 structure::scenes::ClipLauncher * clipLauncher () const;
118 structure::scenes::ClipPlaybackService * clipPlaybackService () const;
119 dsp::Transport * getTransport () const;
120 dsp::AudioEngine * engine () const;
121 dsp::TempoMapWrapper * getTempoMap () const;
122 structure::arrangement::TempoObjectManager * tempoObjectManager () const;
123
124 // =========================================================
125 // TODO: Remove these accessors - QML should access via ControlRoom instead
126
127 dsp::Fader &monitor_fader () const;
128 dsp::Metronome &metronome () const;
129
130 // TODO: delete this getter, no one else should use factory directly
131 auto * arrangerObjectFactory () const
132 {
133 return arranger_object_factory_.get ();
134 }
135
136 dsp::PortObservationManager * portObservationManager () const;
137
138 friend void init_from (
139 Project &obj,
140 const Project &other,
141 utils::ObjectCloneType clone_type);
142
148 void add_default_tracks ();
149
150 structure::tracks::FinalTrackDependencies get_final_track_dependencies ();
151
152 utils::IObjectRegistry &get_registry () { return project_registry_; }
153 const utils::IObjectRegistry &get_registry () const
154 {
155 return project_registry_;
156 }
157
158 const auto &tempo_map () const { return tempo_map_; }
159
160 void set_audio_input_selection_provider (AudioInputSelectionProvider provider)
161 {
162 audio_input_selection_provider_ = std::move (provider);
163 }
164
165 const auto &audio_input_selection_provider () const
166 {
167 return audio_input_selection_provider_;
168 }
169
170 void set_midi_input_selection_provider (MidiInputSelectionProvider provider)
171 {
172 midi_input_selection_provider_ = std::move (provider);
173 }
175 const auto &midi_input_selection_provider () const
176 {
177 return midi_input_selection_provider_;
178 }
179
187 structure::tracks::TrackRecordingCallback callback);
188
189private:
190 static constexpr auto kTempoMapKey = "tempoMap"sv;
191 static constexpr auto kRegistryKey = "registry"sv;
192 static constexpr auto kTransportKey = "transport"sv;
193 static constexpr auto kAudioPoolKey = "audioPool"sv;
194 static constexpr auto kTracklistKey = "tracklist"sv;
195 static constexpr auto kRegionLinkGroupManagerKey = "regionLinkGroupManager"sv;
196 static constexpr auto kPortConnectionsManagerKey = "portConnectionsManager"sv;
197 static constexpr auto kTempoObjectManagerKey = "tempoObjectManager"sv;
198 static constexpr auto kClipLauncherKey = "clipLauncher"sv;
199 friend void to_json (nlohmann::json &j, const Project &project);
200 friend void from_json (const nlohmann::json &j, Project &project);
201
202private:
203 utils::AppSettings &app_settings_;
204 dsp::TempoMap tempo_map_;
206
207 plugins::PluginHostWindowFactory plugin_host_window_provider_;
208
209 ProjectRegistry project_registry_;
210
211 ProjectDirectoryPathProvider project_directory_path_provider_;
213 /* !!! IMPORTANT: order matters (for destruction) !!! */
214
215 dsp::IHardwareAudioInterface &hw_interface_;
216 std::shared_ptr<juce::AudioPluginFormatManager> plugin_format_manager_;
217
218public:
225
226public:
231
238 std::unique_ptr<dsp::AudioPool> pool_;
239
241 // structure::arrangement::RegionLinkGroupManager region_link_group_manager_;
242
249
256 std::vector<structure::tracks::Track *> tracks_rt_;
257
258private:
261 clip_playback_service_;
262
263 std::unique_ptr<structure::arrangement::ArrangerObjectFactory>
264 arranger_object_factory_;
265
266public:
268 std::unique_ptr<structure::tracks::TrackFactory> track_factory_;
269
270private:
272 tempo_object_manager_;
273
274 dsp::Fader &monitor_fader_;
275 dsp::Metronome &metronome_;
276
277 AudioInputSelectionProvider audio_input_selection_provider_;
278 MidiInputSelectionProvider midi_input_selection_provider_;
279
280 structure::tracks::TrackRecordingCallback track_recording_callback_;
281
289
293 std::vector<dsp::graph::IProcessable *> fixed_graph_endpoints_;
294
301 std::vector<dsp::graph::IProcessable *> playback_graph_endpoints_;
302
309 dsp::DspGraphDispatcher graph_dispatcher_;
310};
311
312}
The audio engine.
Definition engine.h:28
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:17
Abstraction for hardware audio interface.
Metronome processor.
Definition metronome.h:19
Manages port observer lifecycle and runs a drain timer.
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:55
std::unique_ptr< dsp::AudioPool > pool_
Audio file pool.
Definition project.h:226
utils::QObjectUniquePtr< dsp::Transport > transport_
Timeline metadata like BPM, time signature, etc.
Definition project.h:218
std::vector< structure::tracks::Track * > tracks_rt_
Realtime cache of tracks.
Definition project.h:244
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:212
utils::QObjectUniquePtr< dsp::AudioEngine > audio_engine_
The audio backend.
Definition project.h:223
utils::QObjectUniquePtr< structure::tracks::Tracklist > tracklist_
Manager for region link groups.
Definition project.h:236
std::function< dsp::AudioInputSelection *( const structure::tracks::Track::Uuid &)> AudioInputSelectionProvider
Callback to look up audio input selection for a track.
Definition project.h:80
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:22
Abstract interface for a UUID-keyed object registry.
A unique pointer for QObject objects that also works with QObject-based ownership.
Definition qt.h:36
String utilities.