Tracks the state of all 128 MIDI keys across 16 channels.
More...
#include <keyboard_state.hpp>
|
| void | process (const MidiEvent &event) |
| | Process a MIDI event.
|
| bool | is_note_on (uint8_t channel, uint8_t note) const |
| | Check if a specific note is currently held on a channel.
|
| uint8_t | velocity (uint8_t channel, uint8_t note) const |
| | Get the velocity of a held note (0 if not held).
|
| int | notes_held (uint8_t channel) const |
| | Count how many notes are currently held on a channel.
|
| int | total_notes_held () const |
| | Count total notes held across all channels.
|
| bool | any_notes_held () const |
| | Check if any note is held on any channel.
|
| int | lowest_note (uint8_t channel) const |
| | Get the lowest held note on a channel (-1 if none).
|
| int | highest_note (uint8_t channel) const |
| | Get the highest held note on a channel (-1 if none).
|
| void | all_notes_off () |
| | Release all notes on all channels.
|
| void | all_notes_off (uint8_t channel) |
| | Release all notes on a specific channel.
|
| void | reset () |
| | Reset all state without firing callbacks.
|
|
| std::function< void(uint8_t channel, uint8_t note, uint8_t velocity)> | on_note_on |
| | Called when a note turns on.
|
| std::function< void(uint8_t channel, uint8_t note)> | on_note_off |
| | Called when a note turns off.
|
Tracks the state of all 128 MIDI keys across 16 channels.
Processes note on/off events and maintains per-key velocity. Optional listeners are called on state changes for UI updates (e.g. on-screen keyboard highlighting).
keys.
on_note_on = [&](uint8_t ch, uint8_t note, uint8_t vel) {
highlight_key(note, true);
};
highlight_key(note, false);
};
for (
auto& event : midi_buffer) keys.
process(event);
Tracks the state of all 128 MIDI keys across 16 channels.
Definition keyboard_state.hpp:35
std::function< void(uint8_t channel, uint8_t note)> on_note_off
Called when a note turns off.
Definition keyboard_state.hpp:40
std::function< void(uint8_t channel, uint8_t note, uint8_t velocity)> on_note_on
Called when a note turns on.
Definition keyboard_state.hpp:38
void process(const MidiEvent &event)
Process a MIDI event.
Definition keyboard_state.hpp:46
bool is_note_on(uint8_t channel, uint8_t note) const
Check if a specific note is currently held on a channel.
Definition keyboard_state.hpp:75
◆ all_notes_off() [1/2]
| void pulp::midi::MidiKeyboardState::all_notes_off |
( |
| ) |
|
|
inline |
Release all notes on all channels.
◆ all_notes_off() [2/2]
| void pulp::midi::MidiKeyboardState::all_notes_off |
( |
uint8_t | channel | ) |
|
|
inline |
Release all notes on a specific channel.
◆ any_notes_held()
| bool pulp::midi::MidiKeyboardState::any_notes_held |
( |
| ) |
const |
|
inline |
Check if any note is held on any channel.
◆ highest_note()
| int pulp::midi::MidiKeyboardState::highest_note |
( |
uint8_t | channel | ) |
const |
|
inline |
Get the highest held note on a channel (-1 if none).
◆ is_note_on()
| bool pulp::midi::MidiKeyboardState::is_note_on |
( |
uint8_t | channel, |
|
|
uint8_t | note ) const |
|
inline |
Check if a specific note is currently held on a channel.
◆ lowest_note()
| int pulp::midi::MidiKeyboardState::lowest_note |
( |
uint8_t | channel | ) |
const |
|
inline |
Get the lowest held note on a channel (-1 if none).
◆ notes_held()
| int pulp::midi::MidiKeyboardState::notes_held |
( |
uint8_t | channel | ) |
const |
|
inline |
Count how many notes are currently held on a channel.
◆ process()
| void pulp::midi::MidiKeyboardState::process |
( |
const MidiEvent & | event | ) |
|
|
inline |
Process a MIDI event.
Note on/off are tracked, and the channel mode messages All Sound Off (CC 120) and All Notes Off (CC 123) release every held note on their channel, firing on_note_off for each, so a panic from a controller cannot leave keys stuck on in a display.
◆ reset()
| void pulp::midi::MidiKeyboardState::reset |
( |
| ) |
|
|
inline |
Reset all state without firing callbacks.
◆ total_notes_held()
| int pulp::midi::MidiKeyboardState::total_notes_held |
( |
| ) |
const |
|
inline |
Count total notes held across all channels.
◆ velocity()
| uint8_t pulp::midi::MidiKeyboardState::velocity |
( |
uint8_t | channel, |
|
|
uint8_t | note ) const |
|
inline |
Get the velocity of a held note (0 if not held).
◆ on_note_off
| std::function<void(uint8_t channel, uint8_t note)> pulp::midi::MidiKeyboardState::on_note_off |
Called when a note turns off.
◆ on_note_on
| std::function<void(uint8_t channel, uint8_t note, uint8_t velocity)> pulp::midi::MidiKeyboardState::on_note_on |
Called when a note turns on.
The documentation for this class was generated from the following file: