index.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  1. import { OpenSheetMusicDisplay } from '../src/OpenSheetMusicDisplay/OpenSheetMusicDisplay';
  2. import { BackendType } from '../src/OpenSheetMusicDisplay/OSMDOptions';
  3. import { PlaybackManager, LinearTimingSource, BasicAudioPlayer, ControlPanel } from '../src/Playback';
  4. import * as jsPDF from '../node_modules/jspdf-yworks/dist/jspdf.min';
  5. import * as svg2pdf from '../node_modules/svg2pdf.js/dist/svg2pdf.min';
  6. import { TransposeCalculator } from '../src/Plugins/Transpose/TransposeCalculator';
  7. /*jslint browser:true */
  8. (function () {
  9. "use strict";
  10. var openSheetMusicDisplay;
  11. var sampleFolder = process.env.STATIC_FILES_SUBFOLDER ? process.env.STATIC_FILES_SUBFOLDER + "/" : "",
  12. samples = {
  13. "Beethoven, L.v. - An die ferne Geliebte": "Beethoven_AnDieFerneGeliebte.xml",
  14. "Clementi, M. - Sonatina Op.36 No.1 Pt.1": "MuzioClementi_SonatinaOpus36No1_Part1.xml",
  15. "Clementi, M. - Sonatina Op.36 No.1 Pt.2": "MuzioClementi_SonatinaOpus36No1_Part2.xml",
  16. "Clementi, M. - Sonatina Op.36 No.3 Pt.1": "MuzioClementi_SonatinaOpus36No3_Part1.xml",
  17. "Clementi, M. - Sonatina Op.36 No.3 Pt.2": "MuzioClementi_SonatinaOpus36No3_Part2.xml",
  18. "Bach, J.S. - Praeludium in C-Dur BWV846 1": "JohannSebastianBach_PraeludiumInCDur_BWV846_1.xml",
  19. "Bach, J.S. - Air": "JohannSebastianBach_Air.xml",
  20. "Gounod, C. - Méditation": "CharlesGounod_Meditation.xml",
  21. "Haydn, J. - Concertante Cello": "JosephHaydn_ConcertanteCello.xml",
  22. "Joplin, S. - Elite Syncopations": "ScottJoplin_EliteSyncopations.xml",
  23. "Joplin, S. - The Entertainer": "ScottJoplin_The_Entertainer.xml",
  24. "Mozart, W.A. - An Chloe": "Mozart_AnChloe.xml",
  25. "Mozart, W.A. - Das Veilchen": "Mozart_DasVeilchen.xml",
  26. "Mozart, W.A. - Clarinet Quintet (Excerpt)": "Mozart_Clarinet_Quintet_Excerpt.mxl",
  27. "Mozart, W.A. - String Quartet in G, K. 387, 1st Mvmt Excerpt": "Mozart_String_Quartet_in_G_K._387_1st_Mvmnt_excerpt.musicxml",
  28. "Mozart/Holzer - Land der Berge (national anthem of Austria)": "Land_der_Berge.musicxml",
  29. "OSMD Function Test - All": "OSMD_function_test_all.xml",
  30. "OSMD Function Test - Accidentals": "OSMD_function_test_accidentals.musicxml",
  31. "OSMD Function Test - Autobeam": "OSMD_function_test_autobeam.musicxml",
  32. "OSMD Function Test - Auto-/Custom-Coloring": "OSMD_function_test_auto-custom-coloring-entchen.musicxml",
  33. "OSMD Function Test - Bar lines": "OSMD_function_test_bar_lines.musicxml",
  34. "OSMD Function Test - Chord Symbols": "OSMD_function_test_chord_symbols.musicxml",
  35. "OSMD Function Test - Chord Spacing": "OSMD_function_test_chord_spacing.mxl",
  36. "OSMD Function Test - Chord Symbols - Various Chords": "OSMD_function_test_chord_tests_various.musicxml",
  37. "OSMD Function Test - Chord Symbols - BrookeWestSample": "BrookeWestSample.mxl",
  38. "OSMD Function Test - Color (from XML)": "OSMD_function_test_color.musicxml",
  39. "OSMD Function Test - Container height (compacttight mode)": "OSMD_Function_Test_Container_height.musicxml",
  40. "OSMD Function Test - Drumset": "OSMD_function_test_drumset.musicxml",
  41. "OSMD Function Test - Drums on one Line": "OSMD_Function_Test_Drums_one_line_snare_plus_piano.musicxml",
  42. "OSMD Function Test - Expressions": "OSMD_function_test_expressions.musicxml",
  43. "OSMD Function Test - Expressions Overlap": "OSMD_function_test_expressions_overlap.musicxml",
  44. "OSMD Function Test - Grace Notes": "OSMD_function_test_GraceNotes.xml",
  45. "OSMD Function Test - Metronome Marks": "OSMD_function_test_metronome_marks.mxl",
  46. "OSMD Function Test - Multiple Rest Measures": "OSMD_function_test_multiple_rest_measures.musicxml",
  47. "OSMD Function Test - Invisible Notes": "OSMD_function_test_invisible_notes.musicxml",
  48. "OSMD Function Test - Notehead Shapes": "OSMD_function_test_noteheadShapes.musicxml",
  49. "OSMD Function Test - Ornaments": "OSMD_function_test_Ornaments.xml",
  50. "OSMD Function Test - Selecting Measures To Draw": "OSMD_function_test_measuresToDraw_Beethoven_AnDieFerneGeliebte.xml",
  51. "OSMD Function Test - System and Page Breaks": "OSMD_Function_Test_System_and_Page_Breaks_4_pages.mxl",
  52. "OSMD Function Test - Tabulature": "OSMD_Function_Test_Tabulature_hayden_study_1.mxl",
  53. "OSMD Function Test - Tabulature MultiBends": "OSMD_Function_Test_Tablature_Multibends.musicxml",
  54. "OSMD Function Test - Tabulature All Effects": "OSMD_Function_Test_Tablature_Alleffects.musicxml",
  55. "OSMD Function Test - Tremolo": "OSMD_Function_Test_Tremolo_2bars.musicxml",
  56. "OSMD Function Test - Labels": "OSMD_Function_Test_Labels.musicxml",
  57. "OSMD Function Test - High Slur Test": "test_slurs_highNotes.musicxml",
  58. "OSMD Function Test - Auto Multirest Measures Single Staff": "Test_Auto_Multirest_1.musicxml",
  59. "OSMD Function Test - Auto Multirest Measures Multiple Staves": "Test_Auto_Multirest_2.musicxml",
  60. "OSMD Function Test - String number collisions": "test_string_number_collisions.musicxml",
  61. "OSMD Function Test - Repeat Stave Connectors": "OSMD_function_Test_Repeat.musicxml",
  62. "Schubert, F. - An Die Musik": "Schubert_An_die_Musik.xml",
  63. "Actor, L. - Prelude (Large Sample, loading time)": "ActorPreludeSample.xml",
  64. "Actor, L. - Prelude (Large, No Print Part Names)": "ActorPreludeSample_PartName.xml",
  65. "Anonymous - Saltarello": "Saltarello.mxl",
  66. "Debussy, C. - Mandoline": "Debussy_Mandoline.xml",
  67. "Levasseur, F. - Parlez Mois": "Parlez-moi.mxl",
  68. "Schumann, R. - Dichterliebe": "Dichterliebe01.xml",
  69. "Telemann, G.P. - Sonate-Nr.1.1-Dolce": "TelemannWV40.102_Sonate-Nr.1.1-Dolce.xml",
  70. "Telemann, G.P. - Sonate-Nr.1.2-Allegro": "TelemannWV40.102_Sonate-Nr.1.2-Allegro-F-Dur.xml",
  71. },
  72. comments = {
  73. "Beethoven_AnDieFerneGeliebte.xml": ["Beethoven_AnDieFerneGeliebte_comments.xml", "Beethoven_AnDieFerneGeliebte_comments_2.xml"]
  74. },
  75. zoom = 1.0,
  76. // HTML Elements in the page
  77. divControls,
  78. zoomControls,
  79. header,
  80. err,
  81. error_tr,
  82. canvas,
  83. selectSample,
  84. selectBounding,
  85. skylineDebug,
  86. bottomlineDebug,
  87. zoomIns,
  88. zoomOuts,
  89. zoomDivs,
  90. custom,
  91. nextCursorBtn,
  92. resetCursorBtn,
  93. followCursorCheckbox,
  94. showCursorBtn,
  95. hideCursorBtn,
  96. backendSelect,
  97. backendSelectDiv,
  98. debugReRenderBtn,
  99. debugClearBtn,
  100. selectPageSizes,
  101. printPdfBtns,
  102. transpose,
  103. transposeBtn,
  104. playbackControlsButton,
  105. playbackControl;
  106. // manage option setting and resetting for specific samples, e.g. in the autobeam sample autobeam is set to true, otherwise reset to previous state
  107. // TODO design a more elegant option state saving & restoring system, though that requires saving the options state in OSMD
  108. var minMeasureToDrawStashed = 1;
  109. var maxMeasureToDrawStashed = Number.MAX_SAFE_INTEGER;
  110. var measureToDrawRangeNeedsReset = false;
  111. var drawingParametersStashed = "default";
  112. var drawingParametersNeedsReset = false;
  113. var autobeamOptionNeedsReset = false;
  114. var autobeamOptionStashedValue = false;
  115. var autoCustomColoringOptionNeedsReset = false;
  116. var autoCustomColoringOptionStashedValue = false;
  117. var drawPartNamesOptionStashedValue = true;
  118. var drawPartAbbreviationsStashedValue = true;
  119. var drawPartNamesOptionNeedsReset = false;
  120. var pageBreaksOptionStashedValue = false;
  121. var pageBreaksOptionNeedsReset = false;
  122. var systemBreaksOptionStashedValue = false; // reset handled by pageBreaksOptionNeedsReset
  123. var showControls = true;
  124. var showExportPdfControl = false;
  125. var showPageFormatControl = false;
  126. var showZoomControl = true;
  127. var showHeader = true;
  128. var showDebugControls = false;
  129. if (process.env.OSMD_DEMO_TITLE) {
  130. document.title = process.env.OSMD_DEMO_TITLE;
  131. }
  132. // Initialization code
  133. function init() {
  134. var name, option;
  135. // Handle window parameter
  136. var paramEmbedded = findGetParameter('embedded');
  137. var paramShowControls = findGetParameter('showControls');
  138. var paramShowPageFormatControl = findGetParameter('showPageFormatControl');
  139. var paramShowExportPdfControl = findGetParameter('showExportPdfControl');
  140. var paramShowZoomControl = findGetParameter('showZoomControl');
  141. var paramShowHeader = findGetParameter('showHeader');
  142. var paramZoom = findGetParameter('zoom');
  143. var paramOverflow = findGetParameter('overflow');
  144. var paramOpenUrl = findGetParameter('openUrl');
  145. var paramDebugControls = findGetParameter('debugControls');
  146. var paramCompactMode = findGetParameter('compactMode');
  147. var paramMeasureRangeStart = findGetParameter('measureRangeStart');
  148. var paramMeasureRangeEnd = findGetParameter('measureRangeEnd');
  149. var paramPageFormat = findGetParameter('pageFormat');
  150. var paramPageBackgroundColor = findGetParameter('pageBackgroundColor');
  151. var paramBackendType = findGetParameter('backendType');
  152. var paramPageWidth = findGetParameter('pageWidth');
  153. var paramPageHeight = findGetParameter('pageHeight');
  154. var paramHorizontalScrolling = findGetParameter('horizontalScrolling');
  155. var paramSingleHorizontalStaffline = findGetParameter('singleHorizontalStaffline');
  156. showHeader = (paramShowHeader !== '0');
  157. showControls = false;
  158. if (paramEmbedded) {
  159. showControls = paramShowControls !== '0';
  160. showZoomControl = paramShowZoomControl !== '0';
  161. showPageFormatControl = paramShowPageFormatControl !== '0';
  162. showExportPdfControl = paramShowExportPdfControl !== '0';
  163. }
  164. if (paramZoom) {
  165. if (paramZoom > 0.1 && paramZoom < 5.0) {
  166. zoom = paramZoom;
  167. }
  168. }
  169. if (paramOverflow && typeof paramOverflow === 'string') {
  170. if (paramOverflow === 'hidden' || paramOverflow === 'auto' || paramOverflow === 'scroll' || paramOverflow === 'visible') {
  171. document.body.style.overflow = paramOverflow;
  172. }
  173. }
  174. var compactMode = paramCompactMode && paramCompactMode !== '0';
  175. var measureRangeStart = paramMeasureRangeStart ? Number.parseInt(paramMeasureRangeStart) : 0;
  176. var measureRangeEnd = paramMeasureRangeEnd ? Number.parseInt(paramMeasureRangeEnd) : Number.MAX_SAFE_INTEGER;
  177. if (measureRangeStart && measureRangeEnd && measureRangeEnd < measureRangeStart) {
  178. console.log("[OSMD] warning: measure range end parameter should not be smaller than measure range start. We've set start measure = end measure now.")
  179. measureRangeStart = measureRangeEnd;
  180. }
  181. let pageFormat = paramPageFormat ? paramPageFormat : "Endless";
  182. if (paramPageHeight && paramPageWidth) {
  183. pageFormat = `${paramPageWidth}x${paramPageHeight}`
  184. }
  185. var pageBackgroundColor = paramPageBackgroundColor ? "#" + paramPageBackgroundColor : undefined; // vexflow format, see OSMDOptions. can't use # in parameters.
  186. //console.log("demo: osmd pagebgcolor: " + pageBackgroundColor);
  187. var backendType = (paramBackendType && paramBackendType.toLowerCase) ? paramBackendType : "svg";
  188. var horizontalScrolling = paramHorizontalScrolling === '1';
  189. var singleHorizontalStaffline = paramSingleHorizontalStaffline === '1';
  190. // set the backendSelect debug controls dropdown menu selected item
  191. //console.log("true: " + backendSelect && backendType.toLowerCase && backendType.toLowerCase() === "canvas");
  192. // TODO somehow backendSelect becomes undefined here:
  193. /*if (backendSelect && backendType.toLowerCase && backendType.toLowerCase() === "canvas") {
  194. console.log("here1");
  195. for (var i=0; i<backendSelect.options.length; i++) {
  196. if (backendSelect.options[i].value.toLowerCase() === "canvas") {
  197. backendSelect.selectedIndex = i;
  198. }
  199. }
  200. backendSelect.value = "Canvas";
  201. }*/
  202. divControls = document.getElementById('divControls');
  203. zoomControls = document.getElementById('zoomControls');
  204. header = document.getElementById('header');
  205. err = document.getElementById("error-td");
  206. error_tr = document.getElementById("error-tr");
  207. zoomDivs = [];
  208. zoomDivs.push(document.getElementById("zoom-str"));
  209. zoomDivs.push(document.getElementById("zoom-str-optional"));
  210. custom = document.createElement("option");
  211. selectSample = document.getElementById("selectSample");
  212. selectBounding = document.getElementById("selectBounding");
  213. skylineDebug = document.getElementById("skylineDebug");
  214. bottomlineDebug = document.getElementById("bottomlineDebug");
  215. zoomIns = [];
  216. zoomIns.push(document.getElementById("zoom-in-btn"));
  217. zoomIns.push(document.getElementById("zoom-in-btn-optional"));
  218. zoomOuts = [];
  219. zoomOuts.push(document.getElementById("zoom-out-btn"));
  220. zoomOuts.push(document.getElementById("zoom-out-btn-optional"));
  221. canvas = document.createElement("div");
  222. if (horizontalScrolling) {
  223. canvas.style.overflowX = 'auto'; // enable horizontal scrolling
  224. }
  225. //canvas.id = 'osmdCanvasDiv';
  226. //canvas.style.overflowX = 'auto'; // enable horizontal scrolling
  227. nextCursorBtn = document.getElementById("next-cursor-btn");
  228. resetCursorBtn = document.getElementById("reset-cursor-btn");
  229. followCursorCheckbox = document.getElementById("follow-cursor-checkbox");
  230. showCursorBtn = document.getElementById("show-cursor-btn");
  231. hideCursorBtn = document.getElementById("hide-cursor-btn");
  232. backendSelect = document.getElementById("backend-select");
  233. backendSelectDiv = document.getElementById("backend-select-div");
  234. debugReRenderBtn = document.getElementById("debug-re-render-btn");
  235. debugClearBtn = document.getElementById("debug-clear-btn");
  236. selectPageSizes = [];
  237. selectPageSizes.push(document.getElementById("selectPageSize"));
  238. selectPageSizes.push(document.getElementById("selectPageSize-optional"));
  239. printPdfBtns = [];
  240. printPdfBtns.push(document.getElementById("print-pdf-btn"));
  241. printPdfBtns.push(document.getElementById("print-pdf-btn-optional"));
  242. transpose = document.getElementById('transpose');
  243. transposeBtn = document.getElementById('transpose-btn');
  244. playbackControlsButton = document.getElementById("playback-settings-button")
  245. //var defaultDisplayVisibleValue = "block"; // TODO in some browsers flow could be the better/default value
  246. var defaultVisibilityValue = "visible";
  247. var devDemoRunning = process.env.OSMD_DEBUG_CONTROLS;
  248. showDebugControls = paramDebugControls === '1' || (devDemoRunning && paramDebugControls !== '0')
  249. if (showDebugControls) {
  250. var elementsToEnable = [
  251. selectSample, selectBounding, selectPageSize, backendSelect, backendSelectDiv, divControls
  252. ];
  253. for (var i=0; i<elementsToEnable.length; i++) {
  254. if (elementsToEnable[i]) { // make sure this element is not null/exists in the index.html, e.g. github.io demo has different index.html
  255. if (elementsToEnable[i].style) {
  256. elementsToEnable[i].style.visibility = defaultVisibilityValue;
  257. elementsToEnable[i].style.opacity = 1.0;
  258. }
  259. }
  260. }
  261. } else {
  262. if (divControls) {
  263. divControls.style.display = "none";
  264. }
  265. }
  266. const optionalControls = document.getElementById('optionalControls');
  267. if (optionalControls) {
  268. if (showControls) {
  269. optionalControls.style.visibility = defaultVisibilityValue;
  270. optionalControls.style.opacity = 0.8;
  271. } else {
  272. optionalControls.style.display = 'none';
  273. }
  274. }
  275. if (!showHeader) {
  276. if (header) {
  277. header.style.display = 'none';
  278. }
  279. } else {
  280. if (header) {
  281. header.style.opacity = 1.0;
  282. }
  283. }
  284. // Hide error
  285. error();
  286. if (showControls) {
  287. const optionalControls = document.getElementById('optionalControls');
  288. if (optionalControls) {
  289. optionalControls.style.opacity = 1.0;
  290. // optionalControls.appendChild(zoomControlsButtons);
  291. // optionalControls.appendChild(zoomControlsString);
  292. optionalControls.style.position = 'absolute';
  293. optionalControls.style.zIndex = '10';
  294. optionalControls.style.right = '10px';
  295. // optionalControls.style.padding = '10px';
  296. }
  297. if (showZoomControl) {
  298. const zoomControlsButtonsColumn = document.getElementById('zoomControlsButtons-optional-column');
  299. zoomControlsButtonsColumn.style.opacity = 1.0;
  300. // const zoomControlsButtons = document.getElementById('zoomControlsButtons-optional');
  301. // zoomControlsButtons.style.opacity = 1.0;
  302. const zoomControlsString = document.getElementById('zoom-str-optional'); // actually === zoomDivs[1] above
  303. if (zoomControlsString) {
  304. zoomControlsString.innerHTML = Math.floor(zoom * 100.0) + "%";
  305. zoomControlsString.style.display = 'inline';
  306. // zoomControlsString.style.padding = '10px';
  307. }
  308. }
  309. if (showExportPdfControl) {
  310. const exportPdfButtonColumn = document.getElementById('print-pdf-btn-optional-column');
  311. if (exportPdfButtonColumn) {
  312. exportPdfButtonColumn.style.opacity = 1.0;
  313. }
  314. }
  315. const pageFormatControlColumn = document.getElementById("selectPageSize-optional-column");
  316. if (pageFormatControlColumn) {
  317. if (showPageFormatControl) {
  318. pageFormatControlColumn.style.opacity = 1.0;
  319. } else {
  320. // showPageFormatControlColumn.innerHTML = "";
  321. // pageFormatControlColumn.style.minWidth = 0;
  322. // pageFormatControlColumn.style.width = 0;
  323. pageFormatControlColumn.style.display = 'none'; // squeezes buttons/columns
  324. // pageFormatControlColumn.style.visibility = 'hidden';
  325. // const optionalControlsColumnContainer = document.getElementById("optionalControlsColumnContainer");
  326. // optionalControlsColumnContainer.removeChild(pageFormatControlColumn);
  327. // optionalControlsColumnContainer.width *= 0.66;
  328. // optionalControls.witdh *= 0.66;
  329. // optionalControls.focus();
  330. }
  331. }
  332. }
  333. // Create select
  334. for (name in samples) {
  335. if (samples.hasOwnProperty(name)) {
  336. option = document.createElement("option");
  337. option.value = samples[name];
  338. option.textContent = name;
  339. }
  340. if (selectSample) {
  341. selectSample.appendChild(option);
  342. }
  343. }
  344. if (selectSample) {
  345. selectSample.onchange = selectSampleOnChange;
  346. }
  347. if (selectBounding) {
  348. selectBounding.onchange = selectBoundingOnChange;
  349. }
  350. for (const selectPageSize of selectPageSizes) {
  351. if (selectPageSize) {
  352. selectPageSize.onchange = function (evt) {
  353. var value = evt.target.value;
  354. openSheetMusicDisplay.setPageFormat(value);
  355. openSheetMusicDisplay.render();
  356. };
  357. }
  358. }
  359. for (const printPdfBtn of printPdfBtns) {
  360. if (printPdfBtn) {
  361. printPdfBtn.onclick = function () {
  362. createPdf();
  363. }
  364. }
  365. }
  366. // Pre-select default music piece
  367. custom.appendChild(document.createTextNode("Custom"));
  368. // Create zoom controls
  369. for (const zoomIn of zoomIns) {
  370. if (zoomIn) {
  371. zoomIn.onclick = function () {
  372. zoom *= 1.2;
  373. scale();
  374. };
  375. }
  376. }
  377. for (const zoomOut of zoomOuts) {
  378. if (zoomOut) {
  379. zoomOut.onclick = function () {
  380. zoom /= 1.2;
  381. scale();
  382. };
  383. }
  384. }
  385. if (skylineDebug) {
  386. skylineDebug.onclick = function () {
  387. openSheetMusicDisplay.DrawSkyLine = !openSheetMusicDisplay.DrawSkyLine;
  388. openSheetMusicDisplay.render();
  389. }
  390. }
  391. if (bottomlineDebug) {
  392. bottomlineDebug.onclick = function () {
  393. openSheetMusicDisplay.DrawBottomLine = !openSheetMusicDisplay.DrawBottomLine;
  394. openSheetMusicDisplay.render();
  395. }
  396. }
  397. if (debugReRenderBtn) {
  398. debugReRenderBtn.onclick = function () {
  399. rerender();
  400. }
  401. }
  402. if (debugClearBtn) {
  403. debugClearBtn.onclick = function () {
  404. openSheetMusicDisplay.clear();
  405. }
  406. }
  407. // Create OSMD object and canvas
  408. openSheetMusicDisplay = new OpenSheetMusicDisplay(canvas, {
  409. autoResize: true,
  410. backend: backendType,
  411. //backend: "canvas",
  412. disableCursor: false,
  413. drawingParameters: compactMode ? "compact" : "default", // try compact (instead of default)
  414. drawPartNames: true, // try false
  415. // drawTitle: false,
  416. // drawSubtitle: false,
  417. drawFingerings: true,
  418. fingeringPosition: "left", // left is default. try right. experimental: auto, above, below.
  419. // fingeringInsideStafflines: "true", // default: false. true draws fingerings directly above/below notes
  420. setWantedStemDirectionByXml: true, // try false, which was previously the default behavior
  421. // drawUpToMeasureNumber: 3, // draws only up to measure 3, meaning it draws measure 1 to 3 of the piece.
  422. drawFromMeasureNumber : measureRangeStart,
  423. drawUpToMeasureNumber : measureRangeEnd,
  424. //drawMeasureNumbers: false, // disable drawing measure numbers
  425. //measureNumberInterval: 4, // draw measure numbers only every 4 bars (and at the beginning of a new system)
  426. useXMLMeasureNumbers: true, // read measure numbers from xml
  427. // coloring options
  428. coloringEnabled: true,
  429. // defaultColorNotehead: "#CC0055", // try setting a default color. default is black (undefined)
  430. // defaultColorStem: "#BB0099",
  431. autoBeam: false, // try true, OSMD Function Test AutoBeam sample
  432. autoBeamOptions: {
  433. beam_rests: false,
  434. beam_middle_rests_only: false,
  435. //groups: [[3,4], [1,1]],
  436. maintain_stem_directions: false
  437. },
  438. pageFormat: pageFormat,
  439. pageBackgroundColor: pageBackgroundColor,
  440. renderSingleHorizontalStaffline: singleHorizontalStaffline
  441. // tupletsBracketed: true, // creates brackets for all tuplets except triplets, even when not set by xml
  442. // tripletsBracketed: true,
  443. // tupletsRatioed: true, // unconventional; renders ratios for tuplets (3:2 instead of 3 for triplets)
  444. });
  445. openSheetMusicDisplay.setLogLevel('info'); // set this to 'debug' if you want to see more detailed control flow information in console
  446. document.body.appendChild(canvas);
  447. window.addEventListener("keydown", function (e) {
  448. var event = window.event ? window.event : e;
  449. if (event.keyCode === 39) {
  450. openSheetMusicDisplay.cursor.next();
  451. }
  452. });
  453. nextCursorBtn.addEventListener("click", function () {
  454. openSheetMusicDisplay.cursor.next();
  455. });
  456. resetCursorBtn.addEventListener("click", function () {
  457. openSheetMusicDisplay.cursor.reset();
  458. });
  459. if (followCursorCheckbox) {
  460. followCursorCheckbox.onchange = function () {
  461. openSheetMusicDisplay.FollowCursor = !openSheetMusicDisplay.FollowCursor;
  462. }
  463. }
  464. window.addEventListener("wheel", function(e){
  465. if(followCursorCheckbox) {
  466. followCursorCheckbox.checked = false;
  467. openSheetMusicDisplay.FollowCursor = false;
  468. }
  469. });
  470. hideCursorBtn.addEventListener("click", function () {
  471. if (openSheetMusicDisplay.cursor) {
  472. openSheetMusicDisplay.cursor.hide();
  473. } else {
  474. console.info("Can't hide cursor, as it was disabled (e.g. by drawingParameters).");
  475. }
  476. });
  477. showCursorBtn.addEventListener("click", function () {
  478. if (openSheetMusicDisplay.cursor) {
  479. openSheetMusicDisplay.cursor.show();
  480. } else {
  481. console.info("Can't show cursor, as it was disabled (e.g. by drawingParameters).");
  482. }
  483. });
  484. backendSelect.addEventListener("change", function (e) {
  485. var value = e.target.value;
  486. var createNewOsmd = true;
  487. if (createNewOsmd) {
  488. // clears the canvas element
  489. canvas.innerHTML = "";
  490. openSheetMusicDisplay = new OpenSheetMusicDisplay(canvas, { backend: value });
  491. openSheetMusicDisplay.setLogLevel('info'); // set this to 'debug' if you want to get more detailed control flow information
  492. } else {
  493. // alternative, doesn't work yet, see setOptions():
  494. openSheetMusicDisplay.setOptions({ backend: value });
  495. }
  496. console.log("[OSMD] selectSampleOnChange addEventListener change");
  497. // selectSampleOnChange();
  498. });
  499. if(transposeBtn && transpose){
  500. openSheetMusicDisplay.TransposeCalculator = new TransposeCalculator();
  501. transposeBtn.onclick = function(){
  502. var transposeValue = parseInt(transpose.value);
  503. openSheetMusicDisplay.Sheet.Transpose = transposeValue;
  504. openSheetMusicDisplay.updateGraphic();
  505. rerender();
  506. }
  507. }
  508. playbackControl = demoPlaybackControl(openSheetMusicDisplay);
  509. playbackControlsButton.addEventListener("click", function(){
  510. if(!playbackControl.IsClosed()){
  511. playbackControl.hideControls();
  512. } else {
  513. playbackControl.showControls();
  514. }
  515. });
  516. // TODO after selectSampleOnChange, the resize handler triggers immediately,
  517. // so we render twice at the start of the demo.
  518. // maybe delay the first osmd render, e.g. when window ready?
  519. if (paramOpenUrl) {
  520. if (openSheetMusicDisplay.getLogLevel() < 2) { // debug or trace
  521. console.log("[OSMD] selectSampleOnChange with " + paramOpenUrl);
  522. }
  523. // DEBUG: cause an error for a certain sample, for testing
  524. // if (paramOpenUrl.startsWith("Beethoven")) {
  525. // paramOpenUrl.causeError();
  526. // }
  527. selectSampleOnChange(paramOpenUrl);
  528. } else {
  529. if (openSheetMusicDisplay.getLogLevel() < 2) { // debug or trace
  530. console.log("[OSMD] selectSampleOnChange without param");
  531. }
  532. selectSampleOnChange();
  533. }
  534. }
  535. function findGetParameter(parameterName) {
  536. // special treatment for the openUrl parameter, because different systems attach different arguments to an URL.
  537. // because of CORS (cross-origin safety restrictions), you can only load an xml file from the same origin (server).
  538. // test parameter: ?openUrl=https://opensheetmusiceducation.org/index.php?gf-download=2020%2F01%2FJohannSebastianBach_PraeludiumInCDur_BWV846_1.xml&endUrl&form-id=1&field-id=4&hash=c4ba271ef08204a26cbd4cd2d751c53b78f238c25ddbb1f343e1172f2ce2aa53
  539. // (enable the console.log at the end of this method for testing)
  540. // working test parameter in local demo: ?openUrl=OSMD_function_test_all.xml&endUrl
  541. if (parameterName === 'openUrl') {
  542. let startParameterName = 'openUrl=';
  543. let endParameterName = '&endUrl';
  544. let openUrlIndex = location.search.indexOf(startParameterName);
  545. if (openUrlIndex < 0) {
  546. return undefined;
  547. }
  548. let endIndex = location.search.indexOf(endParameterName) + endParameterName.length;
  549. if (endIndex < 0) {
  550. console.log("[OSMD] If using openUrl as a parameter, you have to end it with '&endUrl'. openUrl parameter omitted.");
  551. return undefined;
  552. }
  553. let urlString = location.search.substring(openUrlIndex + startParameterName.length, endIndex - endParameterName.length);
  554. //console.log("openUrl: " + urlString);
  555. return urlString;
  556. }
  557. let result = undefined;
  558. let tmp = [];
  559. location.search
  560. .substr(1)
  561. .split('&')
  562. .forEach(function (item) {
  563. tmp = item.split('=');
  564. if (tmp[0] === parameterName) {
  565. result = decodeURIComponent(tmp[1]);
  566. //console.log('Found param:' + parameterName + ' = ' + result);
  567. }
  568. });
  569. return result;
  570. }
  571. function selectBoundingOnChange(evt) {
  572. var value = evt.target.value;
  573. openSheetMusicDisplay.DrawBoundingBox = value;
  574. }
  575. function selectSampleOnChange(str) {
  576. var comment = undefined;
  577. var sampleStr = undefined;
  578. error();
  579. disable();
  580. var isCustom = typeof str === "string";
  581. if (!isCustom) {
  582. if (selectSample) {
  583. sampleStr = selectSample.value;
  584. str = sampleFolder + sampleStr;
  585. } else {
  586. if (samples && samples.length > 0) {
  587. sampleStr = samples[0];
  588. str = sampleFolder + sampleStr;
  589. } else {
  590. return; // no sample to load right now
  591. }
  592. }
  593. if(comments.hasOwnProperty(sampleStr)){
  594. comment = comments[sampleStr];
  595. }
  596. }
  597. // zoom = 1.0;
  598. setSampleSpecificOptions(str, isCustom);
  599. openSheetMusicDisplay.load(str, comment).then(
  600. function () {
  601. // This gives you access to the osmd object in the console. Do not use in production code
  602. window.osmd = openSheetMusicDisplay;
  603. openSheetMusicDisplay.zoom = zoom;
  604. //openSheetMusicDisplay.Sheet.Transpose = 3; // try transposing between load and first render if you have transpose issues with F# etc
  605. return openSheetMusicDisplay.render();
  606. },
  607. function (e) {
  608. errorLoadingOrRenderingSheet(e, "rendering");
  609. }
  610. ).then(
  611. function () {
  612. return onLoadingEnd(isCustom);
  613. }, function (e) {
  614. errorLoadingOrRenderingSheet(e, "loading");
  615. onLoadingEnd(isCustom);
  616. }
  617. );
  618. }
  619. function setSampleSpecificOptions(str, isCustom) {
  620. if (!isCustom && str.includes("measuresToDraw")) { // set options for measuresToDraw sample
  621. // stash previously set range of measures to draw
  622. if (!measureToDrawRangeNeedsReset) { // only stash once, when measuresToDraw called multiple times in a row
  623. minMeasureToDrawStashed = openSheetMusicDisplay.EngravingRules.MinMeasureToDrawIndex + 1;
  624. maxMeasureToDrawStashed = openSheetMusicDisplay.EngravingRules.MaxMeasureToDrawIndex + 1;
  625. }
  626. measureToDrawRangeNeedsReset = true;
  627. // for debugging: draw from a random range of measures
  628. let minMeasureToDraw = Math.ceil(Math.random() * 15); // measures start at 1 (measureIndex = measure number - 1 elsewhere)
  629. let maxMeasureToDraw = Math.ceil(Math.random() * 15);
  630. if (minMeasureToDraw > maxMeasureToDraw) {
  631. minMeasureToDraw = maxMeasureToDraw;
  632. let a = minMeasureToDraw;
  633. maxMeasureToDraw = a;
  634. }
  635. //minMeasureToDraw = 1; // set your custom indexes here. Drawing only one measure can be a special case
  636. //maxMeasureToDraw = 1;
  637. console.log("drawing measures in the range: [" + minMeasureToDraw + "," + maxMeasureToDraw + "]");
  638. openSheetMusicDisplay.setOptions({
  639. drawFromMeasureNumber: minMeasureToDraw,
  640. drawUpToMeasureNumber: maxMeasureToDraw
  641. });
  642. } else if (measureToDrawRangeNeedsReset) { // reset for other samples
  643. openSheetMusicDisplay.setOptions({
  644. drawFromMeasureNumber: minMeasureToDrawStashed,
  645. drawUpToMeasureNumber: maxMeasureToDrawStashed
  646. });
  647. measureToDrawRangeNeedsReset = false;
  648. }
  649. if (!isCustom && str.includes("Test_Container_height")) {
  650. drawingParametersStashed = openSheetMusicDisplay.drawingParameters.drawingParametersEnum;
  651. openSheetMusicDisplay.setOptions({
  652. drawingParameters: "compacttight"
  653. });
  654. drawingParametersNeedsReset = true;
  655. } else if (drawingParametersNeedsReset) {
  656. openSheetMusicDisplay.setOptions({
  657. drawingParameters: drawingParametersStashed
  658. });
  659. drawingParametersNeedsReset = false;
  660. }
  661. // Enable Boomwhacker-like coloring for OSMD Function Test - Auto-Coloring (Boomwhacker-like, custom color set)
  662. if (!isCustom && str.includes("auto-custom-coloring")) { // set options for auto coloring sample
  663. autoCustomColoringOptionNeedsReset = true;
  664. //openSheetMusicDisplay.setOptions({coloringMode: 1}); // Auto-Coloring with pre-defined colors
  665. openSheetMusicDisplay.setOptions({
  666. coloringMode: 2, // custom coloring set. 0 would be XML, 1 autocoloring
  667. coloringSetCustom: ["#d82c6b", "#F89D15", "#FFE21A", "#4dbd5c", "#009D96", "#43469d", "#76429c", "#ff0000"],
  668. // last color value of coloringSetCustom is for rest notes
  669. colorStemsLikeNoteheads: true
  670. });
  671. } else if (autoCustomColoringOptionNeedsReset) {
  672. openSheetMusicDisplay.setOptions({ // set default values. better would be to restore to stashed values, but unnecessarily complex for demo
  673. coloringMode: 0,
  674. colorStemsLikeNoteheads: false,
  675. coloringSetCustom: null
  676. });
  677. autoCustomColoringOptionNeedsReset = false;
  678. }
  679. if (!isCustom && str.includes("autobeam")) {
  680. autobeamOptionStashedValue = openSheetMusicDisplay.EngravingRules.AutoBeamNotes; // stash previously set value, to restore later
  681. autobeamOptionNeedsReset = true;
  682. openSheetMusicDisplay.setOptions({ autoBeam: true });
  683. } else if (autobeamOptionNeedsReset) {
  684. openSheetMusicDisplay.setOptions({ autoBeam: autobeamOptionStashedValue });
  685. autobeamOptionNeedsReset = false;
  686. }
  687. if (!isCustom && str.includes("OSMD_Function_Test_System_and_Page_Breaks")) {
  688. pageBreaksOptionStashedValue = openSheetMusicDisplay.EngravingRules.NewPageAtXMLNewPageAttribute;
  689. systemBreaksOptionStashedValue = openSheetMusicDisplay.EngravingRules.NewSystemAtXMLNewSystemAttribute;
  690. pageBreaksOptionNeedsReset = true;
  691. openSheetMusicDisplay.setOptions({ newPageFromXML: true, newSystemFromXML: true });
  692. }
  693. else if (pageBreaksOptionNeedsReset) {
  694. openSheetMusicDisplay.setOptions({ newPageFromXML: pageBreaksOptionStashedValue, newSystemFromXML: systemBreaksOptionStashedValue });
  695. pageBreaksOptionNeedsReset = false;
  696. }
  697. if (!isCustom && str.includes("Schubert_An_die_Musik")) { // TODO weird layout bug here with part names. but shouldn't be in score anyways
  698. drawPartNamesOptionStashedValue = openSheetMusicDisplay.EngravingRules.RenderPartNames;
  699. drawPartAbbreviationsStashedValue = openSheetMusicDisplay.EngravingRules.RenderPartAbbreviations;
  700. openSheetMusicDisplay.setOptions({ drawPartNames: false, drawPartAbbreviations: false }); // TODO sets osmd.drawingParameters.DrawPartNames! also check EngravingRules.RenderPartAbbreviations, was false
  701. drawPartNamesOptionNeedsReset = true;
  702. } else if (drawPartNamesOptionNeedsReset) {
  703. openSheetMusicDisplay.setOptions({ drawPartNames: drawPartNamesOptionStashedValue, drawPartAbbreviations: drawPartAbbreviationsStashedValue });
  704. drawPartNamesOptionNeedsReset = false;
  705. }
  706. }
  707. function errorLoadingOrRenderingSheet(e, loadingOrRenderingString) {
  708. var errorString = "Error " + loadingOrRenderingString + " sheet: " + e;
  709. // if (process.env.DEBUG) { // people may not set a debug environment variable for the demo.
  710. // Always giving a StackTrace might give us more and better error reports.
  711. // TODO for a release, StackTrace control could be reenabled
  712. errorString += "\n" + "StackTrace: \n" + e.stack;
  713. // }
  714. console.warn(errorString);
  715. }
  716. function onLoadingEnd(isCustom) {
  717. // Remove option from select
  718. if (!isCustom && custom.parentElement === selectSample) {
  719. selectSample.removeChild(custom);
  720. }
  721. playbackControl.initialize();
  722. // Enable controls again
  723. enable();
  724. }
  725. function logCanvasSize() {
  726. for (const zoomDiv of zoomDivs) {
  727. if (zoomDiv) {
  728. zoomDiv.innerHTML = Math.floor(zoom * 100.0) + "%";
  729. }
  730. }
  731. }
  732. function scale() {
  733. disable();
  734. window.setTimeout(function () {
  735. openSheetMusicDisplay.Zoom = zoom;
  736. openSheetMusicDisplay.render();
  737. enable();
  738. }, 0);
  739. }
  740. function rerender() {
  741. disable();
  742. window.setTimeout(function () {
  743. if (openSheetMusicDisplay.IsReadyToRender()) {
  744. openSheetMusicDisplay.render();
  745. } else {
  746. console.log("[OSMD demo] Loses context!"); // TODO not sure that this message is reasonable, renders fine anyways. maybe vexflow context lost?
  747. selectSampleOnChange(); // reload sample e.g. after osmd.clear()
  748. }
  749. enable();
  750. }, 0);
  751. }
  752. function error(errString) {
  753. if (!errString) {
  754. error_tr.style.display = "none";
  755. } else {
  756. console.log("[OSMD demo] error: " + errString)
  757. err.textContent = errString;
  758. error_tr.style.display = "";
  759. canvas.width = canvas.height = 0;
  760. enable();
  761. }
  762. }
  763. // Enable/Disable Controls
  764. function disable() {
  765. document.body.style.opacity = 0.3;
  766. setDisabledForControls("disabled");
  767. }
  768. function enable() {
  769. document.body.style.opacity = 1;
  770. setDisabledForControls("");
  771. logCanvasSize();
  772. }
  773. function setDisabledForControls(disabledValue) {
  774. if (selectSample) {
  775. selectSample.disabled = disabledValue;
  776. }
  777. for (const zoomIn of zoomIns) {
  778. if (zoomIn) {
  779. zoomIn.disabled = disabledValue;
  780. }
  781. }
  782. for (const zoomOut of zoomOuts) {
  783. if (zoomOut) {
  784. zoomOut.disabled = disabledValue;
  785. }
  786. }
  787. }
  788. /**
  789. * Creates a Pdf of the currently rendered MusicXML
  790. * @param pdfName if no name is given, the composer and title of the piece will be used
  791. */
  792. function createPdf(pdfName) {
  793. if (openSheetMusicDisplay.backendType !== BackendType.SVG) {
  794. console.log("[OSMD] createPdf(): Warning: createPDF is only supported for SVG background for now, not for Canvas." +
  795. " Please use osmd.setOptions({backendType: SVG}).");
  796. return;
  797. }
  798. if (pdfName === undefined) {
  799. pdfName = openSheetMusicDisplay.sheet.FullNameString + ".pdf";
  800. }
  801. const backends = openSheetMusicDisplay.drawer.Backends;
  802. let svgElement = backends[0].getSvgElement();
  803. let pageWidth = 210;
  804. let pageHeight = 297;
  805. const engravingRulesPageFormat = openSheetMusicDisplay.rules.PageFormat;
  806. if (engravingRulesPageFormat && !engravingRulesPageFormat.IsUndefined) {
  807. pageWidth = engravingRulesPageFormat.width;
  808. pageHeight = engravingRulesPageFormat.height;
  809. } else {
  810. pageHeight = pageWidth * svgElement.clientHeight / svgElement.clientWidth;
  811. }
  812. const orientation = pageHeight > pageWidth ? "p" : "l";
  813. // create a new jsPDF instance
  814. const pdf = new jsPDF(orientation, "mm", [pageWidth, pageHeight]);
  815. const scale = pageWidth / svgElement.clientWidth;
  816. for (let idx = 0, len = backends.length; idx < len; ++idx) {
  817. if (idx > 0) {
  818. pdf.addPage();
  819. }
  820. svgElement = backends[idx].getSvgElement();
  821. // render the svg element
  822. svg2pdf(svgElement, pdf, {
  823. scale: scale,
  824. xOffset: 0,
  825. yOffset: 0
  826. });
  827. }
  828. // simply save the created pdf
  829. pdf.save(pdfName);
  830. // note that using jspdf with svg2pdf creates unnecessary console warnings "AcroForm-Classes are not populated into global-namespace..."
  831. // this will hopefully be fixed with a new jspdf release, see https://github.com/yWorks/jsPDF/pull/32
  832. }
  833. var demoPlaybackControl = function(osmd) {
  834. var playbackListener = {
  835. play() {
  836. followCursorCheckbox.checked = true;
  837. openSheetMusicDisplay.FollowCursor = true;
  838. },
  839. pause() {},
  840. reset() {},
  841. bpmChanged() {},
  842. volumeChanged() {},
  843. volumeMute() {},
  844. volumeUnmute() {}
  845. }
  846. var timingSource = new LinearTimingSource();
  847. var playbackManager = new PlaybackManager(timingSource, undefined, new BasicAudioPlayer(), undefined);
  848. playbackManager.DoPlayback = true;
  849. playbackManager.DoPreCount = false;
  850. var playbackControlPanel = new ControlPanel();
  851. playbackControlPanel.addListener(playbackManager);
  852. playbackControlPanel.addListener(playbackListener);
  853. function initialize() {
  854. timingSource.reset();
  855. timingSource.pause();
  856. timingSource.Settings = osmd.sheet.playbackSettings;
  857. playbackManager.initialize(osmd.sheet.musicPartManager);
  858. playbackManager.addListener(osmd.cursor);
  859. playbackManager.reset();
  860. osmd.PlaybackManager = playbackManager;
  861. playbackControlPanel.clearVolumeTracks();
  862. playbackControlPanel.addVolumeTrack(playbackManager.Metronome.Name, playbackManager.Metronome.Id, playbackManager.Metronome.Volume*100);
  863. for(const instrId of playbackManager.InstrumentIdMapping.keys()) {
  864. const instr = playbackManager.InstrumentIdMapping.getValue(instrId);
  865. playbackControlPanel.addVolumeTrack(instr.Name, instrId, instr.Volume * 100);
  866. }
  867. playbackControlPanel.bpmChanged(osmd.sheet.DefaultStartTempoInBpm);
  868. }
  869. function showControls() {
  870. playbackControlPanel.show();
  871. }
  872. function hideControls() {
  873. playbackControlPanel.hideAndClear();
  874. }
  875. function IsClosed() {
  876. return playbackControlPanel.IsClosed;
  877. }
  878. return {
  879. initialize: initialize,
  880. showControls: showControls,
  881. hideControls: hideControls,
  882. IsClosed: IsClosed
  883. }
  884. };
  885. // Register events: load, drag&drop
  886. window.addEventListener("load", function () {
  887. init();
  888. });
  889. window.addEventListener("dragenter", function (event) {
  890. event.preventDefault();
  891. disable();
  892. });
  893. window.addEventListener("dragover", function (event) {
  894. event.preventDefault();
  895. });
  896. window.addEventListener("dragleave", function (event) {
  897. enable();
  898. });
  899. window.addEventListener("drop", function (event) {
  900. event.preventDefault();
  901. if (!event.dataTransfer || !event.dataTransfer.files || event.dataTransfer.files.length === 0) {
  902. return;
  903. }
  904. // Add "Custom..." score
  905. selectSample.appendChild(custom);
  906. custom.selected = "selected";
  907. // Read dragged file
  908. var reader = new FileReader();
  909. reader.onload = function (res) {
  910. selectSampleOnChange(res.target.result);
  911. };
  912. var filename = event.dataTransfer.files[0].name;
  913. if (filename.toLowerCase().indexOf(".xml") > 0
  914. || filename.toLowerCase().indexOf(".musicxml") > 0) {
  915. reader.readAsText(event.dataTransfer.files[0]);
  916. } else if (event.dataTransfer.files[0].name.toLowerCase().indexOf(".mxl") > 0) {
  917. reader.readAsBinaryString(event.dataTransfer.files[0]);
  918. }
  919. else {
  920. alert("No vaild .xml/.mxl/.musicxml file!");
  921. }
  922. });
  923. }());