Zrythm v2.0.0-alpha.1
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::controllers::RecordingSession< Packet > Class Template Reference

Per-track recording state with a lock-free SPSC queue. More...

#include <src/controllers/recording_session.h>

Public Types

enum class  State : uint8_t { Armed , Capturing , Finalizing }
using PacketType = Packet

Public Member Functions

 RecordingSession (units::sample_u32_t max_block_length)
void prepare_for_processing (units::sample_u32_t block_length)
 Prepares internal buffers for processing at the given block length.
void write (units::sample_t timeline_position, bool transport_recording, std::span< const float > l_data, std::span< const float > r_data) noexcept
 RT-safe: writes audio data into the ring buffer.
void write (units::sample_t timeline_position, bool transport_recording, std::span< const dsp::MidiEvent > midi_events, units::sample_u32_t nframes) noexcept
 RT-safe: writes MIDI events into the ring buffer.
std::vector< Packet > drain_pending ()
 Non-RT: drains all pending packets from the ring buffer.
auto state () const
void finalize () noexcept
 Transitions to Finalizing state, rejecting further writes.
void reset ()
 Resets the session to Armed state for reuse.
uint64_t dropped_packets () const

Static Public Attributes

static constexpr size_t kFifoCapacity = 1024

Detailed Description

template<RecordingPacket Packet>
class zrythm::controllers::RecordingSession< Packet >

Per-track recording state with a lock-free SPSC queue.

The RT thread writes packets into pre-allocated slots and pushes slot indices onto a farbot SPSC fifo. The non-RT timer drains pending indices and reads the corresponding slot data into Packet objects.

Template Parameters
PacketThe packet type (RecordingAudioPacket or RecordingMidiPacket). Must provide static copy_from(slot, source) and resize(slot, block_length).

Thread contracts:

  • write(): audio thread only (single producer)
  • drain_pending(): timer thread only (single consumer)
  • finalize(): any thread (atomic flag — safe during active writes)
  • reset(): any thread (must not overlap with write/drain)

Definition at line 43 of file recording_session.h.

Member Typedef Documentation

◆ PacketType

template<RecordingPacket Packet>
using zrythm::controllers::RecordingSession< Packet >::PacketType = Packet

Definition at line 60 of file recording_session.h.

Member Enumeration Documentation

◆ State

template<RecordingPacket Packet>
enum class zrythm::controllers::RecordingSession::State : uint8_t
strong

Definition at line 46 of file recording_session.h.

Member Function Documentation

◆ drain_pending()

template<RecordingPacket Packet>
std::vector< Packet > zrythm::controllers::RecordingSession< Packet >::drain_pending ( )
nodiscard

Non-RT: drains all pending packets from the ring buffer.

Called from the timer thread. Reads slot indices from the SPSC fifo and copies the slot data into Packet objects.

◆ dropped_packets()

template<RecordingPacket Packet>
uint64_t zrythm::controllers::RecordingSession< Packet >::dropped_packets ( ) const
inlinenodiscard

Definition at line 119 of file recording_session.h.

◆ prepare_for_processing()

template<RecordingPacket Packet>
void zrythm::controllers::RecordingSession< Packet >::prepare_for_processing ( units::sample_u32_t block_length)

Prepares internal buffers for processing at the given block length.

Must be called before audio processing starts (not concurrently with write() or drain_pending()).

◆ state()

template<RecordingPacket Packet>
auto zrythm::controllers::RecordingSession< Packet >::state ( ) const
inlinenodiscard

Definition at line 104 of file recording_session.h.

◆ write() [1/2]

template<RecordingPacket Packet>
void zrythm::controllers::RecordingSession< Packet >::write ( units::sample_t timeline_position,
bool transport_recording,
std::span< const dsp::MidiEvent > midi_events,
units::sample_u32_t nframes )
noexcept

RT-safe: writes MIDI events into the ring buffer.

Called from the audio thread. No allocations — copies events into pre-allocated slot memory and pushes the slot index onto the SPSC fifo.

◆ write() [2/2]

template<RecordingPacket Packet>
void zrythm::controllers::RecordingSession< Packet >::write ( units::sample_t timeline_position,
bool transport_recording,
std::span< const float > l_data,
std::span< const float > r_data )
noexcept

RT-safe: writes audio data into the ring buffer.

Called from the audio thread. No allocations — copies data into pre-allocated slot memory and pushes the slot index onto the SPSC fifo.

Field Documentation

◆ kFifoCapacity

template<RecordingPacket Packet>
size_t zrythm::controllers::RecordingSession< Packet >::kFifoCapacity = 1024
staticconstexpr

Definition at line 58 of file recording_session.h.


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