Exemplo n.º 1
0
 private function writeNote(Note $note)
 {
     $flags = 0x20 | 0x10;
     if ($note->getEffect()->isGhostNote()) {
         $flags |= 0x4;
     }
     if ($note->getEffect()->isBend() || $note->getEffect()->isGrace() || $note->getEffect()->isSlide() || $note->getEffect()->isHammer() || $note->getEffect()->isLetRing()) {
         $flags |= 0x8;
     }
     $this->writeUnsignedByte($flags);
     if (($flags & 0x20) != 0) {
         $typeHeader = 0x1;
         if ($note->isTiedNote()) {
             $typeHeader = 0x2;
         } else {
             if ($note->getEffect()->isDeadNote()) {
                 $typeHeader = 0x3;
             }
         }
         $this->writeUnsignedByte($typeHeader);
     }
     if (($flags & 0x10) != 0) {
         $this->writeByte(intval(($note->getVelocity() - Velocities::MIN_VELOCITY) / Velocities::VELOCITY_INCREMENT + 1));
     }
     if (($flags & 0x20) != 0) {
         $this->writeByte($note->getValue());
     }
     if (($flags & 0x8) != 0) {
         $this->writeNoteEffects($note->getEffect());
     }
 }
Exemplo n.º 2
0
 private function getPreviousNote(MidiSequenceHelper $sHelper, Note $note, Track $track, $mIndex, $bIndex, $breakAtRest)
 {
     $nextBIndex = $bIndex;
     for ($m = $mIndex; $m >= 0; $m--) {
         $mHelper = $sHelper->getMeasureHelper($m);
         $measure = $track->getMeasure($mHelper->getIndex());
         if ($this->sHeader == -1 || $this->sHeader <= $measure->getNumber()) {
             $nextBIndex = $nextBIndex < 0 ? $measure->countBeats() : $nextBIndex;
             for ($b = $nextBIndex - 1; $b >= 0; $b--) {
                 $beat = $measure->getBeat($b);
                 $voice = $beat->getVoice($note->getVoice()->getIndex());
                 if (!$voice->isEmpty()) {
                     $noteCount = $voice->countNotes();
                     for ($n = 0; $n < $noteCount; $n++) {
                         $current = $voice->getNote($n);
                         if ($current->getString() == $note->getString()) {
                             return new MidiNoteHelper($mHelper, $current);
                         }
                     }
                     if ($breakAtRest) {
                         return null;
                     }
                 }
             }
         }
         $nextBIndex = -1;
     }
     return null;
 }
Exemplo n.º 3
0
 private function writeNote(Note $note)
 {
     $flags = 0x20 | 0x10;
     if ($note->getEffect()->isVibrato() || $note->getEffect()->isBend() || $note->getEffect()->isGrace() || $note->getEffect()->isSlide() || $note->getEffect()->isHammer() || $note->getEffect()->isLetRing() || $note->getEffect()->isPalmMute() || $note->getEffect()->isStaccato() || $note->getEffect()->isHarmonic() || $note->getEffect()->isTrill() || $note->getEffect()->isTremoloPicking()) {
         $flags |= 0x8;
     }
     if ($note->getEffect()->isGhostNote()) {
         $flags |= 0x4;
     }
     if ($note->getEffect()->isHeavyAccentuatedNote()) {
         $flags |= 0x2;
     }
     if ($note->getEffect()->isAccentuatedNote()) {
         $flags |= 0x40;
     }
     $this->writeUnsignedByte($flags);
     if (($flags & 0x20) != 0) {
         $typeHeader = 0x1;
         if ($note->isTiedNote()) {
             $typeHeader = 0x2;
         } else {
             if ($note->getEffect()->isDeadNote()) {
                 $typeHeader = 0x3;
             }
         }
         $this->writeUnsignedByte($typeHeader);
     }
     if (($flags & 0x10) != 0) {
         $this->writeByte(intval(($note->getVelocity() - Velocities::MIN_VELOCITY) / Velocities::VELOCITY_INCREMENT + 1));
     }
     if (($flags & 0x20) != 0) {
         $this->writeByte($note->getValue());
     }
     $this->skipBytes(1);
     if (($flags & 0x8) != 0) {
         $this->writeNoteEffects($note->getEffect());
     }
 }
Exemplo n.º 4
0
 private function makeNoteEffect(Note $note, array $pitchBends)
 {
     $tmp = array();
     foreach ($pitchBends as $pitchBend) {
         if (!in_array($pitchBend, $tmp)) {
             array_push($tmp, $pitchBend);
         }
     }
     // All pitches have the same value: vibrato
     if (count($tmp) == 1) {
         $note->getEffect()->setVibrato(true);
         return;
     }
     // Bend
     $bend = new EffectBend();
     $bend->addPoint(0, 0);
     foreach ($pitchBends as $k => $pitchBend) {
         $bend->addPoint($k, $pitchBend);
     }
     $note->getEffect()->setBend($bend);
 }
Exemplo n.º 5
0
 /**
  * Reads a note
  * 
  * @param TabString $string
  * @param track $track
  * @param NoteEffect $effect
  * @return Note
  */
 public function readNote(TabString $string, Track $track, NoteEffect $effect)
 {
     $flags = $this->reader->readUnsignedByte();
     $note = new Note();
     $note->setString($string->getNumber());
     $note->setEffect($effect);
     $note->getEffect()->setAccentuatedNote(($flags & 0x40) != 0);
     $note->getEffect()->setGhostNote(($flags & 0x4) != 0);
     if (($flags & 0x20) != 0) {
         $noteType = $this->reader->readUnsignedByte();
         $note->setTiedNote($noteType == 0x2);
         $note->getEffect()->setDeadNote($noteType == 0x3);
     }
     if (($flags & 0x1) != 0) {
         $this->reader->skip(2);
     }
     if (($flags & 0x10) != 0) {
         $note->setVelocity(Velocities::MIN_VELOCITY + Velocities::VELOCITY_INCREMENT * $this->reader->readByte() - Velocities::VELOCITY_INCREMENT);
     }
     if (($flags & 0x20) != 0) {
         $fret = $this->reader->readByte();
         $value = $note->isTiedNote() ? $this->reader->factory('GuitarPro3TiedNote')->getTiedNoteValue($string->getNumber(), $track) : $fret;
         $note->setValue($value >= 0 && $value < 100 ? $value : 0);
     }
     if (($flags & 0x80) != 0) {
         $this->reader->skip(2);
     }
     if (($flags & 0x8) != 0) {
         $this->reader->factory('GuitarPro4NoteEffects')->readNoteEffects($note->getEffect());
     }
     return $note;
 }