Hi
I managed to play MIDI using fun example
https://github.com/ARMmbed/mbed-os-snippet-USBMIDI_Take_Me_Out
My goal is a converter of MIDI notes to CV(Control Voltage)
Hence, I must read and parse MIDI message
I reused and modified the Cookbook code,
https://os.mbed.com/users/simon/code/USBMIDI_DrumExample/docs/040c2c8ca5eb/main_8cpp_source.html
My code looks like this:
// read midi and send CV
#include "mbed.h"
#include "USBMIDI.h"
DigitalOut led(LED1);
USBMIDI midi;
MIDIMessage msg;
void cv(int state){
led = state;
}
static void do_message(void) {
if(midi.read(&msg)){
switch (msg.type()) {
case MIDIMessage::NoteOnType:
cv(1);
break;
case MIDIMessage::NoteOffType:
cv(0);
break;
}
}
}
int main() {
midi.attach(do_message);
cv(0);
while (1);
}
I had to use external variable msg, which is not elegant.
The code works and blinks LED1 when piano key is pressed!!
But, when I tried to midi.attach(do_message) with msg like this do_message(MIDIMessage msg){…} as in Cookbook example, I got multiple error messages. I got rid of them using do_message(void)
How should I call midi.attach() to be compliant with best practices?
Tom