Zrythm v2.0.0-alpha.1
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/tempo_map_qml_adapter.h"
14#include "dsp/transport.h"
15#include "plugins/plugin.h"
16#include "plugins/plugin_factory.h"
17#include "structure/arrangement/arranger_object_factory.h"
18#include "structure/arrangement/tempo_object_manager.h"
19#include "structure/project/project_registry.h"
20#include "structure/scenes/clip_launcher.h"
21#include "structure/scenes/clip_playback_service.h"
22#include "structure/tracks/track_factory.h"
23#include "structure/tracks/tracklist.h"
24
25namespace zrythm::dsp
26{
27class Fader;
28}
29namespace zrythm::utils
30{
31class AppSettings;
32}
33
34namespace zrythm::structure::project
35{
36
37#define PORT_CONNECTIONS_MGR (PROJECT->port_connections_manager_.get ())
38#define AUDIO_POOL (PROJECT->audio_pool_.get ())
39#define TRANSPORT (PROJECT->transport_)
40
41#define TRACKLIST (PROJECT->tracklist_)
42#define P_CHORD_TRACK (TRACKLIST->singletonTracks ()->chordTrack ())
43#define P_MARKER_TRACK (TRACKLIST->singletonTracks ()->markerTrack ())
44#define P_MASTER_TRACK (TRACKLIST->singletonTracks ()->masterTrack ())
45#define P_MODULATOR_TRACK (TRACKLIST->singletonTracks ()->modulatorTrack ())
46#define MONITOR_FADER (PROJECT->controlRoom ()->monitor_fader_)
47#define ROUTER (&PROJECT->engine ()->graph_dispatcher ())
48#define AUDIO_ENGINE (PROJECT->engine ())
49
53class Project final : public QObject
54{
55 Q_OBJECT
56 QML_ELEMENT
57 Q_PROPERTY (
58 zrythm::structure::tracks::Tracklist * tracklist READ tracklist CONSTANT
59 FINAL)
60 Q_PROPERTY (
61 zrythm::structure::scenes::ClipLauncher * clipLauncher READ clipLauncher
62 CONSTANT FINAL)
63 Q_PROPERTY (
64 zrythm::structure::scenes::ClipPlaybackService * clipPlaybackService READ
65 clipPlaybackService CONSTANT FINAL)
66 Q_PROPERTY (zrythm::dsp::AudioEngine * engine READ engine CONSTANT FINAL)
67 Q_PROPERTY (
68 zrythm::dsp::Transport * transport READ getTransport CONSTANT FINAL)
69 Q_PROPERTY (
70 zrythm::dsp::TempoMapWrapper * tempoMap READ getTempoMap CONSTANT FINAL)
71 Q_PROPERTY (
73 tempoObjectManager CONSTANT FINAL)
74 QML_UNCREATABLE ("")
75
76public:
77 using TrackUuid = structure::tracks::TrackUuid;
78 using PluginPtrVariant = plugins::PluginPtrVariant;
79 using ProjectDirectoryPathProvider =
80 std::function<std::filesystem::path (bool for_backup)>;
81
90
91 using MidiInputSelectionProvider = std::function<dsp::MidiInputSelection *(
93
94public:
95 Project (
96 utils::AppSettings &app_settings,
97 ProjectDirectoryPathProvider project_directory_path_provider,
98 dsp::IHardwareAudioInterface &hw_interface,
99 dsp::IHardwareMidiInterface &midi_interface,
100 std::shared_ptr<juce::AudioPluginFormatManager> plugin_format_manager,
101 plugins::PluginHostWindowFactory plugin_host_window_provider,
102 dsp::Metronome &metronome,
103 dsp::Fader &monitor_fader,
104 QObject * parent = nullptr);
105 ~Project () override;
106 Q_DISABLE_COPY_MOVE (Project)
107
108 // =========================================================
109 // QML interface
110 // =========================================================
111
112 structure::tracks::Tracklist * tracklist () const;
113 structure::scenes::ClipLauncher * clipLauncher () const;
114 structure::scenes::ClipPlaybackService * clipPlaybackService () const;
115 dsp::Transport * getTransport () const;
116 dsp::AudioEngine * engine () const;
117 dsp::TempoMapWrapper * getTempoMap () const;
118 structure::arrangement::TempoObjectManager * tempoObjectManager () const;
119
120 // =========================================================
121 // TODO: Remove these accessors - QML should access via ControlRoom instead
122
123 dsp::Fader &monitor_fader () const;
124 dsp::Metronome &metronome () const;
125
126 // TODO: delete this getter, no one else should use factory directly
127 auto * arrangerObjectFactory () const
128 {
129 return arranger_object_factory_.get ();
130 }
131
132 friend void init_from (
133 Project &obj,
134 const Project &other,
135 utils::ObjectCloneType clone_type);
136
142 void add_default_tracks ();
143
144 structure::tracks::FinalTrackDependencies get_final_track_dependencies ();
145
146 utils::IObjectRegistry &get_registry () { return project_registry_; }
147 const utils::IObjectRegistry &get_registry () const
148 {
149 return project_registry_;
150 }
151
152 const auto &tempo_map () const { return tempo_map_; }
153
154 void set_audio_input_selection_provider (AudioInputSelectionProvider provider)
155 {
156 audio_input_selection_provider_ = std::move (provider);
157 }
158
159 const auto &audio_input_selection_provider () const
160 {
161 return audio_input_selection_provider_;
162 }
163
164 void set_midi_input_selection_provider (MidiInputSelectionProvider provider)
165 {
166 midi_input_selection_provider_ = std::move (provider);
167 }
168
169 const auto &midi_input_selection_provider () const
171 return midi_input_selection_provider_;
172 }
173
181 structure::tracks::TrackRecordingCallback callback);
182
183private:
184 static constexpr auto kTempoMapKey = "tempoMap"sv;
185 static constexpr auto kRegistryKey = "registry"sv;
186 static constexpr auto kTransportKey = "transport"sv;
187 static constexpr auto kAudioPoolKey = "audioPool"sv;
188 static constexpr auto kTracklistKey = "tracklist"sv;
189 static constexpr auto kRegionLinkGroupManagerKey = "regionLinkGroupManager"sv;
190 static constexpr auto kPortConnectionsManagerKey = "portConnectionsManager"sv;
191 static constexpr auto kTempoObjectManagerKey = "tempoObjectManager"sv;
192 static constexpr auto kClipLauncherKey = "clipLauncher"sv;
193 friend void to_json (nlohmann::json &j, const Project &project);
194 friend void from_json (const nlohmann::json &j, Project &project);
195
196private:
197 utils::AppSettings &app_settings_;
198 dsp::TempoMap tempo_map_;
200
201 plugins::PluginHostWindowFactory plugin_host_window_provider_;
202
203 ProjectRegistry project_registry_;
204
205 ProjectDirectoryPathProvider project_directory_path_provider_;
206
207 /* !!! IMPORTANT: order matters (for destruction) !!! */
209 dsp::IHardwareAudioInterface &hw_interface_;
210 std::shared_ptr<juce::AudioPluginFormatManager> plugin_format_manager_;
211
212public:
220public:
225
230
232 std::unique_ptr<dsp::AudioPool> pool_;
233
235 // structure::arrangement::RegionLinkGroupManager region_link_group_manager_;
236
243
250 std::vector<structure::tracks::Track *> tracks_rt_;
251
252private:
255 clip_playback_service_;
256
257 std::unique_ptr<structure::arrangement::ArrangerObjectFactory>
258 arranger_object_factory_;
259
260public:
262 std::unique_ptr<structure::tracks::TrackFactory> track_factory_;
263
264private:
266 tempo_object_manager_;
267
268 dsp::Fader &monitor_fader_;
269 dsp::Metronome &metronome_;
270
271 AudioInputSelectionProvider audio_input_selection_provider_;
272 MidiInputSelectionProvider midi_input_selection_provider_;
273
274 structure::tracks::TrackRecordingCallback track_recording_callback_;
275
282 dsp::DspGraphDispatcher graph_dispatcher_;
283};
284
285}
The audio engine.
Definition engine.h:28
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.
Abstraction for hardware MIDI interface.
Metronome processor.
Definition metronome.h:19
MIDI hardware input selection for a track.
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:54
std::unique_ptr< dsp::AudioPool > pool_
Audio file pool.
Definition project.h:222
utils::QObjectUniquePtr< dsp::Transport > transport_
Timeline metadata like BPM, time signature, etc.
Definition project.h:214
std::vector< structure::tracks::Track * > tracks_rt_
Realtime cache of tracks.
Definition project.h:240
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:208
utils::QObjectUniquePtr< dsp::AudioEngine > audio_engine_
The audio backend.
Definition project.h:219
utils::QObjectUniquePtr< structure::tracks::Tracklist > tracklist_
Manager for region link groups.
Definition project.h:232
std::function< dsp::AudioInputSelection *( const structure::tracks::Track::Uuid &)> AudioInputSelectionProvider
Callback to look up audio input selection for a track.
Definition project.h:78
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.