@k-l-lambda/lilylet 0.1.60 → 0.1.63
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/abc/grammar.jison.js +300 -187
- package/lib/lilylet/abcDecoder.js +40 -12
- package/lib/lilylet/grammar.jison.js +273 -169
- package/lib/lilylet/lilypondDecoder.js +163 -39
- package/lib/lilylet/lilypondEncoder.js +120 -7
- package/lib/lilylet/meiEncoder.js +29 -8
- package/lib/lilylet/musicXmlEncoder.js +1 -1
- package/lib/lilylet/parser.d.ts +12 -1
- package/lib/lilylet/parser.js +11 -1
- package/lib/lilylet/serializer.js +33 -4
- package/lib/lilylet/types.d.ts +8 -2
- package/package.json +16 -8
- package/source/abc/TODO.md +97 -0
- package/source/abc/abc.jison +90 -15
- package/source/abc/grammar.jison.js +300 -187
- package/source/lilylet/abcDecoder.ts +42 -14
- package/source/lilylet/grammar.jison.js +273 -169
- package/source/lilylet/lilylet.jison +114 -15
- package/source/lilylet/lilypondDecoder.ts +139 -42
- package/source/lilylet/lilypondEncoder.ts +116 -9
- package/source/lilylet/meiEncoder.ts +32 -9
- package/source/lilylet/musicXmlDecoder.ts +2 -2
- package/source/lilylet/musicXmlEncoder.ts +1 -1
- package/source/lilylet/parser.ts +20 -0
- package/source/lilylet/serializer.ts +31 -6
- package/source/lilylet/types.ts +10 -2
|
@@ -758,13 +758,13 @@ const convertEventTerm = (
|
|
|
758
758
|
const firstPitch = chord.pitches[0];
|
|
759
759
|
|
|
760
760
|
// Check if rest
|
|
761
|
-
if (firstPitch.phonet === "z" || firstPitch.phonet === "Z" || firstPitch.phonet === "x") {
|
|
761
|
+
if (firstPitch.phonet === "z" || firstPitch.phonet === "Z" || firstPitch.phonet === "x" || firstPitch.phonet === "y") {
|
|
762
762
|
const duration = convertDuration(eventData.duration, unitLength);
|
|
763
763
|
const rest: RestEvent = {
|
|
764
764
|
type: "rest",
|
|
765
765
|
duration,
|
|
766
766
|
};
|
|
767
|
-
if (firstPitch.phonet === "x") {
|
|
767
|
+
if (firstPitch.phonet === "x" || firstPitch.phonet === "y") {
|
|
768
768
|
rest.invisible = true;
|
|
769
769
|
}
|
|
770
770
|
if (firstPitch.phonet === "Z") {
|
|
@@ -779,7 +779,7 @@ const convertEventTerm = (
|
|
|
779
779
|
|
|
780
780
|
// Note or chord
|
|
781
781
|
const pitches = chord.pitches.filter(p =>
|
|
782
|
-
p.phonet !== "z" && p.phonet !== "Z" && p.phonet !== "x"
|
|
782
|
+
p.phonet !== "z" && p.phonet !== "Z" && p.phonet !== "x" && p.phonet !== "y"
|
|
783
783
|
).map(convertPitch);
|
|
784
784
|
|
|
785
785
|
if (pitches.length === 0) return undefined;
|
|
@@ -865,8 +865,17 @@ const decodeTune = (tune: ABC.Tune): LilyletDoc => {
|
|
|
865
865
|
let timeSig: TimeSig | undefined;
|
|
866
866
|
let keySig: KeySignature | undefined;
|
|
867
867
|
let tempo: Tempo | undefined;
|
|
868
|
-
const voiceConfigs = new Map<number, VoiceConfig>();
|
|
869
|
-
const voiceClefs = new Map<number, Clef>();
|
|
868
|
+
const voiceConfigs = new Map<number | string, VoiceConfig>();
|
|
869
|
+
const voiceClefs = new Map<number | string, Clef>();
|
|
870
|
+
|
|
871
|
+
// Pre-scan for unit length (needed for bare Q: tempo)
|
|
872
|
+
for (const h of headers) {
|
|
873
|
+
const hdr = h as { name: string; value: any };
|
|
874
|
+
if (hdr.name === "L" && hdr.value?.numerator && hdr.value?.denominator) {
|
|
875
|
+
unitLength = hdr.value;
|
|
876
|
+
break;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
870
879
|
|
|
871
880
|
for (const h of headers) {
|
|
872
881
|
if ((h as any).comment) continue;
|
|
@@ -905,24 +914,43 @@ const decodeTune = (tune: ABC.Tune): LilyletDoc => {
|
|
|
905
914
|
const beatDuration = convertDuration(header.value.note, { numerator: 1, denominator: 1 });
|
|
906
915
|
tempo = { beat: beatDuration, bpm: header.value.bpm };
|
|
907
916
|
} else if (typeof header.value === "number") {
|
|
908
|
-
|
|
917
|
+
const beat = convertDuration({ numerator: 1, denominator: 1 }, unitLength);
|
|
918
|
+
tempo = { beat, bpm: header.value };
|
|
909
919
|
}
|
|
910
920
|
break;
|
|
911
921
|
case "V": {
|
|
912
922
|
const voiceValue = header.value;
|
|
913
923
|
if (voiceValue) {
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
924
|
+
let voiceId: number | string;
|
|
925
|
+
let clefStr: string | undefined;
|
|
926
|
+
|
|
927
|
+
if (typeof voiceValue === "number") {
|
|
928
|
+
voiceId = voiceValue;
|
|
929
|
+
} else if (typeof voiceValue === "string") {
|
|
930
|
+
voiceId = voiceValue;
|
|
931
|
+
} else {
|
|
932
|
+
const rawClef = (voiceValue.clef || "").replace(/,+$/, "").trim();
|
|
933
|
+
const isKnownClef = !!convertClef(rawClef);
|
|
934
|
+
if (isKnownClef) {
|
|
935
|
+
// V:1 treble → voiceId=number, clef=treble
|
|
936
|
+
voiceId = voiceValue.name || 1;
|
|
937
|
+
clefStr = rawClef;
|
|
938
|
+
} else {
|
|
939
|
+
// V:S clef=treble → voiceId=voiceName, clef from properties
|
|
940
|
+
voiceId = rawClef || voiceValue.name || 1;
|
|
941
|
+
const propClef = (voiceValue.properties?.clef || "").replace(/,+$/, "").trim();
|
|
942
|
+
clefStr = propClef || undefined;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
voiceConfigs.set(voiceId, {
|
|
947
|
+
name: typeof voiceId === "number" ? voiceId : 1,
|
|
920
948
|
clef: clefStr,
|
|
921
|
-
properties: voiceValue
|
|
949
|
+
properties: voiceValue?.properties,
|
|
922
950
|
});
|
|
923
951
|
if (clefStr) {
|
|
924
952
|
const clef = convertClef(clefStr);
|
|
925
|
-
if (clef) voiceClefs.set(
|
|
953
|
+
if (clef) voiceClefs.set(voiceId, clef);
|
|
926
954
|
}
|
|
927
955
|
}
|
|
928
956
|
break;
|