musicxml-io 0.12.0 → 0.12.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.
Files changed (98) hide show
  1. package/README.md +96 -8
  2. package/dist/abc-HXITSXCS.js +9 -0
  3. package/dist/abc-IAD53SFI.mjs +11 -0
  4. package/dist/abc-MTGVOYKS.js +11 -0
  5. package/dist/abc-R7DIJSHG.mjs +9 -0
  6. package/dist/abc.d.mts +67 -0
  7. package/dist/abc.d.ts +67 -0
  8. package/dist/abc.js +17 -0
  9. package/dist/abc.mjs +17 -0
  10. package/dist/accessors/index.d.mts +1 -1
  11. package/dist/accessors/index.d.ts +1 -1
  12. package/dist/browser.d.mts +11 -187
  13. package/dist/browser.d.ts +11 -187
  14. package/dist/browser.js +30 -6
  15. package/dist/browser.mjs +96 -72
  16. package/dist/chunk-2EH2MGBY.js +1799 -0
  17. package/dist/chunk-33IQXDOH.js +1 -0
  18. package/dist/chunk-5EK7K5X3.js +29 -0
  19. package/dist/chunk-5VF442RA.mjs +29 -0
  20. package/dist/chunk-626TXMVP.js +706 -0
  21. package/dist/chunk-63UT3IEY.mjs +2788 -0
  22. package/dist/chunk-6EKVRPFF.js +407 -0
  23. package/dist/chunk-776XPK66.js +45 -0
  24. package/dist/chunk-7D4MLQKO.js +69 -0
  25. package/dist/chunk-A2CGW2UF.js +25 -0
  26. package/dist/chunk-AOSK4RGV.mjs +45 -0
  27. package/dist/{chunk-FQ3NEYIV.js → chunk-ASPCIBWD.js} +127 -1249
  28. package/dist/chunk-BDHPMB7Q.mjs +61 -0
  29. package/dist/chunk-BHHOS2E6.mjs +407 -0
  30. package/dist/chunk-F2UCOAO6.mjs +155 -0
  31. package/dist/chunk-HP4DAUGT.js +2788 -0
  32. package/dist/chunk-JF5TM534.js +1065 -0
  33. package/dist/chunk-K6DSQPVF.mjs +706 -0
  34. package/dist/chunk-KJK2IGNN.mjs +0 -0
  35. package/dist/chunk-KYGLANYG.mjs +2354 -0
  36. package/dist/chunk-LFQXT7PV.mjs +69 -0
  37. package/dist/chunk-LS5SHP75.js +155 -0
  38. package/dist/chunk-MMIZQMIO.mjs +25 -0
  39. package/dist/chunk-NIUEAHPN.js +2354 -0
  40. package/dist/{chunk-EWLB5X64.js → chunk-PMPROVJW.js} +66 -770
  41. package/dist/chunk-QFYOH4DY.mjs +0 -0
  42. package/dist/chunk-QKUNJEVW.mjs +1401 -0
  43. package/dist/chunk-SBT2RMUW.mjs +1065 -0
  44. package/dist/chunk-TCXDBRRT.mjs +1799 -0
  45. package/dist/chunk-WNQIUYWY.js +61 -0
  46. package/dist/{chunk-I4X4GRMP.mjs → chunk-WS5LSW3S.mjs} +13 -1135
  47. package/dist/chunk-YKMNCYOD.js +1 -0
  48. package/dist/{chunk-UMEH3ENQ.mjs → chunk-ZRKJKEP7.mjs} +0 -704
  49. package/dist/chunk-ZSEJQPBO.js +1401 -0
  50. package/dist/core.d.mts +33 -0
  51. package/dist/core.d.ts +33 -0
  52. package/dist/core.js +524 -0
  53. package/dist/core.mjs +524 -0
  54. package/dist/file.d.mts +37 -0
  55. package/dist/file.d.ts +37 -0
  56. package/dist/file.js +14 -0
  57. package/dist/file.mjs +14 -0
  58. package/dist/index-C9lLZwol.d.mts +185 -0
  59. package/dist/index-DNA970t1.d.ts +185 -0
  60. package/dist/index.d.mts +12 -38
  61. package/dist/index.d.ts +12 -38
  62. package/dist/index.js +34 -49
  63. package/dist/index.mjs +101 -116
  64. package/dist/midi.d.mts +54 -0
  65. package/dist/midi.d.ts +54 -0
  66. package/dist/midi.js +10 -0
  67. package/dist/midi.mjs +10 -0
  68. package/dist/musicxml-DWPClEqa.d.ts +25 -0
  69. package/dist/musicxml-DzuFr2c3.d.mts +25 -0
  70. package/dist/musicxml-compressed-7NUEGLSF.mjs +8 -0
  71. package/dist/musicxml-compressed-7RL6QRF7.js +12 -0
  72. package/dist/musicxml-compressed-WPEIBOZ3.js +8 -0
  73. package/dist/musicxml-compressed-ZHZYFJ7H.mjs +12 -0
  74. package/dist/musicxml-compressed.d.mts +33 -0
  75. package/dist/musicxml-compressed.d.ts +33 -0
  76. package/dist/musicxml-compressed.js +18 -0
  77. package/dist/musicxml-compressed.mjs +18 -0
  78. package/dist/musicxml.d.mts +8 -0
  79. package/dist/musicxml.d.ts +8 -0
  80. package/dist/musicxml.js +14 -0
  81. package/dist/musicxml.mjs +14 -0
  82. package/dist/operations/index.d.mts +1234 -2
  83. package/dist/operations/index.d.ts +1234 -2
  84. package/dist/operations/index.js +7 -3
  85. package/dist/operations/index.mjs +6 -2
  86. package/dist/playback-timeline-CVRHsikj.d.mts +129 -0
  87. package/dist/playback-timeline-CmWA8YDy.d.ts +129 -0
  88. package/dist/query/index.d.mts +3 -128
  89. package/dist/query/index.d.ts +3 -128
  90. package/dist/query/index.js +4 -2
  91. package/dist/query/index.mjs +7 -5
  92. package/dist/{types-Cy0veafI.d.mts → types-B-RGHY0c.d.mts} +1 -1
  93. package/dist/{types-Cy0veafI.d.ts → types-B-RGHY0c.d.ts} +1 -1
  94. package/package.json +36 -2
  95. package/dist/chunk-T2USSS5E.mjs +0 -8939
  96. package/dist/chunk-UT7LQW6V.js +0 -8939
  97. package/dist/index-CbUtBHLD.d.ts +0 -1415
  98. package/dist/index-CuMPBK7U.d.mts +0 -1415
@@ -0,0 +1,1799 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+ var _chunkJF5TM534js = require('./chunk-JF5TM534.js');
5
+
6
+ // src/exporters/musicxml.ts
7
+ function serialize(score, options = {}) {
8
+ const version = options.version || score.version || "4.0";
9
+ const indent = _nullishCoalesce(options.indent, () => ( " "));
10
+ if (options.validate) {
11
+ const result = _chunkJF5TM534js.validate.call(void 0, score, options.validateOptions);
12
+ if (options.onValidation) {
13
+ options.onValidation(result);
14
+ }
15
+ if (!result.valid && options.throwOnValidationError) {
16
+ const errorMessages = result.errors.map((e) => `[${e.code}] ${e.message}`).join("\n");
17
+ throw new (0, _chunkJF5TM534js.ValidationException)(result.errors, `Score validation failed:
18
+ ${errorMessages}`);
19
+ }
20
+ }
21
+ return serializeUnchecked(score, { version, indent });
22
+ }
23
+ function serializeUnchecked(score, options = {}) {
24
+ const version = options.version || score.version || "4.0";
25
+ const indent = _nullishCoalesce(options.indent, () => ( " "));
26
+ const lines = [];
27
+ lines.push('<?xml version="1.0" encoding="UTF-8"?>');
28
+ lines.push(`<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML ${version} Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">`);
29
+ lines.push(`<score-partwise version="${version}">`);
30
+ serializeMetadata(score.metadata, indent, lines);
31
+ if (score.defaults) {
32
+ serializeDefaults(score.defaults, indent, lines);
33
+ }
34
+ if (score.credits) {
35
+ for (const credit of score.credits) {
36
+ serializeCredit(credit, indent, lines);
37
+ }
38
+ }
39
+ serializePartList(score.partList, indent, lines);
40
+ for (const part of score.parts) {
41
+ serializePart(part, indent, lines);
42
+ }
43
+ lines.push("</score-partwise>");
44
+ return lines.join("\n");
45
+ }
46
+ function serializeMetadata(metadata, indent, out) {
47
+ if (metadata.workTitle !== void 0 || metadata.workNumber !== void 0) {
48
+ out.push(`${indent}<work>`);
49
+ if (metadata.workNumber !== void 0) {
50
+ out.push(`${indent}${indent}<work-number>${escapeXml(metadata.workNumber)}</work-number>`);
51
+ }
52
+ if (metadata.workTitle !== void 0) {
53
+ out.push(`${indent}${indent}<work-title>${escapeXml(metadata.workTitle)}</work-title>`);
54
+ }
55
+ out.push(`${indent}</work>`);
56
+ }
57
+ if (metadata.movementNumber !== void 0) {
58
+ out.push(`${indent}<movement-number>${escapeXml(metadata.movementNumber)}</movement-number>`);
59
+ }
60
+ if (metadata.movementTitle !== void 0) {
61
+ out.push(`${indent}<movement-title>${escapeXml(metadata.movementTitle)}</movement-title>`);
62
+ }
63
+ if (metadata.creators || metadata.rights || metadata.encoding || metadata.source || metadata.miscellaneous) {
64
+ out.push(`${indent}<identification>`);
65
+ if (metadata.creators) {
66
+ for (const creator of metadata.creators) {
67
+ const typeAttr = creator.type ? ` type="${escapeXml(creator.type)}"` : "";
68
+ out.push(`${indent}${indent}<creator${typeAttr}>${escapeXml(creator.value)}</creator>`);
69
+ }
70
+ }
71
+ if (metadata.rights) {
72
+ for (const right of metadata.rights) {
73
+ out.push(`${indent}${indent}<rights>${escapeXml(right)}</rights>`);
74
+ }
75
+ }
76
+ if (metadata.encoding) {
77
+ out.push(`${indent}${indent}<encoding>`);
78
+ if (metadata.encoding.software) {
79
+ for (const sw of metadata.encoding.software) {
80
+ out.push(`${indent}${indent}${indent}<software>${escapeXml(sw)}</software>`);
81
+ }
82
+ }
83
+ if (metadata.encoding.encodingDate) {
84
+ out.push(`${indent}${indent}${indent}<encoding-date>${escapeXml(metadata.encoding.encodingDate)}</encoding-date>`);
85
+ }
86
+ if (metadata.encoding.encoder) {
87
+ for (const enc of metadata.encoding.encoder) {
88
+ out.push(`${indent}${indent}${indent}<encoder>${escapeXml(enc)}</encoder>`);
89
+ }
90
+ }
91
+ if (metadata.encoding.encodingDescription) {
92
+ out.push(`${indent}${indent}${indent}<encoding-description>${escapeXml(metadata.encoding.encodingDescription)}</encoding-description>`);
93
+ }
94
+ if (metadata.encoding.supports) {
95
+ for (const support of metadata.encoding.supports) {
96
+ let attrs = ` element="${escapeXml(support.element)}" type="${support.type}"`;
97
+ if (support.attribute) attrs += ` attribute="${escapeXml(support.attribute)}"`;
98
+ if (support.value) attrs += ` value="${escapeXml(support.value)}"`;
99
+ out.push(`${indent}${indent}${indent}<supports${attrs}/>`);
100
+ }
101
+ }
102
+ out.push(`${indent}${indent}</encoding>`);
103
+ }
104
+ if (metadata.source) {
105
+ out.push(`${indent}${indent}<source>${escapeXml(metadata.source)}</source>`);
106
+ }
107
+ if (metadata.miscellaneous) {
108
+ out.push(`${indent}${indent}<miscellaneous>`);
109
+ for (const field of metadata.miscellaneous) {
110
+ out.push(`${indent}${indent}${indent}<miscellaneous-field name="${escapeXml(field.name)}">${escapeXml(field.value)}</miscellaneous-field>`);
111
+ }
112
+ out.push(`${indent}${indent}</miscellaneous>`);
113
+ }
114
+ out.push(`${indent}</identification>`);
115
+ }
116
+ }
117
+ function serializeDefaults(defaults, indent, out) {
118
+ out.push(`${indent}<defaults>`);
119
+ if (defaults.scaling) {
120
+ out.push(`${indent}${indent}<scaling>`);
121
+ out.push(`${indent}${indent}${indent}<millimeters>${defaults.scaling.millimeters}</millimeters>`);
122
+ out.push(`${indent}${indent}${indent}<tenths>${defaults.scaling.tenths}</tenths>`);
123
+ out.push(`${indent}${indent}</scaling>`);
124
+ }
125
+ if (defaults.pageLayout) {
126
+ serializePageLayout(defaults.pageLayout, indent + indent, out);
127
+ }
128
+ if (defaults.systemLayout) {
129
+ serializeSystemLayout(defaults.systemLayout, indent + indent, out);
130
+ }
131
+ if (defaults.staffLayout) {
132
+ for (const sl of defaults.staffLayout) {
133
+ const numAttr = sl.number !== void 0 ? ` number="${sl.number}"` : "";
134
+ out.push(`${indent}${indent}<staff-layout${numAttr}>`);
135
+ if (sl.staffDistance !== void 0) {
136
+ out.push(`${indent}${indent}${indent}<staff-distance>${sl.staffDistance}</staff-distance>`);
137
+ }
138
+ out.push(`${indent}${indent}</staff-layout>`);
139
+ }
140
+ }
141
+ if (defaults.appearance) {
142
+ out.push(`${indent}${indent}<appearance>`);
143
+ const app = defaults.appearance;
144
+ if (app["line-widths"]) {
145
+ for (const lw of app["line-widths"]) {
146
+ out.push(`${indent}${indent}${indent}<line-width type="${escapeXml(lw.type)}">${lw.value}</line-width>`);
147
+ }
148
+ }
149
+ if (app["note-sizes"]) {
150
+ for (const ns of app["note-sizes"]) {
151
+ out.push(`${indent}${indent}${indent}<note-size type="${escapeXml(ns.type)}">${ns.value}</note-size>`);
152
+ }
153
+ }
154
+ if (app["distances"]) {
155
+ for (const d of app["distances"]) {
156
+ out.push(`${indent}${indent}${indent}<distance type="${escapeXml(d.type)}">${d.value}</distance>`);
157
+ }
158
+ }
159
+ if (app["glyphs"]) {
160
+ for (const g of app["glyphs"]) {
161
+ out.push(`${indent}${indent}${indent}<glyph type="${escapeXml(g.type)}">${escapeXml(g.value)}</glyph>`);
162
+ }
163
+ }
164
+ out.push(`${indent}${indent}</appearance>`);
165
+ }
166
+ if (defaults.musicFont) {
167
+ let attrs = "";
168
+ if (defaults.musicFont.fontFamily) attrs += ` font-family="${escapeXml(defaults.musicFont.fontFamily)}"`;
169
+ if (defaults.musicFont.fontSize) attrs += ` font-size="${escapeXml(defaults.musicFont.fontSize)}"`;
170
+ if (defaults.musicFont.fontStyle) attrs += ` font-style="${escapeXml(defaults.musicFont.fontStyle)}"`;
171
+ if (defaults.musicFont.fontWeight) attrs += ` font-weight="${escapeXml(defaults.musicFont.fontWeight)}"`;
172
+ out.push(`${indent}${indent}<music-font${attrs}/>`);
173
+ }
174
+ if (defaults.wordFont) {
175
+ let attrs = "";
176
+ if (defaults.wordFont.fontFamily) attrs += ` font-family="${escapeXml(defaults.wordFont.fontFamily)}"`;
177
+ if (defaults.wordFont.fontSize) attrs += ` font-size="${escapeXml(defaults.wordFont.fontSize)}"`;
178
+ if (defaults.wordFont.fontStyle) attrs += ` font-style="${escapeXml(defaults.wordFont.fontStyle)}"`;
179
+ if (defaults.wordFont.fontWeight) attrs += ` font-weight="${escapeXml(defaults.wordFont.fontWeight)}"`;
180
+ out.push(`${indent}${indent}<word-font${attrs}/>`);
181
+ }
182
+ if (defaults.lyricFont) {
183
+ for (const lf of defaults.lyricFont) {
184
+ let attrs = "";
185
+ if (lf.number !== void 0) attrs += ` number="${lf.number}"`;
186
+ if (lf.name) attrs += ` name="${escapeXml(lf.name)}"`;
187
+ if (lf.fontFamily) attrs += ` font-family="${escapeXml(lf.fontFamily)}"`;
188
+ if (lf.fontSize) attrs += ` font-size="${escapeXml(lf.fontSize)}"`;
189
+ if (lf.fontStyle) attrs += ` font-style="${escapeXml(lf.fontStyle)}"`;
190
+ if (lf.fontWeight) attrs += ` font-weight="${escapeXml(lf.fontWeight)}"`;
191
+ out.push(`${indent}${indent}<lyric-font${attrs}/>`);
192
+ }
193
+ }
194
+ if (defaults.lyricLanguage) {
195
+ for (const ll of defaults.lyricLanguage) {
196
+ let attrs = "";
197
+ if (ll.number !== void 0) attrs += ` number="${ll.number}"`;
198
+ if (ll.name) attrs += ` name="${escapeXml(ll.name)}"`;
199
+ attrs += ` xml:lang="${escapeXml(ll.xmlLang)}"`;
200
+ out.push(`${indent}${indent}<lyric-language${attrs}/>`);
201
+ }
202
+ }
203
+ out.push(`${indent}</defaults>`);
204
+ }
205
+ function serializePageLayout(layout, indent, out) {
206
+ out.push(`${indent}<page-layout>`);
207
+ if (layout.pageHeight !== void 0) {
208
+ out.push(`${indent} <page-height>${layout.pageHeight}</page-height>`);
209
+ }
210
+ if (layout.pageWidth !== void 0) {
211
+ out.push(`${indent} <page-width>${layout.pageWidth}</page-width>`);
212
+ }
213
+ if (layout.pageMargins) {
214
+ for (const m of layout.pageMargins) {
215
+ const typeAttr = m.type ? ` type="${m.type}"` : "";
216
+ out.push(`${indent} <page-margins${typeAttr}>`);
217
+ if (m.leftMargin !== void 0) {
218
+ out.push(`${indent} <left-margin>${_nullishCoalesce(m.leftMarginRaw, () => ( m.leftMargin))}</left-margin>`);
219
+ }
220
+ if (m.rightMargin !== void 0) {
221
+ out.push(`${indent} <right-margin>${_nullishCoalesce(m.rightMarginRaw, () => ( m.rightMargin))}</right-margin>`);
222
+ }
223
+ if (m.topMargin !== void 0) {
224
+ out.push(`${indent} <top-margin>${_nullishCoalesce(m.topMarginRaw, () => ( m.topMargin))}</top-margin>`);
225
+ }
226
+ if (m.bottomMargin !== void 0) {
227
+ out.push(`${indent} <bottom-margin>${_nullishCoalesce(m.bottomMarginRaw, () => ( m.bottomMargin))}</bottom-margin>`);
228
+ }
229
+ out.push(`${indent} </page-margins>`);
230
+ }
231
+ }
232
+ out.push(`${indent}</page-layout>`);
233
+ }
234
+ function serializeSystemLayout(layout, indent, out) {
235
+ out.push(`${indent}<system-layout>`);
236
+ if (layout.systemMargins) {
237
+ out.push(`${indent} <system-margins>`);
238
+ if (layout.systemMargins.leftMargin !== void 0) {
239
+ out.push(`${indent} <left-margin>${_nullishCoalesce(layout.systemMargins.leftMarginRaw, () => ( layout.systemMargins.leftMargin))}</left-margin>`);
240
+ }
241
+ if (layout.systemMargins.rightMargin !== void 0) {
242
+ out.push(`${indent} <right-margin>${_nullishCoalesce(layout.systemMargins.rightMarginRaw, () => ( layout.systemMargins.rightMargin))}</right-margin>`);
243
+ }
244
+ out.push(`${indent} </system-margins>`);
245
+ }
246
+ if (layout.systemDistance !== void 0) {
247
+ out.push(`${indent} <system-distance>${_nullishCoalesce(layout.systemDistanceRaw, () => ( layout.systemDistance))}</system-distance>`);
248
+ }
249
+ if (layout.topSystemDistance !== void 0) {
250
+ out.push(`${indent} <top-system-distance>${_nullishCoalesce(layout.topSystemDistanceRaw, () => ( layout.topSystemDistance))}</top-system-distance>`);
251
+ }
252
+ if (layout.systemDividers) {
253
+ out.push(`${indent} <system-dividers>`);
254
+ if (layout.systemDividers.leftDivider) {
255
+ let attrs = "";
256
+ if (layout.systemDividers.leftDivider.printObject !== void 0) {
257
+ attrs += ` print-object="${layout.systemDividers.leftDivider.printObject ? "yes" : "no"}"`;
258
+ }
259
+ if (layout.systemDividers.leftDivider.halign) {
260
+ attrs += ` halign="${layout.systemDividers.leftDivider.halign}"`;
261
+ }
262
+ if (layout.systemDividers.leftDivider.valign) {
263
+ attrs += ` valign="${layout.systemDividers.leftDivider.valign}"`;
264
+ }
265
+ out.push(`${indent} <left-divider${attrs}/>`);
266
+ }
267
+ if (layout.systemDividers.rightDivider) {
268
+ let attrs = "";
269
+ if (layout.systemDividers.rightDivider.printObject !== void 0) {
270
+ attrs += ` print-object="${layout.systemDividers.rightDivider.printObject ? "yes" : "no"}"`;
271
+ }
272
+ if (layout.systemDividers.rightDivider.halign) {
273
+ attrs += ` halign="${layout.systemDividers.rightDivider.halign}"`;
274
+ }
275
+ if (layout.systemDividers.rightDivider.valign) {
276
+ attrs += ` valign="${layout.systemDividers.rightDivider.valign}"`;
277
+ }
278
+ out.push(`${indent} <right-divider${attrs}/>`);
279
+ }
280
+ out.push(`${indent} </system-dividers>`);
281
+ }
282
+ out.push(`${indent}</system-layout>`);
283
+ }
284
+ function serializeCredit(credit, indent, out) {
285
+ let attrs = "";
286
+ if (credit._id) attrs += ` id="${escapeXml(credit._id)}"`;
287
+ if (credit.page !== void 0) attrs += ` page="${credit.page}"`;
288
+ out.push(`${indent}<credit${attrs}>`);
289
+ if (credit.creditType) {
290
+ for (const ct of credit.creditType) {
291
+ out.push(`${indent}${indent}<credit-type>${escapeXml(ct)}</credit-type>`);
292
+ }
293
+ }
294
+ if (credit.creditImage) {
295
+ const ci = credit.creditImage;
296
+ let attrs2 = ` source="${escapeXml(ci.source)}" type="${escapeXml(ci.type)}"`;
297
+ if (ci.height !== void 0) attrs2 += ` height="${ci.height}"`;
298
+ if (ci.width !== void 0) attrs2 += ` width="${ci.width}"`;
299
+ if (ci.defaultX !== void 0) attrs2 += ` default-x="${ci.defaultX}"`;
300
+ if (ci.defaultY !== void 0) attrs2 += ` default-y="${ci.defaultY}"`;
301
+ if (ci.relativeX !== void 0) attrs2 += ` relative-x="${ci.relativeX}"`;
302
+ if (ci.relativeY !== void 0) attrs2 += ` relative-y="${ci.relativeY}"`;
303
+ if (ci.halign) attrs2 += ` halign="${escapeXml(ci.halign)}"`;
304
+ if (ci.valign) attrs2 += ` valign="${escapeXml(ci.valign)}"`;
305
+ out.push(`${indent}${indent}<credit-image${attrs2}/>`);
306
+ }
307
+ if (credit.creditWords) {
308
+ for (const cw of credit.creditWords) {
309
+ let attrs2 = "";
310
+ if (cw.defaultX !== void 0) attrs2 += ` default-x="${cw.defaultX}"`;
311
+ if (cw.defaultY !== void 0) attrs2 += ` default-y="${cw.defaultY}"`;
312
+ if (cw.fontFamily) attrs2 += ` font-family="${escapeXml(cw.fontFamily)}"`;
313
+ if (cw.fontSize) attrs2 += ` font-size="${escapeXml(cw.fontSize)}"`;
314
+ if (cw.fontWeight) attrs2 += ` font-weight="${escapeXml(cw.fontWeight)}"`;
315
+ if (cw.fontStyle) attrs2 += ` font-style="${escapeXml(cw.fontStyle)}"`;
316
+ if (cw.justify) attrs2 += ` justify="${escapeXml(cw.justify)}"`;
317
+ if (cw.halign) attrs2 += ` halign="${escapeXml(cw.halign)}"`;
318
+ if (cw.valign) attrs2 += ` valign="${escapeXml(cw.valign)}"`;
319
+ if (cw.letterSpacing) attrs2 += ` letter-spacing="${escapeXml(cw.letterSpacing)}"`;
320
+ if (cw.xmlLang) attrs2 += ` xml:lang="${escapeXml(cw.xmlLang)}"`;
321
+ if (cw.xmlSpace) attrs2 += ` xml:space="${escapeXml(cw.xmlSpace)}"`;
322
+ if (cw.color) attrs2 += ` color="${escapeXml(cw.color)}"`;
323
+ out.push(`${indent}${indent}<credit-words${attrs2}>${escapeXml(cw.text)}</credit-words>`);
324
+ }
325
+ }
326
+ out.push(`${indent}</credit>`);
327
+ }
328
+ function serializePartList(partList, indent, out) {
329
+ out.push(`${indent}<part-list>`);
330
+ for (const entry of partList) {
331
+ if (entry.type === "score-part") {
332
+ serializeScorePart(entry, indent + indent, out);
333
+ } else if (entry.type === "part-group") {
334
+ serializePartGroup(entry, indent + indent, out);
335
+ }
336
+ }
337
+ out.push(`${indent}</part-list>`);
338
+ }
339
+ function serializeDisplayTexts(texts, indent, out) {
340
+ for (const dt of texts) {
341
+ let attrs = "";
342
+ if (dt.fontFamily) attrs += ` font-family="${escapeXml(dt.fontFamily)}"`;
343
+ if (dt.fontSize) attrs += ` font-size="${escapeXml(dt.fontSize)}"`;
344
+ if (dt.fontStyle) attrs += ` font-style="${escapeXml(dt.fontStyle)}"`;
345
+ if (dt.fontWeight) attrs += ` font-weight="${escapeXml(dt.fontWeight)}"`;
346
+ if (dt.xmlSpace) attrs += ` xml:space="${escapeXml(dt.xmlSpace)}"`;
347
+ if (dt.color) attrs += ` color="${escapeXml(dt.color)}"`;
348
+ out.push(`${indent}<display-text${attrs}>${escapeXml(dt.text)}</display-text>`);
349
+ }
350
+ }
351
+ function serializeScorePart(part, indent, out) {
352
+ out.push(`${indent}<score-part id="${escapeXml(part.id)}">`);
353
+ if (part.name !== void 0) {
354
+ let pnAttrs = "";
355
+ if (part.namePrintObject === false) pnAttrs += ' print-object="no"';
356
+ if (part.nameColor) pnAttrs += ` color="${escapeXml(part.nameColor)}"`;
357
+ out.push(`${indent} <part-name${pnAttrs}>${escapeXml(part.name)}</part-name>`);
358
+ }
359
+ if (part.partNameDisplay && part.partNameDisplay.length > 0) {
360
+ out.push(`${indent} <part-name-display>`);
361
+ serializeDisplayTexts(part.partNameDisplay, indent + " ", out);
362
+ out.push(`${indent} </part-name-display>`);
363
+ }
364
+ if (part.abbreviation !== void 0) {
365
+ let paAttrs = "";
366
+ if (part.abbreviationPrintObject === false) paAttrs += ' print-object="no"';
367
+ if (part.abbreviationColor) paAttrs += ` color="${escapeXml(part.abbreviationColor)}"`;
368
+ out.push(`${indent} <part-abbreviation${paAttrs}>${escapeXml(part.abbreviation)}</part-abbreviation>`);
369
+ }
370
+ if (part.partAbbreviationDisplay && part.partAbbreviationDisplay.length > 0) {
371
+ out.push(`${indent} <part-abbreviation-display>`);
372
+ serializeDisplayTexts(part.partAbbreviationDisplay, indent + " ", out);
373
+ out.push(`${indent} </part-abbreviation-display>`);
374
+ }
375
+ if (part.scoreInstruments) {
376
+ for (const inst of part.scoreInstruments) {
377
+ out.push(`${indent} <score-instrument id="${escapeXml(inst.id)}">`);
378
+ out.push(`${indent} <instrument-name>${escapeXml(inst.name)}</instrument-name>`);
379
+ if (inst.abbreviation) {
380
+ out.push(`${indent} <instrument-abbreviation>${escapeXml(inst.abbreviation)}</instrument-abbreviation>`);
381
+ }
382
+ if (inst.sound) {
383
+ out.push(`${indent} <instrument-sound>${escapeXml(inst.sound)}</instrument-sound>`);
384
+ }
385
+ if (inst.solo) {
386
+ out.push(`${indent} <solo/>`);
387
+ }
388
+ if (inst.ensemble !== void 0) {
389
+ if (inst.ensemble === 0) {
390
+ out.push(`${indent} <ensemble/>`);
391
+ } else {
392
+ out.push(`${indent} <ensemble>${inst.ensemble}</ensemble>`);
393
+ }
394
+ }
395
+ out.push(`${indent} </score-instrument>`);
396
+ }
397
+ }
398
+ if (part.groups) {
399
+ for (const group of part.groups) {
400
+ out.push(`${indent} <group>${escapeXml(group)}</group>`);
401
+ }
402
+ }
403
+ if (part.midiInstruments) {
404
+ for (const midi of part.midiInstruments) {
405
+ out.push(`${indent} <midi-instrument id="${escapeXml(midi.id)}">`);
406
+ if (midi.channel !== void 0) {
407
+ out.push(`${indent} <midi-channel>${midi.channel}</midi-channel>`);
408
+ }
409
+ if (midi.name) {
410
+ out.push(`${indent} <midi-name>${escapeXml(midi.name)}</midi-name>`);
411
+ }
412
+ if (midi.bank !== void 0) {
413
+ out.push(`${indent} <midi-bank>${midi.bank}</midi-bank>`);
414
+ }
415
+ if (midi.program !== void 0) {
416
+ out.push(`${indent} <midi-program>${midi.program}</midi-program>`);
417
+ }
418
+ if (midi.unpitched !== void 0) {
419
+ out.push(`${indent} <midi-unpitched>${midi.unpitched}</midi-unpitched>`);
420
+ }
421
+ if (midi.volume !== void 0) {
422
+ out.push(`${indent} <volume>${midi.volume}</volume>`);
423
+ }
424
+ if (midi.pan !== void 0) {
425
+ out.push(`${indent} <pan>${midi.pan}</pan>`);
426
+ }
427
+ if (midi.elevation !== void 0) {
428
+ out.push(`${indent} <elevation>${midi.elevation}</elevation>`);
429
+ }
430
+ out.push(`${indent} </midi-instrument>`);
431
+ }
432
+ }
433
+ out.push(`${indent}</score-part>`);
434
+ }
435
+ function serializePartGroup(group, indent, out) {
436
+ let attrs = ` type="${group.groupType}"`;
437
+ if (group.number !== void 0) attrs += ` number="${group.number}"`;
438
+ if (group._id) attrs += ` id="${escapeXml(group._id)}"`;
439
+ out.push(`${indent}<part-group${attrs}>`);
440
+ if (group.groupName) {
441
+ const gnAttrs = group.groupNameColor ? ` color="${escapeXml(group.groupNameColor)}"` : "";
442
+ out.push(`${indent} <group-name${gnAttrs}>${escapeXml(group.groupName)}</group-name>`);
443
+ }
444
+ if (group.groupNameDisplay && group.groupNameDisplay.length > 0) {
445
+ out.push(`${indent} <group-name-display>`);
446
+ serializeDisplayTexts(group.groupNameDisplay, indent + " ", out);
447
+ out.push(`${indent} </group-name-display>`);
448
+ }
449
+ if (group.groupAbbreviation) {
450
+ const gaAttrs = group.groupAbbreviationColor ? ` color="${escapeXml(group.groupAbbreviationColor)}"` : "";
451
+ out.push(`${indent} <group-abbreviation${gaAttrs}>${escapeXml(group.groupAbbreviation)}</group-abbreviation>`);
452
+ }
453
+ if (group.groupAbbreviationDisplay && group.groupAbbreviationDisplay.length > 0) {
454
+ out.push(`${indent} <group-abbreviation-display>`);
455
+ serializeDisplayTexts(group.groupAbbreviationDisplay, indent + " ", out);
456
+ out.push(`${indent} </group-abbreviation-display>`);
457
+ }
458
+ if (group.groupSymbol) {
459
+ let gsAttrs = group.groupSymbolDefaultX !== void 0 ? ` default-x="${group.groupSymbolDefaultX}"` : "";
460
+ if (group.groupSymbolColor) gsAttrs += ` color="${escapeXml(group.groupSymbolColor)}"`;
461
+ out.push(`${indent} <group-symbol${gsAttrs}>${group.groupSymbol}</group-symbol>`);
462
+ }
463
+ if (group.groupBarline) {
464
+ out.push(`${indent} <group-barline>${group.groupBarline}</group-barline>`);
465
+ }
466
+ out.push(`${indent}</part-group>`);
467
+ }
468
+ function serializePart(part, indent, out) {
469
+ const idAttr = part.id ? ` id="${escapeXml(part.id)}"` : "";
470
+ out.push(`${indent}<part${idAttr}>`);
471
+ for (const measure of part.measures) {
472
+ const measureLines = [];
473
+ serializeMeasure(measure, indent + indent, measureLines);
474
+ out.push(measureLines.join("\n"));
475
+ }
476
+ out.push(`${indent}</part>`);
477
+ }
478
+ function serializeMeasure(measure, indent, out) {
479
+ let attrs = ` number="${measure.number}"`;
480
+ if (measure._id) attrs += ` id="${escapeXml(measure._id)}"`;
481
+ if (measure.width !== void 0) attrs += ` width="${measure.width}"`;
482
+ if (measure.implicit) attrs += ` implicit="yes"`;
483
+ out.push(`${indent}<measure${attrs}>`);
484
+ if (measure.print) {
485
+ serializePrint(measure.print, indent + " ", out);
486
+ }
487
+ if (measure.attributes) {
488
+ serializeAttributes(measure.attributes, indent + " ", out, measure.attributes._id);
489
+ }
490
+ for (const entry of measure.entries) {
491
+ serializeEntry(entry, indent + " ", out);
492
+ }
493
+ if (measure.barlines) {
494
+ for (const barline of measure.barlines) {
495
+ serializeBarline(barline, indent + " ", out);
496
+ }
497
+ }
498
+ out.push(`${indent}</measure>`);
499
+ }
500
+ function serializePrint(print, indent, out) {
501
+ let attrs = "";
502
+ if (print.newSystem) attrs += ' new-system="yes"';
503
+ if (print.newPage) attrs += ' new-page="yes"';
504
+ if (print.blankPage !== void 0) attrs += ` blank-page="${print.blankPage}"`;
505
+ if (print.pageNumber) attrs += ` page-number="${escapeXml(print.pageNumber)}"`;
506
+ out.push(`${indent}<print${attrs}>`);
507
+ if (print.pageLayout) {
508
+ serializePageLayout(print.pageLayout, indent + " ", out);
509
+ }
510
+ if (print.systemLayout) {
511
+ serializeSystemLayout(print.systemLayout, indent + " ", out);
512
+ }
513
+ if (print.staffLayouts) {
514
+ for (const sl of print.staffLayouts) {
515
+ const numAttr = sl.number !== void 0 ? ` number="${sl.number}"` : "";
516
+ out.push(`${indent} <staff-layout${numAttr}>`);
517
+ if (sl.staffDistance !== void 0) {
518
+ out.push(`${indent} <staff-distance>${sl.staffDistance}</staff-distance>`);
519
+ }
520
+ out.push(`${indent} </staff-layout>`);
521
+ }
522
+ }
523
+ if (print.measureLayout) {
524
+ out.push(`${indent} <measure-layout>`);
525
+ if (print.measureLayout.measureDistance !== void 0) {
526
+ out.push(`${indent} <measure-distance>${print.measureLayout.measureDistance}</measure-distance>`);
527
+ }
528
+ out.push(`${indent} </measure-layout>`);
529
+ }
530
+ if (print.measureNumbering) {
531
+ const mn = print.measureNumbering;
532
+ if (typeof mn === "string") {
533
+ out.push(`${indent} <measure-numbering>${escapeXml(mn)}</measure-numbering>`);
534
+ } else {
535
+ let mnAttrs = "";
536
+ if (mn.system) mnAttrs += ` system="${mn.system}"`;
537
+ out.push(`${indent} <measure-numbering${mnAttrs}>${escapeXml(mn.value)}</measure-numbering>`);
538
+ }
539
+ }
540
+ if (print.partNameDisplay && print.partNameDisplay.length > 0) {
541
+ out.push(`${indent} <part-name-display>`);
542
+ serializeDisplayTexts(print.partNameDisplay, indent + " ", out);
543
+ out.push(`${indent} </part-name-display>`);
544
+ }
545
+ if (print.partAbbreviationDisplay && print.partAbbreviationDisplay.length > 0) {
546
+ out.push(`${indent} <part-abbreviation-display>`);
547
+ serializeDisplayTexts(print.partAbbreviationDisplay, indent + " ", out);
548
+ out.push(`${indent} </part-abbreviation-display>`);
549
+ }
550
+ out.push(`${indent}</print>`);
551
+ }
552
+ function serializeAttributes(attrs, indent, out, id) {
553
+ const idAttr = id ? ` id="${escapeXml(id)}"` : "";
554
+ out.push(`${indent}<attributes${idAttr}>`);
555
+ if (attrs.divisions !== void 0) {
556
+ out.push(`${indent} <divisions>${attrs.divisions}</divisions>`);
557
+ }
558
+ if (attrs.keys && attrs.keys.length > 0) {
559
+ for (const key of attrs.keys) {
560
+ serializeKey(key, indent + " ", out);
561
+ }
562
+ } else if (attrs.key) {
563
+ serializeKey(attrs.key, indent + " ", out);
564
+ }
565
+ if (attrs.time) {
566
+ serializeTime(attrs.time, indent + " ", out);
567
+ }
568
+ if (attrs.staves !== void 0) {
569
+ out.push(`${indent} <staves>${attrs.staves}</staves>`);
570
+ }
571
+ if (attrs.instruments !== void 0) {
572
+ out.push(`${indent} <instruments>${attrs.instruments}</instruments>`);
573
+ }
574
+ if (attrs.clef) {
575
+ for (const clef of attrs.clef) {
576
+ serializeClef(clef, indent + " ", out);
577
+ }
578
+ }
579
+ if (attrs.transpose) {
580
+ serializeTranspose(attrs.transpose, indent + " ", out);
581
+ }
582
+ if (attrs.staffDetails) {
583
+ for (const sd of attrs.staffDetails) {
584
+ serializeStaffDetails(sd, indent + " ", out);
585
+ }
586
+ }
587
+ if (attrs.measureStyle) {
588
+ for (const ms of attrs.measureStyle) {
589
+ serializeMeasureStyle(ms, indent + " ", out);
590
+ }
591
+ }
592
+ out.push(`${indent}</attributes>`);
593
+ }
594
+ function serializeKey(key, indent, out) {
595
+ let keyAttrs = "";
596
+ if (key.number !== void 0) keyAttrs += ` number="${key.number}"`;
597
+ if (key.printObject === false) keyAttrs += ' print-object="no"';
598
+ else if (key.printObject === true) keyAttrs += ' print-object="yes"';
599
+ if (key.color) keyAttrs += ` color="${escapeXml(key.color)}"`;
600
+ out.push(`${indent}<key${keyAttrs}>`);
601
+ if (key.cancel !== void 0) {
602
+ const locationAttr = key.cancelLocation ? ` location="${key.cancelLocation}"` : "";
603
+ out.push(`${indent} <cancel${locationAttr}>${key.cancel}</cancel>`);
604
+ }
605
+ if (key.keySteps && key.keyAlters && key.keySteps.length > 0) {
606
+ for (let i = 0; i < key.keySteps.length; i++) {
607
+ out.push(`${indent} <key-step>${key.keySteps[i]}</key-step>`);
608
+ if (i < key.keyAlters.length) {
609
+ out.push(`${indent} <key-alter>${key.keyAlters[i]}</key-alter>`);
610
+ }
611
+ }
612
+ if (key.keyOctaves) {
613
+ for (const ko of key.keyOctaves) {
614
+ let koAttrs = ` number="${ko.number}"`;
615
+ if (ko.cancel !== void 0) koAttrs += ` cancel="${ko.cancel ? "yes" : "no"}"`;
616
+ out.push(`${indent} <key-octave${koAttrs}>${ko.octave}</key-octave>`);
617
+ }
618
+ }
619
+ } else {
620
+ out.push(`${indent} <fifths>${key.fifths}</fifths>`);
621
+ if (key.mode) {
622
+ out.push(`${indent} <mode>${key.mode}</mode>`);
623
+ }
624
+ if (key.keyOctaves) {
625
+ for (const ko of key.keyOctaves) {
626
+ let koAttrs = ` number="${ko.number}"`;
627
+ if (ko.cancel !== void 0) koAttrs += ` cancel="${ko.cancel ? "yes" : "no"}"`;
628
+ out.push(`${indent} <key-octave${koAttrs}>${ko.octave}</key-octave>`);
629
+ }
630
+ }
631
+ }
632
+ out.push(`${indent}</key>`);
633
+ }
634
+ function serializeTime(time, indent, out) {
635
+ let attrs = "";
636
+ if (time.symbol) attrs += ` symbol="${time.symbol}"`;
637
+ if (time.printObject === false) attrs += ' print-object="no"';
638
+ if (time.color) attrs += ` color="${escapeXml(time.color)}"`;
639
+ out.push(`${indent}<time${attrs}>`);
640
+ if (time.senzaMisura) {
641
+ out.push(`${indent} <senza-misura/>`);
642
+ } else if (time.beatsList && time.beatTypeList && time.beatsList.length > 1) {
643
+ const maxLen = Math.max(time.beatsList.length, time.beatTypeList.length);
644
+ for (let i = 0; i < maxLen; i++) {
645
+ if (i < time.beatsList.length) {
646
+ const beatsValue = time.beatsStrList && i < time.beatsStrList.length ? time.beatsStrList[i] : time.beatsList[i];
647
+ out.push(`${indent} <beats>${beatsValue}</beats>`);
648
+ }
649
+ if (i < time.beatTypeList.length) {
650
+ out.push(`${indent} <beat-type>${time.beatTypeList[i]}</beat-type>`);
651
+ }
652
+ }
653
+ } else {
654
+ out.push(`${indent} <beats>${time.beats}</beats>`);
655
+ out.push(`${indent} <beat-type>${time.beatType}</beat-type>`);
656
+ }
657
+ out.push(`${indent}</time>`);
658
+ }
659
+ function serializeClef(clef, indent, out) {
660
+ let attrs = clef.staff ? ` number="${clef.staff}"` : "";
661
+ if (clef.printObject === false) attrs += ' print-object="no"';
662
+ else if (clef.printObject === true) attrs += ' print-object="yes"';
663
+ if (clef.afterBarline) attrs += ' after-barline="yes"';
664
+ if (clef.color) attrs += ` color="${escapeXml(clef.color)}"`;
665
+ out.push(`${indent}<clef${attrs}>`);
666
+ out.push(`${indent} <sign>${clef.sign}</sign>`);
667
+ if (clef.line !== void 0) {
668
+ out.push(`${indent} <line>${clef.line}</line>`);
669
+ }
670
+ if (clef.clefOctaveChange !== void 0) {
671
+ out.push(`${indent} <clef-octave-change>${clef.clefOctaveChange}</clef-octave-change>`);
672
+ }
673
+ out.push(`${indent}</clef>`);
674
+ }
675
+ function serializeTranspose(transpose, indent, out) {
676
+ out.push(`${indent}<transpose>`);
677
+ out.push(`${indent} <diatonic>${transpose.diatonic}</diatonic>`);
678
+ out.push(`${indent} <chromatic>${transpose.chromatic}</chromatic>`);
679
+ if (transpose.octaveChange !== void 0) {
680
+ out.push(`${indent} <octave-change>${transpose.octaveChange}</octave-change>`);
681
+ }
682
+ out.push(`${indent}</transpose>`);
683
+ }
684
+ function serializeEntry(entry, indent, out) {
685
+ switch (entry.type) {
686
+ case "note":
687
+ serializeNote(entry, indent, out);
688
+ break;
689
+ case "backup":
690
+ serializeBackup(entry, indent, out);
691
+ break;
692
+ case "forward":
693
+ serializeForward(entry, indent, out);
694
+ break;
695
+ case "direction":
696
+ serializeDirection(entry, indent, out);
697
+ break;
698
+ case "harmony":
699
+ serializeHarmony(entry, indent, out);
700
+ break;
701
+ case "figured-bass":
702
+ serializeFiguredBass(entry, indent, out);
703
+ break;
704
+ case "sound":
705
+ serializeSound(entry, indent, out);
706
+ break;
707
+ case "attributes":
708
+ serializeAttributes(entry.attributes, indent, out, entry._id);
709
+ break;
710
+ case "grouping": {
711
+ const grp = entry;
712
+ let grpAttrs = ` type="${grp.groupingType}"`;
713
+ if (grp.number) grpAttrs += ` number="${grp.number}"`;
714
+ out.push(`${indent}<grouping${grpAttrs}/>`);
715
+ break;
716
+ }
717
+ default:
718
+ break;
719
+ }
720
+ }
721
+ function serializeNote(note, indent, out) {
722
+ let noteAttrs = note._id !== void 0 ? ` id="${escapeXml(note._id)}"` : "";
723
+ noteAttrs += positionAttrs(note);
724
+ if (note.dynamics !== void 0) noteAttrs += ` dynamics="${note.dynamics}"`;
725
+ if (note.printObject === false) noteAttrs += ' print-object="no"';
726
+ if (note.printDot !== void 0) noteAttrs += ` print-dot="${note.printDot ? "yes" : "no"}"`;
727
+ if (note.printSpacing !== void 0) noteAttrs += ` print-spacing="${note.printSpacing ? "yes" : "no"}"`;
728
+ noteAttrs += colorAttr(note.color);
729
+ out.push(`${indent}<note${noteAttrs}>`);
730
+ if (note.grace) {
731
+ const graceAttrs = buildAttrs({
732
+ "slash": note.grace.slash !== void 0 ? note.grace.slash : void 0,
733
+ "steal-time-previous": note.grace.stealTimePrevious,
734
+ "steal-time-following": note.grace.stealTimeFollowing
735
+ });
736
+ out.push(`${indent} <grace${graceAttrs}/>`);
737
+ }
738
+ if (note.cue) {
739
+ out.push(`${indent} <cue/>`);
740
+ }
741
+ if (note.chord) {
742
+ out.push(`${indent} <chord/>`);
743
+ }
744
+ if (note.pitch) {
745
+ serializePitch(note.pitch, indent + " ", out);
746
+ } else if (note.rest) {
747
+ let restAttrs = "";
748
+ if (note.rest.measure) restAttrs += ' measure="yes"';
749
+ if (note.rest.displayStep || note.rest.displayOctave !== void 0) {
750
+ out.push(`${indent} <rest${restAttrs}>`);
751
+ if (note.rest.displayStep) {
752
+ out.push(`${indent} <display-step>${note.rest.displayStep}</display-step>`);
753
+ }
754
+ if (note.rest.displayOctave !== void 0) {
755
+ out.push(`${indent} <display-octave>${note.rest.displayOctave}</display-octave>`);
756
+ }
757
+ out.push(`${indent} </rest>`);
758
+ } else {
759
+ out.push(`${indent} <rest${restAttrs}/>`);
760
+ }
761
+ } else if (note.unpitched) {
762
+ if (note.unpitched.displayStep || note.unpitched.displayOctave !== void 0) {
763
+ out.push(`${indent} <unpitched>`);
764
+ if (note.unpitched.displayStep) {
765
+ out.push(`${indent} <display-step>${note.unpitched.displayStep}</display-step>`);
766
+ }
767
+ if (note.unpitched.displayOctave !== void 0) {
768
+ out.push(`${indent} <display-octave>${note.unpitched.displayOctave}</display-octave>`);
769
+ }
770
+ out.push(`${indent} </unpitched>`);
771
+ } else {
772
+ out.push(`${indent} <unpitched/>`);
773
+ }
774
+ } else {
775
+ out.push(`${indent} <rest/>`);
776
+ }
777
+ if (!note.grace) {
778
+ out.push(`${indent} <duration>${note.duration}</duration>`);
779
+ }
780
+ if (note.ties && note.ties.length > 0) {
781
+ for (const tie of note.ties) {
782
+ out.push(`${indent} <tie type="${tie.type}"/>`);
783
+ }
784
+ } else if (note.tie) {
785
+ out.push(`${indent} <tie type="${note.tie.type}"/>`);
786
+ }
787
+ if (note.voice !== void 0) {
788
+ out.push(`${indent} <voice>${note.voice}</voice>`);
789
+ }
790
+ if (note.noteType) {
791
+ const typeAttrs = (note.noteTypeSize !== void 0 ? ` size="${escapeXml(note.noteTypeSize)}"` : "") + colorAttr(note.noteTypeColor);
792
+ out.push(`${indent} <type${typeAttrs}>${note.noteType}</type>`);
793
+ }
794
+ if (note.dots) {
795
+ const dotAttrs = note.dotColor ? ` color="${escapeXml(note.dotColor)}"` : "";
796
+ for (let i = 0; i < note.dots; i++) {
797
+ out.push(`${indent} <dot${dotAttrs}/>`);
798
+ }
799
+ }
800
+ if (note.accidental) {
801
+ const accAttrs = buildAttrs({
802
+ "cautionary": note.accidental.cautionary || void 0,
803
+ "editorial": note.accidental.editorial || void 0,
804
+ "parentheses": note.accidental.parentheses || void 0,
805
+ "bracket": note.accidental.bracket || void 0,
806
+ "default-x": note.accidental.defaultX,
807
+ "default-y": note.accidental.defaultY,
808
+ "relative-x": note.accidental.relativeX,
809
+ "relative-y": note.accidental.relativeY,
810
+ "color": note.accidental.color,
811
+ "size": note.accidental.size,
812
+ "font-size": note.accidental.fontSize
813
+ });
814
+ out.push(`${indent} <accidental${accAttrs}>${note.accidental.value}</accidental>`);
815
+ }
816
+ if (note.timeModification) {
817
+ out.push(`${indent} <time-modification>`);
818
+ out.push(`${indent} <actual-notes>${note.timeModification.actualNotes}</actual-notes>`);
819
+ out.push(`${indent} <normal-notes>${note.timeModification.normalNotes}</normal-notes>`);
820
+ if (note.timeModification.normalType) {
821
+ out.push(`${indent} <normal-type>${note.timeModification.normalType}</normal-type>`);
822
+ }
823
+ if (note.timeModification.normalDots) {
824
+ for (let i = 0; i < note.timeModification.normalDots; i++) {
825
+ out.push(`${indent} <normal-dot/>`);
826
+ }
827
+ }
828
+ out.push(`${indent} </time-modification>`);
829
+ }
830
+ if (note.stem) {
831
+ const stemAttrs = positionAttrs(note.stem) + colorAttr(note.stem.color);
832
+ out.push(`${indent} <stem${stemAttrs}>${note.stem.value}</stem>`);
833
+ }
834
+ if (note.notehead) {
835
+ let nhAttrs = note.notehead.filled !== void 0 ? ` filled="${note.notehead.filled ? "yes" : "no"}"` : "";
836
+ if (note.notehead.parentheses) nhAttrs += ' parentheses="yes"';
837
+ nhAttrs += colorAttr(note.notehead.color);
838
+ out.push(`${indent} <notehead${nhAttrs}>${note.notehead.value}</notehead>`);
839
+ }
840
+ if (note.staff !== void 0) {
841
+ out.push(`${indent} <staff>${note.staff}</staff>`);
842
+ }
843
+ if (note.instrument) {
844
+ out.push(`${indent} <instrument id="${escapeXml(note.instrument)}"/>`);
845
+ }
846
+ if (note.beam) {
847
+ for (const beam of note.beam) {
848
+ serializeBeam(beam, indent + " ", out);
849
+ }
850
+ }
851
+ if (note.notations && note.notations.length > 0) {
852
+ serializeNotations(note.notations, indent + " ", out);
853
+ }
854
+ if (note.lyrics) {
855
+ for (const lyric of note.lyrics) {
856
+ serializeLyric(lyric, indent + " ", out);
857
+ }
858
+ }
859
+ out.push(`${indent}</note>`);
860
+ }
861
+ function serializePitch(pitch, indent, out) {
862
+ const alter = pitch.alter !== void 0 && pitch.alter !== 0 ? `${indent} <alter>${pitch.alter}</alter>
863
+ ` : "";
864
+ out.push(`${indent}<pitch>
865
+ ${indent} <step>${pitch.step}</step>
866
+ ${alter}${indent} <octave>${pitch.octave}</octave>
867
+ ${indent}</pitch>`);
868
+ }
869
+ function serializeBeam(beam, indent, out) {
870
+ let beamAttrs = beam.fan ? ` fan="${beam.fan}"` : "";
871
+ if (beam.color) beamAttrs += ` color="${escapeXml(beam.color)}"`;
872
+ out.push(`${indent}<beam number="${beam.number}"${beamAttrs}>${beam.type}</beam>`);
873
+ }
874
+ function serializeNotations(notations, indent, out) {
875
+ const firstIndex = _nullishCoalesce(_optionalChain([notations, 'access', _ => _[0], 'optionalAccess', _2 => _2.notationsIndex]), () => ( 0));
876
+ if (notations.every((notation) => (_nullishCoalesce(notation.notationsIndex, () => ( 0))) === firstIndex)) {
877
+ serializeNotationsGroup(notations, indent, out);
878
+ return;
879
+ }
880
+ const notationsGroups = /* @__PURE__ */ new Map();
881
+ for (const notation of notations) {
882
+ const idx = _nullishCoalesce(notation.notationsIndex, () => ( 0));
883
+ if (!notationsGroups.has(idx)) {
884
+ notationsGroups.set(idx, []);
885
+ }
886
+ notationsGroups.get(idx).push(notation);
887
+ }
888
+ const sortedIndices = Array.from(notationsGroups.keys()).sort((a, b) => a - b);
889
+ for (const notationsIdx of sortedIndices) {
890
+ const groupNotations = notationsGroups.get(notationsIdx);
891
+ serializeNotationsGroup(groupNotations, indent, out);
892
+ }
893
+ }
894
+ function serializeNotationsGroup(notations, indent, out) {
895
+ out.push(`${indent}<notations>`);
896
+ for (let i = 0; i < notations.length; ) {
897
+ const notation = notations[i];
898
+ const type = notation.type;
899
+ if (type !== "articulation" && type !== "ornament" && type !== "technical") {
900
+ serializeStandaloneNotation(notation, indent, out);
901
+ i++;
902
+ continue;
903
+ }
904
+ let end = i + 1;
905
+ while (end < notations.length && notations[end].type === type && (type !== "articulation" || (_nullishCoalesce(notations[end].articulationsIndex, () => ( 0))) === (_nullishCoalesce(notation.articulationsIndex, () => ( 0))))) end++;
906
+ const items = i === 0 && end === notations.length ? notations : notations.slice(i, end);
907
+ if (type === "articulation") serializeArticulationsGroup(items, indent, out);
908
+ else if (type === "ornament") serializeOrnamentsGroup(items, indent, out);
909
+ else serializeTechnicalGroup(items, indent, out);
910
+ i = end;
911
+ }
912
+ out.push(`${indent}</notations>`);
913
+ }
914
+ function serializeStandaloneNotation(notation, indent, out) {
915
+ if (notation.type === "tied") {
916
+ let attrs = ` type="${notation.tiedType}"`;
917
+ if (notation.number !== void 0) attrs += ` number="${notation.number}"`;
918
+ if (notation.orientation) attrs += ` orientation="${notation.orientation}"`;
919
+ attrs += positionAttrs(notation);
920
+ attrs += bezierAttrs(notation);
921
+ attrs += colorAttr(notation.color);
922
+ out.push(`${indent} <tied${attrs}/>`);
923
+ } else if (notation.type === "slur") {
924
+ let attrs = "";
925
+ if (notation.number !== void 0) attrs += ` number="${notation.number}"`;
926
+ attrs += ` type="${notation.slurType}"`;
927
+ if (notation.lineType) attrs += ` line-type="${notation.lineType}"`;
928
+ if (notation.orientation) attrs += ` orientation="${notation.orientation}"`;
929
+ attrs += positionAttrs(notation);
930
+ attrs += bezierAttrs(notation);
931
+ if (notation.placement) attrs += ` placement="${notation.placement}"`;
932
+ attrs += colorAttr(notation.color);
933
+ out.push(`${indent} <slur${attrs}/>`);
934
+ } else if (notation.type === "tuplet") {
935
+ let attrs = ` type="${notation.tupletType}"`;
936
+ if (notation.number !== void 0) attrs += ` number="${notation.number}"`;
937
+ if (notation.bracket !== void 0) attrs += ` bracket="${notation.bracket ? "yes" : "no"}"`;
938
+ if (notation.showNumber) attrs += ` show-number="${notation.showNumber}"`;
939
+ if (notation.showType) attrs += ` show-type="${notation.showType}"`;
940
+ if (notation.lineShape) attrs += ` line-shape="${notation.lineShape}"`;
941
+ if (notation.placement) attrs += ` placement="${notation.placement}"`;
942
+ attrs += positionAttrs(notation);
943
+ const tup = notation;
944
+ if (tup.tupletActual || tup.tupletNormal) {
945
+ out.push(`${indent} <tuplet${attrs}>`);
946
+ if (tup.tupletActual) {
947
+ out.push(`${indent} <tuplet-actual>`);
948
+ if (tup.tupletActual.tupletNumber !== void 0) {
949
+ out.push(`${indent} <tuplet-number>${tup.tupletActual.tupletNumber}</tuplet-number>`);
950
+ }
951
+ if (tup.tupletActual.tupletType) {
952
+ out.push(`${indent} <tuplet-type>${tup.tupletActual.tupletType}</tuplet-type>`);
953
+ }
954
+ if (tup.tupletActual.tupletDots) {
955
+ for (let i = 0; i < tup.tupletActual.tupletDots; i++) {
956
+ out.push(`${indent} <tuplet-dot/>`);
957
+ }
958
+ }
959
+ out.push(`${indent} </tuplet-actual>`);
960
+ }
961
+ if (tup.tupletNormal) {
962
+ out.push(`${indent} <tuplet-normal>`);
963
+ if (tup.tupletNormal.tupletNumber !== void 0) {
964
+ out.push(`${indent} <tuplet-number>${tup.tupletNormal.tupletNumber}</tuplet-number>`);
965
+ }
966
+ if (tup.tupletNormal.tupletType) {
967
+ out.push(`${indent} <tuplet-type>${tup.tupletNormal.tupletType}</tuplet-type>`);
968
+ }
969
+ if (tup.tupletNormal.tupletDots) {
970
+ for (let i = 0; i < tup.tupletNormal.tupletDots; i++) {
971
+ out.push(`${indent} <tuplet-dot/>`);
972
+ }
973
+ }
974
+ out.push(`${indent} </tuplet-normal>`);
975
+ }
976
+ out.push(`${indent} </tuplet>`);
977
+ } else {
978
+ out.push(`${indent} <tuplet${attrs}/>`);
979
+ }
980
+ } else if (notation.type === "dynamics") {
981
+ const dynAttrs = (notation.placement ? ` placement="${notation.placement}"` : "") + colorAttr(notation.color);
982
+ out.push(`${indent} <dynamics${dynAttrs}>`);
983
+ for (const dyn of notation.dynamics) {
984
+ out.push(`${indent} <${dyn}/>`);
985
+ }
986
+ if (notation.otherDynamics) {
987
+ out.push(`${indent} <other-dynamics>${escapeXml(notation.otherDynamics)}</other-dynamics>`);
988
+ }
989
+ out.push(`${indent} </dynamics>`);
990
+ } else if (notation.type === "fermata") {
991
+ let attrs = "";
992
+ if (notation.fermataType) attrs += ` type="${notation.fermataType}"`;
993
+ if (notation.placement) attrs += ` placement="${notation.placement}"`;
994
+ attrs += positionAttrs(notation);
995
+ attrs += colorAttr(notation.color);
996
+ if (notation.shape) {
997
+ out.push(`${indent} <fermata${attrs}>${notation.shape}</fermata>`);
998
+ } else {
999
+ out.push(`${indent} <fermata${attrs}/>`);
1000
+ }
1001
+ } else if (notation.type === "arpeggiate") {
1002
+ let attrs = "";
1003
+ if (notation.direction) attrs += ` direction="${notation.direction}"`;
1004
+ if (notation.number !== void 0) attrs += ` number="${notation.number}"`;
1005
+ attrs += positionAttrs(notation);
1006
+ attrs += colorAttr(notation.color);
1007
+ out.push(`${indent} <arpeggiate${attrs}/>`);
1008
+ } else if (notation.type === "non-arpeggiate") {
1009
+ let attrs = ` type="${notation.nonArpeggiateType}"`;
1010
+ if (notation.number !== void 0) attrs += ` number="${notation.number}"`;
1011
+ if (notation.placement) attrs += ` placement="${notation.placement}"`;
1012
+ attrs += colorAttr(notation.color);
1013
+ out.push(`${indent} <non-arpeggiate${attrs}/>`);
1014
+ } else if (notation.type === "accidental-mark") {
1015
+ let attrs = "";
1016
+ if (notation.placement) attrs += ` placement="${notation.placement}"`;
1017
+ attrs += positionAttrs(notation);
1018
+ attrs += colorAttr(notation.color);
1019
+ out.push(`${indent} <accidental-mark${attrs}>${escapeXml(notation.value)}</accidental-mark>`);
1020
+ } else if (notation.type === "glissando") {
1021
+ let attrs = ` type="${notation.glissandoType}"`;
1022
+ if (notation.number !== void 0) attrs += ` number="${notation.number}"`;
1023
+ if (notation.lineType) attrs += ` line-type="${notation.lineType}"`;
1024
+ attrs += colorAttr(notation.color);
1025
+ if (notation.text) {
1026
+ out.push(`${indent} <glissando${attrs}>${escapeXml(notation.text)}</glissando>`);
1027
+ } else {
1028
+ out.push(`${indent} <glissando${attrs}/>`);
1029
+ }
1030
+ } else if (notation.type === "slide") {
1031
+ let attrs = ` type="${notation.slideType}"`;
1032
+ if (notation.number !== void 0) attrs += ` number="${notation.number}"`;
1033
+ if (notation.lineType) attrs += ` line-type="${notation.lineType}"`;
1034
+ attrs += colorAttr(notation.color);
1035
+ if (notation.text) {
1036
+ out.push(`${indent} <slide${attrs}>${escapeXml(notation.text)}</slide>`);
1037
+ } else {
1038
+ out.push(`${indent} <slide${attrs}/>`);
1039
+ }
1040
+ }
1041
+ }
1042
+ function serializeArticulationsGroup(artGroup, indent, out) {
1043
+ out.push(`${indent} <articulations>`);
1044
+ for (const art of artGroup) {
1045
+ if (art.type === "articulation") {
1046
+ let artAttrs = art.placement ? ` placement="${art.placement}"` : "";
1047
+ if (art.articulation === "strong-accent" && art.strongAccentType) {
1048
+ artAttrs += ` type="${art.strongAccentType}"`;
1049
+ }
1050
+ artAttrs += positionAttrs(art);
1051
+ artAttrs += colorAttr(art.color);
1052
+ out.push(`${indent} <${art.articulation}${artAttrs}/>`);
1053
+ }
1054
+ }
1055
+ out.push(`${indent} </articulations>`);
1056
+ }
1057
+ function serializeOrnamentsGroup(ornaments, indent, out) {
1058
+ const hasOnlyEmptyMarker = ornaments.length === 1 && ornaments[0].type === "ornament" && ornaments[0].ornament === "empty";
1059
+ if (hasOnlyEmptyMarker) {
1060
+ out.push(`${indent} <ornaments/>`);
1061
+ } else {
1062
+ out.push(`${indent} <ornaments>`);
1063
+ const allAccidentalMarks = [];
1064
+ for (const orn of ornaments) {
1065
+ if (orn.type === "ornament") {
1066
+ if (orn.ornament === "empty") continue;
1067
+ const placementAttr = orn.placement ? ` placement="${orn.placement}"` : "";
1068
+ if (orn.ornament === "wavy-line") {
1069
+ let wlAttrs = "";
1070
+ if (orn.wavyLineType) wlAttrs += ` type="${orn.wavyLineType}"`;
1071
+ if (orn.number !== void 0) wlAttrs += ` number="${orn.number}"`;
1072
+ wlAttrs += placementAttr;
1073
+ wlAttrs += positionAttrs(orn);
1074
+ wlAttrs += colorAttr(orn.color);
1075
+ out.push(`${indent} <wavy-line${wlAttrs}/>`);
1076
+ } else if (orn.ornament === "tremolo") {
1077
+ let tremAttrs = "";
1078
+ if (orn.tremoloType) tremAttrs += ` type="${orn.tremoloType}"`;
1079
+ tremAttrs += placementAttr;
1080
+ tremAttrs += positionAttrs(orn);
1081
+ tremAttrs += colorAttr(orn.color);
1082
+ if (orn.tremoloMarks !== void 0) {
1083
+ out.push(`${indent} <tremolo${tremAttrs}>${orn.tremoloMarks}</tremolo>`);
1084
+ } else {
1085
+ out.push(`${indent} <tremolo${tremAttrs}/>`);
1086
+ }
1087
+ } else {
1088
+ let ornAttrs = placementAttr;
1089
+ ornAttrs += positionAttrs(orn);
1090
+ ornAttrs += colorAttr(orn.color);
1091
+ out.push(`${indent} <${orn.ornament}${ornAttrs}/>`);
1092
+ }
1093
+ if (orn.accidentalMarks) {
1094
+ allAccidentalMarks.push(...orn.accidentalMarks);
1095
+ }
1096
+ }
1097
+ }
1098
+ for (const am of allAccidentalMarks) {
1099
+ const amAttrs = (am.placement ? ` placement="${am.placement}"` : "") + positionAttrs(am) + colorAttr(am.color);
1100
+ out.push(`${indent} <accidental-mark${amAttrs}>${am.value}</accidental-mark>`);
1101
+ }
1102
+ out.push(`${indent} </ornaments>`);
1103
+ }
1104
+ }
1105
+ function serializeTechnicalGroup(technicals, indent, out) {
1106
+ out.push(`${indent} <technical>`);
1107
+ for (const tech of technicals) {
1108
+ if (tech.type === "technical") {
1109
+ let placementAttr = tech.placement ? ` placement="${tech.placement}"` : "";
1110
+ const techNotation = tech;
1111
+ placementAttr += positionAttrs(techNotation);
1112
+ if (techNotation.fontSize !== void 0) placementAttr += ` font-size="${techNotation.fontSize}"`;
1113
+ placementAttr += colorAttr(techNotation.color);
1114
+ if (tech.technical === "bend" && (techNotation.bendAlter !== void 0 || techNotation.preBend || techNotation.release)) {
1115
+ out.push(`${indent} <bend${placementAttr}>`);
1116
+ if (techNotation.bendAlter !== void 0) {
1117
+ out.push(`${indent} <bend-alter>${techNotation.bendAlter}</bend-alter>`);
1118
+ }
1119
+ if (techNotation.preBend) {
1120
+ out.push(`${indent} <pre-bend/>`);
1121
+ }
1122
+ if (techNotation.release) {
1123
+ out.push(`${indent} <release/>`);
1124
+ }
1125
+ if (techNotation.withBar) {
1126
+ out.push(`${indent} <with-bar/>`);
1127
+ }
1128
+ out.push(`${indent} </bend>`);
1129
+ } else if (tech.technical === "harmonic") {
1130
+ const hasChildren = techNotation.harmonicNatural || techNotation.harmonicArtificial || techNotation.basePitch || techNotation.touchingPitch || techNotation.soundingPitch;
1131
+ if (hasChildren) {
1132
+ out.push(`${indent} <harmonic${placementAttr}>`);
1133
+ if (techNotation.harmonicNatural) out.push(`${indent} <natural/>`);
1134
+ if (techNotation.harmonicArtificial) out.push(`${indent} <artificial/>`);
1135
+ if (techNotation.basePitch) out.push(`${indent} <base-pitch/>`);
1136
+ if (techNotation.touchingPitch) out.push(`${indent} <touching-pitch/>`);
1137
+ if (techNotation.soundingPitch) out.push(`${indent} <sounding-pitch/>`);
1138
+ out.push(`${indent} </harmonic>`);
1139
+ } else {
1140
+ out.push(`${indent} <harmonic${placementAttr}/>`);
1141
+ }
1142
+ } else if (tech.technical === "hammer-on" || tech.technical === "pull-off") {
1143
+ let attrs = "";
1144
+ if (techNotation.number !== void 0) attrs += ` number="${techNotation.number}"`;
1145
+ if (techNotation.startStop) attrs += ` type="${techNotation.startStop}"`;
1146
+ attrs += placementAttr;
1147
+ if (techNotation.text !== void 0) {
1148
+ out.push(`${indent} <${tech.technical}${attrs}>${escapeXml(techNotation.text)}</${tech.technical}>`);
1149
+ } else {
1150
+ out.push(`${indent} <${tech.technical}${attrs}/>`);
1151
+ }
1152
+ } else if (tech.technical === "string" && techNotation.string !== void 0) {
1153
+ out.push(`${indent} <string${placementAttr}>${techNotation.string}</string>`);
1154
+ } else if (tech.technical === "fret" && techNotation.fret !== void 0) {
1155
+ out.push(`${indent} <fret${placementAttr}>${techNotation.fret}</fret>`);
1156
+ } else if (tech.technical === "fingering") {
1157
+ let fAttrs = placementAttr;
1158
+ if (techNotation.fingeringSubstitution) fAttrs += ' substitution="yes"';
1159
+ if (techNotation.fingeringAlternate) fAttrs += ' alternate="yes"';
1160
+ if (techNotation.text !== void 0) {
1161
+ out.push(`${indent} <fingering${fAttrs}>${escapeXml(techNotation.text)}</fingering>`);
1162
+ } else {
1163
+ out.push(`${indent} <fingering${fAttrs}/>`);
1164
+ }
1165
+ } else if (tech.technical === "heel" || tech.technical === "toe") {
1166
+ let htAttrs = placementAttr;
1167
+ if (techNotation.substitution) htAttrs += ' substitution="yes"';
1168
+ out.push(`${indent} <${tech.technical}${htAttrs}/>`);
1169
+ } else if (techNotation.text !== void 0) {
1170
+ out.push(`${indent} <${tech.technical}${placementAttr}>${escapeXml(techNotation.text)}</${tech.technical}>`);
1171
+ } else {
1172
+ out.push(`${indent} <${tech.technical}${placementAttr}/>`);
1173
+ }
1174
+ }
1175
+ }
1176
+ out.push(`${indent} </technical>`);
1177
+ }
1178
+ function serializeLyric(lyric, indent, out) {
1179
+ let attrs = "";
1180
+ const number = _nullishCoalesce(lyric.numberText, () => ( (lyric.number !== void 0 ? String(lyric.number) : void 0)));
1181
+ if (number !== void 0) attrs += ` number="${escapeXml(number)}"`;
1182
+ if (lyric.name) attrs += ` name="${escapeXml(lyric.name)}"`;
1183
+ attrs += positionAttrs(lyric);
1184
+ if (lyric.justify) attrs += ` justify="${escapeXml(lyric.justify)}"`;
1185
+ if (lyric.placement) attrs += ` placement="${lyric.placement}"`;
1186
+ attrs += colorAttr(lyric.color);
1187
+ out.push(`${indent}<lyric${attrs}>`);
1188
+ if (lyric.textElements && lyric.textElements.length > 1) {
1189
+ for (let i = 0; i < lyric.textElements.length; i++) {
1190
+ const te = lyric.textElements[i];
1191
+ if (te.syllabic) {
1192
+ out.push(`${indent} <syllabic>${te.syllabic}</syllabic>`);
1193
+ }
1194
+ out.push(`${indent} <text${colorAttr(te.color)}>${escapeXml(te.text)}</text>`);
1195
+ if (i < lyric.textElements.length - 1) {
1196
+ out.push(`${indent} <elision/>`);
1197
+ }
1198
+ }
1199
+ } else if (lyric.syllabic || lyric.text) {
1200
+ if (lyric.syllabic) {
1201
+ out.push(`${indent} <syllabic>${lyric.syllabic}</syllabic>`);
1202
+ }
1203
+ const textColor = _nullishCoalesce(lyric.textColor, () => ( _optionalChain([lyric, 'access', _3 => _3.textElements, 'optionalAccess', _4 => _4[0], 'optionalAccess', _5 => _5.color])));
1204
+ out.push(`${indent} <text${colorAttr(textColor)}>${escapeXml(lyric.text)}</text>`);
1205
+ }
1206
+ if (lyric.extend) {
1207
+ if (typeof lyric.extend === "object") {
1208
+ const extendAttrs = (lyric.extend.type ? ` type="${lyric.extend.type}"` : "") + colorAttr(lyric.extend.color);
1209
+ out.push(`${indent} <extend${extendAttrs}/>`);
1210
+ } else {
1211
+ out.push(`${indent} <extend/>`);
1212
+ }
1213
+ }
1214
+ if (lyric.endLine) {
1215
+ out.push(`${indent} <end-line/>`);
1216
+ }
1217
+ if (lyric.endParagraph) {
1218
+ out.push(`${indent} <end-paragraph/>`);
1219
+ }
1220
+ out.push(`${indent}</lyric>`);
1221
+ }
1222
+ function serializeBackup(backup, indent, out) {
1223
+ out.push(`${indent}<backup>`);
1224
+ out.push(`${indent} <duration>${backup.duration}</duration>`);
1225
+ out.push(`${indent}</backup>`);
1226
+ }
1227
+ function serializeForward(forward, indent, out) {
1228
+ const idAttr = forward._id ? ` id="${escapeXml(forward._id)}"` : "";
1229
+ out.push(`${indent}<forward${idAttr}>`);
1230
+ out.push(`${indent} <duration>${forward.duration}</duration>`);
1231
+ if (forward.voice !== void 0) {
1232
+ out.push(`${indent} <voice>${forward.voice}</voice>`);
1233
+ }
1234
+ if (forward.staff !== void 0) {
1235
+ out.push(`${indent} <staff>${forward.staff}</staff>`);
1236
+ }
1237
+ out.push(`${indent}</forward>`);
1238
+ }
1239
+ function serializeDirection(direction, indent, out) {
1240
+ let attrs = "";
1241
+ if (direction._id) attrs += ` id="${escapeXml(direction._id)}"`;
1242
+ if (direction.placement) attrs += ` placement="${direction.placement}"`;
1243
+ if (direction.directive) attrs += ' directive="yes"';
1244
+ if (direction.system) attrs += ` system="${direction.system}"`;
1245
+ out.push(`${indent}<direction${attrs}>`);
1246
+ for (const dirType of direction.directionTypes) {
1247
+ serializeDirectionType(dirType, indent + " ", out);
1248
+ }
1249
+ if (direction.offset !== void 0) {
1250
+ const soundAttr = direction.offsetSound ? ' sound="yes"' : "";
1251
+ out.push(`${indent} <offset${soundAttr}>${direction.offset}</offset>`);
1252
+ }
1253
+ if (direction.staff !== void 0) {
1254
+ out.push(`${indent} <staff>${direction.staff}</staff>`);
1255
+ }
1256
+ if (direction.sound) {
1257
+ const attrs2 = [];
1258
+ if (direction.sound.tempo !== void 0) {
1259
+ attrs2.push(`tempo="${direction.sound.tempo}"`);
1260
+ }
1261
+ if (direction.sound.dynamics !== void 0) {
1262
+ attrs2.push(`dynamics="${direction.sound.dynamics}"`);
1263
+ }
1264
+ if (direction.sound.damperPedal) {
1265
+ attrs2.push(`damper-pedal="${direction.sound.damperPedal}"`);
1266
+ }
1267
+ if (direction.sound.softPedal) {
1268
+ attrs2.push(`soft-pedal="${direction.sound.softPedal}"`);
1269
+ }
1270
+ if (direction.sound.sostenutoPedal) {
1271
+ attrs2.push(`sostenuto-pedal="${direction.sound.sostenutoPedal}"`);
1272
+ }
1273
+ const attrStr = attrs2.length > 0 ? ` ${attrs2.join(" ")}` : "";
1274
+ if (direction.sound.midiInstrument) {
1275
+ out.push(`${indent} <sound${attrStr}>`);
1276
+ const midi = direction.sound.midiInstrument;
1277
+ out.push(`${indent} <midi-instrument id="${escapeXml(midi.id)}">`);
1278
+ if (midi.midiChannel !== void 0) {
1279
+ out.push(`${indent} <midi-channel>${midi.midiChannel}</midi-channel>`);
1280
+ }
1281
+ if (midi.midiProgram !== void 0) {
1282
+ out.push(`${indent} <midi-program>${midi.midiProgram}</midi-program>`);
1283
+ }
1284
+ if (midi.volume !== void 0) {
1285
+ out.push(`${indent} <volume>${midi.volume}</volume>`);
1286
+ }
1287
+ if (midi.pan !== void 0) {
1288
+ out.push(`${indent} <pan>${midi.pan}</pan>`);
1289
+ }
1290
+ out.push(`${indent} </midi-instrument>`);
1291
+ out.push(`${indent} </sound>`);
1292
+ } else if (attrs2.length > 0) {
1293
+ out.push(`${indent} <sound${attrStr}/>`);
1294
+ }
1295
+ }
1296
+ out.push(`${indent}</direction>`);
1297
+ }
1298
+ function serializeDirectionType(dirType, indent, out) {
1299
+ out.push(`${indent}<direction-type>`);
1300
+ switch (dirType.kind) {
1301
+ case "dynamics": {
1302
+ let dynAttrs = positionAttrs(dirType);
1303
+ if (dirType.halign) dynAttrs += ` halign="${dirType.halign}"`;
1304
+ dynAttrs += colorAttr(dirType.color);
1305
+ out.push(`${indent} <dynamics${dynAttrs}>`);
1306
+ if (dirType.value) {
1307
+ out.push(`${indent} <${dirType.value}/>`);
1308
+ }
1309
+ if (dirType.otherDynamics) {
1310
+ out.push(`${indent} <other-dynamics>${escapeXml(dirType.otherDynamics)}</other-dynamics>`);
1311
+ }
1312
+ out.push(`${indent} </dynamics>`);
1313
+ break;
1314
+ }
1315
+ case "wedge": {
1316
+ let wedgeAttrs = ` type="${dirType.type}"`;
1317
+ if (dirType.spread !== void 0) wedgeAttrs += ` spread="${dirType.spread}"`;
1318
+ wedgeAttrs += positionAttrs(dirType);
1319
+ wedgeAttrs += colorAttr(dirType.color);
1320
+ out.push(`${indent} <wedge${wedgeAttrs}/>`);
1321
+ break;
1322
+ }
1323
+ case "metronome": {
1324
+ let metAttrs = "";
1325
+ if (dirType.printObject === false) metAttrs += ' print-object="no"';
1326
+ if (dirType.parentheses) metAttrs += ' parentheses="yes"';
1327
+ metAttrs += positionAttrs(dirType);
1328
+ if (dirType.fontFamily) metAttrs += ` font-family="${escapeXml(dirType.fontFamily)}"`;
1329
+ if (dirType.fontSize) metAttrs += ` font-size="${escapeXml(dirType.fontSize)}"`;
1330
+ metAttrs += colorAttr(dirType.color);
1331
+ out.push(`${indent} <metronome${metAttrs}>`);
1332
+ out.push(`${indent} <beat-unit>${dirType.beatUnit}</beat-unit>`);
1333
+ if (dirType.beatUnitDot) {
1334
+ out.push(`${indent} <beat-unit-dot/>`);
1335
+ }
1336
+ if (dirType.beatUnit2) {
1337
+ out.push(`${indent} <beat-unit>${dirType.beatUnit2}</beat-unit>`);
1338
+ if (dirType.beatUnitDot2) {
1339
+ out.push(`${indent} <beat-unit-dot/>`);
1340
+ }
1341
+ }
1342
+ if (dirType.perMinute !== void 0) {
1343
+ out.push(`${indent} <per-minute>${dirType.perMinute}</per-minute>`);
1344
+ }
1345
+ out.push(`${indent} </metronome>`);
1346
+ break;
1347
+ }
1348
+ case "words": {
1349
+ let wordAttrs = positionAttrs(dirType);
1350
+ if (dirType.fontFamily) wordAttrs += ` font-family="${escapeXml(dirType.fontFamily)}"`;
1351
+ if (dirType.fontSize) wordAttrs += ` font-size="${escapeXml(dirType.fontSize)}"`;
1352
+ if (dirType.fontStyle) wordAttrs += ` font-style="${escapeXml(dirType.fontStyle)}"`;
1353
+ if (dirType.fontWeight) wordAttrs += ` font-weight="${escapeXml(dirType.fontWeight)}"`;
1354
+ if (dirType.xmlLang) wordAttrs += ` xml:lang="${escapeXml(dirType.xmlLang)}"`;
1355
+ if (dirType.justify) wordAttrs += ` justify="${escapeXml(dirType.justify)}"`;
1356
+ if (dirType.color) wordAttrs += ` color="${escapeXml(dirType.color)}"`;
1357
+ if (dirType.xmlSpace) wordAttrs += ` xml:space="${escapeXml(dirType.xmlSpace)}"`;
1358
+ if (dirType.halign) wordAttrs += ` halign="${escapeXml(dirType.halign)}"`;
1359
+ out.push(`${indent} <words${wordAttrs}>${escapeXml(dirType.text)}</words>`);
1360
+ break;
1361
+ }
1362
+ case "rehearsal": {
1363
+ let rehAttrs = "";
1364
+ if (dirType.enclosure) rehAttrs += ` enclosure="${escapeXml(dirType.enclosure)}"`;
1365
+ rehAttrs += positionAttrs(dirType);
1366
+ if (dirType.fontSize) rehAttrs += ` font-size="${escapeXml(dirType.fontSize)}"`;
1367
+ if (dirType.fontWeight) rehAttrs += ` font-weight="${escapeXml(dirType.fontWeight)}"`;
1368
+ rehAttrs += colorAttr(dirType.color);
1369
+ out.push(`${indent} <rehearsal${rehAttrs}>${escapeXml(dirType.text)}</rehearsal>`);
1370
+ break;
1371
+ }
1372
+ case "bracket": {
1373
+ let bracketAttrs = ` type="${dirType.type}"`;
1374
+ if (dirType.number !== void 0) bracketAttrs += ` number="${dirType.number}"`;
1375
+ if (dirType.lineEnd) bracketAttrs += ` line-end="${dirType.lineEnd}"`;
1376
+ if (dirType.lineType) bracketAttrs += ` line-type="${dirType.lineType}"`;
1377
+ bracketAttrs += positionAttrs(dirType);
1378
+ bracketAttrs += colorAttr(dirType.color);
1379
+ out.push(`${indent} <bracket${bracketAttrs}/>`);
1380
+ break;
1381
+ }
1382
+ case "dashes": {
1383
+ let dashAttrs = ` type="${dirType.type}"`;
1384
+ if (dirType.number !== void 0) dashAttrs += ` number="${dirType.number}"`;
1385
+ if (dirType.dashLength !== void 0) dashAttrs += ` dash-length="${dirType.dashLength}"`;
1386
+ if (dirType.spaceLength !== void 0) dashAttrs += ` space-length="${dirType.spaceLength}"`;
1387
+ dashAttrs += positionAttrs(dirType);
1388
+ dashAttrs += colorAttr(dirType.color);
1389
+ out.push(`${indent} <dashes${dashAttrs}/>`);
1390
+ break;
1391
+ }
1392
+ case "accordion-registration":
1393
+ out.push(`${indent} <accordion-registration${positionAttrs(dirType)}${colorAttr(dirType.color)}>`);
1394
+ if (dirType.high) {
1395
+ out.push(`${indent} <accordion-high/>`);
1396
+ }
1397
+ if (dirType.middlePresent || dirType.middle !== void 0) {
1398
+ if (dirType.middle !== void 0) {
1399
+ out.push(`${indent} <accordion-middle>${dirType.middle}</accordion-middle>`);
1400
+ } else {
1401
+ out.push(`${indent} <accordion-middle/>`);
1402
+ }
1403
+ }
1404
+ if (dirType.low) {
1405
+ out.push(`${indent} <accordion-low/>`);
1406
+ }
1407
+ out.push(`${indent} </accordion-registration>`);
1408
+ break;
1409
+ case "other-direction":
1410
+ {
1411
+ let otherAttrs = positionAttrs(dirType);
1412
+ if (dirType.halign) otherAttrs += ` halign="${escapeXml(dirType.halign)}"`;
1413
+ if (dirType.printObject === false) otherAttrs += ' print-object="no"';
1414
+ otherAttrs += colorAttr(dirType.color);
1415
+ out.push(`${indent} <other-direction${otherAttrs}>${escapeXml(dirType.text)}</other-direction>`);
1416
+ }
1417
+ break;
1418
+ case "segno":
1419
+ out.push(`${indent} <segno${positionAttrs(dirType)}${colorAttr(dirType.color)}/>`);
1420
+ break;
1421
+ case "coda":
1422
+ out.push(`${indent} <coda${positionAttrs(dirType)}${colorAttr(dirType.color)}/>`);
1423
+ break;
1424
+ case "eyeglasses":
1425
+ out.push(`${indent} <eyeglasses${positionAttrs(dirType)}${colorAttr(dirType.color)}/>`);
1426
+ break;
1427
+ case "damp":
1428
+ out.push(`${indent} <damp${positionAttrs(dirType)}${colorAttr(dirType.color)}/>`);
1429
+ break;
1430
+ case "damp-all":
1431
+ out.push(`${indent} <damp-all${positionAttrs(dirType)}${colorAttr(dirType.color)}/>`);
1432
+ break;
1433
+ case "scordatura":
1434
+ if (dirType.accords && dirType.accords.length > 0) {
1435
+ out.push(`${indent} <scordatura${colorAttr(dirType.color)}>`);
1436
+ for (const accord of dirType.accords) {
1437
+ out.push(`${indent} <accord string="${accord.string}">`);
1438
+ out.push(`${indent} <tuning-step>${accord.tuningStep}</tuning-step>`);
1439
+ if (accord.tuningAlter !== void 0) {
1440
+ out.push(`${indent} <tuning-alter>${accord.tuningAlter}</tuning-alter>`);
1441
+ }
1442
+ out.push(`${indent} <tuning-octave>${accord.tuningOctave}</tuning-octave>`);
1443
+ out.push(`${indent} </accord>`);
1444
+ }
1445
+ out.push(`${indent} </scordatura>`);
1446
+ } else {
1447
+ out.push(`${indent} <scordatura${colorAttr(dirType.color)}/>`);
1448
+ }
1449
+ break;
1450
+ case "harp-pedals":
1451
+ if (dirType.pedalTunings && dirType.pedalTunings.length > 0) {
1452
+ out.push(`${indent} <harp-pedals${positionAttrs(dirType)}${colorAttr(dirType.color)}>`);
1453
+ for (const pt of dirType.pedalTunings) {
1454
+ out.push(`${indent} <pedal-tuning>`);
1455
+ out.push(`${indent} <pedal-step>${pt.pedalStep}</pedal-step>`);
1456
+ out.push(`${indent} <pedal-alter>${pt.pedalAlter}</pedal-alter>`);
1457
+ out.push(`${indent} </pedal-tuning>`);
1458
+ }
1459
+ out.push(`${indent} </harp-pedals>`);
1460
+ } else {
1461
+ out.push(`${indent} <harp-pedals${positionAttrs(dirType)}${colorAttr(dirType.color)}/>`);
1462
+ }
1463
+ break;
1464
+ case "image":
1465
+ let imgAttrs = "";
1466
+ if (dirType.source) imgAttrs += ` source="${escapeXml(dirType.source)}"`;
1467
+ if (dirType.type) imgAttrs += ` type="${escapeXml(dirType.type)}"`;
1468
+ imgAttrs += positionAttrs(dirType);
1469
+ out.push(`${indent} <image${imgAttrs}/>`);
1470
+ break;
1471
+ case "pedal": {
1472
+ let pedalAttrs = ` type="${dirType.type}"`;
1473
+ if (dirType.line !== void 0) pedalAttrs += ` line="${dirType.line ? "yes" : "no"}"`;
1474
+ pedalAttrs += positionAttrs(dirType);
1475
+ if (dirType.halign) pedalAttrs += ` halign="${dirType.halign}"`;
1476
+ pedalAttrs += colorAttr(dirType.color);
1477
+ out.push(`${indent} <pedal${pedalAttrs}/>`);
1478
+ break;
1479
+ }
1480
+ case "octave-shift": {
1481
+ const sizeAttr = dirType.size !== void 0 ? ` size="${dirType.size}"` : "";
1482
+ out.push(`${indent} <octave-shift type="${dirType.type}"${sizeAttr}${positionAttrs(dirType)}${colorAttr(dirType.color)}/>`);
1483
+ break;
1484
+ }
1485
+ case "swing":
1486
+ out.push(`${indent} <swing>`);
1487
+ if (dirType.straight) {
1488
+ out.push(`${indent} <straight/>`);
1489
+ } else {
1490
+ if (dirType.first !== void 0) {
1491
+ out.push(`${indent} <first>${dirType.first}</first>`);
1492
+ }
1493
+ if (dirType.second !== void 0) {
1494
+ out.push(`${indent} <second>${dirType.second}</second>`);
1495
+ }
1496
+ if (dirType.swingType) {
1497
+ out.push(`${indent} <swing-type>${dirType.swingType}</swing-type>`);
1498
+ }
1499
+ }
1500
+ out.push(`${indent} </swing>`);
1501
+ break;
1502
+ }
1503
+ out.push(`${indent}</direction-type>`);
1504
+ }
1505
+ function serializeBarline(barline, indent, out) {
1506
+ let attrs = ` location="${barline.location}"`;
1507
+ if (barline._id) attrs += ` id="${escapeXml(barline._id)}"`;
1508
+ out.push(`${indent}<barline${attrs}>`);
1509
+ if (barline.barStyle) {
1510
+ out.push(`${indent} <bar-style${colorAttr(barline.barStyleColor)}>${barline.barStyle}</bar-style>`);
1511
+ }
1512
+ if (barline.ending) {
1513
+ let endingAttrs = ` number="${barline.ending.number}" type="${barline.ending.type}"`;
1514
+ endingAttrs += positionAttrs(barline.ending);
1515
+ if (barline.ending.endLength !== void 0) endingAttrs += ` end-length="${barline.ending.endLength}"`;
1516
+ endingAttrs += colorAttr(barline.ending.color);
1517
+ if (barline.ending.text) {
1518
+ out.push(`${indent} <ending${endingAttrs}>${escapeXml(barline.ending.text)}</ending>`);
1519
+ } else {
1520
+ out.push(`${indent} <ending${endingAttrs}/>`);
1521
+ }
1522
+ }
1523
+ if (barline.repeat) {
1524
+ let repeatAttrs = ` direction="${barline.repeat.direction}"`;
1525
+ if (barline.repeat.times !== void 0) repeatAttrs += ` times="${barline.repeat.times}"`;
1526
+ if (barline.repeat.winged) repeatAttrs += ` winged="${barline.repeat.winged}"`;
1527
+ out.push(`${indent} <repeat${repeatAttrs}/>`);
1528
+ }
1529
+ out.push(`${indent}</barline>`);
1530
+ }
1531
+ var XML_ESCAPE_RE = /[&<>"']/g;
1532
+ var XML_ESCAPE_MAP = {
1533
+ "&": "&amp;",
1534
+ "<": "&lt;",
1535
+ ">": "&gt;",
1536
+ '"': "&quot;",
1537
+ "'": "&apos;"
1538
+ };
1539
+ var XML_ESCAPE_TEST = /[&<>"']/;
1540
+ function escapeXml(str) {
1541
+ if (!XML_ESCAPE_TEST.test(str)) return str;
1542
+ return str.replace(XML_ESCAPE_RE, (ch) => XML_ESCAPE_MAP[ch]);
1543
+ }
1544
+ function colorAttr(color) {
1545
+ return color ? ` color="${escapeXml(color)}"` : "";
1546
+ }
1547
+ function positionAttrs(p) {
1548
+ let result = "";
1549
+ if (p.defaultX !== void 0) result += ` default-x="${p.defaultX}"`;
1550
+ if (p.defaultY !== void 0) result += ` default-y="${p.defaultY}"`;
1551
+ if (p.relativeX !== void 0) result += ` relative-x="${p.relativeX}"`;
1552
+ if (p.relativeY !== void 0) result += ` relative-y="${p.relativeY}"`;
1553
+ return result;
1554
+ }
1555
+ function bezierAttrs(b) {
1556
+ let result = "";
1557
+ if (b.bezierX !== void 0) result += ` bezier-x="${b.bezierX}"`;
1558
+ if (b.bezierY !== void 0) result += ` bezier-y="${b.bezierY}"`;
1559
+ if (b.bezierX2 !== void 0) result += ` bezier-x2="${b.bezierX2}"`;
1560
+ if (b.bezierY2 !== void 0) result += ` bezier-y2="${b.bezierY2}"`;
1561
+ if (b.bezierOffset !== void 0) result += ` bezier-offset="${b.bezierOffset}"`;
1562
+ if (b.bezierOffset2 !== void 0) result += ` bezier-offset2="${b.bezierOffset2}"`;
1563
+ return result;
1564
+ }
1565
+ function buildAttrs(attrs) {
1566
+ let result = "";
1567
+ for (const key in attrs) {
1568
+ const value = attrs[key];
1569
+ if (value === void 0) continue;
1570
+ if (typeof value === "boolean") {
1571
+ result += ` ${key}="${value ? "yes" : "no"}"`;
1572
+ } else if (typeof value === "number") {
1573
+ result += ` ${key}="${value}"`;
1574
+ } else {
1575
+ result += ` ${key}="${escapeXml(value)}"`;
1576
+ }
1577
+ }
1578
+ return result;
1579
+ }
1580
+ function pushOptionalElement(lines, indent, tag, value) {
1581
+ if (value !== void 0) {
1582
+ const escaped = typeof value === "string" ? escapeXml(value) : value;
1583
+ lines.push(`${indent}<${tag}>${escaped}</${tag}>`);
1584
+ }
1585
+ }
1586
+ function serializeStaffDetails(sd, indent, out) {
1587
+ const attrs = buildAttrs({
1588
+ "number": sd.number,
1589
+ "show-frets": sd.showFrets,
1590
+ "print-object": sd.printObject,
1591
+ "print-spacing": sd.printSpacing
1592
+ });
1593
+ out.push(`${indent}<staff-details${attrs}>`);
1594
+ pushOptionalElement(out, `${indent} `, "staff-type", sd.staffType);
1595
+ pushOptionalElement(out, `${indent} `, "staff-lines", sd.staffLines);
1596
+ if (sd.staffTuning) {
1597
+ for (const tuning of sd.staffTuning) {
1598
+ out.push(`${indent} <staff-tuning${buildAttrs({ line: tuning.line })}>`);
1599
+ out.push(`${indent} <tuning-step>${tuning.tuningStep}</tuning-step>`);
1600
+ pushOptionalElement(out, `${indent} `, "tuning-alter", tuning.tuningAlter);
1601
+ out.push(`${indent} <tuning-octave>${tuning.tuningOctave}</tuning-octave>`);
1602
+ out.push(`${indent} </staff-tuning>`);
1603
+ }
1604
+ }
1605
+ pushOptionalElement(out, `${indent} `, "capo", sd.capo);
1606
+ if (sd.staffSize !== void 0) {
1607
+ const attrs2 = buildAttrs({ scaling: sd.staffSizeScaling });
1608
+ out.push(`${indent} <staff-size${attrs2}>${sd.staffSize}</staff-size>`);
1609
+ }
1610
+ out.push(`${indent}</staff-details>`);
1611
+ }
1612
+ function serializeMeasureStyle(ms, indent, out) {
1613
+ out.push(`${indent}<measure-style${buildAttrs({ number: ms.number, color: ms.color })}>`);
1614
+ pushOptionalElement(out, `${indent} `, "multiple-rest", ms.multipleRest);
1615
+ if (ms.measureRepeat) {
1616
+ const mrAttrs = buildAttrs({
1617
+ type: ms.measureRepeat.type,
1618
+ slashes: ms.measureRepeat.slashes
1619
+ });
1620
+ out.push(`${indent} <measure-repeat${mrAttrs}/>`);
1621
+ }
1622
+ if (ms.beatRepeat) {
1623
+ const brAttrs = buildAttrs({ type: ms.beatRepeat.type, slashes: ms.beatRepeat.slashes });
1624
+ out.push(`${indent} <beat-repeat${brAttrs}/>`);
1625
+ }
1626
+ if (ms.slash) {
1627
+ const slAttrs = buildAttrs({
1628
+ type: ms.slash.type,
1629
+ "use-dots": ms.slash.useDots,
1630
+ "use-stems": ms.slash.useStems
1631
+ });
1632
+ out.push(`${indent} <slash${slAttrs}/>`);
1633
+ }
1634
+ out.push(`${indent}</measure-style>`);
1635
+ }
1636
+ function serializeHarmony(harmony, indent, out) {
1637
+ const attrs = buildAttrs({
1638
+ id: harmony._id,
1639
+ placement: harmony.placement,
1640
+ "print-frame": harmony.printFrame,
1641
+ "default-x": harmony.defaultX,
1642
+ "default-y": harmony.defaultY,
1643
+ "relative-x": harmony.relativeX,
1644
+ "relative-y": harmony.relativeY,
1645
+ halign: harmony.halign,
1646
+ "font-size": harmony.fontSize,
1647
+ color: harmony.color
1648
+ });
1649
+ out.push(`${indent}<harmony${attrs}>`);
1650
+ out.push(`${indent} <root>`);
1651
+ out.push(`${indent} <root-step>${harmony.root.rootStep}</root-step>`);
1652
+ if (harmony.root.rootAlter !== void 0) {
1653
+ out.push(`${indent} <root-alter>${harmony.root.rootAlter}</root-alter>`);
1654
+ }
1655
+ out.push(`${indent} </root>`);
1656
+ let kindAttrs = "";
1657
+ if (harmony.kindText !== void 0) kindAttrs += ` text="${escapeXml(harmony.kindText)}"`;
1658
+ if (harmony.kindHalign) kindAttrs += ` halign="${escapeXml(harmony.kindHalign)}"`;
1659
+ kindAttrs += colorAttr(harmony.kindColor);
1660
+ out.push(`${indent} <kind${kindAttrs}>${escapeXml(harmony.kind)}</kind>`);
1661
+ if (harmony.bass) {
1662
+ let bassAttrs = "";
1663
+ if (harmony.bass.arrangement) bassAttrs += ` arrangement="${escapeXml(harmony.bass.arrangement)}"`;
1664
+ out.push(`${indent} <bass${bassAttrs}>`);
1665
+ out.push(`${indent} <bass-step>${harmony.bass.bassStep}</bass-step>`);
1666
+ if (harmony.bass.bassAlter !== void 0) {
1667
+ out.push(`${indent} <bass-alter>${harmony.bass.bassAlter}</bass-alter>`);
1668
+ }
1669
+ out.push(`${indent} </bass>`);
1670
+ }
1671
+ if (harmony.inversion !== void 0) {
1672
+ out.push(`${indent} <inversion>${harmony.inversion}</inversion>`);
1673
+ }
1674
+ if (harmony.degrees) {
1675
+ for (const deg of harmony.degrees) {
1676
+ out.push(`${indent} <degree>`);
1677
+ out.push(`${indent} <degree-value>${deg.degreeValue}</degree-value>`);
1678
+ if (deg.degreeAlter !== void 0) {
1679
+ out.push(`${indent} <degree-alter>${deg.degreeAlter}</degree-alter>`);
1680
+ }
1681
+ out.push(`${indent} <degree-type>${deg.degreeType}</degree-type>`);
1682
+ out.push(`${indent} </degree>`);
1683
+ }
1684
+ }
1685
+ if (harmony.frame) {
1686
+ out.push(`${indent} <frame${colorAttr(harmony.frame.color)}>`);
1687
+ if (harmony.frame.frameStrings !== void 0) {
1688
+ out.push(`${indent} <frame-strings>${harmony.frame.frameStrings}</frame-strings>`);
1689
+ }
1690
+ if (harmony.frame.frameFrets !== void 0) {
1691
+ out.push(`${indent} <frame-frets>${harmony.frame.frameFrets}</frame-frets>`);
1692
+ }
1693
+ if (harmony.frame.firstFret !== void 0) {
1694
+ let ffAttrs = "";
1695
+ if (harmony.frame.firstFretText) ffAttrs += ` text="${escapeXml(harmony.frame.firstFretText)}"`;
1696
+ if (harmony.frame.firstFretLocation) ffAttrs += ` location="${harmony.frame.firstFretLocation}"`;
1697
+ out.push(`${indent} <first-fret${ffAttrs}>${harmony.frame.firstFret}</first-fret>`);
1698
+ }
1699
+ if (harmony.frame.frameNotes) {
1700
+ for (const fn of harmony.frame.frameNotes) {
1701
+ out.push(`${indent} <frame-note>`);
1702
+ out.push(`${indent} <string>${fn.string}</string>`);
1703
+ out.push(`${indent} <fret>${fn.fret}</fret>`);
1704
+ if (fn.fingering) {
1705
+ out.push(`${indent} <fingering>${escapeXml(fn.fingering)}</fingering>`);
1706
+ }
1707
+ if (fn.barre) {
1708
+ out.push(`${indent} <barre type="${fn.barre}"/>`);
1709
+ }
1710
+ out.push(`${indent} </frame-note>`);
1711
+ }
1712
+ }
1713
+ out.push(`${indent} </frame>`);
1714
+ }
1715
+ if (harmony.offset !== void 0) {
1716
+ out.push(`${indent} <offset>${harmony.offset}</offset>`);
1717
+ }
1718
+ if (harmony.staff !== void 0) {
1719
+ out.push(`${indent} <staff>${harmony.staff}</staff>`);
1720
+ }
1721
+ out.push(`${indent}</harmony>`);
1722
+ }
1723
+ function serializeFiguredBass(fb, indent, out) {
1724
+ let attrs = "";
1725
+ if (fb._id) attrs += ` id="${escapeXml(fb._id)}"`;
1726
+ if (fb.parentheses) attrs += ' parentheses="yes"';
1727
+ attrs += colorAttr(fb.color);
1728
+ out.push(`${indent}<figured-bass${attrs}>`);
1729
+ for (const fig of fb.figures) {
1730
+ out.push(`${indent} <figure>`);
1731
+ if (fig.prefix) {
1732
+ out.push(`${indent} <prefix>${escapeXml(fig.prefix)}</prefix>`);
1733
+ }
1734
+ if (fig.figureNumber) {
1735
+ out.push(`${indent} <figure-number>${escapeXml(fig.figureNumber)}</figure-number>`);
1736
+ }
1737
+ if (fig.suffix) {
1738
+ out.push(`${indent} <suffix>${escapeXml(fig.suffix)}</suffix>`);
1739
+ }
1740
+ if (fig.extend) {
1741
+ if (typeof fig.extend === "object") {
1742
+ const extendAttrs = (fig.extend.type ? ` type="${fig.extend.type}"` : "") + colorAttr(fig.extend.color);
1743
+ out.push(`${indent} <extend${extendAttrs}/>`);
1744
+ } else {
1745
+ out.push(`${indent} <extend/>`);
1746
+ }
1747
+ }
1748
+ out.push(`${indent} </figure>`);
1749
+ }
1750
+ if (fb.duration !== void 0) {
1751
+ out.push(`${indent} <duration>${fb.duration}</duration>`);
1752
+ }
1753
+ out.push(`${indent}</figured-bass>`);
1754
+ }
1755
+ function serializeSound(sound, indent, out) {
1756
+ const attrs = [];
1757
+ if (sound._id) attrs.push(`id="${escapeXml(sound._id)}"`);
1758
+ if (sound.tempo !== void 0) attrs.push(`tempo="${sound.tempo}"`);
1759
+ if (sound.dynamics !== void 0) attrs.push(`dynamics="${sound.dynamics}"`);
1760
+ if (sound.dacapo) attrs.push('dacapo="yes"');
1761
+ if (sound.segno) attrs.push(`segno="${escapeXml(sound.segno)}"`);
1762
+ if (sound.dalsegno) attrs.push(`dalsegno="${escapeXml(sound.dalsegno)}"`);
1763
+ if (sound.coda) attrs.push(`coda="${escapeXml(sound.coda)}"`);
1764
+ if (sound.tocoda) attrs.push(`tocoda="${escapeXml(sound.tocoda)}"`);
1765
+ if (sound.fine) attrs.push('fine="yes"');
1766
+ if (sound.forwardRepeat) attrs.push('forward-repeat="yes"');
1767
+ if (sound.damperPedal) attrs.push(`damper-pedal="${sound.damperPedal === true ? "yes" : sound.damperPedal}"`);
1768
+ if (sound.softPedal) attrs.push(`soft-pedal="${sound.softPedal === true ? "yes" : sound.softPedal}"`);
1769
+ if (sound.sostenutoPedal) attrs.push(`sostenuto-pedal="${sound.sostenutoPedal === true ? "yes" : sound.sostenutoPedal}"`);
1770
+ const attrStr = attrs.length > 0 ? ` ${attrs.join(" ")}` : "";
1771
+ if (sound.swing) {
1772
+ out.push(`${indent}<sound${attrStr}>`);
1773
+ out.push(`${indent} <swing>`);
1774
+ if (sound.swing.straight) {
1775
+ out.push(`${indent} <straight/>`);
1776
+ } else {
1777
+ if (sound.swing.first !== void 0) {
1778
+ out.push(`${indent} <first>${sound.swing.first}</first>`);
1779
+ }
1780
+ if (sound.swing.second !== void 0) {
1781
+ out.push(`${indent} <second>${sound.swing.second}</second>`);
1782
+ }
1783
+ if (sound.swing.swingType) {
1784
+ out.push(`${indent} <swing-type>${sound.swing.swingType}</swing-type>`);
1785
+ }
1786
+ }
1787
+ out.push(`${indent} </swing>`);
1788
+ out.push(`${indent}</sound>`);
1789
+ } else if (attrs.length === 0 && !sound._id) {
1790
+ out.push(`${indent}<sound/>`);
1791
+ } else {
1792
+ out.push(`${indent}<sound${attrStr}/>`);
1793
+ }
1794
+ }
1795
+
1796
+
1797
+
1798
+
1799
+ exports.serialize = serialize; exports.serializeUnchecked = serializeUnchecked;