-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathfileSelectAndLoadOSMD.js
49 lines (44 loc) · 1.98 KB
/
fileSelectAndLoadOSMD.js
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
function handleFileSelect(evt) {
var maxOSMDDisplays = 10; // how many scores can be displayed at once (in a vertical layout)
var files = evt.target.files; // FileList object
var osmdDisplays = Math.min(files.length, maxOSMDDisplays);
var output = [];
for (var i=0, file = files[i]; i<osmdDisplays; i++) {
output.push("<li><strong>", escape(file.name), "</strong> </li>");
output.push("<div id='osmdCanvas" + i + "'/>");
}
document.getElementById("list").innerHTML = "<ul>" + output.join("") + "</ul>";
for (var i=0, file = files[i]; i < osmdDisplays; i++) {
if (!file.name.match('.*\.xml') && !file.name.match('.*\.musicxml') && false) {
alert('You selected a non-xml file. Please select only music xml files.');
continue;
}
var reader = new FileReader();
reader.onload = function(e) {
var osmd = new opensheetmusicdisplay.OpenSheetMusicDisplay("osmdCanvas", {
// set options here
backend: "svg",
drawFromMeasureNumber: 1,
drawUpToMeasureNumber: Number.MAX_SAFE_INTEGER // draw all measures, up to the end of the sample
});
osmd
.load(e.target.result)
.then(
function() {
window.osmd = osmd; // give access to osmd object in Browser console, e.g. for osmd.setOptions()
//console.log("e.target.result: " + e.target.result);
osmd.render();
// osmd.cursor.show(); // this would show the cursor on the first note
// osmd.cursor.next(); // advance the cursor one note
}
);
};
if (file.name.match('.*\.mxl')) {
// have to read as binary, otherwise JSZip will throw ("corrupted zip: missing 37 bytes" or similar)
reader.readAsBinaryString(file);
} else {
reader.readAsText(file);
}
}
}
document.getElementById("files").addEventListener("change", handleFileSelect, false);