index.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. import { OpenSheetMusicDisplay } from '../src/OpenSheetMusicDisplay/OpenSheetMusicDisplay';
  2. /*jslint browser:true */
  3. (function () {
  4. "use strict";
  5. var openSheetMusicDisplay;
  6. var sampleFolder = process.env.STATIC_FILES_SUBFOLDER ? process.env.STATIC_FILES_SUBFOLDER + "/" : "",
  7. samples = {
  8. "Beethoven, L.v. - An die ferne Geliebte": "Beethoven_AnDieFerneGeliebte.xml",
  9. "Clementi, M. - Sonatina Op.36 No.1 Pt.1": "MuzioClementi_SonatinaOpus36No1_Part1.xml",
  10. "Clementi, M. - Sonatina Op.36 No.1 Pt.2": "MuzioClementi_SonatinaOpus36No1_Part2.xml",
  11. "Clementi, M. - Sonatina Op.36 No.3 Pt.1": "MuzioClementi_SonatinaOpus36No3_Part1.xml",
  12. "Clementi, M. - Sonatina Op.36 No.3 Pt.2": "MuzioClementi_SonatinaOpus36No3_Part2.xml",
  13. "Bach, J.S. - Praeludium in C-Dur BWV846 1": "JohannSebastianBach_PraeludiumInCDur_BWV846_1.xml",
  14. "Bach, J.S. - Air": "JohannSebastianBach_Air.xml",
  15. "Gounod, C. - Méditation": "CharlesGounod_Meditation.xml",
  16. "Haydn, J. - Concertante Cello": "JosephHaydn_ConcertanteCello.xml",
  17. "Joplin, S. - Elite Syncopations": "ScottJoplin_EliteSyncopations.xml",
  18. "Joplin, S. - The Entertainer": "ScottJoplin_The_Entertainer.xml",
  19. "Mozart, W.A. - An Chloe": "Mozart_AnChloe.xml",
  20. "Mozart, W.A. - Das Veilchen": "Mozart_DasVeilchen.xml",
  21. "Mozart, W.A. - Clarinet Quintet (Excerpt)": "Mozart_Clarinet_Quintet_Excerpt.mxl",
  22. "Mozart, W.A. - String Quartet in G, K. 387, 1st Mvmt Excerpt": "Mozart_String_Quartet_in_G_K._387_1st_Mvmnt_excerpt.musicxml",
  23. "Mozart/Holzer - Land der Berge (national anthem of Austria)": "Land_der_Berge.musicxml",
  24. "OSMD Function Test - All": "OSMD_function_test_all.xml",
  25. "OSMD Function Test - Accidentals": "OSMD_function_test_accidentals.musicxml",
  26. "OSMD Function Test - Autobeam": "OSMD_function_test_autobeam.musicxml",
  27. "OSMD Function Test - Auto-/Custom-Coloring": "OSMD_function_test_auto-custom-coloring-entchen.musicxml",
  28. "OSMD Function Test - Bar lines": "OSMD_function_test_bar_lines.musicxml",
  29. "OSMD Function Test - Color (from XML)": "OSMD_function_test_color.musicxml",
  30. "OSMD Function Test - Drumset": "OSMD_function_test_drumset.musicxml",
  31. "OSMD Function Test - Expressions": "OSMD_function_test_expressions.musicxml",
  32. "OSMD Function Test - Expressions Overlap": "OSMD_function_test_expressions_overlap.musicxml",
  33. "OSMD Function Test - Grace Notes": "OSMD_function_test_GraceNotes.xml",
  34. "OSMD Function Test - Invisible Notes": "OSMD_function_test_invisible_notes.musicxml",
  35. "OSMD Function Test - Selecting Measures To Draw": "OSMD_function_test_measuresToDraw_Beethoven_AnDieFerneGeliebte.xml",
  36. "OSMD Function Test - Notehead Shapes": "OSMD_function_test_noteheadShapes.musicxml",
  37. "OSMD Function Test - Ornaments": "OSMD_function_test_Ornaments.xml",
  38. "OSMD Function Test - Tremolo": "OSMD_Function_Test_Tremolo_2bars.musicxml",
  39. "Schubert, F. - An Die Musik": "Schubert_An_die_Musik.xml",
  40. "Actor, L. - Prelude (Large Sample, loading time)": "ActorPreludeSample.xml",
  41. "Anonymous - Saltarello": "Saltarello.mxl",
  42. "Debussy, C. - Mandoline": "Debussy_Mandoline.xml",
  43. "Levasseur, F. - Parlez Mois": "Parlez-moi.mxl",
  44. "Schumann, R. - Dichterliebe": "Dichterliebe01.xml",
  45. "Telemann, G.P. - Sonate-Nr.1.1-Dolce": "TelemannWV40.102_Sonate-Nr.1.1-Dolce.xml",
  46. "Telemann, G.P. - Sonate-Nr.1.2-Allegro": "TelemannWV40.102_Sonate-Nr.1.2-Allegro-F-Dur.xml",
  47. },
  48. zoom = 1.0,
  49. // HTML Elements in the page
  50. divControls,
  51. zoomControls,
  52. header,
  53. err,
  54. error_tr,
  55. canvas,
  56. selectSample,
  57. selectBounding,
  58. skylineDebug,
  59. bottomlineDebug,
  60. zoomIn,
  61. zoomOut,
  62. zoomDiv,
  63. custom,
  64. nextCursorBtn,
  65. resetCursorBtn,
  66. followCursorCheckbox,
  67. showCursorBtn,
  68. hideCursorBtn,
  69. backendSelect,
  70. debugReRenderBtn,
  71. debugClearBtn;
  72. // manage option setting and resetting for specific samples, e.g. in the autobeam sample autobeam is set to true, otherwise reset to previous state
  73. // TODO design a more elegant option state saving & restoring system, though that requires saving the options state in OSMD
  74. var minMeasureToDrawStashed = 1;
  75. var maxMeasureToDrawStashed = Number.MAX_SAFE_INTEGER;
  76. var measureToDrawRangeNeedsReset = false;
  77. var autobeamOptionNeedsReset = false;
  78. var autobeamOptionStashedValue = false;
  79. var autoCustomColoringOptionNeedsReset = false;
  80. var autoCustomColoringOptionStashedValue = false;
  81. var drawPartNamesOptionStashedValue = true;
  82. var drawPartNamesOptionNeedsReset = false;
  83. var showControls = true;
  84. var showZoomControl = true;
  85. var showHeader = true;
  86. // Initialization code
  87. function init() {
  88. var name, option;
  89. // Handle window parameter
  90. var paramEmbedded = findGetParameter('embedded');
  91. var paramShowControls = findGetParameter('showControls');
  92. var paramShowZoomControl = findGetParameter('showZoomControl');
  93. var paramShowHeader = findGetParameter('showHeader');
  94. var paramZoom = findGetParameter('zoom');
  95. var paramOverflow = findGetParameter('overflow');
  96. var paramOpenUrl = findGetParameter('openUrl');
  97. if (paramEmbedded !== undefined) {
  98. showControls = (paramShowControls === '1');
  99. showZoomControl = (paramShowZoomControl === '1');
  100. showHeader = (paramShowHeader === '1');
  101. }
  102. if (paramZoom !== undefined) {
  103. if (paramZoom > 0.1 && paramZoom < 5.0) {
  104. zoom = paramZoom;
  105. console.log('Set zoom to ' + zoom);
  106. }
  107. }
  108. if (paramOverflow !== undefined && typeof paramOverflow === 'string') {
  109. if (paramOverflow === 'hidden' || paramOverflow === 'auto' || paramOverflow === 'scroll' || paramOverflow === 'visible') {
  110. document.body.style.overflow = paramOverflow;
  111. }
  112. }
  113. divControls = document.getElementById('divControls');
  114. zoomControls = document.getElementById('zoomControls');
  115. header = document.getElementById('header');
  116. err = document.getElementById("error-td");
  117. error_tr = document.getElementById("error-tr");
  118. zoomDiv = document.getElementById("zoom-str");
  119. custom = document.createElement("option");
  120. selectSample = document.getElementById("selectSample");
  121. selectBounding = document.getElementById("selectBounding");
  122. skylineDebug = document.getElementById("skylineDebug");
  123. bottomlineDebug = document.getElementById("bottomlineDebug");
  124. zoomIn = document.getElementById("zoom-in-btn");
  125. zoomOut = document.getElementById("zoom-out-btn");
  126. canvas = document.createElement("div");
  127. //canvas.style.overflowX = 'auto'; // enable horizontal scrolling
  128. nextCursorBtn = document.getElementById("next-cursor-btn");
  129. resetCursorBtn = document.getElementById("reset-cursor-btn");
  130. followCursorCheckbox = document.getElementById("follow-cursor-checkbox");
  131. showCursorBtn = document.getElementById("show-cursor-btn");
  132. hideCursorBtn = document.getElementById("hide-cursor-btn");
  133. backendSelect = document.getElementById("backend-select");
  134. debugReRenderBtn = document.getElementById("debug-re-render-btn");
  135. debugClearBtn = document.getElementById("debug-clear-btn");
  136. if (!showControls) {
  137. divControls.style.display = 'none';
  138. }
  139. if (!showHeader) {
  140. header.style.display = 'none';
  141. }
  142. // Hide error
  143. error();
  144. if (!showControls && showZoomControl) {
  145. const zoomControlsButtons = document.getElementById('zoomControlsButtons');
  146. const zoomControlsString = document.getElementById('zoom-str');
  147. const optionalControls = document.getElementById('optionalControls');
  148. optionalControls.appendChild(zoomControlsButtons);
  149. optionalControls.appendChild(zoomControlsString);
  150. optionalControls.style.position = 'absolute';
  151. optionalControls.style.zIndex = '10';
  152. optionalControls.style.right = '10px';
  153. optionalControls.style.padding = '10px';
  154. zoomControlsString.style.display = 'inline';
  155. zoomControlsString.style.padding = '10px';
  156. }
  157. // Create select
  158. for (name in samples) {
  159. if (samples.hasOwnProperty(name)) {
  160. option = document.createElement("option");
  161. option.value = samples[name];
  162. option.textContent = name;
  163. }
  164. selectSample.appendChild(option);
  165. }
  166. selectSample.onchange = selectSampleOnChange;
  167. if (selectBounding) {
  168. selectBounding.onchange = selectBoundingOnChange;
  169. }
  170. // Pre-select default music piece
  171. custom.appendChild(document.createTextNode("Custom"));
  172. // Create zoom controls
  173. zoomIn.onclick = function () {
  174. zoom *= 1.2;
  175. scale();
  176. };
  177. zoomOut.onclick = function () {
  178. zoom /= 1.2;
  179. scale();
  180. };
  181. if (skylineDebug) {
  182. skylineDebug.onclick = function () {
  183. openSheetMusicDisplay.DrawSkyLine = !openSheetMusicDisplay.DrawSkyLine;
  184. }
  185. }
  186. if (bottomlineDebug) {
  187. bottomlineDebug.onclick = function () {
  188. openSheetMusicDisplay.DrawBottomLine = !openSheetMusicDisplay.DrawBottomLine;
  189. }
  190. }
  191. if (debugReRenderBtn) {
  192. debugReRenderBtn.onclick = function () {
  193. rerender();
  194. }
  195. }
  196. if (debugClearBtn) {
  197. debugClearBtn.onclick = function () {
  198. openSheetMusicDisplay.clear();
  199. }
  200. }
  201. // Create OSMD object and canvas
  202. openSheetMusicDisplay = new OpenSheetMusicDisplay(canvas, {
  203. autoResize: true,
  204. backend: backendSelect.value,
  205. disableCursor: false,
  206. drawingParameters: "default", // try compact (instead of default)
  207. drawPartNames: true, // try false
  208. // drawTitle: false,
  209. // drawSubtitle: false,
  210. //drawFromMeasureNumber: 4,
  211. //drawUpToMeasureNumber: 8,
  212. drawFingerings: true,
  213. fingeringPosition: "auto", // left is default. try right. experimental: auto, above, below.
  214. // fingeringInsideStafflines: "true", // default: false. true draws fingerings directly above/below notes
  215. setWantedStemDirectionByXml: true, // try false, which was previously the default behavior
  216. // drawUpToMeasureNumber: 3, // draws only up to measure 3, meaning it draws measure 1 to 3 of the piece.
  217. // coloring options
  218. coloringEnabled: true,
  219. // defaultColorNotehead: "#CC0055", // try setting a default color. default is black (undefined)
  220. // defaultColorStem: "#BB0099",
  221. autoBeam: false, // try true, OSMD Function Test AutoBeam sample
  222. autoBeamOptions: {
  223. beam_rests: false,
  224. beam_middle_rests_only: false,
  225. //groups: [[3,4], [1,1]],
  226. maintain_stem_directions: false
  227. },
  228. // tupletsBracketed: true, // creates brackets for all tuplets except triplets, even when not set by xml
  229. // tripletsBracketed: true,
  230. // tupletsRatioed: true, // unconventional; renders ratios for tuplets (3:2 instead of 3 for triplets)
  231. });
  232. openSheetMusicDisplay.setLogLevel('info');
  233. document.body.appendChild(canvas);
  234. window.addEventListener("keydown", function (e) {
  235. var event = window.event ? window.event : e;
  236. if (event.keyCode === 39) {
  237. openSheetMusicDisplay.cursor.next();
  238. }
  239. });
  240. nextCursorBtn.addEventListener("click", function () {
  241. openSheetMusicDisplay.cursor.next();
  242. });
  243. resetCursorBtn.addEventListener("click", function () {
  244. openSheetMusicDisplay.cursor.reset();
  245. });
  246. if (followCursorCheckbox) {
  247. followCursorCheckbox.onclick = function () {
  248. openSheetMusicDisplay.FollowCursor = !openSheetMusicDisplay.FollowCursor;
  249. }
  250. }
  251. hideCursorBtn.addEventListener("click", function () {
  252. openSheetMusicDisplay.cursor.hide();
  253. });
  254. showCursorBtn.addEventListener("click", function () {
  255. if (openSheetMusicDisplay.cursor) {
  256. openSheetMusicDisplay.cursor.show();
  257. } else {
  258. console.info("Can't show cursor, as it was disabled (e.g. by drawingParameters).");
  259. }
  260. });
  261. backendSelect.addEventListener("change", function (e) {
  262. var value = e.target.value;
  263. var createNewOsmd = true;
  264. if (createNewOsmd) {
  265. // clears the canvas element
  266. canvas.innerHTML = "";
  267. openSheetMusicDisplay = new OpenSheetMusicDisplay(canvas, { backend: value });
  268. openSheetMusicDisplay.setLogLevel('info');
  269. } else {
  270. // alternative, doesn't work yet, see setOptions():
  271. openSheetMusicDisplay.setOptions({ backend: value });
  272. }
  273. selectSampleOnChange();
  274. });
  275. }
  276. function findGetParameter(parameterName) {
  277. let result = undefined;
  278. let tmp = [];
  279. location.search
  280. .substr(1)
  281. .split('&')
  282. .forEach(function (item) {
  283. tmp = item.split('=');
  284. if (tmp[0] === parameterName) {
  285. result = decodeURIComponent(tmp[1]);
  286. console.log('Found param:' + parameterName + ' = ' + result);
  287. }
  288. });
  289. return result;
  290. }
  291. function selectBoundingOnChange(evt) {
  292. var value = evt.target.value;
  293. openSheetMusicDisplay.DrawBoundingBox = value;
  294. }
  295. function selectSampleOnChange(str) {
  296. error();
  297. disable();
  298. var isCustom = typeof str === "string";
  299. if (!isCustom) {
  300. str = sampleFolder + selectSample.value;
  301. }
  302. // zoom = 1.0;
  303. setSampleSpecificOptions(str, isCustom);
  304. openSheetMusicDisplay.load(str).then(
  305. function () {
  306. // This gives you access to the osmd object in the console. Do not use in productive code
  307. window.osmd = openSheetMusicDisplay;
  308. openSheetMusicDisplay.zoom = zoom;
  309. return openSheetMusicDisplay.render();
  310. },
  311. function (e) {
  312. errorLoadingOrRenderingSheet(e, "rendering");
  313. }
  314. ).then(
  315. function () {
  316. return onLoadingEnd(isCustom);
  317. }, function (e) {
  318. errorLoadingOrRenderingSheet(e, "loading");
  319. onLoadingEnd(isCustom);
  320. }
  321. );
  322. }
  323. function setSampleSpecificOptions(str, isCustom) {
  324. if (!isCustom && str.includes("measuresToDraw")) { // set options for measuresToDraw sample
  325. // stash previously set range of measures to draw
  326. if (!measureToDrawRangeNeedsReset) { // only stash once, when measuresToDraw called multiple times in a row
  327. minMeasureToDrawStashed = openSheetMusicDisplay.EngravingRules.MinMeasureToDrawIndex + 1;
  328. maxMeasureToDrawStashed = openSheetMusicDisplay.EngravingRules.MaxMeasureToDrawIndex + 1;
  329. }
  330. measureToDrawRangeNeedsReset = true;
  331. // for debugging: draw from a random range of measures
  332. let minMeasureToDraw = Math.ceil(Math.random() * 15); // measures start at 1 (measureIndex = measure number - 1 elsewhere)
  333. let maxMeasureToDraw = Math.ceil(Math.random() * 15);
  334. if (minMeasureToDraw > maxMeasureToDraw) {
  335. minMeasureToDraw = maxMeasureToDraw;
  336. let a = minMeasureToDraw;
  337. maxMeasureToDraw = a;
  338. }
  339. //minMeasureToDraw = 1; // set your custom indexes here. Drawing only one measure can be a special case
  340. //maxMeasureToDraw = 1;
  341. console.log("drawing measures in the range: [" + minMeasureToDraw + "," + maxMeasureToDraw + "]");
  342. openSheetMusicDisplay.setOptions({
  343. drawFromMeasureNumber: minMeasureToDraw,
  344. drawUpToMeasureNumber: maxMeasureToDraw
  345. });
  346. } else if (measureToDrawRangeNeedsReset) { // reset for other samples
  347. openSheetMusicDisplay.setOptions({
  348. drawFromMeasureNumber: minMeasureToDrawStashed,
  349. drawUpToMeasureNumber: maxMeasureToDrawStashed
  350. });
  351. measureToDrawRangeNeedsReset = false;
  352. }
  353. // Enable Boomwhacker-like coloring for OSMD Function Test - Auto-Coloring (Boomwhacker-like, custom color set)
  354. if (!isCustom && str.includes("auto-custom-coloring")) { // set options for auto coloring sample
  355. autoCustomColoringOptionNeedsReset = true;
  356. //openSheetMusicDisplay.setOptions({coloringMode: 1}); // Auto-Coloring with pre-defined colors
  357. openSheetMusicDisplay.setOptions({
  358. coloringMode: 2, // custom coloring set. 0 would be XML, 1 autocoloring
  359. coloringSetCustom: ["#d82c6b", "#F89D15", "#FFE21A", "#4dbd5c", "#009D96", "#43469d", "#76429c", "#ff0000"],
  360. // last color value of coloringSetCustom is for rest notes
  361. colorStemsLikeNoteheads: true
  362. });
  363. } else if (autoCustomColoringOptionNeedsReset) {
  364. openSheetMusicDisplay.setOptions({ // set default values. better would be to restore to stashed values, but unnecessarily complex for demo
  365. coloringMode: 0,
  366. colorStemsLikeNoteheads: false,
  367. coloringSetCustom: null
  368. });
  369. autoCustomColoringOptionNeedsReset = false;
  370. }
  371. if (!isCustom && str.includes("autobeam")) {
  372. autobeamOptionStashedValue = openSheetMusicDisplay.EngravingRules.AutoBeamNotes; // stash previously set value, to restore later
  373. autobeamOptionNeedsReset = true;
  374. openSheetMusicDisplay.setOptions({ autoBeam: true });
  375. } else if (autobeamOptionNeedsReset) {
  376. openSheetMusicDisplay.setOptions({ autoBeam: autobeamOptionStashedValue });
  377. autobeamOptionNeedsReset = false;
  378. }
  379. if (!isCustom && str.includes("Schubert_An_die_Musik")) { // TODO weird layout bug here with part names. but shouldn't be in score anyways
  380. drawPartNamesOptionStashedValue = openSheetMusicDisplay.EngravingRules.RenderPartNames;
  381. openSheetMusicDisplay.setOptions({ drawPartNames: false }); // TODO sets osmd.drawingParameters.DrawPartNames! also check EngravingRules.RenderPartAbbreviations, was false
  382. drawPartNamesOptionNeedsReset = true;
  383. } else if (drawPartNamesOptionNeedsReset) {
  384. openSheetMusicDisplay.setOptions({ drawPartNames: drawPartNamesOptionStashedValue });
  385. drawPartNamesOptionNeedsReset = false;
  386. }
  387. }
  388. function errorLoadingOrRenderingSheet(e, loadingOrRenderingString) {
  389. var errorString = "Error " + loadingOrRenderingString + " sheet: " + e;
  390. // if (process.env.DEBUG) { // people may not set a debug environment variable for the demo.
  391. // Always giving a StackTrace might give us more and better error reports.
  392. // TODO for a release, StackTrace control could be reenabled
  393. errorString += "\n" + "StackTrace: \n" + e.stack;
  394. // }
  395. console.warn(errorString);
  396. }
  397. function onLoadingEnd(isCustom) {
  398. // Remove option from select
  399. if (!isCustom && custom.parentElement === selectSample) {
  400. selectSample.removeChild(custom);
  401. }
  402. // Enable controls again
  403. enable();
  404. }
  405. function logCanvasSize() {
  406. zoomDiv.innerHTML = Math.floor(zoom * 100.0) + "%";
  407. }
  408. function scale() {
  409. disable();
  410. window.setTimeout(function () {
  411. openSheetMusicDisplay.zoom = zoom;
  412. openSheetMusicDisplay.render();
  413. enable();
  414. }, 0);
  415. }
  416. function rerender() {
  417. disable();
  418. window.setTimeout(function () {
  419. if (openSheetMusicDisplay.IsReadyToRender()) {
  420. openSheetMusicDisplay.render();
  421. } else {
  422. selectSampleOnChange(); // reload sample e.g. after osmd.clear()
  423. }
  424. enable();
  425. }, 0);
  426. }
  427. function error(errString) {
  428. if (!errString) {
  429. error_tr.style.display = "none";
  430. } else {
  431. err.textContent = errString;
  432. error_tr.style.display = "";
  433. canvas.width = canvas.height = 0;
  434. enable();
  435. }
  436. }
  437. // Enable/Disable Controls
  438. function disable() {
  439. document.body.style.opacity = 0.3;
  440. selectSample.disabled = zoomIn.disabled = zoomOut.disabled = "disabled";
  441. }
  442. function enable() {
  443. document.body.style.opacity = 1;
  444. selectSample.disabled = zoomIn.disabled = zoomOut.disabled = "";
  445. logCanvasSize();
  446. }
  447. // Register events: load, drag&drop
  448. window.addEventListener("load", function () {
  449. init();
  450. selectSampleOnChange();
  451. });
  452. window.addEventListener("dragenter", function (event) {
  453. event.preventDefault();
  454. disable();
  455. });
  456. window.addEventListener("dragover", function (event) {
  457. event.preventDefault();
  458. });
  459. window.addEventListener("dragleave", function (event) {
  460. enable();
  461. });
  462. window.addEventListener("drop", function (event) {
  463. event.preventDefault();
  464. if (!event.dataTransfer || !event.dataTransfer.files || event.dataTransfer.files.length === 0) {
  465. return;
  466. }
  467. // Add "Custom..." score
  468. selectSample.appendChild(custom);
  469. custom.selected = "selected";
  470. // Read dragged file
  471. var reader = new FileReader();
  472. reader.onload = function (res) {
  473. selectSampleOnChange(res.target.result);
  474. };
  475. var filename = event.dataTransfer.files[0].name;
  476. if (filename.toLowerCase().indexOf(".xml") > 0
  477. || filename.toLowerCase().indexOf(".musicxml") > 0) {
  478. reader.readAsText(event.dataTransfer.files[0]);
  479. } else if (event.dataTransfer.files[0].name.toLowerCase().indexOf(".mxl") > 0) {
  480. reader.readAsBinaryString(event.dataTransfer.files[0]);
  481. }
  482. else {
  483. alert("No vaild .xml/.mxl/.musicxml file!");
  484. }
  485. });
  486. }());