Closed
Description
Operating System
MacOS
IDE version
1.8.16
Board
Adafruit Trinket M0
BSP version
1.8.11
TinyUSB Library version
1.5.0
Sketch
/**
* MIDI_ProgramChangeTest_TinyUSB.ino
*
* Demonstrate MIDI Program Change issues on Adafruit_TinyUSB_Arduino 1.5.0.
* This program when compiled with "USB Stack: Arduino" outputs
* correct Program Change messages ("0xC0 0x07") but when set to
* "USB Stack: TinyUSB" outputs incorrect Program Change messages
* ("0x00 0x07")
*
* Note: this problem also was evident in CircuitPython, but is
* somewhat fixed: https://github.com/adafruit/Adafruit_CircuitPython_MIDI/issues/37
* However on older MacOS versions (10.14 and before), CircuitPython
* is still outputting invalid Program Change messages.
*
* Thus, this seems like it's an issue in TinyUSB itself.
*
* Libraries used:
* - Arduino MIDI Library : https://github.com/FortySevenEffects/arduino_midi_library
* - Adafruit TinyUSB Arduino: https://github.com/adafruit/Adafruit_TinyUSB_Arduino
*
* 24 Oct 2021 - @todbot
*/
#if USE_TINYUSB
#include <Adafruit_TinyUSB.h>
#include <MIDI.h>
Adafruit_USBD_MIDI usb_midi;
MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);
#else
#include <USB-MIDI.h>
USBMIDI_CREATE_DEFAULT_INSTANCE();
#endif
void setup()
{
MIDI.begin(MIDI_CHANNEL_OMNI);
}
void loop() {
MIDI.sendNoteOn(65, 100, 1);
delay(600);
MIDI.sendNoteOff(65, 0, 1);
delay(600);
MIDI.sendProgramChange(7, 1);
delay(1600);
}
What happened ?
Mac MIDI Monitor is reporting Program Change messages are corrupted. The same sketch works with both TinyUSB and Arduino USB stacks. With the Arduino stack, the Program Change MIDI messages are correct. With the TinyUSB stack, the Program Change MIDI messages are incorrect. See MIDI Monitor screenshot below.
How to reproduce ?
- Run Arduino IDE
- Install "MIDI Library" and "USB-MIDI" library in Library Manager
- Load sketch above
- Choose a board supported by both Arduino USB and TinyUSB
- Pick "USB Stack: Arduino", upload sketch, and watch MIDI monitor
- Pck "USB Stack: TinyUSB", upload sketch, and watch MIDI monitor
Debug Log
No response