xml2abc.js 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984
  1. //~ Revision: 118, Copyright (C) 2014-2021: Willem Vree
  2. //~ This program is free software; you can redistribute it and/or modify it under the terms of the
  3. //~ Lesser GNU General Public License as published by the Free Software Foundation;
  4. //~ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  5. //~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  6. //~ See the Lesser GNU General Public License for more details. <http://www.gnu.org/licenses/lgpl.html>.
  7. var $jscomp = $jscomp || {};
  8. $jscomp.scope = {};
  9. $jscomp.arrayIteratorImpl = function (h) {
  10. var u = 0;
  11. return function () {
  12. return u < h.length ? { done: !1, value: h[u++] } : { done: !0 };
  13. };
  14. };
  15. $jscomp.arrayIterator = function (h) {
  16. return { next: $jscomp.arrayIteratorImpl(h) };
  17. };
  18. $jscomp.makeIterator = function (h) {
  19. var u = "undefined" != typeof Symbol && Symbol.iterator && h[Symbol.iterator];
  20. return u ? u.call(h) : $jscomp.arrayIterator(h);
  21. };
  22. $jscomp.ASSUME_ES5 = !1;
  23. $jscomp.ASSUME_NO_NATIVE_MAP = !1;
  24. $jscomp.ASSUME_NO_NATIVE_SET = !1;
  25. $jscomp.SIMPLE_FROUND_POLYFILL = !1;
  26. $jscomp.defineProperty =
  27. $jscomp.ASSUME_ES5 || "function" == typeof Object.defineProperties
  28. ? Object.defineProperty
  29. : function (h, u, n) {
  30. h != Array.prototype && h != Object.prototype && (h[u] = n.value);
  31. };
  32. $jscomp.getGlobal = function (h) {
  33. h = [
  34. "object" == typeof window && window,
  35. "object" == typeof self && self,
  36. "object" == typeof global && global,
  37. h,
  38. ];
  39. for (var u = 0; u < h.length; ++u) {
  40. var n = h[u];
  41. if (n && n.Math == Math) return n;
  42. }
  43. return globalThis;
  44. };
  45. $jscomp.global = $jscomp.getGlobal(this);
  46. $jscomp.SYMBOL_PREFIX = "jscomp_symbol_";
  47. $jscomp.initSymbol = function () {
  48. $jscomp.initSymbol = function () { };
  49. $jscomp.global.Symbol || ($jscomp.global.Symbol = $jscomp.Symbol);
  50. };
  51. $jscomp.SymbolClass = function (h, u) {
  52. this.$jscomp$symbol$id_ = h;
  53. $jscomp.defineProperty(this, "description", { configurable: !0, writable: !0, value: u });
  54. };
  55. $jscomp.SymbolClass.prototype.toString = function () {
  56. return this.$jscomp$symbol$id_;
  57. };
  58. $jscomp.Symbol = (function () {
  59. function h(n) {
  60. if (this instanceof h) throw new TypeError("Symbol is not a constructor");
  61. return new $jscomp.SymbolClass($jscomp.SYMBOL_PREFIX + (n || "") + "_" + u++, n);
  62. }
  63. var u = 0;
  64. return h;
  65. })();
  66. $jscomp.initSymbolIterator = function () {
  67. $jscomp.initSymbol();
  68. var h = $jscomp.global.Symbol.iterator;
  69. h || (h = $jscomp.global.Symbol.iterator = $jscomp.global.Symbol("Symbol.iterator"));
  70. "function" != typeof Array.prototype[h] &&
  71. $jscomp.defineProperty(Array.prototype, h, {
  72. configurable: !0,
  73. writable: !0,
  74. value: function () {
  75. return $jscomp.iteratorPrototype($jscomp.arrayIteratorImpl(this));
  76. },
  77. });
  78. $jscomp.initSymbolIterator = function () { };
  79. };
  80. $jscomp.initSymbolAsyncIterator = function () {
  81. $jscomp.initSymbol();
  82. var h = $jscomp.global.Symbol.asyncIterator;
  83. h || (h = $jscomp.global.Symbol.asyncIterator = $jscomp.global.Symbol("Symbol.asyncIterator"));
  84. $jscomp.initSymbolAsyncIterator = function () { };
  85. };
  86. $jscomp.iteratorPrototype = function (h) {
  87. $jscomp.initSymbolIterator();
  88. h = { next: h };
  89. h[$jscomp.global.Symbol.iterator] = function () {
  90. return this;
  91. };
  92. return h;
  93. };
  94. $jscomp.iteratorFromArray = function (h, u) {
  95. $jscomp.initSymbolIterator();
  96. h instanceof String && (h += "");
  97. var n = 0,
  98. q = {
  99. next: function () {
  100. if (n < h.length) {
  101. var p = n++;
  102. return { value: u(p, h[p]), done: !1 };
  103. }
  104. q.next = function () {
  105. return { done: !0, value: void 0 };
  106. };
  107. return q.next();
  108. },
  109. };
  110. q[Symbol.iterator] = function () {
  111. return q;
  112. };
  113. return q;
  114. };
  115. $jscomp.polyfill = function (h, u, n, q) {
  116. if (u) {
  117. n = $jscomp.global;
  118. h = h.split(".");
  119. for (q = 0; q < h.length - 1; q++) {
  120. var p = h[q];
  121. p in n || (n[p] = {});
  122. n = n[p];
  123. }
  124. h = h[h.length - 1];
  125. q = n[h];
  126. u = u(q);
  127. u != q && null != u && $jscomp.defineProperty(n, h, { configurable: !0, writable: !0, value: u });
  128. }
  129. };
  130. $jscomp.polyfill(
  131. "Array.prototype.keys",
  132. function (h) {
  133. return h
  134. ? h
  135. : function () {
  136. return $jscomp.iteratorFromArray(this, function (h) {
  137. return h;
  138. });
  139. };
  140. },
  141. "es6",
  142. "es3"
  143. );
  144. $jscomp.findInternal = function (h, u, n) {
  145. h instanceof String && (h = String(h));
  146. for (var q = h.length, p = 0; p < q; p++) {
  147. var D = h[p];
  148. if (u.call(n, D, p, h)) return { i: p, v: D };
  149. }
  150. return { i: -1, v: void 0 };
  151. };
  152. $jscomp.polyfill(
  153. "Array.prototype.find",
  154. function (h) {
  155. return h
  156. ? h
  157. : function (h, n) {
  158. return $jscomp.findInternal(this, h, n).v;
  159. };
  160. },
  161. "es6",
  162. "es3"
  163. );
  164. var xml2abc_VERSION = 118,
  165. vertaal;
  166. (function () {
  167. function h(a, b) {
  168. return Array(a + 1).join(b);
  169. }
  170. function u(a, b) {
  171. for (var c = []; a;) c.push(b), --a;
  172. return c;
  173. }
  174. function n(a, b) {
  175. for (var c = 0, d = {}; c < a.length; ++c) d[a[c]] = b[c];
  176. return d;
  177. }
  178. function q(a, b) {
  179. var c = a.split(/%[ds]/);
  180. c.length > b.length && b.push("");
  181. return b
  182. .map(function (a, b) {
  183. return c[b] + a;
  184. })
  185. .join("");
  186. }
  187. function p(a, b) {
  188. v.info(q(a, b));
  189. }
  190. function D(a, b) {
  191. return -1 !== a.indexOf(b, a.length - b.length);
  192. }
  193. function H(a) {
  194. return Object.keys(a).map(function (a) {
  195. return parseInt(a);
  196. });
  197. }
  198. function M(a, b) {
  199. var c = [],
  200. d;
  201. if (Array.isArray(a)) for (d = 0; d < a.length; ++d) d in a && c.push([d, a[d]]);
  202. else for (d in a) c.push([d, a[d]]);
  203. c.sort(
  204. b
  205. ? function (a, b) {
  206. return a[0] - b[0];
  207. }
  208. : function (a, b) {
  209. return a[1] - b[1] || b[0] - a[0];
  210. }
  211. );
  212. return c;
  213. }
  214. function N(a) {
  215. this.reset();
  216. this.ixp = a;
  217. this.divs = this.mdur = this.ixm = 0;
  218. this.mtr = [4, 4];
  219. }
  220. function C(a, b) {
  221. this.tijd = 0;
  222. this.dur = a;
  223. this.fact = null;
  224. this.tup = [""];
  225. this.tupabc = "";
  226. this.grace = this.beam = 0;
  227. this.before = [];
  228. this.after = "";
  229. this.ns = b ? [b] : [];
  230. this.lyrs = {};
  231. this.pos = 0;
  232. this.tab = null;
  233. this.ntdec = "";
  234. }
  235. function E(a) {
  236. this.tijd = 0;
  237. this.str = a;
  238. this.pos = 0;
  239. }
  240. function F() { }
  241. function z(a) {
  242. this.maxtime = this.tijd = 0;
  243. this.gMaten = [];
  244. this.gLyrics = [];
  245. this.vnums = {};
  246. this.cnt = new F();
  247. this.vceCnt = 1;
  248. this.lastnote = null;
  249. this.bpl = a.b;
  250. this.cpl = a.n;
  251. this.repbra = 0;
  252. this.nvlt = a.v;
  253. }
  254. function G(a, b, c, d) {
  255. this.fnmext = a;
  256. this.outlist = [];
  257. this.infolist = [];
  258. this.title = "T:Title";
  259. this.key = "none";
  260. this.clefs = {};
  261. this.mtr = "none";
  262. this.tempo = 0;
  263. this.tempo_units = [1, 4];
  264. this.pad = b;
  265. this.X = c + 1;
  266. this.denL = d.d;
  267. this.volpan = d.m;
  268. this.cmpL = [];
  269. this.scale = "";
  270. this.tstep = d.t;
  271. this.stemless = 0;
  272. this.rightmargin = this.leftmargin = this.pagewidth = "";
  273. this.shiftStem = d.s;
  274. this.mnum = d.mnum;
  275. 4 == d.p.length &&
  276. ((this.scale = "" != d.p[0] ? parseFloat(d.p[0]) : ""),
  277. (this.pagewidth = "" != d.p[1] ? parseFloat(d.p[1]) : ""),
  278. (this.leftmargin = "" != d.p[2] ? parseFloat(d.p[2]) : ""),
  279. (this.rightmargin = "" != d.p[3] ? parseFloat(d.p[3]) : ""));
  280. }
  281. function W(a, b) {
  282. if (!a.join("")) return ["", 0];
  283. for (var c = [], d = 0; d < a.length; ++d) {
  284. var e = a[d];
  285. "" == e
  286. ? (e = b ? "_" : "*")
  287. : D(e, "_") && !D(e, "\\_")
  288. ? ((e = e.replace("_", "")), (b = 1))
  289. : (b = 0);
  290. c.push(e);
  291. }
  292. return [c.join(" "), b];
  293. }
  294. function I(a, b) {
  295. for (var c = a, d = b, e; b;) (e = a % b), (a = b), (b = e);
  296. return [c / a, d / a];
  297. }
  298. function O(a, b, c) {
  299. if (0 == a.dur) return "";
  300. var d = I(c * a.dur, 4 * b);
  301. b = d[0];
  302. c = d[1];
  303. a.fact && ((d = a.fact[0]), (a = a.fact[1]), (d = I(b * d, c * a)), (b = d[0]), (c = d[1]));
  304. 64 < c &&
  305. ((a = b / c),
  306. (d = Math.floor(a)),
  307. a - d < 0.1 * a && ((b = d), (c = 1)),
  308. (d = I(Math.round((64 * b) / c) || 1, 64)),
  309. p("denominator too small: %d/%d rounded to %d/%d", [b, c, d[0], d[1]]),
  310. (b = d[0]),
  311. (c = d[1]));
  312. return 1 == b ? (1 == c ? "" : 2 == c ? "/" : "/" + c) : 1 == c ? "" + b : b + "/" + c;
  313. }
  314. function P(a) {
  315. var b = a.match(/([_^]*)([A-Ga-g])([',]*)/);
  316. if (!b) return -1;
  317. a = b[1];
  318. var c = b[2];
  319. b = b[3];
  320. var d = c.toUpperCase();
  321. c = 60 + [0, 2, 4, 5, 7, 9, 11]["CDEFGAB".indexOf(d)] + (d != c ? 12 : 0);
  322. a && (c += ("^" == a[0] ? 1 : -1) * a.length);
  323. b && (c += ("'" == b[0] ? 12 : -12) * b.length);
  324. return c;
  325. }
  326. function X(a, b, c, d) {
  327. var e = 0;
  328. 0 <= c.indexOf("stafflines=1") && (e += 4);
  329. !d && 0 <= c.indexOf("bass") && (e += 12);
  330. e && ((c = "CDEFGAB".split("")), (e = c.indexOf(a) + e), (a = c[e % 7]), (b += Math.floor(e / 7)));
  331. 4 < b && (a = a.toLowerCase());
  332. 5 < b && (a += h(b - 5, "'"));
  333. 4 > b && (a += h(4 - b, ","));
  334. return a;
  335. }
  336. function Y(a, b) {
  337. var c = {
  338. maj: 8,
  339. ion: 8,
  340. m: 11,
  341. min: 11,
  342. aeo: 11,
  343. mix: 9,
  344. dor: 10,
  345. phr: 12,
  346. lyd: 7,
  347. loc: 13,
  348. non: 8,
  349. };
  350. b = b.slice(0, 3).toLowerCase();
  351. b =
  352. "Fb Cb Gb Db Ab Eb Bb F C G D A E B F# C# G# D# A# E# B#".split(" ")[c[b] + a] +
  353. (8 != c[b] ? b : "");
  354. c = "FCGDAEB".split("");
  355. a = 0 <= a ? n(c.slice(0, a), u(a, 1)) : n(c.slice(a), u(-a, -1));
  356. return [b, a];
  357. }
  358. function Q(a, b, c) {
  359. var d = 0,
  360. e = b[a];
  361. var g = e.tup.indexOf("start");
  362. -1 < g && e.tup.splice(g, 1);
  363. var f = a;
  364. for (c = [e.fact[0] / c[0], e.fact[1] / c[1]]; a < b.length;) {
  365. e = b[a];
  366. if (!(e instanceof E || e.grace)) {
  367. -1 < e.tup.indexOf("start")
  368. ? ((g = Q(a, b, c)), (a = g[0]), (g = g[1]), (d += g))
  369. : e.fact && (d += 1);
  370. g = e.tup.indexOf("stop");
  371. if (-1 < g) {
  372. e.tup.splice(g, 1);
  373. break;
  374. }
  375. if (!e.fact) {
  376. a = l;
  377. break;
  378. }
  379. var l = a;
  380. }
  381. a += 1;
  382. }
  383. l = [c[0], c[1], d];
  384. l = "3,2,3" == l.toString() ? "(3" : q("(%d:%d:%d", l);
  385. b[f].tupabc = l + b[f].tupabc;
  386. return [a, d];
  387. }
  388. function Z(a) {
  389. a = a.filter(function (a) {
  390. return a instanceof C;
  391. });
  392. for (var b = 0; b < a.length - 1;) {
  393. var c = a[b],
  394. d = a[b + 1];
  395. !c.fact &&
  396. !d.fact &&
  397. 0 < c.dur &&
  398. d.beam &&
  399. (3 * c.dur == d.dur
  400. ? ((d.dur = (2 * d.dur) / 3), (c.dur *= 2), (c.after = "<" + c.after), (b += 1))
  401. : 3 * d.dur == c.dur &&
  402. ((c.dur = (2 * c.dur) / 3), (d.dur *= 2), (c.after = ">" + c.after), (b += 1)));
  403. b += 1;
  404. }
  405. }
  406. function aa(a, b, c, d, e) {
  407. for (d = 0; d < a.length;)
  408. (c = a[d]), c instanceof C && c.fact && !c.grace && ((c = Q(d, a, [1, 1])), (d = c[0])), (d += 1);
  409. d = [];
  410. for (var g, f = 0; f < a.length; ++f) {
  411. c = a[f];
  412. if (c instanceof C) {
  413. var l = O(c, b, e),
  414. k = 1 < c.ns.length;
  415. g = c.ns.filter(function (a) {
  416. return D(a, "-");
  417. });
  418. g = g.map(function (a) {
  419. return a.slice(0, -1);
  420. });
  421. var m = "";
  422. k && g.length == c.ns.length && ((c.ns = g), (m = "-"));
  423. g = c.tupabc + c.before.join("");
  424. k && (g += "[");
  425. g += c.ns.join("");
  426. k && (g += "]" + m);
  427. D(g, "-") && ((g = g.slice(0, -1)), (m = "-"));
  428. g += l + m;
  429. g += c.after;
  430. c = c.beam;
  431. } else c.str instanceof Array && (c.str = c.str[0]), (g = c.str), (c = 1);
  432. c ? d.push(g) : d.push(" " + g);
  433. }
  434. for (d = d.join(""); 0 <= d.indexOf("!ped!!ped!");) d = d.replace(/!ped!!ped!/g, "!ped!");
  435. for (; 0 <= d.indexOf("!ped-up!!ped-up!");) d = d.replace(/!ped-up!!ped-up!/g, "!ped-up!");
  436. for (; 0 <= d.indexOf("!8va(!!8va)!");) d = d.replace(/!8va\(!!8va\)!/g, "");
  437. return d;
  438. }
  439. function ba(a, b) {
  440. a.map(function (a, b) {
  441. a.pos = b;
  442. });
  443. a.sort(function (a, b) {
  444. return a.tijd - b.tijd || a.pos - b.pos;
  445. });
  446. for (var c = 0, d = [], e = [], g = 0; g < a.length; ++g) {
  447. var f = a[g];
  448. f.tijd > c && K(f.tijd - c, b) && (d.push(new C(f.tijd - c, "x")), e.push(d.length - 1));
  449. if (f instanceof E) f.tijd < c && (f.tijd = c), d.push(f), (c = f.tijd);
  450. else {
  451. if (f.tijd < c) {
  452. if ("z" == f.ns[0]) continue;
  453. var l = d[d.length - 1];
  454. if (l.tijd <= f.tijd)
  455. if ("z" == l.ns[0])
  456. (l.dur = f.tijd - l.tijd),
  457. 0 == l.dur && d.pop(),
  458. p("overlap in part %d, measure %d: rest shortened", [b.ixp + 1, b.ixm + 1]);
  459. else {
  460. l.ns = l.ns.concat(f.ns);
  461. p("overlap in part %d, measure %d: added chord", [b.ixp + 1, b.ixm + 1]);
  462. f.dur = f.tijd + f.dur - c;
  463. if (0 >= f.dur) continue;
  464. f.tijd = c;
  465. }
  466. else {
  467. p("overlapping notes in one voice! part %d, measure %d, note %s discarded", [
  468. b.ixp + 1,
  469. b.ixm + 1,
  470. f instanceof C ? f.ns : f.str,
  471. ]);
  472. continue;
  473. }
  474. }
  475. d.push(f);
  476. if (f instanceof C)
  477. if (((c = f.ns[0]), "x" == c || "z" == c)) e.push(d.length - 1);
  478. else if (e.length) {
  479. if (f.beam && !f.grace) for (c = 0; c < e.length; ++c) d[e[c]].beam = f.beam;
  480. e = [];
  481. }
  482. c = f.tijd + f.dur;
  483. }
  484. }
  485. 0 == c &&
  486. p("empty measure in part %d, measure %d, it should contain at least a rest to advance the time!", [
  487. b.ixp + 1,
  488. b.ixm + 1,
  489. ]);
  490. return d;
  491. }
  492. function ca(a) {
  493. function b(a) {
  494. a = q('<part-group number="%d" type="%s"></part-group>', [a, "stop"]);
  495. return $(a, d);
  496. }
  497. var c,
  498. d = a[0];
  499. var e = [];
  500. var g = [];
  501. var f = a.children();
  502. for (c = 0; c < f.length; c++)
  503. if (((a = $(f[c])), "part-group" == a[0].tagName)) {
  504. var l = a.attr("number");
  505. var k = a.attr("type");
  506. var m = g.indexOf(l);
  507. "start" == k
  508. ? -1 < m
  509. ? (e.push(b(l)), e.push(a))
  510. : (e.push(a), g.push(l))
  511. : -1 < m && (g.splice(m, 1), e.push(a));
  512. } else e.push(a);
  513. for (c = g.length - 1; 0 <= c; --c) (l = g[c]), e.push(b(l));
  514. return e;
  515. }
  516. function J(a, b, c) {
  517. if (0 == a.length) return [[], []];
  518. var d = a.shift();
  519. if ("part-group" == d[0].tagName) {
  520. var e = d.attr("number");
  521. var g = d.attr("type");
  522. if ("start" == g) {
  523. g = [];
  524. for (f in { "group-symbol": 0, "group-barline": 0, "group-name": 0, "group-abbreviation": 0 })
  525. g.push(d.find(f).text() || "");
  526. b[e] = g;
  527. c.push(e);
  528. var f = J(a, b, c);
  529. a = f[0];
  530. d = f[1];
  531. f = J(d, b, c);
  532. b = f[0];
  533. c = f[1];
  534. return [[a].concat(b), c];
  535. }
  536. c = c.pop();
  537. a.length && "stop" == a[0].attr("type") && e != c && ((f = b[c]), (b[c] = b[e]), (b[e] = f));
  538. b = b[e];
  539. return [[b], a];
  540. }
  541. f = J(a, b, c);
  542. b = f[0];
  543. a = f[1];
  544. return [
  545. [
  546. ["name_tuple", d.find("part-name").text() || "", d.find("part-abbreviation").text() || ""],
  547. ].concat(b),
  548. a,
  549. ];
  550. }
  551. function R(a) {
  552. var b, c;
  553. if (0 == a.length) return [];
  554. var d = [];
  555. for (b = 0; b < a.length; ++b) {
  556. var e = a[b];
  557. if (1 == e.length) d.push("" + e[0]);
  558. else {
  559. d.push("(");
  560. for (c = 0; c < e.length; ++c) d.push("" + e[c]);
  561. d.push(")");
  562. }
  563. d.push("|");
  564. }
  565. d.splice(-1, 1);
  566. 1 < a.length && (d = ["{"].concat(d).concat(["}"]));
  567. return d;
  568. }
  569. function S(a, b, c, d, e, g) {
  570. if ("name_tuple" == a[0])
  571. (d = d.shift()),
  572. b[0] && ((a[1] = b[0] + ":" + a[1]), (a[2] = b[1] + ":" + a[2])),
  573. e.push(a),
  574. g.push.apply(g, R(d));
  575. else if (2 == a.length && "name_tuple" == a[0][0])
  576. (d = d.shift()),
  577. (c = ["name_tuple", "", ""]),
  578. (c[1] = a[0][1] + ":" + a[1][2]),
  579. (c[2] = a[0][2] + ":" + a[1][3]),
  580. e.push(c),
  581. g.push.apply(g, R(d));
  582. else {
  583. var f = a[a.length - 1];
  584. b = f[0];
  585. var l = f[1];
  586. var k = f[2];
  587. f = f[3];
  588. l = "yes" == l || c;
  589. g.push("brace" == b ? "{" : "[");
  590. for (c = 0; c < a.length - 1; ++c) S(a[c], [k, f], l, d, e, g), l && g.push("|");
  591. l && g.splice(-1, 1);
  592. g.push("brace" == b ? "}" : "]");
  593. }
  594. }
  595. function da(a) {
  596. for (var b = "", c = a.children(), d = 0; d < c.length; ++d) {
  597. var e = c[d];
  598. switch (e.tagName) {
  599. case "elision":
  600. b += "~";
  601. break;
  602. case "text":
  603. b += $(e).text().replace(/_/g, "\\_").replace(/-/g, "\\-").replace(/ /g, "~");
  604. }
  605. }
  606. if (!b) return b;
  607. c = a.find("syllabic").text();
  608. if ("begin" == c || "middle" == c) b += "-";
  609. a.find("extend").length && (b += "_");
  610. return b;
  611. }
  612. function ea(a) {
  613. var b = { diamond: 1, triangle: 1, square: 1, normal: 1 },
  614. c = fa,
  615. d,
  616. e = "default",
  617. g = { default: [] },
  618. f = { default: [] };
  619. a = a.split("\n");
  620. for (d = 0; d < a.length; ++d) {
  621. var l = a[d];
  622. if (0 <= l.indexOf("I:percmap")) {
  623. l = l.split(" ").map(function (a) {
  624. return a.trim();
  625. });
  626. var k = l[4];
  627. k in b && (k = k + "+," + k);
  628. l = "%%map perc" + e + " " + l[1] + " print=" + l[2] + " midi=" + l[3] + " heads=" + k;
  629. g[e].push(l);
  630. }
  631. 0 <= l.indexOf("%%MIDI") && f[e].push(l);
  632. 0 <= l.indexOf("V:") &&
  633. (k = l.match(/V:\s*(\S+)/)) &&
  634. ((e = k[1]), e in g || ((g[e] = []), (f[e] = [])));
  635. }
  636. b = Object.keys(g).sort();
  637. for (d = 0; d < b.length; ++d) c = c.concat(g[b[d]]);
  638. e = "default";
  639. for (d = 0; d < a.length; ++d)
  640. (l = a[d]),
  641. 0 <= l.indexOf("I:percmap") ||
  642. 0 <= l.indexOf("%%MIDI") ||
  643. (0 <= l.indexOf("V:") || 0 <= l.indexOf("K:")
  644. ? ((k = l.match(/V:\s*(\S+)/)) && (e = k[1]),
  645. c.push(l),
  646. e in f && f[e].length && ((c = c.concat(f[e])), delete f[e]),
  647. 0 <= l.indexOf("perc") && -1 == l.indexOf("map=") && (l += " map=perc"),
  648. 0 <= l.indexOf("map=perc") && 0 < g[e].length && c.push("%%voicemap perc" + e),
  649. 0 <= l.indexOf("map=off") && c.push("%%voicemap"))
  650. : c.push(l));
  651. return c.join("\n");
  652. }
  653. function L(a, b) {
  654. var c = a;
  655. 4 < b && (c = a.toLowerCase());
  656. 5 < b && (c += h(b - 5, "'"));
  657. 4 > b && (c += h(4 - b, ","));
  658. return c;
  659. }
  660. function K(a, b) {
  661. if (a > b.divs / 16) return 1;
  662. p("MuseScore bug: incorrect duration, smaller then 1/64! in measure %d, part %d", [b.ixm, b.ixp]);
  663. return 0;
  664. }
  665. function w(a) {
  666. this.slurBuf = {};
  667. this.dirStk = {};
  668. this.ingrace = 0;
  669. this.msc = new z(a);
  670. this.unfold = a.u;
  671. this.ctf = a.c;
  672. this.gStfMap = [];
  673. this.midiMap = [];
  674. this.drumInst = {};
  675. this.drumNotes = {};
  676. this.instMid = [];
  677. this.midDflt = [-1, -1, -1, -91];
  678. this.msralts = {};
  679. this.curalts = {};
  680. this.stfMap = {};
  681. this.vce2stf = {};
  682. this.clefMap = {};
  683. this.curClef = {};
  684. this.stemDir = {};
  685. this.clefOct = {};
  686. this.curStf = {};
  687. this.nolbrk = a.x;
  688. this.doPageFmt = 1 == a.p.length;
  689. this.tstep = a.t;
  690. this.dirtov1 = a.v1;
  691. this.ped = !a.noped;
  692. this.wstems = a.stm;
  693. this.pedVce = null;
  694. this.repeat_str = {};
  695. this.tabVceMap = {};
  696. this.koppen = {};
  697. this.note_alts = [
  698. "=C ^C =D ^D =E =F ^F =G ^G =A ^A =B".split(" "),
  699. "^B _D ^^C _E _F ^E _G ^^F _A ^^G _B _C".split(" "),
  700. "__D ^^B __E __F ^^D __G ^^E __A _/A __B __C ^^A".split(" "),
  701. ];
  702. this.step_map = { C: 0, D: 2, E: 4, F: 5, G: 7, A: 9, B: 11 };
  703. }
  704. var ha = Math.pow(2, 53),
  705. T = {
  706. "ornaments>trill-mark": "T",
  707. "ornaments>mordent": "M",
  708. "ornaments>inverted-mordent": "P",
  709. "ornaments>turn": "!turn!",
  710. "ornaments>inverted-turn": "!invertedturn!",
  711. "technical>up-bow": "u",
  712. "technical>down-bow": "v",
  713. "technical>harmonic": "!open!",
  714. "technical>open-string": "!open!",
  715. "technical>stopped": "!plus!",
  716. "technical>snap-pizzicato": "!snap!",
  717. "technical>thumb-position": "!thumb!",
  718. "articulations>accent": "!>!",
  719. "articulations>strong-accent": "!^!",
  720. "articulations>staccato": ".",
  721. "articulations>staccatissimo": "!wedge!",
  722. "articulations>scoop": "!slide!",
  723. fermata: "!fermata!",
  724. arpeggiate: "!arpeggio!",
  725. "articulations>tenuto": "!tenuto!",
  726. "articulations>spiccato": "!wedge!",
  727. "articulations>breath-mark": "!breath!",
  728. "articulations>detached-legato": "!tenuto!.",
  729. },
  730. U = {
  731. p: "!p!",
  732. pp: "!pp!",
  733. ppp: "!ppp!",
  734. pppp: "!pppp!",
  735. f: "!f!",
  736. ff: "!ff!",
  737. fff: "!fff!",
  738. ffff: "!ffff!",
  739. mp: "!mp!",
  740. mf: "!mf!",
  741. sfz: "!sfz!",
  742. },
  743. fa =
  744. '%%beginsvg\n<defs>,<text id="x" x="-3" y="0">&#xe263;</text>,<text id="x-" x="-3" y="0">&#xe263;</text>,<text id="x+" x="-3" y="0">&#xe263;</text>,<text id="normal" x="-3.7" y="0">&#xe0a3;</text>,<text id="normal-" x="-3.7" y="0">&#xe0a3;</text>,<text id="normal+" x="-3.7" y="0">&#xe0a4;</text>,<g id="circle-x"><text x="-3" y="0">&#xe263;</text><circle r="4" class="stroke"></circle></g>,<g id="circle-x-"><text x="-3" y="0">&#xe263;</text><circle r="4" class="stroke"></circle></g>,<path id="triangle" d="m-4 -3.2l4 6.4 4 -6.4z" class="stroke" style="stroke-width:1.4"></path>,<path id="triangle-" d="m-4 -3.2l4 6.4 4 -6.4z" class="stroke" style="stroke-width:1.4"></path>,<path id="triangle+" d="m-4 -3.2l4 6.4 4 -6.4z" class="stroke" style="fill:#000"></path>,<path id="square" d="m-3.5 3l0 -6.2 7.2 0 0 6.2z" class="stroke" style="stroke-width:1.4"></path>,<path id="square-" d="m-3.5 3l0 -6.2 7.2 0 0 6.2z" class="stroke" style="stroke-width:1.4"></path>,<path id="square+" d="m-3.5 3l0 -6.2 7.2 0 0 6.2z" class="stroke" style="fill:#000"></path>,<path id="diamond" d="m0 -3l4.2 3.2 -4.2 3.2 -4.2 -3.2z" class="stroke" style="stroke-width:1.4"></path>,<path id="diamond-" d="m0 -3l4.2 3.2 -4.2 3.2 -4.2 -3.2z" class="stroke" style="stroke-width:1.4"></path>,<path id="diamond+" d="m0 -3l4.2 3.2 -4.2 3.2 -4.2 -3.2z" class="stroke" style="fill:#000"></path>,</defs>\n%%endsvg'.split(
  745. ","
  746. ),
  747. V =
  748. '%%beginsvg\n,<style type="text/css">\n,.bf {font-family:sans-serif; font-size:7px}\n,</style>\n,<defs>\n,<rect id="clr" x="-3" y="-1" width="6" height="5" fill="white"></rect>\n,<rect id="clr2" x="-3" y="-1" width="11" height="5" fill="white"></rect>\n'.split(
  749. ","
  750. ),
  751. v;
  752. N.prototype.reset = function () {
  753. this.lline = this.attr = "";
  754. this.rline = "|";
  755. this.lnum = "";
  756. };
  757. F.prototype.inc = function (a, b) {
  758. this.counters[a][b] = (this.counters[a][b] || 0) + 1;
  759. };
  760. F.prototype.clear = function (a) {
  761. a = Object.keys(a);
  762. var b = u(a.length, 0);
  763. this.counters = { note: n(a, b), nopr: n(a, b), nopt: n(a, b) };
  764. };
  765. F.prototype.getv = function (a, b) {
  766. return this.counters[a][b];
  767. };
  768. F.prototype.prcnt = function (a) {
  769. for (var b in this.counters.note)
  770. 0 != this.getv("nopr", b) &&
  771. p("part %d, voice %d has %d skipped non printable notes", [a, b, this.getv("nopr", b)]),
  772. 0 != this.getv("nopt", b) &&
  773. p("part %d, voice %d has %d notes without pitch", [a, b, this.getv("nopt", b)]),
  774. 0 == this.getv("note", b) && p("part %d, skipped empty voice %d", [a, b]);
  775. };
  776. z.prototype.initVoices = function (a) {
  777. this.vtimes = {};
  778. this.voices = {};
  779. this.lyrics = {};
  780. for (var b in this.vnums) (this.vtimes[b] = 0), (this.voices[b] = []), (this.lyrics[b] = []);
  781. a && this.cnt.clear(this.vnums);
  782. };
  783. z.prototype.incTime = function (a) {
  784. this.tijd += a;
  785. 0 > this.tijd && (this.tijd = 0);
  786. this.tijd > this.maxtime && (this.maxtime = this.tijd);
  787. };
  788. z.prototype.appendElemCv = function (a, b) {
  789. for (var c in a) this.appendElem(c, b);
  790. };
  791. z.prototype.insertElem = function (a, b) {
  792. b = new E(b);
  793. b.tijd = 0;
  794. this.voices[a].unshift(b);
  795. };
  796. z.prototype.appendObj = function (a, b, c) {
  797. b.tijd = this.tijd;
  798. this.voices[a].push(b);
  799. this.incTime(c);
  800. this.tijd > this.vtimes[a] && (this.vtimes[a] = this.tijd);
  801. };
  802. z.prototype.appendElemT = function (a, b, c) {
  803. b = new E(b);
  804. b.tijd = c;
  805. this.voices[a].push(b);
  806. };
  807. z.prototype.appendElem = function (a, b, c) {
  808. this.appendObj(a, new E(b), 0);
  809. c && this.cnt.inc("note", a);
  810. };
  811. z.prototype.appendNote = function (a, b, c) {
  812. b.ns.push(b.ntdec + c);
  813. this.appendObj(a, b, parseInt(b.dur));
  814. this.lastnote = b;
  815. "z" != c && "x" != c && (this.cnt.inc("note", a), b.grace || this.lyrics[a].push(b.lyrs));
  816. };
  817. z.prototype.getLastRec = function (a) {
  818. return this.gMaten.length ? ((a = this.gMaten[this.gMaten.length - 1][a]), a[a.length - 1]) : null;
  819. };
  820. z.prototype.getLastMelis = function (a, b) {
  821. return this.gLyrics.length && ((a = this.gLyrics[this.gLyrics.length - 1][a]), b in a) ? a[b][1] : 0;
  822. };
  823. z.prototype.addChord = function (a, b) {
  824. for (var c = 0; c < a.before.length; c++) {
  825. var d = a.before[c];
  826. 0 > this.lastnote.before.indexOf(d) && this.lastnote.before.push(d);
  827. }
  828. this.lastnote.ns.push(a.ntdec + b);
  829. };
  830. z.prototype.addBar = function (a, b) {
  831. b.mdur &&
  832. this.maxtime > b.mdur &&
  833. p("measure %d in part %d longer than metre", [b.ixm + 1, b.ixp + 1]);
  834. this.tijd = this.maxtime;
  835. for (var c in this.vnums) {
  836. if (b.lline || b.lnum) {
  837. var d = this.getLastRec(c);
  838. if (d) {
  839. var e = d.str;
  840. b.lline && (e = (e + b.lline).replace(/:\|:/g, "::").replace(/\|\|/g, "|"));
  841. 3 == this.nvlt
  842. ? b.ixp + parseInt(c) == Math.min.apply(null, H(this.vnums)) && (e += b.lnum)
  843. : 4 == this.nvlt
  844. ? parseInt(c) == Math.min.apply(null, H(this.vnums)) && (e += b.lnum)
  845. : b.lnum && ((e += b.lnum), (this.repbra = 1));
  846. d.str = e;
  847. } else b.lline && this.insertElem(c, "|:");
  848. }
  849. a && (d = this.getLastRec(c)) && (d.str += a);
  850. b.attr && this.insertElem(c, "" + b.attr);
  851. this.appendElem(c, " " + b.rline);
  852. this.voices[c] = ba(this.voices[c], b);
  853. d = this.lyrics[c];
  854. e = {};
  855. for (
  856. var g = d.reduce(function (a, b) {
  857. return a.concat(H(b));
  858. }, []),
  859. f = Math.max.apply(null, g.concat([0]));
  860. 0 < f;
  861. --f
  862. ) {
  863. g = d.map(function (a) {
  864. return a[f] || "";
  865. });
  866. var l = this.getLastMelis(c, f);
  867. e[f] = W(g, l);
  868. }
  869. this.lyrics[c] = e;
  870. Z(this.voices[c]);
  871. }
  872. this.gMaten.push(this.voices);
  873. this.gLyrics.push(this.lyrics);
  874. this.tijd = this.maxtime = 0;
  875. this.initVoices();
  876. };
  877. z.prototype.outVoices = function (a, b) {
  878. var c;
  879. var d = {};
  880. var e = Math.min.apply(null, H(this.vnums) || [1]);
  881. for (c in this.vnums)
  882. if (0 != this.cnt.getv("note", c)) {
  883. if (v.denL) var g = v.denL;
  884. else {
  885. var f, l;
  886. g = c;
  887. var k = this.gMaten;
  888. var m = a;
  889. var B = 0;
  890. var h = ha;
  891. for (var r = [4, 8, 16]; r.length;) {
  892. var t = r.shift(),
  893. q = 0;
  894. for (l = 0; l < k.length; ++l) {
  895. var y = k[l][g];
  896. for (f = 0; f < y.length; ++f) {
  897. var p = y[f];
  898. p instanceof E || 0 == p.dur || (q += O(p, m[l], t).length);
  899. }
  900. }
  901. q < h && ((B = t), (h = q));
  902. }
  903. g = B;
  904. }
  905. v.cmpL.push(g);
  906. f = [];
  907. l = {};
  908. for (k = 0; k < this.gMaten.length; ++k) {
  909. m = this.gMaten[k][c];
  910. f.push(aa(m, a[k], k, b, g));
  911. m = void 0;
  912. r = this.gLyrics;
  913. if (0 != k)
  914. for (m in ((B = this.gMaten[k][c]), (h = r[k][c]), (r = r[k - 1][c]), r))
  915. if (((t = r[m][1]), !(m in h) && t)) {
  916. t = B;
  917. q = [];
  918. for (y = 0; y < t.length; ++y)
  919. if (((p = t[y]), p instanceof C && !p.grace)) {
  920. if ("z" == p.ns[0] || "x" == p.ns[0]) break;
  921. q.push("_");
  922. }
  923. (t = q.join(" ")) && (h[m] = [t, 0]);
  924. }
  925. B = this.gLyrics[k][c];
  926. for (n in B)
  927. if (((m = B[n]), (m = m[0]), n in l)) {
  928. for (; l[n].length < k;) l[n].push("");
  929. l[n].push(m);
  930. } else l[n] = u(k, "").concat([m]);
  931. }
  932. for (n in l) (m = l[n]), (g = f.length - m.length), (l[n] = m.concat(u(g, "")));
  933. v.add("V:" + this.vceCnt);
  934. this.repbra &&
  935. (1 == this.nvlt && 1 < this.vceCnt && v.add("I:repbra 0"),
  936. 2 == this.nvlt && parseInt(c) > e && v.add("I:repbra 0"));
  937. 0 < this.cpl ? (this.bpl = 0) : 0 == this.bpl && (this.cpl = 100);
  938. for (g = 0; f.length;) {
  939. k = 1;
  940. for (
  941. m = f[0];
  942. k < f.length &&
  943. !(0 < this.cpl && m.length + f[k].length >= this.cpl) &&
  944. !(0 < this.bpl && k >= this.bpl);
  945. )
  946. (m += f[k]), (k += 1);
  947. g += k;
  948. v.add(m + " %" + g);
  949. f.splice(0, k);
  950. B = M(l, 1);
  951. for (h = 0; h < B.length; ++h) {
  952. m = B[h];
  953. var n = m[0];
  954. m = m[1];
  955. v.add("w: " + m.slice(0, k).join("|") + "|");
  956. m.splice(0, k);
  957. }
  958. }
  959. d[c] = this.vceCnt;
  960. this.vceCnt += 1;
  961. }
  962. this.gMaten = [];
  963. this.gLyrics = [];
  964. this.cnt.prcnt(b + 1);
  965. return d;
  966. };
  967. G.prototype.add = function (a) {
  968. this.outlist.push(a + "\n");
  969. };
  970. G.prototype.info = function (a, b) {
  971. this.infolist.push(("undefined" == typeof b || b ? "-- " : "") + a);
  972. };
  973. G.prototype.mkHeader = function (a, b, c, d, e) {
  974. var g = [],
  975. f = [],
  976. l,
  977. k;
  978. var m = a.slice();
  979. for (k = 0; k < b.length; ++k) {
  980. var h = b[k];
  981. try {
  982. S(h, ["", ""], "", a, g, f);
  983. } catch (ia) {
  984. p("lousy musicxml: error in part-list", []);
  985. }
  986. }
  987. b = f.join(" ");
  988. a = {};
  989. for (k = 0; k < m.length && k < g.length; ++k) {
  990. var x = m[k];
  991. h = g[k];
  992. var r = h[1];
  993. h = h[2];
  994. 0 != x.length &&
  995. ((x = x[0][0]),
  996. (r = r.replace(/\n/g, "\\n").replace(/\.:/g, ".").replace(/^:|:$/g, "")),
  997. (h = h.replace(/\n/g, "\\n").replace(/\.:/g, ".").replace(/^:|:$/g, "")),
  998. (a[x] = (r ? 'nm="' + r + '"' : "") + (h ? ' snm="' + h + '"' : "")));
  999. }
  1000. g = [
  1001. q("X:%d\n%s\n%s", [this.X, this.title, -1 < this.mnum ? "%%measurenb " + this.mnum + "\n" : ""]),
  1002. ];
  1003. "" !== this.scale && g.push("%%scale " + this.scale + "\n");
  1004. "" !== this.pagewidth && g.push("%%pagewidth " + this.pagewidth + "cm\n");
  1005. "" !== this.leftmargin && g.push("%%leftmargin " + this.leftmargin + "cm\n");
  1006. "" !== this.rightmargin && g.push("%%rightmargin " + this.rightmargin + "cm\n");
  1007. b && 1 < f.length && g.push("%%score " + b + "\n");
  1008. m = this.tempo ? q("Q:%d/%d=%s\n", [this.tempo_units[0], this.tempo_units[1], this.tempo]) : "";
  1009. f = [];
  1010. for (k = 0; k < this.cmpL.length; ++k) (h = this.cmpL[k]), (f[h] = (f[h] || 0) + 1);
  1011. f = M(f);
  1012. f = f[f.length - 1][0];
  1013. f = this.denL ? this.denL : f;
  1014. g.push(q("L:1/%d\n%sM:%s\n", [f, m, this.mtr]));
  1015. g.push(q("I:linebreak $\nK:%s\n", [this.key]));
  1016. this.stemless && g.push("U:s=!stemless!\n");
  1017. m = Object.keys(d).sort();
  1018. for (k = 0; k < m.length; ++k) g = g.concat(d[m[k]]);
  1019. this.dojef = 0;
  1020. for (l in this.clefs) {
  1021. h = c[l - 1];
  1022. k = h[0];
  1023. b = h[1];
  1024. r = h[2];
  1025. x = h[3];
  1026. m = h.slice(4);
  1027. h = this.clefs[l];
  1028. m.length && 0 > h.indexOf("perc") && (h = (h + " map=perc").trim());
  1029. g.push(q("V:%d %s %s\n", [l, h, a[l] || ""]));
  1030. l in d &&
  1031. (g.push(q("%%voicemap tab%d\n", [l])),
  1032. g.push("K:none\nM:none\n%%clef none\n%%staffscale 1.6\n%%flatbeams true\n%%stemdir down\n"));
  1033. -1 < h.indexOf("perc") && g.push("K:none\n");
  1034. 1 < this.volpan
  1035. ? (0 < k && k != l && g.push("%%MIDI channel " + k + "\n"),
  1036. 0 < b && g.push("%%MIDI program " + (b - 1) + "\n"),
  1037. 0 <= r && g.push("%%MIDI control 7 " + r + "\n"),
  1038. 0 <= x && g.push("%%MIDI control 10 " + x + "\n"))
  1039. : 0 < this.volpan &&
  1040. (m.length && 0 < k && g.push("%%MIDI channel " + k + "\n"),
  1041. 0 < b && g.push("%%MIDI program " + (b - 1) + "\n"));
  1042. for (k = 0; k < m.length; ++k)
  1043. if (
  1044. ((h = m[k].nt),
  1045. (r = m[k].step),
  1046. (b = m[k].midi),
  1047. (x = m[k].nhd) || (x = "normal"),
  1048. P(h) != b || h != r)
  1049. )
  1050. 0 < this.volpan && g.push("%%MIDI drummap " + h + " " + b + "\n"),
  1051. g.push("I:percmap " + h + " " + r + " " + b + " " + x + "\n"),
  1052. (this.dojef = this.tstep);
  1053. f != this.cmpL[l - 1] && g.push("L:1/" + this.cmpL[l - 1] + "\n");
  1054. }
  1055. this.outlist = g.concat(this.outlist);
  1056. c = Object.keys(e).sort();
  1057. if (c.length) {
  1058. var t = [];
  1059. var n = this.shiftStem
  1060. ? '<g id="kop%s" class="bf"><use xlink:href="#clr"></use><text x="-2" y="3">%s</text></g>\n'.replace(
  1061. "-2",
  1062. "-5"
  1063. )
  1064. : '<g id="kop%s" class="bf"><use xlink:href="#clr"></use><text x="-2" y="3">%s</text></g>\n',
  1065. y = this.shiftStem
  1066. ? '<g id="kop%s" class="bf"><use xlink:href="#clr2"></use><text x="-2" y="3">%s</text></g>\n'.replace(
  1067. "-2",
  1068. "-5"
  1069. )
  1070. : '<g id="kop%s" class="bf"><use xlink:href="#clr2"></use><text x="-2" y="3">%s</text></g>\n';
  1071. d = this.shiftStem
  1072. ? V.map(function (a) {
  1073. return a.replace("-3", "-6");
  1074. })
  1075. : V;
  1076. c.forEach(function (a) {
  1077. t.push(1 < a.length ? q(y, [a, a]) : q(n, [a, a]));
  1078. });
  1079. this.outlist = d.concat(t, "</defs>\n%%endsvg\n", this.outlist);
  1080. }
  1081. };
  1082. G.prototype.writeall = function () {
  1083. var a = v.outlist.join("");
  1084. this.dojef && (a = ea(a));
  1085. return [a, this.infolist.join("\n")];
  1086. };
  1087. w.prototype.matchSlur = function (a, b, c, d, e, g) {
  1088. if (-1 != ["start", "stop"].indexOf(a))
  1089. if ((b || (b = "1"), b in this.slurBuf)) {
  1090. var f = this.slurBuf[b],
  1091. l = f[0],
  1092. k = f[1],
  1093. m = f[2];
  1094. f = f[3];
  1095. a != l
  1096. ? (c != k || "start" != l || (f && g) || (m.before.unshift("("), (d.after += ")")),
  1097. delete this.slurBuf[b])
  1098. : (p("double slur numbers %s-%s in part %d, measure %d, voice %d note %s, first discarded", [
  1099. a,
  1100. b,
  1101. this.msr.ixp + 1,
  1102. this.msr.ixm + 1,
  1103. c,
  1104. d.ns,
  1105. ]),
  1106. (this.slurBuf[b] = [a, c, d, e]));
  1107. } else this.slurBuf[b] = [a, c, d, e];
  1108. };
  1109. w.prototype.doNotations = function (a, b, c) {
  1110. for (var d = Object.keys(T).sort(), e = 0; e < d.length; ++e) {
  1111. var g = d[e],
  1112. f = T[g];
  1113. b.find(g).length && a.before.push(f);
  1114. }
  1115. e = b.find("ornaments>tremolo");
  1116. e.length &&
  1117. ((g = e.attr("type")),
  1118. (d = h(parseInt(e.text()), "/")),
  1119. "single" == g
  1120. ? a.before.unshift("!" + d + "!")
  1121. : ((a.fact = null),
  1122. this.tstep
  1123. ? "stop" == g && a.before.unshift("!trem" + e.text() + "!")
  1124. : "start" == g && a.before.unshift("!" + d + "-!")));
  1125. d = b.find("technical>fingering");
  1126. c ||
  1127. d.each(function () {
  1128. a.before.push("!" + $(this).text() + "!");
  1129. });
  1130. d = b.find("technical>string");
  1131. d.length &&
  1132. c &&
  1133. (this.tstep
  1134. ? ((c = b.find("technical>fret")), c.length && (a.tab = [d.eq(0).text(), c.eq(0).text()]))
  1135. : d.each(function () {
  1136. var b = "!" + $(this).text() + "!";
  1137. 0 > a.ntdec.indexOf(b) && (a.ntdec += b);
  1138. }));
  1139. c = b.find("ornaments>wavy-line");
  1140. c = $jscomp.makeIterator(c.toArray());
  1141. for (d = c.next(); !d.done; d = c.next())
  1142. switch (((d = d.value), $(d).attr("type"))) {
  1143. case "start":
  1144. a.before.unshift("!trill(!");
  1145. break;
  1146. case "stop":
  1147. a.after += "!trill)!";
  1148. }
  1149. c = b.find("glissando");
  1150. 0 == c.length && (c = b.find("slide"));
  1151. c.length &&
  1152. ((b = "wavy" == c.attr("line-type") ? "~" : "-"),
  1153. "start" == c.attr("type")
  1154. ? a.before.unshift(q("!%s(!", [b]))
  1155. : "stop" == c.attr("type") && a.before.unshift(q("!%s)!", [b])));
  1156. };
  1157. w.prototype.tabnote = function (a, b, c, d, e) {
  1158. var g;
  1159. var f = this.step_map[b] + parseInt(a || "0");
  1160. 11 < f && ((c += 1), (f -= 12));
  1161. 0 > f && (--c, (f += 12));
  1162. a = e.tab[0];
  1163. b = e.tab[1];
  1164. for (g = 0; 4 > g; ++g) {
  1165. var l = this.note_alts[g % 3][f];
  1166. var k = c;
  1167. -1 < ["^B", "^^B"].indexOf(l) && --k;
  1168. -1 < ["_C", "__C"].indexOf(l) && (k += 1);
  1169. if (-1 < l.indexOf("/") || 3 == g) k = 9;
  1170. l = L(l, k);
  1171. var m = this.tabmap[[d, l]] || ["", ""];
  1172. k = m[0];
  1173. m = m[1];
  1174. if (!k) break;
  1175. if (a == k) return l;
  1176. 3 == g &&
  1177. (p("rejected: voice %d note %s string %s fret %s remains: string %s fret %s", [
  1178. d,
  1179. l,
  1180. a,
  1181. b,
  1182. k,
  1183. m,
  1184. ]),
  1185. (e.tab = [k, m]));
  1186. }
  1187. this.tabmap[[d, l]] = e.tab;
  1188. return l;
  1189. };
  1190. w.prototype.ntAbc = function (a, b, c, d, e, g) {
  1191. var f = {
  1192. "double-flat": -2,
  1193. "flat-flat": -2,
  1194. flat: -1,
  1195. natural: 0,
  1196. sharp: 1,
  1197. "sharp-sharp": 2,
  1198. "double-sharp": 2,
  1199. };
  1200. b += this.clefOct[this.curStf[d]] || 0;
  1201. var l = c.find("accidental").text(),
  1202. k = c.find("pitch>alter").text();
  1203. if (e.tab) return this.tabnote(k, a, b, d, e);
  1204. g &&
  1205. this.tstep &&
  1206. ((e = ["__", "_", "", "^", "^^"][parseInt(k || "0") + 2] + L(a, b)),
  1207. p("no string notation found for note %s in voice %d", [e, d]));
  1208. b = L(a, b);
  1209. !k && this.msralts[a] && (k = 0);
  1210. e = b + "#" + d;
  1211. !k && e in this.curalts && (k = 0);
  1212. if ("" === l && "" === k) return b;
  1213. if ("" != l) k = f[l];
  1214. else {
  1215. k = parseFloat(k);
  1216. if (e in this.curalts) {
  1217. if (k == this.curalts[e]) return b;
  1218. } else if (k == (this.msralts[a] || 0)) return b;
  1219. if (
  1220. c
  1221. .find("tie")
  1222. .add(c.find("notations>tied"))
  1223. .get()
  1224. .some(function (a) {
  1225. return "stop" == $(a).attr("type");
  1226. })
  1227. )
  1228. return b;
  1229. p("accidental %d added in part %d, measure %d, voice %d note %s", [
  1230. k,
  1231. this.msr.ixp + 1,
  1232. this.msr.ixm + 1,
  1233. d + 1,
  1234. b,
  1235. ]);
  1236. }
  1237. this.curalts[e] = k;
  1238. return (b = ["__", "_", "=", "^", "^^"][k + 2] + b);
  1239. };
  1240. w.prototype.doNote = function (a) {
  1241. var b = new C(0, null),
  1242. c = parseInt(a.find("voice").text() || "1");
  1243. this.isSib && (c += 100 * (a.find("staff").text() || 1));
  1244. var d = 0 < a.find("chord").length,
  1245. e = a.find("pitch>step").text() || a.find("unpitched>display-step").text(),
  1246. g = a.find("pitch>octave").text() || a.find("unpitched>display-octave").text(),
  1247. f = 0 < a.find("rest").length,
  1248. l = a.find("time-modification>actual-notes").text();
  1249. if (l) {
  1250. var k = a.find("time-modification>normal-notes").text();
  1251. b.fact = [parseInt(l), parseInt(k)];
  1252. }
  1253. b.tup = a
  1254. .find("notations>tuplet")
  1255. .map(function () {
  1256. return $(this).attr("type");
  1257. })
  1258. .get();
  1259. k = a.find("duration").text();
  1260. l = a.find("grace");
  1261. b.grace = 0 < l.length;
  1262. b.before = [""];
  1263. b.after = "";
  1264. b.grace &&
  1265. !this.ingrace &&
  1266. ((this.ingrace = 1), (b.before = ["{"]), "yes" == l.attr("slash") && b.before.push("/"));
  1267. if ((l = !b.grace && this.ingrace)) (this.ingrace = 0), (this.msc.lastnote.after += "}");
  1268. if (!k || b.grace) k = 0;
  1269. if (!f && "no" == a.attr("print-object")) {
  1270. if (d) return;
  1271. f = 1;
  1272. }
  1273. b.dur = parseInt(k);
  1274. f || (e && g) || (this.msc.cnt.inc("nopt", c), (g = 5), (e = "E"));
  1275. k = 0 == ((this.curClef && this.curClef[this.curStf[c]]) || "").indexOf("tab");
  1276. var m = a.find("notations");
  1277. m.length && this.doNotations(b, m, k);
  1278. m = a.find("stem");
  1279. !f &&
  1280. m.length &&
  1281. "none" == m.text() &&
  1282. (!k || c in this.hasStems || this.tstep) &&
  1283. (b.before.push("s"), (v.stemless = 1));
  1284. m = a.find("accidental");
  1285. m.length && "yes" == m.attr("parentheses") && (b.ntdec += "!courtesy!");
  1286. f = f ? ("no" == a.attr("print-object") || k ? "x" : "z") : this.ntAbc(e, parseInt(g), a, c, b, k);
  1287. if (a.find("unpitched").length) {
  1288. k = this.curClef[this.curStf[c]];
  1289. e = X(e, parseInt(g), k, this.tstep);
  1290. g = a.find("instrument");
  1291. g = g.length ? g.attr("id") : "dummyId";
  1292. g = this.drumInst[g] || P(f);
  1293. k = a.find("notehead");
  1294. m = k.text().replace(" ", "-");
  1295. "x" == m && (f = "^" + f.replace(/\^/g, "").replace(/_/g, ""));
  1296. if ("circle-x" == m || "diamond" == m || "triangle" == m)
  1297. f = "_" + f.replace(/\^/g, "").replace(/_/g, "");
  1298. "yes" == k.attr("filled") && (m += "+");
  1299. "no" == k.attr("filled") && (m += "-");
  1300. this.drumNotes[c + ";" + f] = [e, g, m];
  1301. }
  1302. e = a.find("tie").add(a.find("notations>tied")).get();
  1303. e.some(function (a) {
  1304. return "start" == $(a).attr("type");
  1305. }) && (f += "-");
  1306. e = a
  1307. .find("beam")
  1308. .map(function () {
  1309. return $(this).text();
  1310. })
  1311. .get();
  1312. b.beam = -1 < e.indexOf("continue") || -1 < e.indexOf("end") || b.grace;
  1313. e = a.find("lyric");
  1314. for (g = k = 0; g < e.length; ++g) {
  1315. m = $(e[g]);
  1316. var h = parseInt((m.attr("number") || "1").replace(/^.*verse/, ""));
  1317. 0 == h ? (h = k + 1) : (k = h);
  1318. b.lyrs[h] = da(m);
  1319. }
  1320. e = a.find("stem").text();
  1321. !this.wstems ||
  1322. ("up" != e && "down" != e) ||
  1323. e == this.stemDir[c] ||
  1324. ((this.stemDir[c] = e), this.msc.appendElem(c, q("[I:stemdir %s]", [e])));
  1325. d
  1326. ? this.msc.addChord(b, f)
  1327. : ((d = parseInt(a.find("staff").text() || "1")),
  1328. this.curStf[c] != d &&
  1329. ((e = d - this.curStf[c]),
  1330. (this.curStf[c] = d),
  1331. this.msc.appendElem(c, "[I:staff " + (0 < e ? "+" : "") + e + "]")),
  1332. this.msc.appendNote(c, b, f));
  1333. e = a.find("notations>slur");
  1334. for (g = 0; g < e.length; ++g)
  1335. (a = $(e[g])), this.matchSlur(a.attr("type"), a.attr("number"), c, this.msc.lastnote, b.grace, l);
  1336. };
  1337. w.prototype.doAttr = function (a) {
  1338. var b, c;
  1339. var d = {
  1340. C1: "alto1",
  1341. C2: "alto2",
  1342. C3: "alto",
  1343. C4: "tenor",
  1344. F4: "bass",
  1345. F3: "bass3",
  1346. G2: "treble",
  1347. TAB: "tab",
  1348. percussion: "perc",
  1349. };
  1350. if ((b = a.find("divisions").text())) this.msr.divs = parseInt(b);
  1351. b = parseInt(a.find("transpose>chromatic").text() || "0");
  1352. var e = a.find("key>fifths").first().text();
  1353. var g = 0 == this.msc.tijd && 0 == this.msr.ixm;
  1354. if (e) {
  1355. var f = Y(parseInt(e), a.find("key>mode").first().text() || "major");
  1356. e = f[0];
  1357. this.msralts = f[1];
  1358. g && !b && "none" == v.key ? (v.key = e) : (e == v.key && g) || (this.msr.attr += "[K:" + e + "]");
  1359. }
  1360. if ((e = a.find("time>beats").text())) {
  1361. f = a.find("time>beat-type").text();
  1362. var l = e + "/" + f;
  1363. g ? (v.mtr = l) : (this.msr.attr += "[M:" + l + "]");
  1364. this.msr.mtr = [parseInt(e), parseInt(f)];
  1365. }
  1366. this.msr.mdur = (this.msr.divs * this.msr.mtr[0] * 4) / this.msr.mtr[1];
  1367. var k = this;
  1368. a.find("measure-style").each(function () {
  1369. var a, b, c, d, e;
  1370. var f = parseInt($(this).attr("number") || "1");
  1371. var g = k.stfMap[f];
  1372. $(this)
  1373. .find("measure-repeat")
  1374. .each(function () {
  1375. a = $(this).attr("type");
  1376. "start" == a
  1377. ? ((k.repeat_str[f] = [k.msr.ixm, $(this).text()]),
  1378. g.forEach(function (a) {
  1379. k.msc.insertElem(a, k.repeat_str[f]);
  1380. }))
  1381. : "stop" == a &&
  1382. ((b = k.repeat_str[f][0]),
  1383. (d = k.repeat_str[f][1]),
  1384. (c = k.msr.ixm - b),
  1385. d ? ((e = d + " "), (c /= parseInt(d))) : (e = ""),
  1386. (k.repeat_str[f][0] = q("[I:repeat %s%d]", [e, c])),
  1387. delete k.repeat_str[f]);
  1388. });
  1389. });
  1390. (e = a.find("transpose>octave-change").text() || "") && (b += 12 * parseInt(e));
  1391. l = a.find("clef");
  1392. for (f = 0; f < l.length; f++) {
  1393. var m = $(l[f]);
  1394. e = parseInt(m.attr("number") || "1");
  1395. var h = m.find("sign").text();
  1396. var x = "percussion" != h && "TAB" != h ? m.find("line").text() || "" : "";
  1397. x = d[h + x] || "";
  1398. m = m.find("clef-octave-change").text() || "0";
  1399. x += { "-2": "-15", "-1": "-8", 1: "+8", 2: "+15" }[m] || "";
  1400. this.clefOct[e] = -parseInt(m);
  1401. b && (x += " transpose=" + b);
  1402. var r = a.find("staff-details");
  1403. if (r.length && (r.attr("number") || 1) == e) {
  1404. if ((m = r.find("staff-lines").text()))
  1405. (h = "3" == m && "TAB" == h ? "|||" : m),
  1406. (x += " stafflines=" + h),
  1407. (this.stafflines = parseInt(m));
  1408. var t = [];
  1409. r.find("staff-tuning").each(function () {
  1410. t.push($(this).find("tuning-step").text() + $(this).find("tuning-octave").text());
  1411. });
  1412. t.length && (x += q(" strings=%s", [t.join(",")]));
  1413. (h = r.find("capo").text()) && (x += q(" capo=%s", [h]));
  1414. }
  1415. this.curClef[e] = x;
  1416. if (g) this.clefMap[e] = x;
  1417. else
  1418. for (m = this.stfMap[e], c = 0; c < m.length; ++c) {
  1419. r = m[c];
  1420. if (e != this.curStf[r]) {
  1421. var n = e - this.curStf[r];
  1422. this.curStf[r] = e;
  1423. h = 0 < n ? "+" : "";
  1424. this.msc.appendElem(r, "[I:staff " + h + n + "]");
  1425. }
  1426. this.msc.appendElem(r, "[K:" + x + "]");
  1427. }
  1428. }
  1429. };
  1430. w.prototype.findVoice = function (a, b) {
  1431. var c = b.eq(a);
  1432. var d = parseInt(c.find("staff").text() || "1");
  1433. var e = this.stfMap[d];
  1434. e = e.length ? e[0] : 1;
  1435. if (this.dirtov1) return { sn: d, v: e, v1: e };
  1436. for (a += 1; a < b.length; ++a) {
  1437. c = b.eq(a);
  1438. if ("note" == c[0].tagName)
  1439. return (
  1440. (b = parseInt(c.find("staff").text() || "1")),
  1441. (d = parseInt(c.find("voice").text() || "1")),
  1442. this.isSib && (d += 100 * b),
  1443. (b = this.vce2stf[d]),
  1444. { sn: b, v: d, v1: e }
  1445. );
  1446. if ("backup" == c[0].tagName) break;
  1447. }
  1448. return { sn: d, v: e, v1: e };
  1449. };
  1450. w.prototype.doDirection = function (a, b, c) {
  1451. function d(a, b, c, d, e) {
  1452. b &&
  1453. ((c = 0 <= b.indexOf("!8v") ? a.stfMap[e] : [c]),
  1454. c.forEach(function (c) {
  1455. null != d
  1456. ? a.msc.appendElemT(c, b.replace("(", ")").replace("ped", "ped-up"), d)
  1457. : a.msc.appendElem(c, b);
  1458. }));
  1459. }
  1460. function e(a, b, c, e) {
  1461. var f = { down: "!8va(!", up: "!8vb(!", crescendo: "!<(!", diminuendo: "!>(!", start: "!ped!" };
  1462. g = t.attr("type") || "";
  1463. var k = b + (t.attr("number") || "1");
  1464. if (g in f)
  1465. if (((f = f[g]), k in a.dirStk)) {
  1466. var l = a.dirStk[k];
  1467. delete a.dirStk[k];
  1468. "stop" == l.type
  1469. ? d(a, f, c, l.tijd, e)
  1470. : (p("%s direction %s has no stop in part %d, measure %d, voice %d", [
  1471. b,
  1472. l.type,
  1473. a.msr.ixp + 1,
  1474. a.msr.ixm + 1,
  1475. c + 1,
  1476. ]),
  1477. (a.dirStk[k] = { type: g, vs: c }));
  1478. } else a.dirStk[k] = { type: g, vs: c };
  1479. else if ("stop" == g)
  1480. k in a.dirStk
  1481. ? ((l = a.dirStk[k]),
  1482. delete a.dirStk[k],
  1483. (g = l.type),
  1484. (c = l.vs),
  1485. "stop" == g
  1486. ? (p("%s direction %s has double stop in part %d, measure %d, voice %d", [
  1487. b,
  1488. g,
  1489. a.msr.ixp + 1,
  1490. a.msr.ixm + 1,
  1491. c + 1,
  1492. ]),
  1493. (f = ""))
  1494. : (f = f[l.type].replace("(", ")").replace("ped", "ped-up")))
  1495. : ((a.dirStk[k] = { type: "stop", tijd: a.msc.tijd }), (f = ""));
  1496. else throw "wrong direction type";
  1497. d(a, f, c, null, e);
  1498. }
  1499. var g,
  1500. f,
  1501. l,
  1502. k = "";
  1503. var m = a.attr("placement");
  1504. var h = this.findVoice(b, c);
  1505. c = h.sn;
  1506. b = h.v;
  1507. h = h.v1;
  1508. var x = "",
  1509. r = { dacapo: "D.C.", dalsegno: "D.S.", tocoda: "dacoda", fine: "fine", coda: "O", segno: "S" };
  1510. var t = a.find("sound");
  1511. if (t.length) {
  1512. var n = t.find("midi-instrument");
  1513. if (n.length) {
  1514. var y = t.find("midi-instrument>midi-program").text();
  1515. var u = t.find("midi-instrument>midi-channel").text();
  1516. for (l in this.vceInst) this.vceInst[l] == n.attr("id") && (b = l);
  1517. (l = (y ? y - 1 : u) + "") &&
  1518. 0 < v.volpan &&
  1519. this.msc.appendElem(b, "[I:MIDI= " + (y ? "program" : "channel") + " " + l + "]");
  1520. }
  1521. if ((y = t.attr("tempo"))) {
  1522. y = parseFloat(y).toFixed(0);
  1523. var w = [1, 4];
  1524. }
  1525. for (A in r)
  1526. if (t.attr(A)) {
  1527. x = r[A];
  1528. break;
  1529. }
  1530. }
  1531. l = a.children("direction-type");
  1532. for (r = 0; r < l.length; ++r) {
  1533. a = $(l[r]);
  1534. var A = { whole: [1, 1], half: [1, 2], quarter: [1, 4], eighth: [1, 8] };
  1535. n = a.find("metronome");
  1536. n.length &&
  1537. ((t = n.find("beat-unit").text() || ""),
  1538. (w = t in A ? A[t] : A.quarter),
  1539. n.find("beat-unit-dot").length && (w = I(3 * w[0], 2 * w[1])),
  1540. (A = n
  1541. .find("per-minute")
  1542. .text()
  1543. .match(/[.\d]+/)) && (y = A[0]));
  1544. t = a.find("wedge");
  1545. t.length && e(this, "wedge", b);
  1546. A = a.find("words");
  1547. 0 == A.length && (A = a.find("rehearsal"));
  1548. for (n = 0; n < A.length; ++n) {
  1549. if (x) {
  1550. this.msc.appendElem(b, q("!%s!", [x]), 1);
  1551. break;
  1552. }
  1553. var z = "below" == m ? "_" : "^";
  1554. u = $(A[n]);
  1555. 0 > parseFloat(u.attr("default-y") || "0") && (z = "_");
  1556. k += u.text().replace(/"/g, '\\"').replace(/\n/g, "\\n");
  1557. }
  1558. k = k.trim();
  1559. for (f in U) (A = U[f]), a.find("dynamics>" + f).length && this.msc.appendElem(b, A, 1);
  1560. a.find("coda").length && this.msc.appendElem(b, "O", 1);
  1561. a.find("segno").length && this.msc.appendElem(b, "S", 1);
  1562. t = a.find("octave-shift");
  1563. t.length && e(this, "octave-shift", b, c);
  1564. t = a.find("pedal");
  1565. t.length && this.ped && (this.pedVce || (this.pedVce = b), e(this, "pedal", this.pedVce));
  1566. "diatonic fretting" == a.find("other-direction").text() && (this.diafret = 1);
  1567. }
  1568. y &&
  1569. ((y = parseFloat(y).toFixed(0)),
  1570. 0 == this.msc.tijd && 0 == this.msr.ixm
  1571. ? ((v.tempo = y), (v.tempo_units = w))
  1572. : this.msc.appendElem(h, q("[Q:%d/%d=%s]", [w[0], w[1], y])));
  1573. k && this.msc.appendElem(b, '"' + z + k + '"', 1);
  1574. };
  1575. w.prototype.doHarmony = function (a, b, c) {
  1576. c = this.findVoice(b, c).v;
  1577. var d = {
  1578. major: "",
  1579. minor: "m",
  1580. augmented: "+",
  1581. diminished: "dim",
  1582. dominant: "7",
  1583. "half-diminished": "m7b5",
  1584. };
  1585. b = { major: "maj", dominant: "", minor: "m", diminished: "dim", augmented: "+", suspended: "sus" };
  1586. var e = {
  1587. second: "2",
  1588. fourth: "4",
  1589. seventh: "7",
  1590. sixth: "6",
  1591. ninth: "9",
  1592. "11th": "11",
  1593. "13th": "13",
  1594. };
  1595. var g = { 1: "#", 0: "", "-1": "b" };
  1596. var f = a.find("root>root-step", "").text();
  1597. var l = g[a.find("root>root-alter").text()] || "";
  1598. var k = "";
  1599. var m = a.find("kind").text();
  1600. m in d
  1601. ? (m = d[m])
  1602. : -1 < m.indexOf("-")
  1603. ? ((d = m.split("-")),
  1604. (m = d[0]),
  1605. (d = d[1]),
  1606. (m = (b[m] || "") + (e[d] || "")),
  1607. 0 == m.indexOf("sus") && ((k = m), (m = "")))
  1608. : "none" == m && (m = a.find("kind").attr("text"));
  1609. e = a.find("degree");
  1610. for (b = 0; b < e.length; ++b)
  1611. (d = $(e[b])), (m += (g[d.find("degree-alter").text()] || "") + d.find("degree-value").text());
  1612. m = m.replace("79", "9").replace("713", "13").replace("maj6", "6");
  1613. a = a.find("bass>bass-step").text() + (g[a.find("bass>bass-alter").text()] || "");
  1614. this.msc.appendElem(c, '"' + f + l + m + k + (a && "/" + a) + '"', 1);
  1615. };
  1616. w.prototype.doBarline = function (a) {
  1617. var b = a.find("repeat"),
  1618. c = 0;
  1619. b.length && (c = b.attr("direction"));
  1620. if (this.unfold) return c ? ("forward" == c ? 1 : 2) : 0;
  1621. "right" == (a.attr("location") || "right") &&
  1622. ((b = a.find("bar-style").text()),
  1623. "light-light" == b ? (this.msr.rline = "||") : "light-heavy" == b && (this.msr.rline = "|]"));
  1624. c && ("forward" == c ? (this.msr.lline = ":") : (this.msr.rline = ":|"));
  1625. a = a.find("ending");
  1626. a.length &&
  1627. ("start" == a.attr("type")
  1628. ? ((a = (a.attr("number") || "1").replace(/\./g, "").replace(/ /g, "")),
  1629. /^[\d,]+$/.test(a) || (a = '"' + a.trim() + '"'),
  1630. (this.msr.lnum = a))
  1631. : "|" == this.msr.rline && (this.msr.rline = "||"));
  1632. return 0;
  1633. };
  1634. w.prototype.doPrint = function (a) {
  1635. if ("yes" == a.attr("new-system") || "yes" == a.attr("new-page")) return this.nolbrk ? "" : "$";
  1636. };
  1637. w.prototype.doPartList = function (a) {
  1638. var b, c;
  1639. var d = a.find("part-list>score-part");
  1640. for (b = 0; b < d.length; ++b) {
  1641. var e = d[b];
  1642. var g = {};
  1643. var f = $(e).find("midi-instrument");
  1644. for (e = 0; e < f.length; ++e) {
  1645. var l = $(f[e]);
  1646. var k = ["midi-channel", "midi-program", "volume", "pan"];
  1647. var m = [];
  1648. for (c = 0; c < k.length; ++c) {
  1649. var h = k[c];
  1650. m.push(l.find(h).text() || this.midDflt[c]);
  1651. }
  1652. c = 1 * m[3];
  1653. -90 <= c && 90 >= c && (c = ((c + 90) / 180) * 127);
  1654. g[l.attr("id")] = [parseInt(m[0]), parseInt(m[1]), 1.27 * parseFloat(m[2]), c];
  1655. (m = l.find("midi-unpitched").text()) && (this.drumInst[l.attr("id")] = m - 1);
  1656. }
  1657. this.instMid.push(g);
  1658. }
  1659. a = a.find("part-list");
  1660. m = ca(a);
  1661. return J(m, {}, [])[0];
  1662. };
  1663. w.prototype.mkTitle = function (a) {
  1664. var b = [],
  1665. c = [],
  1666. d = [],
  1667. e,
  1668. g;
  1669. var f = a.find("work>work-title").text().trim();
  1670. var l = a.find("movement-title").text().trim();
  1671. var k = a.find("identification>creator");
  1672. for (e = 0; e < k.length; ++e) {
  1673. var m = $(k[e]);
  1674. var h = m.text();
  1675. m = m.attr("type");
  1676. h &&
  1677. ((h = h.split("\n").map(function (a) {
  1678. return a.trim();
  1679. })),
  1680. "composer" == m
  1681. ? b.push.apply(b, h)
  1682. : ("lyricist" == m || "transcriber" == m) && c.push.apply(c, h));
  1683. }
  1684. k = a.find("identification>rights");
  1685. for (e = 0; e < k.length; ++e)
  1686. if ((h = $(k[e]).text()))
  1687. (h = h.split("\n").map(function (a) {
  1688. return a.trim();
  1689. })),
  1690. c.push.apply(c, h);
  1691. k = a.find("credit");
  1692. for (e = 0; e < k.length; ++e) {
  1693. h = "";
  1694. m = $(k[e]).find("credit-words");
  1695. for (g = 0; g < m.length; ++g) h += $(m[g]).text();
  1696. d.push(h.replace(/\s*[\r\n]\s*/g, " "));
  1697. }
  1698. d = (function (a) {
  1699. function e(a) {
  1700. return a && -1 < h.indexOf(a);
  1701. }
  1702. var g = [],
  1703. k;
  1704. for (k = 0; k < d.length; ++k) {
  1705. var h = d[k];
  1706. (6 > a && ((h && -1 < f.indexOf(h)) || (h && -1 < l.indexOf(h)))) ||
  1707. (5 > a && ((h && -1 < b.indexOf(h)) || (h && -1 < c.indexOf(h)))) ||
  1708. (4 > a && ((f && -1 < h.indexOf(f)) || (l && -1 < h.indexOf(l)))) ||
  1709. (3 > a && (b.some(e) || c.some(e))) ||
  1710. (2 > a && /^[\d\W]*$/.test(h)) ||
  1711. g.push(h);
  1712. }
  1713. 0 == a && f + l && (g = "");
  1714. return g;
  1715. })(this.ctf);
  1716. f && (f = "T:" + f.replace(/\n/g, "\nT:") + "\n");
  1717. l && (f += "T:" + l.replace(/\n/g, "\nT:") + "\n");
  1718. d.length &&
  1719. (f +=
  1720. d
  1721. .map(function (a) {
  1722. return "T:" + a;
  1723. })
  1724. .join("\n") + "\n");
  1725. b.length &&
  1726. (f +=
  1727. b
  1728. .map(function (a) {
  1729. return "C:" + a;
  1730. })
  1731. .join("\n") + "\n");
  1732. c.length &&
  1733. (f +=
  1734. c
  1735. .map(function (a) {
  1736. return "Z:" + a;
  1737. })
  1738. .join("\n") + "\n");
  1739. f && (v.title = f.substr(0, f.length - 1));
  1740. (this.isSib = 0 <= a.find("identification>encoding>software").text().indexOf("Sibelius")) &&
  1741. p("Sibelius MusicXMl is unreliable", []);
  1742. };
  1743. w.prototype.doDefaults = function (a) {
  1744. if (this.doPageFmt) {
  1745. var b = a.find("defaults");
  1746. if (b.length) {
  1747. a = b.find("scaling>millimeters").text();
  1748. var c = b.find("scaling>tenths").text();
  1749. c = a / c / 10;
  1750. a = b.find("page-layout>page-width").text() * c;
  1751. var d = b.find("page-layout>page-margins").first();
  1752. b = d.find("left-margin").text();
  1753. d = d.find("right-margin").text();
  1754. var e = (10 * c) / 0.2117;
  1755. !v.scale && e && (v.scale = e.toFixed(2));
  1756. !v.pagewidth && a && (v.pagewidth = a.toFixed(2));
  1757. v.leftmargin || "" == b || (v.leftmargin = (b * c).toFixed(2));
  1758. v.rightmargin || "" == d || (v.rightmargin = (d * c).toFixed(2));
  1759. }
  1760. }
  1761. };
  1762. w.prototype.locStaffMap = function (a) {
  1763. var b = {};
  1764. this.vceInst = {};
  1765. this.msc.vnums = {};
  1766. this.hasStems = {};
  1767. this.stfMap = {};
  1768. this.clefMap = {};
  1769. a = a.find("measure>note");
  1770. for (var c = 0; c < a.length; c++) {
  1771. var d = $(a[c]),
  1772. e = parseInt(d.find("voice").text() || "1");
  1773. this.isSib && (e += 100 * (d.find("staff").text() || 1));
  1774. this.msc.vnums[e] = 1;
  1775. var g = parseInt(d.find("staff").text() || "1");
  1776. this.stfMap[g] = [];
  1777. if (e in b) {
  1778. var f = b[e];
  1779. f[g] = (f[g] || 0) + 1;
  1780. } else (f = {}), (f[g] = 1), (b[e] = f);
  1781. f = d.find("instrument");
  1782. f.length && (this.vceInst[e] = $(f).attr("id"));
  1783. f = d.find("stem");
  1784. 0 != d.find("rest").length || (0 != f.length && "none" == f.text()) || (this.hasStems[e] = 1);
  1785. }
  1786. for (e in b) {
  1787. a = [];
  1788. c = b[e];
  1789. for (g in c) a.push([c[g], g]);
  1790. a.sort(function (a, b) {
  1791. return a[0] - b[0];
  1792. });
  1793. a = a[a.length - 1][1];
  1794. this.stfMap[a].push(e);
  1795. this.vce2stf[e] = a;
  1796. this.curStf[e] = a;
  1797. }
  1798. };
  1799. w.prototype.addStaffMap = function (a) {
  1800. var b,
  1801. c,
  1802. d = [],
  1803. e = Object.keys(this.stfMap).sort();
  1804. for (c = 0; c < e.length; ++c) {
  1805. var g = e[c];
  1806. var f = this.stfMap[g];
  1807. var l = [];
  1808. var k = [];
  1809. for (b = 0; b < f.length; ++b) {
  1810. var h = f[b];
  1811. h in a && (l.push(a[h]), k.push(void 0 == this.hasStems[h]));
  1812. }
  1813. if (l.length)
  1814. for (d.push(l), f = (g in this.clefMap) ? this.clefMap[g] : "treble", b = 0; b < l.length; ++b)
  1815. (h = l[b]),
  1816. (g = ""),
  1817. 0 == f.indexOf("tab") &&
  1818. (k[b] && 0 > f.indexOf("nostems") && (g = " nostems"),
  1819. this.diafret && 0 > f.indexOf("diafret") && (g += " diafret")),
  1820. (v.clefs[h] = f + g);
  1821. }
  1822. this.gStfMap.push(d);
  1823. };
  1824. w.prototype.addMidiMap = function (a, b) {
  1825. var c = this.instMid[a],
  1826. d = Object.keys(c);
  1827. var e = d.length ? c[d[0]] : this.midDflt;
  1828. a = [];
  1829. var g = this;
  1830. for (m in b) {
  1831. d = Object.keys(this.drumNotes)
  1832. .sort()
  1833. .filter(function (a) {
  1834. return a.split(";")[0] == m;
  1835. });
  1836. var f = d.map(function (a) {
  1837. return {
  1838. nt: a.split(";")[1],
  1839. step: g.drumNotes[a][0],
  1840. midi: g.drumNotes[a][1],
  1841. nhd: g.drumNotes[a][2],
  1842. };
  1843. });
  1844. var h = b[m];
  1845. d = this.vceInst[m] || "";
  1846. d in c ? a.push([h, c[d].concat(f)]) : a.push([h, e.concat(f)]);
  1847. }
  1848. a.sort(function (a, b) {
  1849. return a[0] - b[0];
  1850. });
  1851. a.forEach(function (a) {
  1852. g.midiMap.push(a[1]);
  1853. });
  1854. e = "E G B d f a c' e'".split(" ");
  1855. var k = "0 1- 1 1+ 2 3 3 4 4 5 6 6+ 7 8- 8 8+ 9 10 10 11 11 12 13 13+ 14".split(" ");
  1856. d = Object.keys(this.tabmap).sort();
  1857. for (c = 0; c < d.length; ++c) {
  1858. h = d[c];
  1859. a = h.match(/(\d+),(.*)/);
  1860. var m = a[1];
  1861. var n = a[2];
  1862. f = this.tabmap[h][0];
  1863. var p = this.tabmap[h][1];
  1864. this.diafret && (p = k[parseInt(p)]);
  1865. h = b[m];
  1866. f = this.stafflines - parseInt(f);
  1867. a = this.tabVceMap[h] || [];
  1868. a.push(q("%%map tab%d %s print=%s heads=kop%s\n", [h, n, e[f], p]));
  1869. this.tabVceMap[h] = a;
  1870. this.koppen[p] = 1;
  1871. }
  1872. };
  1873. w.prototype.parse = function (a) {
  1874. var b = {},
  1875. c = $(a);
  1876. this.mkTitle(c);
  1877. this.doDefaults(c);
  1878. a = this.doPartList(c);
  1879. for (var d = c.find("part"), e = 0; e < d.length; ++e) {
  1880. var g = d.eq(e),
  1881. f = g.find("measure");
  1882. this.locStaffMap(g);
  1883. this.drumNotes = {};
  1884. this.clefOct = {};
  1885. this.curClef = {};
  1886. this.stemDir = {};
  1887. this.tabmap = {};
  1888. this.diafret = 0;
  1889. this.stafflines = 5;
  1890. this.msc.initVoices(1);
  1891. var h = 0,
  1892. k = 0;
  1893. g = [];
  1894. for (this.msr = new N(e); this.msr.ixm < f.length;) {
  1895. var m = f.eq(this.msr.ixm),
  1896. n = 0,
  1897. u = "";
  1898. this.msr.reset();
  1899. this.curalts = {};
  1900. for (var r = m.children(), t = 0; t < r.length; t++)
  1901. switch (((c = r.eq(t)), c[0].tagName)) {
  1902. case "note":
  1903. this.doNote(c);
  1904. break;
  1905. case "attributes":
  1906. this.doAttr(c);
  1907. break;
  1908. case "direction":
  1909. this.doDirection(c, t, r);
  1910. break;
  1911. case "sound":
  1912. this.doDirection(m, t, r);
  1913. break;
  1914. case "harmony":
  1915. this.doHarmony(c, t, r);
  1916. break;
  1917. case "barline":
  1918. n = this.doBarline(c);
  1919. break;
  1920. case "backup":
  1921. c = parseInt(c.find("duration").text());
  1922. K(c, this.msr) && this.msc.incTime(-c);
  1923. break;
  1924. case "forward":
  1925. c = parseInt(c.find("duration").text());
  1926. K(c, this.msr) && this.msc.incTime(c);
  1927. break;
  1928. case "print":
  1929. u = this.doPrint(c);
  1930. }
  1931. this.msc.addBar(u, this.msr);
  1932. g.push(this.msr.divs);
  1933. 1 == n
  1934. ? ((k = this.msr.ixm), (this.msr.ixm += 1))
  1935. : 2 == n
  1936. ? 1 > h
  1937. ? ((this.msr.ixm = k), (h += 1))
  1938. : ((h = 0), (this.msr.ixm += 1))
  1939. : (this.msr.ixm += 1);
  1940. }
  1941. for (var w in this.repeat_str) (f = this.repeat_str[w]), (f[0] = q("[I:repeat %s %d]", [f[1], 1]));
  1942. f = this.msc.outVoices(g, e);
  1943. this.addStaffMap(f);
  1944. this.addMidiMap(e, f);
  1945. for (w in f) b[w] = f[w];
  1946. }
  1947. Object.keys(b).length
  1948. ? v.mkHeader(this.gStfMap, a, this.midiMap, this.tabVceMap, this.koppen)
  1949. : p("nothing written, %s has no notes ...", [v.fnmext]);
  1950. };
  1951. vertaal = function (a, b) {
  1952. var c = {
  1953. u: 0,
  1954. b: 0,
  1955. n: 0,
  1956. c: 0,
  1957. v: 0,
  1958. d: 0,
  1959. m: 0,
  1960. x: 0,
  1961. t: 0,
  1962. v1: 0,
  1963. noped: 0,
  1964. stm: 0,
  1965. mnum: -1,
  1966. p: "f",
  1967. s: 0,
  1968. },
  1969. d;
  1970. for (d in b) c[d] = b[d];
  1971. c.p = c.p ? c.p.split(",") : [];
  1972. v = new G(".abc", "", 0, c);
  1973. b = new w(c);
  1974. try {
  1975. b.parse(a);
  1976. } catch (e) {
  1977. p("** exception occurred: %s", [e]);
  1978. }
  1979. return v.writeall();
  1980. };
  1981. })();
  1982. "undefined" != typeof exports &&
  1983. ((exports.vertaal = vertaal), (exports.xml2abc_VERSION = xml2abc_VERSION));