示例#1
0
 private function checkTripletFeel(Voice $voice, $bIndex)
 {
     $bStart = $voice->getBeat()->getStart();
     $bDuration = $voice->getDuration()->getTime();
     if ($voice->getBeat()->getMeasure()->getTripletFeel() == MeasureHeader::TRIPLET_FEEL_EIGHTH) {
         if ($voice->getDuration()->isEqual($this->newDuration(Duration::EIGHTH))) {
             //first time
             if ($bStart % Duration::QUARTER_TIME == 0) {
                 $v = $this->getNextBeat($voice, $bIndex);
                 if ($v === null || ($v->getBeat()->getStart() > $bStart + $voice->getDuration()->getTime() || $v->getDuration()->isEqual($this->newDuration(Duration::EIGHTH)))) {
                     $duration = $this->newDuration(Duration::EIGHTH);
                     $duration->getDivision()->setEnters(3);
                     $duration->getDivision()->setTimes(2);
                     $bDuration = $duration->getTime() * 2;
                 }
             } else {
                 if ($bStart % (Duration::QUARTER_TIME / 2) == 0) {
                     $v = $this->getPreviousBeat($voice, $bIndex);
                     if ($v === null || ($v->getBeat()->getStart() < $bStart - $voice->getDuration()->getTime() || $v->getDuration()->isEqual($this->newDuration(Duration::EIGHTH)))) {
                         $duration = $this->newDuration(Duration::EIGHTH);
                         $duration->getDivision()->setEnters(3);
                         $duration->getDivision()->setTimes(2);
                         $bStart = $bStart - $voice->getDuration()->getTime() + $duration->getTime() * 2;
                         $bDuration = $duration->getTime();
                     }
                 }
             }
         }
     } else {
         if ($voice->getBeat()->getMeasure()->getTripletFeel() == MeasureHeader::TRIPLET_FEEL_SIXTEENTH) {
             if ($voice->getDuration()->isEqual($this->newDuration(Duration::SIXTEENTH))) {
                 //first time
                 if ($bStart % (Duration::QUARTER_TIME / 2) == 0) {
                     $v = $this->getNextBeat($voice, $bIndex);
                     if ($v === null || ($v->getBeat()->getStart() > $bStart + $voice->getDuration()->getTime() || $v->getDuration()->isEqual($this->newDuration(Duration::SIXTEENTH)))) {
                         $duration = $this->newDuration(Duration::SIXTEENTH);
                         $duration->getDivision()->setEnters(3);
                         $duration->getDivision()->setTimes(2);
                         $bDuration = $duration->getTime() * 2;
                     }
                 } else {
                     if ($bStart % (Duration::QUARTER_TIME / 4) == 0) {
                         $v = $this->getPreviousBeat($voice, $bIndex);
                         if ($v === null || ($v->getBeat()->getStart() < $bStart - $voice->getDuration()->getTime() || $v->getDuration()->isEqual($this->newDuration(Duration::SIXTEENTH)))) {
                             $duration = $this->newDuration(Duration::SIXTEENTH);
                             $duration->getDivision()->setEnters(3);
                             $duration->getDivision()->setTimes(2);
                             $bStart = $bStart - $voice->getDuration()->getTime() + $duration->getTime() * 2;
                             $bDuration = $duration->getTime();
                         }
                     }
                 }
             }
         }
     }
     return new MidiTickHelper($bStart, $bDuration);
 }
示例#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);
 }