jpfun 0.4.1 → 0.6.0
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 +53 -113
- package/dist/converter/midi/convert.js +14 -7
- package/dist/converter/musicxml/features.d.ts +57 -16
- package/dist/converter/musicxml/features.js +204 -42
- package/dist/converter/musicxml/index.d.ts +7 -2
- package/dist/converter/musicxml/index.js +256 -268
- package/dist/converter/musicxml/model.d.ts +36 -7
- package/dist/converter/musicxml/resolve.d.ts +10 -0
- package/dist/converter/musicxml/resolve.js +152 -0
- package/dist/core.d.ts +1 -0
- package/dist/core.js +1 -0
- package/dist/fraction.js +7 -1
- package/dist/functions/ASTtypes.d.ts +6 -3
- package/dist/functions/ASTtypes.js +30 -23
- package/dist/functions/adjust/index.js +10 -50
- package/dist/functions/arpeggio/index.js +40 -25
- package/dist/functions/beam/auto.js +2 -11
- package/dist/functions/box/index.js +132 -82
- package/dist/functions/dash/index.js +20 -11
- package/dist/functions/default.js +2 -1
- package/dist/functions/div/index.d.ts +1 -1
- package/dist/functions/div/index.js +9 -10
- package/dist/functions/dot/index.js +4 -5
- package/dist/functions/dyn/index.js +28 -32
- package/dist/functions/grace/index.d.ts +23 -8
- package/dist/functions/grace/index.js +138 -119
- package/dist/functions/head/index.js +11 -4
- package/dist/functions/key/index.js +1 -1
- package/dist/functions/meter/index.js +40 -7
- package/dist/functions/meter/shape.d.ts +3 -0
- package/dist/functions/meter/shape.js +43 -0
- package/dist/functions/note/index.d.ts +6 -1
- package/dist/functions/note/index.js +60 -57
- package/dist/functions/note/source-transform.d.ts +21 -0
- package/dist/functions/note/source-transform.js +164 -0
- package/dist/functions/page/index.d.ts +5 -0
- package/dist/functions/page/index.js +8 -5
- package/dist/functions/rest/index.d.ts +2 -0
- package/dist/functions/rest/index.js +233 -0
- package/dist/functions/set/index.js +5 -1
- package/dist/functions/symbol/index.d.ts +2 -0
- package/dist/functions/symbol/index.js +1 -1
- package/dist/functions/symbol/ornament.d.ts +3 -3
- package/dist/functions/symbol/ornament.js +21 -35
- package/dist/functions/symbol/symbols/accent.js +5 -5
- package/dist/functions/symbol/symbols/fermata.js +5 -4
- package/dist/functions/temporal.d.ts +21 -7
- package/dist/functions/temporal.js +14 -4
- package/dist/functions/tie/index.js +36 -42
- package/dist/functions/tuplet/index.js +20 -24
- package/dist/functions/up/index.js +54 -34
- package/dist/functions/voice/connections.d.ts +19 -0
- package/dist/functions/voice/connections.js +88 -0
- package/dist/functions/voice/index.js +248 -102
- package/dist/functions/volta/index.js +7 -12
- package/dist/jpfun.core.min.js +61 -41
- package/dist/jpfun.from-midi.min.js +5 -5
- package/dist/jpfun.from-musicxml.min.js +8 -8
- package/dist/jpfun.min.js +70 -50
- package/dist/layout/engine.d.ts +13 -1
- package/dist/layout/engine.js +458 -129
- package/dist/layout/model.js +22 -66
- package/dist/layout/page.js +3 -1
- package/dist/layout/range.d.ts +26 -0
- package/dist/layout/range.js +75 -0
- package/dist/layout/types.d.ts +63 -49
- package/dist/lowering/loweringContext.d.ts +1 -1
- package/dist/lowering/loweringContext.js +34 -4
- package/dist/lowering/types.d.ts +5 -0
- package/dist/parser/parse-utils/length-utils.js +2 -0
- package/dist/parser/parse-utils/note-utils.d.ts +2 -0
- package/dist/parser/parse-utils/note-utils.js +6 -2
- package/dist/parser/parserContext.js +5 -9
- package/dist/parser/preprocess.js +4 -6
- package/dist/playback/compile.d.ts +2 -9
- package/dist/playback/compile.js +297 -186
- package/dist/playback/event.d.ts +8 -16
- package/dist/playback/event.js +13 -3
- package/dist/playback/types.d.ts +76 -18
- package/dist/playback/types.js +1 -0
- package/dist/render/index.d.ts +1 -1
- package/dist/render/index.js +1 -1
- package/dist/render/paint.js +1 -1
- package/dist/render/recording.d.ts +1 -0
- package/dist/render/recording.js +21 -0
- package/dist/render/translate.d.ts +14 -0
- package/dist/render/translate.js +48 -0
- package/grammar.md +200 -250
- package/package.json +4 -4
|
@@ -1,6 +1,69 @@
|
|
|
1
1
|
import { child, children, descendant, descendants, nameOf, number, text, } from "./dom.js";
|
|
2
|
+
import { NoteNameMap, SHARP_NOTE_NAMES } from "../../parser/parse-utils/note-utils.js";
|
|
2
3
|
const DYNAMIC_NAMES = new Set(["ppp", "pp", "p", "mp", "mf", "f", "ff", "fff"]);
|
|
3
4
|
const MAX_ENDING_PASS = 256;
|
|
5
|
+
const DIAGNOSTICS = {
|
|
6
|
+
percussion: ["PERCUSSION_SKIPPED", "MIDI channel 10 percussion note was omitted."],
|
|
7
|
+
displayPitch: ["APPROXIMATED", "Unpitched note was converted to a melodic note using its display pitch."],
|
|
8
|
+
afterGrace: ["APPROXIMATED", "After-grace note has no preceding event and was treated as a before-grace note."],
|
|
9
|
+
wedge: ["APPROXIMATED", "Wedge was mapped to note onsets with a fixed velocity change of {value}."],
|
|
10
|
+
unsupported: ["UNSUPPORTED_ELEMENT", "MusicXML <{value}> was omitted."],
|
|
11
|
+
gracePitch: ["UNATTACHED_CONTENT", "Grace note without a pitch was omitted."],
|
|
12
|
+
graceHost: ["UNATTACHED_CONTENT", "Before-grace note has no following event and was omitted."],
|
|
13
|
+
dynamicHost: ["UNATTACHED_CONTENT", "Dynamic {value} has no target voice and was omitted."],
|
|
14
|
+
directionOutput: ["UNATTACHED_CONTENT", "Direction mark has no generated output position and was omitted."],
|
|
15
|
+
tempoReplaced: ["UNATTACHED_CONTENT", "Tempo {value} was replaced by a different tempo at the same time and was omitted."],
|
|
16
|
+
arpeggioOutput: ["UNSUPPORTED_ELEMENT", "Arpeggiate mark requires at least two pitches in one event and was omitted."],
|
|
17
|
+
textHost: ["UNATTACHED_CONTENT", "Text {value} has no target event and was omitted."],
|
|
18
|
+
wedgeStart: ["UNRESOLVED_RELATION", "Wedge stop has no matching start and was omitted."],
|
|
19
|
+
wedgeReplaced: ["UNRESOLVED_RELATION", "Wedge start was replaced before a matching stop and was omitted."],
|
|
20
|
+
wedgeStop: ["UNRESOLVED_RELATION", "Wedge start has no matching stop and was omitted."],
|
|
21
|
+
wedgeVoice: ["UNRESOLVED_RELATION", "Wedge has no target voice and was omitted."],
|
|
22
|
+
wedgeEndpoints: ["UNRESOLVED_RELATION", "Wedge has no two distinct note onsets to use as endpoints and was omitted."],
|
|
23
|
+
endingStart: ["UNRESOLVED_RELATION", "Ending stop has no matching start and was omitted."],
|
|
24
|
+
endingReplaced: ["UNRESOLVED_RELATION", "Ending start was replaced before a matching stop and was omitted."],
|
|
25
|
+
endingStop: ["UNRESOLVED_RELATION", "Ending start has no matching stop and was omitted."],
|
|
26
|
+
endingEndpoints: ["UNRESOLVED_RELATION", "Ending has no event endpoints in its interval and was omitted."],
|
|
27
|
+
tieStart: ["UNRESOLVED_RELATION", "Tie stop has no matching start and was omitted."],
|
|
28
|
+
tieStop: ["UNRESOLVED_RELATION", "Tie start has no matching stop in any ending branch and was omitted."],
|
|
29
|
+
};
|
|
30
|
+
export function reportDiagnostic(diagnostics, issue, location, value = "") {
|
|
31
|
+
const [kind, message] = DIAGNOSTICS[issue];
|
|
32
|
+
diagnostics.push({ code: `W_MUSICXML_${kind}`, severity: "warning",
|
|
33
|
+
message: message.replace("{value}", () => String(value)), location });
|
|
34
|
+
}
|
|
35
|
+
/** 查询不改变覆盖状态;解析结果写入语义模型后显式确认,未确认项按 XML 顺序报告 */
|
|
36
|
+
export class MusicXmlReader {
|
|
37
|
+
roots;
|
|
38
|
+
accepted = [];
|
|
39
|
+
constructor(roots) {
|
|
40
|
+
this.roots = roots;
|
|
41
|
+
}
|
|
42
|
+
read(name, deep = false, parent) {
|
|
43
|
+
for (const root of parent ? [parent] : this.roots) {
|
|
44
|
+
const element = deep ? descendant(root, name) : child(root, name);
|
|
45
|
+
if (element)
|
|
46
|
+
return element;
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
readAll(name, deep = false) {
|
|
51
|
+
return this.roots.flatMap(root => deep ? descendants(root, name) : children(root, name));
|
|
52
|
+
}
|
|
53
|
+
accept(element) {
|
|
54
|
+
if (element)
|
|
55
|
+
this.accepted.push(element);
|
|
56
|
+
}
|
|
57
|
+
report(diagnostics, location, parent) {
|
|
58
|
+
for (const root of parent ? [parent] : this.roots)
|
|
59
|
+
for (const element of children(root)) {
|
|
60
|
+
if (this.accepted.includes(element))
|
|
61
|
+
continue;
|
|
62
|
+
const name = nameOf(element);
|
|
63
|
+
reportDiagnostic(diagnostics, "unsupported", { ...location, element: name }, name);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
4
67
|
/** 读取上下方位置,非法或缺失值回落到调用方默认值 */
|
|
5
68
|
function placementOf(element, fallback) {
|
|
6
69
|
const placement = element.getAttribute("placement");
|
|
@@ -28,8 +91,64 @@ export function partMeasures(root) {
|
|
|
28
91
|
}
|
|
29
92
|
throw new TypeError(`Unsupported MusicXML root <${rootName}>`);
|
|
30
93
|
}
|
|
94
|
+
/** 校验 MIDI 乐器字段,并将一基 program 转为内部零基编号 */
|
|
95
|
+
export function readInstrument(midi) {
|
|
96
|
+
const instrument = {};
|
|
97
|
+
if (child(midi, "midi-channel")) {
|
|
98
|
+
instrument.channel = number(midi, "midi-channel");
|
|
99
|
+
if (!Number.isSafeInteger(instrument.channel) || instrument.channel < 1 || instrument.channel > 16) {
|
|
100
|
+
throw new RangeError("MusicXML midi-channel must be an integer in 1..16");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (child(midi, "midi-program")) {
|
|
104
|
+
instrument.program = number(midi, "midi-program") - 1;
|
|
105
|
+
if (!Number.isSafeInteger(instrument.program) || instrument.program < 0 || instrument.program > 127) {
|
|
106
|
+
throw new RangeError("MusicXML midi-program must be an integer in 1..128");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return instrument;
|
|
110
|
+
}
|
|
111
|
+
/** 文档元数据不参与时间推进;仅完整的页面声明覆盖默认页面 */
|
|
112
|
+
export function scoreMetadata(root) {
|
|
113
|
+
const credits = children(root, "credit");
|
|
114
|
+
const credit = (type) => {
|
|
115
|
+
const item = credits.find(value => text(value, "credit-type") === type);
|
|
116
|
+
return item ? text(item, "credit-words") : "";
|
|
117
|
+
};
|
|
118
|
+
const workTitle = text(child(root, "work"), "work-title");
|
|
119
|
+
const title = text(root, "movement-title")
|
|
120
|
+
|| (workTitle !== "Untitled Score" && workTitle !== "未命名乐谱" ? workTitle : "")
|
|
121
|
+
|| credit("title");
|
|
122
|
+
const subtitle = credit("subtitle");
|
|
123
|
+
const creator = credit("composer") || (() => {
|
|
124
|
+
const identification = child(root, "identification");
|
|
125
|
+
const creators = identification ? children(identification, "creator") : [];
|
|
126
|
+
return text(creators.find(item => item.getAttribute("type") === "composer") ?? creators[0]);
|
|
127
|
+
})();
|
|
128
|
+
let page;
|
|
129
|
+
const defaults = child(root, "defaults");
|
|
130
|
+
const scaling = defaults && child(defaults, "scaling");
|
|
131
|
+
const pageLayout = defaults && child(defaults, "page-layout");
|
|
132
|
+
if (scaling && pageLayout && child(pageLayout, "page-width") && child(pageLayout, "page-height")) {
|
|
133
|
+
const pixelsPerTenth = number(scaling, "millimeters") / number(scaling, "tenths") * 96 / 25.4;
|
|
134
|
+
const marginList = children(pageLayout, "page-margins");
|
|
135
|
+
const margins = marginList.find(item => item.getAttribute("type") === "odd") ?? marginList[0];
|
|
136
|
+
if (Number.isFinite(pixelsPerTenth) && pixelsPerTenth > 0) {
|
|
137
|
+
page = {
|
|
138
|
+
width: number(pageLayout, "page-width") * pixelsPerTenth,
|
|
139
|
+
height: number(pageLayout, "page-height") * pixelsPerTenth,
|
|
140
|
+
top: margins ? number(margins, "top-margin", 48 / pixelsPerTenth) * pixelsPerTenth : 48,
|
|
141
|
+
bottom: margins ? number(margins, "bottom-margin", 48 / pixelsPerTenth) * pixelsPerTenth : 48,
|
|
142
|
+
left: margins ? number(margins, "left-margin", 40 / pixelsPerTenth) * pixelsPerTenth : 40,
|
|
143
|
+
right: margins ? number(margins, "right-margin", 40 / pixelsPerTenth) * pixelsPerTenth : 40,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return { title, subtitle, creator, page };
|
|
148
|
+
}
|
|
31
149
|
/** 解析书面音高及该和弦成员自己的 tie 起止标记 */
|
|
32
|
-
export function parsePitch(note) {
|
|
150
|
+
export function parsePitch(note, location, notations) {
|
|
151
|
+
const tied = notations?.readAll("tied");
|
|
33
152
|
const pitched = child(note, "pitch");
|
|
34
153
|
const pitch = pitched ?? child(note, "unpitched");
|
|
35
154
|
if (!pitch)
|
|
@@ -41,13 +160,18 @@ export function parsePitch(note) {
|
|
|
41
160
|
throw new RangeError("jpFun requires MusicXML pitches with integer step alterations and octaves");
|
|
42
161
|
}
|
|
43
162
|
const tieTypes = new Set();
|
|
44
|
-
|
|
163
|
+
const ties = children(note, "tie");
|
|
164
|
+
for (const tie of ties)
|
|
45
165
|
tieTypes.add(tie.getAttribute("type") ?? "");
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
tieTypes.add(
|
|
166
|
+
if (tied)
|
|
167
|
+
for (const tie of tied) {
|
|
168
|
+
const type = tie.getAttribute("type") ?? "";
|
|
169
|
+
tieTypes.add(type);
|
|
170
|
+
if (type === "start" || type === "stop" || type === "continue")
|
|
171
|
+
notations?.accept(tie);
|
|
172
|
+
}
|
|
50
173
|
return {
|
|
174
|
+
location: { ...location, element: ties.length ? "tie" : tied?.length ? "tied" : nameOf(note) },
|
|
51
175
|
step,
|
|
52
176
|
alter,
|
|
53
177
|
octave,
|
|
@@ -55,23 +179,43 @@ export function parsePitch(note) {
|
|
|
55
179
|
tieStop: tieTypes.has("stop") || tieTypes.has("continue"),
|
|
56
180
|
};
|
|
57
181
|
}
|
|
182
|
+
export function transposePitch(pitch, chromatic, diatonic, octaves) {
|
|
183
|
+
const midi = (pitch.octave + 1) * 12 + NoteNameMap[pitch.step] + pitch.alter + chromatic + octaves * 12;
|
|
184
|
+
if (diatonic === undefined) {
|
|
185
|
+
const spelling = SHARP_NOTE_NAMES[((midi % 12) + 12) % 12];
|
|
186
|
+
pitch.step = spelling[0];
|
|
187
|
+
pitch.alter = spelling.length - 1;
|
|
188
|
+
pitch.octave = Math.floor(midi / 12) - 1;
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
const letters = "CDEFGAB";
|
|
192
|
+
const degree = pitch.octave * 7 + letters.indexOf(pitch.step) + diatonic + octaves * 7;
|
|
193
|
+
pitch.step = letters[((degree % 7) + 7) % 7];
|
|
194
|
+
pitch.octave = Math.floor(degree / 7);
|
|
195
|
+
pitch.alter = midi - (pitch.octave + 1) * 12 - NoteNameMap[pitch.step];
|
|
196
|
+
}
|
|
197
|
+
}
|
|
58
198
|
/** 将支持的 fermata articulation 和 ornament 转成 jpFun 修饰符 */
|
|
59
|
-
export function noteModifiers(
|
|
199
|
+
export function noteModifiers(notations, diagnostics, location) {
|
|
60
200
|
const result = [];
|
|
61
|
-
const notations = child(note, "notations");
|
|
62
201
|
if (!notations)
|
|
63
202
|
return result;
|
|
64
|
-
const fermata =
|
|
65
|
-
if (fermata)
|
|
66
|
-
result.push({
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
203
|
+
const fermata = notations.read("fermata");
|
|
204
|
+
if (fermata) {
|
|
205
|
+
result.push({ name: "fermata", placement: placementOf(fermata, fermata.getAttribute("type") === "inverted" ? "below" : "above") });
|
|
206
|
+
notations.accept(fermata);
|
|
207
|
+
}
|
|
208
|
+
const articulations = notations.read("articulations");
|
|
209
|
+
if (articulations) {
|
|
210
|
+
const accent = notations.read("accent", false, articulations);
|
|
211
|
+
if (accent) {
|
|
212
|
+
result.push({ name: "accent", placement: placementOf(accent, "above") });
|
|
213
|
+
notations.accept(accent);
|
|
214
|
+
}
|
|
215
|
+
notations.report(diagnostics, location, articulations);
|
|
216
|
+
notations.accept(articulations);
|
|
217
|
+
}
|
|
218
|
+
const ornaments = notations.read("ornaments");
|
|
75
219
|
if (ornaments) {
|
|
76
220
|
const names = [
|
|
77
221
|
["trill-mark", "tr"],
|
|
@@ -79,40 +223,43 @@ export function noteModifiers(note) {
|
|
|
79
223
|
["inverted-mordent", "prall"],
|
|
80
224
|
];
|
|
81
225
|
for (const [tag, name] of names) {
|
|
82
|
-
const ornament =
|
|
83
|
-
if (ornament)
|
|
226
|
+
const ornament = notations.read(tag, false, ornaments);
|
|
227
|
+
if (ornament) {
|
|
84
228
|
result.push({ name, placement: placementOf(ornament, "above") });
|
|
229
|
+
notations.accept(ornament);
|
|
230
|
+
}
|
|
85
231
|
}
|
|
232
|
+
notations.report(diagnostics, location, ornaments);
|
|
233
|
+
notations.accept(ornaments);
|
|
86
234
|
}
|
|
87
235
|
return result;
|
|
88
236
|
}
|
|
89
237
|
/** 无箭头不覆盖显式方向,两个相反的显式方向不能属于同一和弦。 */
|
|
90
238
|
export function mergeArpeggio(current, next) {
|
|
91
|
-
if (!next || next === "none")
|
|
239
|
+
if (!next || next.direction === "none")
|
|
92
240
|
return current ?? next;
|
|
93
|
-
if (current && current !== "none" && current !== next) {
|
|
241
|
+
if (current && current.direction !== "none" && current.direction !== next.direction) {
|
|
94
242
|
throw new RangeError("Conflicting MusicXML arpeggiate directions in one chord");
|
|
95
243
|
}
|
|
96
244
|
return next;
|
|
97
245
|
}
|
|
98
246
|
/** 读取和弦成员上的琶音方向;none 表示无箭头但仍按自下而上演奏。 */
|
|
99
|
-
export function noteArpeggio(
|
|
100
|
-
const notations = child(note, "notations");
|
|
247
|
+
export function noteArpeggio(notations, location) {
|
|
101
248
|
if (!notations)
|
|
102
249
|
return undefined;
|
|
103
250
|
let result;
|
|
104
|
-
for (const arpeggiate of
|
|
105
|
-
const
|
|
106
|
-
const value = attribute === null || attribute === "" ? "none" : attribute;
|
|
251
|
+
for (const arpeggiate of notations.readAll("arpeggiate")) {
|
|
252
|
+
const value = arpeggiate.getAttribute("direction") || "none";
|
|
107
253
|
if (value !== "none" && value !== "up" && value !== "down") {
|
|
108
254
|
throw new RangeError(`Unsupported MusicXML arpeggiate direction: ${value}`);
|
|
109
255
|
}
|
|
110
|
-
result = mergeArpeggio(result, value);
|
|
256
|
+
result = mergeArpeggio(result, { direction: value, location: { ...location, element: "arpeggiate" } });
|
|
257
|
+
notations.accept(arpeggiate);
|
|
111
258
|
}
|
|
112
259
|
return result;
|
|
113
260
|
}
|
|
114
261
|
/** 解析 tuplet 的实际音数与正常音数,并保留显式组边界 */
|
|
115
|
-
export function timeModification(note) {
|
|
262
|
+
export function timeModification(note, tuplets) {
|
|
116
263
|
const modification = child(note, "time-modification");
|
|
117
264
|
if (!modification)
|
|
118
265
|
return undefined;
|
|
@@ -121,15 +268,23 @@ export function timeModification(note) {
|
|
|
121
268
|
if (!Number.isSafeInteger(actual) || actual < 2 || !Number.isSafeInteger(normal) || normal <= 0) {
|
|
122
269
|
throw new RangeError("MusicXML time-modification requires positive integer actual-notes and normal-notes");
|
|
123
270
|
}
|
|
124
|
-
const notations = child(note, "notations");
|
|
125
|
-
const tuplets = notations ? children(notations, "tuplet") : [];
|
|
126
271
|
return {
|
|
127
272
|
actual,
|
|
128
273
|
normal,
|
|
129
|
-
start: tuplets
|
|
130
|
-
stop: tuplets
|
|
274
|
+
start: tuplets?.some(item => item.getAttribute("type") === "start") ?? false,
|
|
275
|
+
stop: tuplets?.some(item => item.getAttribute("type") === "stop") ?? false,
|
|
131
276
|
};
|
|
132
277
|
}
|
|
278
|
+
/** 和弦成员可重复声明同一边界;仅确认最终事件确实持有的节奏标记 */
|
|
279
|
+
export function acceptTuplets(notations, tuplets, rhythm) {
|
|
280
|
+
if (!notations || !tuplets || !rhythm)
|
|
281
|
+
return;
|
|
282
|
+
for (const tuplet of tuplets) {
|
|
283
|
+
const type = tuplet.getAttribute("type");
|
|
284
|
+
if ((type === "start" || type === "stop") && rhythm[type])
|
|
285
|
+
notations.accept(tuplet);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
133
288
|
/** 按 verse 收集歌词并用尾部连字符保留音节延续 */
|
|
134
289
|
export function noteLyrics(note) {
|
|
135
290
|
const result = new Map();
|
|
@@ -144,28 +299,35 @@ export function noteLyrics(note) {
|
|
|
144
299
|
}
|
|
145
300
|
return result;
|
|
146
301
|
}
|
|
147
|
-
/** 返回
|
|
148
|
-
export function directionDynamic(
|
|
149
|
-
const dynamics = descendant(direction, "dynamics");
|
|
302
|
+
/** 返回 dynamics 中首个受支持的力度记号 */
|
|
303
|
+
export function directionDynamic(dynamics, diagnostics, location) {
|
|
150
304
|
if (!dynamics)
|
|
151
305
|
return undefined;
|
|
152
|
-
|
|
306
|
+
let dynamic;
|
|
307
|
+
for (const element of children(dynamics)) {
|
|
308
|
+
const name = nameOf(element);
|
|
309
|
+
if (!dynamic && DYNAMIC_NAMES.has(name))
|
|
310
|
+
dynamic = name;
|
|
311
|
+
else
|
|
312
|
+
reportDiagnostic(diagnostics, "unsupported", { ...location, element: name }, name);
|
|
313
|
+
}
|
|
314
|
+
return dynamic;
|
|
153
315
|
}
|
|
154
|
-
/**
|
|
316
|
+
/** 收集排练标记与普通文字,排练标记保留方框语义;空白文字视为空内容 */
|
|
155
317
|
export function directionTexts(direction) {
|
|
156
318
|
const result = [];
|
|
157
319
|
for (const name of ["rehearsal", "words"]) {
|
|
158
|
-
for (const node of
|
|
320
|
+
for (const node of direction.readAll(name, true)) {
|
|
159
321
|
const value = node.textContent?.trim();
|
|
160
322
|
if (value)
|
|
161
323
|
result.push({ text: value, boxed: name === "rehearsal" });
|
|
324
|
+
direction.accept(node);
|
|
162
325
|
}
|
|
163
326
|
}
|
|
164
327
|
return result;
|
|
165
328
|
}
|
|
166
329
|
/** 将 metronome 的拍单位和附点折算成四分音符 BPM */
|
|
167
|
-
export function metronomeBpm(
|
|
168
|
-
const metronome = descendant(direction, "metronome");
|
|
330
|
+
export function metronomeBpm(metronome) {
|
|
169
331
|
if (!metronome)
|
|
170
332
|
return undefined;
|
|
171
333
|
const perMinute = Number(text(metronome, "per-minute"));
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { type MusicXmlElement } from "./dom.js";
|
|
2
|
+
import type { MusicXmlDiagnostic } from "./model.js";
|
|
2
3
|
import { type PitchMode } from "../source.js";
|
|
3
4
|
export type { MusicXmlElement, MusicXmlNode } from "./dom.js";
|
|
5
|
+
export type { MusicXmlDiagnostic } from "./model.js";
|
|
4
6
|
export interface MusicXmlToJpFunOptions {
|
|
5
7
|
pitchMode?: PitchMode;
|
|
6
8
|
barsPerLine?: number;
|
|
7
9
|
}
|
|
8
|
-
/** 将解析好的 MusicXML
|
|
9
|
-
export declare function musicXmlToJpFun(root: MusicXmlElement, options?: MusicXmlToJpFunOptions):
|
|
10
|
+
/** 将解析好的 MusicXML 根元素同步转换为 jpFun 源码,并报告未保留或近似转换的语义 */
|
|
11
|
+
export declare function musicXmlToJpFun(root: MusicXmlElement, options?: MusicXmlToJpFunOptions): {
|
|
12
|
+
script: string;
|
|
13
|
+
diagnostics: MusicXmlDiagnostic[];
|
|
14
|
+
};
|