示例#1
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);
     }
 }
示例#2
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);
     }
 }