@k-l-lambda/lilylet 0.1.32 → 0.1.33

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/lib/meiEncoder.js CHANGED
@@ -1374,9 +1374,15 @@ const encode = (doc, options = {}) => {
1374
1374
  }
1375
1375
  // Encode measures
1376
1376
  measures.forEach((measure, mi) => {
1377
- // Update key signature if measure has one
1377
+ // Check for key signature change and output scoreDef if needed
1378
1378
  if (measure.key) {
1379
- currentKey = keyToFifths(measure.key);
1379
+ const newKey = keyToFifths(measure.key);
1380
+ if (newKey !== currentKey) {
1381
+ currentKey = newKey;
1382
+ const newKeySig = KEY_SIGS[currentKey] || "0";
1383
+ // Output a scoreDef with the new key signature
1384
+ mei += `${indent}${indent}${indent}${indent}${indent}${indent}<scoreDef xml:id="${generateId('scoredef')}" key.sig="${newKeySig}" />\n`;
1385
+ }
1380
1386
  }
1381
1387
  mei += encodeMeasure(measure, mi + 1, `${indent}${indent}${indent}${indent}${indent}${indent}`, totalStaves, tieState, slurState, hairpinState, currentKey, partInfos, clefState);
1382
1388
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k-l-lambda/lilylet",
3
- "version": "0.1.32",
3
+ "version": "0.1.33",
4
4
  "description": "Lilylet is a lilyopnd-like sheet music language designed for Markdown rendering and symbolic music representation in AIGC applications.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -1754,9 +1754,15 @@ const encode = (doc: LilyletDoc, options: MEIEncoderOptions = {}): string => {
1754
1754
 
1755
1755
  // Encode measures
1756
1756
  measures.forEach((measure, mi) => {
1757
- // Update key signature if measure has one
1757
+ // Check for key signature change and output scoreDef if needed
1758
1758
  if (measure.key) {
1759
- currentKey = keyToFifths(measure.key);
1759
+ const newKey = keyToFifths(measure.key);
1760
+ if (newKey !== currentKey) {
1761
+ currentKey = newKey;
1762
+ const newKeySig = KEY_SIGS[currentKey] || "0";
1763
+ // Output a scoreDef with the new key signature
1764
+ mei += `${indent}${indent}${indent}${indent}${indent}${indent}<scoreDef xml:id="${generateId('scoredef')}" key.sig="${newKeySig}" />\n`;
1765
+ }
1760
1766
  }
1761
1767
  mei += encodeMeasure(measure, mi + 1, `${indent}${indent}${indent}${indent}${indent}${indent}`, totalStaves, tieState, slurState, hairpinState, currentKey, partInfos, clefState);
1762
1768
  });