/**
  * Reads a Measure
  * 
  * @param Measure $measure
  * @param Track $track
  * @param Tempo $tempo
  */
 public function readMeasure(Measure $measure, Track $track, Tempo $tempo)
 {
     for ($voice = 0; $voice < 2; $voice++) {
         $nextNoteStart = intval($measure->getStart());
         $numberOfBeats = $this->reader->readInt();
         for ($i = 0; $i < $numberOfBeats; $i++) {
             $nextNoteStart += $this->reader->factory('GuitarPro5Beat')->readBeat($nextNoteStart, $measure, $track, $tempo, $voice);
         }
     }
     $emptyBeats = array();
     for ($i = 0; $i < $measure->countBeats(); $i++) {
         $beat = $measure->getBeat($i);
         $empty = true;
         for ($v = 0; $v < $beat->countVoices(); $v++) {
             if (!$beat->getVoice($v)->isEmpty()) {
                 $empty = false;
             }
         }
         if ($empty) {
             $emptyBeats[] = $beat;
         }
     }
     foreach ($emptyBeats as $beat) {
         $measure->removeBeat($beat);
     }
     $measure->setClef($this->reader->factory('GuitarProClef')->getClef($track));
     $measure->setKeySignature($this->reader->getKeySignature());
 }
 /**
  * Reads a Measure
  * 
  * @param Measure $measure
  * @param Track $track
  * @param Tempo $tempo
  */
 public function readMeasure(Measure $measure, Track $track, Tempo $tempo)
 {
     $nextNoteStart = intval($measure->getStart());
     $numberOfBeats = $this->reader->readInt();
     for ($i = 0; $i < $numberOfBeats; $i++) {
         $nextNoteStart += $this->reader->factory('GuitarPro3Beat')->readBeat($nextNoteStart, $measure, $track, $tempo);
     }
     $measure->setClef($this->reader->factory('GuitarProClef')->getClef($track));
     $measure->setKeySignature($this->reader->getKeySignature());
 }
Exemple #3
0
 /**
  * Reads some Beat informations
  * 
  * @param integer $start
  * @param Measure $measure
  * @param Track $track
  * @param Tempo $tempo
  * @param integer $voiceIndex
  * 
  * @return integer $time A duration time
  */
 public function readBeat($start, Measure $measure, Track $track, Tempo $tempo, $voiceIndex)
 {
     $flags = $this->reader->readUnsignedByte();
     $beat = $measure->getBeatByStart($start);
     $voice = $beat->getVoice($voiceIndex);
     if (($flags & 0x40) != 0) {
         $beatType = $this->reader->readUnsignedByte();
         $voice->setEmpty(($beatType & 0x2) == 0);
     }
     $duration = $this->reader->factory('GuitarProDuration')->readDuration($flags);
     $effect = new NoteEffect();
     if (($flags & 0x2) != 0) {
         $this->reader->factory('GuitarPro5Chord')->readChord($track->countStrings(), $beat);
     }
     if (($flags & 0x4) != 0) {
         $this->reader->factory('GuitarProText')->readText($beat);
     }
     if (($flags & 0x8) != 0) {
         $this->reader->factory('GuitarPro4BeatEffects')->readBeatEffects($beat, $effect);
     }
     if (($flags & 0x10) != 0) {
         $this->reader->factory('GuitarPro5MixChange')->readMixChange($tempo);
     }
     $stringFlags = $this->reader->readUnsignedByte();
     for ($i = 6; $i >= 0; $i--) {
         if (($stringFlags & 1 << $i) != 0 && 6 - $i < $track->countStrings()) {
             $string = clone $track->getString(6 - $i + 1);
             $note = $this->reader->factory('GuitarPro5Note')->readNote($string, $track, clone $effect);
             $voice->addNote($note);
         }
         $voice->getDuration()->copyFrom($duration);
     }
     $this->reader->skip();
     if (($this->reader->readByte() & 0x8) != 0) {
         $this->reader->skip();
     }
     return !$voice->isEmpty() ? $duration->getTime() : 0;
 }
Exemple #4
0
 /**
  * Reads some Beat informations
  * 
  * @param integer $start
  * @param Measure $measure
  * @param Track $track
  * @param Tempo $tempo
  * 
  * @return integer $time duration time
  */
 public function readBeat($start, Measure $measure, Track $track, Tempo $tempo)
 {
     $flags = $this->reader->readUnsignedByte();
     if (($flags & 0x40) != 0) {
         $this->reader->readUnsignedByte();
     }
     $beat = new Beat();
     $voice = $beat->getVoice(0);
     $duration = $this->reader->factory('GuitarProDuration')->readDuration($flags);
     $effect = new NoteEffect();
     if (($flags & 0x2) != 0) {
         $this->reader->factory($this->getParserName() . 'Chord')->readChord($track->countStrings(), $beat);
     }
     if (($flags & 0x4) != 0) {
         $this->reader->factory('GuitarProText')->readText($beat);
     }
     if (($flags & 0x8) != 0) {
         $this->reader->factory($this->getParserName() . 'BeatEffects')->readBeatEffects($beat, $effect);
     }
     if (($flags & 0x10) != 0) {
         $this->reader->factory($this->getParserName() . 'MixChange')->readMixChange($tempo);
     }
     $stringFlags = $this->reader->readUnsignedByte();
     for ($i = 6; $i >= 0; $i--) {
         if (($stringFlags & 1 << $i) != 0 && 6 - $i < $track->countStrings()) {
             $string = clone $track->getString(6 - $i + 1);
             $note = $this->reader->factory($this->getParserName() . 'Note')->readNote($string, $track, clone $effect);
             $voice->addNote($note);
         }
     }
     $beat->setStart($start);
     $voice->setEmpty(false);
     $voice->getDuration()->copyFrom($duration);
     $measure->addBeat($beat);
     return $duration->getTime();
 }
Exemple #5
0
 private function writeBeat(Beat $beat, Measure $measure, $changeTempo)
 {
     $voice = $beat->getVoice(0);
     $duration = $voice->getDuration();
     $flags = 0;
     if ($duration->isDotted() || $duration->isDoubleDotted()) {
         $flags |= 0x1;
     }
     if (!$duration->getDivision()->isEqual(DivisionType::normal())) {
         $flags |= 0x20;
     }
     if ($beat->isTextBeat()) {
         $flags |= 0x4;
     }
     if ($changeTempo) {
         $flags |= 0x10;
     }
     $effect = null;
     if ($voice->isRestVoice()) {
         $flags |= 0x40;
     } else {
         if ($voice->countNotes() > 0) {
             $note = $voice->getNote(0);
             $effect = $note->getEffect();
             if ($effect->isVibrato() || $effect->isTremoloBar() || $effect->isTapping() || $effect->isSlapping() || $effect->isPopping() || $effect->isHarmonic() || $effect->isFadeIn() || $beat->getStroke()->getDirection() != Stroke::STROKE_NONE) {
                 $flags |= 0x8;
             }
         }
     }
     $this->writeUnsignedByte($flags);
     if (($flags & 0x40) != 0) {
         $this->writeUnsignedByte(2);
     }
     $this->writeByte($this->parseDuration($duration));
     if (($flags & 0x20) != 0) {
         $this->writeInt($duration->getDivision()->getEnters());
     }
     if (($flags & 0x4) != 0) {
         $this->writeText($beat->getText());
     }
     if (($flags & 0x8) != 0) {
         $this->writeBeatEffects($beat, $effect);
     }
     if (($flags & 0x10) != 0) {
         $this->writeMixChange($measure->getTempo());
     }
     $stringFlags = 0;
     if (!$voice->isRestVoice()) {
         for ($i = 0; $i < $voice->countNotes(); $i++) {
             $playedNote = $voice->getNote($i);
             $string = 7 - $playedNote->getString();
             $stringFlags |= 1 << $string;
         }
     }
     $this->writeUnsignedByte($stringFlags);
     for ($i = 6; $i >= 0; $i--) {
         if (($stringFlags & 1 << $i) != 0) {
             for ($n = 0; $n < $voice->countNotes(); $n++) {
                 $playedNote = $voice->getNote($n);
                 if ($playedNote->getString() == 6 - $i + 1) {
                     $this->writeNote($playedNote);
                     break;
                 }
             }
         }
     }
 }
 private function addTempo(MidiSequenceHelper $sHelper, Measure $currMeasure, Measure $prevMeasure = null, $startMove)
 {
     $addTempo = false;
     if ($prevMeasure === null) {
         $addTempo = true;
     } else {
         if ($currMeasure->getTempo()->getInTPQ() != $prevMeasure->getTempo()->getInTPQ()) {
             $addTempo = true;
         }
     }
     if ($addTempo) {
         $usq = $currMeasure->getTempo()->getInTPQ() * 100 / $this->tempoPercent;
         $sHelper->getSequence()->addTempoInUSQ($this->getTick($currMeasure->getStart() + $startMove), $this->getInfoTrack(), $usq);
     }
 }
Exemple #7
0
 private function writeMeasure(Measure $measure, $changeTempo)
 {
     for ($v = 0; $v < 2; $v++) {
         $voices = array();
         for ($m = 0; $m < $measure->countBeats(); $m++) {
             $beat = $measure->getBeat($m);
             if ($v < $beat->countVoices()) {
                 $voice = $beat->getVoice($v);
                 if (!$voice->isEmpty()) {
                     $voices[] = $voice;
                 }
             }
         }
         if (count($voices) > 0) {
             $this->writeInt(count($voices));
             for ($i = 0; $i < count($voices); $i++) {
                 $voice = $voices[$i];
                 $this->writeBeat($voice, $voice->getBeat(), $measure, $changeTempo && $i == 0);
             }
         } else {
             $count = $measure->getTimeSignature()->getNumerator();
             $beat = new Beat();
             if ($v < $beat->countVoices()) {
                 $voice = $beat->getVoice($v);
                 $voice->getDuration()->setValue($measure->getTimeSignature()->getDenominator()->getValue());
                 $voice->setEmpty(true);
                 $this->writeInt($count);
                 for ($i = 0; $i < $count; $i++) {
                     $this->writeBeat($voice, $voice->getBeat(), $measure, $changeTempo && $i == 0);
                 }
             }
         }
     }
 }
Exemple #8
0
 private function adjustBeatsStrings(Measure $measure)
 {
     for ($i = 0; $i < $measure->countBeats(); $i++) {
         $beat = $measure->getBeat($i);
         $this->adjustStrings($beat);
     }
 }