Beispiel #1
0
$path = 'uploads/midi/' . $file;
$name = p_string('title');
try {
    $tracks = array();
    $trackNoteCount = array();
    $currentTrack = 0;
    $trackNoteCount[$currentTrack] = 0;
    $tracks[$currentTrack] = '[Untitled Track]';
    $parser = new FileParser();
    $parser->load($path);
    $time = 0;
    $maxTime = -1;
    $noteArray = array();
    $noteOnTime = array();
    $timeDivision = 0;
    while ($chunk = $parser->parse()) {
        if ($chunk instanceof Delta) {
            $a = $chunk->getData();
            $time = $time + $a[0];
        } else {
            if ($chunk instanceof SetTempoEvent) {
                $bpm = $chunk->bpm;
            } else {
                if ($chunk instanceof NoteOnEvent) {
                    if ($currentTrack == -1) {
                        $currentTrack++;
                        $tracks[$currentTrack] = '[Untitled Track]';
                        $trackNoteCount[$currentTrack] = 0;
                    }
                    $noteTime = $time / ($timeDivision / 4);
                    $noteArray[] = array((int) $noteTime, str_replace(array("7", "8"), "6", \Midi\Util\Note::getNoteName($chunk->param1 + 12)), 1);