33#include <unordered_map>
51 static constexpr float kVelStep = 1.0f / 16.0f;
61 if (
e.is_down && !
e.is_repeat)
68 if (
e.is_down && !
e.is_repeat)
77 const int kc =
static_cast<int>(
e.key);
81 const int note = std::clamp(base_note_ + octave_shift_ * 12 + semi, 0, 127);
86 auto it = held_.find(kc);
87 if (it != held_.end()) {
112 const int lo = -((base_note_ + 11) / 12);
113 const int hi = std::max(5, (92 - base_note_ + 11) / 12);
114 octave_shift_ = std::clamp(
s, lo, hi);
120 for (
const auto& [kc, note] : held_)
127 return !held_.empty();
176 int octave_shift_ = 0;
177 std::unordered_map<int, int> held_;
Definition musical_typing.hpp:37
int base_note() const
Definition musical_typing.hpp:44
static int semitone_for_key(KeyCode k)
QWERTY key -> semitone offset within the layout, or -1 if not a note key.
Definition musical_typing.hpp:131
bool any_held() const
Definition musical_typing.hpp:126
void all_notes_off()
Release every held note (focus loss / capture disabled).
Definition musical_typing.hpp:119
static constexpr float kVelStep
Definition musical_typing.hpp:51
float velocity
Definition musical_typing.hpp:50
int octave_shift() const
Current octave shift (in octaves; z/x decrement/increment).
Definition musical_typing.hpp:98
void set_octave_shift(int s)
Set the octave shift directly.
Definition musical_typing.hpp:111
void set_base_note(int note)
MIDI note for the first key ('a').
Definition musical_typing.hpp:41
std::function< void(int note)> on_note_off
Definition musical_typing.hpp:49
bool handle_key(const KeyEvent &e)
Feed a key event.
Definition musical_typing.hpp:56
std::function< void(int note, float velocity)> on_note_on
Definition musical_typing.hpp:48
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ kModCmd
Command (macOS) — alias for platform primary modifier.
Definition input_events.hpp:21
@ kModMeta
Windows key / Command key.
Definition input_events.hpp:20
@ kModAlt
Alt / Option.
Definition input_events.hpp:19
@ kModCtrl
Control key (Ctrl on Windows/Linux).
Definition input_events.hpp:18
KeyCode
Definition input_events.hpp:35
@ s
Definition input_events.hpp:41
@ a
Definition input_events.hpp:39
@ h
Definition input_events.hpp:39
@ l
Definition input_events.hpp:40
@ j
Definition input_events.hpp:40
@ y
Definition input_events.hpp:42
@ c
Definition input_events.hpp:39
@ apostrophe
Definition input_events.hpp:50
@ semicolon
Definition input_events.hpp:50
@ u
Definition input_events.hpp:41
@ d
Definition input_events.hpp:39
@ p
Definition input_events.hpp:40
@ k
Definition input_events.hpp:40
@ f
Definition input_events.hpp:39
@ x
Definition input_events.hpp:41
@ v
Definition input_events.hpp:41
@ g
Definition input_events.hpp:39
@ o
Definition input_events.hpp:40
@ e
Definition input_events.hpp:39
@ t
Definition input_events.hpp:41
@ w
Definition input_events.hpp:41
@ z
Definition input_events.hpp:42
Rich key event with key code, modifiers, and repeat state.
Definition input_events.hpp:193