musicxml-io 0.5.0 → 0.5.2

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.mjs CHANGED
@@ -127,7 +127,7 @@ import {
127
127
  validateTiesAcrossMeasures,
128
128
  validateTuplets,
129
129
  validateVoiceStaff
130
- } from "./chunk-KGLK46XO.mjs";
130
+ } from "./chunk-2RIFJYXX.mjs";
131
131
  import {
132
132
  STEPS,
133
133
  STEP_SEMITONES,
@@ -214,9 +214,14 @@ import {
214
214
 
215
215
  // src/importers/musicxml.ts
216
216
  import { parse as txmlParse } from "txml";
217
+ var _entityMap = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'" };
218
+ var _entityRegex = /&(?:(amp|lt|gt|quot|apos)|#(\d+)|#x([0-9a-fA-F]+));/g;
217
219
  function decodeXmlEntities(s) {
218
220
  if (s.indexOf("&") === -1) return s;
219
- return s.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&#(\d+);/g, (_, num) => String.fromCharCode(parseInt(num, 10))).replace(/&#x([0-9a-fA-F]+);/g, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
221
+ return s.replace(
222
+ _entityRegex,
223
+ (_, named, dec, hex) => named ? _entityMap[named] : dec ? String.fromCharCode(parseInt(dec, 10)) : String.fromCharCode(parseInt(hex, 16))
224
+ );
220
225
  }
221
226
  function decodeTree(nodes) {
222
227
  for (let i = 0; i < nodes.length; i++) {
@@ -237,8 +242,9 @@ function decodeTree(nodes) {
237
242
  }
238
243
  }
239
244
  }
245
+ var TXML_OPTIONS = { noChildNodes: [] };
240
246
  function parse(xmlString) {
241
- const parsed = txmlParse(xmlString);
247
+ const parsed = txmlParse(xmlString, TXML_OPTIONS);
242
248
  decodeTree(parsed);
243
249
  let scorePartwiseVersion;
244
250
  let scorePartwise;
@@ -259,7 +265,8 @@ function parse(xmlString) {
259
265
  return score;
260
266
  }
261
267
  function findElement(elements, tagName) {
262
- for (const el of elements) {
268
+ for (let i = 0; i < elements.length; i++) {
269
+ const el = elements[i];
263
270
  if (typeof el !== "string" && el.tagName === tagName) {
264
271
  return el.children;
265
272
  }
@@ -270,9 +277,12 @@ function getElementContent(elements, tagName) {
270
277
  return findElement(elements, tagName);
271
278
  }
272
279
  function extractText(elements, preserveWhitespace = false) {
273
- for (const item of elements) {
280
+ for (let i = 0; i < elements.length; i++) {
281
+ const item = elements[i];
274
282
  if (typeof item === "string") {
275
- return preserveWhitespace ? item : item.trim();
283
+ if (preserveWhitespace) return item;
284
+ const trimmed = item.trim();
285
+ if (trimmed.length > 0) return trimmed;
276
286
  }
277
287
  }
278
288
  return "";
@@ -291,7 +301,8 @@ function getElementTextAsInt(elements, tagName, defaultValue) {
291
301
  }
292
302
  function collectElements(elements, tagName, parser) {
293
303
  const results = [];
294
- for (const el of elements) {
304
+ for (let i = 0; i < elements.length; i++) {
305
+ const el = elements[i];
295
306
  if (typeof el !== "string" && el.tagName === tagName) {
296
307
  results.push(parser(el.children, el.attributes));
297
308
  }
@@ -299,7 +310,8 @@ function collectElements(elements, tagName, parser) {
299
310
  return results;
300
311
  }
301
312
  function parseFirstElement(elements, tagName, parser) {
302
- for (const el of elements) {
313
+ for (let i = 0; i < elements.length; i++) {
314
+ const el = elements[i];
303
315
  if (typeof el !== "string" && el.tagName === tagName) {
304
316
  return parser(el.children, el.attributes);
305
317
  }
@@ -1040,12 +1052,8 @@ function parseNote(elements, attrs) {
1040
1052
  const note = {
1041
1053
  _id: generateId(),
1042
1054
  type: "note",
1043
- duration: getElementTextAsInt(elements, "duration", 0)
1055
+ duration: 0
1044
1056
  };
1045
- const voiceValue = getElementText(elements, "voice");
1046
- if (voiceValue !== void 0 && voiceValue !== "") {
1047
- note.voice = voiceValue;
1048
- }
1049
1057
  if (attrs["default-x"]) note.defaultX = parseFloat(attrs["default-x"]);
1050
1058
  if (attrs["default-y"]) note.defaultY = parseFloat(attrs["default-y"]);
1051
1059
  if (attrs["relative-x"]) note.relativeX = parseFloat(attrs["relative-x"]);
@@ -1056,149 +1064,183 @@ function parseNote(elements, attrs) {
1056
1064
  if (attrs["print-dot"] === "yes") note.printDot = true;
1057
1065
  if (attrs["print-spacing"] === "yes") note.printSpacing = true;
1058
1066
  if (attrs["print-spacing"] === "no") note.printSpacing = false;
1059
- if (hasElement(elements, "cue")) {
1060
- note.cue = true;
1061
- }
1062
- const instData = parseFirstElement(elements, "instrument", (_, attrs2) => attrs2["id"]);
1063
- if (instData) note.instrument = instData;
1064
- const pitch = getElementContent(elements, "pitch");
1065
- if (pitch) {
1066
- note.pitch = parsePitch(pitch);
1067
- }
1068
- for (const el of elements) {
1067
+ let dotCount = 0;
1068
+ let notationsIndex = 0;
1069
+ let tieElements;
1070
+ let beams;
1071
+ let allNotations;
1072
+ let lyrics;
1073
+ let hasGrace = false;
1074
+ for (let i = 0; i < elements.length; i++) {
1075
+ const el = elements[i];
1069
1076
  if (typeof el === "string") continue;
1070
- if (el.tagName === "rest") {
1071
- const restContent = el.children;
1072
- const restInfo = {};
1073
- const restAttrs = el.attributes;
1074
- if (restAttrs["measure"] === "yes") restInfo.measure = true;
1075
- const displayStep = getElementText(restContent, "display-step");
1076
- if (displayStep) restInfo.displayStep = displayStep;
1077
- const displayOctave = getElementText(restContent, "display-octave");
1078
- if (displayOctave) restInfo.displayOctave = parseInt(displayOctave, 10);
1079
- note.rest = restInfo;
1080
- break;
1077
+ const tag = el.tagName;
1078
+ const elAttrs = el.attributes;
1079
+ const c = el.children;
1080
+ switch (tag) {
1081
+ case "duration": {
1082
+ const text = extractText(c);
1083
+ if (text) note.duration = parseInt(text, 10) || 0;
1084
+ break;
1085
+ }
1086
+ case "voice": {
1087
+ const text = extractText(c);
1088
+ if (text) note.voice = text;
1089
+ break;
1090
+ }
1091
+ case "cue":
1092
+ note.cue = true;
1093
+ break;
1094
+ case "chord":
1095
+ note.chord = true;
1096
+ break;
1097
+ case "dot":
1098
+ dotCount++;
1099
+ break;
1100
+ case "instrument":
1101
+ if (elAttrs["id"]) note.instrument = elAttrs["id"];
1102
+ break;
1103
+ case "pitch":
1104
+ note.pitch = parsePitch(c);
1105
+ break;
1106
+ case "rest": {
1107
+ const restInfo = {};
1108
+ if (elAttrs["measure"] === "yes") restInfo.measure = true;
1109
+ const displayStep = getElementText(c, "display-step");
1110
+ if (displayStep) restInfo.displayStep = displayStep;
1111
+ const displayOctave = getElementText(c, "display-octave");
1112
+ if (displayOctave) restInfo.displayOctave = parseInt(displayOctave, 10);
1113
+ note.rest = restInfo;
1114
+ break;
1115
+ }
1116
+ case "unpitched": {
1117
+ note.unpitched = {};
1118
+ const displayStep = getElementText(c, "display-step");
1119
+ if (displayStep) note.unpitched.displayStep = displayStep;
1120
+ const displayOctave = getElementText(c, "display-octave");
1121
+ if (displayOctave) note.unpitched.displayOctave = parseInt(displayOctave, 10);
1122
+ break;
1123
+ }
1124
+ case "staff": {
1125
+ const text = extractText(c);
1126
+ if (text) {
1127
+ const v = parseInt(text, 10);
1128
+ if (!isNaN(v)) note.staff = v;
1129
+ }
1130
+ break;
1131
+ }
1132
+ case "type": {
1133
+ const noteType = extractText(c);
1134
+ if (isValidNoteType(noteType)) note.noteType = noteType;
1135
+ if (elAttrs["size"]) note.noteTypeSize = elAttrs["size"];
1136
+ break;
1137
+ }
1138
+ case "accidental": {
1139
+ const accValue = extractText(c);
1140
+ if (isValidAccidental(accValue)) {
1141
+ const accInfo = { value: accValue };
1142
+ if (elAttrs["cautionary"] === "yes") accInfo.cautionary = true;
1143
+ if (elAttrs["editorial"] === "yes") accInfo.editorial = true;
1144
+ if (elAttrs["parentheses"] === "yes") accInfo.parentheses = true;
1145
+ if (elAttrs["bracket"] === "yes") accInfo.bracket = true;
1146
+ if (elAttrs["relative-x"]) accInfo.relativeX = parseFloat(elAttrs["relative-x"]);
1147
+ if (elAttrs["relative-y"]) accInfo.relativeY = parseFloat(elAttrs["relative-y"]);
1148
+ if (elAttrs["color"]) accInfo.color = elAttrs["color"];
1149
+ if (elAttrs["size"]) accInfo.size = elAttrs["size"];
1150
+ if (elAttrs["font-size"]) accInfo.fontSize = elAttrs["font-size"];
1151
+ note.accidental = accInfo;
1152
+ }
1153
+ break;
1154
+ }
1155
+ case "stem": {
1156
+ const stemValue = extractText(c);
1157
+ if (stemValue === "up" || stemValue === "down" || stemValue === "none" || stemValue === "double") {
1158
+ note.stem = { value: stemValue };
1159
+ if (elAttrs["default-x"]) note.stem.defaultX = parseFloat(elAttrs["default-x"]);
1160
+ if (elAttrs["default-y"]) note.stem.defaultY = parseFloat(elAttrs["default-y"]);
1161
+ }
1162
+ break;
1163
+ }
1164
+ case "notehead": {
1165
+ const nhValue = extractText(c);
1166
+ if (isValidNotehead(nhValue)) {
1167
+ const nhInfo = { value: nhValue };
1168
+ if (elAttrs["filled"] === "yes") nhInfo.filled = true;
1169
+ else if (elAttrs["filled"] === "no") nhInfo.filled = false;
1170
+ if (elAttrs["parentheses"] === "yes") nhInfo.parentheses = true;
1171
+ note.notehead = nhInfo;
1172
+ }
1173
+ break;
1174
+ }
1175
+ case "tie": {
1176
+ const t = elAttrs["type"];
1177
+ if (t === "start" || t === "stop" || t === "continue") {
1178
+ if (!tieElements) tieElements = [];
1179
+ tieElements.push({ type: t });
1180
+ }
1181
+ break;
1182
+ }
1183
+ case "beam": {
1184
+ if (!beams) beams = [];
1185
+ beams.push(parseBeam(c, elAttrs));
1186
+ break;
1187
+ }
1188
+ case "notations": {
1189
+ const parsedNotations = parseNotations(c, notationsIndex);
1190
+ if (parsedNotations.length > 0) {
1191
+ if (!allNotations) allNotations = [];
1192
+ for (let j = 0; j < parsedNotations.length; j++) allNotations.push(parsedNotations[j]);
1193
+ }
1194
+ notationsIndex++;
1195
+ break;
1196
+ }
1197
+ case "lyric": {
1198
+ if (!lyrics) lyrics = [];
1199
+ lyrics.push(parseLyric(c, elAttrs));
1200
+ break;
1201
+ }
1202
+ case "grace": {
1203
+ hasGrace = true;
1204
+ note.grace = {};
1205
+ if (elAttrs["slash"] === "yes") note.grace.slash = true;
1206
+ else if (elAttrs["slash"] === "no") note.grace.slash = false;
1207
+ if (elAttrs["steal-time-previous"]) {
1208
+ note.grace.stealTimePrevious = parseFloat(elAttrs["steal-time-previous"]);
1209
+ }
1210
+ if (elAttrs["steal-time-following"]) {
1211
+ note.grace.stealTimeFollowing = parseFloat(elAttrs["steal-time-following"]);
1212
+ }
1213
+ break;
1214
+ }
1215
+ case "time-modification": {
1216
+ const actualNotes = getElementText(c, "actual-notes");
1217
+ const normalNotes = getElementText(c, "normal-notes");
1218
+ const normalType = getElementText(c, "normal-type");
1219
+ note.timeModification = {
1220
+ actualNotes: parseInt(actualNotes || "3", 10),
1221
+ normalNotes: parseInt(normalNotes || "2", 10)
1222
+ };
1223
+ if (normalType && isValidNoteType(normalType)) {
1224
+ note.timeModification.normalType = normalType;
1225
+ }
1226
+ let ndCount = 0;
1227
+ for (const tm of c) {
1228
+ if (typeof tm !== "string" && tm.tagName === "normal-dot") ndCount++;
1229
+ }
1230
+ if (ndCount > 0) note.timeModification.normalDots = ndCount;
1231
+ break;
1232
+ }
1081
1233
  }
1082
1234
  }
1083
- parseFirstElement(elements, "unpitched", (c) => {
1084
- note.unpitched = {};
1085
- const displayStep = getElementText(c, "display-step");
1086
- if (displayStep) note.unpitched.displayStep = displayStep;
1087
- const displayOctave = getElementText(c, "display-octave");
1088
- if (displayOctave) note.unpitched.displayOctave = parseInt(displayOctave, 10);
1089
- });
1090
- const staff = getElementTextAsInt(elements, "staff");
1091
- if (staff !== void 0) note.staff = staff;
1092
- if (hasElement(elements, "chord")) {
1093
- note.chord = true;
1094
- }
1095
- parseFirstElement(elements, "type", (c, a) => {
1096
- const noteType = extractText(c);
1097
- if (isValidNoteType(noteType)) note.noteType = noteType;
1098
- if (a["size"]) note.noteTypeSize = a["size"];
1099
- });
1100
- const dotCount = elements.filter((el) => typeof el !== "string" && el.tagName === "dot").length;
1101
1235
  if (dotCount > 0) note.dots = dotCount;
1102
- parseFirstElement(elements, "accidental", (c, a) => {
1103
- const accValue = extractText(c);
1104
- if (isValidAccidental(accValue)) {
1105
- const accInfo = { value: accValue };
1106
- if (a["cautionary"] === "yes") accInfo.cautionary = true;
1107
- if (a["editorial"] === "yes") accInfo.editorial = true;
1108
- if (a["parentheses"] === "yes") accInfo.parentheses = true;
1109
- if (a["bracket"] === "yes") accInfo.bracket = true;
1110
- if (a["relative-x"]) accInfo.relativeX = parseFloat(a["relative-x"]);
1111
- if (a["relative-y"]) accInfo.relativeY = parseFloat(a["relative-y"]);
1112
- if (a["color"]) accInfo.color = a["color"];
1113
- if (a["size"]) accInfo.size = a["size"];
1114
- if (a["font-size"]) accInfo.fontSize = a["font-size"];
1115
- note.accidental = accInfo;
1116
- }
1117
- });
1118
- parseFirstElement(elements, "stem", (c, a) => {
1119
- const stemValue = extractText(c);
1120
- if (stemValue === "up" || stemValue === "down" || stemValue === "none" || stemValue === "double") {
1121
- note.stem = { value: stemValue };
1122
- if (a["default-x"]) note.stem.defaultX = parseFloat(a["default-x"]);
1123
- if (a["default-y"]) note.stem.defaultY = parseFloat(a["default-y"]);
1124
- }
1125
- });
1126
- parseFirstElement(elements, "notehead", (c, a) => {
1127
- const nhValue = extractText(c);
1128
- if (isValidNotehead(nhValue)) {
1129
- const nhInfo = { value: nhValue };
1130
- if (a["filled"] === "yes") nhInfo.filled = true;
1131
- else if (a["filled"] === "no") nhInfo.filled = false;
1132
- if (a["parentheses"] === "yes") nhInfo.parentheses = true;
1133
- note.notehead = nhInfo;
1134
- }
1135
- });
1136
- const tieElements = collectElements(elements, "tie", (_, a) => {
1137
- const t = a["type"];
1138
- return t === "start" || t === "stop" || t === "continue" ? { type: t } : null;
1139
- }).filter((t) => t !== null);
1140
- if (tieElements.length > 0) {
1236
+ if (tieElements) {
1141
1237
  note.tie = tieElements[0];
1142
1238
  if (tieElements.length > 1) note.ties = tieElements;
1143
1239
  }
1144
- const beams = collectElements(elements, "beam", (c, a) => parseBeam(c, a));
1145
- if (beams.length > 0) note.beam = beams;
1146
- const allNotations = [];
1147
- let notationsIndex = 0;
1148
- for (const el of elements) {
1149
- if (typeof el === "string") continue;
1150
- if (el.tagName === "notations") {
1151
- const parsedNotations = parseNotations(el.children, notationsIndex);
1152
- allNotations.push(...parsedNotations);
1153
- notationsIndex++;
1154
- }
1155
- }
1156
- if (allNotations.length > 0) {
1157
- note.notations = allNotations;
1158
- }
1159
- const lyrics = [];
1160
- for (const el of elements) {
1161
- if (typeof el === "string") continue;
1162
- if (el.tagName === "lyric") {
1163
- lyrics.push(parseLyric(el.children, el.attributes));
1164
- }
1165
- }
1166
- if (lyrics.length > 0) note.lyrics = lyrics;
1167
- for (const el of elements) {
1168
- if (typeof el === "string") continue;
1169
- if (el.tagName === "grace") {
1170
- const graceAttrs = el.attributes;
1171
- note.grace = {};
1172
- if (graceAttrs["slash"] === "yes") note.grace.slash = true;
1173
- else if (graceAttrs["slash"] === "no") note.grace.slash = false;
1174
- if (graceAttrs["steal-time-previous"]) {
1175
- note.grace.stealTimePrevious = parseFloat(graceAttrs["steal-time-previous"]);
1176
- }
1177
- if (graceAttrs["steal-time-following"]) {
1178
- note.grace.stealTimeFollowing = parseFloat(graceAttrs["steal-time-following"]);
1179
- }
1180
- note.duration = 0;
1181
- break;
1182
- }
1183
- }
1184
- const timeMod = getElementContent(elements, "time-modification");
1185
- if (timeMod) {
1186
- const actualNotes = getElementText(timeMod, "actual-notes");
1187
- const normalNotes = getElementText(timeMod, "normal-notes");
1188
- const normalType = getElementText(timeMod, "normal-type");
1189
- note.timeModification = {
1190
- actualNotes: parseInt(actualNotes || "3", 10),
1191
- normalNotes: parseInt(normalNotes || "2", 10)
1192
- };
1193
- if (normalType && isValidNoteType(normalType)) {
1194
- note.timeModification.normalType = normalType;
1195
- }
1196
- let dotCount2 = 0;
1197
- for (const tm of timeMod) {
1198
- if (typeof tm !== "string" && tm.tagName === "normal-dot") dotCount2++;
1199
- }
1200
- if (dotCount2 > 0) note.timeModification.normalDots = dotCount2;
1201
- }
1240
+ if (beams) note.beam = beams;
1241
+ if (allNotations) note.notations = allNotations;
1242
+ if (lyrics) note.lyrics = lyrics;
1243
+ if (hasGrace) note.duration = 0;
1202
1244
  return note;
1203
1245
  }
1204
1246
  function parsePitch(elements) {
@@ -4498,144 +4540,141 @@ ${errorMessages}`);
4498
4540
  lines.push('<?xml version="1.0" encoding="UTF-8"?>');
4499
4541
  lines.push(`<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML ${version} Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">`);
4500
4542
  lines.push(`<score-partwise version="${version}">`);
4501
- lines.push(...serializeMetadata(score.metadata, indent));
4543
+ serializeMetadata(score.metadata, indent, lines);
4502
4544
  if (score.defaults) {
4503
- lines.push(...serializeDefaults(score.defaults, indent));
4545
+ serializeDefaults(score.defaults, indent, lines);
4504
4546
  }
4505
4547
  if (score.credits) {
4506
4548
  for (const credit of score.credits) {
4507
- lines.push(...serializeCredit(credit, indent));
4549
+ serializeCredit(credit, indent, lines);
4508
4550
  }
4509
4551
  }
4510
- lines.push(...serializePartList(score.partList, indent));
4552
+ serializePartList(score.partList, indent, lines);
4511
4553
  for (const part of score.parts) {
4512
- lines.push(...serializePart(part, indent));
4554
+ serializePart(part, indent, lines);
4513
4555
  }
4514
4556
  lines.push("</score-partwise>");
4515
4557
  return lines.join("\n");
4516
4558
  }
4517
- function serializeMetadata(metadata, indent) {
4518
- const lines = [];
4559
+ function serializeMetadata(metadata, indent, out) {
4519
4560
  if (metadata.workTitle !== void 0 || metadata.workNumber !== void 0) {
4520
- lines.push(`${indent}<work>`);
4561
+ out.push(`${indent}<work>`);
4521
4562
  if (metadata.workNumber !== void 0) {
4522
- lines.push(`${indent}${indent}<work-number>${escapeXml(metadata.workNumber)}</work-number>`);
4563
+ out.push(`${indent}${indent}<work-number>${escapeXml(metadata.workNumber)}</work-number>`);
4523
4564
  }
4524
4565
  if (metadata.workTitle !== void 0) {
4525
- lines.push(`${indent}${indent}<work-title>${escapeXml(metadata.workTitle)}</work-title>`);
4566
+ out.push(`${indent}${indent}<work-title>${escapeXml(metadata.workTitle)}</work-title>`);
4526
4567
  }
4527
- lines.push(`${indent}</work>`);
4568
+ out.push(`${indent}</work>`);
4528
4569
  }
4529
4570
  if (metadata.movementNumber !== void 0) {
4530
- lines.push(`${indent}<movement-number>${escapeXml(metadata.movementNumber)}</movement-number>`);
4571
+ out.push(`${indent}<movement-number>${escapeXml(metadata.movementNumber)}</movement-number>`);
4531
4572
  }
4532
4573
  if (metadata.movementTitle !== void 0) {
4533
- lines.push(`${indent}<movement-title>${escapeXml(metadata.movementTitle)}</movement-title>`);
4574
+ out.push(`${indent}<movement-title>${escapeXml(metadata.movementTitle)}</movement-title>`);
4534
4575
  }
4535
4576
  if (metadata.creators || metadata.rights || metadata.encoding || metadata.source || metadata.miscellaneous) {
4536
- lines.push(`${indent}<identification>`);
4577
+ out.push(`${indent}<identification>`);
4537
4578
  if (metadata.creators) {
4538
4579
  for (const creator of metadata.creators) {
4539
4580
  const typeAttr = creator.type ? ` type="${escapeXml(creator.type)}"` : "";
4540
- lines.push(`${indent}${indent}<creator${typeAttr}>${escapeXml(creator.value)}</creator>`);
4581
+ out.push(`${indent}${indent}<creator${typeAttr}>${escapeXml(creator.value)}</creator>`);
4541
4582
  }
4542
4583
  }
4543
4584
  if (metadata.rights) {
4544
4585
  for (const right of metadata.rights) {
4545
- lines.push(`${indent}${indent}<rights>${escapeXml(right)}</rights>`);
4586
+ out.push(`${indent}${indent}<rights>${escapeXml(right)}</rights>`);
4546
4587
  }
4547
4588
  }
4548
4589
  if (metadata.encoding) {
4549
- lines.push(`${indent}${indent}<encoding>`);
4590
+ out.push(`${indent}${indent}<encoding>`);
4550
4591
  if (metadata.encoding.software) {
4551
4592
  for (const sw of metadata.encoding.software) {
4552
- lines.push(`${indent}${indent}${indent}<software>${escapeXml(sw)}</software>`);
4593
+ out.push(`${indent}${indent}${indent}<software>${escapeXml(sw)}</software>`);
4553
4594
  }
4554
4595
  }
4555
4596
  if (metadata.encoding.encodingDate) {
4556
- lines.push(`${indent}${indent}${indent}<encoding-date>${escapeXml(metadata.encoding.encodingDate)}</encoding-date>`);
4597
+ out.push(`${indent}${indent}${indent}<encoding-date>${escapeXml(metadata.encoding.encodingDate)}</encoding-date>`);
4557
4598
  }
4558
4599
  if (metadata.encoding.encoder) {
4559
4600
  for (const enc of metadata.encoding.encoder) {
4560
- lines.push(`${indent}${indent}${indent}<encoder>${escapeXml(enc)}</encoder>`);
4601
+ out.push(`${indent}${indent}${indent}<encoder>${escapeXml(enc)}</encoder>`);
4561
4602
  }
4562
4603
  }
4563
4604
  if (metadata.encoding.encodingDescription) {
4564
- lines.push(`${indent}${indent}${indent}<encoding-description>${escapeXml(metadata.encoding.encodingDescription)}</encoding-description>`);
4605
+ out.push(`${indent}${indent}${indent}<encoding-description>${escapeXml(metadata.encoding.encodingDescription)}</encoding-description>`);
4565
4606
  }
4566
4607
  if (metadata.encoding.supports) {
4567
4608
  for (const support of metadata.encoding.supports) {
4568
4609
  let attrs = ` element="${escapeXml(support.element)}" type="${support.type}"`;
4569
4610
  if (support.attribute) attrs += ` attribute="${escapeXml(support.attribute)}"`;
4570
4611
  if (support.value) attrs += ` value="${escapeXml(support.value)}"`;
4571
- lines.push(`${indent}${indent}${indent}<supports${attrs}/>`);
4612
+ out.push(`${indent}${indent}${indent}<supports${attrs}/>`);
4572
4613
  }
4573
4614
  }
4574
- lines.push(`${indent}${indent}</encoding>`);
4615
+ out.push(`${indent}${indent}</encoding>`);
4575
4616
  }
4576
4617
  if (metadata.source) {
4577
- lines.push(`${indent}${indent}<source>${escapeXml(metadata.source)}</source>`);
4618
+ out.push(`${indent}${indent}<source>${escapeXml(metadata.source)}</source>`);
4578
4619
  }
4579
4620
  if (metadata.miscellaneous) {
4580
- lines.push(`${indent}${indent}<miscellaneous>`);
4621
+ out.push(`${indent}${indent}<miscellaneous>`);
4581
4622
  for (const field of metadata.miscellaneous) {
4582
- lines.push(`${indent}${indent}${indent}<miscellaneous-field name="${escapeXml(field.name)}">${escapeXml(field.value)}</miscellaneous-field>`);
4623
+ out.push(`${indent}${indent}${indent}<miscellaneous-field name="${escapeXml(field.name)}">${escapeXml(field.value)}</miscellaneous-field>`);
4583
4624
  }
4584
- lines.push(`${indent}${indent}</miscellaneous>`);
4625
+ out.push(`${indent}${indent}</miscellaneous>`);
4585
4626
  }
4586
- lines.push(`${indent}</identification>`);
4627
+ out.push(`${indent}</identification>`);
4587
4628
  }
4588
- return lines;
4589
4629
  }
4590
- function serializeDefaults(defaults, indent) {
4591
- const lines = [];
4592
- lines.push(`${indent}<defaults>`);
4630
+ function serializeDefaults(defaults, indent, out) {
4631
+ out.push(`${indent}<defaults>`);
4593
4632
  if (defaults.scaling) {
4594
- lines.push(`${indent}${indent}<scaling>`);
4595
- lines.push(`${indent}${indent}${indent}<millimeters>${defaults.scaling.millimeters}</millimeters>`);
4596
- lines.push(`${indent}${indent}${indent}<tenths>${defaults.scaling.tenths}</tenths>`);
4597
- lines.push(`${indent}${indent}</scaling>`);
4633
+ out.push(`${indent}${indent}<scaling>`);
4634
+ out.push(`${indent}${indent}${indent}<millimeters>${defaults.scaling.millimeters}</millimeters>`);
4635
+ out.push(`${indent}${indent}${indent}<tenths>${defaults.scaling.tenths}</tenths>`);
4636
+ out.push(`${indent}${indent}</scaling>`);
4598
4637
  }
4599
4638
  if (defaults.pageLayout) {
4600
- lines.push(...serializePageLayout(defaults.pageLayout, indent + indent));
4639
+ serializePageLayout(defaults.pageLayout, indent + indent, out);
4601
4640
  }
4602
4641
  if (defaults.systemLayout) {
4603
- lines.push(...serializeSystemLayout(defaults.systemLayout, indent + indent));
4642
+ serializeSystemLayout(defaults.systemLayout, indent + indent, out);
4604
4643
  }
4605
4644
  if (defaults.staffLayout) {
4606
4645
  for (const sl of defaults.staffLayout) {
4607
4646
  const numAttr = sl.number !== void 0 ? ` number="${sl.number}"` : "";
4608
- lines.push(`${indent}${indent}<staff-layout${numAttr}>`);
4647
+ out.push(`${indent}${indent}<staff-layout${numAttr}>`);
4609
4648
  if (sl.staffDistance !== void 0) {
4610
- lines.push(`${indent}${indent}${indent}<staff-distance>${sl.staffDistance}</staff-distance>`);
4649
+ out.push(`${indent}${indent}${indent}<staff-distance>${sl.staffDistance}</staff-distance>`);
4611
4650
  }
4612
- lines.push(`${indent}${indent}</staff-layout>`);
4651
+ out.push(`${indent}${indent}</staff-layout>`);
4613
4652
  }
4614
4653
  }
4615
4654
  if (defaults.appearance) {
4616
- lines.push(`${indent}${indent}<appearance>`);
4655
+ out.push(`${indent}${indent}<appearance>`);
4617
4656
  const app = defaults.appearance;
4618
4657
  if (app["line-widths"]) {
4619
4658
  for (const lw of app["line-widths"]) {
4620
- lines.push(`${indent}${indent}${indent}<line-width type="${escapeXml(lw.type)}">${lw.value}</line-width>`);
4659
+ out.push(`${indent}${indent}${indent}<line-width type="${escapeXml(lw.type)}">${lw.value}</line-width>`);
4621
4660
  }
4622
4661
  }
4623
4662
  if (app["note-sizes"]) {
4624
4663
  for (const ns of app["note-sizes"]) {
4625
- lines.push(`${indent}${indent}${indent}<note-size type="${escapeXml(ns.type)}">${ns.value}</note-size>`);
4664
+ out.push(`${indent}${indent}${indent}<note-size type="${escapeXml(ns.type)}">${ns.value}</note-size>`);
4626
4665
  }
4627
4666
  }
4628
4667
  if (app["distances"]) {
4629
4668
  for (const d of app["distances"]) {
4630
- lines.push(`${indent}${indent}${indent}<distance type="${escapeXml(d.type)}">${d.value}</distance>`);
4669
+ out.push(`${indent}${indent}${indent}<distance type="${escapeXml(d.type)}">${d.value}</distance>`);
4631
4670
  }
4632
4671
  }
4633
4672
  if (app["glyphs"]) {
4634
4673
  for (const g of app["glyphs"]) {
4635
- lines.push(`${indent}${indent}${indent}<glyph type="${escapeXml(g.type)}">${escapeXml(g.value)}</glyph>`);
4674
+ out.push(`${indent}${indent}${indent}<glyph type="${escapeXml(g.type)}">${escapeXml(g.value)}</glyph>`);
4636
4675
  }
4637
4676
  }
4638
- lines.push(`${indent}${indent}</appearance>`);
4677
+ out.push(`${indent}${indent}</appearance>`);
4639
4678
  }
4640
4679
  if (defaults.musicFont) {
4641
4680
  let attrs = "";
@@ -4643,7 +4682,7 @@ function serializeDefaults(defaults, indent) {
4643
4682
  if (defaults.musicFont.fontSize) attrs += ` font-size="${escapeXml(defaults.musicFont.fontSize)}"`;
4644
4683
  if (defaults.musicFont.fontStyle) attrs += ` font-style="${escapeXml(defaults.musicFont.fontStyle)}"`;
4645
4684
  if (defaults.musicFont.fontWeight) attrs += ` font-weight="${escapeXml(defaults.musicFont.fontWeight)}"`;
4646
- lines.push(`${indent}${indent}<music-font${attrs}/>`);
4685
+ out.push(`${indent}${indent}<music-font${attrs}/>`);
4647
4686
  }
4648
4687
  if (defaults.wordFont) {
4649
4688
  let attrs = "";
@@ -4651,7 +4690,7 @@ function serializeDefaults(defaults, indent) {
4651
4690
  if (defaults.wordFont.fontSize) attrs += ` font-size="${escapeXml(defaults.wordFont.fontSize)}"`;
4652
4691
  if (defaults.wordFont.fontStyle) attrs += ` font-style="${escapeXml(defaults.wordFont.fontStyle)}"`;
4653
4692
  if (defaults.wordFont.fontWeight) attrs += ` font-weight="${escapeXml(defaults.wordFont.fontWeight)}"`;
4654
- lines.push(`${indent}${indent}<word-font${attrs}/>`);
4693
+ out.push(`${indent}${indent}<word-font${attrs}/>`);
4655
4694
  }
4656
4695
  if (defaults.lyricFont) {
4657
4696
  for (const lf of defaults.lyricFont) {
@@ -4662,7 +4701,7 @@ function serializeDefaults(defaults, indent) {
4662
4701
  if (lf.fontSize) attrs += ` font-size="${escapeXml(lf.fontSize)}"`;
4663
4702
  if (lf.fontStyle) attrs += ` font-style="${escapeXml(lf.fontStyle)}"`;
4664
4703
  if (lf.fontWeight) attrs += ` font-weight="${escapeXml(lf.fontWeight)}"`;
4665
- lines.push(`${indent}${indent}<lyric-font${attrs}/>`);
4704
+ out.push(`${indent}${indent}<lyric-font${attrs}/>`);
4666
4705
  }
4667
4706
  }
4668
4707
  if (defaults.lyricLanguage) {
@@ -4671,64 +4710,60 @@ function serializeDefaults(defaults, indent) {
4671
4710
  if (ll.number !== void 0) attrs += ` number="${ll.number}"`;
4672
4711
  if (ll.name) attrs += ` name="${escapeXml(ll.name)}"`;
4673
4712
  attrs += ` xml:lang="${escapeXml(ll.xmlLang)}"`;
4674
- lines.push(`${indent}${indent}<lyric-language${attrs}/>`);
4713
+ out.push(`${indent}${indent}<lyric-language${attrs}/>`);
4675
4714
  }
4676
4715
  }
4677
- lines.push(`${indent}</defaults>`);
4678
- return lines;
4716
+ out.push(`${indent}</defaults>`);
4679
4717
  }
4680
- function serializePageLayout(layout, indent) {
4681
- const lines = [];
4682
- lines.push(`${indent}<page-layout>`);
4718
+ function serializePageLayout(layout, indent, out) {
4719
+ out.push(`${indent}<page-layout>`);
4683
4720
  if (layout.pageHeight !== void 0) {
4684
- lines.push(`${indent} <page-height>${layout.pageHeight}</page-height>`);
4721
+ out.push(`${indent} <page-height>${layout.pageHeight}</page-height>`);
4685
4722
  }
4686
4723
  if (layout.pageWidth !== void 0) {
4687
- lines.push(`${indent} <page-width>${layout.pageWidth}</page-width>`);
4724
+ out.push(`${indent} <page-width>${layout.pageWidth}</page-width>`);
4688
4725
  }
4689
4726
  if (layout.pageMargins) {
4690
4727
  for (const m of layout.pageMargins) {
4691
4728
  const typeAttr = m.type ? ` type="${m.type}"` : "";
4692
- lines.push(`${indent} <page-margins${typeAttr}>`);
4729
+ out.push(`${indent} <page-margins${typeAttr}>`);
4693
4730
  if (m.leftMargin !== void 0) {
4694
- lines.push(`${indent} <left-margin>${m.leftMarginRaw ?? m.leftMargin}</left-margin>`);
4731
+ out.push(`${indent} <left-margin>${m.leftMarginRaw ?? m.leftMargin}</left-margin>`);
4695
4732
  }
4696
4733
  if (m.rightMargin !== void 0) {
4697
- lines.push(`${indent} <right-margin>${m.rightMarginRaw ?? m.rightMargin}</right-margin>`);
4734
+ out.push(`${indent} <right-margin>${m.rightMarginRaw ?? m.rightMargin}</right-margin>`);
4698
4735
  }
4699
4736
  if (m.topMargin !== void 0) {
4700
- lines.push(`${indent} <top-margin>${m.topMarginRaw ?? m.topMargin}</top-margin>`);
4737
+ out.push(`${indent} <top-margin>${m.topMarginRaw ?? m.topMargin}</top-margin>`);
4701
4738
  }
4702
4739
  if (m.bottomMargin !== void 0) {
4703
- lines.push(`${indent} <bottom-margin>${m.bottomMarginRaw ?? m.bottomMargin}</bottom-margin>`);
4740
+ out.push(`${indent} <bottom-margin>${m.bottomMarginRaw ?? m.bottomMargin}</bottom-margin>`);
4704
4741
  }
4705
- lines.push(`${indent} </page-margins>`);
4742
+ out.push(`${indent} </page-margins>`);
4706
4743
  }
4707
4744
  }
4708
- lines.push(`${indent}</page-layout>`);
4709
- return lines;
4745
+ out.push(`${indent}</page-layout>`);
4710
4746
  }
4711
- function serializeSystemLayout(layout, indent) {
4712
- const lines = [];
4713
- lines.push(`${indent}<system-layout>`);
4747
+ function serializeSystemLayout(layout, indent, out) {
4748
+ out.push(`${indent}<system-layout>`);
4714
4749
  if (layout.systemMargins) {
4715
- lines.push(`${indent} <system-margins>`);
4750
+ out.push(`${indent} <system-margins>`);
4716
4751
  if (layout.systemMargins.leftMargin !== void 0) {
4717
- lines.push(`${indent} <left-margin>${layout.systemMargins.leftMarginRaw ?? layout.systemMargins.leftMargin}</left-margin>`);
4752
+ out.push(`${indent} <left-margin>${layout.systemMargins.leftMarginRaw ?? layout.systemMargins.leftMargin}</left-margin>`);
4718
4753
  }
4719
4754
  if (layout.systemMargins.rightMargin !== void 0) {
4720
- lines.push(`${indent} <right-margin>${layout.systemMargins.rightMarginRaw ?? layout.systemMargins.rightMargin}</right-margin>`);
4755
+ out.push(`${indent} <right-margin>${layout.systemMargins.rightMarginRaw ?? layout.systemMargins.rightMargin}</right-margin>`);
4721
4756
  }
4722
- lines.push(`${indent} </system-margins>`);
4757
+ out.push(`${indent} </system-margins>`);
4723
4758
  }
4724
4759
  if (layout.systemDistance !== void 0) {
4725
- lines.push(`${indent} <system-distance>${layout.systemDistanceRaw ?? layout.systemDistance}</system-distance>`);
4760
+ out.push(`${indent} <system-distance>${layout.systemDistanceRaw ?? layout.systemDistance}</system-distance>`);
4726
4761
  }
4727
4762
  if (layout.topSystemDistance !== void 0) {
4728
- lines.push(`${indent} <top-system-distance>${layout.topSystemDistanceRaw ?? layout.topSystemDistance}</top-system-distance>`);
4763
+ out.push(`${indent} <top-system-distance>${layout.topSystemDistanceRaw ?? layout.topSystemDistance}</top-system-distance>`);
4729
4764
  }
4730
4765
  if (layout.systemDividers) {
4731
- lines.push(`${indent} <system-dividers>`);
4766
+ out.push(`${indent} <system-dividers>`);
4732
4767
  if (layout.systemDividers.leftDivider) {
4733
4768
  let attrs = "";
4734
4769
  if (layout.systemDividers.leftDivider.printObject !== void 0) {
@@ -4740,7 +4775,7 @@ function serializeSystemLayout(layout, indent) {
4740
4775
  if (layout.systemDividers.leftDivider.valign) {
4741
4776
  attrs += ` valign="${layout.systemDividers.leftDivider.valign}"`;
4742
4777
  }
4743
- lines.push(`${indent} <left-divider${attrs}/>`);
4778
+ out.push(`${indent} <left-divider${attrs}/>`);
4744
4779
  }
4745
4780
  if (layout.systemDividers.rightDivider) {
4746
4781
  let attrs = "";
@@ -4753,22 +4788,20 @@ function serializeSystemLayout(layout, indent) {
4753
4788
  if (layout.systemDividers.rightDivider.valign) {
4754
4789
  attrs += ` valign="${layout.systemDividers.rightDivider.valign}"`;
4755
4790
  }
4756
- lines.push(`${indent} <right-divider${attrs}/>`);
4791
+ out.push(`${indent} <right-divider${attrs}/>`);
4757
4792
  }
4758
- lines.push(`${indent} </system-dividers>`);
4793
+ out.push(`${indent} </system-dividers>`);
4759
4794
  }
4760
- lines.push(`${indent}</system-layout>`);
4761
- return lines;
4795
+ out.push(`${indent}</system-layout>`);
4762
4796
  }
4763
- function serializeCredit(credit, indent) {
4764
- const lines = [];
4797
+ function serializeCredit(credit, indent, out) {
4765
4798
  let attrs = "";
4766
4799
  if (credit._id) attrs += ` id="${escapeXml(credit._id)}"`;
4767
4800
  if (credit.page !== void 0) attrs += ` page="${credit.page}"`;
4768
- lines.push(`${indent}<credit${attrs}>`);
4801
+ out.push(`${indent}<credit${attrs}>`);
4769
4802
  if (credit.creditType) {
4770
4803
  for (const ct of credit.creditType) {
4771
- lines.push(`${indent}${indent}<credit-type>${escapeXml(ct)}</credit-type>`);
4804
+ out.push(`${indent}${indent}<credit-type>${escapeXml(ct)}</credit-type>`);
4772
4805
  }
4773
4806
  }
4774
4807
  if (credit.creditWords) {
@@ -4786,27 +4819,23 @@ function serializeCredit(credit, indent) {
4786
4819
  if (cw.letterSpacing) attrs2 += ` letter-spacing="${escapeXml(cw.letterSpacing)}"`;
4787
4820
  if (cw.xmlLang) attrs2 += ` xml:lang="${escapeXml(cw.xmlLang)}"`;
4788
4821
  if (cw.xmlSpace) attrs2 += ` xml:space="${escapeXml(cw.xmlSpace)}"`;
4789
- lines.push(`${indent}${indent}<credit-words${attrs2}>${escapeXml(cw.text)}</credit-words>`);
4822
+ out.push(`${indent}${indent}<credit-words${attrs2}>${escapeXml(cw.text)}</credit-words>`);
4790
4823
  }
4791
4824
  }
4792
- lines.push(`${indent}</credit>`);
4793
- return lines;
4825
+ out.push(`${indent}</credit>`);
4794
4826
  }
4795
- function serializePartList(partList, indent) {
4796
- const lines = [];
4797
- lines.push(`${indent}<part-list>`);
4827
+ function serializePartList(partList, indent, out) {
4828
+ out.push(`${indent}<part-list>`);
4798
4829
  for (const entry of partList) {
4799
4830
  if (entry.type === "score-part") {
4800
- lines.push(...serializeScorePart(entry, indent + indent));
4831
+ serializeScorePart(entry, indent + indent, out);
4801
4832
  } else if (entry.type === "part-group") {
4802
- lines.push(...serializePartGroup(entry, indent + indent));
4833
+ serializePartGroup(entry, indent + indent, out);
4803
4834
  }
4804
4835
  }
4805
- lines.push(`${indent}</part-list>`);
4806
- return lines;
4836
+ out.push(`${indent}</part-list>`);
4807
4837
  }
4808
- function serializeDisplayTexts(texts, indent) {
4809
- const lines = [];
4838
+ function serializeDisplayTexts(texts, indent, out) {
4810
4839
  for (const dt of texts) {
4811
4840
  let attrs = "";
4812
4841
  if (dt.fontFamily) attrs += ` font-family="${escapeXml(dt.fontFamily)}"`;
@@ -4814,383 +4843,370 @@ function serializeDisplayTexts(texts, indent) {
4814
4843
  if (dt.fontStyle) attrs += ` font-style="${escapeXml(dt.fontStyle)}"`;
4815
4844
  if (dt.fontWeight) attrs += ` font-weight="${escapeXml(dt.fontWeight)}"`;
4816
4845
  if (dt.xmlSpace) attrs += ` xml:space="${escapeXml(dt.xmlSpace)}"`;
4817
- lines.push(`${indent}<display-text${attrs}>${escapeXml(dt.text)}</display-text>`);
4846
+ out.push(`${indent}<display-text${attrs}>${escapeXml(dt.text)}</display-text>`);
4818
4847
  }
4819
- return lines;
4820
4848
  }
4821
- function serializeScorePart(part, indent) {
4822
- const lines = [];
4823
- lines.push(`${indent}<score-part id="${escapeXml(part.id)}">`);
4849
+ function serializeScorePart(part, indent, out) {
4850
+ out.push(`${indent}<score-part id="${escapeXml(part.id)}">`);
4824
4851
  if (part.name !== void 0) {
4825
4852
  let pnAttrs = "";
4826
4853
  if (part.namePrintObject === false) pnAttrs += ' print-object="no"';
4827
- lines.push(`${indent} <part-name${pnAttrs}>${escapeXml(part.name)}</part-name>`);
4854
+ out.push(`${indent} <part-name${pnAttrs}>${escapeXml(part.name)}</part-name>`);
4828
4855
  }
4829
4856
  if (part.partNameDisplay && part.partNameDisplay.length > 0) {
4830
- lines.push(`${indent} <part-name-display>`);
4831
- lines.push(...serializeDisplayTexts(part.partNameDisplay, indent + " "));
4832
- lines.push(`${indent} </part-name-display>`);
4857
+ out.push(`${indent} <part-name-display>`);
4858
+ serializeDisplayTexts(part.partNameDisplay, indent + " ", out);
4859
+ out.push(`${indent} </part-name-display>`);
4833
4860
  }
4834
4861
  if (part.abbreviation !== void 0) {
4835
4862
  let paAttrs = "";
4836
4863
  if (part.abbreviationPrintObject === false) paAttrs += ' print-object="no"';
4837
- lines.push(`${indent} <part-abbreviation${paAttrs}>${escapeXml(part.abbreviation)}</part-abbreviation>`);
4864
+ out.push(`${indent} <part-abbreviation${paAttrs}>${escapeXml(part.abbreviation)}</part-abbreviation>`);
4838
4865
  }
4839
4866
  if (part.partAbbreviationDisplay && part.partAbbreviationDisplay.length > 0) {
4840
- lines.push(`${indent} <part-abbreviation-display>`);
4841
- lines.push(...serializeDisplayTexts(part.partAbbreviationDisplay, indent + " "));
4842
- lines.push(`${indent} </part-abbreviation-display>`);
4867
+ out.push(`${indent} <part-abbreviation-display>`);
4868
+ serializeDisplayTexts(part.partAbbreviationDisplay, indent + " ", out);
4869
+ out.push(`${indent} </part-abbreviation-display>`);
4843
4870
  }
4844
4871
  if (part.scoreInstruments) {
4845
4872
  for (const inst of part.scoreInstruments) {
4846
- lines.push(`${indent} <score-instrument id="${escapeXml(inst.id)}">`);
4847
- lines.push(`${indent} <instrument-name>${escapeXml(inst.name)}</instrument-name>`);
4873
+ out.push(`${indent} <score-instrument id="${escapeXml(inst.id)}">`);
4874
+ out.push(`${indent} <instrument-name>${escapeXml(inst.name)}</instrument-name>`);
4848
4875
  if (inst.abbreviation) {
4849
- lines.push(`${indent} <instrument-abbreviation>${escapeXml(inst.abbreviation)}</instrument-abbreviation>`);
4876
+ out.push(`${indent} <instrument-abbreviation>${escapeXml(inst.abbreviation)}</instrument-abbreviation>`);
4850
4877
  }
4851
4878
  if (inst.sound) {
4852
- lines.push(`${indent} <instrument-sound>${escapeXml(inst.sound)}</instrument-sound>`);
4879
+ out.push(`${indent} <instrument-sound>${escapeXml(inst.sound)}</instrument-sound>`);
4853
4880
  }
4854
4881
  if (inst.solo) {
4855
- lines.push(`${indent} <solo/>`);
4882
+ out.push(`${indent} <solo/>`);
4856
4883
  }
4857
4884
  if (inst.ensemble !== void 0) {
4858
4885
  if (inst.ensemble === 0) {
4859
- lines.push(`${indent} <ensemble/>`);
4886
+ out.push(`${indent} <ensemble/>`);
4860
4887
  } else {
4861
- lines.push(`${indent} <ensemble>${inst.ensemble}</ensemble>`);
4888
+ out.push(`${indent} <ensemble>${inst.ensemble}</ensemble>`);
4862
4889
  }
4863
4890
  }
4864
- lines.push(`${indent} </score-instrument>`);
4891
+ out.push(`${indent} </score-instrument>`);
4865
4892
  }
4866
4893
  }
4867
4894
  if (part.groups) {
4868
4895
  for (const group of part.groups) {
4869
- lines.push(`${indent} <group>${escapeXml(group)}</group>`);
4896
+ out.push(`${indent} <group>${escapeXml(group)}</group>`);
4870
4897
  }
4871
4898
  }
4872
4899
  if (part.midiInstruments) {
4873
4900
  for (const midi of part.midiInstruments) {
4874
- lines.push(`${indent} <midi-instrument id="${escapeXml(midi.id)}">`);
4901
+ out.push(`${indent} <midi-instrument id="${escapeXml(midi.id)}">`);
4875
4902
  if (midi.channel !== void 0) {
4876
- lines.push(`${indent} <midi-channel>${midi.channel}</midi-channel>`);
4903
+ out.push(`${indent} <midi-channel>${midi.channel}</midi-channel>`);
4877
4904
  }
4878
4905
  if (midi.name) {
4879
- lines.push(`${indent} <midi-name>${escapeXml(midi.name)}</midi-name>`);
4906
+ out.push(`${indent} <midi-name>${escapeXml(midi.name)}</midi-name>`);
4880
4907
  }
4881
4908
  if (midi.bank !== void 0) {
4882
- lines.push(`${indent} <midi-bank>${midi.bank}</midi-bank>`);
4909
+ out.push(`${indent} <midi-bank>${midi.bank}</midi-bank>`);
4883
4910
  }
4884
4911
  if (midi.program !== void 0) {
4885
- lines.push(`${indent} <midi-program>${midi.program}</midi-program>`);
4912
+ out.push(`${indent} <midi-program>${midi.program}</midi-program>`);
4886
4913
  }
4887
4914
  if (midi.unpitched !== void 0) {
4888
- lines.push(`${indent} <midi-unpitched>${midi.unpitched}</midi-unpitched>`);
4915
+ out.push(`${indent} <midi-unpitched>${midi.unpitched}</midi-unpitched>`);
4889
4916
  }
4890
4917
  if (midi.volume !== void 0) {
4891
- lines.push(`${indent} <volume>${midi.volume}</volume>`);
4918
+ out.push(`${indent} <volume>${midi.volume}</volume>`);
4892
4919
  }
4893
4920
  if (midi.pan !== void 0) {
4894
- lines.push(`${indent} <pan>${midi.pan}</pan>`);
4921
+ out.push(`${indent} <pan>${midi.pan}</pan>`);
4895
4922
  }
4896
4923
  if (midi.elevation !== void 0) {
4897
- lines.push(`${indent} <elevation>${midi.elevation}</elevation>`);
4924
+ out.push(`${indent} <elevation>${midi.elevation}</elevation>`);
4898
4925
  }
4899
- lines.push(`${indent} </midi-instrument>`);
4926
+ out.push(`${indent} </midi-instrument>`);
4900
4927
  }
4901
4928
  }
4902
- lines.push(`${indent}</score-part>`);
4903
- return lines;
4929
+ out.push(`${indent}</score-part>`);
4904
4930
  }
4905
- function serializePartGroup(group, indent) {
4906
- const lines = [];
4931
+ function serializePartGroup(group, indent, out) {
4907
4932
  let attrs = ` type="${group.groupType}"`;
4908
4933
  if (group.number !== void 0) attrs += ` number="${group.number}"`;
4909
4934
  if (group._id) attrs += ` id="${escapeXml(group._id)}"`;
4910
- lines.push(`${indent}<part-group${attrs}>`);
4935
+ out.push(`${indent}<part-group${attrs}>`);
4911
4936
  if (group.groupName) {
4912
- lines.push(`${indent} <group-name>${escapeXml(group.groupName)}</group-name>`);
4937
+ out.push(`${indent} <group-name>${escapeXml(group.groupName)}</group-name>`);
4913
4938
  }
4914
4939
  if (group.groupNameDisplay && group.groupNameDisplay.length > 0) {
4915
- lines.push(`${indent} <group-name-display>`);
4916
- lines.push(...serializeDisplayTexts(group.groupNameDisplay, indent + " "));
4917
- lines.push(`${indent} </group-name-display>`);
4940
+ out.push(`${indent} <group-name-display>`);
4941
+ serializeDisplayTexts(group.groupNameDisplay, indent + " ", out);
4942
+ out.push(`${indent} </group-name-display>`);
4918
4943
  }
4919
4944
  if (group.groupAbbreviation) {
4920
- lines.push(`${indent} <group-abbreviation>${escapeXml(group.groupAbbreviation)}</group-abbreviation>`);
4945
+ out.push(`${indent} <group-abbreviation>${escapeXml(group.groupAbbreviation)}</group-abbreviation>`);
4921
4946
  }
4922
4947
  if (group.groupAbbreviationDisplay && group.groupAbbreviationDisplay.length > 0) {
4923
- lines.push(`${indent} <group-abbreviation-display>`);
4924
- lines.push(...serializeDisplayTexts(group.groupAbbreviationDisplay, indent + " "));
4925
- lines.push(`${indent} </group-abbreviation-display>`);
4948
+ out.push(`${indent} <group-abbreviation-display>`);
4949
+ serializeDisplayTexts(group.groupAbbreviationDisplay, indent + " ", out);
4950
+ out.push(`${indent} </group-abbreviation-display>`);
4926
4951
  }
4927
4952
  if (group.groupSymbol) {
4928
4953
  const defaultXAttr = group.groupSymbolDefaultX !== void 0 ? ` default-x="${group.groupSymbolDefaultX}"` : "";
4929
- lines.push(`${indent} <group-symbol${defaultXAttr}>${group.groupSymbol}</group-symbol>`);
4954
+ out.push(`${indent} <group-symbol${defaultXAttr}>${group.groupSymbol}</group-symbol>`);
4930
4955
  }
4931
4956
  if (group.groupBarline) {
4932
- lines.push(`${indent} <group-barline>${group.groupBarline}</group-barline>`);
4957
+ out.push(`${indent} <group-barline>${group.groupBarline}</group-barline>`);
4933
4958
  }
4934
- lines.push(`${indent}</part-group>`);
4935
- return lines;
4959
+ out.push(`${indent}</part-group>`);
4936
4960
  }
4937
- function serializePart(part, indent) {
4938
- const lines = [];
4961
+ function serializePart(part, indent, out) {
4939
4962
  const idAttr = part.id ? ` id="${escapeXml(part.id)}"` : "";
4940
- lines.push(`${indent}<part${idAttr}>`);
4963
+ out.push(`${indent}<part${idAttr}>`);
4941
4964
  for (const measure of part.measures) {
4942
- lines.push(...serializeMeasure(measure, indent + indent));
4965
+ serializeMeasure(measure, indent + indent, out);
4943
4966
  }
4944
- lines.push(`${indent}</part>`);
4945
- return lines;
4967
+ out.push(`${indent}</part>`);
4946
4968
  }
4947
- function serializeMeasure(measure, indent) {
4948
- const lines = [];
4969
+ function serializeMeasure(measure, indent, out) {
4949
4970
  let attrs = ` number="${measure.number}"`;
4950
4971
  if (measure._id) attrs += ` id="${escapeXml(measure._id)}"`;
4951
4972
  if (measure.width !== void 0) attrs += ` width="${measure.width}"`;
4952
4973
  if (measure.implicit) attrs += ` implicit="yes"`;
4953
- lines.push(`${indent}<measure${attrs}>`);
4974
+ out.push(`${indent}<measure${attrs}>`);
4954
4975
  if (measure.print) {
4955
- lines.push(...serializePrint(measure.print, indent + " "));
4976
+ serializePrint(measure.print, indent + " ", out);
4956
4977
  }
4957
4978
  if (measure.attributes) {
4958
- lines.push(...serializeAttributes(measure.attributes, indent + " "));
4979
+ serializeAttributes(measure.attributes, indent + " ", out);
4959
4980
  }
4960
4981
  for (const entry of measure.entries) {
4961
- lines.push(...serializeEntry(entry, indent + " "));
4982
+ serializeEntry(entry, indent + " ", out);
4962
4983
  }
4963
4984
  if (measure.barlines) {
4964
4985
  for (const barline of measure.barlines) {
4965
- lines.push(...serializeBarline(barline, indent + " "));
4986
+ serializeBarline(barline, indent + " ", out);
4966
4987
  }
4967
4988
  }
4968
- lines.push(`${indent}</measure>`);
4969
- return lines;
4989
+ out.push(`${indent}</measure>`);
4970
4990
  }
4971
- function serializePrint(print, indent) {
4972
- const lines = [];
4991
+ function serializePrint(print, indent, out) {
4973
4992
  let attrs = "";
4974
4993
  if (print.newSystem) attrs += ' new-system="yes"';
4975
4994
  if (print.newPage) attrs += ' new-page="yes"';
4976
4995
  if (print.blankPage !== void 0) attrs += ` blank-page="${print.blankPage}"`;
4977
4996
  if (print.pageNumber) attrs += ` page-number="${escapeXml(print.pageNumber)}"`;
4978
- lines.push(`${indent}<print${attrs}>`);
4997
+ out.push(`${indent}<print${attrs}>`);
4979
4998
  if (print.pageLayout) {
4980
- lines.push(...serializePageLayout(print.pageLayout, indent + " "));
4999
+ serializePageLayout(print.pageLayout, indent + " ", out);
4981
5000
  }
4982
5001
  if (print.systemLayout) {
4983
- lines.push(...serializeSystemLayout(print.systemLayout, indent + " "));
5002
+ serializeSystemLayout(print.systemLayout, indent + " ", out);
4984
5003
  }
4985
5004
  if (print.staffLayouts) {
4986
5005
  for (const sl of print.staffLayouts) {
4987
5006
  const numAttr = sl.number !== void 0 ? ` number="${sl.number}"` : "";
4988
- lines.push(`${indent} <staff-layout${numAttr}>`);
5007
+ out.push(`${indent} <staff-layout${numAttr}>`);
4989
5008
  if (sl.staffDistance !== void 0) {
4990
- lines.push(`${indent} <staff-distance>${sl.staffDistance}</staff-distance>`);
5009
+ out.push(`${indent} <staff-distance>${sl.staffDistance}</staff-distance>`);
4991
5010
  }
4992
- lines.push(`${indent} </staff-layout>`);
5011
+ out.push(`${indent} </staff-layout>`);
4993
5012
  }
4994
5013
  }
4995
5014
  if (print.measureLayout) {
4996
- lines.push(`${indent} <measure-layout>`);
5015
+ out.push(`${indent} <measure-layout>`);
4997
5016
  if (print.measureLayout.measureDistance !== void 0) {
4998
- lines.push(`${indent} <measure-distance>${print.measureLayout.measureDistance}</measure-distance>`);
5017
+ out.push(`${indent} <measure-distance>${print.measureLayout.measureDistance}</measure-distance>`);
4999
5018
  }
5000
- lines.push(`${indent} </measure-layout>`);
5019
+ out.push(`${indent} </measure-layout>`);
5001
5020
  }
5002
5021
  if (print.measureNumbering) {
5003
5022
  const mn = print.measureNumbering;
5004
5023
  if (typeof mn === "string") {
5005
- lines.push(`${indent} <measure-numbering>${escapeXml(mn)}</measure-numbering>`);
5024
+ out.push(`${indent} <measure-numbering>${escapeXml(mn)}</measure-numbering>`);
5006
5025
  } else {
5007
5026
  let mnAttrs = "";
5008
5027
  if (mn.system) mnAttrs += ` system="${mn.system}"`;
5009
- lines.push(`${indent} <measure-numbering${mnAttrs}>${escapeXml(mn.value)}</measure-numbering>`);
5028
+ out.push(`${indent} <measure-numbering${mnAttrs}>${escapeXml(mn.value)}</measure-numbering>`);
5010
5029
  }
5011
5030
  }
5012
5031
  if (print.partNameDisplay && print.partNameDisplay.length > 0) {
5013
- lines.push(`${indent} <part-name-display>`);
5014
- lines.push(...serializeDisplayTexts(print.partNameDisplay, indent + " "));
5015
- lines.push(`${indent} </part-name-display>`);
5032
+ out.push(`${indent} <part-name-display>`);
5033
+ serializeDisplayTexts(print.partNameDisplay, indent + " ", out);
5034
+ out.push(`${indent} </part-name-display>`);
5016
5035
  }
5017
5036
  if (print.partAbbreviationDisplay && print.partAbbreviationDisplay.length > 0) {
5018
- lines.push(`${indent} <part-abbreviation-display>`);
5019
- lines.push(...serializeDisplayTexts(print.partAbbreviationDisplay, indent + " "));
5020
- lines.push(`${indent} </part-abbreviation-display>`);
5037
+ out.push(`${indent} <part-abbreviation-display>`);
5038
+ serializeDisplayTexts(print.partAbbreviationDisplay, indent + " ", out);
5039
+ out.push(`${indent} </part-abbreviation-display>`);
5021
5040
  }
5022
- lines.push(`${indent}</print>`);
5023
- return lines;
5041
+ out.push(`${indent}</print>`);
5024
5042
  }
5025
- function serializeAttributes(attrs, indent, id) {
5026
- const lines = [];
5043
+ function serializeAttributes(attrs, indent, out, id) {
5027
5044
  const idAttr = id ? ` id="${escapeXml(id)}"` : "";
5028
- lines.push(`${indent}<attributes${idAttr}>`);
5045
+ out.push(`${indent}<attributes${idAttr}>`);
5029
5046
  if (attrs.divisions !== void 0) {
5030
- lines.push(`${indent} <divisions>${attrs.divisions}</divisions>`);
5047
+ out.push(`${indent} <divisions>${attrs.divisions}</divisions>`);
5031
5048
  }
5032
5049
  if (attrs.keys && attrs.keys.length > 0) {
5033
5050
  for (const key of attrs.keys) {
5034
- lines.push(...serializeKey(key, indent + " "));
5051
+ serializeKey(key, indent + " ", out);
5035
5052
  }
5036
5053
  } else if (attrs.key) {
5037
- lines.push(...serializeKey(attrs.key, indent + " "));
5054
+ serializeKey(attrs.key, indent + " ", out);
5038
5055
  }
5039
5056
  if (attrs.time) {
5040
- lines.push(...serializeTime(attrs.time, indent + " "));
5057
+ serializeTime(attrs.time, indent + " ", out);
5041
5058
  }
5042
5059
  if (attrs.staves !== void 0) {
5043
- lines.push(`${indent} <staves>${attrs.staves}</staves>`);
5060
+ out.push(`${indent} <staves>${attrs.staves}</staves>`);
5044
5061
  }
5045
5062
  if (attrs.instruments !== void 0) {
5046
- lines.push(`${indent} <instruments>${attrs.instruments}</instruments>`);
5063
+ out.push(`${indent} <instruments>${attrs.instruments}</instruments>`);
5047
5064
  }
5048
5065
  if (attrs.clef) {
5049
5066
  for (const clef of attrs.clef) {
5050
- lines.push(...serializeClef(clef, indent + " "));
5067
+ serializeClef(clef, indent + " ", out);
5051
5068
  }
5052
5069
  }
5053
5070
  if (attrs.transpose) {
5054
- lines.push(...serializeTranspose(attrs.transpose, indent + " "));
5071
+ serializeTranspose(attrs.transpose, indent + " ", out);
5055
5072
  }
5056
5073
  if (attrs.staffDetails) {
5057
5074
  for (const sd of attrs.staffDetails) {
5058
- lines.push(...serializeStaffDetails(sd, indent + " "));
5075
+ serializeStaffDetails(sd, indent + " ", out);
5059
5076
  }
5060
5077
  }
5061
5078
  if (attrs.measureStyle) {
5062
5079
  for (const ms of attrs.measureStyle) {
5063
- lines.push(...serializeMeasureStyle(ms, indent + " "));
5080
+ serializeMeasureStyle(ms, indent + " ", out);
5064
5081
  }
5065
5082
  }
5066
- lines.push(`${indent}</attributes>`);
5067
- return lines;
5083
+ out.push(`${indent}</attributes>`);
5068
5084
  }
5069
- function serializeKey(key, indent) {
5070
- const lines = [];
5085
+ function serializeKey(key, indent, out) {
5071
5086
  let keyAttrs = "";
5072
5087
  if (key.number !== void 0) keyAttrs += ` number="${key.number}"`;
5073
5088
  if (key.printObject === false) keyAttrs += ' print-object="no"';
5074
5089
  else if (key.printObject === true) keyAttrs += ' print-object="yes"';
5075
- lines.push(`${indent}<key${keyAttrs}>`);
5090
+ out.push(`${indent}<key${keyAttrs}>`);
5076
5091
  if (key.cancel !== void 0) {
5077
5092
  const locationAttr = key.cancelLocation ? ` location="${key.cancelLocation}"` : "";
5078
- lines.push(`${indent} <cancel${locationAttr}>${key.cancel}</cancel>`);
5093
+ out.push(`${indent} <cancel${locationAttr}>${key.cancel}</cancel>`);
5079
5094
  }
5080
5095
  if (key.keySteps && key.keyAlters && key.keySteps.length > 0) {
5081
5096
  for (let i = 0; i < key.keySteps.length; i++) {
5082
- lines.push(`${indent} <key-step>${key.keySteps[i]}</key-step>`);
5097
+ out.push(`${indent} <key-step>${key.keySteps[i]}</key-step>`);
5083
5098
  if (i < key.keyAlters.length) {
5084
- lines.push(`${indent} <key-alter>${key.keyAlters[i]}</key-alter>`);
5099
+ out.push(`${indent} <key-alter>${key.keyAlters[i]}</key-alter>`);
5085
5100
  }
5086
5101
  }
5087
5102
  if (key.keyOctaves) {
5088
5103
  for (const ko of key.keyOctaves) {
5089
5104
  let koAttrs = ` number="${ko.number}"`;
5090
5105
  if (ko.cancel !== void 0) koAttrs += ` cancel="${ko.cancel ? "yes" : "no"}"`;
5091
- lines.push(`${indent} <key-octave${koAttrs}>${ko.octave}</key-octave>`);
5106
+ out.push(`${indent} <key-octave${koAttrs}>${ko.octave}</key-octave>`);
5092
5107
  }
5093
5108
  }
5094
5109
  } else {
5095
- lines.push(`${indent} <fifths>${key.fifths}</fifths>`);
5110
+ out.push(`${indent} <fifths>${key.fifths}</fifths>`);
5096
5111
  if (key.mode) {
5097
- lines.push(`${indent} <mode>${key.mode}</mode>`);
5112
+ out.push(`${indent} <mode>${key.mode}</mode>`);
5098
5113
  }
5099
5114
  if (key.keyOctaves) {
5100
5115
  for (const ko of key.keyOctaves) {
5101
5116
  let koAttrs = ` number="${ko.number}"`;
5102
5117
  if (ko.cancel !== void 0) koAttrs += ` cancel="${ko.cancel ? "yes" : "no"}"`;
5103
- lines.push(`${indent} <key-octave${koAttrs}>${ko.octave}</key-octave>`);
5118
+ out.push(`${indent} <key-octave${koAttrs}>${ko.octave}</key-octave>`);
5104
5119
  }
5105
5120
  }
5106
5121
  }
5107
- lines.push(`${indent}</key>`);
5108
- return lines;
5122
+ out.push(`${indent}</key>`);
5109
5123
  }
5110
- function serializeTime(time, indent) {
5111
- const lines = [];
5124
+ function serializeTime(time, indent, out) {
5112
5125
  let attrs = "";
5113
5126
  if (time.symbol) attrs += ` symbol="${time.symbol}"`;
5114
5127
  if (time.printObject === false) attrs += ' print-object="no"';
5115
- lines.push(`${indent}<time${attrs}>`);
5128
+ out.push(`${indent}<time${attrs}>`);
5116
5129
  if (time.senzaMisura) {
5117
- lines.push(`${indent} <senza-misura/>`);
5130
+ out.push(`${indent} <senza-misura/>`);
5118
5131
  } else if (time.beatsList && time.beatTypeList && time.beatsList.length > 1) {
5119
5132
  const maxLen = Math.max(time.beatsList.length, time.beatTypeList.length);
5120
5133
  for (let i = 0; i < maxLen; i++) {
5121
5134
  if (i < time.beatsList.length) {
5122
5135
  const beatsValue = time.beatsStrList && i < time.beatsStrList.length ? time.beatsStrList[i] : time.beatsList[i];
5123
- lines.push(`${indent} <beats>${beatsValue}</beats>`);
5136
+ out.push(`${indent} <beats>${beatsValue}</beats>`);
5124
5137
  }
5125
5138
  if (i < time.beatTypeList.length) {
5126
- lines.push(`${indent} <beat-type>${time.beatTypeList[i]}</beat-type>`);
5139
+ out.push(`${indent} <beat-type>${time.beatTypeList[i]}</beat-type>`);
5127
5140
  }
5128
5141
  }
5129
5142
  } else {
5130
- lines.push(`${indent} <beats>${time.beats}</beats>`);
5131
- lines.push(`${indent} <beat-type>${time.beatType}</beat-type>`);
5143
+ out.push(`${indent} <beats>${time.beats}</beats>`);
5144
+ out.push(`${indent} <beat-type>${time.beatType}</beat-type>`);
5132
5145
  }
5133
- lines.push(`${indent}</time>`);
5134
- return lines;
5146
+ out.push(`${indent}</time>`);
5135
5147
  }
5136
- function serializeClef(clef, indent) {
5137
- const lines = [];
5148
+ function serializeClef(clef, indent, out) {
5138
5149
  let attrs = clef.staff ? ` number="${clef.staff}"` : "";
5139
5150
  if (clef.printObject === false) attrs += ' print-object="no"';
5140
5151
  else if (clef.printObject === true) attrs += ' print-object="yes"';
5141
5152
  if (clef.afterBarline) attrs += ' after-barline="yes"';
5142
- lines.push(`${indent}<clef${attrs}>`);
5143
- lines.push(`${indent} <sign>${clef.sign}</sign>`);
5153
+ out.push(`${indent}<clef${attrs}>`);
5154
+ out.push(`${indent} <sign>${clef.sign}</sign>`);
5144
5155
  if (clef.line !== void 0) {
5145
- lines.push(`${indent} <line>${clef.line}</line>`);
5156
+ out.push(`${indent} <line>${clef.line}</line>`);
5146
5157
  }
5147
5158
  if (clef.clefOctaveChange !== void 0) {
5148
- lines.push(`${indent} <clef-octave-change>${clef.clefOctaveChange}</clef-octave-change>`);
5159
+ out.push(`${indent} <clef-octave-change>${clef.clefOctaveChange}</clef-octave-change>`);
5149
5160
  }
5150
- lines.push(`${indent}</clef>`);
5151
- return lines;
5161
+ out.push(`${indent}</clef>`);
5152
5162
  }
5153
- function serializeTranspose(transpose2, indent) {
5154
- const lines = [];
5155
- lines.push(`${indent}<transpose>`);
5156
- lines.push(`${indent} <diatonic>${transpose2.diatonic}</diatonic>`);
5157
- lines.push(`${indent} <chromatic>${transpose2.chromatic}</chromatic>`);
5163
+ function serializeTranspose(transpose2, indent, out) {
5164
+ out.push(`${indent}<transpose>`);
5165
+ out.push(`${indent} <diatonic>${transpose2.diatonic}</diatonic>`);
5166
+ out.push(`${indent} <chromatic>${transpose2.chromatic}</chromatic>`);
5158
5167
  if (transpose2.octaveChange !== void 0) {
5159
- lines.push(`${indent} <octave-change>${transpose2.octaveChange}</octave-change>`);
5168
+ out.push(`${indent} <octave-change>${transpose2.octaveChange}</octave-change>`);
5160
5169
  }
5161
- lines.push(`${indent}</transpose>`);
5162
- return lines;
5170
+ out.push(`${indent}</transpose>`);
5163
5171
  }
5164
- function serializeEntry(entry, indent) {
5172
+ function serializeEntry(entry, indent, out) {
5165
5173
  switch (entry.type) {
5166
5174
  case "note":
5167
- return serializeNote(entry, indent);
5175
+ serializeNote(entry, indent, out);
5176
+ break;
5168
5177
  case "backup":
5169
- return serializeBackup(entry, indent);
5178
+ serializeBackup(entry, indent, out);
5179
+ break;
5170
5180
  case "forward":
5171
- return serializeForward(entry, indent);
5181
+ serializeForward(entry, indent, out);
5182
+ break;
5172
5183
  case "direction":
5173
- return serializeDirection(entry, indent);
5184
+ serializeDirection(entry, indent, out);
5185
+ break;
5174
5186
  case "harmony":
5175
- return serializeHarmony(entry, indent);
5187
+ serializeHarmony(entry, indent, out);
5188
+ break;
5176
5189
  case "figured-bass":
5177
- return serializeFiguredBass(entry, indent);
5190
+ serializeFiguredBass(entry, indent, out);
5191
+ break;
5178
5192
  case "sound":
5179
- return serializeSound(entry, indent);
5193
+ serializeSound(entry, indent, out);
5194
+ break;
5180
5195
  case "attributes":
5181
- return serializeAttributes(entry.attributes, indent, entry._id);
5196
+ serializeAttributes(entry.attributes, indent, out, entry._id);
5197
+ break;
5182
5198
  case "grouping": {
5183
5199
  const grp = entry;
5184
5200
  let grpAttrs = ` type="${grp.groupingType}"`;
5185
5201
  if (grp.number) grpAttrs += ` number="${grp.number}"`;
5186
- return [`${indent}<grouping${grpAttrs}/>`];
5202
+ out.push(`${indent}<grouping${grpAttrs}/>`);
5203
+ break;
5187
5204
  }
5188
5205
  default:
5189
- return [];
5206
+ break;
5190
5207
  }
5191
5208
  }
5192
- function serializeNote(note, indent) {
5193
- const lines = [];
5209
+ function serializeNote(note, indent, out) {
5194
5210
  const noteAttrs = buildAttrs({
5195
5211
  "id": note._id,
5196
5212
  "default-x": note.defaultX,
@@ -5202,74 +5218,74 @@ function serializeNote(note, indent) {
5202
5218
  "print-dot": note.printDot !== void 0 ? note.printDot : void 0,
5203
5219
  "print-spacing": note.printSpacing
5204
5220
  });
5205
- lines.push(`${indent}<note${noteAttrs}>`);
5221
+ out.push(`${indent}<note${noteAttrs}>`);
5206
5222
  if (note.grace) {
5207
5223
  const graceAttrs = buildAttrs({
5208
5224
  "slash": note.grace.slash !== void 0 ? note.grace.slash : void 0,
5209
5225
  "steal-time-previous": note.grace.stealTimePrevious,
5210
5226
  "steal-time-following": note.grace.stealTimeFollowing
5211
5227
  });
5212
- lines.push(`${indent} <grace${graceAttrs}/>`);
5228
+ out.push(`${indent} <grace${graceAttrs}/>`);
5213
5229
  }
5214
5230
  if (note.cue) {
5215
- lines.push(`${indent} <cue/>`);
5231
+ out.push(`${indent} <cue/>`);
5216
5232
  }
5217
5233
  if (note.chord) {
5218
- lines.push(`${indent} <chord/>`);
5234
+ out.push(`${indent} <chord/>`);
5219
5235
  }
5220
5236
  if (note.pitch) {
5221
- lines.push(...serializePitch(note.pitch, indent + " "));
5237
+ serializePitch(note.pitch, indent + " ", out);
5222
5238
  } else if (note.rest) {
5223
5239
  let restAttrs = "";
5224
5240
  if (note.rest.measure) restAttrs += ' measure="yes"';
5225
5241
  if (note.rest.displayStep || note.rest.displayOctave !== void 0) {
5226
- lines.push(`${indent} <rest${restAttrs}>`);
5242
+ out.push(`${indent} <rest${restAttrs}>`);
5227
5243
  if (note.rest.displayStep) {
5228
- lines.push(`${indent} <display-step>${note.rest.displayStep}</display-step>`);
5244
+ out.push(`${indent} <display-step>${note.rest.displayStep}</display-step>`);
5229
5245
  }
5230
5246
  if (note.rest.displayOctave !== void 0) {
5231
- lines.push(`${indent} <display-octave>${note.rest.displayOctave}</display-octave>`);
5247
+ out.push(`${indent} <display-octave>${note.rest.displayOctave}</display-octave>`);
5232
5248
  }
5233
- lines.push(`${indent} </rest>`);
5249
+ out.push(`${indent} </rest>`);
5234
5250
  } else {
5235
- lines.push(`${indent} <rest${restAttrs}/>`);
5251
+ out.push(`${indent} <rest${restAttrs}/>`);
5236
5252
  }
5237
5253
  } else if (note.unpitched) {
5238
5254
  if (note.unpitched.displayStep || note.unpitched.displayOctave !== void 0) {
5239
- lines.push(`${indent} <unpitched>`);
5255
+ out.push(`${indent} <unpitched>`);
5240
5256
  if (note.unpitched.displayStep) {
5241
- lines.push(`${indent} <display-step>${note.unpitched.displayStep}</display-step>`);
5257
+ out.push(`${indent} <display-step>${note.unpitched.displayStep}</display-step>`);
5242
5258
  }
5243
5259
  if (note.unpitched.displayOctave !== void 0) {
5244
- lines.push(`${indent} <display-octave>${note.unpitched.displayOctave}</display-octave>`);
5260
+ out.push(`${indent} <display-octave>${note.unpitched.displayOctave}</display-octave>`);
5245
5261
  }
5246
- lines.push(`${indent} </unpitched>`);
5262
+ out.push(`${indent} </unpitched>`);
5247
5263
  } else {
5248
- lines.push(`${indent} <unpitched/>`);
5264
+ out.push(`${indent} <unpitched/>`);
5249
5265
  }
5250
5266
  } else {
5251
- lines.push(`${indent} <rest/>`);
5267
+ out.push(`${indent} <rest/>`);
5252
5268
  }
5253
5269
  if (!note.grace) {
5254
- lines.push(`${indent} <duration>${note.duration}</duration>`);
5270
+ out.push(`${indent} <duration>${note.duration}</duration>`);
5255
5271
  }
5256
5272
  if (note.ties && note.ties.length > 0) {
5257
5273
  for (const tie of note.ties) {
5258
- lines.push(`${indent} <tie type="${tie.type}"/>`);
5274
+ out.push(`${indent} <tie type="${tie.type}"/>`);
5259
5275
  }
5260
5276
  } else if (note.tie) {
5261
- lines.push(`${indent} <tie type="${note.tie.type}"/>`);
5277
+ out.push(`${indent} <tie type="${note.tie.type}"/>`);
5262
5278
  }
5263
5279
  if (note.voice !== void 0) {
5264
- lines.push(`${indent} <voice>${note.voice}</voice>`);
5280
+ out.push(`${indent} <voice>${note.voice}</voice>`);
5265
5281
  }
5266
5282
  if (note.noteType) {
5267
5283
  const typeAttrs = note.noteTypeSize ? ` size="${escapeXml(note.noteTypeSize)}"` : "";
5268
- lines.push(`${indent} <type${typeAttrs}>${note.noteType}</type>`);
5284
+ out.push(`${indent} <type${typeAttrs}>${note.noteType}</type>`);
5269
5285
  }
5270
5286
  if (note.dots) {
5271
5287
  for (let i = 0; i < note.dots; i++) {
5272
- lines.push(`${indent} <dot/>`);
5288
+ out.push(`${indent} <dot/>`);
5273
5289
  }
5274
5290
  }
5275
5291
  if (note.accidental) {
@@ -5284,74 +5300,70 @@ function serializeNote(note, indent) {
5284
5300
  "size": note.accidental.size,
5285
5301
  "font-size": note.accidental.fontSize
5286
5302
  });
5287
- lines.push(`${indent} <accidental${accAttrs}>${note.accidental.value}</accidental>`);
5303
+ out.push(`${indent} <accidental${accAttrs}>${note.accidental.value}</accidental>`);
5288
5304
  }
5289
5305
  if (note.timeModification) {
5290
- lines.push(`${indent} <time-modification>`);
5291
- lines.push(`${indent} <actual-notes>${note.timeModification.actualNotes}</actual-notes>`);
5292
- lines.push(`${indent} <normal-notes>${note.timeModification.normalNotes}</normal-notes>`);
5306
+ out.push(`${indent} <time-modification>`);
5307
+ out.push(`${indent} <actual-notes>${note.timeModification.actualNotes}</actual-notes>`);
5308
+ out.push(`${indent} <normal-notes>${note.timeModification.normalNotes}</normal-notes>`);
5293
5309
  if (note.timeModification.normalType) {
5294
- lines.push(`${indent} <normal-type>${note.timeModification.normalType}</normal-type>`);
5310
+ out.push(`${indent} <normal-type>${note.timeModification.normalType}</normal-type>`);
5295
5311
  }
5296
5312
  if (note.timeModification.normalDots) {
5297
5313
  for (let i = 0; i < note.timeModification.normalDots; i++) {
5298
- lines.push(`${indent} <normal-dot/>`);
5314
+ out.push(`${indent} <normal-dot/>`);
5299
5315
  }
5300
5316
  }
5301
- lines.push(`${indent} </time-modification>`);
5317
+ out.push(`${indent} </time-modification>`);
5302
5318
  }
5303
5319
  if (note.stem) {
5304
5320
  const stemAttrs = buildAttrs({
5305
5321
  "default-x": note.stem.defaultX,
5306
5322
  "default-y": note.stem.defaultY
5307
5323
  });
5308
- lines.push(`${indent} <stem${stemAttrs}>${note.stem.value}</stem>`);
5324
+ out.push(`${indent} <stem${stemAttrs}>${note.stem.value}</stem>`);
5309
5325
  }
5310
5326
  if (note.notehead) {
5311
5327
  const nhAttrs = buildAttrs({
5312
5328
  "filled": note.notehead.filled,
5313
5329
  "parentheses": note.notehead.parentheses || void 0
5314
5330
  });
5315
- lines.push(`${indent} <notehead${nhAttrs}>${note.notehead.value}</notehead>`);
5331
+ out.push(`${indent} <notehead${nhAttrs}>${note.notehead.value}</notehead>`);
5316
5332
  }
5317
5333
  if (note.staff !== void 0) {
5318
- lines.push(`${indent} <staff>${note.staff}</staff>`);
5334
+ out.push(`${indent} <staff>${note.staff}</staff>`);
5319
5335
  }
5320
5336
  if (note.instrument) {
5321
- lines.push(`${indent} <instrument id="${escapeXml(note.instrument)}"/>`);
5337
+ out.push(`${indent} <instrument id="${escapeXml(note.instrument)}"/>`);
5322
5338
  }
5323
5339
  if (note.beam) {
5324
5340
  for (const beam of note.beam) {
5325
- lines.push(...serializeBeam(beam, indent + " "));
5341
+ serializeBeam(beam, indent + " ", out);
5326
5342
  }
5327
5343
  }
5328
5344
  if (note.notations && note.notations.length > 0) {
5329
- lines.push(...serializeNotations(note.notations, indent + " "));
5345
+ serializeNotations(note.notations, indent + " ", out);
5330
5346
  }
5331
5347
  if (note.lyrics) {
5332
5348
  for (const lyric of note.lyrics) {
5333
- lines.push(...serializeLyric(lyric, indent + " "));
5349
+ serializeLyric(lyric, indent + " ", out);
5334
5350
  }
5335
5351
  }
5336
- lines.push(`${indent}</note>`);
5337
- return lines;
5352
+ out.push(`${indent}</note>`);
5338
5353
  }
5339
- function serializePitch(pitch, indent) {
5340
- const lines = [];
5341
- lines.push(`${indent}<pitch>`);
5342
- lines.push(`${indent} <step>${pitch.step}</step>`);
5354
+ function serializePitch(pitch, indent, out) {
5355
+ out.push(`${indent}<pitch>`);
5356
+ out.push(`${indent} <step>${pitch.step}</step>`);
5343
5357
  if (pitch.alter !== void 0 && pitch.alter !== 0) {
5344
- lines.push(`${indent} <alter>${pitch.alter}</alter>`);
5358
+ out.push(`${indent} <alter>${pitch.alter}</alter>`);
5345
5359
  }
5346
- lines.push(`${indent} <octave>${pitch.octave}</octave>`);
5347
- lines.push(`${indent}</pitch>`);
5348
- return lines;
5360
+ out.push(`${indent} <octave>${pitch.octave}</octave>`);
5361
+ out.push(`${indent}</pitch>`);
5349
5362
  }
5350
- function serializeBeam(beam, indent) {
5351
- return [`${indent}<beam number="${beam.number}">${beam.type}</beam>`];
5363
+ function serializeBeam(beam, indent, out) {
5364
+ out.push(`${indent}<beam number="${beam.number}">${beam.type}</beam>`);
5352
5365
  }
5353
- function serializeNotations(notations, indent) {
5354
- const lines = [];
5366
+ function serializeNotations(notations, indent, out) {
5355
5367
  const notationsGroups = /* @__PURE__ */ new Map();
5356
5368
  for (const notation of notations) {
5357
5369
  const idx = notation.notationsIndex ?? 0;
@@ -5363,13 +5375,11 @@ function serializeNotations(notations, indent) {
5363
5375
  const sortedIndices = Array.from(notationsGroups.keys()).sort((a, b) => a - b);
5364
5376
  for (const notationsIdx of sortedIndices) {
5365
5377
  const groupNotations = notationsGroups.get(notationsIdx);
5366
- lines.push(...serializeNotationsGroup(groupNotations, indent));
5378
+ serializeNotationsGroup(groupNotations, indent, out);
5367
5379
  }
5368
- return lines;
5369
5380
  }
5370
- function serializeNotationsGroup(notations, indent) {
5371
- const lines = [];
5372
- lines.push(`${indent}<notations>`);
5381
+ function serializeNotationsGroup(notations, indent, out) {
5382
+ out.push(`${indent}<notations>`);
5373
5383
  const chunks = [];
5374
5384
  for (const notation of notations) {
5375
5385
  if (notation.type === "articulation") {
@@ -5400,25 +5410,23 @@ function serializeNotationsGroup(notations, indent) {
5400
5410
  }
5401
5411
  for (const chunk of chunks) {
5402
5412
  if (chunk.kind === "standalone") {
5403
- lines.push(...serializeStandaloneNotation(chunk.notation, indent));
5413
+ serializeStandaloneNotation(chunk.notation, indent, out);
5404
5414
  } else if (chunk.kind === "articulations") {
5405
- lines.push(...serializeArticulationsGroup(chunk.items, indent));
5415
+ serializeArticulationsGroup(chunk.items, indent, out);
5406
5416
  } else if (chunk.kind === "ornaments") {
5407
- lines.push(...serializeOrnamentsGroup(chunk.items, indent));
5417
+ serializeOrnamentsGroup(chunk.items, indent, out);
5408
5418
  } else if (chunk.kind === "technical") {
5409
- lines.push(...serializeTechnicalGroup(chunk.items, indent));
5419
+ serializeTechnicalGroup(chunk.items, indent, out);
5410
5420
  }
5411
5421
  }
5412
- lines.push(`${indent}</notations>`);
5413
- return lines;
5422
+ out.push(`${indent}</notations>`);
5414
5423
  }
5415
- function serializeStandaloneNotation(notation, indent) {
5416
- const lines = [];
5424
+ function serializeStandaloneNotation(notation, indent, out) {
5417
5425
  if (notation.type === "tied") {
5418
5426
  let attrs = ` type="${notation.tiedType}"`;
5419
5427
  if (notation.number !== void 0) attrs += ` number="${notation.number}"`;
5420
5428
  if (notation.orientation) attrs += ` orientation="${notation.orientation}"`;
5421
- lines.push(`${indent} <tied${attrs}/>`);
5429
+ out.push(`${indent} <tied${attrs}/>`);
5422
5430
  } else if (notation.type === "slur") {
5423
5431
  let attrs = "";
5424
5432
  if (notation.number !== void 0) attrs += ` number="${notation.number}"`;
@@ -5432,7 +5440,7 @@ function serializeStandaloneNotation(notation, indent) {
5432
5440
  if (notation.bezierX2 !== void 0) attrs += ` bezier-x2="${notation.bezierX2}"`;
5433
5441
  if (notation.bezierY2 !== void 0) attrs += ` bezier-y2="${notation.bezierY2}"`;
5434
5442
  if (notation.placement) attrs += ` placement="${notation.placement}"`;
5435
- lines.push(`${indent} <slur${attrs}/>`);
5443
+ out.push(`${indent} <slur${attrs}/>`);
5436
5444
  } else if (notation.type === "tuplet") {
5437
5445
  let attrs = ` type="${notation.tupletType}"`;
5438
5446
  if (notation.number !== void 0) attrs += ` number="${notation.number}"`;
@@ -5443,51 +5451,51 @@ function serializeStandaloneNotation(notation, indent) {
5443
5451
  if (notation.placement) attrs += ` placement="${notation.placement}"`;
5444
5452
  const tup = notation;
5445
5453
  if (tup.tupletActual || tup.tupletNormal) {
5446
- lines.push(`${indent} <tuplet${attrs}>`);
5454
+ out.push(`${indent} <tuplet${attrs}>`);
5447
5455
  if (tup.tupletActual) {
5448
- lines.push(`${indent} <tuplet-actual>`);
5456
+ out.push(`${indent} <tuplet-actual>`);
5449
5457
  if (tup.tupletActual.tupletNumber !== void 0) {
5450
- lines.push(`${indent} <tuplet-number>${tup.tupletActual.tupletNumber}</tuplet-number>`);
5458
+ out.push(`${indent} <tuplet-number>${tup.tupletActual.tupletNumber}</tuplet-number>`);
5451
5459
  }
5452
5460
  if (tup.tupletActual.tupletType) {
5453
- lines.push(`${indent} <tuplet-type>${tup.tupletActual.tupletType}</tuplet-type>`);
5461
+ out.push(`${indent} <tuplet-type>${tup.tupletActual.tupletType}</tuplet-type>`);
5454
5462
  }
5455
5463
  if (tup.tupletActual.tupletDots) {
5456
5464
  for (let i = 0; i < tup.tupletActual.tupletDots; i++) {
5457
- lines.push(`${indent} <tuplet-dot/>`);
5465
+ out.push(`${indent} <tuplet-dot/>`);
5458
5466
  }
5459
5467
  }
5460
- lines.push(`${indent} </tuplet-actual>`);
5468
+ out.push(`${indent} </tuplet-actual>`);
5461
5469
  }
5462
5470
  if (tup.tupletNormal) {
5463
- lines.push(`${indent} <tuplet-normal>`);
5471
+ out.push(`${indent} <tuplet-normal>`);
5464
5472
  if (tup.tupletNormal.tupletNumber !== void 0) {
5465
- lines.push(`${indent} <tuplet-number>${tup.tupletNormal.tupletNumber}</tuplet-number>`);
5473
+ out.push(`${indent} <tuplet-number>${tup.tupletNormal.tupletNumber}</tuplet-number>`);
5466
5474
  }
5467
5475
  if (tup.tupletNormal.tupletType) {
5468
- lines.push(`${indent} <tuplet-type>${tup.tupletNormal.tupletType}</tuplet-type>`);
5476
+ out.push(`${indent} <tuplet-type>${tup.tupletNormal.tupletType}</tuplet-type>`);
5469
5477
  }
5470
5478
  if (tup.tupletNormal.tupletDots) {
5471
5479
  for (let i = 0; i < tup.tupletNormal.tupletDots; i++) {
5472
- lines.push(`${indent} <tuplet-dot/>`);
5480
+ out.push(`${indent} <tuplet-dot/>`);
5473
5481
  }
5474
5482
  }
5475
- lines.push(`${indent} </tuplet-normal>`);
5483
+ out.push(`${indent} </tuplet-normal>`);
5476
5484
  }
5477
- lines.push(`${indent} </tuplet>`);
5485
+ out.push(`${indent} </tuplet>`);
5478
5486
  } else {
5479
- lines.push(`${indent} <tuplet${attrs}/>`);
5487
+ out.push(`${indent} <tuplet${attrs}/>`);
5480
5488
  }
5481
5489
  } else if (notation.type === "dynamics") {
5482
5490
  const placementAttr = notation.placement ? ` placement="${notation.placement}"` : "";
5483
- lines.push(`${indent} <dynamics${placementAttr}>`);
5491
+ out.push(`${indent} <dynamics${placementAttr}>`);
5484
5492
  for (const dyn of notation.dynamics) {
5485
- lines.push(`${indent} <${dyn}/>`);
5493
+ out.push(`${indent} <${dyn}/>`);
5486
5494
  }
5487
5495
  if (notation.otherDynamics) {
5488
- lines.push(`${indent} <other-dynamics>${escapeXml(notation.otherDynamics)}</other-dynamics>`);
5496
+ out.push(`${indent} <other-dynamics>${escapeXml(notation.otherDynamics)}</other-dynamics>`);
5489
5497
  }
5490
- lines.push(`${indent} </dynamics>`);
5498
+ out.push(`${indent} </dynamics>`);
5491
5499
  } else if (notation.type === "fermata") {
5492
5500
  let attrs = "";
5493
5501
  if (notation.fermataType) attrs += ` type="${notation.fermataType}"`;
@@ -5495,9 +5503,9 @@ function serializeStandaloneNotation(notation, indent) {
5495
5503
  if (notation.defaultX !== void 0) attrs += ` default-x="${notation.defaultX}"`;
5496
5504
  if (notation.defaultY !== void 0) attrs += ` default-y="${notation.defaultY}"`;
5497
5505
  if (notation.shape) {
5498
- lines.push(`${indent} <fermata${attrs}>${notation.shape}</fermata>`);
5506
+ out.push(`${indent} <fermata${attrs}>${notation.shape}</fermata>`);
5499
5507
  } else {
5500
- lines.push(`${indent} <fermata${attrs}/>`);
5508
+ out.push(`${indent} <fermata${attrs}/>`);
5501
5509
  }
5502
5510
  } else if (notation.type === "arpeggiate") {
5503
5511
  let attrs = "";
@@ -5505,40 +5513,38 @@ function serializeStandaloneNotation(notation, indent) {
5505
5513
  if (notation.number !== void 0) attrs += ` number="${notation.number}"`;
5506
5514
  if (notation.defaultX !== void 0) attrs += ` default-x="${notation.defaultX}"`;
5507
5515
  if (notation.defaultY !== void 0) attrs += ` default-y="${notation.defaultY}"`;
5508
- lines.push(`${indent} <arpeggiate${attrs}/>`);
5516
+ out.push(`${indent} <arpeggiate${attrs}/>`);
5509
5517
  } else if (notation.type === "non-arpeggiate") {
5510
5518
  let attrs = ` type="${notation.nonArpeggiateType}"`;
5511
5519
  if (notation.number !== void 0) attrs += ` number="${notation.number}"`;
5512
5520
  if (notation.placement) attrs += ` placement="${notation.placement}"`;
5513
- lines.push(`${indent} <non-arpeggiate${attrs}/>`);
5521
+ out.push(`${indent} <non-arpeggiate${attrs}/>`);
5514
5522
  } else if (notation.type === "accidental-mark") {
5515
5523
  let attrs = "";
5516
5524
  if (notation.placement) attrs += ` placement="${notation.placement}"`;
5517
- lines.push(`${indent} <accidental-mark${attrs}>${escapeXml(notation.value)}</accidental-mark>`);
5525
+ out.push(`${indent} <accidental-mark${attrs}>${escapeXml(notation.value)}</accidental-mark>`);
5518
5526
  } else if (notation.type === "glissando") {
5519
5527
  let attrs = ` type="${notation.glissandoType}"`;
5520
5528
  if (notation.number !== void 0) attrs += ` number="${notation.number}"`;
5521
5529
  if (notation.lineType) attrs += ` line-type="${notation.lineType}"`;
5522
5530
  if (notation.text) {
5523
- lines.push(`${indent} <glissando${attrs}>${escapeXml(notation.text)}</glissando>`);
5531
+ out.push(`${indent} <glissando${attrs}>${escapeXml(notation.text)}</glissando>`);
5524
5532
  } else {
5525
- lines.push(`${indent} <glissando${attrs}/>`);
5533
+ out.push(`${indent} <glissando${attrs}/>`);
5526
5534
  }
5527
5535
  } else if (notation.type === "slide") {
5528
5536
  let attrs = ` type="${notation.slideType}"`;
5529
5537
  if (notation.number !== void 0) attrs += ` number="${notation.number}"`;
5530
5538
  if (notation.lineType) attrs += ` line-type="${notation.lineType}"`;
5531
5539
  if (notation.text) {
5532
- lines.push(`${indent} <slide${attrs}>${escapeXml(notation.text)}</slide>`);
5540
+ out.push(`${indent} <slide${attrs}>${escapeXml(notation.text)}</slide>`);
5533
5541
  } else {
5534
- lines.push(`${indent} <slide${attrs}/>`);
5542
+ out.push(`${indent} <slide${attrs}/>`);
5535
5543
  }
5536
5544
  }
5537
- return lines;
5538
5545
  }
5539
- function serializeArticulationsGroup(artGroup, indent) {
5540
- const lines = [];
5541
- lines.push(`${indent} <articulations>`);
5546
+ function serializeArticulationsGroup(artGroup, indent, out) {
5547
+ out.push(`${indent} <articulations>`);
5542
5548
  for (const art of artGroup) {
5543
5549
  if (art.type === "articulation") {
5544
5550
  let artAttrs = art.placement ? ` placement="${art.placement}"` : "";
@@ -5547,19 +5553,17 @@ function serializeArticulationsGroup(artGroup, indent) {
5547
5553
  }
5548
5554
  if (art.defaultX !== void 0) artAttrs += ` default-x="${art.defaultX}"`;
5549
5555
  if (art.defaultY !== void 0) artAttrs += ` default-y="${art.defaultY}"`;
5550
- lines.push(`${indent} <${art.articulation}${artAttrs}/>`);
5556
+ out.push(`${indent} <${art.articulation}${artAttrs}/>`);
5551
5557
  }
5552
5558
  }
5553
- lines.push(`${indent} </articulations>`);
5554
- return lines;
5559
+ out.push(`${indent} </articulations>`);
5555
5560
  }
5556
- function serializeOrnamentsGroup(ornaments, indent) {
5557
- const lines = [];
5561
+ function serializeOrnamentsGroup(ornaments, indent, out) {
5558
5562
  const hasOnlyEmptyMarker = ornaments.length === 1 && ornaments[0].type === "ornament" && ornaments[0].ornament === "empty";
5559
5563
  if (hasOnlyEmptyMarker) {
5560
- lines.push(`${indent} <ornaments/>`);
5564
+ out.push(`${indent} <ornaments/>`);
5561
5565
  } else {
5562
- lines.push(`${indent} <ornaments>`);
5566
+ out.push(`${indent} <ornaments>`);
5563
5567
  const allAccidentalMarks = [];
5564
5568
  for (const orn of ornaments) {
5565
5569
  if (orn.type === "ornament") {
@@ -5571,7 +5575,7 @@ function serializeOrnamentsGroup(ornaments, indent) {
5571
5575
  if (orn.number !== void 0) wlAttrs += ` number="${orn.number}"`;
5572
5576
  wlAttrs += placementAttr;
5573
5577
  if (orn.defaultY !== void 0) wlAttrs += ` default-y="${orn.defaultY}"`;
5574
- lines.push(`${indent} <wavy-line${wlAttrs}/>`);
5578
+ out.push(`${indent} <wavy-line${wlAttrs}/>`);
5575
5579
  } else if (orn.ornament === "tremolo") {
5576
5580
  let tremAttrs = "";
5577
5581
  if (orn.tremoloType) tremAttrs += ` type="${orn.tremoloType}"`;
@@ -5579,14 +5583,14 @@ function serializeOrnamentsGroup(ornaments, indent) {
5579
5583
  if (orn.defaultX !== void 0) tremAttrs += ` default-x="${orn.defaultX}"`;
5580
5584
  if (orn.defaultY !== void 0) tremAttrs += ` default-y="${orn.defaultY}"`;
5581
5585
  if (orn.tremoloMarks !== void 0) {
5582
- lines.push(`${indent} <tremolo${tremAttrs}>${orn.tremoloMarks}</tremolo>`);
5586
+ out.push(`${indent} <tremolo${tremAttrs}>${orn.tremoloMarks}</tremolo>`);
5583
5587
  } else {
5584
- lines.push(`${indent} <tremolo${tremAttrs}/>`);
5588
+ out.push(`${indent} <tremolo${tremAttrs}/>`);
5585
5589
  }
5586
5590
  } else {
5587
5591
  let ornAttrs = placementAttr;
5588
5592
  if (orn.defaultY !== void 0) ornAttrs += ` default-y="${orn.defaultY}"`;
5589
- lines.push(`${indent} <${orn.ornament}${ornAttrs}/>`);
5593
+ out.push(`${indent} <${orn.ornament}${ornAttrs}/>`);
5590
5594
  }
5591
5595
  if (orn.accidentalMarks) {
5592
5596
  allAccidentalMarks.push(...orn.accidentalMarks);
@@ -5595,15 +5599,13 @@ function serializeOrnamentsGroup(ornaments, indent) {
5595
5599
  }
5596
5600
  for (const am of allAccidentalMarks) {
5597
5601
  const amPlacement = am.placement ? ` placement="${am.placement}"` : "";
5598
- lines.push(`${indent} <accidental-mark${amPlacement}>${am.value}</accidental-mark>`);
5602
+ out.push(`${indent} <accidental-mark${amPlacement}>${am.value}</accidental-mark>`);
5599
5603
  }
5600
- lines.push(`${indent} </ornaments>`);
5604
+ out.push(`${indent} </ornaments>`);
5601
5605
  }
5602
- return lines;
5603
5606
  }
5604
- function serializeTechnicalGroup(technicals, indent) {
5605
- const lines = [];
5606
- lines.push(`${indent} <technical>`);
5607
+ function serializeTechnicalGroup(technicals, indent, out) {
5608
+ out.push(`${indent} <technical>`);
5607
5609
  for (const tech of technicals) {
5608
5610
  if (tech.type === "technical") {
5609
5611
  let placementAttr = tech.placement ? ` placement="${tech.placement}"` : "";
@@ -5611,32 +5613,32 @@ function serializeTechnicalGroup(technicals, indent) {
5611
5613
  if (techNotation.defaultX !== void 0) placementAttr += ` default-x="${techNotation.defaultX}"`;
5612
5614
  if (techNotation.defaultY !== void 0) placementAttr += ` default-y="${techNotation.defaultY}"`;
5613
5615
  if (tech.technical === "bend" && (techNotation.bendAlter !== void 0 || techNotation.preBend || techNotation.release)) {
5614
- lines.push(`${indent} <bend${placementAttr}>`);
5616
+ out.push(`${indent} <bend${placementAttr}>`);
5615
5617
  if (techNotation.bendAlter !== void 0) {
5616
- lines.push(`${indent} <bend-alter>${techNotation.bendAlter}</bend-alter>`);
5618
+ out.push(`${indent} <bend-alter>${techNotation.bendAlter}</bend-alter>`);
5617
5619
  }
5618
5620
  if (techNotation.preBend) {
5619
- lines.push(`${indent} <pre-bend/>`);
5621
+ out.push(`${indent} <pre-bend/>`);
5620
5622
  }
5621
5623
  if (techNotation.release) {
5622
- lines.push(`${indent} <release/>`);
5624
+ out.push(`${indent} <release/>`);
5623
5625
  }
5624
5626
  if (techNotation.withBar) {
5625
- lines.push(`${indent} <with-bar/>`);
5627
+ out.push(`${indent} <with-bar/>`);
5626
5628
  }
5627
- lines.push(`${indent} </bend>`);
5629
+ out.push(`${indent} </bend>`);
5628
5630
  } else if (tech.technical === "harmonic") {
5629
5631
  const hasChildren = techNotation.harmonicNatural || techNotation.harmonicArtificial || techNotation.basePitch || techNotation.touchingPitch || techNotation.soundingPitch;
5630
5632
  if (hasChildren) {
5631
- lines.push(`${indent} <harmonic${placementAttr}>`);
5632
- if (techNotation.harmonicNatural) lines.push(`${indent} <natural/>`);
5633
- if (techNotation.harmonicArtificial) lines.push(`${indent} <artificial/>`);
5634
- if (techNotation.basePitch) lines.push(`${indent} <base-pitch/>`);
5635
- if (techNotation.touchingPitch) lines.push(`${indent} <touching-pitch/>`);
5636
- if (techNotation.soundingPitch) lines.push(`${indent} <sounding-pitch/>`);
5637
- lines.push(`${indent} </harmonic>`);
5633
+ out.push(`${indent} <harmonic${placementAttr}>`);
5634
+ if (techNotation.harmonicNatural) out.push(`${indent} <natural/>`);
5635
+ if (techNotation.harmonicArtificial) out.push(`${indent} <artificial/>`);
5636
+ if (techNotation.basePitch) out.push(`${indent} <base-pitch/>`);
5637
+ if (techNotation.touchingPitch) out.push(`${indent} <touching-pitch/>`);
5638
+ if (techNotation.soundingPitch) out.push(`${indent} <sounding-pitch/>`);
5639
+ out.push(`${indent} </harmonic>`);
5638
5640
  } else {
5639
- lines.push(`${indent} <harmonic${placementAttr}/>`);
5641
+ out.push(`${indent} <harmonic${placementAttr}/>`);
5640
5642
  }
5641
5643
  } else if (tech.technical === "hammer-on" || tech.technical === "pull-off") {
5642
5644
  let attrs = "";
@@ -5644,39 +5646,37 @@ function serializeTechnicalGroup(technicals, indent) {
5644
5646
  if (techNotation.startStop) attrs += ` type="${techNotation.startStop}"`;
5645
5647
  attrs += placementAttr;
5646
5648
  if (techNotation.text !== void 0) {
5647
- lines.push(`${indent} <${tech.technical}${attrs}>${escapeXml(techNotation.text)}</${tech.technical}>`);
5649
+ out.push(`${indent} <${tech.technical}${attrs}>${escapeXml(techNotation.text)}</${tech.technical}>`);
5648
5650
  } else {
5649
- lines.push(`${indent} <${tech.technical}${attrs}/>`);
5651
+ out.push(`${indent} <${tech.technical}${attrs}/>`);
5650
5652
  }
5651
5653
  } else if (tech.technical === "string" && techNotation.string !== void 0) {
5652
- lines.push(`${indent} <string${placementAttr}>${techNotation.string}</string>`);
5654
+ out.push(`${indent} <string${placementAttr}>${techNotation.string}</string>`);
5653
5655
  } else if (tech.technical === "fret" && techNotation.fret !== void 0) {
5654
- lines.push(`${indent} <fret${placementAttr}>${techNotation.fret}</fret>`);
5656
+ out.push(`${indent} <fret${placementAttr}>${techNotation.fret}</fret>`);
5655
5657
  } else if (tech.technical === "fingering") {
5656
5658
  let fAttrs = placementAttr;
5657
5659
  if (techNotation.fingeringSubstitution) fAttrs += ' substitution="yes"';
5658
5660
  if (techNotation.fingeringAlternate) fAttrs += ' alternate="yes"';
5659
5661
  if (techNotation.text !== void 0) {
5660
- lines.push(`${indent} <fingering${fAttrs}>${escapeXml(techNotation.text)}</fingering>`);
5662
+ out.push(`${indent} <fingering${fAttrs}>${escapeXml(techNotation.text)}</fingering>`);
5661
5663
  } else {
5662
- lines.push(`${indent} <fingering${fAttrs}/>`);
5664
+ out.push(`${indent} <fingering${fAttrs}/>`);
5663
5665
  }
5664
5666
  } else if (tech.technical === "heel" || tech.technical === "toe") {
5665
5667
  let htAttrs = placementAttr;
5666
5668
  if (techNotation.substitution) htAttrs += ' substitution="yes"';
5667
- lines.push(`${indent} <${tech.technical}${htAttrs}/>`);
5669
+ out.push(`${indent} <${tech.technical}${htAttrs}/>`);
5668
5670
  } else if (techNotation.text !== void 0) {
5669
- lines.push(`${indent} <${tech.technical}${placementAttr}>${escapeXml(techNotation.text)}</${tech.technical}>`);
5671
+ out.push(`${indent} <${tech.technical}${placementAttr}>${escapeXml(techNotation.text)}</${tech.technical}>`);
5670
5672
  } else {
5671
- lines.push(`${indent} <${tech.technical}${placementAttr}/>`);
5673
+ out.push(`${indent} <${tech.technical}${placementAttr}/>`);
5672
5674
  }
5673
5675
  }
5674
5676
  }
5675
- lines.push(`${indent} </technical>`);
5676
- return lines;
5677
+ out.push(`${indent} </technical>`);
5677
5678
  }
5678
- function serializeLyric(lyric, indent) {
5679
- const lines = [];
5679
+ function serializeLyric(lyric, indent, out) {
5680
5680
  let attrs = "";
5681
5681
  if (lyric.number) attrs += ` number="${lyric.number}"`;
5682
5682
  if (lyric.name) attrs += ` name="${escapeXml(lyric.name)}"`;
@@ -5684,78 +5684,72 @@ function serializeLyric(lyric, indent) {
5684
5684
  if (lyric.relativeX !== void 0) attrs += ` relative-x="${lyric.relativeX}"`;
5685
5685
  if (lyric.justify) attrs += ` justify="${escapeXml(lyric.justify)}"`;
5686
5686
  if (lyric.placement) attrs += ` placement="${lyric.placement}"`;
5687
- lines.push(`${indent}<lyric${attrs}>`);
5687
+ out.push(`${indent}<lyric${attrs}>`);
5688
5688
  if (lyric.textElements && lyric.textElements.length > 1) {
5689
5689
  for (let i = 0; i < lyric.textElements.length; i++) {
5690
5690
  const te = lyric.textElements[i];
5691
5691
  if (te.syllabic) {
5692
- lines.push(`${indent} <syllabic>${te.syllabic}</syllabic>`);
5692
+ out.push(`${indent} <syllabic>${te.syllabic}</syllabic>`);
5693
5693
  }
5694
- lines.push(`${indent} <text>${escapeXml(te.text)}</text>`);
5694
+ out.push(`${indent} <text>${escapeXml(te.text)}</text>`);
5695
5695
  if (i < lyric.textElements.length - 1) {
5696
- lines.push(`${indent} <elision/>`);
5696
+ out.push(`${indent} <elision/>`);
5697
5697
  }
5698
5698
  }
5699
5699
  } else if (lyric.syllabic || lyric.text) {
5700
5700
  if (lyric.syllabic) {
5701
- lines.push(`${indent} <syllabic>${lyric.syllabic}</syllabic>`);
5701
+ out.push(`${indent} <syllabic>${lyric.syllabic}</syllabic>`);
5702
5702
  }
5703
- lines.push(`${indent} <text>${escapeXml(lyric.text)}</text>`);
5703
+ out.push(`${indent} <text>${escapeXml(lyric.text)}</text>`);
5704
5704
  }
5705
5705
  if (lyric.extend) {
5706
5706
  if (typeof lyric.extend === "object" && lyric.extend.type) {
5707
- lines.push(`${indent} <extend type="${lyric.extend.type}"/>`);
5707
+ out.push(`${indent} <extend type="${lyric.extend.type}"/>`);
5708
5708
  } else {
5709
- lines.push(`${indent} <extend/>`);
5709
+ out.push(`${indent} <extend/>`);
5710
5710
  }
5711
5711
  }
5712
5712
  if (lyric.endLine) {
5713
- lines.push(`${indent} <end-line/>`);
5713
+ out.push(`${indent} <end-line/>`);
5714
5714
  }
5715
5715
  if (lyric.endParagraph) {
5716
- lines.push(`${indent} <end-paragraph/>`);
5716
+ out.push(`${indent} <end-paragraph/>`);
5717
5717
  }
5718
- lines.push(`${indent}</lyric>`);
5719
- return lines;
5718
+ out.push(`${indent}</lyric>`);
5720
5719
  }
5721
- function serializeBackup(backup, indent) {
5722
- return [
5723
- `${indent}<backup>`,
5724
- `${indent} <duration>${backup.duration}</duration>`,
5725
- `${indent}</backup>`
5726
- ];
5720
+ function serializeBackup(backup, indent, out) {
5721
+ out.push(`${indent}<backup>`);
5722
+ out.push(`${indent} <duration>${backup.duration}</duration>`);
5723
+ out.push(`${indent}</backup>`);
5727
5724
  }
5728
- function serializeForward(forward, indent) {
5729
- const lines = [];
5725
+ function serializeForward(forward, indent, out) {
5730
5726
  const idAttr = forward._id ? ` id="${escapeXml(forward._id)}"` : "";
5731
- lines.push(`${indent}<forward${idAttr}>`);
5732
- lines.push(`${indent} <duration>${forward.duration}</duration>`);
5727
+ out.push(`${indent}<forward${idAttr}>`);
5728
+ out.push(`${indent} <duration>${forward.duration}</duration>`);
5733
5729
  if (forward.voice !== void 0) {
5734
- lines.push(`${indent} <voice>${forward.voice}</voice>`);
5730
+ out.push(`${indent} <voice>${forward.voice}</voice>`);
5735
5731
  }
5736
5732
  if (forward.staff !== void 0) {
5737
- lines.push(`${indent} <staff>${forward.staff}</staff>`);
5733
+ out.push(`${indent} <staff>${forward.staff}</staff>`);
5738
5734
  }
5739
- lines.push(`${indent}</forward>`);
5740
- return lines;
5735
+ out.push(`${indent}</forward>`);
5741
5736
  }
5742
- function serializeDirection(direction, indent) {
5743
- const lines = [];
5737
+ function serializeDirection(direction, indent, out) {
5744
5738
  let attrs = "";
5745
5739
  if (direction._id) attrs += ` id="${escapeXml(direction._id)}"`;
5746
5740
  if (direction.placement) attrs += ` placement="${direction.placement}"`;
5747
5741
  if (direction.directive) attrs += ' directive="yes"';
5748
5742
  if (direction.system) attrs += ` system="${direction.system}"`;
5749
- lines.push(`${indent}<direction${attrs}>`);
5743
+ out.push(`${indent}<direction${attrs}>`);
5750
5744
  for (const dirType of direction.directionTypes) {
5751
- lines.push(...serializeDirectionType(dirType, indent + " "));
5745
+ serializeDirectionType(dirType, indent + " ", out);
5752
5746
  }
5753
5747
  if (direction.offset !== void 0) {
5754
5748
  const soundAttr = direction.offsetSound ? ' sound="yes"' : "";
5755
- lines.push(`${indent} <offset${soundAttr}>${direction.offset}</offset>`);
5749
+ out.push(`${indent} <offset${soundAttr}>${direction.offset}</offset>`);
5756
5750
  }
5757
5751
  if (direction.staff !== void 0) {
5758
- lines.push(`${indent} <staff>${direction.staff}</staff>`);
5752
+ out.push(`${indent} <staff>${direction.staff}</staff>`);
5759
5753
  }
5760
5754
  if (direction.sound) {
5761
5755
  const attrs2 = [];
@@ -5776,33 +5770,31 @@ function serializeDirection(direction, indent) {
5776
5770
  }
5777
5771
  const attrStr = attrs2.length > 0 ? ` ${attrs2.join(" ")}` : "";
5778
5772
  if (direction.sound.midiInstrument) {
5779
- lines.push(`${indent} <sound${attrStr}>`);
5773
+ out.push(`${indent} <sound${attrStr}>`);
5780
5774
  const midi = direction.sound.midiInstrument;
5781
- lines.push(`${indent} <midi-instrument id="${escapeXml(midi.id)}">`);
5775
+ out.push(`${indent} <midi-instrument id="${escapeXml(midi.id)}">`);
5782
5776
  if (midi.midiChannel !== void 0) {
5783
- lines.push(`${indent} <midi-channel>${midi.midiChannel}</midi-channel>`);
5777
+ out.push(`${indent} <midi-channel>${midi.midiChannel}</midi-channel>`);
5784
5778
  }
5785
5779
  if (midi.midiProgram !== void 0) {
5786
- lines.push(`${indent} <midi-program>${midi.midiProgram}</midi-program>`);
5780
+ out.push(`${indent} <midi-program>${midi.midiProgram}</midi-program>`);
5787
5781
  }
5788
5782
  if (midi.volume !== void 0) {
5789
- lines.push(`${indent} <volume>${midi.volume}</volume>`);
5783
+ out.push(`${indent} <volume>${midi.volume}</volume>`);
5790
5784
  }
5791
5785
  if (midi.pan !== void 0) {
5792
- lines.push(`${indent} <pan>${midi.pan}</pan>`);
5786
+ out.push(`${indent} <pan>${midi.pan}</pan>`);
5793
5787
  }
5794
- lines.push(`${indent} </midi-instrument>`);
5795
- lines.push(`${indent} </sound>`);
5788
+ out.push(`${indent} </midi-instrument>`);
5789
+ out.push(`${indent} </sound>`);
5796
5790
  } else if (attrs2.length > 0) {
5797
- lines.push(`${indent} <sound${attrStr}/>`);
5791
+ out.push(`${indent} <sound${attrStr}/>`);
5798
5792
  }
5799
5793
  }
5800
- lines.push(`${indent}</direction>`);
5801
- return lines;
5794
+ out.push(`${indent}</direction>`);
5802
5795
  }
5803
- function serializeDirectionType(dirType, indent) {
5804
- const lines = [];
5805
- lines.push(`${indent}<direction-type>`);
5796
+ function serializeDirectionType(dirType, indent, out) {
5797
+ out.push(`${indent}<direction-type>`);
5806
5798
  switch (dirType.kind) {
5807
5799
  case "dynamics": {
5808
5800
  let dynAttrs = "";
@@ -5810,14 +5802,14 @@ function serializeDirectionType(dirType, indent) {
5810
5802
  if (dirType.defaultY !== void 0) dynAttrs += ` default-y="${dirType.defaultY}"`;
5811
5803
  if (dirType.relativeX !== void 0) dynAttrs += ` relative-x="${dirType.relativeX}"`;
5812
5804
  if (dirType.halign) dynAttrs += ` halign="${dirType.halign}"`;
5813
- lines.push(`${indent} <dynamics${dynAttrs}>`);
5805
+ out.push(`${indent} <dynamics${dynAttrs}>`);
5814
5806
  if (dirType.value) {
5815
- lines.push(`${indent} <${dirType.value}/>`);
5807
+ out.push(`${indent} <${dirType.value}/>`);
5816
5808
  }
5817
5809
  if (dirType.otherDynamics) {
5818
- lines.push(`${indent} <other-dynamics>${escapeXml(dirType.otherDynamics)}</other-dynamics>`);
5810
+ out.push(`${indent} <other-dynamics>${escapeXml(dirType.otherDynamics)}</other-dynamics>`);
5819
5811
  }
5820
- lines.push(`${indent} </dynamics>`);
5812
+ out.push(`${indent} </dynamics>`);
5821
5813
  break;
5822
5814
  }
5823
5815
  case "wedge": {
@@ -5825,7 +5817,7 @@ function serializeDirectionType(dirType, indent) {
5825
5817
  if (dirType.spread !== void 0) wedgeAttrs += ` spread="${dirType.spread}"`;
5826
5818
  if (dirType.defaultY !== void 0) wedgeAttrs += ` default-y="${dirType.defaultY}"`;
5827
5819
  if (dirType.relativeX !== void 0) wedgeAttrs += ` relative-x="${dirType.relativeX}"`;
5828
- lines.push(`${indent} <wedge${wedgeAttrs}/>`);
5820
+ out.push(`${indent} <wedge${wedgeAttrs}/>`);
5829
5821
  break;
5830
5822
  }
5831
5823
  case "metronome": {
@@ -5835,21 +5827,21 @@ function serializeDirectionType(dirType, indent) {
5835
5827
  if (dirType.defaultY !== void 0) metAttrs += ` default-y="${dirType.defaultY}"`;
5836
5828
  if (dirType.fontFamily) metAttrs += ` font-family="${escapeXml(dirType.fontFamily)}"`;
5837
5829
  if (dirType.fontSize) metAttrs += ` font-size="${escapeXml(dirType.fontSize)}"`;
5838
- lines.push(`${indent} <metronome${metAttrs}>`);
5839
- lines.push(`${indent} <beat-unit>${dirType.beatUnit}</beat-unit>`);
5830
+ out.push(`${indent} <metronome${metAttrs}>`);
5831
+ out.push(`${indent} <beat-unit>${dirType.beatUnit}</beat-unit>`);
5840
5832
  if (dirType.beatUnitDot) {
5841
- lines.push(`${indent} <beat-unit-dot/>`);
5833
+ out.push(`${indent} <beat-unit-dot/>`);
5842
5834
  }
5843
5835
  if (dirType.beatUnit2) {
5844
- lines.push(`${indent} <beat-unit>${dirType.beatUnit2}</beat-unit>`);
5836
+ out.push(`${indent} <beat-unit>${dirType.beatUnit2}</beat-unit>`);
5845
5837
  if (dirType.beatUnitDot2) {
5846
- lines.push(`${indent} <beat-unit-dot/>`);
5838
+ out.push(`${indent} <beat-unit-dot/>`);
5847
5839
  }
5848
5840
  }
5849
5841
  if (dirType.perMinute !== void 0) {
5850
- lines.push(`${indent} <per-minute>${dirType.perMinute}</per-minute>`);
5842
+ out.push(`${indent} <per-minute>${dirType.perMinute}</per-minute>`);
5851
5843
  }
5852
- lines.push(`${indent} </metronome>`);
5844
+ out.push(`${indent} </metronome>`);
5853
5845
  break;
5854
5846
  }
5855
5847
  case "words": {
@@ -5867,7 +5859,7 @@ function serializeDirectionType(dirType, indent) {
5867
5859
  if (dirType.color) wordAttrs += ` color="${escapeXml(dirType.color)}"`;
5868
5860
  if (dirType.xmlSpace) wordAttrs += ` xml:space="${escapeXml(dirType.xmlSpace)}"`;
5869
5861
  if (dirType.halign) wordAttrs += ` halign="${escapeXml(dirType.halign)}"`;
5870
- lines.push(`${indent} <words${wordAttrs}>${escapeXml(dirType.text)}</words>`);
5862
+ out.push(`${indent} <words${wordAttrs}>${escapeXml(dirType.text)}</words>`);
5871
5863
  break;
5872
5864
  }
5873
5865
  case "rehearsal": {
@@ -5877,7 +5869,7 @@ function serializeDirectionType(dirType, indent) {
5877
5869
  if (dirType.defaultY !== void 0) rehAttrs += ` default-y="${dirType.defaultY}"`;
5878
5870
  if (dirType.fontSize) rehAttrs += ` font-size="${escapeXml(dirType.fontSize)}"`;
5879
5871
  if (dirType.fontWeight) rehAttrs += ` font-weight="${escapeXml(dirType.fontWeight)}"`;
5880
- lines.push(`${indent} <rehearsal${rehAttrs}>${escapeXml(dirType.text)}</rehearsal>`);
5872
+ out.push(`${indent} <rehearsal${rehAttrs}>${escapeXml(dirType.text)}</rehearsal>`);
5881
5873
  break;
5882
5874
  }
5883
5875
  case "bracket": {
@@ -5887,7 +5879,7 @@ function serializeDirectionType(dirType, indent) {
5887
5879
  if (dirType.lineType) bracketAttrs += ` line-type="${dirType.lineType}"`;
5888
5880
  if (dirType.defaultY !== void 0) bracketAttrs += ` default-y="${dirType.defaultY}"`;
5889
5881
  if (dirType.relativeX !== void 0) bracketAttrs += ` relative-x="${dirType.relativeX}"`;
5890
- lines.push(`${indent} <bracket${bracketAttrs}/>`);
5882
+ out.push(`${indent} <bracket${bracketAttrs}/>`);
5891
5883
  break;
5892
5884
  }
5893
5885
  case "dashes": {
@@ -5896,25 +5888,25 @@ function serializeDirectionType(dirType, indent) {
5896
5888
  if (dirType.dashLength !== void 0) dashAttrs += ` dash-length="${dirType.dashLength}"`;
5897
5889
  if (dirType.defaultY !== void 0) dashAttrs += ` default-y="${dirType.defaultY}"`;
5898
5890
  if (dirType.spaceLength !== void 0) dashAttrs += ` space-length="${dirType.spaceLength}"`;
5899
- lines.push(`${indent} <dashes${dashAttrs}/>`);
5891
+ out.push(`${indent} <dashes${dashAttrs}/>`);
5900
5892
  break;
5901
5893
  }
5902
5894
  case "accordion-registration":
5903
- lines.push(`${indent} <accordion-registration>`);
5895
+ out.push(`${indent} <accordion-registration>`);
5904
5896
  if (dirType.high) {
5905
- lines.push(`${indent} <accordion-high/>`);
5897
+ out.push(`${indent} <accordion-high/>`);
5906
5898
  }
5907
5899
  if (dirType.middlePresent || dirType.middle !== void 0) {
5908
5900
  if (dirType.middle !== void 0) {
5909
- lines.push(`${indent} <accordion-middle>${dirType.middle}</accordion-middle>`);
5901
+ out.push(`${indent} <accordion-middle>${dirType.middle}</accordion-middle>`);
5910
5902
  } else {
5911
- lines.push(`${indent} <accordion-middle/>`);
5903
+ out.push(`${indent} <accordion-middle/>`);
5912
5904
  }
5913
5905
  }
5914
5906
  if (dirType.low) {
5915
- lines.push(`${indent} <accordion-low/>`);
5907
+ out.push(`${indent} <accordion-low/>`);
5916
5908
  }
5917
- lines.push(`${indent} </accordion-registration>`);
5909
+ out.push(`${indent} </accordion-registration>`);
5918
5910
  break;
5919
5911
  case "other-direction":
5920
5912
  {
@@ -5923,60 +5915,60 @@ function serializeDirectionType(dirType, indent) {
5923
5915
  if (dirType.defaultY !== void 0) otherAttrs += ` default-y="${dirType.defaultY}"`;
5924
5916
  if (dirType.halign) otherAttrs += ` halign="${escapeXml(dirType.halign)}"`;
5925
5917
  if (dirType.printObject === false) otherAttrs += ' print-object="no"';
5926
- lines.push(`${indent} <other-direction${otherAttrs}>${escapeXml(dirType.text)}</other-direction>`);
5918
+ out.push(`${indent} <other-direction${otherAttrs}>${escapeXml(dirType.text)}</other-direction>`);
5927
5919
  }
5928
5920
  break;
5929
5921
  case "segno":
5930
- lines.push(`${indent} <segno/>`);
5922
+ out.push(`${indent} <segno/>`);
5931
5923
  break;
5932
5924
  case "coda":
5933
- lines.push(`${indent} <coda/>`);
5925
+ out.push(`${indent} <coda/>`);
5934
5926
  break;
5935
5927
  case "eyeglasses":
5936
- lines.push(`${indent} <eyeglasses/>`);
5928
+ out.push(`${indent} <eyeglasses/>`);
5937
5929
  break;
5938
5930
  case "damp":
5939
- lines.push(`${indent} <damp/>`);
5931
+ out.push(`${indent} <damp/>`);
5940
5932
  break;
5941
5933
  case "damp-all":
5942
- lines.push(`${indent} <damp-all/>`);
5934
+ out.push(`${indent} <damp-all/>`);
5943
5935
  break;
5944
5936
  case "scordatura":
5945
5937
  if (dirType.accords && dirType.accords.length > 0) {
5946
- lines.push(`${indent} <scordatura>`);
5938
+ out.push(`${indent} <scordatura>`);
5947
5939
  for (const accord of dirType.accords) {
5948
- lines.push(`${indent} <accord string="${accord.string}">`);
5949
- lines.push(`${indent} <tuning-step>${accord.tuningStep}</tuning-step>`);
5940
+ out.push(`${indent} <accord string="${accord.string}">`);
5941
+ out.push(`${indent} <tuning-step>${accord.tuningStep}</tuning-step>`);
5950
5942
  if (accord.tuningAlter !== void 0) {
5951
- lines.push(`${indent} <tuning-alter>${accord.tuningAlter}</tuning-alter>`);
5943
+ out.push(`${indent} <tuning-alter>${accord.tuningAlter}</tuning-alter>`);
5952
5944
  }
5953
- lines.push(`${indent} <tuning-octave>${accord.tuningOctave}</tuning-octave>`);
5954
- lines.push(`${indent} </accord>`);
5945
+ out.push(`${indent} <tuning-octave>${accord.tuningOctave}</tuning-octave>`);
5946
+ out.push(`${indent} </accord>`);
5955
5947
  }
5956
- lines.push(`${indent} </scordatura>`);
5948
+ out.push(`${indent} </scordatura>`);
5957
5949
  } else {
5958
- lines.push(`${indent} <scordatura/>`);
5950
+ out.push(`${indent} <scordatura/>`);
5959
5951
  }
5960
5952
  break;
5961
5953
  case "harp-pedals":
5962
5954
  if (dirType.pedalTunings && dirType.pedalTunings.length > 0) {
5963
- lines.push(`${indent} <harp-pedals>`);
5955
+ out.push(`${indent} <harp-pedals>`);
5964
5956
  for (const pt of dirType.pedalTunings) {
5965
- lines.push(`${indent} <pedal-tuning>`);
5966
- lines.push(`${indent} <pedal-step>${pt.pedalStep}</pedal-step>`);
5967
- lines.push(`${indent} <pedal-alter>${pt.pedalAlter}</pedal-alter>`);
5968
- lines.push(`${indent} </pedal-tuning>`);
5957
+ out.push(`${indent} <pedal-tuning>`);
5958
+ out.push(`${indent} <pedal-step>${pt.pedalStep}</pedal-step>`);
5959
+ out.push(`${indent} <pedal-alter>${pt.pedalAlter}</pedal-alter>`);
5960
+ out.push(`${indent} </pedal-tuning>`);
5969
5961
  }
5970
- lines.push(`${indent} </harp-pedals>`);
5962
+ out.push(`${indent} </harp-pedals>`);
5971
5963
  } else {
5972
- lines.push(`${indent} <harp-pedals/>`);
5964
+ out.push(`${indent} <harp-pedals/>`);
5973
5965
  }
5974
5966
  break;
5975
5967
  case "image":
5976
5968
  let imgAttrs = "";
5977
5969
  if (dirType.source) imgAttrs += ` source="${escapeXml(dirType.source)}"`;
5978
5970
  if (dirType.type) imgAttrs += ` type="${escapeXml(dirType.type)}"`;
5979
- lines.push(`${indent} <image${imgAttrs}/>`);
5971
+ out.push(`${indent} <image${imgAttrs}/>`);
5980
5972
  break;
5981
5973
  case "pedal": {
5982
5974
  let pedalAttrs = ` type="${dirType.type}"`;
@@ -5984,68 +5976,76 @@ function serializeDirectionType(dirType, indent) {
5984
5976
  if (dirType.defaultY !== void 0) pedalAttrs += ` default-y="${dirType.defaultY}"`;
5985
5977
  if (dirType.relativeX !== void 0) pedalAttrs += ` relative-x="${dirType.relativeX}"`;
5986
5978
  if (dirType.halign) pedalAttrs += ` halign="${dirType.halign}"`;
5987
- lines.push(`${indent} <pedal${pedalAttrs}/>`);
5979
+ out.push(`${indent} <pedal${pedalAttrs}/>`);
5988
5980
  break;
5989
5981
  }
5990
5982
  case "octave-shift": {
5991
5983
  const sizeAttr = dirType.size !== void 0 ? ` size="${dirType.size}"` : "";
5992
- lines.push(`${indent} <octave-shift type="${dirType.type}"${sizeAttr}/>`);
5984
+ out.push(`${indent} <octave-shift type="${dirType.type}"${sizeAttr}/>`);
5993
5985
  break;
5994
5986
  }
5995
5987
  case "swing":
5996
- lines.push(`${indent} <swing>`);
5988
+ out.push(`${indent} <swing>`);
5997
5989
  if (dirType.straight) {
5998
- lines.push(`${indent} <straight/>`);
5990
+ out.push(`${indent} <straight/>`);
5999
5991
  } else {
6000
5992
  if (dirType.first !== void 0) {
6001
- lines.push(`${indent} <first>${dirType.first}</first>`);
5993
+ out.push(`${indent} <first>${dirType.first}</first>`);
6002
5994
  }
6003
5995
  if (dirType.second !== void 0) {
6004
- lines.push(`${indent} <second>${dirType.second}</second>`);
5996
+ out.push(`${indent} <second>${dirType.second}</second>`);
6005
5997
  }
6006
5998
  if (dirType.swingType) {
6007
- lines.push(`${indent} <swing-type>${dirType.swingType}</swing-type>`);
5999
+ out.push(`${indent} <swing-type>${dirType.swingType}</swing-type>`);
6008
6000
  }
6009
6001
  }
6010
- lines.push(`${indent} </swing>`);
6002
+ out.push(`${indent} </swing>`);
6011
6003
  break;
6012
6004
  }
6013
- lines.push(`${indent}</direction-type>`);
6014
- return lines;
6005
+ out.push(`${indent}</direction-type>`);
6015
6006
  }
6016
- function serializeBarline(barline, indent) {
6017
- const lines = [];
6007
+ function serializeBarline(barline, indent, out) {
6018
6008
  let attrs = ` location="${barline.location}"`;
6019
6009
  if (barline._id) attrs += ` id="${escapeXml(barline._id)}"`;
6020
- lines.push(`${indent}<barline${attrs}>`);
6010
+ out.push(`${indent}<barline${attrs}>`);
6021
6011
  if (barline.barStyle) {
6022
- lines.push(`${indent} <bar-style>${barline.barStyle}</bar-style>`);
6012
+ out.push(`${indent} <bar-style>${barline.barStyle}</bar-style>`);
6023
6013
  }
6024
6014
  if (barline.ending) {
6025
6015
  let endingAttrs = ` number="${barline.ending.number}" type="${barline.ending.type}"`;
6026
6016
  if (barline.ending.defaultY !== void 0) endingAttrs += ` default-y="${barline.ending.defaultY}"`;
6027
6017
  if (barline.ending.endLength !== void 0) endingAttrs += ` end-length="${barline.ending.endLength}"`;
6028
6018
  if (barline.ending.text) {
6029
- lines.push(`${indent} <ending${endingAttrs}>${escapeXml(barline.ending.text)}</ending>`);
6019
+ out.push(`${indent} <ending${endingAttrs}>${escapeXml(barline.ending.text)}</ending>`);
6030
6020
  } else {
6031
- lines.push(`${indent} <ending${endingAttrs}/>`);
6021
+ out.push(`${indent} <ending${endingAttrs}/>`);
6032
6022
  }
6033
6023
  }
6034
6024
  if (barline.repeat) {
6035
6025
  let repeatAttrs = ` direction="${barline.repeat.direction}"`;
6036
6026
  if (barline.repeat.times !== void 0) repeatAttrs += ` times="${barline.repeat.times}"`;
6037
6027
  if (barline.repeat.winged) repeatAttrs += ` winged="${barline.repeat.winged}"`;
6038
- lines.push(`${indent} <repeat${repeatAttrs}/>`);
6028
+ out.push(`${indent} <repeat${repeatAttrs}/>`);
6039
6029
  }
6040
- lines.push(`${indent}</barline>`);
6041
- return lines;
6030
+ out.push(`${indent}</barline>`);
6042
6031
  }
6032
+ var XML_ESCAPE_RE = /[&<>"']/g;
6033
+ var XML_ESCAPE_MAP = {
6034
+ "&": "&amp;",
6035
+ "<": "&lt;",
6036
+ ">": "&gt;",
6037
+ '"': "&quot;",
6038
+ "'": "&apos;"
6039
+ };
6040
+ var XML_ESCAPE_TEST = /[&<>"']/;
6043
6041
  function escapeXml(str) {
6044
- return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
6042
+ if (!XML_ESCAPE_TEST.test(str)) return str;
6043
+ return str.replace(XML_ESCAPE_RE, (ch) => XML_ESCAPE_MAP[ch]);
6045
6044
  }
6046
6045
  function buildAttrs(attrs) {
6047
6046
  let result = "";
6048
- for (const [key, value] of Object.entries(attrs)) {
6047
+ for (const key in attrs) {
6048
+ const value = attrs[key];
6049
6049
  if (value === void 0) continue;
6050
6050
  if (typeof value === "boolean") {
6051
6051
  result += ` ${key}="${value ? "yes" : "no"}"`;
@@ -6063,48 +6063,45 @@ function pushOptionalElement(lines, indent, tag, value) {
6063
6063
  lines.push(`${indent}<${tag}>${escaped}</${tag}>`);
6064
6064
  }
6065
6065
  }
6066
- function serializeStaffDetails(sd, indent) {
6067
- const lines = [];
6066
+ function serializeStaffDetails(sd, indent, out) {
6068
6067
  const attrs = buildAttrs({
6069
6068
  "number": sd.number,
6070
6069
  "show-frets": sd.showFrets,
6071
6070
  "print-object": sd.printObject,
6072
6071
  "print-spacing": sd.printSpacing
6073
6072
  });
6074
- lines.push(`${indent}<staff-details${attrs}>`);
6075
- pushOptionalElement(lines, `${indent} `, "staff-type", sd.staffType);
6076
- pushOptionalElement(lines, `${indent} `, "staff-lines", sd.staffLines);
6073
+ out.push(`${indent}<staff-details${attrs}>`);
6074
+ pushOptionalElement(out, `${indent} `, "staff-type", sd.staffType);
6075
+ pushOptionalElement(out, `${indent} `, "staff-lines", sd.staffLines);
6077
6076
  if (sd.staffTuning) {
6078
6077
  for (const tuning of sd.staffTuning) {
6079
- lines.push(`${indent} <staff-tuning${buildAttrs({ line: tuning.line })}>`);
6080
- lines.push(`${indent} <tuning-step>${tuning.tuningStep}</tuning-step>`);
6081
- pushOptionalElement(lines, `${indent} `, "tuning-alter", tuning.tuningAlter);
6082
- lines.push(`${indent} <tuning-octave>${tuning.tuningOctave}</tuning-octave>`);
6083
- lines.push(`${indent} </staff-tuning>`);
6078
+ out.push(`${indent} <staff-tuning${buildAttrs({ line: tuning.line })}>`);
6079
+ out.push(`${indent} <tuning-step>${tuning.tuningStep}</tuning-step>`);
6080
+ pushOptionalElement(out, `${indent} `, "tuning-alter", tuning.tuningAlter);
6081
+ out.push(`${indent} <tuning-octave>${tuning.tuningOctave}</tuning-octave>`);
6082
+ out.push(`${indent} </staff-tuning>`);
6084
6083
  }
6085
6084
  }
6086
- pushOptionalElement(lines, `${indent} `, "capo", sd.capo);
6085
+ pushOptionalElement(out, `${indent} `, "capo", sd.capo);
6087
6086
  if (sd.staffSize !== void 0) {
6088
6087
  const attrs2 = buildAttrs({ scaling: sd.staffSizeScaling });
6089
- lines.push(`${indent} <staff-size${attrs2}>${sd.staffSize}</staff-size>`);
6088
+ out.push(`${indent} <staff-size${attrs2}>${sd.staffSize}</staff-size>`);
6090
6089
  }
6091
- lines.push(`${indent}</staff-details>`);
6092
- return lines;
6090
+ out.push(`${indent}</staff-details>`);
6093
6091
  }
6094
- function serializeMeasureStyle(ms, indent) {
6095
- const lines = [];
6096
- lines.push(`${indent}<measure-style${buildAttrs({ number: ms.number })}>`);
6097
- pushOptionalElement(lines, `${indent} `, "multiple-rest", ms.multipleRest);
6092
+ function serializeMeasureStyle(ms, indent, out) {
6093
+ out.push(`${indent}<measure-style${buildAttrs({ number: ms.number })}>`);
6094
+ pushOptionalElement(out, `${indent} `, "multiple-rest", ms.multipleRest);
6098
6095
  if (ms.measureRepeat) {
6099
6096
  const mrAttrs = buildAttrs({
6100
6097
  type: ms.measureRepeat.type,
6101
6098
  slashes: ms.measureRepeat.slashes
6102
6099
  });
6103
- lines.push(`${indent} <measure-repeat${mrAttrs}/>`);
6100
+ out.push(`${indent} <measure-repeat${mrAttrs}/>`);
6104
6101
  }
6105
6102
  if (ms.beatRepeat) {
6106
6103
  const brAttrs = buildAttrs({ type: ms.beatRepeat.type, slashes: ms.beatRepeat.slashes });
6107
- lines.push(`${indent} <beat-repeat${brAttrs}/>`);
6104
+ out.push(`${indent} <beat-repeat${brAttrs}/>`);
6108
6105
  }
6109
6106
  if (ms.slash) {
6110
6107
  const slAttrs = buildAttrs({
@@ -6112,13 +6109,11 @@ function serializeMeasureStyle(ms, indent) {
6112
6109
  "use-dots": ms.slash.useDots,
6113
6110
  "use-stems": ms.slash.useStems
6114
6111
  });
6115
- lines.push(`${indent} <slash${slAttrs}/>`);
6112
+ out.push(`${indent} <slash${slAttrs}/>`);
6116
6113
  }
6117
- lines.push(`${indent}</measure-style>`);
6118
- return lines;
6114
+ out.push(`${indent}</measure-style>`);
6119
6115
  }
6120
- function serializeHarmony(harmony, indent) {
6121
- const lines = [];
6116
+ function serializeHarmony(harmony, indent, out) {
6122
6117
  const attrs = buildAttrs({
6123
6118
  id: harmony._id,
6124
6119
  placement: harmony.placement,
@@ -6127,114 +6122,110 @@ function serializeHarmony(harmony, indent) {
6127
6122
  halign: harmony.halign,
6128
6123
  "font-size": harmony.fontSize
6129
6124
  });
6130
- lines.push(`${indent}<harmony${attrs}>`);
6131
- lines.push(`${indent} <root>`);
6132
- lines.push(`${indent} <root-step>${harmony.root.rootStep}</root-step>`);
6125
+ out.push(`${indent}<harmony${attrs}>`);
6126
+ out.push(`${indent} <root>`);
6127
+ out.push(`${indent} <root-step>${harmony.root.rootStep}</root-step>`);
6133
6128
  if (harmony.root.rootAlter !== void 0) {
6134
- lines.push(`${indent} <root-alter>${harmony.root.rootAlter}</root-alter>`);
6129
+ out.push(`${indent} <root-alter>${harmony.root.rootAlter}</root-alter>`);
6135
6130
  }
6136
- lines.push(`${indent} </root>`);
6131
+ out.push(`${indent} </root>`);
6137
6132
  let kindAttrs = "";
6138
6133
  if (harmony.kindText !== void 0) kindAttrs += ` text="${escapeXml(harmony.kindText)}"`;
6139
6134
  if (harmony.kindHalign) kindAttrs += ` halign="${escapeXml(harmony.kindHalign)}"`;
6140
- lines.push(`${indent} <kind${kindAttrs}>${escapeXml(harmony.kind)}</kind>`);
6135
+ out.push(`${indent} <kind${kindAttrs}>${escapeXml(harmony.kind)}</kind>`);
6141
6136
  if (harmony.bass) {
6142
6137
  let bassAttrs = "";
6143
6138
  if (harmony.bass.arrangement) bassAttrs += ` arrangement="${escapeXml(harmony.bass.arrangement)}"`;
6144
- lines.push(`${indent} <bass${bassAttrs}>`);
6145
- lines.push(`${indent} <bass-step>${harmony.bass.bassStep}</bass-step>`);
6139
+ out.push(`${indent} <bass${bassAttrs}>`);
6140
+ out.push(`${indent} <bass-step>${harmony.bass.bassStep}</bass-step>`);
6146
6141
  if (harmony.bass.bassAlter !== void 0) {
6147
- lines.push(`${indent} <bass-alter>${harmony.bass.bassAlter}</bass-alter>`);
6142
+ out.push(`${indent} <bass-alter>${harmony.bass.bassAlter}</bass-alter>`);
6148
6143
  }
6149
- lines.push(`${indent} </bass>`);
6144
+ out.push(`${indent} </bass>`);
6150
6145
  }
6151
6146
  if (harmony.inversion !== void 0) {
6152
- lines.push(`${indent} <inversion>${harmony.inversion}</inversion>`);
6147
+ out.push(`${indent} <inversion>${harmony.inversion}</inversion>`);
6153
6148
  }
6154
6149
  if (harmony.degrees) {
6155
6150
  for (const deg of harmony.degrees) {
6156
- lines.push(`${indent} <degree>`);
6157
- lines.push(`${indent} <degree-value>${deg.degreeValue}</degree-value>`);
6151
+ out.push(`${indent} <degree>`);
6152
+ out.push(`${indent} <degree-value>${deg.degreeValue}</degree-value>`);
6158
6153
  if (deg.degreeAlter !== void 0) {
6159
- lines.push(`${indent} <degree-alter>${deg.degreeAlter}</degree-alter>`);
6154
+ out.push(`${indent} <degree-alter>${deg.degreeAlter}</degree-alter>`);
6160
6155
  }
6161
- lines.push(`${indent} <degree-type>${deg.degreeType}</degree-type>`);
6162
- lines.push(`${indent} </degree>`);
6156
+ out.push(`${indent} <degree-type>${deg.degreeType}</degree-type>`);
6157
+ out.push(`${indent} </degree>`);
6163
6158
  }
6164
6159
  }
6165
6160
  if (harmony.frame) {
6166
- lines.push(`${indent} <frame>`);
6161
+ out.push(`${indent} <frame>`);
6167
6162
  if (harmony.frame.frameStrings !== void 0) {
6168
- lines.push(`${indent} <frame-strings>${harmony.frame.frameStrings}</frame-strings>`);
6163
+ out.push(`${indent} <frame-strings>${harmony.frame.frameStrings}</frame-strings>`);
6169
6164
  }
6170
6165
  if (harmony.frame.frameFrets !== void 0) {
6171
- lines.push(`${indent} <frame-frets>${harmony.frame.frameFrets}</frame-frets>`);
6166
+ out.push(`${indent} <frame-frets>${harmony.frame.frameFrets}</frame-frets>`);
6172
6167
  }
6173
6168
  if (harmony.frame.firstFret !== void 0) {
6174
6169
  let ffAttrs = "";
6175
6170
  if (harmony.frame.firstFretText) ffAttrs += ` text="${escapeXml(harmony.frame.firstFretText)}"`;
6176
6171
  if (harmony.frame.firstFretLocation) ffAttrs += ` location="${harmony.frame.firstFretLocation}"`;
6177
- lines.push(`${indent} <first-fret${ffAttrs}>${harmony.frame.firstFret}</first-fret>`);
6172
+ out.push(`${indent} <first-fret${ffAttrs}>${harmony.frame.firstFret}</first-fret>`);
6178
6173
  }
6179
6174
  if (harmony.frame.frameNotes) {
6180
6175
  for (const fn of harmony.frame.frameNotes) {
6181
- lines.push(`${indent} <frame-note>`);
6182
- lines.push(`${indent} <string>${fn.string}</string>`);
6183
- lines.push(`${indent} <fret>${fn.fret}</fret>`);
6176
+ out.push(`${indent} <frame-note>`);
6177
+ out.push(`${indent} <string>${fn.string}</string>`);
6178
+ out.push(`${indent} <fret>${fn.fret}</fret>`);
6184
6179
  if (fn.fingering) {
6185
- lines.push(`${indent} <fingering>${escapeXml(fn.fingering)}</fingering>`);
6180
+ out.push(`${indent} <fingering>${escapeXml(fn.fingering)}</fingering>`);
6186
6181
  }
6187
6182
  if (fn.barre) {
6188
- lines.push(`${indent} <barre type="${fn.barre}"/>`);
6183
+ out.push(`${indent} <barre type="${fn.barre}"/>`);
6189
6184
  }
6190
- lines.push(`${indent} </frame-note>`);
6185
+ out.push(`${indent} </frame-note>`);
6191
6186
  }
6192
6187
  }
6193
- lines.push(`${indent} </frame>`);
6188
+ out.push(`${indent} </frame>`);
6194
6189
  }
6195
6190
  if (harmony.offset !== void 0) {
6196
- lines.push(`${indent} <offset>${harmony.offset}</offset>`);
6191
+ out.push(`${indent} <offset>${harmony.offset}</offset>`);
6197
6192
  }
6198
6193
  if (harmony.staff !== void 0) {
6199
- lines.push(`${indent} <staff>${harmony.staff}</staff>`);
6194
+ out.push(`${indent} <staff>${harmony.staff}</staff>`);
6200
6195
  }
6201
- lines.push(`${indent}</harmony>`);
6202
- return lines;
6196
+ out.push(`${indent}</harmony>`);
6203
6197
  }
6204
- function serializeFiguredBass(fb, indent) {
6205
- const lines = [];
6198
+ function serializeFiguredBass(fb, indent, out) {
6206
6199
  let attrs = "";
6207
6200
  if (fb._id) attrs += ` id="${escapeXml(fb._id)}"`;
6208
6201
  if (fb.parentheses) attrs += ' parentheses="yes"';
6209
- lines.push(`${indent}<figured-bass${attrs}>`);
6202
+ out.push(`${indent}<figured-bass${attrs}>`);
6210
6203
  for (const fig of fb.figures) {
6211
- lines.push(`${indent} <figure>`);
6204
+ out.push(`${indent} <figure>`);
6212
6205
  if (fig.prefix) {
6213
- lines.push(`${indent} <prefix>${escapeXml(fig.prefix)}</prefix>`);
6206
+ out.push(`${indent} <prefix>${escapeXml(fig.prefix)}</prefix>`);
6214
6207
  }
6215
6208
  if (fig.figureNumber) {
6216
- lines.push(`${indent} <figure-number>${escapeXml(fig.figureNumber)}</figure-number>`);
6209
+ out.push(`${indent} <figure-number>${escapeXml(fig.figureNumber)}</figure-number>`);
6217
6210
  }
6218
6211
  if (fig.suffix) {
6219
- lines.push(`${indent} <suffix>${escapeXml(fig.suffix)}</suffix>`);
6212
+ out.push(`${indent} <suffix>${escapeXml(fig.suffix)}</suffix>`);
6220
6213
  }
6221
6214
  if (fig.extend) {
6222
6215
  if (typeof fig.extend === "object" && fig.extend.type) {
6223
- lines.push(`${indent} <extend type="${fig.extend.type}"/>`);
6216
+ out.push(`${indent} <extend type="${fig.extend.type}"/>`);
6224
6217
  } else {
6225
- lines.push(`${indent} <extend/>`);
6218
+ out.push(`${indent} <extend/>`);
6226
6219
  }
6227
6220
  }
6228
- lines.push(`${indent} </figure>`);
6221
+ out.push(`${indent} </figure>`);
6229
6222
  }
6230
6223
  if (fb.duration !== void 0) {
6231
- lines.push(`${indent} <duration>${fb.duration}</duration>`);
6224
+ out.push(`${indent} <duration>${fb.duration}</duration>`);
6232
6225
  }
6233
- lines.push(`${indent}</figured-bass>`);
6234
- return lines;
6226
+ out.push(`${indent}</figured-bass>`);
6235
6227
  }
6236
- function serializeSound(sound, indent) {
6237
- const lines = [];
6228
+ function serializeSound(sound, indent, out) {
6238
6229
  const attrs = [];
6239
6230
  if (sound._id) attrs.push(`id="${escapeXml(sound._id)}"`);
6240
6231
  if (sound.tempo !== void 0) attrs.push(`tempo="${sound.tempo}"`);
@@ -6251,29 +6242,28 @@ function serializeSound(sound, indent) {
6251
6242
  if (sound.sostenutoPedal) attrs.push(`sostenuto-pedal="${sound.sostenutoPedal === true ? "yes" : sound.sostenutoPedal}"`);
6252
6243
  const attrStr = attrs.length > 0 ? ` ${attrs.join(" ")}` : "";
6253
6244
  if (sound.swing) {
6254
- lines.push(`${indent}<sound${attrStr}>`);
6255
- lines.push(`${indent} <swing>`);
6245
+ out.push(`${indent}<sound${attrStr}>`);
6246
+ out.push(`${indent} <swing>`);
6256
6247
  if (sound.swing.straight) {
6257
- lines.push(`${indent} <straight/>`);
6248
+ out.push(`${indent} <straight/>`);
6258
6249
  } else {
6259
6250
  if (sound.swing.first !== void 0) {
6260
- lines.push(`${indent} <first>${sound.swing.first}</first>`);
6251
+ out.push(`${indent} <first>${sound.swing.first}</first>`);
6261
6252
  }
6262
6253
  if (sound.swing.second !== void 0) {
6263
- lines.push(`${indent} <second>${sound.swing.second}</second>`);
6254
+ out.push(`${indent} <second>${sound.swing.second}</second>`);
6264
6255
  }
6265
6256
  if (sound.swing.swingType) {
6266
- lines.push(`${indent} <swing-type>${sound.swing.swingType}</swing-type>`);
6257
+ out.push(`${indent} <swing-type>${sound.swing.swingType}</swing-type>`);
6267
6258
  }
6268
6259
  }
6269
- lines.push(`${indent} </swing>`);
6270
- lines.push(`${indent}</sound>`);
6260
+ out.push(`${indent} </swing>`);
6261
+ out.push(`${indent}</sound>`);
6271
6262
  } else if (attrs.length === 0 && !sound._id) {
6272
- lines.push(`${indent}<sound/>`);
6263
+ out.push(`${indent}<sound/>`);
6273
6264
  } else {
6274
- lines.push(`${indent}<sound${attrStr}/>`);
6265
+ out.push(`${indent}<sound${attrStr}/>`);
6275
6266
  }
6276
- return lines;
6277
6267
  }
6278
6268
 
6279
6269
  // src/exporters/musicxml-compressed.ts