private function adjustTrack(Track $track) { $measures = $track->getMeasures(); foreach ($measures as $measure) { $this->process($measure); } }
/** * Reads Channel informations * * @param Song $song * @param Track $track * @param array $channels */ public function readChannel(Song $song, Track $track, $channels) { $gChannel1 = $this->reader->readInt() - 1; $gChannel2 = $this->reader->readInt() - 1; if ($gChannel1 >= 0 && $gChannel1 < count($channels)) { $channel = new Channel(); $gChannel1Param = new ChannelParameter(); $gChannel2Param = new ChannelParameter(); $gChannel1Param->setKey("channel-1"); $gChannel1Param->setValue("{$gChannel1}"); $gChannel2Param->setKey("channel-2"); $gChannel2Param->setValue($gChannel1 != 9 ? "{$gChannel2}" : "{$gChannel1}"); $channel->copyFrom($channels[$gChannel1]); for ($i = 0; $i < $song->countChannels(); $i++) { $channelAux = $song->getChannel($i); for ($n = 0; $n < $channelAux->countParameters(); $n++) { $channelParameter = $channelAux->getParameter($n); if ($channelParameter->getKey() == "{$gChannel1}") { if ("{$gChannel1}" == $channelParameter->getValue()) { $channel->setChannelId($channelAux->getChannelId()); } } } } if ($channel->getChannelId() <= 0) { $channel->setChannelId($song->countChannels() + 1); $channel->setName($this->createChannelNameFromProgram($song, $channel)); $channel->addParameter($gChannel1Param); $channel->addParameter($gChannel2Param); $song->addChannel($channel); } $track->setChannelId($channel->getChannelId()); } }
/** * @param Track $track * @return integer Clef of $track */ public function getClef(Track $track) { if (!$this->isPercussionChannel($track->getSong(), $track->getChannelId())) { $strings = $track->getStrings(); foreach ($strings as $string) { if ($string->getValue() <= 34) { return Measure::CLEF_BASS; } } } return Measure::CLEF_TREBLE; }
/** * Reads Track informations * @param Song $song * @param integer $number * @param array $channels an array of Channel objects * @param Lyric $lyrics * * @return Track */ public function readTrack(Song $song, $number, $channels, Lyric $lyrics) { $track = new Track(); $track->setSong($song); $track->setNumber($number); $track->setLyrics($lyrics); $this->reader->readUnsignedByte(); $track->setName($this->reader->readStringByte(40)); $stringCount = $this->reader->readInt(); for ($i = 0; $i < 7; $i++) { $tuning = $this->reader->readInt(); if ($stringCount > $i) { $string = new TabString(); $string->setNumber($i + 1); $string->setValue($tuning); $track->addString($string); } } $this->reader->readInt(); $this->reader->factory('GuitarProChannel')->readChannel($song, $track, $channels); $this->reader->readInt(); $track->setOffset($this->reader->readInt()); $this->reader->factory('GuitarProColor')->readColor($track->getColor()); return $track; }
/** * @param integer $string String on which note has started * @param Track $track * * @return integer tied note value */ public function getTiedNoteValue($string, Track $track) { $measureCount = $track->countMeasures(); if ($measureCount > 0) { for ($m = $measureCount - 1; $m >= 0; $m--) { $measure = $track->getMeasure($m); for ($b = $measure->countBeats() - 1; $b >= 0; $b--) { $beat = $measure->getBeat($b); $voice = $beat->getVoice(0); for ($n = 0; $n < $voice->countNotes(); $n++) { $note = $voice->getNote($n); if ($note->getString() == $string) { return $note->getValue(); } } } } } return -1; }
/** * Reads some Beat informations * * @param integer $start * @param Measure $measure * @param Track $track * @param Tempo $tempo * @param integer $voiceIndex * * @return integer $time A duration time */ public function readBeat($start, Measure $measure, Track $track, Tempo $tempo, $voiceIndex) { $flags = $this->reader->readUnsignedByte(); $beat = $measure->getBeatByStart($start); $voice = $beat->getVoice($voiceIndex); if (($flags & 0x40) != 0) { $beatType = $this->reader->readUnsignedByte(); $voice->setEmpty(($beatType & 0x2) == 0); } $duration = $this->reader->factory('GuitarProDuration')->readDuration($flags); $effect = new NoteEffect(); if (($flags & 0x2) != 0) { $this->reader->factory('GuitarPro5Chord')->readChord($track->countStrings(), $beat); } if (($flags & 0x4) != 0) { $this->reader->factory('GuitarProText')->readText($beat); } if (($flags & 0x8) != 0) { $this->reader->factory('GuitarPro4BeatEffects')->readBeatEffects($beat, $effect); } if (($flags & 0x10) != 0) { $this->reader->factory('GuitarPro5MixChange')->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('GuitarPro5Note')->readNote($string, $track, clone $effect); $voice->addNote($note); } $voice->getDuration()->copyFrom($duration); } $this->reader->skip(); if (($this->reader->readByte() & 0x8) != 0) { $this->reader->skip(); } return !$voice->isEmpty() ? $duration->getTime() : 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(); }
private function writeTrack(Track $track) { $channel = $this->getChannelRoute($track->getChannelId()); $flags = 0; if ($this->isPercussionChannel($track->getSong(), $track->getChannelId())) { $flags |= 0x1; } $this->writeUnsignedByte($flags); $this->writeStringByte($track->getName(), 40); $this->writeInt(count($track->getStrings())); for ($i = 0; $i < 7; $i++) { $value = 0; if (count($track->getStrings()) > $i) { $string = $track->getStrings()[$i]; $value = $string->getValue(); } $this->writeInt($value); } $this->writeInt(1); $this->writeInt($channel->getChannel1() + 1); $this->writeInt($channel->getChannel2() + 1); $this->writeInt(24); $this->writeInt(min(max($track->getOffset(), 0), 12)); $this->writeColor($track->getColor()); }
private function getPreviousNote(MidiSequenceHelper $sHelper, Note $note, Track $track, $mIndex, $bIndex, $breakAtRest) { $nextBIndex = $bIndex; for ($m = $mIndex; $m >= 0; $m--) { $mHelper = $sHelper->getMeasureHelper($m); $measure = $track->getMeasure($mHelper->getIndex()); if ($this->sHeader == -1 || $this->sHeader <= $measure->getNumber()) { $nextBIndex = $nextBIndex < 0 ? $measure->countBeats() : $nextBIndex; for ($b = $nextBIndex - 1; $b >= 0; $b--) { $beat = $measure->getBeat($b); $voice = $beat->getVoice($note->getVoice()->getIndex()); if (!$voice->isEmpty()) { $noteCount = $voice->countNotes(); for ($n = 0; $n < $noteCount; $n++) { $current = $voice->getNote($n); if ($current->getString() == $note->getString()) { return new MidiNoteHelper($mHelper, $current); } } if ($breakAtRest) { return null; } } } } $nextBIndex = -1; } return null; }
private function getTrack($number) { foreach ($this->tracks as $track) { if ($track->getNumber() == $number) { return $track; } } $track = new Track(); $track->setNumber($number); $track->setChannelId(-1); $track->getColor()->setR(Color::$red[0]); $track->getColor()->setG(Color::$red[1]); $track->getColor()->setB(Color::$red[2]); $this->tracks[] = $track; return $track; }
private function writeTrack(Track $track) { $channel = $this->getChannelRoute($track->getChannelId()); $flags = 0; if ($this->isPercussionChannel($track->getSong(), $track->getChannelId())) { $flags |= 0x1; } $this->writeUnsignedByte($flags); $this->writeUnsignedByte(8 | $flags); $this->writeStringByte($track->getName(), 40); $this->writeInt(count($track->getStrings())); for ($i = 0; $i < 7; $i++) { $value = 0; if (count($track->getStrings()) > $i) { $string = $track->getStrings()[$i]; $value = $string->getValue(); } $this->writeInt($value); } $this->writeInt(1); $this->writeInt($channel->getChannel1() + 1); $this->writeInt($channel->getChannel2() + 1); $this->writeInt(24); $this->writeInt($track->getOffset()); $this->writeColor($track->getColor()); $this->writeBytes(array(67, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1)); }