require __DIR__ . "/../../vendor/autoload.php"; require __DIR__ . "/../../src/MIDI/midi.class.php"; $admin = new LTE\AdminLte2(); $admin->title("MIDI"); echo $admin; ?> <section class="container"> <?php $midi = new Midi(); $files = glob(__DIR__ . "/../../midifiles/*.mid"); shuffle($files); $file = $files[0]; $midi->importMid($file); $track = $midi->getTrack(0); echo "<h1>" . basename($file) . "</h1>\n"; echo "<pre>"; $tempo = $midi->getTempo(); $bpm = $midi->getBpm(); //returns tempo as beats per minute (0 if tempo not set). $timebase = $midi->getTimebase(); //returns timebase value. $trackCount = $midi->getTrackCount(); //returns number of tracks. $duration = $midi->getDuration(); //in sec echo "tempo={$tempo}\n"; echo "BPM={$bpm}\n"; echo "duration={$duration} sec\n"; echo "timebase={$timebase}\n"; echo "trackCount={$trackCount}\n"; //print_r($track);
copy($file, $path . "/song.midi"); require '../scripts/midi.class.php'; require '../scripts/ConvertCharset.class.php'; $NewEncoding = new ConvertCharset(); $midi = new Midi(); $midi->importMid($file, 0); $track = $midi->getTrack(0); // list of meta events that we are interested in (adjust!) $texttypes = array('Text', 'Copyright', 'TrkName', 'InstrName', 'Lyric', 'Marker', 'Cue'); $lyric = array(); // poustawianie czasów trwania foreach ($track as $msgStr) { //print_r($msgStr); $msg = explode(' ', $msgStr); if ($msg[1] == 'Meta' && in_array($msg[2], $texttypes)) { $milis = (int) ($msg[0] * $midi->getTempo() / $midi->getTimebase() / 1000); $text = $NewEncoding->Convert(substr($msgStr, strpos($msgStr, '"')), "windows-1250", "utf-8"); $text = str_replace("_", " ", $text); $text = str_replace("\n", "/", $text); $text = str_replace("\r", "/", $text); $text = str_replace("//", "/", $text); $text = str_replace("//", "/", $text); $text = substr($text, 1, strlen($text) - 2); array_push($lyric, array($milis, 0, $text)); } } define("SYLABE_TIME_MIN", 50); define("SYLABE_TIME_MAX", 1000); define("SYLABE_GAP_MIN", 100); $oldObjs = null; foreach ($lyric as $arrKey => $newObjs) {
//returns tempo as beats per minute (0 if tempo not set). $f['timebase'] = $midi->getTimebase(); //returns timebase value. $f['trackCount'] = $midi->getTrackCount(); //returns number of tracks. $dat['files'][] = $f; } exit(json_encode($dat)); case 'fileInfo': $dat['post'] = $_POST; $midi = new Midi(); $midi->importMid(__DIR__ . "/../../midifiles/" . $_POST['filename']); //$track = $midi->getTrack(0); $dat['bpm'] = $midi->getBpm(); //returns tempo as beats per minute (0 if tempo not set). $dat['timebase'] = $midi->getTimebase(); //returns timebase value. $dat['trackCount'] = $midi->getTrackCount(); //returns number of tracks. $track = $midi->getTrack(0); // list of meta events that we are interested in (adjust!) //$texttypes = array('Text','Copyright','TrkName','InstrName','Lyric','Marker','Cue'); $texttypes = array('TrkName'); foreach ($track as $msgStr) { $msg = explode(' ', $msgStr); if ($msg[1] == 'Meta' && $msg[2] == 'TrkName') { //print_r($msgStr);//ex : 0 Meta TrkName "A Message to Rudy by THE SPECIALS" //$dat['meta'][]=$msg[2].': '.substr($msgStr,strpos($msgStr,'"')); $dat['trackName'] = trim(explode('TrkName', $msgStr)[1]); } }