Ejemplo n.º 1
0
 private function parseDuration(Duration $duration)
 {
     $value = 0;
     switch ($duration->getValue()) {
         case Duration::WHOLE:
             $value = -2;
             break;
         case Duration::HALF:
             $value = -1;
             break;
         case Duration::QUARTER:
             $value = 0;
             break;
         case Duration::EIGHTH:
             $value = 1;
             break;
         case Duration::SIXTEENTH:
             $value = 2;
             break;
         case Duration::THIRTY_SECOND:
             $value = 3;
             break;
         case Duration::SIXTY_FOURTH:
             $value = 4;
             break;
     }
     return $value;
 }
Ejemplo n.º 2
0
 private function newDuration($value)
 {
     $duration = new Duration();
     $duration->setValue($value);
     return $duration;
 }
Ejemplo n.º 3
0
 private function joinBeats(Measure $measure)
 {
     $previous = null;
     $finish = true;
     $measureStart = $measure->getStart();
     $measureEnd = $measureStart + $measure->getLength();
     for ($i = 0; $i < $measure->countBeats(); $i++) {
         $beat = $measure->getBeat($i);
         $beatStart = $beat->getStart();
         $beatLength = $beat->getVoice(0)->getDuration()->getTime();
         if ($previous !== null) {
             $previousStart = $previous->getStart();
             $previousLength = $previous->getVoice(0)->getDuration()->getTime();
             if ($beatStart >= $previousStart && $previousStart + $this->minDurationTime > $beatStart) {
                 // add beat notes to previous
                 for ($n = 0; $n < $beat->getVoice(0)->countNotes(); $n++) {
                     $note = $beat->getVoice(0)->getNote($n);
                     $previous->getVoice(0)->addNote($note);
                 }
                 // add beat chord to previous
                 if (!$previous->isChordBeat() && $beat->isChordBeat()) {
                     $previous->setChord($beat->getChord());
                 }
                 // add beat text to previous
                 if (!$previous->isTextBeat() && $beat->isTextBeat()) {
                     $previous->setText($beat->getText());
                 }
                 // set the best duration
                 if ($beatLength > $previousLength && $beatStart + $beatLength <= $measureEnd) {
                     $previous->getVoice(0)->getDuration()->copyFrom($beat->getVoice(0)->getDuration());
                 }
                 $measure->removeBeat($beat);
                 $finish = false;
                 break;
             } else {
                 if ($previousStart < $beatStart && $previousStart + $previousLength > $beatStart) {
                     if ($beat->getVoice(0)->isRestVoice()) {
                         $measure->removeBeat($beat);
                         $finish = false;
                         break;
                     }
                     $duration = Duration::fromTime($beatStart - $previousStart);
                     $previous->getVoice(0)->getDuration()->copyFrom($duration);
                 }
             }
         }
         if ($beatStart + $beatLength > $measureEnd) {
             if ($beat->getVoice(0)->isRestVoice()) {
                 $measure->removeBeat($beat);
                 $finish = false;
                 break;
             }
             $duration = Duration::fromTime($measureEnd - $beatStart);
             $beat->getVoice(0)->getDuration()->copyFrom($duration);
         }
         $previous = $beat;
     }
     if (!$finish) {
         $this->joinBeats($measure);
     }
 }
Ejemplo n.º 4
0
 private function makeNote($tick, $track, $channel, $value)
 {
     $tempNote = $this->getTempNote($track, $channel, $value, true);
     if ($tempNote !== null) {
         $nString = 0;
         $nValue = $tempNote->getValue() + $this->settings->getTranspose();
         $nVelocity = $tempNote->getVelocity();
         $nStart = $tempNote->getTick();
         $minDuration = new Duration();
         $minDuration->setValue(Duration::SIXTY_FOURTH);
         $nDuration = Duration::fromTime($tick - $tempNote->getTick(), $minDuration);
         $measure = $this->getMeasure($this->getTrack($track), $tempNote->getTick());
         $beat = $measure->getBeatByStart($nStart);
         $beat->getVoice(0)->getDuration()->copyFrom($nDuration);
         $note = new Note();
         $note->setValue($nValue);
         $note->setString($nString);
         $note->setVelocity($nVelocity);
         // Effect Bends / Vibrato
         if ($tempNote->countPitchBends() > 0) {
             $this->makeNoteEffect($note, $tempNote->getPitchBends());
         }
         $beat->getVoice(0)->addNote($note);
     }
 }
Ejemplo n.º 5
0
 /**
  * Reads Duration
  *
  * @param byte $flags unsigned bytes
  * @return Duration
  */
 public function readDuration($flags)
 {
     $duration = new Duration();
     $duration->setValue(pow(2, $this->reader->readByte() + 4) / 4);
     $duration->setDotted(($flags & 0x1) != 0);
     if (($flags & 0x20) != 0) {
         $divisionType = $this->reader->readInt();
         switch ($divisionType) {
             case 3:
                 $duration->getDivision()->setEnters(3);
                 $duration->getDivision()->setTimes(2);
                 break;
             case 5:
                 $duration->getDivision()->setEnters(5);
                 $duration->getDivision()->setTimes(4);
                 break;
             case 6:
                 $duration->getDivision()->setEnters(6);
                 $duration->getDivision()->setTimes(4);
                 break;
             case 7:
                 $duration->getDivision()->setEnters(7);
                 $duration->getDivision()->setTimes(4);
                 break;
             case 9:
                 $duration->getDivision()->setEnters(9);
                 $duration->getDivision()->setTimes(8);
                 break;
             case 10:
                 $duration->getDivision()->setEnters(10);
                 $duration->getDivision()->setTimes(8);
                 break;
             case 11:
                 $duration->getDivision()->setEnters(11);
                 $duration->getDivision()->setTimes(8);
                 break;
             case 12:
                 $duration->getDivision()->setEnters(12);
                 $duration->getDivision()->setTimes(8);
                 break;
         }
     }
     return $duration;
 }