예제 #1
0
 /**
  * @since 1.0
  * @uses  parseTrackHeader()
  * @uses  getRawTrackHeader()
  * @uses  TrackHeader::getSize()
  * @uses  DeltaParser::parse()
  * @uses  Chunk::getLength()
  * @uses  EventParser::parse()
  * @uses  checkTrackLength()
  * 
  * @throws {@link ParseException}
  * @throws {@link StateException}
  * @return Chunk
  */
 public function parse()
 {
     $state = $this->getState();
     $chunk = null;
     switch ($state) {
         case ParseState::TRACK_HEADER:
             $chunk = $this->parseTrackHeader($this->getRawTrackHeader());
             $this->parsedTrackLength = 0;
             $this->expectedTrackLength = $chunk->getSize();
             $this->setState(ParseState::DELTA);
             break;
         case ParseState::DELTA:
             $chunk = $this->deltaParser->parse();
             $this->setState(ParseState::EVENT);
             $this->checkTrackLength($chunk->getLength());
             break;
         case ParseState::EVENT:
             $chunk = $this->eventParser->parse();
             $this->checkTrackLength($chunk->getLength());
             if ($this->getParsedTrackLength() === $this->getExpectedTrackLength()) {
                 if (!$chunk instanceof Event\EndOfTrackEvent) {
                     throw new ParseException('Expected end of track');
                 } else {
                     $this->setState(ParseState::TRACK_HEADER);
                 }
             } else {
                 $this->setState(ParseState::DELTA);
             }
             break;
         default:
             throw new StateException('Invalid state: ' . $state);
     }
     return $chunk;
 }
예제 #2
0
 public function testParseUnknownEvent()
 {
     //normal channel event
     $this->obj = $this->getMock('Tmont\\Midi\\Parsing\\EventParser', array('read'));
     $this->obj->expects($this->once())->method('read')->with(1, true)->will($this->returnValue(pack('C', 0xf3)));
     $this->setExpectedException('Tmont\\Midi\\Parsing\\ParseException', 'Unsupported event type: 0xF3');
     $this->obj->parse();
 }