private function getStroke(Beat $beat, Beat $previous = null, array $stroke) { $direction = $beat->getStroke()->getDirection(); if ($previous === null || !($direction == Stroke::STROKE_NONE && $previous->getStroke()->getDirection() == Stroke::STROKE_NONE)) { if ($direction == Stroke::STROKE_NONE) { for ($i = 0; $i < count($stroke); $i++) { $stroke[$i] = 0; } } else { $stringUseds = 0; $stringCount = 0; for ($vIndex = 0; $vIndex < $beat->countVoices(); $vIndex++) { $voice = $beat->getVoice($vIndex); for ($nIndex = 0; $nIndex < $voice->countNotes(); $nIndex++) { $note = $voice->getNote($nIndex); if (!$note->isTiedNote()) { $stringUseds |= 0x1 << $note->getString() - 1; $stringCount++; } } } if ($stringCount > 0) { $strokeMove = 0; $strokeIncrement = $beat->getStroke()->getIncrementTime($beat); for ($i = 0; $i < count($stroke); $i++) { $index = $direction == Stroke::STROKE_DOWN ? count($stroke) - 1 - $i : $i; if (($stringUseds & 0x1 << $index) != 0) { $stroke[$index] = $strokeMove; $strokeMove += $strokeIncrement; } } } } } return $stroke; }
private function writeMeasure(Measure $measure, $changeTempo) { for ($v = 0; $v < 2; $v++) { $voices = array(); for ($m = 0; $m < $measure->countBeats(); $m++) { $beat = $measure->getBeat($m); if ($v < $beat->countVoices()) { $voice = $beat->getVoice($v); if (!$voice->isEmpty()) { $voices[] = $voice; } } } if (count($voices) > 0) { $this->writeInt(count($voices)); for ($i = 0; $i < count($voices); $i++) { $voice = $voices[$i]; $this->writeBeat($voice, $voice->getBeat(), $measure, $changeTempo && $i == 0); } } else { $count = $measure->getTimeSignature()->getNumerator(); $beat = new Beat(); if ($v < $beat->countVoices()) { $voice = $beat->getVoice($v); $voice->getDuration()->setValue($measure->getTimeSignature()->getDenominator()->getValue()); $voice->setEmpty(true); $this->writeInt($count); for ($i = 0; $i < $count; $i++) { $this->writeBeat($voice, $voice->getBeat(), $measure, $changeTempo && $i == 0); } } } } }