USB Midi output code - Please help me! :)

Status
Not open for further replies.

rarefaction

New member
I am a n00b at Arduino code and although i understand syntax of other languages and i can chop and change pieces of code from all over the place to generally do what i want to do.. i am completely stumped on how to get the usb midi from teensy to output to a pin..

I read through all of the references and still i don't get it and there are no examples of midi output as such... at least not midi data just a flashing LED.. basically I have a teensy 3.2 with audio adapter shield which i want to pass midi data out from the teensy USB device in Ableton to a DSP-G1 chip. I already have the audio passing through fine and the chip is working with another additional USB Midi interface i happen to have however i need help writing the code for relaying midi data from the teensy USB midi output device to a pin (i'm assuming TX) that can deliver a TTL midi signal for the DSP-G1 synth chip.

Any tips, or advice I have no idea where to start really..

Thanks,
rf
 
It turns out to be a more complicated to implement code to pass from usdMIDI to hardware MIDI (rx/tx connected to midi circuit) than it should be.


The problem is mentioned in the following thread after about the 10th post (discussion between me and Adrian)
https://forum.pjrc.com/threads/34697-Midi-usb-raw-input-question-and-possible-bug-in-usb_midi-h

I believe Adrain has had some success with this by altering the usbMIDI library but I'm still hoping for library improvements to make it as easy as it should be (at least for everything other than sysex).
 
If you only need to deal with standard midi from USB to hardware (and not the reverse) then just the MIDI.send part should cover it if you adjust for the type integer difference.

Code:
void loop() {
 
  if (usbMIDI.read() &&  usbMIDI.getType() < SystemExclusive) {
    type = (kMIDIType) usbMIDI.getType();
    type = 128 + type * 16; // REMAP TYPE!
    d1 = usbMIDI.getData1();
    d2 = usbMIDI.getData2();

    chnl = usbMIDI.getChannel();
    // and then send...
    MIDI.send(type,d1,d2,chnl);
  }
}
There's likely some better bit fiddle to get the 0-6 midi types to map to the high-nibble offsets used by MIDI.send for 'type' but I think the insterted line will work (or something similar if I've got the details wrong).

I've not tested (as I don't have the MIDI hardware ready... but it does compile.

If usbMIDI is updated you'd just delete that line to make it work again.

If I've got this correct (which is a bit of a big 'if').
 
Last edited:
Status
Not open for further replies.
Back
Top