Drefinition of USB MIDI setHandlePitchChange differs between Teensy 2.0 and 3.0

Status
Not open for further replies.

Nantonos

Well-known member
Definition of USB MIDI setHandlePitchChange differs between Teensy 2.0 and 3.0

Arduino 1..4 with Teensyduino 1.13
example Teensy > USB_MIDI > PrintIncoming
Teensy 2.0, USB type set to USB_MIDI
fails to compile, the error is
Code:
PrintIncoming.pde: In function 'void setup()':
PrintIncoming:19: error: invalid conversion from 'void (*)(byte, int)' to 'void (*)(uint8_t, uint16_t)'
PrintIncoming:19: error: initializing argument 1 of 'void usb_midi_class::setHandlePitchChange(void (*)(uint8_t, uint16_t))'

changing
Code:
void OnPitchChange(byte channel,  int pitch) {
to
Code:
void OnPitchChange(byte channel, unsigned int pitch) {
makes the example compile for Teensy 2.0 with USB MIDI. However, it then fails for Teensy 3.0 and USB MIDI, as follows:

Code:
PrintIncoming.pde: In function 'void setup()':
PrintIncoming.pde:19:45: error: invalid conversion from 'void (*)(byte, unsigned int) {aka void (*)(unsigned char, unsigned int)}' to 'void (*)(uint8_t, int) {aka void (*)(unsigned char, int)}' [-fpermissive]
In file included from F:\Arduino\arduino-1.0.4-teensyduino113\hardware\teensy\cores\teensy3/WProgram.h:28:0,
                 from F:\Arduino\arduino-1.0.4-teensyduino113\hardware\teensy\cores\teensy3/Arduino.h:1,
                 from PrintIncoming.pde:11:
F:\Arduino\arduino-1.0.4-teensyduino113\hardware\teensy\cores\teensy3/usb_midi.h:124:21: error:   initializing argument 1 of 'void usb_midi_class::setHandlePitchChange(void (*)(uint8_t, int))' [-fpermissive]

looking at the definitions, in hardware/teensy/cores/usb_midi/usb_api.h I see
Code:
inline void setHandlePitchChange(void (*fptr)(uint8_t channel, uint16_t pitch)) {
while in hardware/teensy/cores/teensy3/usb_midi.h I see
Code:
extern void (*usb_midi_handlePitchChange)(uint8_t ch, int pitch);
and
Code:
inline void setHandlePitchChange(void (*fptr)(uint8_t channel, int pitch)) {

According to the MIDI specification, this parameter is a 14bit unsigned integer, with 0x2000 corresponding to no pitch bend.
0lllllll 0mmmmmmm
Pitch Wheel Change. 0mmmmmmm This message is sent to indicate a change in the pitch wheel. The pitch wheel is measured by a fourteen bit value. Center (no pitch change) is 2000H. Sensitivity is a function of the transmitter. (llllll) are the least significant 7 bits. (mmmmmm) are the most significant 7 bits.

In the Teensy 3.0 code, shouldn't that be changed to either uint16_t or unsigned int?
 
Last edited:
Hey I am getting this error on this example too! How do I get past this this?
(Teensy 2.0 USB_MIDI arduino 1.0.5 0SX)
 
Is OnPitchChange actually working on Teensy 3.0 ? I can blink the onboard led with Note on/off activity through USB MIDI... but not with pitchbend changes ?
 
Receiving control change messages doesn't work either ?

Code:
/* USB-MIDI receive example
*/

const int LedPin = 13 ;

void setup()   {     
  pinMode(LedPin, OUTPUT);
  usbMIDI.setHandleControlChange(OnControlChange);
}


void loop() {

usbMIDI.read();   
}

void OnControlChange(byte channel, byte control, byte value)
{
   if (value = 0 ) {
     digitalWrite(LedPin , HIGH);
     
     
   } 
   
    if (value = 127 ) {
     digitalWrite(LedPin , LOW);
    
     
   }
  

}
 
Last edited:
Status
Not open for further replies.
Back
Top