tttapa / MIDI_controller

This is a library for creating a MIDI controller using an Arduino or Teensy board.
GNU General Public License v3.0
404 stars 69 forks source link

Why return MidiUSB.read().header != 0 in USBMIDI_Interface::refresh class ? #93

Closed AurelGTS closed 4 years ago

AurelGTS commented 5 years ago

Hello,

Just a question on library USBMIDI_Interface. Why did you put a read function ? I trying to receive MIDI Note on my input but some MIDI packets disappear. If I comment this line, it works fine. I saw that you create a control surface . I think you are reading Midi Input too in order to know which light to push on if a control is ON on DAW, isn't it ? Do you encountered this problem ?

Thanks in advance.

Aurélien

Steps to reproduce the problem USBMIDI_Interface

Hardware

Arduino Leonardo

Software versions:

MIDI Controller library: 3.1.0 ? Arduino IDE: 1.8.9 Windows Operating System version: 10, (Encoder library): 1.4.1 (MIDIUSB library**): 1.0.4

Settings in the IDE

tttapa commented 5 years ago

Some software sends MIDI data to MIDI controllers. When you don't read that data in your sketch, the buffer gets full, and the application can't send more any data. Some applications wait until there's room in the buffer, but this never happens, so the application freezes.

That's why the MIDI controller library reads the data from the buffer, and discards it.

The reason that you're losing data is because sometimes you're the first one to read it, sometimes MIDI_Controller is first, and in that case, it's lost.

Control Surface also reads the data from the MIDI input, but it doesn't discard it, that's the difference, it finds out what MIDI Input Element to send the message to, and then updates that element with the new data.

What do you want to use the MIDI input for? Chances are it's already supported by Control Surface. And if not, you can add your own callbacks to handle MIDI input:
https://tttapa.github.io/Control-Surface/Doc/Doxygen/d0/d32/MIDI-Input-Callback_8ino-example.html