Zrythm v2.0.0-alpha.1
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
itransport.h
1// SPDX-FileCopyrightText: © 2024-2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <cstdint>
7
8#include "utils/units.h"
9
10namespace zrythm::dsp
11{
19inline units::sample_t
20playhead_position_after_adding_frames (
21 units::sample_t current_position,
22 units::sample_t frames_to_add,
23 bool loop_enabled,
24 units::sample_t loop_start,
25 units::sample_t loop_end) noexcept
26{
27 auto new_pos = current_position + frames_to_add;
28
29 /* if start frames were before the loop-end point and the new frames are
30 * after (loop crossed) */
31 if (loop_enabled)
32 {
33 while (current_position < loop_end && new_pos >= loop_end)
34 {
35 /* adjust the new frames */
36 new_pos += loop_start - loop_end;
37 }
38 }
39
40 return new_pos;
41}
42
47{
48public:
49 enum class PlayState : std::uint8_t
50 {
51 RollRequested,
52 Rolling,
53 PauseRequested,
54 Paused
55 };
56
57public:
58 virtual ~ITransport () = default;
59
63 virtual std::pair<units::sample_t, units::sample_t>
64 get_loop_range_positions () const noexcept [[clang::nonblocking]] = 0;
65
69 virtual std::pair<units::sample_t, units::sample_t>
70 get_punch_range_positions () const noexcept [[clang::nonblocking]] = 0;
71
72 virtual PlayState get_play_state () const noexcept [[clang::nonblocking]] = 0;
73
79 virtual units::sample_t
81 [[clang::nonblocking]] = 0;
82
90 const units::sample_t current_playhead_position,
91 const units::sample_t frames_to_add) const noexcept [[clang::nonblocking]]
92 {
93 const auto [loop_start, loop_end] = get_loop_range_positions ();
94 return playhead_position_after_adding_frames (
95 current_playhead_position, frames_to_add, loop_enabled (), loop_start,
96 loop_end);
97 }
98
99 virtual bool loop_enabled () const noexcept [[clang::nonblocking]] = 0;
100
101 virtual bool punch_enabled () const noexcept [[clang::nonblocking]] = 0;
102
106 virtual bool recording_enabled () const noexcept [[clang::nonblocking]] = 0;
107
115 virtual units::sample_t recording_preroll_frames_remaining () const noexcept
116 [[clang::nonblocking]] = 0;
117
118 bool
119 has_recording_preroll_frames_remaining () const noexcept [[clang::nonblocking]]
120 {
121 return recording_preroll_frames_remaining () > units::samples (0);
122 }
123
129 virtual units::sample_t metronome_countin_frames_remaining () const noexcept
130 [[clang::nonblocking]] = 0;
131
138 units::sample_t g_start_frames,
139 units::sample_t nframes) const noexcept [[clang::nonblocking]]
140 {
141 auto [loop_start_pos, loop_end_pos] = get_loop_range_positions ();
142 bool loop_end_between_start_and_end =
143 (loop_end_pos > g_start_frames && loop_end_pos <= g_start_frames + nframes);
144
145 if (loop_end_between_start_and_end && loop_enabled ()) [[unlikely]]
146 {
147 return loop_end_pos - g_start_frames;
148 }
149 return units::samples (0);
150 }
151};
152
153} // namespace zrythm::dsp
Interface for transport.
Definition itransport.h:47
virtual units::sample_t recording_preroll_frames_remaining() const noexcept=0
Frames remaining to preroll (playing back some time earlier before actually recording/rolling).
units::sample_t get_playhead_position_after_adding_frames_in_audio_thread(const units::sample_t current_playhead_position, const units::sample_t frames_to_add) const noexcept
Gets the playhead position, similarly to get_playhead_position(), except that it adjusts the new posi...
Definition itransport.h:89
virtual bool recording_enabled() const noexcept=0
Returns whether recording is enabled.
virtual std::pair< units::sample_t, units::sample_t > get_loop_range_positions() const noexcept=0
Returns the loop range positions in samples.
virtual std::pair< units::sample_t, units::sample_t > get_punch_range_positions() const noexcept=0
Returns the punch recording range positions in samples.
virtual units::sample_t get_playhead_position_in_audio_thread() const noexcept=0
Get the playhead position.
units::sample_t is_loop_point_met_in_audio_thread(units::sample_t g_start_frames, units::sample_t nframes) const noexcept
Returns the number of processable frames until and excluding the loop end point as a positive number ...
Definition itransport.h:137
virtual units::sample_t metronome_countin_frames_remaining() const noexcept=0
Frames remaining for metronome countin.