private function writeGrace(EffectGrace $grace) { if ($grace->isDead()) { $this->writeUnsignedByte(255); } else { $this->writeUnsignedByte($grace->getFret()); } $this->writeUnsignedByte(intval(($grace->getDynamic() - Velocities::MIN_VELOCITY) / Velocities::VELOCITY_INCREMENT + 1)); if ($grace->getTransition() == EffectGrace::TRANSITION_NONE) { $this->writeUnsignedByte(0); } else { if ($grace->getTransition() == EffectGrace::TRANSITION_SLIDE) { $this->writeUnsignedByte(1); } else { if ($grace->getTransition() == EffectGrace::TRANSITION_BEND) { $this->writeUnsignedByte(2); } else { if ($grace->getTransition() == EffectGrace::TRANSITION_HAMMER) { $this->writeUnsignedByte(3); } } } } $this->writeUnsignedByte($grace->getDuration()); }
/** * Reads GraceEffect * * @param NoteEffect $effect */ public function readGrace(NoteEffect $effect) { $fret = $this->readUnsignedByte(); $grace = new EffectGrace(); $grace->setOnBeat(false); $grace->setDead($fret == 255); $grace->setFret(!$grace->isDead() ? $fret : 0); $grace->setDynamic(Velocities::MIN_VELOCITY + Velocities::VELOCITY_INCREMENT * $this->readUnsignedByte() - Velocities::VELOCITY_INCREMENT); $transition = $this->readUnsignedByte(); if ($transition == 0) { $grace->setTransition(EffectGrace::TRANSITION_NONE); } else { if ($transition == 1) { $grace->setTransition(EffectGrace::TRANSITION_SLIDE); } else { if ($transition == 2) { $grace->setTransition(EffectGrace::TRANSITION_BEND); } else { if ($transition == 3) { $grace->setTransition(EffectGrace::TRANSITION_HAMMER); } } } } $grace->setDuration($this->readUnsignedByte()); $effect->setGrace($grace); }
/** * Reads EffectGrace * * @param NoteEffect $effect */ private function readGrace(NoteEffect $effect) { $fret = $this->reader->readUnsignedByte(); $dynamic = $this->reader->readUnsignedByte(); $transition = $this->reader->readByte(); $duration = $this->reader->readUnsignedByte(); $flags = $this->reader->readUnsignedByte(); $grace = new EffectGrace(); $grace->setFret($fret); $grace->setDynamic(Velocities::MIN_VELOCITY + Velocities::VELOCITY_INCREMENT * $dynamic - Velocities::VELOCITY_INCREMENT); $grace->setDuration($duration); $grace->setDead(($flags & 0x1) != 0); $grace->setOnBeat(($flags & 0x2) != 0); if ($transition == 0) { $grace->setTransition(EffectGrace::TRANSITION_NONE); } else { if ($transition == 1) { $grace->setTransition(EffectGrace::TRANSITION_SLIDE); } else { if ($transition == 2) { $grace->setTransition(EffectGrace::TRANSITION_BEND); } else { if ($transition == 3) { $grace->setTransition(EffectGrace::TRANSITION_HAMMER); } } } } $effect->setGrace($grace); }