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

Orchestrates the recording lifecycle across all armed tracks. More...

#include <src/controllers/recording_coordinator.h>

Inheritance diagram for zrythm::controllers::RecordingCoordinator:
Collaboration diagram for zrythm::controllers::RecordingCoordinator:

Signals

void audioDataReady (structure::tracks::TrackUuid track_id, std::vector< RecordingAudioPacket > packets)
 Emitted when recorded audio data has been drained from a session.
void recordingSessionEnded ()
 Emitted when a recording take has been finalized.

Public Member Functions

 RecordingCoordinator (QObject *parent=nullptr)
void arm_track (structure::tracks::TrackUuid track_id, units::sample_u32_t max_block_length)
 Arms a track for recording.
void disarm_track (structure::tracks::TrackUuid track_id)
 Disarms a track.
bool has_session (structure::tracks::TrackUuid track_id) const
 Returns whether a session exists for the given track.
void process_pending ()
 Drains all active sessions and processes pending deletions.
Q_SLOT void finalizeAllSessions ()
 Finalizes the current recording take and resets sessions for reuse.
AudioRecordingSessionsession_for_track (structure::tracks::TrackUuid track_id) const noexcept
 Gets the session for a track (for RT callback access).
void prepare_for_processing (units::sample_u32_t block_length)
 Prepares all active sessions for processing at the given block length.

Static Public Attributes

static constexpr auto kDrainInterval = std::chrono::milliseconds (100)

Detailed Description

Orchestrates the recording lifecycle across all armed tracks.

Owns per-track AudioRecordingSession objects and runs a periodic timer that drains recorded audio from each session's ring buffer for region creation.

Thread Safety

Session access from RT threads is mediated by an atomic snapshot pointer (rt_snapshot_). The non-RT thread publishes new snapshots via atomic exchange after arm/disarm operations; RT threads read via atomic load. This guarantees lock-free, allocation-free RT reads and supports multiple concurrent RT readers (the DSP graph processes nodes in parallel).

Old snapshots are deferred: publish_snapshot() moves the previous snapshot to a pending-deletion list. process_pending() clears that list, which runs at least kDrainInterval (100 ms) after the last publish. Since audio callbacks complete in ~1-10 ms, all RT threads have long since loaded a newer snapshot before any old snapshot is destroyed.

Note
process_pending() may be called manually only when it is guaranteed that no RT processing is occurring simultaneously (e.g., when the audio engine is stopped). Otherwise, pending snapshots could be destroyed while an RT thread still holds a pointer.

Definition at line 45 of file recording_coordinator.h.

Member Function Documentation

◆ arm_track()

void zrythm::controllers::RecordingCoordinator::arm_track ( structure::tracks::TrackUuid track_id,
units::sample_u32_t max_block_length )

Arms a track for recording.

Creates an AudioRecordingSession.

Must be called from the non-RT thread.

◆ audioDataReady

void zrythm::controllers::RecordingCoordinator::audioDataReady ( structure::tracks::TrackUuid track_id,
std::vector< RecordingAudioPacket > packets )
signal

Emitted when recorded audio data has been drained from a session.

Connected consumers (e.g. RecordingMaterializer) use this to create or expand regions from the recorded audio packets.

◆ disarm_track()

void zrythm::controllers::RecordingCoordinator::disarm_track ( structure::tracks::TrackUuid track_id)

Disarms a track.

Moves session to pending deletion.

Must be called from the non-RT thread.

◆ finalizeAllSessions()

Q_SLOT void zrythm::controllers::RecordingCoordinator::finalizeAllSessions ( )

Finalizes the current recording take and resets sessions for reuse.

Drains all pending audio data from active sessions, emits audioDataReady for each track with data, then emits recordingSessionEnded to finalize the undo macro. Sessions are reset to Armed state rather than destroyed, so they accept new writes when recording resumes (e.g., after transport restart).

Intended to be called when transport stops. Sessions are only destroyed via disarm_track().

Must be called from the non-RT thread.

◆ has_session()

bool zrythm::controllers::RecordingCoordinator::has_session ( structure::tracks::TrackUuid track_id) const
nodiscard

Returns whether a session exists for the given track.

Must be called from the same non-RT thread as arm_track()/disarm_track().

◆ prepare_for_processing()

void zrythm::controllers::RecordingCoordinator::prepare_for_processing ( units::sample_u32_t block_length)

Prepares all active sessions for processing at the given block length.

Buffers are only grown, never shrunk. Must be called before audio processing starts (not concurrently with write_samples() or drain_pending()).

◆ process_pending()

void zrythm::controllers::RecordingCoordinator::process_pending ( )

Drains all active sessions and processes pending deletions.

Called by the internal timer. May be called manually only when no RT processing is occurring simultaneously (e.g., engine stopped).

◆ recordingSessionEnded

void zrythm::controllers::RecordingCoordinator::recordingSessionEnded ( )
signal

Emitted when a recording take has been finalized.

Fires from finalizeAllSessions() after all pending audio data is drained and sessions are reset to Armed state. Consumers should finalize any open recording context (e.g. closing an undo macro) when this signal is received — no more audio data will arrive for this take. Sessions remain alive and can accept new writes when recording resumes.

◆ session_for_track()

AudioRecordingSession * zrythm::controllers::RecordingCoordinator::session_for_track ( structure::tracks::TrackUuid track_id) const
nodiscardnoexcept

Gets the session for a track (for RT callback access).

Safe to call from multiple RT threads concurrently. Returns nullptr if no session exists.

Field Documentation

◆ kDrainInterval

auto zrythm::controllers::RecordingCoordinator::kDrainInterval = std::chrono::milliseconds (100)
staticconstexpr

Definition at line 50 of file recording_coordinator.h.


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