Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: USB Midi output code - Please help me! :)

  1. #1
    Junior Member
    Join Date
    Nov 2015
    Posts
    2

    USB Midi output code - Please help me! :)

    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

  2. #2
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,091
    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...-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).

  3. #3
    Junior Member
    Join Date
    Nov 2015
    Posts
    2
    Thanks man, I'll suss it out. It shouldn't be this hard hey...

  4. #4
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,091
    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 by oddson; 08-30-2016 at 06:05 AM. Reason: Clarity

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •