MCPcopy Create free account
hub / github.com/VCVRack/Rack / onKeyPress

Method onKeyPress

src/keyboard.cpp:122–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120 }
121
122 void onKeyPress(int key) {
123 // Do nothing if no ports are subscribed
124 if (subscribed.empty())
125 return;
126 const auto& keyMap = deviceInfos[deviceId].keyMap;
127 auto it = keyMap.find(key);
128 if (it == keyMap.end())
129 return;
130 int note = it->second;
131
132 if (note < 0) {
133 if (note == CMD_OCTAVE_DOWN)
134 octave--;
135 else if (note == CMD_OCTAVE_UP)
136 octave++;
137 octave = math::clamp(octave, 0, 9);
138 return;
139 }
140
141 note += 12 * octave;
142 if (note > 127)
143 return;
144
145 // MIDI note on
146 midi::Message msg;
147 msg.setStatus(0x9);
148 msg.setNote(note);
149 msg.setValue(127);
150 onMessage(msg);
151
152 pressedNotes[key] = note;
153 }
154
155 void onKeyRelease(int key) {
156 // Do nothing if no ports are subscribed

Callers

nothing calls this directly

Calls 5

setStatusMethod · 0.80
setNoteMethod · 0.80
clampFunction · 0.70
emptyMethod · 0.45
setValueMethod · 0.45

Tested by

no test coverage detected