UNPKG

vexmxl

Version:

MusicXML binding for VexFlow

1,317 lines (1,315 loc) 881 kB
/******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // identity function for calling harmony imports with the correct context /******/ __webpack_require__.i = function(value) { return value; }; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { /******/ configurable: false, /******/ enumerable: true, /******/ get: getter /******/ }); /******/ } /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 1); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /* WEBPACK VAR INJECTION */(function(__dirname) {/** * (C) Josh Netterfield <joshua@nettek.ca> 2015. * Part of the musicxml-interfaces <https://github.com/ripieno/musicxml-interfaces>. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * ***************************************************************** * * MusicXML™ Version 3.0 * * Copyright © 2004-2011 MakeMusic, Inc. * http://www.makemusic.com/ * * This MusicXML™ work is being provided by the copyright * holder under the MusicXML Public License Version 3.0, * available from: * * http://www.musicxml.org/dtds/license.html * This file contains multiple DTDs. */ /*---- Parsing API ------------------------------------------------------------------------------*/ /** * Converts a MusicXML document into a MusicXML parttime-inspired JSON object. * See ScoreTimewise for full return type specification. * * This function will accept timepart MusicXML files, but will still return a * structure similar to parttime. */ function parseScore(score) { var dom = xmlToParttimeDoc(score); return xmlToScoreTimewise(dom.documentElement); } exports.parseScore = parseScore; /** * Reads a document, and returns header information. * * ScoreHeader is a subset of ScoreTimewise, so you can always just call MusicXML.parse.score. * This function is a bit faster though, if you only care about metadata. */ function paseScoreHeader(score) { return xmlToScoreHeader(xmlToDoc(score).documentElement); } exports.paseScoreHeader = paseScoreHeader; /** * Converts a MusicXML <measure /> from a **parttime** document into JSON. */ function parseMeasure(str) { return xmlToMeasure(xmlToDoc(str).documentElement); } exports.parseMeasure = parseMeasure; /** * Converts a MusicXML <note /> into JSON. */ function parseNote(str) { return xmlToNote(xmlToDoc(str).documentElement); } exports.parseNote = parseNote; /** * Converts a MusicXML <clef /> into JSON. */ function parseClef(str) { return xmlToClef(xmlToDoc(str).documentElement); } exports.parseClef = parseClef; /** * Converts a MusicXML <time /> into JSON. */ function parseTime(str) { return xmlToTime(xmlToDoc(str).documentElement); } exports.parseTime = parseTime; /** * Converts a MusicXML <key /> into JSON. */ function parseKey(str) { return xmlToKey(xmlToDoc(str).documentElement); } exports.parseKey = parseKey; /** * Converts a MusicXML <part-symbol /> into JSON. */ function parsePartSymbol(str) { return xmlToPartSymbol(xmlToDoc(str).documentElement); } exports.parsePartSymbol = parsePartSymbol; /** * Converts a MusicXML <backup /> into JSON. */ function parseBackup(str) { return xmlToBackup(xmlToDoc(str).documentElement); } exports.parseBackup = parseBackup; /** * Converts a MusicXML <harmony /> into JSON. */ function parseHarmony(str) { return xmlToHarmony(xmlToDoc(str).documentElement); } exports.parseHarmony = parseHarmony; /** * Converts a MusicXML <forward /> into JSON. */ function parseForward(str) { return xmlToForward(xmlToDoc(str).documentElement); } exports.parseForward = parseForward; /** * Converts a MusicXML <print /> into JSON. */ function parsePrint(str) { return xmlToPrint(xmlToDoc(str).documentElement); } exports.parsePrint = parsePrint; /** * Converts a MusicXML <figured-bass /> into JSON. */ function parseFiguredBass(str) { return xmlToFiguredBass(xmlToDoc(str).documentElement); } exports.parseFiguredBass = parseFiguredBass; /** * Converts a MusicXML <direction /> into JSON. */ function parseDirection(str) { return xmlToDirection(xmlToDoc(str).documentElement); } exports.parseDirection = parseDirection; /** * Converts a MusicXML <attributes /> object into JSON. */ function parseAttributes(str) { return xmlToAttributes(xmlToDoc(str).documentElement); } exports.parseAttributes = parseAttributes; /** * Converts a MusicXML <sound /> into JSON. */ function parseSound(str) { return xmlToSound(xmlToDoc(str).documentElement); } exports.parseSound = parseSound; /** * Converts a MusicXML <barline /> into JSON. */ function parseBarline(str) { return xmlToBarline(xmlToDoc(str).documentElement); } exports.parseBarline = parseBarline; /** * Converts a MusicXML <grouping /> into JSON. */ function parseGrouping(str) { return xmlToGrouping(xmlToDoc(str).documentElement); } exports.parseGrouping = parseGrouping; /*---- Serialization API ------------------------------------------------------------------------*/ function serializeScore(score, parttime) { if (parttime === void 0) { parttime = false; } var timewise = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE score-timewise\n PUBLIC \"-//Recordare//DTD MusicXML 3.0 Timewise//EN\" \"http://www.musicxml.org/dtds/timewise.dtd\">\n<score-timewise version=\"3.0\">\n" + scoreHeaderToXML(score).join("\n").split("\n").map(function (line) { return " " + line; }).join("\n") + "\n" + score.measures.map(function (measure) { return measureToXML(measure); }).join("\n") .split("\n").map(function (line) { return " " + line; }).join("\n") + "\n</score-timewise>"; if (!parttime) { return timewise; } return timewiseToPartwise(timewise); } exports.serializeScore = serializeScore; function serializeScoreHeader(scoreHeader) { return scoreHeaderToXML(scoreHeader).join("\n"); } exports.serializeScoreHeader = serializeScoreHeader; exports.serializeMeasure = measureToXML; exports.serializeNote = noteToXML; exports.serializeClef = clefToXML; exports.serializeTime = timeToXML; exports.serializeKey = keyToXML; exports.serializePartSymbol = partSymbolToXML; exports.serializeBackup = backupToXML; exports.serializeHarmony = harmonyToXML; exports.serializeForward = forwardToXML; exports.serializePrint = printToXML; exports.serializeFiguredBass = figuredBassToXML; exports.serializeDirection = directionToXML; exports.serializeAttributes = attributesToXML; exports.serializeSound = soundToXML; exports.serializeBarline = barlineToXML; exports.serializeGrouping = groupingToXML; var process; var isIE = typeof window !== "undefined" && "ActiveXObject" in window; var isNode = typeof window === "undefined" || typeof process !== "undefined" && !process.browser; var xmlToParttimeDoc; var timewiseToPartwise; var xmlToDoc; (function init() { var parttimeXSLBuffer = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"> <xsl:output method=\"xml\" indent=\"yes\" encoding=\"UTF-8\" omit-xml-declaration=\"no\" standalone=\"no\" doctype-system=\"http://www.musicxml.org/dtds/timewise.dtd\" doctype-public=\"-//Recordare//DTD MusicXML 3.0 Timewise//EN\" /> <xsl:template match=\"/\"> <xsl:apply-templates select=\"./score-partwise\"/> <xsl:apply-templates select=\"./score-timewise\"/> </xsl:template> <xsl:template match=\"score-timewise\"> <xsl:copy-of select=\".\" /> </xsl:template> <xsl:template match=\"text()\"> <xsl:value-of select=\".\" /> </xsl:template> <xsl:template match=\"*|@*|comment()|processing-instruction()\"> <xsl:copy><xsl:apply-templates select=\"*|@*|comment()|processing-instruction()|text()\" /></xsl:copy> </xsl:template> <xsl:template match=\"score-partwise\"> <xsl:element name=\"score-timewise\"> <xsl:apply-templates select=\"@version[.!='1.0']\"/> <xsl:apply-templates select=\"work\"/> <xsl:apply-templates select=\"movement-number\"/> <xsl:apply-templates select=\"movement-title\"/> <xsl:apply-templates select=\"identification\"/> <xsl:apply-templates select=\"defaults\"/> <xsl:apply-templates select=\"credit\"/> <xsl:apply-templates select=\"part-list\"/> <xsl:for-each select=\"part[1]/measure\"> <xsl:variable name=\"measure-number\"> <xsl:value-of select=\"@number\"/> </xsl:variable> <xsl:element name=\"measure\"> <xsl:attribute name=\"number\"> <xsl:value-of select=\"$measure-number\"/> </xsl:attribute> <xsl:if test=\"@implicit[. = 'yes']\"> <xsl:attribute name=\"implicit\"> <xsl:value-of select=\"@implicit\"/> </xsl:attribute> </xsl:if> <xsl:if test=\"@non-controlling[. = 'yes']\"> <xsl:attribute name=\"non-controlling\"> <xsl:value-of select=\"@non-controlling\"/> </xsl:attribute> </xsl:if> <xsl:if test=\"@width\"> <xsl:attribute name=\"width\"> <xsl:value-of select=\"@width\"/> </xsl:attribute> </xsl:if> <xsl:for-each select=\"../../part/measure\"> <xsl:if test=\"@number=$measure-number\"> <xsl:element name=\"part\"> <xsl:attribute name=\"id\"> <xsl:value-of select=\"parent::part/@id\"/> </xsl:attribute> <xsl:apply-templates /> </xsl:element> </xsl:if> </xsl:for-each> </xsl:element> </xsl:for-each> </xsl:element> </xsl:template> </xsl:stylesheet>"; var timepartXSLBuffer = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"> <xsl:output method=\"xml\" indent=\"yes\" encoding=\"UTF-8\" omit-xml-declaration=\"no\" standalone=\"no\" doctype-system=\"http://www.musicxml.org/dtds/partwise.dtd\" doctype-public=\"-//Recordare//DTD MusicXML 3.0 Partwise//EN\" /> <xsl:template match=\"/\"> <xsl:apply-templates select=\"./score-partwise\"/> <xsl:apply-templates select=\"./score-timewise\"/> </xsl:template> <xsl:template match=\"score-partwise\"> <xsl:copy-of select=\".\" /> </xsl:template> <xsl:template match=\"text()\"> <xsl:value-of select=\".\" /> </xsl:template> <xsl:template match=\"*|@*|comment()|processing-instruction()\"> <xsl:copy><xsl:apply-templates select=\"*|@*|comment()|processing-instruction()|text()\" /></xsl:copy> </xsl:template> <xsl:template match=\"score-timewise\"> <xsl:element name=\"score-partwise\"> <xsl:apply-templates select=\"@version[.!='1.0']\"/> <xsl:apply-templates select=\"work\"/> <xsl:apply-templates select=\"movement-number\"/> <xsl:apply-templates select=\"movement-title\"/> <xsl:apply-templates select=\"identification\"/> <xsl:apply-templates select=\"defaults\"/> <xsl:apply-templates select=\"credit\"/> <xsl:apply-templates select=\"part-list\"/> <xsl:for-each select=\"measure[1]/part\"> <xsl:variable name=\"part-id\"> <xsl:value-of select=\"@id\"/> </xsl:variable> <xsl:element name=\"part\"> <xsl:copy-of select=\"@id\" /> <xsl:for-each select=\"../../measure/part\"> <xsl:if test=\"@id=$part-id\"> <xsl:element name=\"measure\"> <xsl:attribute name=\"number\"> <xsl:value-of select=\"parent::measure/@number\"/> </xsl:attribute> <xsl:if test=\"parent::measure/@implicit[. = 'yes']\"> <xsl:attribute name=\"implicit\"> <xsl:value-of select=\"parent::measure/@implicit\"/> </xsl:attribute> </xsl:if> <xsl:if test=\"parent::measure/@non-controlling[. = 'yes']\"> <xsl:attribute name=\"non-controlling\"> <xsl:value-of select=\"parent::measure/@non-controlling\"/> </xsl:attribute> </xsl:if> <xsl:if test=\"parent::measure/@width\"> <xsl:attribute name=\"width\"> <xsl:value-of select=\"parent::measure/@width\"/> </xsl:attribute> </xsl:if> <xsl:apply-templates /> </xsl:element> </xsl:if> </xsl:for-each> </xsl:element> </xsl:for-each> </xsl:element> </xsl:template> </xsl:stylesheet>"; if (isIE) { var DOMParser = window.DOMParser; xmlToDoc = function (str) { return (new DOMParser).parseFromString(str, "text/xml"); }; xmlToParttimeDoc = function (str) { var xslt = new ActiveXObject("Msxml2.XSLTemplate"); var xmlDoc = new ActiveXObject("Msxml2.DOMDocument"); var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument"); // Why these aren't set by default completely flabbergasts me. xmlDoc.validateOnParse = false; xslDoc.validateOnParse = false; xmlDoc.resolveExternals = false; xslDoc.resolveExternals = false; xmlDoc.loadXML(str); xslDoc.loadXML(parttimeXSLBuffer); xslt.stylesheet = xslDoc; var xslProc = xslt.createProcessor(); xslProc.input = xmlDoc; xslProc.transform(); return xmlToDoc(xslProc.output); }; timewiseToPartwise = function (str) { var xslt = new ActiveXObject("Msxml2.XSLTemplate"); var xmlDoc = new ActiveXObject("Msxml2.DOMDocument"); var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument"); // Why these aren't set by default completely flabbergasts me. xmlDoc.validateOnParse = false; xslDoc.validateOnParse = false; xmlDoc.resolveExternals = false; xslDoc.resolveExternals = false; xmlDoc.loadXML(str); xslDoc.loadXML(timepartXSLBuffer); xslt.stylesheet = xslDoc; var xslProc = xslt.createProcessor(); xslProc.input = xmlDoc; xslProc.transform(); return xslProc.output; }; } else if (isNode) { var DOMParser = __webpack_require__(5).DOMParser; var spawnSync_1 = __webpack_require__(4).spawnSync; var path_1 = __webpack_require__(2); xmlToDoc = function (str) { return (new DOMParser).parseFromString(str, "text/xml"); }; xmlToParttimeDoc = function (str) { var res = spawnSync_1("xsltproc", ["--nonet", path_1.join(__dirname, "..", "vendor", "musicxml-dtd", "parttime.xsl"), "-"], { input: str, env: { "XML_CATALOG_FILES": path_1.join(__dirname, "..", "vendor", "musicxml-dtd", "catalog.xml"), } }); if (res.error) { throw res.error; } return xmlToDoc(res.stdout.toString()); }; timewiseToPartwise = function (str) { var res = spawnSync_1("xsltproc", ["--nonet", path_1.join(__dirname, "..", "vendor", "musicxml-dtd", "parttime.xsl"), "-"], { input: str, env: { "XML_CATALOG_FILES": path_1.join(__dirname, "..", "vendor", "musicxml-dtd", "catalog.xml"), } }); if (res.error) { throw res.error; } return res.stdout.toString(); }; } else { var DOMParser = window.DOMParser; var parttimeXSLDoc = (new DOMParser).parseFromString(parttimeXSLBuffer, "text/xml"); var timepartXSLDoc = (new DOMParser).parseFromString(timepartXSLBuffer, "text/xml"); var parttimeXSLProcessor_1 = new XSLTProcessor; parttimeXSLProcessor_1.importStylesheet(parttimeXSLDoc); var timepartXSLProcessor_1 = new XSLTProcessor; timepartXSLProcessor_1.importStylesheet(timepartXSLDoc); xmlToDoc = function (str) { return (new DOMParser).parseFromString(str, "text/xml"); }; xmlToParttimeDoc = function (str) { var dom = (new DOMParser).parseFromString(str, "text/xml"); return parttimeXSLProcessor_1.transformToDocument(dom); }; timewiseToPartwise = function (str) { var dom = (new DOMParser).parseFromString(str, "text/xml"); return new XMLSerializer().serializeToString(timepartXSLProcessor_1.transformToDocument(dom).documentElement); }; } }()); function popFront(t) { return t.slice(1); } function getString(ch, required) { return (ch.nodeType === ch.ATTRIBUTE_NODE ? ch.value : ch.textContent).trim(); } function getNumber(ch, required) { var s = getString(ch, required); if (s.toLowerCase().indexOf("0x") === 0) { return parseInt(s, 16); } else { return parseFloat(s); } } function toCamelCase(input) { return input.toLowerCase().replace(/-(.)/g, function (match, group1) { return group1.toUpperCase(); }); } /** * The start-stop entity is used for musical elements that * can either start or stop, such as slurs, tuplets, and * wedges. * * See also start-stop-continue and start-stop-single. * * The values of start and stop refer to how an * element appears in musical score order, not in MusicXML * document order. An element with a stop attribute may * precede the corresponding element with a start attribute * within a MusicXML document. This is particularly common * in multi-staff music. For example, the stopping point for * a slur may appear in staff 1 before the starting point for * the slur appears in staff 2 later in the document. */ (function (StartStop) { StartStop[StartStop["Start"] = 0] = "Start"; StartStop[StartStop["Stop"] = 1] = "Stop"; })(exports.StartStop || (exports.StartStop = {})); var StartStop = exports.StartStop; /** * The start-stop-continue (as opposed to the start-stop entity) * entity is used when there is a need to refer to an * intermediate point in the symbol, as for complex slurs * or for specifying formatting of symbols across system * breaks. * * The values of start, stop, and continue refer to how an * element appears in musical score order, not in MusicXML * document order. An element with a stop attribute may * precede the corresponding element with a start attribute * within a MusicXML document. This is particularly common * in multi-staff music. For example, the stopping point for * a slur may appear in staff 1 before the starting point for * the slur appears in staff 2 later in the document. */ (function (StartStopContinue) { StartStopContinue[StartStopContinue["Start"] = 0] = "Start"; StartStopContinue[StartStopContinue["Stop"] = 1] = "Stop"; StartStopContinue[StartStopContinue["Continue"] = 2] = "Continue"; })(exports.StartStopContinue || (exports.StartStopContinue = {})); var StartStopContinue = exports.StartStopContinue; /** * The start-stop-single entity (as opposed to start-stop * and start-stop-continue) is used when the same * element is used for multi-note and single-note notations, * as for tremolos. * * The values of start and stop refer to how an * element appears in musical score order, not in MusicXML * document order. An element with a stop attribute may * precede the corresponding element with a start attribute * within a MusicXML document. This is particularly common * in multi-staff music. For example, the stopping point for * a slur may appear in staff 1 before the starting point for * the slur appears in staff 2 later in the document. */ (function (StartStopSingle) { StartStopSingle[StartStopSingle["Single"] = 3] = "Single"; StartStopSingle[StartStopSingle["Start"] = 0] = "Start"; StartStopSingle[StartStopSingle["Stop"] = 1] = "Stop"; })(exports.StartStopSingle || (exports.StartStopSingle = {})); var StartStopSingle = exports.StartStopSingle; /** * The symbol-size entity is used to indicate full vs. * cue-sized vs. oversized symbols. The large value * for oversized symbols was added in version 1.1. */ (function (SymbolSize) { /** * Context-dependant. */ SymbolSize[SymbolSize["Unspecified"] = 0] = "Unspecified"; SymbolSize[SymbolSize["Full"] = 1] = "Full"; SymbolSize[SymbolSize["Cue"] = 2] = "Cue"; /** * Oversized. */ SymbolSize[SymbolSize["Large"] = 3] = "Large"; })(exports.SymbolSize || (exports.SymbolSize = {})); var SymbolSize = exports.SymbolSize; /** * The above-below type is used to indicate whether one * element appears above or below another element. */ (function (AboveBelow) { AboveBelow[AboveBelow["Above"] = 1] = "Above"; AboveBelow[AboveBelow["Below"] = 2] = "Below"; AboveBelow[AboveBelow["Unspecified"] = 0] = "Unspecified"; })(exports.AboveBelow || (exports.AboveBelow = {})); var AboveBelow = exports.AboveBelow; /** * Specifies orientation. */ (function (OverUnder) { OverUnder[OverUnder["Over"] = 1] = "Over"; OverUnder[OverUnder["Under"] = 2] = "Under"; OverUnder[OverUnder["Unspecified"] = 0] = "Unspecified"; })(exports.OverUnder || (exports.OverUnder = {})); var OverUnder = exports.OverUnder; /** * The up-down entity is used for arrow direction, * indicating which way the tip is pointing. */ (function (UpDown) { UpDown[UpDown["Down"] = 1] = "Down"; UpDown[UpDown["Up"] = 0] = "Up"; })(exports.UpDown || (exports.UpDown = {})); var UpDown = exports.UpDown; /** * The top-bottom entity is used to indicate the top or * bottom part of a vertical shape like non-arpeggiate. */ (function (TopBottom) { TopBottom[TopBottom["Top"] = 0] = "Top"; TopBottom[TopBottom["Bottom"] = 1] = "Bottom"; })(exports.TopBottom || (exports.TopBottom = {})); var TopBottom = exports.TopBottom; /** * The left-right entity is used to indicate whether one * element appears to the left or the right of another * element. */ (function (LeftRight) { LeftRight[LeftRight["Right"] = 1] = "Right"; LeftRight[LeftRight["Left"] = 0] = "Left"; })(exports.LeftRight || (exports.LeftRight = {})); var LeftRight = exports.LeftRight; /** * The enclosure-shape entity describes the shape and * presence / absence of an enclosure around text. A bracket * enclosure is similar to a rectangle with the bottom line * missing, as is common in jazz notation. */ (function (EnclosureShape) { EnclosureShape[EnclosureShape["Circle"] = 3] = "Circle"; EnclosureShape[EnclosureShape["Bracket"] = 4] = "Bracket"; EnclosureShape[EnclosureShape["Triangle"] = 5] = "Triangle"; EnclosureShape[EnclosureShape["Diamond"] = 6] = "Diamond"; EnclosureShape[EnclosureShape["None"] = 7] = "None"; EnclosureShape[EnclosureShape["Square"] = 1] = "Square"; EnclosureShape[EnclosureShape["Oval"] = 2] = "Oval"; EnclosureShape[EnclosureShape["Rectangle"] = 0] = "Rectangle"; })(exports.EnclosureShape || (exports.EnclosureShape = {})); var EnclosureShape = exports.EnclosureShape; (function (NormalItalic) { NormalItalic[NormalItalic["Italic"] = 1] = "Italic"; NormalItalic[NormalItalic["Normal"] = 0] = "Normal"; })(exports.NormalItalic || (exports.NormalItalic = {})); var NormalItalic = exports.NormalItalic; (function (NormalBold) { NormalBold[NormalBold["Bold"] = 2] = "Bold"; NormalBold[NormalBold["Normal"] = 0] = "Normal"; })(exports.NormalBold || (exports.NormalBold = {})); var NormalBold = exports.NormalBold; (function (LeftCenterRight) { LeftCenterRight[LeftCenterRight["Right"] = 1] = "Right"; LeftCenterRight[LeftCenterRight["Center"] = 2] = "Center"; LeftCenterRight[LeftCenterRight["Left"] = 0] = "Left"; })(exports.LeftCenterRight || (exports.LeftCenterRight = {})); var LeftCenterRight = exports.LeftCenterRight; (function (TopMiddleBottomBaseline) { TopMiddleBottomBaseline[TopMiddleBottomBaseline["Top"] = 0] = "Top"; TopMiddleBottomBaseline[TopMiddleBottomBaseline["Middle"] = 1] = "Middle"; TopMiddleBottomBaseline[TopMiddleBottomBaseline["Baseline"] = 3] = "Baseline"; TopMiddleBottomBaseline[TopMiddleBottomBaseline["Bottom"] = 2] = "Bottom"; })(exports.TopMiddleBottomBaseline || (exports.TopMiddleBottomBaseline = {})); var TopMiddleBottomBaseline = exports.TopMiddleBottomBaseline; (function (DirectionMode) { DirectionMode[DirectionMode["Lro"] = 2] = "Lro"; DirectionMode[DirectionMode["Rlo"] = 3] = "Rlo"; DirectionMode[DirectionMode["Ltr"] = 0] = "Ltr"; DirectionMode[DirectionMode["Rtl"] = 1] = "Rtl"; })(exports.DirectionMode || (exports.DirectionMode = {})); var DirectionMode = exports.DirectionMode; (function (StraightCurved) { StraightCurved[StraightCurved["Curved"] = 1] = "Curved"; StraightCurved[StraightCurved["Straight"] = 0] = "Straight"; })(exports.StraightCurved || (exports.StraightCurved = {})); var StraightCurved = exports.StraightCurved; (function (SolidDashedDottedWavy) { SolidDashedDottedWavy[SolidDashedDottedWavy["Dashed"] = 1] = "Dashed"; SolidDashedDottedWavy[SolidDashedDottedWavy["Wavy"] = 3] = "Wavy"; SolidDashedDottedWavy[SolidDashedDottedWavy["Dotted"] = 2] = "Dotted"; SolidDashedDottedWavy[SolidDashedDottedWavy["Solid"] = 0] = "Solid"; })(exports.SolidDashedDottedWavy || (exports.SolidDashedDottedWavy = {})); var SolidDashedDottedWavy = exports.SolidDashedDottedWavy; (function (NormalAngledSquare) { NormalAngledSquare[NormalAngledSquare["Angled"] = 1] = "Angled"; NormalAngledSquare[NormalAngledSquare["Square"] = 2] = "Square"; NormalAngledSquare[NormalAngledSquare["Normal"] = 0] = "Normal"; })(exports.NormalAngledSquare || (exports.NormalAngledSquare = {})); var NormalAngledSquare = exports.NormalAngledSquare; (function (UprightInverted) { UprightInverted[UprightInverted["Upright"] = 0] = "Upright"; UprightInverted[UprightInverted["Inverted"] = 1] = "Inverted"; })(exports.UprightInverted || (exports.UprightInverted = {})); var UprightInverted = exports.UprightInverted; (function (UpperMainBelow) { UpperMainBelow[UpperMainBelow["Main"] = 1] = "Main"; UpperMainBelow[UpperMainBelow["Below"] = 2] = "Below"; UpperMainBelow[UpperMainBelow["Upper"] = 0] = "Upper"; })(exports.UpperMainBelow || (exports.UpperMainBelow = {})); var UpperMainBelow = exports.UpperMainBelow; (function (WholeHalfUnison) { WholeHalfUnison[WholeHalfUnison["Unison"] = 2] = "Unison"; WholeHalfUnison[WholeHalfUnison["Whole"] = 0] = "Whole"; WholeHalfUnison[WholeHalfUnison["Half"] = 1] = "Half"; })(exports.WholeHalfUnison || (exports.WholeHalfUnison = {})); var WholeHalfUnison = exports.WholeHalfUnison; (function (WholeHalfNone) { WholeHalfNone[WholeHalfNone["None"] = 3] = "None"; WholeHalfNone[WholeHalfNone["Whole"] = 0] = "Whole"; WholeHalfNone[WholeHalfNone["Half"] = 1] = "Half"; })(exports.WholeHalfNone || (exports.WholeHalfNone = {})); var WholeHalfNone = exports.WholeHalfNone; function xmlToEncodingDate(node) { var text = getString(node, true); if (text.length < 10) { return null; } return { year: parseFloat(text.slice(0, 4)), month: parseFloat(text.slice(5, 7)), day: parseFloat(text.slice(8, 10)) }; } function xmlToMeasure(node) { var ret = {}; var foundImplicit = false; var foundNonControlling = false; var foundNumber = false; var foundWidth = false; for (var i = 0; i < node.childNodes.length; ++i) { var ch = node.childNodes[i]; if (ch.nodeName === "part") { var dataPart = xmlToPart(ch); ret.parts = ret.parts || {}; ret.parts[ch.getAttribute("id")] = dataPart; } } for (var i = 0; i < node.attributes.length; ++i) { var ch2 = node.attributes[i]; if (ch2.name === "number") { var dataNumber = getString(ch2, true); ret.number = dataNumber; foundNumber = true; } if (ch2.name === "implicit") { var dataImplicit = xmlToYesNo(ch2, true); ret.implicit = dataImplicit; foundImplicit = true; } if (ch2.name === "width") { var dataWidth = getNumber(ch2, true); ret.width = dataWidth; foundWidth = true; } if (ch2.name === "non-controlling") { var dataNonControlling = xmlToYesNo(ch2, true); ret.nonControlling = dataNonControlling; foundNonControlling = true; } } if (!foundNumber) { ret.number = ""; } if (!foundImplicit) { ret.implicit = false; } if (!foundNonControlling) { ret.nonControlling = false; } if (!foundWidth) { ret.width = null; } return ret; } function xmlToYesNo(p, required) { var s = getString(p, true); if (s == "no") { return false; } if (s == "yes") { return true; } return false; } function xmlToNoteheadText(p) { // TODO return null; } function xmlToPartNameDisplay(p) { // TODO return null; } function xmlToPartAbbreviationDisplay(p) { // TODO return null; } function xmlToGroupNameDisplay(p) { // TODO return null; } function xmlToGroupAbbreviationDisplay(p) { // TODO return null; } function xmlToLyric(node) { var ret = {}; var foundNumber_ = false; var foundJustify = false; var foundDefaultX = false; var foundRelativeY = false; var foundDefaultY = false; var foundRelativeX = false; var foundPlacement = false; var foundColor = false; var foundPrintObject = false; var foundName = false; for (var i = 0; i < node.childNodes.length; ++i) { var ch = node.childNodes[i]; if (ch.nodeName === "footnote") { var dataFootnote = xmlToFootnote(ch); ret.footnote = dataFootnote; } if (ch.nodeName === "level") { var dataLevel = xmlToLevel(ch); ret.level = dataLevel; } } for (var i = 0; i < node.attributes.length; ++i) { var ch2 = node.attributes[i]; if (ch2.name === "number") { var dataNumber_ = getNumber(ch2, true); ret.number = dataNumber_; foundNumber_ = true; } if (ch2.name === "justify") { var dataJustify = getLeftCenterRight(ch2, LeftCenterRight.Left); ret.justify = dataJustify; foundJustify = true; } if (ch2.name === "default-x") { var dataDefaultX = getNumber(ch2, true); ret.defaultX = dataDefaultX; foundDefaultX = true; } if (ch2.name === "relative-y") { var dataRelativeY = getNumber(ch2, true); ret.relativeY = dataRelativeY; foundRelativeY = true; } if (ch2.name === "default-y") { var dataDefaultY = getNumber(ch2, true); ret.defaultY = dataDefaultY; foundDefaultY = true; } if (ch2.name === "relative-x") { var dataRelativeX = getNumber(ch2, true); ret.relativeX = dataRelativeX; foundRelativeX = true; } if (ch2.name === "placement") { var dataPlacement = getAboveBelow(ch2, AboveBelow.Unspecified); ret.placement = dataPlacement; foundPlacement = true; } if (ch2.name === "color") { var dataColor = getString(ch2, true); ret.color = dataColor; foundColor = true; } if (ch2.name === "print-object") { var dataPrintObject = xmlToYesNo(ch2); ret.printObject = dataPrintObject; foundPrintObject = true; } if (ch2.name === "name") { var dataName = getString(ch2, true); ret.name = dataName; foundName = true; } } ret.lyricParts = xmlToLyricParts(node); if (!foundNumber_) { ret.number = 1; } if (!foundJustify) { ret.justify = LeftCenterRight.Left; } if (!foundDefaultX) { ret.defaultX = NaN; } if (!foundRelativeY) { ret.relativeY = 0; } if (!foundDefaultY) { ret.defaultY = NaN; } if (!foundRelativeX) { ret.relativeX = 0; } if (!foundPlacement) { ret.placement = AboveBelow.Unspecified; } if (!foundColor) { ret.color = "#000000"; } if (!foundPrintObject) { ret.printObject = true; } if (!foundName) { ret.name = ""; } return ret; } function getStartStop(node, fallbackVal) { "use strict"; var s = (node.nodeType === node.ATTRIBUTE_NODE ? node.value : node.textContent).trim(); if (s === "" && fallbackVal !== null && fallbackVal !== undefined) { return fallbackVal; } if (s == "start") { return StartStop.Start; } if (s == "stop") { return StartStop.Stop; } return fallbackVal; } function getStartStopContinue(node, fallbackVal) { "use strict"; var s = (node.nodeType === node.ATTRIBUTE_NODE ? node.value : node.textContent).trim(); if (s === "" && fallbackVal !== null && fallbackVal !== undefined) { return fallbackVal; } if (s == "start") { return StartStopContinue.Start; } if (s == "stop") { return StartStopContinue.Stop; } if (s == "continue") { return StartStopContinue.Continue; } return fallbackVal; } function getStartStopSingle(node, fallbackVal) { "use strict"; var s = (node.nodeType === node.ATTRIBUTE_NODE ? node.value : node.textContent).trim(); if (s === "" && fallbackVal !== null && fallbackVal !== undefined) { return fallbackVal; } if (s == "single") { return StartStopSingle.Single; } if (s == "start") { return StartStopSingle.Start; } if (s == "stop") { return StartStopSingle.Stop; } return fallbackVal; } function getSymbolSize(node, fallbackVal) { "use strict"; var s = (node.nodeType === node.ATTRIBUTE_NODE ? node.value : node.textContent).trim(); if (s === "" && fallbackVal !== null && fallbackVal !== undefined) { return fallbackVal; } if (s == "unspecified") { return SymbolSize.Unspecified; } if (s == "full") { return SymbolSize.Full; } if (s == "cue") { return SymbolSize.Cue; } if (s == "large") { return SymbolSize.Large; } return fallbackVal; } function getAboveBelow(node, fallbackVal) { "use strict"; var s = (node.nodeType === node.ATTRIBUTE_NODE ? node.value : node.textContent).trim(); if (s === "" && fallbackVal !== null && fallbackVal !== undefined) { return fallbackVal; } if (s == "above") { return AboveBelow.Above; } if (s == "below") { return AboveBelow.Below; } if (s == "unspecified") { return AboveBelow.Unspecified; } return fallbackVal; } function getUpDown(node, fallbackVal) { "use strict"; var s = (node.nodeType === node.ATTRIBUTE_NODE ? node.value : node.textContent).trim(); if (s === "" && fallbackVal !== null && fallbackVal !== undefined) { return fallbackVal; } if (s == "down") { return UpDown.Down; } if (s == "up") { return UpDown.Up; } return fallbackVal; } function getOverUnder(node, fallbackVal) { "use strict"; var s = (node.nodeType === node.ATTRIBUTE_NODE ? node.value : node.textContent).trim(); if (s === "" && fallbackVal !== null && fallbackVal !== undefined) { return fallbackVal; } if (s == "over") { return OverUnder.Over; } if (s == "under") { return OverUnder.Under; } if (s == "unspecified") { return OverUnder.Unspecified; } return fallbackVal; } function getTopBottom(node, fallbackVal) { "use strict"; var s = (node.nodeType === node.ATTRIBUTE_NODE ? node.value : node.textContent).trim(); if (s === "" && fallbackVal !== null && fallbackVal !== undefined) { return fallbackVal; } if (s == "top") { return TopBottom.Top; } if (s == "bottom") { return TopBottom.Bottom; } return fallbackVal; } function getLeftRight(node, fallbackVal) { "use strict"; var s = (node.nodeType === node.ATTRIBUTE_NODE ? node.value : node.textContent).trim(); if (s === "" && fallbackVal !== null && fallbackVal !== undefined) { return fallbackVal; } if (s == "right") { return LeftRight.Right; } if (s == "left") { return LeftRight.Left; } return fallbackVal; } /** * The number-of-lines entity is used to specify the * number of lines in text decoration attributes. */ function verifyNumberOfLines(m) { // assert(m >= 0 && m <= 3); } function xmlToNumberOfLines(node) { var str = node.textContent; var num = str.toLowerCase().indexOf("0x") === 0 ? parseInt(str, 16) : parseFloat(str); return num; } function verifyRotation(m) { // assert(m >= -180 && m <= 180); } function xmlToRotation(node) { var str = node.textContent; var num = str.toLowerCase().indexOf("0x") === 0 ? parseInt(str, 16) : parseFloat(str); return num; } function getEnclosureShape(node, fallbackVal) { "use strict"; var s = (node.nodeType === node.ATTRIBUTE_NODE ? node.value : node.textContent).trim(); if (s === "" && fallbackVal !== null && fallbackVal !== undefined) { return fallbackVal; } if (s == "circle") { return EnclosureShape.Circle; } if (s == "bracket") { return EnclosureShape.Bracket; } if (s == "triangle") { return EnclosureShape.Triangle; } if (s == "diamond") { return EnclosureShape.Diamond; } if (s == "none") { return EnclosureShape.None; } if (s == "square") { return EnclosureShape.Square; } if (s == "oval") { return EnclosureShape.Oval; } if (s == "rectangle") { return EnclosureShape.Rectangle; } return fallbackVal; } function getNormalItalic(node, fallbackVal) { "use strict"; var s = (node.nodeType === node.ATTRIBUTE_NODE ? node.value : node.textContent).trim(); if (s === "" && fallbackVal !== null && fallbackVal !== undefined) { return fallbackVal; } if (s == "italic") { return NormalItalic.Italic; } if (s == "normal") { return NormalItalic.Normal; } return fallbackVal; } function getNormalBold(node, fallbackVal) { "use strict"; var s = (node.nodeType === node.ATTRIBUTE_NODE ? node.value : node.textContent).trim(); if (s === "" && fallbackVal !== null && fallbackVal !== undefined) { return fallbackVal; } if (s == "bold") { return NormalBold.Bold; } if (s == "normal") { return NormalBold.Normal; } return fallbackVal; } /** * Slurs, tuplets, and many other features can be * concurrent and overlapping within a single musical * part. The number-level attribute distinguishes up to * six concurrent objects of the same type. A reading * program should be prepared to handle cases where * the number-levels stop in an arbitrary order. * Different numbers are needed when the features * overlap in MusicXML document order. When a number-level * value is implied, the value is 1 by default. */ function verifyNumberLevel(m) { // assert(m >= 1 && m <= 6); } function xmlToNumberLevel(node) { var str = node.textContent; var num = str.toLowerCase().indexOf("0x") === 0 ? parseInt(str, 16) : parseFloat(str); return num; } /** * The MusicXML format supports eight levels of beaming, up * to 1024th notes. Unlike the number-level attribute, the * beam-level attribute identifies concurrent beams in a beam * group. It does not distinguish overlapping beams such as * grace notes within regular notes, or beams used in different * voices. */ function verifyBeamLevel(m) { // assert(m >= 1 && m <= 8); } function xmlToBeamLevel(node) { var str = node.textContent; var num = str.toLowerCase().indexOf("0x") === 0 ? parseInt(str, 16) : parseFloat(str); return num; } function xmlToPosition(node) { var ret = {}; for (var i = 0; i < node.childNodes.length; ++i) { var ch = node.childNodes[i]; } for (var i = 0; i < node.attributes.length; ++i) { var ch2 = node.attributes[i]; if (ch2.name === "default-x") { var dataDefaultX = getNumber(ch2, true); ret.defaultX = dataDefaultX; } if (ch2.name === "relative-y") { var dataRelativeY = getNumber(ch2, true); ret.relativeY = dataRelativeY; } if (ch2.name === "default-y") { var dataDefaultY = getNumber(ch2, true); ret.defaultY = dataDefaultY; } if (ch2.name === "relative-x") { var dataRelativeX = getNumber(ch2, true); ret.relativeX = dataRelativeX; } } return ret; } function xmlToPlacement(node) { var ret = {}; var foundPlacement = false; for (var i = 0; i < node.childNodes.length; ++i) { var ch = node.childNodes[i]; } for (var i = 0; i < node.attributes.length; ++i) { var ch2 = node.attributes[i]; if (ch2.name === "placement") { var dataPlacement = getAboveBelow(ch2, AboveBelow.Unspecified); ret.placement = dataPlacement; foundPlacement = true; } } if (!foundPlacement) { ret.placement = AboveBelow.Unspecified; } return ret; } function xmlToDirectiveEntity(node) { var ret = {}; for (var i = 0; i < node.childNodes.length; ++i) { var ch = node.childNodes[i]; } for (var i = 0; i < node.attributes.length; ++i) { var ch2 = node.attributes[i]; if (ch2.name === "directive") { var dataDirective = xmlToYesNo(ch2); ret.directive = dataDirective; } } return ret; } function xmlToBezier(node) { var ret = {}; for (var i = 0; i < node.childNodes.length; ++i) { var ch = node.childNodes[i]; } for (var i = 0; i < node.attributes.length; ++i) { var ch2 = node.attributes[i]; if (ch2.name === "bezier-x2") { var dataBezierX2 = getNumber(ch2, true); ret.bezierX2 = dataBezierX2; } if (ch2.name === "bezier-offset") { var dataBezierOffset = getNumber(ch2, true); ret.bezierOffset = dataBezierOffset; } if (ch2.name === "bezier-offset2") { var dataBezierOffset2 = getNumber(ch2, true); ret.bezierOffset2 = dataBezierOffset2; } if (ch2.name === "bezier-x") { var dataBezierX = getNumber(ch2, true); ret.bezierX = dataBezierX; } if (ch2.name === "bezier-y") { var dataBezierY = getNumber(ch2, true); ret.bezierY = dataBezierY; } if (ch2.name === "bezier-y2") { var dataBezierY2 = getNumber(ch2, true); ret.bezierY2 = dataBezierY2; } } return ret; } function xmlToOrientation(node) { var ret = {}; var foundOrientation = false; for (var i = 0; i < node.childNodes.length; ++i) { var ch = node.childNodes[i]; } for (var i = 0; i < node.attributes.length; ++i) { var ch2 = node.attributes[i]; if (ch2.name === "orientation") { var dataOrientation = getOverUnder(ch2, OverUnder.Unspecified); ret.orientation = dataOrientation; foundOrientation = true; } } if (!foundOrientation) { ret.orientation = OverUnder.Unspecified; } return ret; } function xmlToFont(node) { var ret = {}; var foundFontWeight = false; var foundFontStyle = false; for (var i = 0; i < node.childNodes.length; ++i) { var ch = node.childNodes[i]; } for (var i = 0; i < node.attributes.length; ++i) { var ch2 = node.attributes[i]; if (ch2.name === "font-family") { var dataFontFamily = getString(ch2, true); ret.fontFamily = dataFontFamily; } if (ch2.name === "font-weight") { var dataFontWeight = getNormalBold(ch2, NormalBold.Normal); ret.fontWeight = dataFontWeight; foundFontWeight = true; } if (ch2.name === "font-style") { var dataFontStyle = getNormalItalic(ch2, NormalItalic.Normal); ret.fontStyle = dataFontStyle; foundFontStyle = true; } if (ch2.name === "font-size") { var dataFontSize = getString(ch2, true); ret.fontSize = dataFontSize; } } if (!foundFontWeight) { ret.fontWeight = NormalBold.Normal; } if (!foundFontStyle) { ret.fontStyle = NormalItalic.Normal; } return ret; } function getLeftCenterRight(node, fallbackVal) { "use strict"; var s = (node.nodeType === node.ATTRIBUTE_NODE ? node.value : node.textContent).trim(); if (s === "" && fallbackVal !== null && fallbackVal !== undefined) { return fallbackVal; } if (s == "right") { return LeftCenterRight.Right; } if (s == "center") { return LeftCenterRight.Center; } if (s == "left") { return LeftCenterRight.Left; } return fallbackVal; } function getTopMiddleBottomBaseline(node, fallbackVal) { "use strict"; var s = (node.nodeType === node.ATTRIBUTE_NODE ? node.value : node.textContent).trim(); if (s === "" && fallbackVal !== null && fallbackVal !== undefined) { return fallbackVal; } if (s == "top") { return TopMiddleBottomBaseline.Top; } if (s == "middle") { return TopMiddleBottomBaseline.Middle; } if (s == "baseline") { return TopMiddleBottomBaseline.Baseline; } if (s == "bottom") { return TopMiddleBottomBaseline.Bottom; } return fallbackVal; } function getDirectionMode(node, fallbackVal) { "use strict"; var s = (node.nodeType === node.ATTRIBUTE_NODE ? node.value : node.textContent).trim(); if (s === "" && fallbackVal !== null && fallbackVal !== undefined) { return fallbackVal; } if (s == "lro") { return DirectionMode.Lro; } if (s == "rlo") { return DirectionMode.Rlo; } if (s == "ltr") { return DirectionMode.Ltr; } if (s == "rtl") { return DirectionMode.Rtl; } return fallbackVal; } function getStraightCurved(node, fallbackVal) { "use strict"; var s = (node.nodeType === node.ATTRIBUTE_NODE ? node.value : node.textContent).trim(); if (s === "" && fallbackVal !== null && fallbackVal !== undefined) { return fallbackVal; } if (s == "curved") { return StraightCurved.Curved; } if (s == "straight") { return StraightCurved.Straight; } return fallbackVal; } function getSolidDashedDottedWavy(node, fallbackVal) { "use strict"; var s = (node.nodeType === node.ATTRIBUTE_NODE ? node.value : node.textContent).trim(); if (s === "" && fallbackVal !== null && fallbackVal !== undefined) { return fallbackVal; } if (s == "dashed") { return SolidDashedDottedWavy.Dashed; } if (s == "wavy") { return SolidDashedDottedWavy.Wavy; } if (s == "dotted") { return SolidDashedDottedWavy.Dotted; } if (s == "solid") { return SolidDashedDottedWavy.Solid; } return fallbackVal; } function getNormalAngledSquare(node, fallbackVal) { "use strict"; var s = (node.nodeType === node.ATTRIBUTE_NODE ? node.value : node.textContent).trim(); if (s === "" && fallbackVal !== null && fallbackVal !== undefined) { return fallbackVal; } if (s == "angled") { return