Zrythm v2.0.0-DEV
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{
16{
17public:
18 enum class PlayState : std::uint8_t
19 {
20 RollRequested,
21 Rolling,
22 PauseRequested,
23 Paused
24 };
25
26public:
27 virtual ~ITransport () = default;
28
32 virtual std::pair<units::sample_t, units::sample_t>
33 get_loop_range_positions () const noexcept [[clang::nonblocking]] = 0;
34
38 virtual std::pair<units::sample_t, units::sample_t>
39 get_punch_range_positions () const noexcept [[clang::nonblocking]] = 0;
40
41 virtual PlayState get_play_state () const noexcept [[clang::nonblocking]] = 0;
42
48 virtual units::sample_t
50 [[clang::nonblocking]] = 0;
51
59 const units::sample_t current_playhead_position,
60 const units::sample_t frames_to_add) const noexcept [[clang::nonblocking]]
61 {
62 auto new_pos = current_playhead_position + frames_to_add;
63
64 /* if start frames were before the loop-end point and the new frames are
65 * after (loop crossed) */
66 if (loop_enabled ())
67 {
68 const auto loop_points = get_loop_range_positions ();
69 const auto loop_start = loop_points.first;
70 const auto loop_end = loop_points.second;
71 while (current_playhead_position < loop_end && new_pos >= loop_end)
72 {
73 /* adjust the new frames */
74 new_pos += loop_start - loop_end;
75 }
76 }
77
78 return new_pos;
79 }
80
81 virtual bool loop_enabled () const noexcept [[clang::nonblocking]] = 0;
82
83 virtual bool punch_enabled () const noexcept [[clang::nonblocking]] = 0;
84
88 virtual bool recording_enabled () const noexcept [[clang::nonblocking]] = 0;
89
97 virtual units::sample_t recording_preroll_frames_remaining () const noexcept
98 [[clang::nonblocking]] = 0;
99
100 bool
101 has_recording_preroll_frames_remaining () const noexcept [[clang::nonblocking]]
102 {
103 return recording_preroll_frames_remaining () > units::samples (0);
104 }
105
111 virtual units::sample_t metronome_countin_frames_remaining () const noexcept
112 [[clang::nonblocking]] = 0;
113
120 units::sample_t g_start_frames,
121 units::sample_t nframes) const noexcept [[clang::nonblocking]]
122 {
123 auto [loop_start_pos, loop_end_pos] = get_loop_range_positions ();
124 bool loop_end_between_start_and_end =
125 (loop_end_pos > g_start_frames && loop_end_pos <= g_start_frames + nframes);
126
127 if (loop_end_between_start_and_end && loop_enabled ()) [[unlikely]]
128 {
129 return loop_end_pos - g_start_frames;
130 }
131 return units::samples (0);
132 }
133};
134
135} // namespace zrythm::dsp
Interface for transport.
Definition itransport.h:16
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:58
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:119
virtual units::sample_t metronome_countin_frames_remaining() const noexcept=0
Frames remaining for metronome countin.