Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::engine::device_io::AudioEngine Class Reference

The audio engine. More...

#include <src/engine/device_io/engine.h>

Inheritance diagram for zrythm::engine::device_io::AudioEngine:
Collaboration diagram for zrythm::engine::device_io::AudioEngine:

Data Structures

struct  PositionInfo

Public Types

enum class  ProcessReturnStatus { ProcessCompleted , ProcessSkipped , ProcessFailed }
using BeatsPerBarGetter = std::function<int ()>
using BpmGetter = std::function<bpm_t ()>

Public Member Functions

 AudioEngine (Project *project=nullptr, std::shared_ptr< juce::AudioDeviceManager > device_mgr=std::make_shared< juce::AudioDeviceManager >())
 Create a new audio engine.
 ~AudioEngine () override
 Closes any connections and free's data.
Q_INVOKABLE int xRunCount () const
Q_INVOKABLE double loadPercentage () const
auto & get_port_registry ()
auto & get_port_registry () const
auto & get_param_registry ()
auto & get_param_registry () const
structure::tracks::TrackRegistry & get_track_registry ()
structure::tracks::TrackRegistry & get_track_registry () const
void wait_for_pause (EngineState &state, bool force_pause, bool with_fadeout)
void realloc_port_buffers (nframes_t buf_size)
void init_loaded (Project *project)
void resume (EngineState &state)
void wait_n_cycles (int n)
 Waits for n processing cycles to finish.
void setup (BeatsPerBarGetter beats_per_bar_getter, BpmGetter bpm_getter)
 Sets up the audio engine after the project is initialized/loaded.
void activate (bool activate)
 Activates the audio engine to start processing and receiving events.
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.
bool process_prepare (dsp::Transport::TransportSnapshot &transport_snapshot, nframes_t nframes, SemaphoreRAII< moodycamel::LightweightSemaphore > *sem=nullptr)
 To be called by each implementation to prepare the structures before processing.
auto process (nframes_t total_frames_to_process) -> ProcessReturnStatus
 Processes current cycle.
void post_process (dsp::Transport::TransportSnapshot &transport_snapshot, nframes_t roll_nframes, nframes_t nframes)
 To be called after processing for common logic.
void reset_bounce_mode ()
 Reset the bounce mode on the engine, all tracks and regions to OFF.
dsp::AudioPortget_monitor_out_port ()
dsp::AudioPortget_dummy_input_port ()
void panic_all ()
 Queues MIDI note off to event queues.
void clear_output_buffers (nframes_t nframes)
 Clears the underlying backend's output buffers.
auto get_device_manager () const
nframes_t get_block_length () const
sample_rate_t get_sample_rate () const

Static Public Member Functions

static AudioEngineget_active_instance ()

Data Fields

Projectproject_ = nullptr
 Pointer to owner project, if any.
std::shared_ptr< juce::AudioDeviceManager > device_manager_
std::atomic_uint64_t cycle_ = 0
 Cycle count to know which cycle we are in.
bool buf_size_set_ {}
 Number of frames/samples per tick.
std::unique_ptr< session::DspGraphDispatcherrouter_
 The processing graph router.
std::unique_ptr< session::ControlRoomcontrol_room_
 The ControlRoom.
std::optional< dsp::PortUuidReference > dummy_audio_input_
 Used during tests to pass input data for recording.
std::optional< dsp::PortUuidReference > monitor_out_
 Monitor - these should be the last ports in the signal chain.
dsp::AudioPortmonitor_out_port_ {}
dsp::MidiEventVector midi_editor_manual_press_
 Manual note press events from the piano roll.
std::unique_ptr< dsp::MidiPortmidi_in_
 Port used for receiving MIDI in messages for binding CC and other non-recording purposes.
nframes_t nframes_ = 0
 Number of frames/samples in the current cycle, per channel.
moodycamel::LightweightSemaphore port_operation_lock_ { 1 }
 Semaphore for blocking DSP while a plugin and its ports are deleted.
std::atomic_bool run_ { false }
 Ok to process or not.
bool preparing_to_export_ = false
 To be set to true when preparing to export.
std::atomic_bool exporting_ { false }
 Whether currently exporting.
dsp::PanLaw pan_law_ = {}
 Pan law.
dsp::PanAlgorithm pan_algo_ = {}
 Pan algorithm.
juce::AudioProcessLoadMeasurer load_measurer_
nframes_t remaining_latency_preroll_ = 0
 When first set, it is equal to the max playback latency of all initial trigger nodes.
QPointer< dsp::PortConnectionsManagerport_connections_manager_
std::unique_ptr< session::SampleProcessorsample_processor_
std::atomic_bool capture_cc_ { false }
 To be set to 1 when the CC from the Midi in port should be captured.
std::array< midi_byte_t, 3 > last_cc_captured_ {}
 Last MIDI CC captured.
BounceMode bounce_mode_ = BounceMode::Off
 If this is on, only tracks/regions marked as "for bounce" will be allowed to make sound.
utils::audio::BounceStep bounce_step_ = {}
 Bounce step cache.
bool bounce_with_parents_ = false
 Whether currently bouncing with parents (cache).
std::atomic_bool cycle_running_ { false }
 Whether the cycle is currently running.
bool setup_ = false
 Whether the engine is already set up.
bool activated_ = false
 Whether the engine is currently activated.
bool destroying_ = false
 Whether the engine is currently undergoing destruction.
PositionInfo pos_nfo_before_ = {}
 True while updating frames per tick.
PositionInfo pos_nfo_current_ = {}
 Position info at the start of the current cycle.
PositionInfo pos_nfo_at_end_ = {}
 Expected position info at the end of the current cycle.
utils::QObjectUniquePtr< dsp::MidiPanicProcessormidi_panic_processor_
std::unique_ptr< AudioCallbackaudio_callback_

Friends

void init_from (AudioEngine &obj, const AudioEngine &other, utils::ObjectCloneType clone_type)
void to_json (nlohmann::json &j, const AudioEngine &engine)
void from_json (const nlohmann::json &j, AudioEngine &engine)

Detailed Description

The audio engine.

Definition at line 49 of file engine.h.

Member Typedef Documentation

◆ BeatsPerBarGetter

using zrythm::engine::device_io::AudioEngine::BeatsPerBarGetter = std::function<int ()>

Definition at line 150 of file engine.h.

◆ BpmGetter

using zrythm::engine::device_io::AudioEngine::BpmGetter = std::function<bpm_t ()>

Definition at line 151 of file engine.h.

Member Enumeration Documentation

◆ ProcessReturnStatus

enum class zrythm::engine::device_io::AudioEngine::ProcessReturnStatus
strong

Definition at line 202 of file engine.h.

Constructor & Destructor Documentation

◆ AudioEngine()

zrythm::engine::device_io::AudioEngine::AudioEngine ( Project * project = nullptr,
std::shared_ptr< juce::AudioDeviceManager > device_mgr = std::make_shared< juce::AudioDeviceManager >() )

Create a new audio engine.

This only initializes the engine and does not connect to any backend.

Member Function Documentation

◆ activate()

void zrythm::engine::device_io::AudioEngine::activate ( bool activate)

Activates the audio engine to start processing and receiving events.

Parameters
activateActivate or deactivate.

◆ clear_output_buffers()

void zrythm::engine::device_io::AudioEngine::clear_output_buffers ( nframes_t nframes)

Clears the underlying backend's output buffers.

Used when returning early.

◆ get_block_length()

nframes_t zrythm::engine::device_io::AudioEngine::get_block_length ( ) const
inline

Definition at line 259 of file engine.h.

◆ get_device_manager()

auto zrythm::engine::device_io::AudioEngine::get_device_manager ( ) const
inline

Definition at line 257 of file engine.h.

◆ get_param_registry() [1/2]

auto & zrythm::engine::device_io::AudioEngine::get_param_registry ( )
inline

Definition at line 119 of file engine.h.

◆ get_param_registry() [2/2]

auto & zrythm::engine::device_io::AudioEngine::get_param_registry ( ) const
inline

Definition at line 120 of file engine.h.

◆ get_port_registry() [1/2]

auto & zrythm::engine::device_io::AudioEngine::get_port_registry ( )
inline

Definition at line 117 of file engine.h.

◆ get_port_registry() [2/2]

auto & zrythm::engine::device_io::AudioEngine::get_port_registry ( ) const
inline

Definition at line 118 of file engine.h.

◆ get_sample_rate()

sample_rate_t zrythm::engine::device_io::AudioEngine::get_sample_rate ( ) const
inline

Definition at line 266 of file engine.h.

◆ init_loaded()

void zrythm::engine::device_io::AudioEngine::init_loaded ( Project * project)
Parameters
project
Exceptions
ZrythmErrorif failed to initialize.

◆ loadPercentage()

Q_INVOKABLE double zrythm::engine::device_io::AudioEngine::loadPercentage ( ) const
inline

Definition at line 112 of file engine.h.

◆ post_process()

void zrythm::engine::device_io::AudioEngine::post_process ( dsp::Transport::TransportSnapshot & transport_snapshot,
nframes_t roll_nframes,
nframes_t nframes )

To be called after processing for common logic.

Parameters
roll_nframesFrames to roll (add to the playhead - if transport rolling).
nframesTotal frames for this processing cycle.

◆ process()

auto zrythm::engine::device_io::AudioEngine::process ( nframes_t total_frames_to_process) ->ProcessReturnStatus

Processes current cycle.

To be called by each implementation in its callback.

◆ process_prepare()

bool zrythm::engine::device_io::AudioEngine::process_prepare ( dsp::Transport::TransportSnapshot & transport_snapshot,
nframes_t nframes,
SemaphoreRAII< moodycamel::LightweightSemaphore > * sem = nullptr )

To be called by each implementation to prepare the structures before processing.

Clears buffers, marks all as unprocessed, etc.

Parameters
semSemamphoreRAII to check if acquired. If not acquired before calling this function, it will only clear output buffers and return true.
Returns
Whether the cycle should be skipped.

◆ setup()

void zrythm::engine::device_io::AudioEngine::setup ( BeatsPerBarGetter beats_per_bar_getter,
BpmGetter bpm_getter )

Sets up the audio engine after the project is initialized/loaded.

This also calls update_frames_per_tick() which requires the project to be initialized/loaded.

◆ update_frames_per_tick()

void zrythm::engine::device_io::AudioEngine::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.

Parameters
thread_checkWhether to throw a warning if not called from GTK thread.
update_from_ticksWhether to update the positions based on ticks (true) or frames (false).
bpm_changeWhether this is a BPM change.

◆ wait_for_pause()

void zrythm::engine::device_io::AudioEngine::wait_for_pause ( EngineState & state,
bool force_pause,
bool with_fadeout )
Parameters
force_pauseWhether to force transport pause, otherwise for engine to process and handle the pause request.

◆ wait_n_cycles()

void zrythm::engine::device_io::AudioEngine::wait_n_cycles ( int n)

Waits for n processing cycles to finish.

Used during tests.

◆ xRunCount()

Q_INVOKABLE int zrythm::engine::device_io::AudioEngine::xRunCount ( ) const
inline

Definition at line 111 of file engine.h.

Field Documentation

◆ activated_

bool zrythm::engine::device_io::AudioEngine::activated_ = false

Whether the engine is currently activated.

Definition at line 447 of file engine.h.

◆ audio_callback_

std::unique_ptr<AudioCallback> zrythm::engine::device_io::AudioEngine::audio_callback_

Definition at line 477 of file engine.h.

◆ bounce_mode_

BounceMode zrythm::engine::device_io::AudioEngine::bounce_mode_ = BounceMode::Off

If this is on, only tracks/regions marked as "for bounce" will be allowed to make sound.

Automation and everything else will work as normal.

Definition at line 432 of file engine.h.

◆ bounce_step_

utils::audio::BounceStep zrythm::engine::device_io::AudioEngine::bounce_step_ = {}

Bounce step cache.

Definition at line 435 of file engine.h.

◆ bounce_with_parents_

bool zrythm::engine::device_io::AudioEngine::bounce_with_parents_ = false

Whether currently bouncing with parents (cache).

Definition at line 438 of file engine.h.

◆ buf_size_set_

bool zrythm::engine::device_io::AudioEngine::buf_size_set_ {}

Number of frames/samples per tick.

Reciprocal of frames_per_tick_. True iff buffer size callback fired.

Definition at line 316 of file engine.h.

◆ capture_cc_

std::atomic_bool zrythm::engine::device_io::AudioEngine::capture_cc_ { false }

To be set to 1 when the CC from the Midi in port should be captured.

Definition at line 421 of file engine.h.

◆ control_room_

std::unique_ptr<session::ControlRoom> zrythm::engine::device_io::AudioEngine::control_room_

The ControlRoom.

Definition at line 339 of file engine.h.

◆ cycle_

std::atomic_uint64_t zrythm::engine::device_io::AudioEngine::cycle_ = 0

Cycle count to know which cycle we are in.

Useful for debugging.

Definition at line 305 of file engine.h.

◆ cycle_running_

std::atomic_bool zrythm::engine::device_io::AudioEngine::cycle_running_ { false }

Whether the cycle is currently running.

Definition at line 441 of file engine.h.

◆ destroying_

bool zrythm::engine::device_io::AudioEngine::destroying_ = false

Whether the engine is currently undergoing destruction.

Definition at line 450 of file engine.h.

◆ device_manager_

std::shared_ptr<juce::AudioDeviceManager> zrythm::engine::device_io::AudioEngine::device_manager_

Definition at line 298 of file engine.h.

◆ dummy_audio_input_

std::optional<dsp::PortUuidReference> zrythm::engine::device_io::AudioEngine::dummy_audio_input_

Used during tests to pass input data for recording.

Will be ignored if NULL.

Definition at line 346 of file engine.h.

◆ exporting_

std::atomic_bool zrythm::engine::device_io::AudioEngine::exporting_ { false }

Whether currently exporting.

Definition at line 401 of file engine.h.

◆ last_cc_captured_

std::array<midi_byte_t, 3> zrythm::engine::device_io::AudioEngine::last_cc_captured_ {}

Last MIDI CC captured.

Definition at line 424 of file engine.h.

◆ load_measurer_

juce::AudioProcessLoadMeasurer zrythm::engine::device_io::AudioEngine::load_measurer_

Definition at line 409 of file engine.h.

◆ midi_editor_manual_press_

dsp::MidiEventVector zrythm::engine::device_io::AudioEngine::midi_editor_manual_press_

Manual note press events from the piano roll.

The events from here should be fed to the corresponding track processor's MIDI in port (TrackProcessor.midi_in). To avoid having to recalculate the graph to reattach this port to the correct track processor, only connect this port to the initial processor in the routing graph and fetch the events manually when processing the corresponding track processor (or just do this at the start of each processing cycle).

See also
DspGraphDispatcher.

Definition at line 372 of file engine.h.

◆ midi_in_

std::unique_ptr<dsp::MidiPort> zrythm::engine::device_io::AudioEngine::midi_in_

Port used for receiving MIDI in messages for binding CC and other non-recording purposes.

This port is exposed to the backend.

Definition at line 380 of file engine.h.

◆ midi_panic_processor_

utils::QObjectUniquePtr<dsp::MidiPanicProcessor> zrythm::engine::device_io::AudioEngine::midi_panic_processor_

Definition at line 475 of file engine.h.

◆ monitor_out_

std::optional<dsp::PortUuidReference> zrythm::engine::device_io::AudioEngine::monitor_out_

Monitor - these should be the last ports in the signal chain.

The L/R ports are exposed to the backend.

Definition at line 354 of file engine.h.

◆ monitor_out_port_

dsp::AudioPort* zrythm::engine::device_io::AudioEngine::monitor_out_port_ {}

Definition at line 357 of file engine.h.

◆ nframes_

nframes_t zrythm::engine::device_io::AudioEngine::nframes_ = 0

Number of frames/samples in the current cycle, per channel.

Note
This is used by the engine internally.

Definition at line 387 of file engine.h.

◆ pan_algo_

dsp::PanAlgorithm zrythm::engine::device_io::AudioEngine::pan_algo_ = {}

Pan algorithm.

Definition at line 407 of file engine.h.

◆ pan_law_

dsp::PanLaw zrythm::engine::device_io::AudioEngine::pan_law_ = {}

Pan law.

Definition at line 405 of file engine.h.

◆ port_connections_manager_

QPointer<dsp::PortConnectionsManager> zrythm::engine::device_io::AudioEngine::port_connections_manager_

Definition at line 416 of file engine.h.

◆ port_operation_lock_

moodycamel::LightweightSemaphore zrythm::engine::device_io::AudioEngine::port_operation_lock_ { 1 }

Semaphore for blocking DSP while a plugin and its ports are deleted.

Definition at line 392 of file engine.h.

◆ pos_nfo_at_end_

PositionInfo zrythm::engine::device_io::AudioEngine::pos_nfo_at_end_ = {}

Expected position info at the end of the current cycle.

Definition at line 473 of file engine.h.

◆ pos_nfo_before_

PositionInfo zrythm::engine::device_io::AudioEngine::pos_nfo_before_ = {}

True while updating frames per tick.

See engine_update_frames_per_tick(). Position info at the end of the previous cycle before moving the transport.

Definition at line 463 of file engine.h.

◆ pos_nfo_current_

PositionInfo zrythm::engine::device_io::AudioEngine::pos_nfo_current_ = {}

Position info at the start of the current cycle.

Definition at line 468 of file engine.h.

◆ preparing_to_export_

bool zrythm::engine::device_io::AudioEngine::preparing_to_export_ = false

To be set to true when preparing to export.

Definition at line 398 of file engine.h.

◆ project_

Project* zrythm::engine::device_io::AudioEngine::project_ = nullptr

Pointer to owner project, if any.

Definition at line 296 of file engine.h.

◆ remaining_latency_preroll_

nframes_t zrythm::engine::device_io::AudioEngine::remaining_latency_preroll_ = 0

When first set, it is equal to the max playback latency of all initial trigger nodes.

Definition at line 414 of file engine.h.

◆ router_

std::unique_ptr<session::DspGraphDispatcher> zrythm::engine::device_io::AudioEngine::router_

The processing graph router.

Definition at line 319 of file engine.h.

◆ run_

std::atomic_bool zrythm::engine::device_io::AudioEngine::run_ { false }

Ok to process or not.

Definition at line 395 of file engine.h.

◆ sample_processor_

std::unique_ptr<session::SampleProcessor> zrythm::engine::device_io::AudioEngine::sample_processor_

Definition at line 418 of file engine.h.

◆ setup_

bool zrythm::engine::device_io::AudioEngine::setup_ = false

Whether the engine is already set up.

Definition at line 444 of file engine.h.


The documentation for this class was generated from the following file: