Esempio n. 1
0
 private function getNextBeat(Voice $beat, $bIndex)
 {
     $next = null;
     for ($b = $bIndex + 1; $b < $beat->getBeat()->getMeasure()->countBeats(); $b++) {
         $current = $beat->getBeat()->getMeasure()->getBeat($b);
         if ($current->getStart() > $beat->getBeat()->getStart() && !$current->getVoice($beat->getIndex())->isEmpty()) {
             if ($next === null || $current->getStart() < $next->getBeat()->getStart()) {
                 $next = $current->getVoice($beat->getIndex());
             }
         }
     }
     return $next;
 }
Esempio n. 2
0
 private function writeBeat(Voice $voice, Beat $beat, Measure $measure, $changeTempo)
 {
     $duration = $voice->getDuration();
     $effect = new NoteEffect();
     for ($i = 0; $i < $voice->countNotes(); $i++) {
         $playedNote = $voice->getNote($i);
         if ($playedNote->getEffect()->isFadeIn()) {
             $effect->setFadeIn(true);
         }
         if ($playedNote->getEffect()->isTremoloBar()) {
             $effect->setTremoloBar(clone $playedNote->getEffect()->getTremoloBar());
         }
         if ($playedNote->getEffect()->isTapping()) {
             $effect->setTapping(true);
         }
         if ($playedNote->getEffect()->isSlapping()) {
             $effect->setSlapping(true);
         }
         if ($playedNote->getEffect()->isPopping()) {
             $effect->setPopping(true);
         }
     }
     $flags = 0;
     if ($duration->isDotted() || $duration->isDoubleDotted()) {
         $flags |= 0x1;
     }
     if ($voice->getIndex() == 0 && $beat->isChordBeat()) {
         $flags |= 0x2;
     }
     if ($voice->getIndex() == 0 && $beat->isTextBeat()) {
         $flags |= 0x4;
     }
     if ($beat->getStroke()->getDirection() != Stroke::STROKE_NONE) {
         $flags |= 0x8;
     } else {
         if ($effect->isTremoloBar() || $effect->isTapping() || $effect->isSlapping() || $effect->isPopping() || $effect->isFadeIn()) {
             $flags |= 0x8;
         }
     }
     if ($changeTempo) {
         $flags |= 0x10;
     }
     if (!$duration->getDivision()->isEqual(DivisionType::normal())) {
         $flags |= 0x20;
     }
     if ($voice->isEmpty() || $voice->isRestVoice()) {
         $flags |= 0x40;
     }
     $this->writeUnsignedByte($flags);
     if (($flags & 0x40) != 0) {
         $this->writeUnsignedByte($voice->isEmpty() ? 0 : 0x2);
     }
     $this->writeByte($this->parseDuration($duration));
     if (($flags & 0x20) != 0) {
         $this->writeInt($duration->getDivision()->getEnters());
     }
     if (($flags & 0x2) != 0) {
         $this->writeChord($beat->getChord());
     }
     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;
                 }
             }
         }
     }
     $this->skipBytes(2);
 }