musicxml-io 0.2.8 → 0.2.9

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/README.md CHANGED
@@ -69,6 +69,8 @@ const transposed = transpose(score, 2); // up 2 semitones
69
69
  const output = serialize(transposed);
70
70
  ```
71
71
 
72
+ ⚠️ **Warning**: This library's API is not yet stable and may change between versions.
73
+
72
74
  ### File I/O (Node.js)
73
75
 
74
76
  ```typescript
package/dist/index.js CHANGED
@@ -3727,8 +3727,10 @@ function serializeSystemLayout(layout, indent) {
3727
3727
  }
3728
3728
  function serializeCredit(credit, indent) {
3729
3729
  const lines = [];
3730
- const pageAttr = credit.page !== void 0 ? ` page="${credit.page}"` : "";
3731
- lines.push(`${indent}<credit${pageAttr}>`);
3730
+ let attrs = "";
3731
+ if (credit._id) attrs += ` id="${escapeXml(credit._id)}"`;
3732
+ if (credit.page !== void 0) attrs += ` page="${credit.page}"`;
3733
+ lines.push(`${indent}<credit${attrs}>`);
3732
3734
  if (credit.creditType) {
3733
3735
  for (const ct of credit.creditType) {
3734
3736
  lines.push(`${indent}${indent}<credit-type>${escapeXml(ct)}</credit-type>`);
@@ -3736,19 +3738,19 @@ function serializeCredit(credit, indent) {
3736
3738
  }
3737
3739
  if (credit.creditWords) {
3738
3740
  for (const cw of credit.creditWords) {
3739
- let attrs = "";
3740
- if (cw.defaultX !== void 0) attrs += ` default-x="${cw.defaultX}"`;
3741
- if (cw.defaultY !== void 0) attrs += ` default-y="${cw.defaultY}"`;
3742
- if (cw.fontSize) attrs += ` font-size="${escapeXml(cw.fontSize)}"`;
3743
- if (cw.fontWeight) attrs += ` font-weight="${escapeXml(cw.fontWeight)}"`;
3744
- if (cw.fontStyle) attrs += ` font-style="${escapeXml(cw.fontStyle)}"`;
3745
- if (cw.justify) attrs += ` justify="${escapeXml(cw.justify)}"`;
3746
- if (cw.halign) attrs += ` halign="${escapeXml(cw.halign)}"`;
3747
- if (cw.valign) attrs += ` valign="${escapeXml(cw.valign)}"`;
3748
- if (cw.letterSpacing) attrs += ` letter-spacing="${escapeXml(cw.letterSpacing)}"`;
3749
- if (cw.xmlLang) attrs += ` xml:lang="${escapeXml(cw.xmlLang)}"`;
3750
- if (cw.xmlSpace) attrs += ` xml:space="${escapeXml(cw.xmlSpace)}"`;
3751
- lines.push(`${indent}${indent}<credit-words${attrs}>${escapeXml(cw.text)}</credit-words>`);
3741
+ let attrs2 = "";
3742
+ if (cw.defaultX !== void 0) attrs2 += ` default-x="${cw.defaultX}"`;
3743
+ if (cw.defaultY !== void 0) attrs2 += ` default-y="${cw.defaultY}"`;
3744
+ if (cw.fontSize) attrs2 += ` font-size="${escapeXml(cw.fontSize)}"`;
3745
+ if (cw.fontWeight) attrs2 += ` font-weight="${escapeXml(cw.fontWeight)}"`;
3746
+ if (cw.fontStyle) attrs2 += ` font-style="${escapeXml(cw.fontStyle)}"`;
3747
+ if (cw.justify) attrs2 += ` justify="${escapeXml(cw.justify)}"`;
3748
+ if (cw.halign) attrs2 += ` halign="${escapeXml(cw.halign)}"`;
3749
+ if (cw.valign) attrs2 += ` valign="${escapeXml(cw.valign)}"`;
3750
+ if (cw.letterSpacing) attrs2 += ` letter-spacing="${escapeXml(cw.letterSpacing)}"`;
3751
+ if (cw.xmlLang) attrs2 += ` xml:lang="${escapeXml(cw.xmlLang)}"`;
3752
+ if (cw.xmlSpace) attrs2 += ` xml:space="${escapeXml(cw.xmlSpace)}"`;
3753
+ lines.push(`${indent}${indent}<credit-words${attrs2}>${escapeXml(cw.text)}</credit-words>`);
3752
3754
  }
3753
3755
  }
3754
3756
  lines.push(`${indent}</credit>`);
@@ -3868,6 +3870,7 @@ function serializePartGroup(group, indent) {
3868
3870
  const lines = [];
3869
3871
  let attrs = ` type="${group.groupType}"`;
3870
3872
  if (group.number !== void 0) attrs += ` number="${group.number}"`;
3873
+ if (group._id) attrs += ` id="${escapeXml(group._id)}"`;
3871
3874
  lines.push(`${indent}<part-group${attrs}>`);
3872
3875
  if (group.groupName) {
3873
3876
  lines.push(`${indent} <group-name>${escapeXml(group.groupName)}</group-name>`);
@@ -3908,6 +3911,7 @@ function serializePart(part, indent) {
3908
3911
  function serializeMeasure(measure, indent) {
3909
3912
  const lines = [];
3910
3913
  let attrs = ` number="${measure.number}"`;
3914
+ if (measure._id) attrs += ` id="${escapeXml(measure._id)}"`;
3911
3915
  if (measure.width !== void 0) attrs += ` width="${measure.width}"`;
3912
3916
  if (measure.implicit) attrs += ` implicit="yes"`;
3913
3917
  lines.push(`${indent}<measure${attrs}>`);
@@ -3982,9 +3986,10 @@ function serializePrint(print, indent) {
3982
3986
  lines.push(`${indent}</print>`);
3983
3987
  return lines;
3984
3988
  }
3985
- function serializeAttributes(attrs, indent) {
3989
+ function serializeAttributes(attrs, indent, id) {
3986
3990
  const lines = [];
3987
- lines.push(`${indent}<attributes>`);
3991
+ const idAttr = id ? ` id="${escapeXml(id)}"` : "";
3992
+ lines.push(`${indent}<attributes${idAttr}>`);
3988
3993
  if (attrs.divisions !== void 0) {
3989
3994
  lines.push(`${indent} <divisions>${attrs.divisions}</divisions>`);
3990
3995
  }
@@ -4132,7 +4137,7 @@ function serializeEntry(entry, indent) {
4132
4137
  case "sound":
4133
4138
  return serializeSound(entry, indent);
4134
4139
  case "attributes":
4135
- return serializeAttributes(entry.attributes, indent);
4140
+ return serializeAttributes(entry.attributes, indent, entry._id);
4136
4141
  default:
4137
4142
  return [];
4138
4143
  }
@@ -4140,6 +4145,7 @@ function serializeEntry(entry, indent) {
4140
4145
  function serializeNote(note, indent) {
4141
4146
  const lines = [];
4142
4147
  const noteAttrs = buildAttrs({
4148
+ "id": note._id,
4143
4149
  "default-x": note.defaultX,
4144
4150
  "default-y": note.defaultY,
4145
4151
  "relative-x": note.relativeX,
@@ -4622,7 +4628,8 @@ function serializeBackup(backup, indent) {
4622
4628
  }
4623
4629
  function serializeForward(forward, indent) {
4624
4630
  const lines = [];
4625
- lines.push(`${indent}<forward>`);
4631
+ const idAttr = forward._id ? ` id="${escapeXml(forward._id)}"` : "";
4632
+ lines.push(`${indent}<forward${idAttr}>`);
4626
4633
  lines.push(`${indent} <duration>${forward.duration}</duration>`);
4627
4634
  if (forward.voice !== void 0) {
4628
4635
  lines.push(`${indent} <voice>${forward.voice}</voice>`);
@@ -4636,6 +4643,7 @@ function serializeForward(forward, indent) {
4636
4643
  function serializeDirection(direction, indent) {
4637
4644
  const lines = [];
4638
4645
  let attrs = "";
4646
+ if (direction._id) attrs += ` id="${escapeXml(direction._id)}"`;
4639
4647
  if (direction.placement) attrs += ` placement="${direction.placement}"`;
4640
4648
  if (direction.directive) attrs += ' directive="yes"';
4641
4649
  if (direction.system) attrs += ` system="${direction.system}"`;
@@ -4897,7 +4905,9 @@ function serializeDirectionType(dirType, indent) {
4897
4905
  }
4898
4906
  function serializeBarline(barline, indent) {
4899
4907
  const lines = [];
4900
- lines.push(`${indent}<barline location="${barline.location}">`);
4908
+ let attrs = ` location="${barline.location}"`;
4909
+ if (barline._id) attrs += ` id="${escapeXml(barline._id)}"`;
4910
+ lines.push(`${indent}<barline${attrs}>`);
4901
4911
  if (barline.barStyle) {
4902
4912
  lines.push(`${indent} <bar-style>${barline.barStyle}</bar-style>`);
4903
4913
  }
@@ -4990,6 +5000,7 @@ function serializeMeasureStyle(ms, indent) {
4990
5000
  function serializeHarmony(harmony, indent) {
4991
5001
  const lines = [];
4992
5002
  const attrs = buildAttrs({
5003
+ id: harmony._id,
4993
5004
  placement: harmony.placement,
4994
5005
  "print-frame": harmony.printFrame,
4995
5006
  "default-y": harmony.defaultY,
@@ -5067,6 +5078,7 @@ function serializeHarmony(harmony, indent) {
5067
5078
  function serializeFiguredBass(fb, indent) {
5068
5079
  const lines = [];
5069
5080
  let attrs = "";
5081
+ if (fb._id) attrs += ` id="${escapeXml(fb._id)}"`;
5070
5082
  if (fb.parentheses) attrs += ' parentheses="yes"';
5071
5083
  lines.push(`${indent}<figured-bass${attrs}>`);
5072
5084
  for (const fig of fb.figures) {
@@ -5098,6 +5110,7 @@ function serializeFiguredBass(fb, indent) {
5098
5110
  function serializeSound(sound, indent) {
5099
5111
  const lines = [];
5100
5112
  const attrs = [];
5113
+ if (sound._id) attrs.push(`id="${escapeXml(sound._id)}"`);
5101
5114
  if (sound.tempo !== void 0) attrs.push(`tempo="${sound.tempo}"`);
5102
5115
  if (sound.dynamics !== void 0) attrs.push(`dynamics="${sound.dynamics}"`);
5103
5116
  if (sound.dacapo) attrs.push('dacapo="yes"');
@@ -5129,7 +5142,7 @@ function serializeSound(sound, indent) {
5129
5142
  }
5130
5143
  lines.push(`${indent} </swing>`);
5131
5144
  lines.push(`${indent}</sound>`);
5132
- } else if (attrs.length === 0) {
5145
+ } else if (attrs.length === 0 && !sound._id) {
5133
5146
  lines.push(`${indent}<sound/>`);
5134
5147
  } else {
5135
5148
  lines.push(`${indent}<sound${attrStr}/>`);
package/dist/index.mjs CHANGED
@@ -3552,8 +3552,10 @@ function serializeSystemLayout(layout, indent) {
3552
3552
  }
3553
3553
  function serializeCredit(credit, indent) {
3554
3554
  const lines = [];
3555
- const pageAttr = credit.page !== void 0 ? ` page="${credit.page}"` : "";
3556
- lines.push(`${indent}<credit${pageAttr}>`);
3555
+ let attrs = "";
3556
+ if (credit._id) attrs += ` id="${escapeXml(credit._id)}"`;
3557
+ if (credit.page !== void 0) attrs += ` page="${credit.page}"`;
3558
+ lines.push(`${indent}<credit${attrs}>`);
3557
3559
  if (credit.creditType) {
3558
3560
  for (const ct of credit.creditType) {
3559
3561
  lines.push(`${indent}${indent}<credit-type>${escapeXml(ct)}</credit-type>`);
@@ -3561,19 +3563,19 @@ function serializeCredit(credit, indent) {
3561
3563
  }
3562
3564
  if (credit.creditWords) {
3563
3565
  for (const cw of credit.creditWords) {
3564
- let attrs = "";
3565
- if (cw.defaultX !== void 0) attrs += ` default-x="${cw.defaultX}"`;
3566
- if (cw.defaultY !== void 0) attrs += ` default-y="${cw.defaultY}"`;
3567
- if (cw.fontSize) attrs += ` font-size="${escapeXml(cw.fontSize)}"`;
3568
- if (cw.fontWeight) attrs += ` font-weight="${escapeXml(cw.fontWeight)}"`;
3569
- if (cw.fontStyle) attrs += ` font-style="${escapeXml(cw.fontStyle)}"`;
3570
- if (cw.justify) attrs += ` justify="${escapeXml(cw.justify)}"`;
3571
- if (cw.halign) attrs += ` halign="${escapeXml(cw.halign)}"`;
3572
- if (cw.valign) attrs += ` valign="${escapeXml(cw.valign)}"`;
3573
- if (cw.letterSpacing) attrs += ` letter-spacing="${escapeXml(cw.letterSpacing)}"`;
3574
- if (cw.xmlLang) attrs += ` xml:lang="${escapeXml(cw.xmlLang)}"`;
3575
- if (cw.xmlSpace) attrs += ` xml:space="${escapeXml(cw.xmlSpace)}"`;
3576
- lines.push(`${indent}${indent}<credit-words${attrs}>${escapeXml(cw.text)}</credit-words>`);
3566
+ let attrs2 = "";
3567
+ if (cw.defaultX !== void 0) attrs2 += ` default-x="${cw.defaultX}"`;
3568
+ if (cw.defaultY !== void 0) attrs2 += ` default-y="${cw.defaultY}"`;
3569
+ if (cw.fontSize) attrs2 += ` font-size="${escapeXml(cw.fontSize)}"`;
3570
+ if (cw.fontWeight) attrs2 += ` font-weight="${escapeXml(cw.fontWeight)}"`;
3571
+ if (cw.fontStyle) attrs2 += ` font-style="${escapeXml(cw.fontStyle)}"`;
3572
+ if (cw.justify) attrs2 += ` justify="${escapeXml(cw.justify)}"`;
3573
+ if (cw.halign) attrs2 += ` halign="${escapeXml(cw.halign)}"`;
3574
+ if (cw.valign) attrs2 += ` valign="${escapeXml(cw.valign)}"`;
3575
+ if (cw.letterSpacing) attrs2 += ` letter-spacing="${escapeXml(cw.letterSpacing)}"`;
3576
+ if (cw.xmlLang) attrs2 += ` xml:lang="${escapeXml(cw.xmlLang)}"`;
3577
+ if (cw.xmlSpace) attrs2 += ` xml:space="${escapeXml(cw.xmlSpace)}"`;
3578
+ lines.push(`${indent}${indent}<credit-words${attrs2}>${escapeXml(cw.text)}</credit-words>`);
3577
3579
  }
3578
3580
  }
3579
3581
  lines.push(`${indent}</credit>`);
@@ -3693,6 +3695,7 @@ function serializePartGroup(group, indent) {
3693
3695
  const lines = [];
3694
3696
  let attrs = ` type="${group.groupType}"`;
3695
3697
  if (group.number !== void 0) attrs += ` number="${group.number}"`;
3698
+ if (group._id) attrs += ` id="${escapeXml(group._id)}"`;
3696
3699
  lines.push(`${indent}<part-group${attrs}>`);
3697
3700
  if (group.groupName) {
3698
3701
  lines.push(`${indent} <group-name>${escapeXml(group.groupName)}</group-name>`);
@@ -3733,6 +3736,7 @@ function serializePart(part, indent) {
3733
3736
  function serializeMeasure(measure, indent) {
3734
3737
  const lines = [];
3735
3738
  let attrs = ` number="${measure.number}"`;
3739
+ if (measure._id) attrs += ` id="${escapeXml(measure._id)}"`;
3736
3740
  if (measure.width !== void 0) attrs += ` width="${measure.width}"`;
3737
3741
  if (measure.implicit) attrs += ` implicit="yes"`;
3738
3742
  lines.push(`${indent}<measure${attrs}>`);
@@ -3807,9 +3811,10 @@ function serializePrint(print, indent) {
3807
3811
  lines.push(`${indent}</print>`);
3808
3812
  return lines;
3809
3813
  }
3810
- function serializeAttributes(attrs, indent) {
3814
+ function serializeAttributes(attrs, indent, id) {
3811
3815
  const lines = [];
3812
- lines.push(`${indent}<attributes>`);
3816
+ const idAttr = id ? ` id="${escapeXml(id)}"` : "";
3817
+ lines.push(`${indent}<attributes${idAttr}>`);
3813
3818
  if (attrs.divisions !== void 0) {
3814
3819
  lines.push(`${indent} <divisions>${attrs.divisions}</divisions>`);
3815
3820
  }
@@ -3957,7 +3962,7 @@ function serializeEntry(entry, indent) {
3957
3962
  case "sound":
3958
3963
  return serializeSound(entry, indent);
3959
3964
  case "attributes":
3960
- return serializeAttributes(entry.attributes, indent);
3965
+ return serializeAttributes(entry.attributes, indent, entry._id);
3961
3966
  default:
3962
3967
  return [];
3963
3968
  }
@@ -3965,6 +3970,7 @@ function serializeEntry(entry, indent) {
3965
3970
  function serializeNote(note, indent) {
3966
3971
  const lines = [];
3967
3972
  const noteAttrs = buildAttrs({
3973
+ "id": note._id,
3968
3974
  "default-x": note.defaultX,
3969
3975
  "default-y": note.defaultY,
3970
3976
  "relative-x": note.relativeX,
@@ -4447,7 +4453,8 @@ function serializeBackup(backup, indent) {
4447
4453
  }
4448
4454
  function serializeForward(forward, indent) {
4449
4455
  const lines = [];
4450
- lines.push(`${indent}<forward>`);
4456
+ const idAttr = forward._id ? ` id="${escapeXml(forward._id)}"` : "";
4457
+ lines.push(`${indent}<forward${idAttr}>`);
4451
4458
  lines.push(`${indent} <duration>${forward.duration}</duration>`);
4452
4459
  if (forward.voice !== void 0) {
4453
4460
  lines.push(`${indent} <voice>${forward.voice}</voice>`);
@@ -4461,6 +4468,7 @@ function serializeForward(forward, indent) {
4461
4468
  function serializeDirection(direction, indent) {
4462
4469
  const lines = [];
4463
4470
  let attrs = "";
4471
+ if (direction._id) attrs += ` id="${escapeXml(direction._id)}"`;
4464
4472
  if (direction.placement) attrs += ` placement="${direction.placement}"`;
4465
4473
  if (direction.directive) attrs += ' directive="yes"';
4466
4474
  if (direction.system) attrs += ` system="${direction.system}"`;
@@ -4722,7 +4730,9 @@ function serializeDirectionType(dirType, indent) {
4722
4730
  }
4723
4731
  function serializeBarline(barline, indent) {
4724
4732
  const lines = [];
4725
- lines.push(`${indent}<barline location="${barline.location}">`);
4733
+ let attrs = ` location="${barline.location}"`;
4734
+ if (barline._id) attrs += ` id="${escapeXml(barline._id)}"`;
4735
+ lines.push(`${indent}<barline${attrs}>`);
4726
4736
  if (barline.barStyle) {
4727
4737
  lines.push(`${indent} <bar-style>${barline.barStyle}</bar-style>`);
4728
4738
  }
@@ -4815,6 +4825,7 @@ function serializeMeasureStyle(ms, indent) {
4815
4825
  function serializeHarmony(harmony, indent) {
4816
4826
  const lines = [];
4817
4827
  const attrs = buildAttrs({
4828
+ id: harmony._id,
4818
4829
  placement: harmony.placement,
4819
4830
  "print-frame": harmony.printFrame,
4820
4831
  "default-y": harmony.defaultY,
@@ -4892,6 +4903,7 @@ function serializeHarmony(harmony, indent) {
4892
4903
  function serializeFiguredBass(fb, indent) {
4893
4904
  const lines = [];
4894
4905
  let attrs = "";
4906
+ if (fb._id) attrs += ` id="${escapeXml(fb._id)}"`;
4895
4907
  if (fb.parentheses) attrs += ' parentheses="yes"';
4896
4908
  lines.push(`${indent}<figured-bass${attrs}>`);
4897
4909
  for (const fig of fb.figures) {
@@ -4923,6 +4935,7 @@ function serializeFiguredBass(fb, indent) {
4923
4935
  function serializeSound(sound, indent) {
4924
4936
  const lines = [];
4925
4937
  const attrs = [];
4938
+ if (sound._id) attrs.push(`id="${escapeXml(sound._id)}"`);
4926
4939
  if (sound.tempo !== void 0) attrs.push(`tempo="${sound.tempo}"`);
4927
4940
  if (sound.dynamics !== void 0) attrs.push(`dynamics="${sound.dynamics}"`);
4928
4941
  if (sound.dacapo) attrs.push('dacapo="yes"');
@@ -4954,7 +4967,7 @@ function serializeSound(sound, indent) {
4954
4967
  }
4955
4968
  lines.push(`${indent} </swing>`);
4956
4969
  lines.push(`${indent}</sound>`);
4957
- } else if (attrs.length === 0) {
4970
+ } else if (attrs.length === 0 && !sound._id) {
4958
4971
  lines.push(`${indent}<sound/>`);
4959
4972
  } else {
4960
4973
  lines.push(`${indent}<sound${attrStr}/>`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musicxml-io",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "Parse and serialize MusicXML (.xml/.mxl) with high round-trip fidelity",
5
5
  "author": "tan-z-tan",
6
6
  "license": "MIT",