1
0
mirror of https://github.com/gdsports/USBHost_t36 synced 2024-08-13 16:53:54 -04:00

Use signed values for MIDI pitch bend (same as Arduino MIDI lib)

This commit is contained in:
PaulStoffregen 2018-01-11 19:19:06 -08:00
parent f59f8a16ef
commit 6bacd44c58
2 changed files with 10 additions and 4 deletions

View File

@ -890,9 +890,13 @@ public:
void sendAfterTouch(uint8_t pressure, uint8_t channel, uint8_t cable=0) {
send(0xD0, pressure, 0, channel, cable);
}
void sendPitchBend(uint16_t value, uint8_t channel, uint8_t cable=0) {
// MIDI 4.3 takes -8192 to +8191. We take 0 to 16383
// MIDI 4.3 also has version that takes float -1.0 to +1.0
void sendPitchBend(int value, uint8_t channel, uint8_t cable=0) {
if (value < -8192) {
value = -8192;
} else if (value > 8191) {
value = 8191;
}
value += 8192;
send(0xE0, value, value >> 7, channel, cable);
}
void sendSysEx(uint32_t length, const uint8_t *data, bool hasTerm=false, uint8_t cable=0) {

View File

@ -430,7 +430,9 @@ bool MIDIDevice::read(uint8_t channel)
if (type1 == 0x0E && type2 == 0x0E) {
msg_type = 0xE0; // 0xE0 = Pitch Bend
if (handlePitchChange) {
(*handlePitchChange)(ch, ((n >> 16) & 0x7F) | ((n >> 17) & 0x3F80));
int value = ((n >> 16) & 0x7F) | ((n >> 17) & 0x3F80);
value -= 8192; // 0 to 16383 --> -8192 to +8191
(*handlePitchChange)(ch, value);
}
} else {
return false;