musicxml-io 0.7.5 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +17 -17
- package/dist/index.mjs +17 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -617,7 +617,7 @@ function parseSystemLayout(elements) {
|
|
|
617
617
|
}
|
|
618
618
|
function parseCredits(elements) {
|
|
619
619
|
const credits = collectElements(elements, "credit", (content, attrs) => {
|
|
620
|
-
const credit = { _id: _chunkKJXV3TD4js.generateId.call(void 0, ) };
|
|
620
|
+
const credit = { _id: attrs["id"] || _chunkKJXV3TD4js.generateId.call(void 0, ) };
|
|
621
621
|
if (attrs["page"]) credit.page = parseInt(attrs["page"], 10);
|
|
622
622
|
const types = collectElements(content, "credit-type", (c) => extractText(c));
|
|
623
623
|
const words = collectElements(content, "credit-words", (c, a) => {
|
|
@@ -760,7 +760,7 @@ function parsePartList(elements) {
|
|
|
760
760
|
const attrs = el.attributes;
|
|
761
761
|
const content = el.children;
|
|
762
762
|
const group = {
|
|
763
|
-
_id: _chunkKJXV3TD4js.generateId.call(void 0, ),
|
|
763
|
+
_id: attrs["id"] || _chunkKJXV3TD4js.generateId.call(void 0, ),
|
|
764
764
|
type: "part-group",
|
|
765
765
|
groupType: attrs["type"] === "stop" ? "stop" : "start"
|
|
766
766
|
};
|
|
@@ -816,7 +816,7 @@ function parseParts(elements) {
|
|
|
816
816
|
}
|
|
817
817
|
function parseMeasure(elements, attrs) {
|
|
818
818
|
const measure = {
|
|
819
|
-
_id: _chunkKJXV3TD4js.generateId.call(void 0, ),
|
|
819
|
+
_id: attrs["id"] || _chunkKJXV3TD4js.generateId.call(void 0, ),
|
|
820
820
|
number: attrs["number"] || "0",
|
|
821
821
|
// Keep as string per MusicXML spec (token type)
|
|
822
822
|
entries: []
|
|
@@ -828,12 +828,12 @@ function parseMeasure(elements, attrs) {
|
|
|
828
828
|
for (const el of elements) {
|
|
829
829
|
if (typeof el === "string") continue;
|
|
830
830
|
if (el.tagName === "attributes") {
|
|
831
|
-
const parsedAttrs = parseAttributes(el.children);
|
|
831
|
+
const parsedAttrs = parseAttributes(el.children, el.attributes);
|
|
832
832
|
if (!hasSeenNote && !measure.attributes) {
|
|
833
833
|
measure.attributes = parsedAttrs;
|
|
834
834
|
} else {
|
|
835
835
|
const attrEntry = {
|
|
836
|
-
_id: _chunkKJXV3TD4js.generateId.call(void 0, ),
|
|
836
|
+
_id: el.attributes["id"] || _chunkKJXV3TD4js.generateId.call(void 0, ),
|
|
837
837
|
type: "attributes",
|
|
838
838
|
attributes: parsedAttrs
|
|
839
839
|
};
|
|
@@ -845,7 +845,7 @@ function parseMeasure(elements, attrs) {
|
|
|
845
845
|
} else if (el.tagName === "backup") {
|
|
846
846
|
measure.entries.push(parseBackup(el.children));
|
|
847
847
|
} else if (el.tagName === "forward") {
|
|
848
|
-
measure.entries.push(parseForward(el.children));
|
|
848
|
+
measure.entries.push(parseForward(el.children, el.attributes));
|
|
849
849
|
} else if (el.tagName === "direction") {
|
|
850
850
|
measure.entries.push(parseDirection(el.children, el.attributes));
|
|
851
851
|
} else if (el.tagName === "barline") {
|
|
@@ -914,8 +914,8 @@ function parsePrint(elements, attrs) {
|
|
|
914
914
|
if (pad) print.partAbbreviationDisplay = pad;
|
|
915
915
|
return print;
|
|
916
916
|
}
|
|
917
|
-
function parseAttributes(elements) {
|
|
918
|
-
const attrs = { _id: _chunkKJXV3TD4js.generateId.call(void 0, ) };
|
|
917
|
+
function parseAttributes(elements, xmlAttrs = {}) {
|
|
918
|
+
const attrs = { _id: xmlAttrs["id"] || _chunkKJXV3TD4js.generateId.call(void 0, ) };
|
|
919
919
|
const divisions = getElementTextAsInt(elements, "divisions");
|
|
920
920
|
if (divisions !== void 0) attrs.divisions = divisions;
|
|
921
921
|
const staves = getElementTextAsInt(elements, "staves");
|
|
@@ -1081,7 +1081,7 @@ function parseTranspose(elements) {
|
|
|
1081
1081
|
}
|
|
1082
1082
|
function parseNote(elements, attrs) {
|
|
1083
1083
|
const note = {
|
|
1084
|
-
_id: _chunkKJXV3TD4js.generateId.call(void 0, ),
|
|
1084
|
+
_id: attrs["id"] || _chunkKJXV3TD4js.generateId.call(void 0, ),
|
|
1085
1085
|
type: "note",
|
|
1086
1086
|
duration: 0
|
|
1087
1087
|
};
|
|
@@ -1837,9 +1837,9 @@ function parseBackup(elements) {
|
|
|
1837
1837
|
duration: parseInt(getElementText(elements, "duration") || "0", 10)
|
|
1838
1838
|
};
|
|
1839
1839
|
}
|
|
1840
|
-
function parseForward(elements) {
|
|
1840
|
+
function parseForward(elements, attrs = {}) {
|
|
1841
1841
|
const forward = {
|
|
1842
|
-
_id: _chunkKJXV3TD4js.generateId.call(void 0, ),
|
|
1842
|
+
_id: attrs["id"] || _chunkKJXV3TD4js.generateId.call(void 0, ),
|
|
1843
1843
|
type: "forward",
|
|
1844
1844
|
duration: parseInt(getElementText(elements, "duration") || "0", 10)
|
|
1845
1845
|
};
|
|
@@ -1851,7 +1851,7 @@ function parseForward(elements) {
|
|
|
1851
1851
|
}
|
|
1852
1852
|
function parseDirection(elements, attrs) {
|
|
1853
1853
|
const direction = {
|
|
1854
|
-
_id: _chunkKJXV3TD4js.generateId.call(void 0, ),
|
|
1854
|
+
_id: attrs["id"] || _chunkKJXV3TD4js.generateId.call(void 0, ),
|
|
1855
1855
|
type: "direction",
|
|
1856
1856
|
directionTypes: []
|
|
1857
1857
|
};
|
|
@@ -2276,7 +2276,7 @@ function parseDirectionTypes(elements) {
|
|
|
2276
2276
|
}
|
|
2277
2277
|
function parseBarline(elements, attrs) {
|
|
2278
2278
|
const location = attrs["location"] || "right";
|
|
2279
|
-
const barline = { _id: _chunkKJXV3TD4js.generateId.call(void 0, ), location };
|
|
2279
|
+
const barline = { _id: attrs["id"] || _chunkKJXV3TD4js.generateId.call(void 0, ), location };
|
|
2280
2280
|
const barStyle = getElementText(elements, "bar-style");
|
|
2281
2281
|
if (barStyle && isValidBarStyle(barStyle)) {
|
|
2282
2282
|
barline.barStyle = barStyle;
|
|
@@ -2508,7 +2508,7 @@ function parseMeasureStyle(elements, attrs) {
|
|
|
2508
2508
|
}
|
|
2509
2509
|
function parseHarmony(elements, attrs) {
|
|
2510
2510
|
const harmony = {
|
|
2511
|
-
_id: _chunkKJXV3TD4js.generateId.call(void 0, ),
|
|
2511
|
+
_id: attrs["id"] || _chunkKJXV3TD4js.generateId.call(void 0, ),
|
|
2512
2512
|
type: "harmony",
|
|
2513
2513
|
root: { rootStep: "C" },
|
|
2514
2514
|
kind: "major"
|
|
@@ -2648,7 +2648,7 @@ function parseHarmony(elements, attrs) {
|
|
|
2648
2648
|
}
|
|
2649
2649
|
function parseFiguredBass(elements, attrs) {
|
|
2650
2650
|
const fb = {
|
|
2651
|
-
_id: _chunkKJXV3TD4js.generateId.call(void 0, ),
|
|
2651
|
+
_id: attrs["id"] || _chunkKJXV3TD4js.generateId.call(void 0, ),
|
|
2652
2652
|
type: "figured-bass",
|
|
2653
2653
|
figures: []
|
|
2654
2654
|
};
|
|
@@ -2697,7 +2697,7 @@ function parseFiguredBass(elements, attrs) {
|
|
|
2697
2697
|
}
|
|
2698
2698
|
function parseSound(elements, attrs) {
|
|
2699
2699
|
const sound = {
|
|
2700
|
-
_id: _chunkKJXV3TD4js.generateId.call(void 0, ),
|
|
2700
|
+
_id: attrs["id"] || _chunkKJXV3TD4js.generateId.call(void 0, ),
|
|
2701
2701
|
type: "sound"
|
|
2702
2702
|
};
|
|
2703
2703
|
if (attrs["tempo"]) sound.tempo = parseFloat(attrs["tempo"]);
|
|
@@ -5021,7 +5021,7 @@ function serializeMeasure(measure, indent, out) {
|
|
|
5021
5021
|
serializePrint(measure.print, indent + " ", out);
|
|
5022
5022
|
}
|
|
5023
5023
|
if (measure.attributes) {
|
|
5024
|
-
serializeAttributes(measure.attributes, indent + " ", out);
|
|
5024
|
+
serializeAttributes(measure.attributes, indent + " ", out, measure.attributes._id);
|
|
5025
5025
|
}
|
|
5026
5026
|
for (const entry of measure.entries) {
|
|
5027
5027
|
serializeEntry(entry, indent + " ", out);
|
package/dist/index.mjs
CHANGED
|
@@ -617,7 +617,7 @@ function parseSystemLayout(elements) {
|
|
|
617
617
|
}
|
|
618
618
|
function parseCredits(elements) {
|
|
619
619
|
const credits = collectElements(elements, "credit", (content, attrs) => {
|
|
620
|
-
const credit = { _id: generateId() };
|
|
620
|
+
const credit = { _id: attrs["id"] || generateId() };
|
|
621
621
|
if (attrs["page"]) credit.page = parseInt(attrs["page"], 10);
|
|
622
622
|
const types = collectElements(content, "credit-type", (c) => extractText(c));
|
|
623
623
|
const words = collectElements(content, "credit-words", (c, a) => {
|
|
@@ -760,7 +760,7 @@ function parsePartList(elements) {
|
|
|
760
760
|
const attrs = el.attributes;
|
|
761
761
|
const content = el.children;
|
|
762
762
|
const group = {
|
|
763
|
-
_id: generateId(),
|
|
763
|
+
_id: attrs["id"] || generateId(),
|
|
764
764
|
type: "part-group",
|
|
765
765
|
groupType: attrs["type"] === "stop" ? "stop" : "start"
|
|
766
766
|
};
|
|
@@ -816,7 +816,7 @@ function parseParts(elements) {
|
|
|
816
816
|
}
|
|
817
817
|
function parseMeasure(elements, attrs) {
|
|
818
818
|
const measure = {
|
|
819
|
-
_id: generateId(),
|
|
819
|
+
_id: attrs["id"] || generateId(),
|
|
820
820
|
number: attrs["number"] || "0",
|
|
821
821
|
// Keep as string per MusicXML spec (token type)
|
|
822
822
|
entries: []
|
|
@@ -828,12 +828,12 @@ function parseMeasure(elements, attrs) {
|
|
|
828
828
|
for (const el of elements) {
|
|
829
829
|
if (typeof el === "string") continue;
|
|
830
830
|
if (el.tagName === "attributes") {
|
|
831
|
-
const parsedAttrs = parseAttributes(el.children);
|
|
831
|
+
const parsedAttrs = parseAttributes(el.children, el.attributes);
|
|
832
832
|
if (!hasSeenNote && !measure.attributes) {
|
|
833
833
|
measure.attributes = parsedAttrs;
|
|
834
834
|
} else {
|
|
835
835
|
const attrEntry = {
|
|
836
|
-
_id: generateId(),
|
|
836
|
+
_id: el.attributes["id"] || generateId(),
|
|
837
837
|
type: "attributes",
|
|
838
838
|
attributes: parsedAttrs
|
|
839
839
|
};
|
|
@@ -845,7 +845,7 @@ function parseMeasure(elements, attrs) {
|
|
|
845
845
|
} else if (el.tagName === "backup") {
|
|
846
846
|
measure.entries.push(parseBackup(el.children));
|
|
847
847
|
} else if (el.tagName === "forward") {
|
|
848
|
-
measure.entries.push(parseForward(el.children));
|
|
848
|
+
measure.entries.push(parseForward(el.children, el.attributes));
|
|
849
849
|
} else if (el.tagName === "direction") {
|
|
850
850
|
measure.entries.push(parseDirection(el.children, el.attributes));
|
|
851
851
|
} else if (el.tagName === "barline") {
|
|
@@ -914,8 +914,8 @@ function parsePrint(elements, attrs) {
|
|
|
914
914
|
if (pad) print.partAbbreviationDisplay = pad;
|
|
915
915
|
return print;
|
|
916
916
|
}
|
|
917
|
-
function parseAttributes(elements) {
|
|
918
|
-
const attrs = { _id: generateId() };
|
|
917
|
+
function parseAttributes(elements, xmlAttrs = {}) {
|
|
918
|
+
const attrs = { _id: xmlAttrs["id"] || generateId() };
|
|
919
919
|
const divisions = getElementTextAsInt(elements, "divisions");
|
|
920
920
|
if (divisions !== void 0) attrs.divisions = divisions;
|
|
921
921
|
const staves = getElementTextAsInt(elements, "staves");
|
|
@@ -1081,7 +1081,7 @@ function parseTranspose(elements) {
|
|
|
1081
1081
|
}
|
|
1082
1082
|
function parseNote(elements, attrs) {
|
|
1083
1083
|
const note = {
|
|
1084
|
-
_id: generateId(),
|
|
1084
|
+
_id: attrs["id"] || generateId(),
|
|
1085
1085
|
type: "note",
|
|
1086
1086
|
duration: 0
|
|
1087
1087
|
};
|
|
@@ -1837,9 +1837,9 @@ function parseBackup(elements) {
|
|
|
1837
1837
|
duration: parseInt(getElementText(elements, "duration") || "0", 10)
|
|
1838
1838
|
};
|
|
1839
1839
|
}
|
|
1840
|
-
function parseForward(elements) {
|
|
1840
|
+
function parseForward(elements, attrs = {}) {
|
|
1841
1841
|
const forward = {
|
|
1842
|
-
_id: generateId(),
|
|
1842
|
+
_id: attrs["id"] || generateId(),
|
|
1843
1843
|
type: "forward",
|
|
1844
1844
|
duration: parseInt(getElementText(elements, "duration") || "0", 10)
|
|
1845
1845
|
};
|
|
@@ -1851,7 +1851,7 @@ function parseForward(elements) {
|
|
|
1851
1851
|
}
|
|
1852
1852
|
function parseDirection(elements, attrs) {
|
|
1853
1853
|
const direction = {
|
|
1854
|
-
_id: generateId(),
|
|
1854
|
+
_id: attrs["id"] || generateId(),
|
|
1855
1855
|
type: "direction",
|
|
1856
1856
|
directionTypes: []
|
|
1857
1857
|
};
|
|
@@ -2276,7 +2276,7 @@ function parseDirectionTypes(elements) {
|
|
|
2276
2276
|
}
|
|
2277
2277
|
function parseBarline(elements, attrs) {
|
|
2278
2278
|
const location = attrs["location"] || "right";
|
|
2279
|
-
const barline = { _id: generateId(), location };
|
|
2279
|
+
const barline = { _id: attrs["id"] || generateId(), location };
|
|
2280
2280
|
const barStyle = getElementText(elements, "bar-style");
|
|
2281
2281
|
if (barStyle && isValidBarStyle(barStyle)) {
|
|
2282
2282
|
barline.barStyle = barStyle;
|
|
@@ -2508,7 +2508,7 @@ function parseMeasureStyle(elements, attrs) {
|
|
|
2508
2508
|
}
|
|
2509
2509
|
function parseHarmony(elements, attrs) {
|
|
2510
2510
|
const harmony = {
|
|
2511
|
-
_id: generateId(),
|
|
2511
|
+
_id: attrs["id"] || generateId(),
|
|
2512
2512
|
type: "harmony",
|
|
2513
2513
|
root: { rootStep: "C" },
|
|
2514
2514
|
kind: "major"
|
|
@@ -2648,7 +2648,7 @@ function parseHarmony(elements, attrs) {
|
|
|
2648
2648
|
}
|
|
2649
2649
|
function parseFiguredBass(elements, attrs) {
|
|
2650
2650
|
const fb = {
|
|
2651
|
-
_id: generateId(),
|
|
2651
|
+
_id: attrs["id"] || generateId(),
|
|
2652
2652
|
type: "figured-bass",
|
|
2653
2653
|
figures: []
|
|
2654
2654
|
};
|
|
@@ -2697,7 +2697,7 @@ function parseFiguredBass(elements, attrs) {
|
|
|
2697
2697
|
}
|
|
2698
2698
|
function parseSound(elements, attrs) {
|
|
2699
2699
|
const sound = {
|
|
2700
|
-
_id: generateId(),
|
|
2700
|
+
_id: attrs["id"] || generateId(),
|
|
2701
2701
|
type: "sound"
|
|
2702
2702
|
};
|
|
2703
2703
|
if (attrs["tempo"]) sound.tempo = parseFloat(attrs["tempo"]);
|
|
@@ -5021,7 +5021,7 @@ function serializeMeasure(measure, indent, out) {
|
|
|
5021
5021
|
serializePrint(measure.print, indent + " ", out);
|
|
5022
5022
|
}
|
|
5023
5023
|
if (measure.attributes) {
|
|
5024
|
-
serializeAttributes(measure.attributes, indent + " ", out);
|
|
5024
|
+
serializeAttributes(measure.attributes, indent + " ", out, measure.attributes._id);
|
|
5025
5025
|
}
|
|
5026
5026
|
for (const entry of measure.entries) {
|
|
5027
5027
|
serializeEntry(entry, indent + " ", out);
|