USB MIDI and MIDI.h

Status
Not open for further replies.

yeahtuna

Well-known member
Hi, I'm trying to build a simple sketch to forward data from a physical MIDI input to a USB MIDI port. I've managed to build the circuit and compile a sketch, and I can confirm the basic functionality like reading from the physical MIDI IN and sending to the USB MIDI port is working. How should I go about forwarding the data in the simplest way possible? Thanks in advance for any help you can offer me.

Regards,
Rob
 
Last edited:
Having learnt to send and receive messages over the physical midi interface, and then learning/learnt same about the USB MIDI interface you write handlers for each event (from each end) which write the data/event to the other interface.

It would surprise me little to find a github repository (or blog, or similar) with a fully fleshed out rendition of this.

The three examples I find at File->Examples->Teensy->USB MIDI->**here** look to me like enough to manage a start on your project.
 
Having learnt to send and receive messages over the physical midi interface, and then learning/learnt same about the USB MIDI interface you write handlers for each event (from each end) which write the data/event to the other interface.

It would surprise me little to find a github repository (or blog, or similar) with a fully fleshed out rendition of this.

The three examples I find at File->Examples->Teensy->USB MIDI->**here** look to me like enough to manage a start on your project.

I'm guessing there's gotta be a one line solution to this problem. And to be honest, looking at the MIDI.h (version 3.2), it seems to indicate that the forwarding should happen automatically. I'm using my own USB MIDI / HID type device, so maybe I need to edit the library to get it working properly.

Regards,
Rob
 
By default there's a MIDIThru enabled. By connecting a 220 ohm resister in series with an LED from the TX to 5v, I can see that any incoming MIDI coming into the MIDI IN is sent right back out the MIDI OUT. If I turn off the thru using MIDI.turnThruOff(), I can see that the MIDI is no longer heading out the MIDI OUT. So now I just need to figure out how to route the MIDI through to the USB MIDI IN instead.

Regards,
Rob
 
Last edited:
USB to MIDI (MIDI to USB) converters can be found as cheap as $5; although the scenario of 'just passing thru' seems easily cater-able I am not sure the people behind USB_MIDI and MIDI will have bothered making such a bridge - maybe they did, if they didn't it would probably be easy hacked into their objects (for an experienced coder who actually wants the functionality themselves).

To be honest myself; I haven't played with MIDI at all, done a little reading about it and touched many many of the other things on 'the hobbyist shelf' (so to speak), but the way I see it the people who have contributed to MIDI and USB_MIDI were making 'end points' and not so much 'mid points'
 
USB to MIDI (MIDI to USB) converters can be found as cheap as $5; although the scenario of 'just passing thru' seems easily cater-able I am not sure the people behind USB_MIDI and MIDI will have bothered making such a bridge - maybe they did, if they didn't it would probably be easy hacked into their objects (for an experienced coder who actually wants the functionality themselves).

To be honest myself; I haven't played with MIDI at all, done a little reading about it and touched many many of the other things on 'the hobbyist shelf' (so to speak), but the way I see it the people who have contributed to MIDI and USB_MIDI were making 'end points' and not so much 'mid points'

Interestingly, the MIDI.h from Sorceforge includes the following defines:
Code:
#define TEENSY_SUPPORT          1           // Set this to 1 to enable Teensyduino support.
#define TEENSY_USB_TO_MIDI      1           // Set this to 1 to forward incoming messages on the USB MIDI to the UART.
#define TEENSY_MIDI_TO_USB      1           // Set this to 1 to forward incoming messages on the UART to the USB MIDI.

However, the version of the MIDI library installed from Teensyduino (1.22) does not include these defines. I'm sure I can figure out a way to hack the functionality I need back into the library.

Regards,
Rob
 
First guess: MIDI to USB Converters/adapters/breakouts are too cheap to bother emulating with $12-$30 gear.

Second guess: More complicated than anyone might guess without actually trying to do it.

It might be worth your while to grab a reasonably recent copy of Arduino (I am sticking to 1.6.3 for now, might try a later one if they leave it as last release for more than a month) and the latest Teensyduino (even the beta, I think there is 1.24 in beta but it may even be release now) to review the latest 'supported' code - there may be more of the 'bridge' in it, there may not.
 
I actually already manufacture and sell USB MIDI Pedal interfaces, and I'm looking to add a new member to the family with MIDI IN/OUT, so I'm not interested in any converters. Thanks your all your suggestions, but I'm still going to look for a software solution.

Regards,
Rob
 
I've managed to add some methods to the usbMIDI class to support System Common, System Realtime, and Active sensing quite easily. By setting up a swtich case, it's simple enough route MIDI to either over the USB cable or the physical DIN MIDI OUT.

One issue I'm going to run into is the limits placed on SysEx messages. The MIDI library only support 128bits and the usbMIDI defaults to 60. I don't have enough memory available on my device to set these much higher. From a theoretical perspective, shouldn't it be possible to handle any size of SysEx message by breaking it down into smaller chunks? If the MIDI.h had two input buffers, wouldn't it be possible to fill one up, pass the data, and then start filling up the other one?

Regards,
Rob
 
Last edited:
I managed to get this working. I didn't need to use two buffers. Instead, I implemented it by setting a sysEx status (start, continue, end, complete) and returned true from read() whenever the buffer was full. Implementing it this way, I was actually able to reduced the size of the buffers in MIDI.h and the usb_api.h dramatically.

Regards,
Rob
 
Status
Not open for further replies.
Back
Top