<?php $p = $_POST; $tt = isset($p['tt']) ? $p['tt'] : 0; $xm = isset($p['xm']) ? $p['xm'] : 0; $file = isset($_FILES['mid_upload']) && $_FILES['mid_upload']['tmp_name'] != '' ? $_FILES['mid_upload']['tmp_name'] : ''; if ($file != '') { require 'midi.class.php'; $midi = new Midi(); $midi->importMid($file); $xml = $midi->getXml($tt); $fn = $_FILES['mid_upload']['name']; $a = explode('.', $fn); array_pop($a); array_push($a, "xml"); $xn = implode('.', $a); //$xn = str_replace('.mid','.xml',$fn); if ($xm == 1) { header('Content-Type: application/octetstream'); header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Content-Disposition: attachment; filename="' . $xn . '"'); header('Pragma: no-cache'); echo $xml; exit; } } ?> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Midi2Xml</title>
$f['name'] = basename($file); $f['size'] = filesize($file); // get midifile info // $f['bpm'] = $midi->getBpm(); //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"
$file = isset($_FILES['file_kar']) && $_FILES['file_kar']['tmp_name'] != '' ? $_FILES['file_kar']['tmp_name'] : ''; if ($file != '') { $par_dir = getCode(); // skopiowanie pliku $path = "../wap/get/" . $par_dir; // TODO: sprawdzi, czy taki kod już jest w filesystemie if (mkdir($path) == FALSE) { $reason = M1K0_REASON_NO_DIR; $par_request = NULL; } else { 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);
private function getTracks() { if (!isset($privateData['tracks'])) { $fretIndex = array(60 => 'easy', 61 => 'easy', 62 => 'easy', 63 => 'easy', 64 => 'easy', 72 => 'medium', 73 => 'medium', 74 => 'medium', 75 => 'medium', 76 => 'medium', 84 => 'hard', 85 => 'hard', 86 => 'hard', 87 => 'hard', 88 => 'hard', 96 => 'expert', 97 => 'expert', 98 => 'expert', 99 => 'expert', 100 => 'expert'); $difficulties = array_unique(array_values($fretIndex)); $midi = new Midi(); // $midi->importMid( 'abeautifullie/notes.mid' ); // $midi->importMid( 'acdc_thunderstruck/notes.mid' ); $midi->importMid($this->directoryPath . DIRECTORY_SEPARATOR . 'notes.mid'); $xmlString = $midi->getXml(); $xml = simplexml_load_string($xmlString); foreach ($xml->Track as $track) { $trackName = (string) $track->Event[0]->TrackName; if (substr($trackName, 0, 5) == 'PART ') { $trackName = ucfirst(strtolower(substr($trackName, 5))); $parts[] = $trackName; // disabled difficulty levels for track $t0 = $track->xpath('Event[Absolute=0 and child::NoteOn]'); foreach ($t0 as $event) { $note = (int) $event->NoteOn[0]['Note']; if (!isset($disabled[$trackName])) { $disabled[$trackName] = array(); } // unknown note, let's skip it for now if (!isset($fretIndex[$note])) { break; } $difficulty = $fretIndex[$note]; if (!isset($disabled[$trackName][$difficulty])) { $disabled[$trackName][$difficulty] = array(); } $disabled[$trackName][$difficulty][$note] = true; } } } // display available difficulties for each track $tracks = array(); foreach ($parts as $track) { $trackDifficulties = array(); foreach ($difficulties as $difficulty) { if (!isset($disabled[$track][$difficulty])) { $trackDifficulties[] = $difficulty; } } if (count($trackDifficulties) > 0) { $currentTrack = new FOFSongTrack($track); $currentTrack->difficulties = $trackDifficulties; $tracks[] = $currentTrack; } } } return $privateData['tracks']; }