Skip to content
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

Disconnections and wrong behavior with music applications #97

Open
ghost opened this issue May 29, 2023 · 3 comments
Open

Disconnections and wrong behavior with music applications #97

ghost opened this issue May 29, 2023 · 3 comments
Labels
type: imperfection Perceived defect in any part of project

Comments

@ghost
Copy link

ghost commented May 29, 2023

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?

@per1234 per1234 added the type: imperfection Perceived defect in any part of project label May 29, 2023
@ghost
Copy link
Author

ghost commented May 30, 2023

I tried to add a small delay after a write, i.e.:

void sendControlChange(byte channel, byte control, byte value) 
{
    midiEventPacket_t event = { EVENT_CONTROL_CHANGE, (byte) (0xB0 | channel), control, value };
    MidiUSB.sendMIDI(event);
    MidiUSB.flush();
    delay(10);
}

but the behavior is always the same.

@ghost
Copy link
Author

ghost commented Jun 14, 2023

UPDATE

I noticed after some time the channel is no more writable (USB_Available(MIDI_TX); returns 0) no matter how many packets I sent before. It may happens after few seconds or minutes. But this happens on Windows only. Linux and Mac work fine. I used different MIDI monitors and the behavior is always the same. Hence is not a problem with those applications.

I tried on four machines, with Windows 10 and 11. I changed the USB cable and tested three Leonardo boards.
When it happens a reset of the board does not recover the functionality. I need to physically disconnect and reconnect the USB cable.

I also added a MidiUSB.read(); in the main loop in order to ignore any incoming packets.

Any suggestion? I'm pretty sure for others it works fine in Windows!

@GuitarPikstar
Copy link

GuitarPikstar commented Aug 8, 2024

Did you find any solution to this problem? We face the exact same phenomena with cubase and we use it for live performance, which is kinda critical...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants