Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
itransport.h
1// SPDX-FileCopyrightText: © 2024 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <cstdint>
7
8#include "utils/types.h"
9#include "utils/units.h"
10
11namespace zrythm::dsp
12{
17{
18public:
19 enum class PlayState : std::uint8_t
20 {
21 RollRequested,
22 Rolling,
23 PauseRequested,
24 Paused
25 };
26
27public:
28 virtual ~ITransport () = default;
29
33 virtual std::pair<units::sample_t, units::sample_t>
34 get_loop_range_positions () const noexcept [[clang::nonblocking]] = 0;
35
39 virtual std::pair<units::sample_t, units::sample_t>
40 get_punch_range_positions () const noexcept [[clang::nonblocking]] = 0;
41
42 virtual PlayState get_play_state () const noexcept [[clang::nonblocking]] = 0;
43
49 virtual units::sample_t
51 [[clang::nonblocking]] = 0;
52
60 const units::sample_t current_playhead_position,
61 const units::sample_t frames_to_add) const noexcept [[clang::nonblocking]]
62 {
63 auto new_pos = current_playhead_position + frames_to_add;
64
65 /* if start frames were before the loop-end point and the new frames are
66 * after (loop crossed) */
67 if (loop_enabled ())
68 {
69 const auto loop_points = get_loop_range_positions ();
70 const auto loop_start = loop_points.first;
71 const auto loop_end = loop_points.second;
72 while (current_playhead_position < loop_end && new_pos >= loop_end)
73 {
74 /* adjust the new frames */
75 new_pos += loop_start - loop_end;
76 }
77 }
78
79 return new_pos;
80 }
81
82 virtual bool loop_enabled () const noexcept [[clang::nonblocking]] = 0;
83
84 virtual bool punch_enabled () const noexcept [[clang::nonblocking]] = 0;
85
89 virtual bool recording_enabled () const noexcept [[clang::nonblocking]] = 0;
90
98 virtual units::sample_t recording_preroll_frames_remaining () const noexcept
99 [[clang::nonblocking]] = 0;
100
101 bool
102 has_recording_preroll_frames_remaining () const noexcept [[clang::nonblocking]]
103 {
104 return recording_preroll_frames_remaining () > units::samples (0);
105 }
106
112 virtual units::sample_t metronome_countin_frames_remaining () const noexcept
113 [[clang::nonblocking]] = 0;
114
121 units::sample_t g_start_frames,
122 units::sample_t nframes) const noexcept [[clang::nonblocking]]
123 {
124 auto [loop_start_pos, loop_end_pos] = get_loop_range_positions ();
125 bool loop_end_between_start_and_end =
126 (loop_end_pos > g_start_frames && loop_end_pos <= g_start_frames + nframes);
127
128 if (loop_end_between_start_and_end && loop_enabled ()) [[unlikely]]
129 {
130 return loop_end_pos - g_start_frames;
131 }
132 return units::samples (0);
133 }
134};
135
136} // namespace zrythm::dsp
Interface for transport.
Definition itransport.h:17
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:59
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:120
virtual units::sample_t metronome_countin_frames_remaining() const noexcept=0
Frames remaining for metronome countin.