Passing MIDI thru Teensy 2.0 ++ to and from pc

Status
Not open for further replies.

Demonclaw

Active member
I would like some help with coding so I can pass MIDI notes or MIDI commands through the Teensy to other devices from my PC. I have made a homemade MIDI controller it also has 2 MIDI ports on it the problem is I don't know how to program the Teensy to pass the MIDI notes/commands through it to another device from a computer. The help documents are a little confusing so any help is good. I also need help making the Teensy to pass MIDI commands/notes from an outside midi controller or device to my PC.

If you need help under standing what I'm asking I attached an Image to show what I need help with.

pc_to_teensy_to_device.png
 
So the code in post #7 of this thread should do what you want... it doesn't work for sysex (I think I have some untested sysex code at home somewhere .... I'm at work at the moment) .... I think I've tested the code in post #7 ... can't remember, so tell me how you get on ....

edit ... maybe the code needs "MIDI.begin();" in setup()??
 
Last edited:
So the code in post #7 of this thread should do what you want... it doesn't work for sysex (I think I have some untested sysex code at home somewhere .... I'm at work at the moment) .... I think I've tested the code in post #7 ... can't remember, so tell me how you get on ....

edit ... maybe the code needs "MIDI.begin();" in setup()??

Is SysEx just for Mac? If so I don't really care because it most likely be used on Linux and/or Windows. I'm looking over what you posted now.
 
SysEx is a kind of midi message ...its System Exclusive ...meaning it is things like special commands and such like. So, within midi, there is noteon/noteoff, CC mesages, pitch bend, two kinds of aftertouch, some other thing, and sysex ...I'm guessing you don't need sysex...

The code reads the teensy midi port messages and punts them to USB / your computer, and also reads USB messages from your computer and punts them out the teensy midi port ... I think it should do the trick. I remember testing it on a setup exactly like you describe in your diagram ...so it should be 'all good'
 
Last edited:
Great, that error message says everything : Remove the ";" behind #include <MIDI.h>

In opposite to C/C++ statements, these preprocessor commands starting with a "#" must never be terminated by ";"

After I removed it, the code (as pasted below) compiled for the Teensy 3.2 without any errors or warnings. When compiling for the Teensy 2.0++ I got still that non blocking warning about the "missing terminating ' character".

These error messages from the compiler are not so bad, they normally point you directly towards potential problems. It's sufficient to read...

Code:
#include <MIDI.h>
int chnl,d1,d2,dd;
kMIDIType type;
void setup() {

  Serial.begin(31250);

}

void loop() {
  if (MIDI.read() &&  MIDI.getType() < SystemExclusive) {
    type = MIDI.getType();
    d1 = MIDI.getData1();
    d2 = MIDI.getData2();
    dd = d1 + (d2 << 8);
    chnl = MIDI.getChannel();
    // and then send...
    switch(type){
      case NoteOn:
        usbMIDI.sendNoteOn(d1,d2,chnl);
      break;
      case NoteOff:
        usbMIDI.sendNoteOff(d1,d2,chnl);
      break;
      case AfterTouchPoly:
        usbMIDI.sendPolyPressure(d1,d2,chnl);
      break;
      case ControlChange:
        usbMIDI.sendControlChange(d1,d2,chnl);
      break;
      case ProgramChange:
        usbMIDI.sendProgramChange(dd,chnl);
      break;
      case AfterTouchChannel:
        usbMIDI.sendAfterTouch(dd,chnl);
      break;
      case PitchBend:

        usbMIDI.sendPitchBend(dd,chnl);
      break;
      case SystemExclusive:
        // handle sysex
      break;
      default:
        // F8 et seq.
      break;
    }
  }
  if (usbMIDI.read() &&  usbMIDI.getType() < SystemExclusive) {
    type = (kMIDIType) usbMIDI.getType();
    d1 = usbMIDI.getData1();
    d2 = usbMIDI.getData2();

    chnl = usbMIDI.getChannel();
    // and then send...
    MIDI.send(type,d1,d2,chnl);
  }
}
 
Last edited:
Edit: looked into that "missing terminating ' character" issue. It's a remainder of text in a non active part of the code. Doesn't disturb, will not prevent the code from running correctly.
 
Great, that error message says everything : Remove the ";" behind #include <MIDI.h>

In opposite to C/C++ statements, these preprocessor commands starting with a "#" must never be terminated by ";"

After I removed it, the code (as pasted below) compiled for the Teensy 3.2 without any errors or warnings. When compiling for the Teensy 2.0++ I got still that non blocking warning about the "missing terminating ' character".

These error messages from the compiler are not so bad, they normally point you directly towards potential problems. It's sufficient to read...

Code:
#include <MIDI.h>
int chnl,d1,d2,dd;
kMIDIType type;
void setup() {

  Serial.begin(31250);

}

void loop() {
  if (MIDI.read() &&  MIDI.getType() < SystemExclusive) {
    type = MIDI.getType();
    d1 = MIDI.getData1();
    d2 = MIDI.getData2();
    dd = d1 + (d2 << 8);
    chnl = MIDI.getChannel();
    // and then send...
    switch(type){
      case NoteOn:
        usbMIDI.sendNoteOn(d1,d2,chnl);
      break;
      case NoteOff:
        usbMIDI.sendNoteOff(d1,d2,chnl);
      break;
      case AfterTouchPoly:
        usbMIDI.sendPolyPressure(d1,d2,chnl);
      break;
      case ControlChange:
        usbMIDI.sendControlChange(d1,d2,chnl);
      break;
      case ProgramChange:
        usbMIDI.sendProgramChange(dd,chnl);
      break;
      case AfterTouchChannel:
        usbMIDI.sendAfterTouch(dd,chnl);
      break;
      case PitchBend:

        usbMIDI.sendPitchBend(dd,chnl);
      break;
      case SystemExclusive:
        // handle sysex
      break;
      default:
        // F8 et seq.
      break;
    }
  }
  if (usbMIDI.read() &&  usbMIDI.getType() < SystemExclusive) {
    type = (kMIDIType) usbMIDI.getType();
    d1 = usbMIDI.getData1();
    d2 = usbMIDI.getData2();

    chnl = usbMIDI.getChannel();
    // and then send...
    MIDI.send(type,d1,d2,chnl);
  }
}

Thanks. That worked and for that lesser error. If it compiles without major one like the one I had its good as gold.
 
That is the midi standard baud rate. sorry bout the semi-colon ... was at work and didn't recheck the code.

You learn something new each day. The code error is not a real big issue some programming languages use semi-colons at the end of the line. Now here comes the fun take your code and my code and shove them together and hope it still works after.
 
its actually not my code ... I have simply appropriated it from the original author @oddson. I'm working on a 2 x 2 midi interface (amongst other things), and oddson's code started me off!!


Good luck with your coding!!
 
its actually not my code ... I have simply appropriated it from the original author @oddson. I'm working on a 2 x 2 midi interface (amongst other things), and oddson's code started me off!!


Good luck with your coding!!

it compiled so its going to work most likely. All I have to do is wait on my OPTOCOUPLER from china to get the input working and a few other small parts. I'll mostly post pictures of the finished thing once the parts are in. Plus the code I used.
 
its actually not my code ... I have simply appropriated it from the original author @oddson. I'm working on a 2 x 2 midi interface (amongst other things), and oddson's code started me off!!


Good luck with your coding!!
Just stumbled across this as I have not been on the site for a while.

So you have working code? I never got past a compile check for lack of hardware.
Did you get sysex done? I don't recall what issue was but I would think it's not that hard.
 
Just stumbled across this as I have not been on the site for a while.

So you have working code? I never got past a compile check for lack of hardware.
Did you get sysex done? I don't recall what issue was but I would think it's not that hard.

Right now I'm still waiting on some stuff like the OPTOCOUPLER, SN74HC4051, and some quadrature encoders all coming from the area around china. If you like I can post the code I have gotten figured out.
 
Status
Not open for further replies.
Back
Top