-
Notifications
You must be signed in to change notification settings - Fork 3
/
print-notes.php
28 lines (23 loc) · 884 Bytes
/
print-notes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
require_once dirname(dirname(__FILE__)) . '/vendor/autoload.php';
use \Tmont\Midi\Parsing\FileParser;
use \Tmont\Midi\Event as Event;
use \Tmont\Midi\Util\Note;
$file = dirname(__FILE__) . '/And_We_Die_Young.mid';
$parser = new FileParser();
$parser->load($file);
$currentTrackName = null;
while ($chunk = $parser->parse()) {
if ($chunk instanceof Event\TrackNameEvent) {
$currentTrackName = $chunk->getParamDescription();
} else if ($chunk instanceof Event\NoteOnEvent) {
list($channel, $noteNumber, $velocity) = $chunk->getData();
if ($velocity) {
//MIDI generators often use a NOTE ON event with a velocity of 0
//to stop playing a note in lieu of a NOTE OFF event
$noteName = Note::getNoteName($noteNumber);
echo $currentTrackName . ': [' . $channel . '] ' . $noteName .
' (velocity=' . $velocity . ')' . PHP_EOL;
}
}
}