Procházet zdrojové kódy

USB MIDI pitch bend uses signed integers (matching Arduino MIDI lib)

main
PaulStoffregen před 6 roky
rodič
revize
afe894aee8
4 změnil soubory, kde provedl 24 přidání a 10 odebrání
  1. +5
    -3
      teensy3/usb_midi.c
  2. +7
    -3
      teensy3/usb_midi.h
  3. +5
    -2
      usb_midi/usb_api.cpp
  4. +7
    -2
      usb_midi/usb_api.h

+ 5
- 3
teensy3/usb_midi.c Zobrazit soubor

@@ -323,9 +323,11 @@ int usb_midi_read(uint32_t channel)
} else
if (type1 == 0x0E && type2 == 0x0E) {
usb_midi_msg_type = 0xE0; // 0xE0 = usbMIDI.PitchBend
if (usb_midi_handlePitchChange)
(*usb_midi_handlePitchChange)(ch,
((n >> 16) & 0x7F) | ((n >> 17) & 0x3F80));
if (usb_midi_handlePitchChange) {
int value = ((n >> 16) & 0x7F) | ((n >> 17) & 0x3F80);
value -= 8192; // 0 to 16383 --> -8192 to +8191
(*usb_midi_handlePitchChange)(ch, value);
}
} else {
return 0;
}

+ 7
- 3
teensy3/usb_midi.h Zobrazit soubor

@@ -160,9 +160,13 @@ class usb_midi_class
void sendAfterTouch(uint8_t pressure, uint8_t channel, uint8_t cable=0) __attribute__((always_inline)) {
send(0xD0, pressure, 0, channel, cable);
}
void sendPitchBend(uint16_t value, uint8_t channel, uint8_t cable=0) __attribute__((always_inline)) {
// 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) __attribute__((always_inline)) {
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) __attribute__((always_inline)) {

+ 5
- 2
usb_midi/usb_api.cpp Zobrazit soubor

@@ -298,8 +298,11 @@ bool usb_midi_class::read(uint8_t channel)
} else
if (type1 == 0x0E && type2 == 0xE0) {
msg_type = 0xE0; // 0xE0 = usbMIDI.PitchBend
if (handlePitchChange) (*handlePitchChange)(c,
(b2 & 0x7F) | ((b3 & 0x7F) << 7));
if (handlePitchChange) {
int value = (b2 & 0x7F) | ((int)(b3 & 0x7F) << 7);
value -= 8192; // 0 to 16383 --> -8192 to +8191
(*handlePitchChange)(c, value);
}
} else {
return false;
}

+ 7
- 2
usb_midi/usb_api.h Zobrazit soubor

@@ -55,8 +55,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
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(uint16_t length, const uint8_t *data, bool hasTerm=false, uint8_t cable=0) {

Načítá se…
Zrušit
Uložit