Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
engine.h
1// SPDX-FileCopyrightText: © 2018-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-FileCopyrightText: © 2020 Ryan Gonzalez <rymg19 at gmail dot com>
3// SPDX-License-Identifier: LicenseRef-ZrythmLicense
4
5#pragma once
6
7#include "zrythm-config.h"
8
9#include "dsp/panning.h"
10#include "gui/backend/channel.h"
11#include "gui/dsp/audio_port.h"
12#include "gui/dsp/control_room.h"
13#include "gui/dsp/ext_port.h"
14#include "gui/dsp/hardware_processor.h"
15#include "gui/dsp/midi_port.h"
16#include "gui/dsp/pool.h"
17#include "gui/dsp/sample_processor.h"
18#include "gui/dsp/transport.h"
19#include "utils/audio.h"
20#include "utils/backtrace.h"
21#include "utils/concurrency.h"
22#include "utils/object_pool.h"
23#include "utils/types.h"
24
25#ifdef HAVE_JACK
26# include "weakjack/weak_libjack.h"
27#endif
28
29#if HAVE_PULSEAUDIO
30# include <pulse/pulseaudio.h>
31#endif
32
33#ifdef HAVE_PORT_AUDIO
34# include <portaudio.h>
35#endif
36
37#if HAVE_RTAUDIO
38# include <rtaudio_c.h>
39#endif
40
41namespace zrythm::gui::old_dsp::plugins
42{
43class Plugin;
44}
45class Tracklist;
46class ExtPort;
47class MidiMappings;
48class Router;
49class Metronome;
50class Project;
52
58
59// should be set by backend
60constexpr int BLOCK_LENGTH = 4096;
61
62// should be set by backend
63constexpr int MIDI_BUF_SIZE = 1024;
64
65#define AUDIO_ENGINE (AudioEngine::get_active_instance ())
66#define AUDIO_POOL (AUDIO_ENGINE->pool_)
67
68#define DENORMAL_PREVENTION_VAL(engine_) ((engine_)->denormal_prevention_val_)
69
70constexpr int ENGINE_MAX_EVENTS = 128;
71
75#define ENGINE_EVENTS_PUSH(et, _arg, _uint_arg, _float_arg) \
76 { \
77 auto _ev = AUDIO_ENGINE->ev_pool_.acquire (); \
78 _ev->file_ = __FILE__; \
79 _ev->func_ = __func__; \
80 _ev->lineno_ = __LINE__; \
81 _ev->type_ = et; \
82 _ev->arg_ = (void *) _arg; \
83 _ev->uint_arg_ = _uint_arg; \
84 _ev->float_arg_ = _float_arg; \
85 AUDIO_ENGINE->ev_queue_.push_back (_ev); \
86 }
87
88enum class AudioBackend
89{
90 AUDIO_BACKEND_DUMMY,
91 AUDIO_BACKEND_DUMMY_LIBSOUNDIO,
92 AUDIO_BACKEND_ALSA,
93 AUDIO_BACKEND_ALSA_LIBSOUNDIO,
94 AUDIO_BACKEND_ALSA_RTAUDIO,
95 AUDIO_BACKEND_JACK,
96 AUDIO_BACKEND_JACK_LIBSOUNDIO,
97 AUDIO_BACKEND_JACK_RTAUDIO,
98 AUDIO_BACKEND_PULSEAUDIO,
99 AUDIO_BACKEND_PULSEAUDIO_LIBSOUNDIO,
100 AUDIO_BACKEND_PULSEAUDIO_RTAUDIO,
101 AUDIO_BACKEND_COREAUDIO_LIBSOUNDIO,
102 AUDIO_BACKEND_COREAUDIO_RTAUDIO,
103 AUDIO_BACKEND_SDL,
104 AUDIO_BACKEND_WASAPI_LIBSOUNDIO,
105 AUDIO_BACKEND_WASAPI_RTAUDIO,
106 AUDIO_BACKEND_ASIO_RTAUDIO,
107};
108
109static inline bool
110audio_backend_is_rtaudio (AudioBackend backend)
111{
112 return backend == AudioBackend::AUDIO_BACKEND_ALSA_RTAUDIO
113 || backend == AudioBackend::AUDIO_BACKEND_JACK_RTAUDIO
114 || backend == AudioBackend::AUDIO_BACKEND_PULSEAUDIO_RTAUDIO
115 || backend == AudioBackend::AUDIO_BACKEND_COREAUDIO_RTAUDIO
116 || backend == AudioBackend::AUDIO_BACKEND_WASAPI_RTAUDIO
117 || backend == AudioBackend::AUDIO_BACKEND_ASIO_RTAUDIO;
118}
119
140
141enum class MidiBackend
142{
143 MIDI_BACKEND_DUMMY,
144 MIDI_BACKEND_ALSA,
145 MIDI_BACKEND_ALSA_RTMIDI,
146 MIDI_BACKEND_JACK,
147 MIDI_BACKEND_JACK_RTMIDI,
148 MIDI_BACKEND_WINDOWS_MME,
149 MIDI_BACKEND_WINDOWS_MME_RTMIDI,
150 MIDI_BACKEND_COREMIDI_RTMIDI,
151 MIDI_BACKEND_WINDOWS_UWP_RTMIDI,
152};
153
154static inline bool
155midi_backend_is_rtmidi (MidiBackend backend)
156{
157 return backend == MidiBackend::MIDI_BACKEND_ALSA_RTMIDI
158 || backend == MidiBackend::MIDI_BACKEND_JACK_RTMIDI
159 || backend == MidiBackend::MIDI_BACKEND_WINDOWS_MME_RTMIDI
160 || backend == MidiBackend::MIDI_BACKEND_COREMIDI_RTMIDI
161 || backend == MidiBackend::MIDI_BACKEND_WINDOWS_UWP_RTMIDI;
162}
163
167class AudioEngine final : public ICloneable<AudioEngine>, public IPortOwner
168{
169public:
170 enum class JackTransportType
171 {
172 TimebaseMaster,
173 TransportClient,
174 NoJackTransport,
175 };
176
180 enum class SampleRate
181 {
182 SR_22050,
183 SR_32000,
184 SR_44100,
185 SR_48000,
186 SR_88200,
187 SR_96000,
188 SR_192000,
189 };
190
195 {
196 AUDIO_ENGINE_EVENT_BUFFER_SIZE_CHANGE,
197 AUDIO_ENGINE_EVENT_SAMPLE_RATE_CHANGE,
198 };
199
203 class Event
204 {
205 public:
206 Event () : file_ (nullptr), func_ (nullptr) { }
207
208 public:
210 AudioEngineEventType::AUDIO_ENGINE_EVENT_BUFFER_SIZE_CHANGE;
211 void * arg_ = nullptr;
212 uint32_t uint_arg_ = 0;
213 float float_arg_ = 0.0f;
214 const char * file_ = nullptr;
215 const char * func_ = nullptr;
216 int lineno_ = 0;
217 utils::Utf8String backtrace_;
218 };
219
223 enum class BufferSize
224 {
225 _16,
226 _32,
227 _64,
228 _128,
229 _256,
230 _512,
231 _1024,
232 _2048,
233 _4096,
234 };
235
236 // TODO: check if pausing/resuming can be done with RAII
237 struct State
238 {
245 };
246
248 {
250 bool is_rolling_ = false;
251
253 float bpm_ = 120.f;
254
256 double playhead_ticks_ = 0.0;
257
258 /* - below are used as cache to avoid re-calculations - */
259
261 int32_t bar_ = 1;
262
264 int32_t beat_ = 1;
265
267 int32_t sixteenth_ = 1;
268
271
275
277 double tick_within_beat_ = 0.0;
278
280 double tick_within_bar_ = 0.0;
281
284 };
285
286public:
292 AudioEngine (Project * project = nullptr);
293
297 ~AudioEngine () override;
298
299 auto &get_port_registry () { return *port_registry_; }
300 auto &get_port_registry () const { return *port_registry_; }
301 TrackRegistry &get_track_registry ();
302 TrackRegistry &get_track_registry () const;
303
304 bool has_handled_buffer_size_change () const
305 {
306 return audio_backend_ != AudioBackend::AUDIO_BACKEND_JACK
307 || (audio_backend_ == AudioBackend::AUDIO_BACKEND_JACK && handled_jack_buffer_size_change_.load());
308 }
309
310 bool is_in_active_project () const override;
311
313 const override;
314
316 get_full_designation_for_port (const dsp::PortIdentifier &id) const override;
317
323 void wait_for_pause (State &state, bool force_pause, bool with_fadeout);
324
325 void realloc_port_buffers (nframes_t buf_size);
326
333 [[gnu::cold]] void init_loaded (Project * project);
334
335 void resume (State &state);
336
342 void wait_n_cycles (int n);
343
344 void append_ports (std::vector<Port *> &ports);
345
349 void pre_setup ();
350
354 void setup ();
355
356 static AudioEngine * get_active_instance ();
357
363 [[gnu::cold]] void activate (bool activate);
364
375 int beats_per_bar,
376 bpm_t bpm,
377 sample_rate_t sample_rate,
378 bool thread_check,
379 bool update_from_ticks,
380 bool bpm_change);
381
386
397 [[gnu::hot]] bool process_prepare (
398 nframes_t nframes,
400
406 [[gnu::hot]] int process (nframes_t total_frames_to_process);
407
415 [[gnu::hot]] void post_process (nframes_t roll_nframes, nframes_t nframes);
416
420 void fill_out_bufs (nframes_t nframes);
421
425 static int buffer_size_enum_to_int (BufferSize buffer_size);
426
430 static int samplerate_enum_to_int (SampleRate samplerate);
431
439 void set_buffer_size (uint32_t buf_size);
440
445
452 static void set_default_backends (bool reset_to_dummy);
453
454 void init_after_cloning (const AudioEngine &other, ObjectCloneType clone_type)
455 override;
456
457 std::pair<AudioPort &, AudioPort &> get_monitor_out_ports ();
458 std::pair<AudioPort &, AudioPort &> get_dummy_input_ports ();
459
460private:
461 static constexpr auto kTransportTypeKey = "transportType"sv;
462 static constexpr auto kSampleRateKey = "sampleRate"sv;
463 static constexpr auto kFramesPerTickKey = "framesPerTick"sv;
464 static constexpr auto kMonitorOutLKey = "monitorOutL"sv;
465 static constexpr auto kMonitorOutRKey = "monitorOutR"sv;
466 static constexpr auto kMidiEditorManualPressKey = "midiEditorManualPress"sv;
467 static constexpr auto kMidiInKey = "midiIn"sv;
468 static constexpr auto kPoolKey = "pool"sv;
469 static constexpr auto kControlRoomKey = "controlRoom"sv;
470 static constexpr auto kSampleProcessorKey = "sampleProcessor"sv;
471 static constexpr auto kHwInProcessorKey = "hwInProcessor"sv;
472 static constexpr auto kHwOutProcessorKey = "hwOutProcessor"sv;
473 friend void to_json (nlohmann::json &j, const AudioEngine &engine)
474 {
475 j = nlohmann::json{
476 { kTransportTypeKey, engine.transport_type_ },
477 { kSampleRateKey, engine.sample_rate_ },
478 { kFramesPerTickKey, engine.frames_per_tick_ },
479 { kMonitorOutLKey, engine.monitor_out_left_ },
480 { kMonitorOutRKey, engine.monitor_out_right_ },
481 { kMidiEditorManualPressKey, engine.midi_editor_manual_press_ },
482 { kMidiInKey, engine.midi_in_ },
483 { kPoolKey, engine.pool_ },
484 { kControlRoomKey, engine.control_room_ },
485 { kSampleProcessorKey, engine.sample_processor_ },
486 { kHwInProcessorKey, engine.hw_in_processor_ },
487 { kHwOutProcessorKey, engine.hw_out_processor_ },
488 };
489 }
490 friend void from_json (const nlohmann::json &j, AudioEngine &engine);
491
495 int clean_duplicate_events_and_copy (std::array<Event *, 100> &ret);
496
497 [[gnu::cold]] void init_common ();
498
499 void update_position_info (PositionInfo &pos_nfo, nframes_t frames_to_add);
500
506 void clear_output_buffers (nframes_t nframes);
507
508 void receive_midi_events (uint32_t nframes);
509
514 void stop_events ();
515
516private:
517 OptionalRef<PortRegistry> port_registry_;
518
519public:
521 Project * project_ = nullptr;
522
528 std::atomic_uint64_t cycle_ = 0;
529
530#ifdef HAVE_JACK
532 jack_client_t * client_ = nullptr;
533#else
534 void * client_ = nullptr;
535#endif
536
543 std::atomic_bool handled_jack_buffer_size_change_ = false;
544
548 JackTransportType transport_type_ = (JackTransportType) 0;
549
551 AudioBackend audio_backend_ = (AudioBackend) 0;
552
554 MidiBackend midi_backend_ = (MidiBackend) 0;
555
558
560 size_t midi_buf_size_ = 0;
561
564
567
572
575
577 std::unique_ptr<Router> router_;
578
580 std::unique_ptr<HardwareProcessor> hw_in_processor_;
581
583 std::unique_ptr<HardwareProcessor> hw_out_processor_;
584
590 std::unique_ptr<MidiPort> midi_clock_in_;
591
597 std::unique_ptr<MidiPort> midi_clock_out_;
598
600 std::unique_ptr<ControlRoom> control_room_;
601
603 std::unique_ptr<AudioPool> pool_;
604
610 std::optional<PortUuidReference> dummy_left_input_;
611 std::optional<PortUuidReference> dummy_right_input_;
612
619 std::optional<PortUuidReference> monitor_out_left_;
620 std::optional<PortUuidReference> monitor_out_right_;
621
628 std::atomic_bool trigger_midi_activity_{ false };
629
640 std::unique_ptr<MidiPort> midi_editor_manual_press_;
641
648 std::unique_ptr<MidiPort> midi_in_;
649
656
660 moodycamel::LightweightSemaphore port_operation_lock_{ 1 };
661
663 std::atomic_bool run_{ false };
664
667
669 std::atomic_bool exporting_{ false };
670
672 std::atomic_bool panic_{ false };
673
674#ifdef HAVE_PORT_AUDIO
675 PaStream * port_audio_stream_ = nullptr;
676#else
677 void * port_audio_stream_ = nullptr;
678#endif
679
687 float * port_audio_out_buf_ = nullptr;
688
689#if HAVE_RTAUDIO
690 rtaudio_t rtaudio_ = nullptr;
691#else
692 void * rtaudio_ = nullptr;
693#endif
694
695#if HAVE_PULSEAUDIO
696 pa_threaded_mainloop * pulse_mainloop_ = nullptr;
697 pa_context * pulse_context_ = nullptr;
698 pa_stream * pulse_stream_ = nullptr;
699#else
700 void * pulse_mainloop_ = nullptr;
701 void * pulse_context_ = nullptr;
702 void * pulse_stream_ = nullptr;
703#endif
704 std::atomic_bool pulse_notified_underflow_{ false };
705
715 std::unique_ptr<juce::Thread> dummy_audio_thread_;
716
717 /* note: these 2 are ignored at the moment */
719 dsp::PanLaw pan_law_ = {};
721 dsp::PanAlgorithm pan_algo_ = {};
722
724 // SteadyDuration last_time_taken_;
725
735 RtDuration max_time_taken_{};
736
738 RtTimePoint timestamp_start_{};
739
741 // SteadyTimePoint timestamp_end_{};
742
745
747 // SteadyTimePoint last_timestamp_end_{};
748
753
754 std::unique_ptr<SampleProcessor> sample_processor_;
755
757 std::atomic_bool capture_cc_{ false };
758
760 std::array<midi_byte_t, 3> last_cc_captured_{};
761
768 SteadyTimePoint last_xrun_notification_;
769
780 float denormal_prevention_val_ = 1e-12f;
781
789
791 utils::audio::BounceStep bounce_step_ = {};
792
795
797 std::unique_ptr<Metronome> metronome_;
798
799 /* --- events --- */
800
810 MPMCQueue<Event *> ev_queue_{ ENGINE_MAX_EVENTS };
811
815 ObjectPool<Event> ev_pool_{ ENGINE_MAX_EVENTS };
816
818 // sigc::scoped_connection process_source_id_;
819
821 bool processing_events_ = false;
822
825
827 SteadyTimePoint last_events_processed_;
828
829 /* --- end events --- */
830
832 std::atomic_bool cycle_running_{ false };
833
835 bool pre_setup_ = false;
836
838 bool setup_ = false;
839
841 bool activated_ = false;
842
844 bool destroying_ = false;
845
852
858
863
868};
869
870DEFINE_ENUM_FORMATTER (
871 AudioBackend,
872 AudioBackend,
873 /* TRANSLATORS: Dummy backend */
874 QT_TR_NOOP_UTF8 ("Dummy"),
875 QT_TR_NOOP_UTF8 ("Dummy (libsoundio)"),
876 "ALSA (not working)",
877 "ALSA (libsoundio)",
878 "ALSA (rtaudio)",
879 "JACK",
880 "JACK (libsoundio)",
881 "JACK (rtaudio)",
882 "PulseAudio",
883 "PulseAudio (libsoundio)",
884 "PulseAudio (rtaudio)",
885 "CoreAudio (libsoundio)",
886 "CoreAudio (rtaudio)",
887 "SDL",
888 "WASAPI (libsoundio)",
889 "WASAPI (rtaudio)",
890 "ASIO (rtaudio)")
891
892DEFINE_ENUM_FORMATTER (
893 MidiBackend,
894 MidiBackend,
895 /* TRANSLATORS: Dummy backend */
896 QT_TR_NOOP_UTF8 ("Dummy"),
897 QT_TR_NOOP_UTF8 ("ALSA Sequencer (not working)"),
898 QT_TR_NOOP_UTF8 ("ALSA Sequencer (rtmidi)"),
899 "JACK MIDI",
900 "JACK MIDI (rtmidi)",
901 "Windows MME",
902 "Windows MME (rtmidi)",
903 "CoreMIDI (rtmidi)",
904 "Windows UWP (rtmidi)")
905
906DEFINE_ENUM_FORMATTER (
907 AudioEngine::SampleRate,
908 AudioEngine_SampleRate,
909 QT_TR_NOOP_UTF8 ("22,050"),
910 QT_TR_NOOP_UTF8 ("32,000"),
911 QT_TR_NOOP_UTF8 ("44,100"),
912 QT_TR_NOOP_UTF8 ("48,000"),
913 QT_TR_NOOP_UTF8 ("88,200"),
914 QT_TR_NOOP_UTF8 ("96,000"),
915 QT_TR_NOOP_UTF8 ("192,000"))
916
917DEFINE_ENUM_FORMATTER (
918 AudioEngine::BufferSize,
919 AudioEngine_BufferSize,
920 "16",
921 "32",
922 "64",
923 "128",
924 "256",
925 "512",
926 QT_TR_NOOP_UTF8 ("1,024"),
927 QT_TR_NOOP_UTF8 ("2,048"),
928 QT_TR_NOOP_UTF8 ("4,096"))
929
The audio engine.
Definition engine.h:168
std::unique_ptr< MidiPort > midi_in_
Port used for receiving MIDI in messages for binding CC and other non-recording purposes.
Definition engine.h:648
AudioEngineEventType
Audio engine event type.
Definition engine.h:195
sample_rate_t sample_rate_
Sample rate.
Definition engine.h:563
RtTimePoint timestamp_start_
Timestamp at the start of the current cycle.
Definition engine.h:738
nframes_t remaining_latency_preroll_
Timestamp at end of previous cycle.
Definition engine.h:752
bool destroying_
Whether the engine is currently undergoing destruction.
Definition engine.h:844
void activate(bool activate)
Activates the audio engine to start processing and receiving events.
BounceMode bounce_mode_
If this is on, only tracks/regions marked as "for bounce" will be allowed to make sound.
Definition engine.h:788
nframes_t block_length_
Audio buffer size (block length), per channel.
Definition engine.h:557
RtDuration max_time_taken_
Time taken to process in the last cycle.
Definition engine.h:735
void wait_n_cycles(int n)
Waits for n processing cycles to finish.
void setup()
Sets up the audio engine after the project is initialized/loaded.
std::atomic_bool panic_
Send note off MIDI everywhere.
Definition engine.h:672
BufferSize
Buffer sizes to be used in combo boxes.
Definition engine.h:224
std::atomic_bool handled_jack_buffer_size_change_
Whether pending jack buffer change was handled (buffers reallocated).
Definition engine.h:543
RtTimePoint last_timestamp_start_
Expected timestamp at the end of the current cycle.
Definition engine.h:744
std::atomic_bool capture_cc_
To be set to 1 when the CC from the Midi in port should be captured.
Definition engine.h:757
SteadyTimePoint last_xrun_notification_
Last time an XRUN notification was shown.
Definition engine.h:768
SteadyTimePoint last_events_process_started_
Time last event processing started.
Definition engine.h:824
bool denormal_prevention_val_positive_
Whether the denormal prevention value (1e-12 ~ 1e-20) is positive.
Definition engine.h:779
SampleRate
Samplerates to be used in comboboxes.
Definition engine.h:181
std::optional< PortUuidReference > dummy_left_input_
Used during tests to pass input data for recording.
Definition engine.h:610
float * port_audio_out_buf_
Port Audio output buffer.
Definition engine.h:687
int process(nframes_t total_frames_to_process)
Processes current cycle.
PositionInfo pos_nfo_before_
Position info at the end of the previous cycle before moving the transport.
Definition engine.h:857
bool processing_events_
ID of the event processing source func.
Definition engine.h:821
std::unique_ptr< MidiPort > midi_clock_out_
MIDI Clock output.
Definition engine.h:597
size_t midi_buf_size_
Size of MIDI port buffers in bytes.
Definition engine.h:560
static int samplerate_enum_to_int(SampleRate samplerate)
Returns the int value corresponding to the given AudioEngineSamplerate.
moodycamel::LightweightSemaphore port_operation_lock_
Semaphore for blocking DSP while a plugin and its ports are deleted.
Definition engine.h:660
MidiBackend midi_backend_
Current MIDI backend.
Definition engine.h:554
ObjectPool< Event > ev_pool_
Object pool of event structs to avoid allocation.
Definition engine.h:815
AudioBackend audio_backend_
Current audio backend.
Definition engine.h:551
std::atomic_bool run_
Ok to process or not.
Definition engine.h:663
static void set_default_backends(bool reset_to_dummy)
Detects the best backends on the system and sets them to GSettings.
std::atomic_bool cycle_running_
Whether the cycle is currently running.
Definition engine.h:832
int buf_size_set_
True iff buffer size callback fired.
Definition engine.h:574
utils::audio::BounceStep bounce_step_
Bounce step cache.
Definition engine.h:791
void pre_setup()
Sets up the audio engine before the project is initialized/loaded.
std::array< midi_byte_t, 3 > last_cc_captured_
Last MIDI CC captured.
Definition engine.h:760
bool preparing_to_export_
To be set to true when preparing to export.
Definition engine.h:666
void update_frames_per_tick(int beats_per_bar, bpm_t bpm, sample_rate_t sample_rate, bool thread_check, bool update_from_ticks, bool bpm_change)
Updates frames per tick based on the time sig, the BPM, and the sample rate.
std::unique_ptr< HardwareProcessor > hw_out_processor_
Output device processor.
Definition engine.h:583
dsp::PanLaw pan_law_
Pan law.
Definition engine.h:719
void init_loaded(Project *project)
JackTransportType transport_type_
Whether transport master/client or no connection with jack transport.
Definition engine.h:548
void fill_out_bufs(nframes_t nframes)
Called to fill in the external buffers at the end of the processing cycle.
MPMCQueue< Event * > ev_queue_
Event queue.
Definition engine.h:810
bool process_prepare(nframes_t nframes, SemaphoreRAII< moodycamel::LightweightSemaphore > *sem=nullptr)
To be called by each implementation to prepare the structures before processing.
std::unique_ptr< HardwareProcessor > hw_in_processor_
Input device processor.
Definition engine.h:580
void reset_bounce_mode()
Reset the bounce mode on the engine, all tracks and regions to OFF.
PositionInfo pos_nfo_current_
Position info at the start of the current cycle.
Definition engine.h:862
std::unique_ptr< juce::Thread > dummy_audio_thread_
Dummy audio DSP processing thread.
Definition engine.h:715
void init_after_cloning(const AudioEngine &other, ObjectCloneType clone_type) override
Initializes the cloned object.
void post_process(nframes_t roll_nframes, nframes_t nframes)
To be called after processing for common logic.
PositionInfo pos_nfo_at_end_
Expected position info at the end of the current cycle.
Definition engine.h:867
static int buffer_size_enum_to_int(BufferSize buffer_size)
Returns the int value corresponding to the given AudioEngineBufferSize.
void set_port_metadata_from_owner(dsp::PortIdentifier &id, PortRange &range) const override
Function that will be called by the Port to update the identifier's relevant members based on this po...
SteadyTimePoint last_events_processed_
Time last event processing completed.
Definition engine.h:827
void wait_for_pause(State &state, bool force_pause, bool with_fadeout)
bool activated_
Whether the engine is currently activated.
Definition engine.h:841
Project * project_
Pointer to owner project, if any.
Definition engine.h:521
std::atomic_bool exporting_
Whether currently exporting.
Definition engine.h:669
dsp::TicksPerFrame ticks_per_frame_
Reciprocal of frames_per_tick_.
Definition engine.h:571
std::unique_ptr< Metronome > metronome_
The metronome.
Definition engine.h:797
bool process_events()
Timeout function to be called periodically by Glib.
nframes_t nframes_
Number of frames/samples in the current cycle, per channel.
Definition engine.h:655
AudioEngine(Project *project=nullptr)
Create a new audio engine.
dsp::FramesPerTick frames_per_tick_
Number of frames/samples per tick.
Definition engine.h:566
std::unique_ptr< ControlRoom > control_room_
The ControlRoom.
Definition engine.h:600
bool pre_setup_
Whether the engine is already pre-set up.
Definition engine.h:835
bool updating_frames_per_tick_
True while updating frames per tick.
Definition engine.h:851
std::unique_ptr< MidiPort > midi_clock_in_
MIDI Clock input TODO.
Definition engine.h:590
dsp::PanAlgorithm pan_algo_
Pan algorithm.
Definition engine.h:721
std::unique_ptr< AudioPool > pool_
Audio file pool.
Definition engine.h:603
std::atomic_bool trigger_midi_activity_
Flag to tell the UI that this channel had MIDI activity.
Definition engine.h:628
std::unique_ptr< Router > router_
The processing graph router.
Definition engine.h:577
~AudioEngine() override
Closes any connections and free's data.
std::optional< PortUuidReference > monitor_out_left_
Monitor - these should be the last ports in the signal chain.
Definition engine.h:619
bool setup_
Whether the engine is already set up.
Definition engine.h:838
bool bounce_with_parents_
Whether currently bouncing with parents (cache).
Definition engine.h:794
void set_buffer_size(uint32_t buf_size)
Request the backend to set the buffer size.
std::atomic_uint64_t cycle_
Cycle count to know which cycle we are in.
Definition engine.h:528
std::unique_ptr< MidiPort > midi_editor_manual_press_
Manual note press events from the piano roll.
Definition engine.h:640
External port.
Definition ext_port.h:41
Hardware processor.
Multiple Producer Multiple Consumer lock-free queue.
Definition mpmc_queue.h:67
Metronome settings.
Definition metronome.h:34
All MIDI mappings in Zrythm.
Thread-safe, realtime-safe object pool.
Definition object_pool.h:18
Contains all of the info that will be serialized into a project file.
Definition project.h:71
The Router class manages the processing graph for the audio engine.
Definition router.h:55
RAII wrapper class for std::binary_semaphore.
Definition concurrency.h:61
The Tracklist contains all the tracks in the Project.
Definition tracklist.h:32
Struct used to identify Ports in the project.
This class provides the core functionality for managing a plugin, including creating/initializing the...
Definition plugin.h:41
Lightweight UTF-8 string wrapper with safe conversions.
Definition string.h:39
External ports.
BounceMode
Mode used when bouncing, either during exporting or when bouncing tracks or regions to audio.
Definition engine.h:125
@ BOUNCE_ON
Bounce.
Definition engine.h:130
@ BOUNCE_INHERIT
Bounce if parent is bouncing.
Definition engine.h:138
@ BOUNCE_OFF
Don't bounce.
Definition engine.h:127
uint32_t sample_rate_t
Sample rate.
Definition types.h:65
uint32_t nframes_t
Frame count.
Definition types.h:62
float bpm_t
The BPM type.
Definition types.h:77
ObjectCloneType
Definition icloneable.h:25
int32_t sixteenth_within_song_
Current sixteenth (within song, ie, total sixteenths).
Definition engine.h:274
double tick_within_bar_
Current tick (within bar).
Definition engine.h:280
int32_t bar_
Current bar.
Definition engine.h:261
int32_t sixteenth_
Current sixteenth (within beat).
Definition engine.h:267
int32_t ninetysixth_notes_
Total 1/96th notes completed up to current pos.
Definition engine.h:283
int32_t beat_
Current beat (within bar).
Definition engine.h:264
double playhead_ticks_
Exact playhead position (in ticks).
Definition engine.h:256
bool is_rolling_
Transport is rolling.
Definition engine.h:250
int32_t sixteenth_within_bar_
Current sixteenth (within bar).
Definition engine.h:270
double tick_within_beat_
Current tick-within-beat.
Definition engine.h:277
bool playing_
Playback.
Definition engine.h:242
bool running_
Engine running.
Definition engine.h:240
bool looping_
Transport loop.
Definition engine.h:244
Custom types.