usbMIDI output Freezes on MacOS Ventura 13.2.1 and iPadOS 16.6.1

Arman

Member
I'm compiling Arduino 2.2.1 and Teensyduino 1.58.1 on a Teensy 4.0.

I'm building a sequencer of sorts that sends note data out via usbMIDI and Serial MIDI. If I am not running a music app (on either the Mac or iPad) my Teensy based sequencer will freeze and the device will lock up.

The Teensy sequencer will run if I delete the lines of code that send the note on messages:

usbMIDI.sendNoteOff(preva,127,cha); //preva is an int that stores the previous note data, cha is the int that stores the MIDI channel


If a MIDI capable music app is open, the Teensy sequencer will run continuously.
When powered via a USB brick (no USB MIDI device connected), the Teensy sequencer will run continuously.

It's as if the Teensy sees a MIDI USB capable device and is sending the data, but if an app isn't open to receive it, the buffer overflows and it crashes.

Is there a way to check to see if the device is really capable and ready to receive MIDI? Is there a command to flush the buffers for OUTPUT? I'm already using usbMIDI.read() and MIDI.read() ... so those buffers shouldn't be the issue.

Although I'm not using the:

while (usbMIDI.read()) {
// ignore incoming messages
}

... I am reading incoming values constantly.

Also - sleeping the Mac/iPad will freeze/crash my Teensy device.

Edit:

I'm not seeing this behaviour on my Windows machines. Maybe there is something going on with the way MacOS/iPad OS enumerates MIDI devices?
 
Last edited:
To clarify ... the Teensy sequencer I'm making freezes when connected to a Mac or iPad, after it plays/sends a few notes - but only if there is no application to receive the messages. Like the buffer is filling up and freezing/crashing the unit.
 
Would something like this worj to check to see if there is something on the other end of the USB to receive the packets:

if(usb_midi_available()){
//send MIDI notes here

}


EDIT:

Nope ... that didn't detect if usbMIDI was "alive" on the other end.
 
Last edited:
Putting

usb_midi_configure();

in my loop seems to keep it from freezing/crashing ... but makes the connection unstable as it looks like it is maybe re-creating some of the buffers each time.

There is also a reference to:

// When the PC isn't listening, how long do we wait before discarding data?
#define TX_TIMEOUT_MSEC 40

In usb_midi.c ... but I'm not sure where to find/change that in my local install.

And also:

tx_noautoflush = 0;

Not sure if toggling that would be helpful or not.
 
Or is something in code sending wayyy too much stuff that overwhelms the signal pathway's ability to handle it.

You might try replacing usbMIDI() calls with some Serial.println(" Some message"); or whatever and see what serial monitor has to say.
 
USB MIDI packets are stored up and queued to be sent outside of the normal "loop". My sketch works totally fine if that single line is commented out. Once I drop it back in, it is easy to reproduce the freeze:

1) Plug my teensy device into a Mac or iPad (it doesn't freeze on a PC)
2) With no calls to send via usbMIDI, the device will function normally
3) Once the sequencer is running, if there are no applications running that read incoming MIDI, my Teensy device will freeze after a few notes of playback.
4) The device will also freeze when the Mac is put to sleep (lid closed)
 
Back
Top