Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
audio_recording_session.h
1// SPDX-FileCopyrightText: © 2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <atomic>
7#include <memory>
8#include <span>
9#include <vector>
10
11#include "utils/units.h"
12
13#include <QtClassHelperMacros>
14
15namespace zrythm::controllers
16{
17
22{
23 units::sample_t timeline_position;
24 bool transport_recording{};
25 units::sample_u32_t nframes;
26 std::vector<float> l_frames;
27 std::vector<float> r_frames;
28};
29
43class AudioRecordingSession
44{
45public:
46 enum class State : uint8_t
47 {
48 Armed,
49 Capturing,
50 Finalizing,
51 };
52
53 explicit AudioRecordingSession (units::sample_u32_t max_block_length);
54 ~AudioRecordingSession ();
55
56 Q_DISABLE_COPY_MOVE (AudioRecordingSession)
57
58 static constexpr size_t kFifoCapacity = 1024;
59
68 void prepare_for_processing (units::sample_u32_t block_length);
69
81 units::sample_t timeline_position,
82 bool transport_recording,
83 std::span<const float> l_data,
84 std::span<const float> r_data) noexcept [[clang::nonblocking]];
85
92 [[nodiscard]] std::vector<RecordingAudioPacket>
93 drain_pending () [[clang::blocking]];
94
95 [[nodiscard]] auto state () const
96 {
97 return state_.load (std::memory_order_acquire);
98 }
99
107 void finalize () noexcept;
108
115 void reset ();
116
120 [[nodiscard]] uint64_t dropped_packets () const
121 {
122 return dropped_packets_.load (std::memory_order_relaxed);
123 }
124
125private:
126 struct Impl;
127 std::unique_ptr<Impl> impl_;
128
129 std::atomic<State> state_{ State::Armed };
130 std::atomic<uint64_t> dropped_packets_{ 0 };
131};
132
133}
void finalize() noexcept
Transitions to Finalizing state, rejecting further writes.
uint64_t dropped_packets() const
Returns the number of packets dropped due to fifo overflow.
void reset()
Resets the session to Armed state for reuse.
void prepare_for_processing(units::sample_u32_t block_length)
Prepares internal buffers for processing at the given block length.
std::vector< RecordingAudioPacket > drain_pending()
Non-RT: drains all pending packets from the ring buffer.
void write_samples(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.
A single packet of recorded audio data transferred from RT to non-RT.