Skip to content

MIDI Control Change message sending is corrupted #130

Closed
@todbot

Description

@todbot

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 ?

  1. Run Arduino IDE
  2. Install "MIDI Library" and "USB-MIDI" library in Library Manager
  3. Load sketch above
  4. Choose a board supported by both Arduino USB and TinyUSB
  5. Pick "USB Stack: Arduino", upload sketch, and watch MIDI monitor
  6. Pck "USB Stack: TinyUSB", upload sketch, and watch MIDI monitor

Debug Log

No response

Screenshots

Arduino_TinyUSB_MIDI_ProgramChange

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions