adafruit / Adafruit_TinyUSB_Arduino

Arduino library for TinyUSB
MIT License
469 stars 122 forks source link

MIDI: support port name strings #215

Closed kaysievers closed 1 year ago

kaysievers commented 1 year ago

MIDI port names

This patch allows to set custom descriptive names for virtual MIDI ports/cables. A MIDI port offers different functionality on the same physical USB device. The names make it easier to distinguish one from the other.

Edit: the tinyusb part was merged: https://github.com/hathach/tinyusb/pull/1738

Screenshot of Chrome on MacOS listing WebMIDI devices:

Screenshot 2022-11-10 at 17 03 00

Screenshot of MacOS system-level MIDI Setup

Screenshot 2022-11-10 at 17 02 35

Example calls in setup() of Arduino sketch:

  Device.usb.midi.setPortName(1, "Keyboard");
  Device.usb.midi.setPortName(2, "Drum Pads");
  Device.usb.midi.setPortName(3, "Lights");

Calls to Adafruit_TinyUSB_Arduino from a local/custom MIDI Library:

  void setPorts(uint8_t n_ports) {
    _midi.interface.setCables(n_ports);
  }

  void setPortName(uint8_t port, const char *name) {
    _midi.interface.setCableNameStringIndex(port, _device.device->addStringToIndex(name));
  }
hathach commented 1 year ago

tinyusb core is sync with upstream, could you revert changes in usbd.h and merge from master to update PR. Note: the pr may still fail on esp32 ci since esp32 update its tinyusb core separately, which requires a bit of time for it to sync up as well.

kaysievers commented 1 year ago

could you revert changes in usbd.h and merge from master

I've updated the PR. Thanks!

kaysievers commented 1 year ago

@hathach is there anything I can do to get this merged? Thanks!

hathach commented 1 year ago

@hathach is there anything I can do to get this merged? Thanks!

nothing from your side, it is my issue. I will try to review and test this out asap.

kaysievers commented 1 year ago

Thanks a lot. That all seems to work fine.

I've updated to the current version and added 3 name entries to a real instrument: versioduo.com/#kontra-2)

It is an acoustic MIDI instrument with two strings that produce sound. The strings can be addressed by the main MIDI device, or both strings separately played as individual MIDI instruments. The 3 devices showing up with the USB connection have descriptive names now showing in the Audio Workstation Software:

Screenshot 2023-01-13 at 12 10 10
hathach commented 1 year ago

that looks great, thank you for the extra info. We will release this shortly.