Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
note_renderer.hpp
Go to the documentation of this file.
1#pragma once
2
9
10#include <array>
11#include <cstddef>
12#include <cstdint>
13
14namespace pulp::playback {
15
16namespace detail {
17
22 timebase::SamplePosition range_start,
23 std::uint32_t frame_count,
24 std::uint32_t& offset) noexcept {
25 if (event < range_start) return false;
26 const auto delta = static_cast<std::uint64_t>(event.value) -
27 static_cast<std::uint64_t>(range_start.value);
28 if (delta >= frame_count) return false;
29 offset = static_cast<std::uint32_t>(delta);
30 return true;
31}
32
33} // namespace detail
34
50
63
78 public:
81 static constexpr std::uint16_t maximum_logical_overlap = 255;
84
85 explicit ArrangementNoteRenderer(timeline::ItemId track_id) noexcept
86 : shell_(track_id) {
87 output_.attach_ump(&ump_output_);
88 }
89
90 bool prepare(std::size_t maximum_events_per_block);
92 const TransportSnapshot& transport) noexcept;
104 const TransportSnapshot& transport,
105 EventCompensationShift requested_shift) noexcept;
108 return latched_shift_;
109 }
110
111 const midi::MidiBuffer& events() const noexcept { return output_; }
112 RendererProgramKey active_key() const noexcept { return shell_.active_key(); }
113 bool has_active_notes() const noexcept;
114 void reset() noexcept;
115
116 private:
117 static constexpr std::size_t kMidiKeyCount = 16u * 128u;
118
119 NoteRenderResult process_shifted(const PlaybackProgramBlock& block,
120 const TransportSnapshot& transport,
121 EventCompensationShift shift) noexcept;
122 bool emit(const NoteProgramEvent& event, std::uint32_t sample_offset) noexcept;
123 bool append_physical(midi::MidiEvent midi1, midi::UmpPacket midi2,
124 std::uint32_t sample_offset) noexcept;
125 bool flush(std::uint32_t sample_offset) noexcept;
126 void record_output_drop() noexcept;
127 void update_carry_state(const TransportSnapshot& transport,
128 std::int64_t event_cursor) noexcept;
129
130 StableRendererShell shell_;
131 midi::MidiBuffer output_;
132 midi::UmpBuffer ump_output_;
133 std::array<std::uint16_t, kMidiKeyCount> active_counts_{};
134 bool prepared_ = false;
135 bool pending_flush_ = false;
136 bool state_overflow_ = false;
137 bool has_block_index_ = false;
138 bool has_latched_shift_ = false;
143 bool has_stream_pass_ = false;
144 std::uint64_t last_stream_pass_ = 0;
145 std::uint64_t last_stream_epoch_ = 0;
146 EventCompensationShift latched_shift_{};
147 std::uint64_t last_block_index_ = 0;
148 std::uint32_t dropped_events_ = 0;
149};
150
151} // namespace pulp::playback
Collection of timestamped MIDI events within a single audio buffer period.
Definition buffer.hpp:31
NoteRenderResult process(const PlaybackProgramBlock &block, const TransportSnapshot &transport, EventCompensationShift requested_shift) noexcept
Schedules against requested_shift samples ahead of each transport range, so a chain that delays the e...
static constexpr std::uint16_t maximum_logical_overlap
Bounded logical overlap depth per MIDI channel/pitch.
Definition note_renderer.hpp:81
const midi::MidiBuffer & events() const noexcept
Definition note_renderer.hpp:111
NoteRenderResult process(const PlaybackProgramBlock &block, const TransportSnapshot &transport) noexcept
static constexpr audio::RtSafetyClass process_rt_safety_class
Definition note_renderer.hpp:82
bool has_active_notes() const noexcept
RendererProgramKey active_key() const noexcept
Definition note_renderer.hpp:112
bool prepare(std::size_t maximum_events_per_block)
EventCompensationShift applied_shift() const noexcept
The shift currently latched for scheduling.
Definition note_renderer.hpp:107
ArrangementNoteRenderer(timeline::ItemId track_id) noexcept
Definition note_renderer.hpp:85
Definition stable_renderer_shell.hpp:22
Definition stable_renderer_shell.hpp:59
RtSafetyClass
Definition rt_safety_contract.hpp:11
@ AudioCallbackSafeAfterPrepare
Definition rt_safety_contract.hpp:13
Definition custom_node_events.hpp:26
Definition automation_program.hpp:17
constexpr bool note_event_offset_in_range(timebase::SamplePosition event, timebase::SamplePosition range_start, std::uint32_t frame_count, std::uint32_t &offset) noexcept
Computes a block-local offset without signed overflow.
Definition note_renderer.hpp:21
Definition audio_renderer.hpp:20
ShellAdoptionResult
Definition stable_renderer_shell.hpp:52
@ Missing
Definition stable_renderer_shell.hpp:52
@ InvalidTransport
Definition audio_renderer.hpp:218
@ NotPrepared
Definition automation_recording.hpp:30
NoteRenderCode
Definition note_renderer.hpp:35
@ MissingProgram
Definition note_renderer.hpp:38
@ ActiveStateOverflow
Definition note_renderer.hpp:42
@ Ok
Definition note_renderer.hpp:36
@ CompensationUnsupported
A compensating shift met a range that locates events by host beat.
Definition note_renderer.hpp:48
@ TempoMapMismatch
Definition automation_cursor.hpp:33
@ AdoptionRejected
Definition automation_cursor.hpp:31
@ Ok
Definition automation_cursor.hpp:29
@ OutputOverflow
Definition external_sync.hpp:99
STL namespace.
One event-injection point's prepared scheduling shift, counted in samples at the program's compiled s...
Definition event_compensation.hpp:33
Immutable arrangement-note event lowered by the program compiler.
Definition program.hpp:70
Definition note_renderer.hpp:51
EventCompensationShift applied_shift
The shift this block actually scheduled against, which is the latched value and not necessarily the o...
Definition note_renderer.hpp:58
ShellAdoptionResult adoption
Definition note_renderer.hpp:53
std::uint32_t emitted_events
Definition note_renderer.hpp:54
NoteRenderCode code
Definition note_renderer.hpp:52
std::uint32_t dropped_events
Definition note_renderer.hpp:55
bool shift_relatch_pending
True while a requested shift differs from the latched one and playback is holding the older alignment...
Definition note_renderer.hpp:61
Definition program_identity.hpp:12
Definition transport.hpp:71
Definition rational_time.hpp:9
Nonzero monotonic identity for a Timeline-owned object.
Definition item_id.hpp:19
Sample-accurate MIDI 2.0 UMP packet stream.