Ejemplo n.º 1
0
 /**
  * Reads bend
  *
  * @param NoteEffect $effect
  */
 public function readBend(NoteEffect $effect)
 {
     $bend = new EffectBend();
     $this->reader->skip(5);
     $points = $this->reader->readInt();
     for ($i = 0; $i < $points; $i++) {
         $bendPosition = $this->reader->readInt();
         $bendValue = $this->reader->readInt();
         $this->reader->readByte();
         //vibrato
         $pointPosition = round($bendPosition * EffectBend::MAX_POSITION_LENGTH / GuitarProReaderInterface::GP_BEND_POSITION);
         $pointValue = round($bendValue * EffectBend::SEMITONE_LENGTH / GuitarProReaderInterface::GP_BEND_SEMITONE);
         $bend->addPoint($pointPosition, $pointValue);
     }
     if (count($bend->getPoints())) {
         $effect->setBend($bend);
     }
 }
Ejemplo n.º 2
0
 private function writeBend(EffectBend $bend)
 {
     $points = count($bend->getPoints());
     $this->writeByte(1);
     $this->writeInt(0);
     $this->writeInt($points);
     for ($i = 0; $i < $points; $i++) {
         $point = $bend->getPoints()[$i];
         $this->writeInt(intval($point->getPosition() * GprInterface::GP_BEND_POSITION / EffectBend::MAX_POSITION_LENGTH));
         $this->writeInt(intval($point->getValue() * GprInterface::GP_BEND_SEMITONE / EffectBend::SEMITONE_LENGTH));
         $this->writeByte(0);
     }
 }
Ejemplo n.º 3
0
 public function makeBend(MidiSequenceHelper $sHelper, $track, $start, $duration, EffectBend $bend, $channel, $midiVoice, $bendMode)
 {
     $points = $bend->getPoints();
     for ($i = 0; $i < count($points); $i++) {
         $point = $points[$i];
         $bendStart = $start + $point->getTime($duration);
         $value = self::DEFAULT_BEND + intval($point->getValue() * self::DEFAULT_BEND_SEMI_TONE / EffectBend::SEMITONE_LENGTH);
         $value = $value <= 127 ? $value : 127;
         $value = $value >= 0 ? $value : 0;
         $this->addBend($sHelper, $track, $bendStart, $value, $channel, $bendMode);
         if (count($points) > $i + 1) {
             $nextPoint = $points[$i + 1];
             $nextValue = self::DEFAULT_BEND + intval($nextPoint->getValue() * self::DEFAULT_BEND_SEMI_TONE / EffectBend::SEMITONE_LENGTH);
             $nextBendStart = $start + $nextPoint->getTime($duration);
             if ($nextValue != $value) {
                 $width = ($nextBendStart - $bendStart) / abs($nextValue - $value);
                 //asc
                 if ($value < $nextValue) {
                     while ($value < $nextValue) {
                         $value++;
                         $bendStart += $width;
                         $this->addBend($sHelper, $track, $bendStart, $value <= 127 ? $value : 127, $channel, $bendMode);
                     }
                     //desc
                 } else {
                     if ($value > $nextValue) {
                         while ($value > $nextValue) {
                             $value--;
                             $bendStart += $width;
                             $this->addBend($sHelper, $track, $bendStart, $value >= 0 ? $value : 0, $channel, $bendMode);
                         }
                     }
                 }
             }
         }
     }
     $this->addBend($sHelper, $track, $start + $duration, self::DEFAULT_BEND, $channel, $bendMode);
 }