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

Thread: Why does MIDI.read() pass MIDI from Input to Output?

  1. #1
    Junior Member
    Join Date
    Dec 2020
    Posts
    5

    Why does MIDI.read() pass MIDI from Input to Output?

    Hi everyone! I'm working on a MIDI filter using a Teensy 2.0. I've built the DIN MIDI input and output ports according to the schematic on the MIDI Library page here. Using only the code below, I noticed that the Teensy is always passing data from the Input port to the Output port unchanged, regardless from what channel I specify in MIDI.begin() or MIDI.read(). I don't want the Teensy to output any MIDI data unless I explicitly say so, and I'd like to at least understand why this is happening. On to the code:

    Code:
    #include <MIDI.h>
    
    MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
    
    void setup() {
       MIDI.begin(1); // receive on channel 1
    }
    
    void loop() {
       MIDI.read(1);
    }
    To generate MIDI data, I'm using an Akai MPC1000 playing a simple one-note loop over 2 bars at 120BPM, with some MIDI CC messages sprinkled in. I connected the MPC1000's MIDI Out port to the MIDI In port on my Teensy-based circuit. Regardless of what MIDI channel I output this data from the MPC1000, the Teensy is allowing it to pass through.

    Upon commenting out "MIDI.read(1);" the Teensy stopped passing MIDI data through. Therefore, it would appear that MIDI.read() is the culprit. Further, it appears that the argument "1" to the function read() has no bearing on whether data passes through. Any ideas why this is happening?

    Lastly, I took a look at "serialMIDI.h" in the MIDI library's src folder, but I didn't gain any further clarity:

    Code:
    (Line 80) byte read()
    (Line 81)	{
    (Line 82)		return mSerial.read();
    (Line 83)	};

  2. #2
    Senior Member
    Join Date
    Aug 2019
    Location
    Melbourne Australia
    Posts
    202
    The Midi library has Thru turned on by default so to turn it off add this line to void setup();

    Code:
    MIDI.turnThruOff();

  3. #3
    Junior Member
    Join Date
    Dec 2020
    Posts
    5
    Quote Originally Posted by MatrixRat View Post
    The Midi library has Thru turned on by default so to turn it off add this line to void setup();

    Code:
    MIDI.turnThruOff();
    Perfect, thank you! I wish I had a better understanding of how to learn what a given library is capable of... I often find myself aimlessly poking around .h files. Cheers.

  4. #4
    Member
    Join Date
    Sep 2020
    Location
    Massachusetts
    Posts
    99
    Took me months to figure that out. Amazing.

  5. #5
    Junior Member
    Join Date
    Dec 2020
    Posts
    5
    Quote Originally Posted by blakeAlbion View Post
    Took me months to figure that out. Amazing.
    It seems to me that it'd be better to *disable* it by default? That way, only if you are actually interesting in including that behavior, you'd be inclined to seek out how to implement it.

Posting Permissions

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