async function uploadMusicPiece(fileUpload) {
if (!fileUpload) {
return null;
}
const n = fileUpload.name;
if (!n) {
return null;
}
if (n.endsWith(".midi") || n.endsWith(".mid")) {
const uintArray = new Uint8Array(await fileUpload.arrayBuffer());
return mvlib.MusicPiece.fromMidi(n, uintArray);
}
if (n.endsWith(".xml") || n.endsWith(".musicxml")) {
return mvlib.MusicPiece.fromMusicXml(n, await fileUpload.text());
}
if (n.endsWith(".mxl")) {
const compressed = await fileUpload.arrayBuffer();
const extracted = await JSZip.loadAsync(compressed);
const scoreFile = Object.keys(extracted.files).filter(
(d) => !d.startsWith("META")
)[0];
const xml = await extracted.file(scoreFile).async("string");
return mvlib.MusicPiece.fromMusicXml(n, xml);
}
}