Exemplo n.º 1
0
 private function writeTrack(MidiTrack $track)
 {
     $length = 0;
     $this->writeInt(MidiReader::TRACK_MAGIC);
     $previous = null;
     for ($i = 0; $i < $track->countEvents(); $i++) {
         $event = $track->get($i);
         $length += $this->writeEvent($event, $previous);
         $previous = $event;
     }
     return $length;
 }
Exemplo n.º 2
0
 private function readTrack(MidiTrack $track)
 {
     while (true) {
         if ($this->readInt() == MidiReaderInterface::TRACK_MAGIC) {
             break;
         }
         $chunkLength = $this->readInt();
         if ($chunkLength % 2 != 0) {
             $chunkLength++;
         }
         $this->skip($chunkLength);
     }
     $helper = new MidiTrackReaderHelper(0, $this->readInt(), -1);
     while ($helper->remainingBytes > 0) {
         $helper->ticks += $this->readVariableLengthQuantity($helper);
         $event = $this->readEvent($helper);
         if ($event !== null) {
             $track->add($event);
         }
     }
 }