@k-l-lambda/lilylet 0.1.36 → 0.1.37
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 +2 -1
- package/lib/index.js +2 -1
- package/lib/lilypondEncoder.d.ts +29 -0
- package/lib/lilypondEncoder.js +669 -0
- package/lib/meiEncoder.js +38 -4
- package/package.json +1 -1
- package/source/lilylet/index.ts +2 -0
- package/source/lilylet/lilypondEncoder.ts +832 -0
- package/source/lilylet/meiEncoder.ts +41 -4
package/lib/meiEncoder.js
CHANGED
|
@@ -1030,14 +1030,48 @@ const encodeStaff = (voices, staffN, indent, tieState = {}, slurState = {}, hair
|
|
|
1030
1030
|
endingClef,
|
|
1031
1031
|
};
|
|
1032
1032
|
};
|
|
1033
|
+
// Tempo text to BPM mapping (approximate values based on musical convention)
|
|
1034
|
+
const TEMPO_TEXT_TO_BPM = {
|
|
1035
|
+
// Very slow
|
|
1036
|
+
'grave': 35,
|
|
1037
|
+
'largo': 50,
|
|
1038
|
+
'larghetto': 63,
|
|
1039
|
+
'lento': 52,
|
|
1040
|
+
'adagio': 70,
|
|
1041
|
+
// Slow to moderate
|
|
1042
|
+
'andante': 92,
|
|
1043
|
+
'andantino': 96,
|
|
1044
|
+
'moderato': 114,
|
|
1045
|
+
// Fast
|
|
1046
|
+
'allegretto': 116,
|
|
1047
|
+
'allegro': 138,
|
|
1048
|
+
'vivace': 166,
|
|
1049
|
+
'presto': 184,
|
|
1050
|
+
'prestissimo': 208,
|
|
1051
|
+
};
|
|
1052
|
+
// Infer BPM from tempo text
|
|
1053
|
+
const inferBpmFromText = (text) => {
|
|
1054
|
+
const lowerText = text.toLowerCase();
|
|
1055
|
+
for (const [keyword, bpm] of Object.entries(TEMPO_TEXT_TO_BPM)) {
|
|
1056
|
+
if (lowerText.includes(keyword)) {
|
|
1057
|
+
return bpm;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
return undefined;
|
|
1061
|
+
};
|
|
1033
1062
|
// Generate tempo element
|
|
1034
1063
|
const generateTempoElement = (tempo, indent, staff = 1) => {
|
|
1035
1064
|
let attrs = `xml:id="${generateId('tempo')}" tstamp="1" staff="${staff}"`;
|
|
1036
|
-
//
|
|
1037
|
-
|
|
1038
|
-
|
|
1065
|
+
// Determine BPM: use explicit value or infer from text
|
|
1066
|
+
let bpm = tempo.bpm;
|
|
1067
|
+
if (!bpm && tempo.text) {
|
|
1068
|
+
bpm = inferBpmFromText(tempo.text);
|
|
1069
|
+
}
|
|
1070
|
+
// Add BPM if available
|
|
1071
|
+
if (bpm) {
|
|
1072
|
+
attrs += ` midi.bpm="${bpm}"`;
|
|
1039
1073
|
if (tempo.beat) {
|
|
1040
|
-
attrs += ` mm="${
|
|
1074
|
+
attrs += ` mm="${bpm}" mm.unit="${tempo.beat.division}"`;
|
|
1041
1075
|
}
|
|
1042
1076
|
}
|
|
1043
1077
|
// Generate content
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@k-l-lambda/lilylet",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.37",
|
|
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",
|
package/source/lilylet/index.ts
CHANGED
|
@@ -5,8 +5,10 @@ export * from "./serializer";
|
|
|
5
5
|
|
|
6
6
|
import * as meiEncoder from "./meiEncoder";
|
|
7
7
|
import * as musicXmlDecoder from "./musicXmlDecoder";
|
|
8
|
+
import * as lilypondEncoder from "./lilypondEncoder";
|
|
8
9
|
|
|
9
10
|
export {
|
|
10
11
|
meiEncoder,
|
|
11
12
|
musicXmlDecoder,
|
|
13
|
+
lilypondEncoder,
|
|
12
14
|
};
|