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

Thread: Looking for info on Serial MIDI Real-Time message support

  1. #1
    Member
    Join Date
    May 2018
    Location
    Portland, OR USA
    Posts
    38

    Looking for info on Serial MIDI Real-Time message support

    Hi All,
    Does anyone have a link to or info on the Serial MIDI Driver support for MIDI real-time messages: Clk, Start, Stop, & Continue (F8, FA, FB, & FC). I can't seem to find a definitive answer, I thought I recall reading that this was fixed but could be confusing with the USB MIDI driver or the USB Host MIDI driver (BTW thx Paul for all this great code!).

    I'm using library MIDI at version 4.3.1 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\MIDI
    It doesn't seem to handle real-time messages. I'm using an if statement and Serial.Write() to handle them now, but it make the code a little obtuse with a mix of Serial, USB and USB Host drivers.

    Thanks,
    Steve

    Code:
                 if ( (MsgType==0xF8)||(MsgType==0xFA)||(MsgType==0xFB)||(MsgType==0xFC) ) {
                      switch (i) { // Send single byte MIDI REAL-TIME MSG via SerialX.write
                         case 0:  Serial1.write(MsgType); break;
                         case 1:  Serial2.write(MsgType); break;
                         case 2:  Serial3.write(MsgType); break;
                         case 3:  Serial4.write(MsgType); break;
                         case 4:  Serial5.write(MsgType); break;
                        // case 5:  Serial6.write(MsgType); break;   //issue here with Serial6 
                     } // end switch
                 } // end if Real Time Msg

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,084
    These handlers appear to be defined in MIDI 4.3.1
    setHandleClock
    setHandleStart
    setHandleContinue
    setHandleStop

    Pete

  3. #3
    Member
    Join Date
    May 2018
    Location
    Portland, OR USA
    Posts
    38
    In MIDI.hpp, on or about line 123, is the Send() function (see code below). It handles sending Real-Time msgs... but the bounds checking requires the channel must = 1-16. It wasn't working for me because the value rtn'd from "channel = midiA.getChannel();" is 0. This is because the Real-Time MIDI messages are NOT channel specific. Feels like an API inconsistency.

    Issue resolved by forcing the channel=1 for all MIDI Real-Time msgs. Just want this in a thread in case someone else was having the same issue.
    Steve


    Code:
    template<class SerialPort, class Settings>
    void MidiInterface<SerialPort, Settings>::send(MidiType inType,
                                                   DataByte inData1,
                                                   DataByte inData2,
                                                   Channel inChannel)
    {
         // Then test if channel is valid
        if (inChannel >= MIDI_CHANNEL_OFF  ||
            inChannel == MIDI_CHANNEL_OMNI ||
            inType < 0x80)  
        {
            return; // Don't send anything
        }
    
        if (inType <= PitchBend)  // Channel messages
        {
            // Protection: remove MSBs on data
            inData1 &= 0x7f;
            inData2 &= 0x7f;
    
            const StatusByte status = getStatus(inType, inChannel);
    
            if (Settings::UseRunningStatus)
            {
                if (mRunningStatus_TX != status)
                {
                    // New message, memorise and send header
                    mRunningStatus_TX = status;
                    mSerial.write(mRunningStatus_TX);
                }
            }
            else
            {
                // Don't care about running status, send the status byte.
                mSerial.write(status);
            }
    
            // Then send data
            mSerial.write(inData1);
            if (inType != ProgramChange && inType != AfterTouchChannel)
            {
                mSerial.write(inData2);
            }
        }
        else if (inType >= Clock && inType <= SystemReset)
        {
     	sendRealTime(inType); // System Real-time and 1 byte.
        }
    
    }
    Last edited by SteveBar; 05-31-2019 at 07:47 PM.

Posting Permissions

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