
Description
I wrote a code based on the examples to read three ADC inputs and transmit MIDI messages to the PC. I'm using a custom Leonardo board.
Here my code:
#define ADC_BASE 18
typedef struct
{
int value;
int shadow;
} slider_t;
slider_t sliders[3];
byte cc[3] = {1, 11, 2};
void loop()
{
for (byte i = 0; i < 3; i++) sendMIDI(i, analogRead(ADC_BASE + i));
}
void sendMIDI(byte idx, int adc)
{
sliders[idx].value = map(adc, 0, 1023, 0, 127);
if (sliders[idx].shadow != sliders[idx].value)
{
if (MidiUSB.isAvailable() == 0) sendControlChange(0, cc[idx], sliders[idx].value);
sliders[idx].shadow = sliders[idx].value;
}
}
void sendControlChange(byte channel, byte control, byte value)
{
midiEventPacket_t event = { EVENT_CONTROL_CHANGE, (byte) (0xB0 | channel), control, value };
MidiUSB.sendMIDI(event);
MidiUSB.flush();
}
On Linux aseqdump
receives the messages with no problems for 8+ hours.
On Windows 10 I'm facing these issues:
Cubase v12.0.60
After few seconds, Cubase does not receive anymore the messages. I have to disconnect, close the application and restart it.
Sometimes, instead, the GUI of Cubase freezes but it is still alive - it continues to play music.
Kontakt Full Standalone v7.3.0
The application receives the messages, but suddenly the virtual keyboard in Kontakt loses the blue color (like if the instrument was disabled). I have to re-assign the instrument to the channel to play. But again, after moving my slider and sending a MIDI message, the application drop the instrument.
Is there something wrong in my code?
Has anybody any experience in a real case scenario?