34 [[nodiscard]]
int channel() const noexcept;
35 [[nodiscard]]
int note() const noexcept;
36 [[nodiscard]]
int velocity() const noexcept;
91 [[nodiscard]]
int capacity() const noexcept {
return capacity_; }
94 [[nodiscard]]
bool grows() const noexcept {
return growing_; }
97 [[nodiscard]]
int high_water() const noexcept {
return high_water_; }
105 [[nodiscard]]
int steal_count() const noexcept {
return steal_count_; }
108 [[nodiscard]]
int growth_count() const noexcept {
return growth_count_; }
116 return steal_count_ > 0 || growth_count_ > 0;
145 return state_[
static_cast<std::size_t
>(index)];
150 return channel_[
static_cast<std::size_t
>(index)];
153 [[nodiscard]]
int note_of(
int index)
const noexcept
155 return note_[
static_cast<std::size_t
>(index)];
160 return velocity_[
static_cast<std::size_t
>(index)];
165 return note_group_[
static_cast<std::size_t
>(index)];
169 [[nodiscard]]
int find_free() const noexcept;
170 [[nodiscard]]
int find_oldest(
VoiceState state) const noexcept;
171 void steal_group(
int note_group,
int except);
174 [[nodiscard]]
int grow();
179 std::vector<
int> channel_;
180 std::vector<
int> note_;
181 std::vector<
int> velocity_;
182 std::vector<
int> note_group_;
183 std::vector<std::int64_t> sequence_;
185 int steal_count_ = 0;
186 int growth_count_ = 0;
189 bool growing_ = false;
190 std::int64_t counter_ = 0;
191 int next_note_group_ = 0;
The voice allocator.
Definition voice_pool.hpp:55
int steal_count() const noexcept
How many times a sounding voice was taken to make room.
Definition voice_pool.hpp:105
void reset() noexcept
Frees every voice immediately.
std::vector< Voice > active() const
The sounding voices.
bool grows() const noexcept
Whether this pool grows rather than steals.
Definition voice_pool.hpp:94
VoicePool(int polyphony, bool growing)
Creates a pool with a given polyphony, optionally allowed to grow past it.
int growth_count() const noexcept
How many times a growing pool allocated another chunk.
Definition voice_pool.hpp:108
VoicePool()
Creates a pool with the hardware's polyphony.
Definition voice_pool.hpp:79
int high_water() const noexcept
The largest capacity reached, which is what a growing render actually needed.
Definition voice_pool.hpp:97
std::function< void(int)> stealing
Called with the index of each slot taken from a sounding note, before it is reassigned.
Definition voice_pool.hpp:76
int begin_note_group() noexcept
Starts a new note group, to be shared by that note's partials.
Definition voice_pool.hpp:123
int note_of(int index) const noexcept
Definition voice_pool.hpp:153
int capacity() const noexcept
How many slots exist now. A growing pool's capacity rises during a render.
Definition voice_pool.hpp:91
int channel_of(int index) const noexcept
Definition voice_pool.hpp:148
int velocity_of(int index) const noexcept
Definition voice_pool.hpp:158
int release(int channel, int note) noexcept
Moves every held voice for a note into its release, and reports how many.
static constexpr int growth_chunk
How many slots a growing pool adds each time it would otherwise steal.
Definition voice_pool.hpp:67
static constexpr int group_size
Voices are rendered in groups of this size; the engine's layout is SIMD-shaped.
Definition voice_pool.hpp:70
void free_slot(int index) noexcept
Frees a voice whose release has finished.
Definition voice_pool.hpp:132
Voice allocate(int channel, int note, int velocity, int note_group)
Allocates one voice, stealing if necessary.
int active_count() const noexcept
Number of slots currently sounding.
static constexpr int default_polyphony
The hardware's polyphony, and this pool's default.
Definition voice_pool.hpp:58
static constexpr int max_voices
Kept as the name the rest of the engine sizes its scratch by.
Definition voice_pool.hpp:61
VoiceState state_of(int index) const noexcept
Definition voice_pool.hpp:143
int note_group_of(int index) const noexcept
Definition voice_pool.hpp:163
bool limit_was_reached() const noexcept
Whether this render's output depends on the polyphony setting.
Definition voice_pool.hpp:114
Definition control_decode.hpp:7
VoiceState
What a voice slot is currently doing.
Definition voice_pool.hpp:11
@ held
Sounding with the key still down.
Definition voice_pool.hpp:15
@ releasing
Sounding through its release after note-off.
Definition voice_pool.hpp:17
@ free
Unused and available.
Definition voice_pool.hpp:13
@ channel
A channel voice message.
Definition smf_reader.hpp:15
A handle to one voice slot: an index into the pool's parallel arrays plus the control-rate operations...
Definition voice_pool.hpp:29
int note_group() const noexcept
The note group this voice belongs to; partials of one note share it.
Definition voice_pool.hpp:214
bool is_active() const noexcept
Definition voice_pool.hpp:40
VoiceState state() const noexcept
Definition voice_pool.hpp:194
int note() const noexcept
Definition voice_pool.hpp:204
int channel() const noexcept
Definition voice_pool.hpp:199
int index
Definition voice_pool.hpp:31
const VoicePool * pool
Definition voice_pool.hpp:30
int velocity() const noexcept
Definition voice_pool.hpp:209