Example #1
0
 public function readStroke(Beat $beat)
 {
     $strokeDown = $this->reader->readByte();
     $strokeUp = $this->reader->readByte();
     if ($strokeDown > 0) {
         $beat->getStroke()->setDirection(Stroke::STROKE_DOWN);
         $beat->getStroke()->setValue($this->toStrokeValue($strokeDown));
     } else {
         if ($strokeUp > 0) {
             $beat->getStroke()->setDirection(Stroke::STROKE_UP);
             $beat->getStroke()->setValue($this->toStrokeValue($strokeUp));
         }
     }
 }
Example #2
0
 private function writeBeatEffects(Beat $beat, NoteEffect $noteEffect)
 {
     $flags = 0;
     if ($noteEffect->isVibrato()) {
         $flags += 0x1;
     }
     if ($noteEffect->isTremoloBar() || $noteEffect->isTapping() || $noteEffect->isSlapping() || $noteEffect->isPopping()) {
         $flags += 0x20;
     }
     if ($beat->getStroke()->getDirection() != Stroke::STROKE_NONE) {
         $flags |= 0x40;
     }
     if ($noteEffect->isHarmonic() && $noteEffect->getHarmonic()->getType() == EffectHarmonic::TYPE_NATURAL) {
         $flags += 0x4;
     }
     if ($noteEffect->isHarmonic() && $noteEffect->getHarmonic()->getType() != EffectHarmonic::TYPE_NATURAL) {
         $flags += 0x8;
     }
     if ($noteEffect->isFadeIn()) {
         $flags += 0x10;
     }
     $this->writeUnsignedByte($flags);
     if (($flags & 0x20) != 0) {
         if ($noteEffect->isTremoloBar()) {
             $this->writeUnsignedByte(0);
             $this->writeInt(100);
         } else {
             if ($noteEffect->isTapping()) {
                 $this->writeUnsignedByte(1);
                 $this->writeInt(0);
             } else {
                 if ($noteEffect->isSlapping()) {
                     $this->writeUnsignedByte(2);
                     $this->writeInt(0);
                 } else {
                     if ($noteEffect->isPopping()) {
                         $this->writeUnsignedByte(3);
                         $this->writeInt(0);
                     }
                 }
             }
         }
     }
     if (($flags & 0x40) != 0) {
         $this->writeUnsignedByte($beat->getStroke()->getDirection() == Stroke::STROKE_DOWN ? $this->toStrokeValue($beat->getStroke()) : 0);
         $this->writeUnsignedByte($beat->getStroke()->getDirection() == Stroke::STROKE_UP ? $this->toStrokeValue($beat->getStroke()) : 0);
     }
 }
Example #3
0
 private function getStroke(Beat $beat, Beat $previous = null, array $stroke)
 {
     $direction = $beat->getStroke()->getDirection();
     if ($previous === null || !($direction == Stroke::STROKE_NONE && $previous->getStroke()->getDirection() == Stroke::STROKE_NONE)) {
         if ($direction == Stroke::STROKE_NONE) {
             for ($i = 0; $i < count($stroke); $i++) {
                 $stroke[$i] = 0;
             }
         } else {
             $stringUseds = 0;
             $stringCount = 0;
             for ($vIndex = 0; $vIndex < $beat->countVoices(); $vIndex++) {
                 $voice = $beat->getVoice($vIndex);
                 for ($nIndex = 0; $nIndex < $voice->countNotes(); $nIndex++) {
                     $note = $voice->getNote($nIndex);
                     if (!$note->isTiedNote()) {
                         $stringUseds |= 0x1 << $note->getString() - 1;
                         $stringCount++;
                     }
                 }
             }
             if ($stringCount > 0) {
                 $strokeMove = 0;
                 $strokeIncrement = $beat->getStroke()->getIncrementTime($beat);
                 for ($i = 0; $i < count($stroke); $i++) {
                     $index = $direction == Stroke::STROKE_DOWN ? count($stroke) - 1 - $i : $i;
                     if (($stringUseds & 0x1 << $index) != 0) {
                         $stroke[$index] = $strokeMove;
                         $strokeMove += $strokeIncrement;
                     }
                 }
             }
         }
     }
     return $stroke;
 }
Example #4
0
 private function writeBeatEffects(Beat $beat, NoteEffect $noteEffect)
 {
     $flags1 = 0;
     $flags2 = 0;
     if ($noteEffect->isFadeIn()) {
         $flags1 |= 0x10;
     }
     if ($noteEffect->isTapping() || $noteEffect->isSlapping() || $noteEffect->isPopping()) {
         $flags1 |= 0x20;
     }
     if ($noteEffect->isTremoloBar()) {
         $flags2 |= 0x4;
     }
     if ($beat->getStroke()->getDirection() != Stroke::STROKE_NONE) {
         $flags1 |= 0x40;
     }
     $this->writeUnsignedByte($flags1);
     $this->writeUnsignedByte($flags2);
     if (($flags1 & 0x20) != 0) {
         if ($noteEffect->isTapping()) {
             $this->writeUnsignedByte(1);
         } else {
             if ($noteEffect->isSlapping()) {
                 $this->writeUnsignedByte(2);
             } else {
                 if ($noteEffect->isPopping()) {
                     $this->writeUnsignedByte(3);
                 }
             }
         }
     }
     if (($flags2 & 0x4) != 0) {
         $this->writeTremoloBar($noteEffect->getTremoloBar());
     }
     if (($flags1 & 0x40) != 0) {
         $this->writeUnsignedByte($beat->getStroke()->getDirection() == Stroke::STROKE_UP ? $this->toStrokeValue($beat->getStroke()) : 0);
         $this->writeUnsignedByte($beat->getStroke()->getDirection() == Stroke::STROKE_DOWN ? $this->toStrokeValue($beat->getStroke()) : 0);
     }
 }