private function writeBeat(Beat $beat, Measure $measure, $changeTempo) { $voice = $beat->getVoice(0); $duration = $voice->getDuration(); $flags = 0; if ($duration->isDotted() || $duration->isDoubleDotted()) { $flags |= 0x1; } if (!$duration->getDivision()->isEqual(DivisionType::normal())) { $flags |= 0x20; } if ($beat->isTextBeat()) { $flags |= 0x4; } if ($changeTempo) { $flags |= 0x10; } $effect = null; if ($voice->isRestVoice()) { $flags |= 0x40; } else { if ($voice->countNotes() > 0) { $note = $voice->getNote(0); $effect = $note->getEffect(); if ($effect->isVibrato() || $effect->isTremoloBar() || $effect->isTapping() || $effect->isSlapping() || $effect->isPopping() || $effect->isHarmonic() || $effect->isFadeIn() || $beat->getStroke()->getDirection() != Stroke::STROKE_NONE) { $flags |= 0x8; } } } $this->writeUnsignedByte($flags); if (($flags & 0x40) != 0) { $this->writeUnsignedByte(2); } $this->writeByte($this->parseDuration($duration)); if (($flags & 0x20) != 0) { $this->writeInt($duration->getDivision()->getEnters()); } if (($flags & 0x4) != 0) { $this->writeText($beat->getText()); } if (($flags & 0x8) != 0) { $this->writeBeatEffects($beat, $effect); } if (($flags & 0x10) != 0) { $this->writeMixChange($measure->getTempo()); } $stringFlags = 0; if (!$voice->isRestVoice()) { for ($i = 0; $i < $voice->countNotes(); $i++) { $playedNote = $voice->getNote($i); $string = 7 - $playedNote->getString(); $stringFlags |= 1 << $string; } } $this->writeUnsignedByte($stringFlags); for ($i = 6; $i >= 0; $i--) { if (($stringFlags & 1 << $i) != 0) { for ($n = 0; $n < $voice->countNotes(); $n++) { $playedNote = $voice->getNote($n); if ($playedNote->getString() == 6 - $i + 1) { $this->writeNote($playedNote); break; } } } } }
private function writeBeat(Voice $voice, Beat $beat, Measure $measure, $changeTempo) { $duration = $voice->getDuration(); $effect = new NoteEffect(); for ($i = 0; $i < $voice->countNotes(); $i++) { $playedNote = $voice->getNote($i); if ($playedNote->getEffect()->isFadeIn()) { $effect->setFadeIn(true); } if ($playedNote->getEffect()->isTremoloBar()) { $effect->setTremoloBar(clone $playedNote->getEffect()->getTremoloBar()); } if ($playedNote->getEffect()->isTapping()) { $effect->setTapping(true); } if ($playedNote->getEffect()->isSlapping()) { $effect->setSlapping(true); } if ($playedNote->getEffect()->isPopping()) { $effect->setPopping(true); } } $flags = 0; if ($duration->isDotted() || $duration->isDoubleDotted()) { $flags |= 0x1; } if ($voice->getIndex() == 0 && $beat->isChordBeat()) { $flags |= 0x2; } if ($voice->getIndex() == 0 && $beat->isTextBeat()) { $flags |= 0x4; } if ($beat->getStroke()->getDirection() != Stroke::STROKE_NONE) { $flags |= 0x8; } else { if ($effect->isTremoloBar() || $effect->isTapping() || $effect->isSlapping() || $effect->isPopping() || $effect->isFadeIn()) { $flags |= 0x8; } } if ($changeTempo) { $flags |= 0x10; } if (!$duration->getDivision()->isEqual(DivisionType::normal())) { $flags |= 0x20; } if ($voice->isEmpty() || $voice->isRestVoice()) { $flags |= 0x40; } $this->writeUnsignedByte($flags); if (($flags & 0x40) != 0) { $this->writeUnsignedByte($voice->isEmpty() ? 0 : 0x2); } $this->writeByte($this->parseDuration($duration)); if (($flags & 0x20) != 0) { $this->writeInt($duration->getDivision()->getEnters()); } if (($flags & 0x2) != 0) { $this->writeChord($beat->getChord()); } if (($flags & 0x4) != 0) { $this->writeText($beat->getText()); } if (($flags & 0x8) != 0) { $this->writeBeatEffects($beat, $effect); } if (($flags & 0x10) != 0) { $this->writeMixChange($measure->getTempo()); } $stringFlags = 0; if (!$voice->isRestVoice()) { for ($i = 0; $i < $voice->countNotes(); $i++) { $playedNote = $voice->getNote($i); $string = 7 - $playedNote->getString(); $stringFlags |= 1 << $string; } } $this->writeUnsignedByte($stringFlags); for ($i = 6; $i >= 0; $i--) { if (($stringFlags & 1 << $i) != 0) { for ($n = 0; $n < $voice->countNotes(); $n++) { $playedNote = $voice->getNote($n); if ($playedNote->getString() == 6 - $i + 1) { $this->writeNote($playedNote); break; } } } } $this->skipBytes(2); }