-
Notifications
You must be signed in to change notification settings - Fork 267
wrong midi CC received with keyboard #363
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
Comments
I think your intuition was correct. Blocking the main thread with Doing a bit of back of the envelope maths, MIDI runs at 320µs per byte, so about 1ms for a 3-byte message. Blocking during 100ms leaves about 300 bytes having to go in the RX buffer (which IIRC is 1024 bytes by default). The issue is that once the delay clears, if the next message in the queue is also a good CC, then the delay blocks again, having only cleared 3 bytes and leaving up to 297 bytes in the queue, leading to accumulation of data and a buffer overflow. You could try a non-blocking way of turning your LED on and off by:
Hope this helps. |
Thanks Franky47 ;) |
Do you have a minimally reproducible sketch I could try? |
here is the code used for debug. a scope is connected to A6 // ARDUINO MICRO PRO CARD #include <avr/pgmspace.h> volatile unsigned char channel_set = 1;//listening channel volatile boolean cc_flag = 0; #define SCOPE A6 //MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI)// start midi on uart 1 // ----------------------------------------------------------------------------- // This function will be automatically called when a NoteOn is received. void handleCC(byte channel, byte controler, byte value) // ----------------------------------------------------------------------------- void setup()
} void loop()
} |
Thanks. The volatile specifier is not needed, the callbacks are also running in the main thread (within MIDI.read), they are not interrupt based. Could it be that you're receiving messages from another channel (ie: you might want to check the channel + CC number combination, or listen to channel 1 specifically) ? |
yes I have tried with and without the volatile specifier to be sure. |
Context
Please answer a few questions to help us understand your problem better and guide you to a solution:
What board are you using ?
What version of the Arduino IDE are you using ?
How are you using MIDI ?
Is your problem related to:
How comfortable are you with code ?
Describe your project and what you expect to happen:
I try to turn on lights when I receive a CC command. set to CC 11 on channel 1 the value is sent to the leds.
Describe your problem (what does not work):
I randomly receive wrong CC number when I turn only the CC11 knob on my M-audio oxygen keyboard
Steps to reproduce
I've check the hardware on scope for delay, and all works fine, I've tried the keyboard under midi ox with usb adapter > the keyboard works fine.
it's as if there was a buffer overflow and in this case, a bad CC was sent.
the test code is as simple as this (the led is used for local debug):
void handleCC(byte channel, byte controler, byte value)
{
controler_channel = channel;
controler_number = controler;
controler_value = value;
cc_flag = 1; // value received
if(controler_number != 11 )
{
digitalWrite(LED, HIGH);
delay(100);
digitalWrite(LED, LOW);
}
}
main loop:
void loop()
{
MIDI.read();
}
when I play quickly with the button, making mini maxi jumps, the blue LED flashes while everything starts from the keyboard in CC11 channel 1
test with callbacks and with cortex M4 power > same thing.
The text was updated successfully, but these errors were encountered: