@k-l-lambda/lilylet 0.1.36 → 0.1.38
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/index.d.ts +3 -1
- package/lib/index.js +3 -1
- package/lib/lilypondEncoder.d.ts +29 -0
- package/lib/lilypondEncoder.js +669 -0
- package/lib/meiEncoder.js +38 -4
- package/lib/musicXmlEncoder.d.ts +15 -0
- package/lib/musicXmlEncoder.js +666 -0
- package/package.json +1 -1
- package/source/lilylet/index.ts +4 -0
- package/source/lilylet/lilypondEncoder.ts +832 -0
- package/source/lilylet/meiEncoder.ts +41 -4
- package/source/lilylet/musicXmlEncoder.ts +858 -0
|
@@ -1348,15 +1348,52 @@ const encodeStaff = (voices: Voice[], staffN: number, indent: string, tieState:
|
|
|
1348
1348
|
};
|
|
1349
1349
|
|
|
1350
1350
|
|
|
1351
|
+
// Tempo text to BPM mapping (approximate values based on musical convention)
|
|
1352
|
+
const TEMPO_TEXT_TO_BPM: Record<string, number> = {
|
|
1353
|
+
// Very slow
|
|
1354
|
+
'grave': 35,
|
|
1355
|
+
'largo': 50,
|
|
1356
|
+
'larghetto': 63,
|
|
1357
|
+
'lento': 52,
|
|
1358
|
+
'adagio': 70,
|
|
1359
|
+
// Slow to moderate
|
|
1360
|
+
'andante': 92,
|
|
1361
|
+
'andantino': 96,
|
|
1362
|
+
'moderato': 114,
|
|
1363
|
+
// Fast
|
|
1364
|
+
'allegretto': 116,
|
|
1365
|
+
'allegro': 138,
|
|
1366
|
+
'vivace': 166,
|
|
1367
|
+
'presto': 184,
|
|
1368
|
+
'prestissimo': 208,
|
|
1369
|
+
};
|
|
1370
|
+
|
|
1371
|
+
// Infer BPM from tempo text
|
|
1372
|
+
const inferBpmFromText = (text: string): number | undefined => {
|
|
1373
|
+
const lowerText = text.toLowerCase();
|
|
1374
|
+
for (const [keyword, bpm] of Object.entries(TEMPO_TEXT_TO_BPM)) {
|
|
1375
|
+
if (lowerText.includes(keyword)) {
|
|
1376
|
+
return bpm;
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
return undefined;
|
|
1380
|
+
};
|
|
1381
|
+
|
|
1351
1382
|
// Generate tempo element
|
|
1352
1383
|
const generateTempoElement = (tempo: Tempo, indent: string, staff: number = 1): string => {
|
|
1353
1384
|
let attrs = `xml:id="${generateId('tempo')}" tstamp="1" staff="${staff}"`;
|
|
1354
1385
|
|
|
1355
|
-
//
|
|
1356
|
-
|
|
1357
|
-
|
|
1386
|
+
// Determine BPM: use explicit value or infer from text
|
|
1387
|
+
let bpm = tempo.bpm;
|
|
1388
|
+
if (!bpm && tempo.text) {
|
|
1389
|
+
bpm = inferBpmFromText(tempo.text);
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
// Add BPM if available
|
|
1393
|
+
if (bpm) {
|
|
1394
|
+
attrs += ` midi.bpm="${bpm}"`;
|
|
1358
1395
|
if (tempo.beat) {
|
|
1359
|
-
attrs += ` mm="${
|
|
1396
|
+
attrs += ` mm="${bpm}" mm.unit="${tempo.beat.division}"`;
|
|
1360
1397
|
}
|
|
1361
1398
|
}
|
|
1362
1399
|
|