midi_led/MIDI.cpp
/*
   * Reads a single midi message and returns it.  
   */
Reads a single midi message and returns it.
Reads a single midi message and returns it .
bool MIDIInput::readPendingEvent()
{
  while (Serial.available())
  {
    uint8_t midiVal = Serial.peek();
    if ((midiVal & MIDI_STATUS_BYTE_MASK) == 0)
    {
      (void)Serial.read();
      continue;
    }
    parseStatusByte(midiVal);
    if (Serial.available() < statusMsg.len)
    {
      statusMsg.reset();
      return false;
    }
    (void)Serial.read();
    for (uint8_t i = 0; i < statusMsg.len; i++)
    {
      statusMsg.data[i] = Serial.read();
    }
    if (statusMsg.status == MIDI_CONTROL)
    {
      switch (statusMsg.data[0])
      {
      case MIDI_CTL_SUSTAIN:
        sustainOn = (statusMsg.data[1] != 0);
        break;
      case MIDI_CTL_EXP:
        expressionLevel = statusMsg.data[1];
        break;
      default:
        break;
      }
    }
    break;
  }
  return true;
}
bool MIDIInput :: readPendingEvent ( ) { while ( Serial . available ( ) ) { uint8_t midiVal = Serial . peek ( ) ; if ( ( midiVal & MIDI_STATUS_BYTE_MASK ) == 0 ) { ( void ) Serial . read ( ) ; continue ; } parseStatusByte ( midiVal ) ; if ( Serial . available ( ) < statusMsg . len ) { statusMsg . reset ( ) ; return false ; } ( void ) Serial . read ( ) ; for ( uint8_t i = 0 ; i < statusMsg . len ; i ++ ) { statusMsg . data [ i ] = Serial . read ( ) ; } if ( statusMsg . status == MIDI_CONTROL ) { switch ( statusMsg . data [ 0 ] ) { case MIDI_CTL_SUSTAIN : sustainOn = ( statusMsg . data [ 1 ] != 0 ) ; break ; case MIDI_CTL_EXP : expressionLevel = statusMsg . data [ 1 ] ; break ; default : break ; } } break ; } return true ; }
Reads a single midi message and returns it.
Reads a single midi message and returns it .
//Read chars until we get a status char or the buffer is empty //Not a status byte.  Discard it. //Ensure the serial buffer contains the data bytes //We don't have the required data bytes yet.  Bail. //Pop the status byte we just peeked at. //Read in the expected data bytes. //This doesn't allow for continuations so it's poor implementation //but it's good enough for getting NOTE_ON messages which is all //we really care about.