Skip to content

Commit 62a89fe

Browse files
committed
Fix MIDI time errors
1 parent a11a61d commit 62a89fe

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/PhpTabs/Writer/Midi/MidiSequenceParser.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class MidiSequenceParser
3939

4040
private $song;
4141
private $flags;
42-
// @todo check that this test value fix
4342
private $infoTrack;
4443
private $metronomeTrack;
4544
private $metronomeChannelId;
@@ -145,7 +144,7 @@ private function createTrack(MidiSequenceHelper $helper, Track $track): void
145144
if ($channel !== null) {
146145
$previous = null;
147146

148-
$this->addBend($helper, $track->getNumber(), Duration::QUARTER_TIME, self::DEFAULT_BEND, $channel->getId(), false);
147+
$this->addBend($helper, $track->getNumber(), Duration::QUARTER_TIME, self::DEFAULT_BEND, $track->getChannelId(), false);
149148
$this->makeChannel($helper, $channel, $track->getNumber());
150149

151150
$mCount = count($helper->getMeasureHelpers());
@@ -255,7 +254,7 @@ private function makeNotes(
255254
$tick = $start;
256255
while (true) {
257256
if ($tick + 10 >= ($start + $duration)) {
258-
break ;
257+
break;
259258
} elseif (($tick + $tpLength) >= ($start + $duration)) {
260259
$tpLength = ((($start + $duration) - $tick) - 1);
261260
}

src/PhpTabs/Writer/Midi/MidiWriter.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,17 @@ private function writeTrack(MidiTrack $track, $out): int
115115
*/
116116
private function writeEvent(MidiEvent $event, MidiEvent $previous = null, $out = null): int
117117
{
118+
// @todo Remove this lines when timing will be patched
119+
// time should not be < 0
120+
$time = $previous !== null
121+
? ($event->getTick() - $previous->getTick())
122+
: 0;
123+
if ($time < 0) {
124+
$time = abs($event->getTick() - $previous->getTick());
125+
}
126+
118127
$length = $this->writeVariableLengthQuantity(
119-
$previous !== null
120-
? ($event->getTick() - $previous->getTick())
121-
: 0,
128+
$time,
122129
$out
123130
);
124131

0 commit comments

Comments
 (0)