-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.php
50 lines (38 loc) · 1.19 KB
/
convert.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
use MusicXML\MusicXMLFromMidi;
use MusicXML\Util\MXL;
require_once "inc.lib/autoload.php";
function fileExtension($name)
{
$n = strrpos($name, '.');
return ($n === false) ? '' : substr($name, $n + 1);
}
$fileList = array();
$directory = __DIR__ . "/test-files";
$items = glob($directory . '/*');
foreach ($items as $item) {
if (is_file($item)) {
$fileList[] = $item;
}
}
$fileList = array(__DIR__."/test-files/1001 Car.mid");
// Iterate over directories
foreach ($fileList as $file) {
if (strtolower(fileExtension($file)) == 'mid') {
$musicXML = new MusicXMLFromMidi();
try {
$source = $file;
$result = str_replace(".mid", ".xml", $source);
echo "Convert file $source\r\n";
$midi = $musicXML->loadMidi($source);
$mxl = new MXL();
$xml = $musicXML->midiToMusicXml($midi, "Online", "4.0", MXL::FORMAT_XML);
//compressed version]
//file_put_contents("convert.mxl", $mxl->createMxl("Test", $xml));
//uncompressed version
file_put_contents($result, $xml);
} catch (Exception $e) {
echo $e->getMessage();
}
}
}