Skip to content

What happens to MIDI messages when I use MIDI.setInputChannel(MIDI_CHANNEL_OFF)? #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MIDIMinion opened this issue Jul 14, 2020 · 2 comments

Comments

@MIDIMinion
Copy link

Do they get stored in the buffer? Is there a way to clear that buffer?

I'd like to be able to turn input on and off as I need, but I'm finding that when I go from input off to input on, and then read, it reads all of the messages that were received while input channel was turned off.

Is there another way of doing this?

Thanks!

@franky47
Copy link
Member

franky47 commented Jul 14, 2020

Yes, when the MIDI input is turned off, messages are not read and remain in the input buffer. You can flush it before re-activating the MIDI input with this code:

while (Serial.available() > 0)
{
  Serial.read();
}

Replace Serial with the serial port used for MIDI (can be Serial1 on some boards, check out the default value).

@MIDIMinion
Copy link
Author

Ah! I had tried the serial.read() loop method with no success, but you've reminded me that I'm using Serial2! Works like a charm, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants