Ejemplo n.º 1
0
 private function writeMeasureHeader(MeasureHeader $measure, TimeSignature $timeSignature)
 {
     $flags = 0;
     if ($measure->getNumber() == 1 || $measure->getTimeSignature()->getNumerator() != $timeSignature->getNumerator()) {
         $flags |= 0x1;
     }
     if ($measure->getNumber() == 1 || $measure->getTimeSignature()->getDenominator()->getValue() != $timeSignature->getDenominator()->getValue()) {
         $flags |= 0x2;
     }
     if ($measure->isRepeatOpen()) {
         $flags |= 0x4;
     }
     if ($measure->getRepeatClose() > 0) {
         $flags |= 0x8;
     }
     if ($measure->hasMarker()) {
         $flags |= 0x20;
     }
     $this->writeUnsignedByte($flags);
     if (($flags & 0x1) != 0) {
         $this->writeByte($measure->getTimeSignature()->getNumerator());
     }
     if (($flags & 0x2) != 0) {
         $this->writeByte($measure->getTimeSignature()->getDenominator()->getValue());
     }
     if (($flags & 0x8) != 0) {
         $this->writeByte($measure->getRepeatClose());
     }
     if (($flags & 0x20) != 0) {
         $this->writeMarker($measure->getMarker());
     }
 }
Ejemplo n.º 2
0
 public function addMetronome(MidiSequenceHelper $sHelper, MeasureHeader $header, $startMove)
 {
     if (($this->flags & MidiWriter::ADD_METRONOME) != 0) {
         if ($this->metronomeChannelId >= 0) {
             $start = $startMove + $header->getStart();
             $length = $header->getTimeSignature()->getDenominator()->getTime();
             for ($i = 1; $i <= $header->getTimeSignature()->getNumerator(); $i++) {
                 $this->makeNote($sHelper, $this->getMetronomeTrack(), self::DEFAULT_METRONOME_KEY, $start, $length, Velocities::_DEFAULT, $this->metronomeChannelId, false);
                 $start += $length;
             }
         }
     }
 }
Ejemplo n.º 3
0
 private function getHeader($tick)
 {
     $realTick = $tick >= Duration::QUARTER_TIME ? $tick : Duration::QUARTER_TIME;
     foreach ($this->headers as $header) {
         if ($realTick >= $header->getStart() && $realTick < $header->getStart() + $header->getLength()) {
             return $header;
         }
     }
     $last = $this->getLastHeader();
     $header = new MeasureHeader();
     $header->setNumber($last !== null ? $last->getNumber() + 1 : 1);
     $header->setStart($last !== null ? $last->getStart() + $last->getLength() : Duration::QUARTER_TIME);
     $header->getTempo()->setValue($last !== null ? $last->getTempo()->getValue() : 120);
     if ($last !== null) {
         $header->getTimeSignature()->copyFrom($last->getTimeSignature());
     } else {
         $header->getTimeSignature()->setNumerator(4);
         $header->getTimeSignature()->getDenominator()->setValue(Duration::QUARTER);
     }
     $this->headers[] = $header;
     if ($realTick >= $header->getStart() && $realTick < $header->getStart() + $header->getLength()) {
         return $header;
     }
     return $this->getHeader($realTick);
 }
Ejemplo n.º 4
0
 private function writeMeasureHeader(MeasureHeader $measure, TimeSignature $timeSignature)
 {
     $flags = 0;
     if ($measure->getNumber() == 1) {
         $flags |= 0x40;
     }
     if ($measure->getNumber() == 1 || !$measure->getTimeSignature()->isEqual($timeSignature)) {
         $flags |= 0x1;
         $flags |= 0x2;
     }
     if ($measure->isRepeatOpen()) {
         $flags |= 0x4;
     }
     if ($measure->getRepeatClose() > 0) {
         $flags |= 0x8;
     }
     if ($measure->getRepeatAlternative() > 0) {
         $flags |= 0x10;
     }
     if ($measure->hasMarker()) {
         $flags |= 0x20;
     }
     $this->writeUnsignedByte($flags);
     if (($flags & 0x1) != 0) {
         $this->writeByte($measure->getTimeSignature()->getNumerator());
     }
     if (($flags & 0x2) != 0) {
         $this->writeByte($measure->getTimeSignature()->getDenominator()->getValue());
     }
     if (($flags & 0x8) != 0) {
         $this->writeByte($measure->getRepeatClose() + 1);
     }
     if (($flags & 0x20) != 0) {
         $this->writeMarker($measure->getMarker());
     }
     if (($flags & 0x10) != 0) {
         $this->writeByte($measure->getRepeatAlternative());
     }
     if (($flags & 0x40) != 0) {
         $this->skipBytes(2);
     }
     if (($flags & 0x1) != 0) {
         $this->writeBytes($this->makeEighthNoteBytes($measure->getTimeSignature()));
     }
     if (($flags & 0x10) == 0) {
         $this->writeByte(0);
     }
     if ($measure->getTripletFeel() == MeasureHeader::TRIPLET_FEEL_NONE) {
         $this->writeByte(0);
     } else {
         if ($measure->getTripletFeel() == MeasureHeader::TRIPLET_FEEL_EIGHTH) {
             $this->writeByte(1);
         } else {
             if ($measure->getTripletFeel() == MeasureHeader::TRIPLET_FEEL_SIXTEENTH) {
                 $this->writeByte(2);
             }
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Reads a mesure header
  * 
  * @param integer $number
  * @param Song $song
  * @param TimeSignature $timeSignature
  * @param integer $tempoValue
  * 
  * @return MeasureHeader
  */
 public function readMeasureHeader($index, TimeSignature $timeSignature, $tempoValue = 120)
 {
     $flags = $this->reader->readUnsignedByte();
     $header = new MeasureHeader();
     $header->setNumber($index + 1);
     $header->setStart(0);
     $header->getTempo()->setValue($tempoValue);
     $header->setRepeatOpen(($flags & 0x4) != 0);
     if (($flags & 0x1) != 0) {
         $timeSignature->setNumerator($this->reader->readByte());
     }
     if (($flags & 0x2) != 0) {
         $timeSignature->getDenominator()->setValue($this->reader->readByte());
     }
     $header->getTimeSignature()->copyFrom($timeSignature);
     if (($flags & 0x8) != 0) {
         $header->setRepeatClose(($this->reader->readByte() & 0xff) - 1);
     }
     if (($flags & 0x20) != 0) {
         $header->setMarker($this->reader->factory('GuitarProMarker')->readMarker($header->getNumber()));
     }
     if (($flags & 0x10) != 0) {
         $header->setRepeatAlternative($this->reader->readUnsignedByte());
     }
     if (($flags & 0x40) != 0) {
         $this->reader->setKeySignature($this->reader->factory('GuitarProKeySignature')->readKeySignature());
         $this->reader->skip(1);
     }
     if (($flags & 0x1) != 0 || ($flags & 0x2) != 0) {
         $this->reader->skip(4);
     }
     if (($flags & 0x10) == 0) {
         $this->reader->skip(1);
     }
     $tripletFeel = $this->reader->readByte();
     if ($tripletFeel == 1) {
         $header->setTripletFeel(MeasureHeader::TRIPLET_FEEL_EIGHTH);
     } else {
         if ($tripletFeel == 2) {
             $header->setTripletFeel(MeasureHeader::TRIPLET_FEEL_SIXTEENTH);
         } else {
             $header->setTripletFeel(MeasureHeader::TRIPLET_FEEL_NONE);
         }
     }
     return $header;
 }
Ejemplo n.º 6
0
 /**
  * Reads a mesure header
  * 
  * @param integer $number
  * @param Song $song
  * @param TimeSignature $timeSignature
  * @param integer $tempoValue
  * 
  * @return MeasureHeader
  */
 public function readMeasureHeader($number, Song $song, TimeSignature $timeSignature, $tempoValue = 120)
 {
     $flags = $this->reader->readUnsignedByte();
     $header = new MeasureHeader();
     $header->setNumber($number);
     $header->setStart(0);
     $header->getTempo()->setValue($tempoValue);
     $header->setTripletFeel($this->reader->getTripletFeel());
     $header->setRepeatOpen(($flags & 0x4) != 0);
     if (($flags & 0x1) != 0) {
         $timeSignature->setNumerator($this->reader->readByte());
     }
     if (($flags & 0x2) != 0) {
         $timeSignature->getDenominator()->setValue($this->reader->readByte());
     }
     $header->getTimeSignature()->copyFrom($timeSignature);
     if (($flags & 0x8) != 0) {
         $header->setRepeatClose($this->reader->readByte());
     }
     if (($flags & 0x10) != 0) {
         $header->setRepeatAlternative($this->reader->factory('GuitarPro3RepeatAlternative')->parseRepeatAlternative($song, $number));
     }
     if (($flags & 0x20) != 0) {
         $header->setMarker($this->reader->factory('GuitarProMarker')->readMarker($number));
     }
     if (($flags & 0x40) != 0) {
         $this->reader->setKeySignature($this->reader->factory('GuitarProKeySignature')->readKeySignature());
         $this->reader->skip(1);
     }
     return $header;
 }