/** * @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; }
public function testGetDeltaChunk() { $this->obj = new DeltaParser(); $chunk = $this->obj->getDeltaChunk(10); $this->assertInstanceOf('Tmont\\Midi\\Delta', $chunk); }