Exemplo n.º 1
0
 /**
  * Reads Chord informations
  * 
  * @param integer $strings
  * @param Beat $beat
  */
 public function readChord($strings, Beat $beat)
 {
     $chord = new Chord($strings);
     if (($this->reader->readUnsignedByte() & 0x1) == 0) {
         $chord->setName($this->reader->readStringByteSizeOfInteger());
         $chord->setFirstFret($this->reader->readInt());
         if ($chord->getFirstFret() != 0) {
             for ($i = 0; $i < 6; $i++) {
                 $this->readFret($chord, $i);
             }
         }
     } else {
         $this->reader->skip(16);
         $chord->setName($this->reader->readStringByte(21));
         $this->reader->skip(4);
         $chord->setFirstFret($this->reader->readInt());
         for ($i = 0; $i < 7; $i++) {
             $this->readFret($chord, $i);
         }
         $this->reader->skip(32);
     }
     if ($chord->countNotes() > 0) {
         $beat->setChord($chord);
     }
 }
Exemplo n.º 2
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));
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Reads Chord informations
  * 
  * @param integer $strings
  * @param Beat $beat
  */
 public function readChord($strings, Beat $beat)
 {
     $chord = new Chord($strings);
     $this->reader->skip(17);
     $chord->setName($this->reader->readStringByte(21));
     $this->reader->skip(4);
     $chord->setFirstFret($this->reader->readInt());
     for ($i = 0; $i < 7; $i++) {
         $fret = $this->reader->readInt();
         if ($i < $chord->countStrings()) {
             $chord->addFretValue($i, $fret);
         }
     }
     $this->reader->skip(32);
     if ($chord->countNotes() > 0) {
         $beat->setChord($chord);
     }
 }
Exemplo n.º 4
0
 /**
  * Read Chord informations
  * 
  * @param integer $strings
  * @param Beat $beat
  */
 public function readChord($strings, Beat $beat)
 {
     $chord = new Chord($strings);
     $header = $this->reader->readUnsignedByte();
     if (($header & 0x1) == 0) {
         $chord->setName($this->reader->readStringByteSizeOfInteger());
         $chord->setFirstFret($this->reader->readInt());
         if ($chord->getFirstFret() != 0) {
             $this->readStrings($chord);
         }
     } else {
         $this->reader->skip(25);
         $chord->setName($this->reader->readStringByte(34));
         $chord->setFirstFret($this->reader->readInt());
         $this->readStrings($chord);
         $this->reader->skip(36);
     }
     if ($chord->countNotes() > 0) {
         $beat->setChord($chord);
     }
 }
Exemplo n.º 5
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();
 }
Exemplo n.º 6
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);
     }
 }
Exemplo n.º 7
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;
 }
Exemplo n.º 8
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);
                 }
             }
         }
     }
 }
Exemplo n.º 9
0
 /**
  * Reads some text
  * 
  * @param Beat $beat
  */
 public function readText(Beat $beat)
 {
     $text = new Text();
     $text->setValue($this->reader->readStringByteSizeOfInteger());
     $beat->setText($text);
 }
Exemplo n.º 10
0
 private function adjustStrings(Beat $beat)
 {
     $track = $beat->getMeasure()->getTrack();
     $freeStrings = $track->getStrings();
     $notesToRemove = array();
     $notes = $beat->getVoice(0)->getNotes();
     foreach ($notes as $note) {
         $string = $this->getStringForValue($freeStrings, $note->getValue());
         for ($j = 0; $j < count($freeStrings); $j++) {
             $tempString = $freeStrings[$j];
             if ($tempString->getNumber() == $string) {
                 $note->setValue($note->getValue() - $tempString->getValue());
                 $note->setString($tempString->getNumber());
                 array_splice($freeStrings, $j, 1);
                 break;
             }
         }
         //Cannot have more notes on same string
         if ($note->getString() < 1) {
             $notesToRemove[] = $note;
         }
     }
     // Remove notes
     while (count($notesToRemove) > 0) {
         $beat->getVoice(0)->removeNote($notesToRemove[0]);
         array_splice($notesToRemove, 0, 1);
     }
 }
Exemplo n.º 11
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_DOWN ? $this->toStrokeValue($beat->getStroke()) : 0);
         $this->writeUnsignedByte($beat->getStroke()->getDirection() == Stroke::STROKE_UP ? $this->toStrokeValue($beat->getStroke()) : 0);
     }
 }