jpfun 0.8.0 → 0.9.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.
Files changed (97) hide show
  1. package/dist/converter/midi/convert.js +8 -55
  2. package/dist/converter/musicxml/features.d.ts +1 -1
  3. package/dist/converter/musicxml/features.js +1 -1
  4. package/dist/converter/musicxml/index.js +8 -18
  5. package/dist/converter/source.d.ts +4 -7
  6. package/dist/converter/source.js +11 -9
  7. package/dist/functions/ASTtypes.d.ts +1 -14
  8. package/dist/functions/ASTtypes.js +5 -36
  9. package/dist/functions/adjust/index.js +45 -33
  10. package/dist/functions/arpeggio/index.js +42 -45
  11. package/dist/functions/arpeggio/shape.d.ts +2 -3
  12. package/dist/functions/arpeggio/shape.js +20 -50
  13. package/dist/functions/bar/index.js +3 -8
  14. package/dist/functions/beam/auto.js +54 -123
  15. package/dist/functions/beam/index.js +4 -9
  16. package/dist/functions/box/index.js +0 -6
  17. package/dist/functions/dash/index.js +3 -4
  18. package/dist/functions/div/index.d.ts +2 -4
  19. package/dist/functions/div/index.js +10 -10
  20. package/dist/functions/dot/index.js +3 -9
  21. package/dist/functions/dyn/index.js +6 -26
  22. package/dist/functions/gliss/index.js +95 -89
  23. package/dist/functions/grace/index.d.ts +2 -5
  24. package/dist/functions/grace/index.js +44 -89
  25. package/dist/functions/head/index.js +9 -6
  26. package/dist/functions/key/index.js +6 -6
  27. package/dist/functions/meter/index.js +3 -3
  28. package/dist/functions/note/index.js +1 -1
  29. package/dist/functions/note/source-transform.js +2 -5
  30. package/dist/functions/ottava/index.js +11 -32
  31. package/dist/functions/page/index.js +13 -16
  32. package/dist/functions/rest/index.js +2 -4
  33. package/dist/functions/slide/index.js +0 -1
  34. package/dist/functions/stack/index.js +8 -57
  35. package/dist/functions/temporal.d.ts +2 -2
  36. package/dist/functions/temporal.js +7 -0
  37. package/dist/functions/text/index.js +24 -30
  38. package/dist/functions/tie/index.js +14 -37
  39. package/dist/functions/tremolo/index.js +0 -1
  40. package/dist/functions/tuplet/index.js +0 -6
  41. package/dist/functions/up/index.js +79 -83
  42. package/dist/functions/voice/connections.d.ts +2 -1
  43. package/dist/functions/voice/connections.js +48 -10
  44. package/dist/functions/voice/index.d.ts +2 -3
  45. package/dist/functions/voice/index.js +2 -970
  46. package/dist/functions/voice/lyrics.d.ts +30 -0
  47. package/dist/functions/voice/lyrics.js +289 -0
  48. package/dist/functions/voice/voice.d.ts +63 -0
  49. package/dist/functions/voice/voice.js +373 -0
  50. package/dist/functions/voice/voices.d.ts +106 -0
  51. package/dist/functions/voice/voices.js +423 -0
  52. package/dist/functions/volta/index.js +5 -23
  53. package/dist/jpfun.core.min.js +65 -56
  54. package/dist/jpfun.from-midi.min.js +5 -5
  55. package/dist/jpfun.from-musicxml.min.js +7 -7
  56. package/dist/jpfun.min.js +68 -59
  57. package/dist/layout/engine.js +30 -18
  58. package/dist/layout/model.d.ts +0 -1
  59. package/dist/layout/model.js +1 -4
  60. package/dist/layout/page.d.ts +2 -1
  61. package/dist/layout/page.js +14 -14
  62. package/dist/layout/range.d.ts +7 -6
  63. package/dist/layout/range.js +23 -14
  64. package/dist/layout/types.d.ts +9 -28
  65. package/dist/lowering/loweringContext.d.ts +8 -11
  66. package/dist/lowering/loweringContext.js +7 -13
  67. package/dist/lowering/track.d.ts +8 -1
  68. package/dist/lowering/types.d.ts +12 -8
  69. package/dist/parser/parse-utils/call-utils.d.ts +1 -2
  70. package/dist/parser/parse-utils/call-utils.js +6 -34
  71. package/dist/parser/parse-utils/note-utils.d.ts +3 -3
  72. package/dist/parser/parse-utils/note-utils.js +17 -28
  73. package/dist/parser/parse-utils/string-utils.d.ts +1 -1
  74. package/dist/parser/parse-utils/string-utils.js +8 -6
  75. package/dist/parser/parserContext.d.ts +9 -9
  76. package/dist/parser/parserContext.js +54 -10
  77. package/dist/pipeline.js +2 -2
  78. package/dist/playback/compile.js +13 -14
  79. package/dist/playback/event.d.ts +6 -6
  80. package/dist/playback/event.js +13 -49
  81. package/dist/render/canvas.d.ts +0 -2
  82. package/dist/render/canvas.js +0 -21
  83. package/dist/render/svg.d.ts +0 -1
  84. package/dist/render/svg.js +33 -31
  85. package/dist/render/text.d.ts +36 -1
  86. package/dist/render/text.js +134 -0
  87. package/dist/render/types.d.ts +0 -2
  88. package/grammar.md +16 -13
  89. package/package.json +1 -1
  90. package/dist/iife/core.d.ts +0 -1
  91. package/dist/iife/core.js +0 -3
  92. package/dist/iife/from-midi.d.ts +0 -1
  93. package/dist/iife/from-midi.js +0 -15
  94. package/dist/iife/from-musicxml.d.ts +0 -1
  95. package/dist/iife/from-musicxml.js +0 -3
  96. package/dist/iife/full.d.ts +0 -1
  97. package/dist/iife/full.js +0 -3
@@ -0,0 +1,373 @@
1
+ import { ASTBraceNode, ASTFunctionNode, ASTTextNode } from "../ASTtypes.js";
2
+ import { Diagnostic, ErrorDiagnostic, WarningDiagnostic } from "../../diagnostic.js";
3
+ import { isLayoutAttachment } from "../../layout/types.js";
4
+ import { findRightParen } from "../../parser/parse-utils/call-utils.js";
5
+ import { findClosingQuote, quote } from "../../parser/parse-utils/string-utils.js";
6
+ import { ParserContext, skipSpaces } from "../../parser/parserContext.js";
7
+ import { paintRichLine, prepareRichLine } from "../../render/text.js";
8
+ import { isVisualTemporalNode, TemporalNodeBase } from "../temporal.js";
9
+ import { lyricNameStyle, parseLyric, serializeLyric, VoiceLyricsAttachment } from "./lyrics.js";
10
+ import { VoicesFunction } from "./voices.js";
11
+ /** 无大括号时标签右侧的空隙,相对声部字号 */
12
+ const NAME_GAP_RATIO = 0.6;
13
+ export function voiceNameStyle(size, fontFamily) {
14
+ return {
15
+ fontFamily,
16
+ fontSize: size * 0.85,
17
+ fill: "#000",
18
+ textAlign: "right",
19
+ };
20
+ }
21
+ export class VoiceFunction extends ASTFunctionNode {
22
+ static def = {
23
+ name: ["voice", "v"],
24
+ description: "声部",
25
+ details: `\
26
+ ~~~jpfun
27
+ @voice({1 2 3}, 钢琴, 男=ha ha ha, 女=la la la)
28
+ ~~~
29
+ - **额外参数**:每项为一行歌词;命名参数同时给出歌词行名,位置参数表示无行名。省略声部名但仍需歌词时,保留空位,如 \`@voice({1 2 3}, , ha ha ha)\`。
30
+
31
+ 歌词可用引号包裹;调用 \`@voice\` 时歌词若含逗号须加引号。英文用空格或连字符 \`-\` 分词,用 \`@\` 留空。名称与歌词均支持 \`*斜体*\`、\`**粗体**\`、\`_下划线_\`、\`^上标^\`(可跨多个音符,如 \`*春眠不觉晓*\`)。
32
+
33
+ **简写**:\`N\` 声明音符行,\`L\` 声明歌词行,括号内的名称可省略:
34
+ ~~~jpfun
35
+ N(钢琴): 1 2 3
36
+ L(男): ha ha ha
37
+ L: la la la
38
+ ~~~
39
+ 换行结束当前行,行末加 \`\\\` 可续行;\`L:\` 中可直接使用逗号。`,
40
+ allowExtraArgs: true,
41
+ extraArgType: "string",
42
+ args: [
43
+ {
44
+ type: "content",
45
+ description: "声部的音符内容",
46
+ default: null,
47
+ },
48
+ {
49
+ name: "name",
50
+ description: "显示在左侧的声部名称,空值隐藏名称",
51
+ type: "string",
52
+ default: "",
53
+ },
54
+ // 之后的参数都当作歌词参数
55
+ ],
56
+ };
57
+ // 去糖第一阶段识别两个标签 这里先不消费换行符,因为 br 可能需要
58
+ static deSugarAtom(source, start, end) {
59
+ if (source[start] !== "N" && source[start] !== "L")
60
+ return null;
61
+ let pos = start + 1;
62
+ let name = { start: pos, end: pos };
63
+ if (source[pos] === "(") {
64
+ // `X(name)` 提取括号
65
+ const at = findRightParen(source, pos + 1, end);
66
+ if (at < 0)
67
+ return null; // 没有找到匹配的右括号 不去糖
68
+ name = { start: pos + 1, end: at };
69
+ pos = at + 1;
70
+ }
71
+ if (source[pos++] !== ":")
72
+ return null; // `:` 之前不允许有空格
73
+ // 识别具体内容
74
+ if (source[start] === "N") {
75
+ // 等到第二轮寻找该层级的终止符 \n 来确定内容范围
76
+ const node = {
77
+ kind: "sugar",
78
+ data: {
79
+ class: VoiceFunction,
80
+ name,
81
+ },
82
+ span: { start, end: pos },
83
+ };
84
+ return { next: pos, node };
85
+ }
86
+ // 字符串收集
87
+ pos = skipSpaces(source, pos, end);
88
+ if (pos >= end)
89
+ return null; // 没有内容了 不去糖
90
+ let lyric;
91
+ // 双引号才是字符串,单引号不是
92
+ if (source[pos] === '"') {
93
+ // 未闭合就不去糖,词法层每次击键都跑,不能抛
94
+ const close = findClosingQuote(source, pos, end);
95
+ if (close < 0)
96
+ return null;
97
+ lyric = { start: pos, end: close + 1 };
98
+ pos = close + 1;
99
+ }
100
+ else {
101
+ // 没有引号的 以换行符为界切分 预处理已经跳过了转义的换行符了
102
+ const from = pos;
103
+ while (pos < end && source[pos] !== "\n")
104
+ pos++;
105
+ lyric = { start: from, end: pos };
106
+ }
107
+ const node = {
108
+ kind: "sugar",
109
+ data: {
110
+ class: VoiceFunction,
111
+ lyric,
112
+ name,
113
+ },
114
+ span: { start, end: pos },
115
+ };
116
+ return { next: pos, node };
117
+ }
118
+ static deSugarRelation(ctx, nodes, at, members) {
119
+ const n = nodes[at++];
120
+ if (n.data?.class !== VoiceFunction)
121
+ return null;
122
+ const parseStr = (span) => ctx.parseArgWithType(span, "string") ?? "";
123
+ if (n.data?.lyric !== void 0) {
124
+ // 歌词 需要找到最近的voice节点并添加歌词
125
+ let voiceNode = null;
126
+ let voiceNodeAt = ctx.nodes.length - 1;
127
+ for (; voiceNodeAt >= 0; voiceNodeAt--) {
128
+ const n = ctx.nodes[voiceNodeAt];
129
+ if (n instanceof ASTTextNode) {
130
+ if (!ctx.variables.strict)
131
+ continue; // 非严格模式下允许文本节点夹在N和L之间
132
+ // ParserContext.parseGrammar 处理后不会有空白字符
133
+ throw new ErrorDiagnostic("E_LYRICS_WITHOUT_VOICE_NOTES", `strict 模式下,语法糖 'L:' 或 'L(name)' 必须跟在 @voice 的音符之后,但在其前面发现了未知文本`, n.sourceSpan);
134
+ }
135
+ if (n instanceof VoiceFunction)
136
+ voiceNode = n;
137
+ else if (n instanceof VoicesFunction)
138
+ voiceNode = n.voices.at(-1) ?? null;
139
+ break;
140
+ }
141
+ if (voiceNode === null) {
142
+ throw new ErrorDiagnostic("E_LYRICS_WITHOUT_VOICE_NOTES", `语法糖 'L:' 或 'L(name):' 必须跟在 @voice(或 N:)之后,但没有找到符合要求的 voice;请检查语法或直接使用 @voice 函数`, n.span);
143
+ }
144
+ voiceNode.addLyric(parseStr(n.data.name), parseStr(n.data.lyric), n.span, ctx);
145
+ ctx.nodes.length = voiceNodeAt + 1; // 清除voiceNodeAt之后的TextNode 因为被夹在N和L之间
146
+ // 消费后面可能的换行符 只消费一个
147
+ if (at < nodes.length && typeof nodes[at] === "number" && ctx.source[nodes[at]] === "\n")
148
+ at++;
149
+ return at;
150
+ }
151
+ const name = parseStr(n.data.name);
152
+ // 当前层的换行或 N/L/V 声明结束音符内容,不能把下一组吞进声部
153
+ let breakAt = at;
154
+ let endWithBr = 0;
155
+ for (; breakAt < nodes.length; breakAt++) {
156
+ const n = nodes[breakAt];
157
+ if (typeof n === "number") {
158
+ if (ctx.source[n] === "\n") {
159
+ // 换行符应该被 N: 消费
160
+ endWithBr = 1;
161
+ break;
162
+ }
163
+ }
164
+ else if (n.kind === "sugar"
165
+ && (n.data?.class === VoiceFunction || n.data?.class === VoicesFunction))
166
+ break;
167
+ }
168
+ // 解析后面的内容 得到 VoiceFunction
169
+ const newCtx = new ParserContext(ctx);
170
+ const slicedNodes = nodes.slice(at, breakAt); // 防止子解析越界
171
+ breakAt += endWithBr; // 不让子内容有换行符
172
+ newCtx.makeNodes(slicedNodes);
173
+ if (newCtx.nodes.length === 0) {
174
+ throw Diagnostic.error.EmptyContent("voice", "content", n.span);
175
+ }
176
+ const span = { start: n.span.start, end: newCtx.nodes.at(-1).sourceSpan.end };
177
+ const argMap = new Map();
178
+ if (newCtx.nodes.length === 1 && newCtx.nodes[0] instanceof ASTBraceNode)
179
+ argMap.set(0, newCtx.nodes[0]);
180
+ // 复制一份:voice 的 span 之后会被歌词撑大,内容 brace 不该跟着长
181
+ else
182
+ argMap.set(0, new ASTBraceNode({ ...span }, newCtx.nodes));
183
+ argMap.set("name", name);
184
+ const newVoice = new VoiceFunction(span, argMap, ctx, null);
185
+ // V 声明直接收集成员,最后统一组装,避免创建临时 voices
186
+ if (members) {
187
+ ctx.pushNode(newVoice);
188
+ members.push(newVoice);
189
+ return breakAt;
190
+ }
191
+ // 如果前面紧挨着 VoicesFunction | VoiceFunction 则直接加入
192
+ let voicesNode = null;
193
+ let voicesNodeAt = ctx.nodes.length - 1;
194
+ let textBetween = null;
195
+ ifCombine: for (; voicesNodeAt >= 0; voicesNodeAt--) {
196
+ const n = ctx.nodes[voicesNodeAt];
197
+ if (n instanceof ASTTextNode) {
198
+ if (ctx.variables.strict)
199
+ break;
200
+ // 如果中间有换行符,直接说明是两个独立的 voice 组件,不能合并
201
+ for (let i = n.sourceSpan.start; i < n.sourceSpan.end; i++) {
202
+ if (ctx.source[i] === "\n")
203
+ break ifCombine;
204
+ }
205
+ textBetween = n;
206
+ continue;
207
+ }
208
+ if (n instanceof VoicesFunction) {
209
+ if (!n.createdBySugar)
210
+ break; // 不会合并到函数创建的 voices 中
211
+ voicesNode = n;
212
+ }
213
+ else if (n instanceof VoiceFunction) {
214
+ const args = new Map();
215
+ args.set(0, n);
216
+ voicesNode = new VoicesFunction({
217
+ start: n.sourceSpan.start,
218
+ end: n.sourceSpan.end,
219
+ }, args, ctx, null);
220
+ voicesNode.createdBySugar = true;
221
+ }
222
+ break;
223
+ }
224
+ if (voicesNode) {
225
+ ctx.nodes[voicesNodeAt] = voicesNode;
226
+ voicesNode.addVoice(newVoice);
227
+ if (textBetween) {
228
+ ctx.nodes.length = voicesNodeAt + 1;
229
+ ctx.diagnostics.push(new WarningDiagnostic("W_VOICES_TEXT_BETWEEN", `两个 @voice 之间有未知文本。当前处于非 strict 模式,会忽略该内容、合并为一个 @voices`, textBetween.sourceSpan));
230
+ }
231
+ }
232
+ else
233
+ ctx.pushNode(newVoice);
234
+ return breakAt;
235
+ }
236
+ content; // 声部内容
237
+ name; // 声部名称
238
+ size; // 声部的字体大小
239
+ font;
240
+ lyrics;
241
+ get children() { return [this.content]; }
242
+ /**
243
+ * voice 的音符内容仍按普通 sequence 进入全局时间列
244
+ * 此处按需建立歌词作用域,并在内容前创建声部名对象
245
+ */
246
+ loweringEnter(ctx) {
247
+ // 无名声部也要产出一个(不可见的)名称事件,才能保证同一个 voices 块内
248
+ // 每个成员的列结构完全一致,从而把所有声部名归并到同一列
249
+ const parent = this.parent;
250
+ // 多声部时同时在名称右侧预留大括号的横向空间
251
+ const braceSpace = parent instanceof VoicesFunction && parent.voices.length > 1
252
+ ? parent.braceSpace
253
+ : 0;
254
+ const nameHost = new VoiceNameTemporal(this, braceSpace);
255
+ if (this.lyrics.length > 0) {
256
+ const group = {
257
+ nameHost,
258
+ nodes: [],
259
+ frames: [],
260
+ onTemporal(node) {
261
+ if (isVisualTemporalNode(node))
262
+ group.nodes.push(node);
263
+ },
264
+ onAttachment(attachment) {
265
+ if (isLayoutAttachment(attachment) && attachment.layer === "background")
266
+ group.frames.push(attachment);
267
+ },
268
+ };
269
+ ctx.beginLoweringGroup(this, group);
270
+ }
271
+ return [nameHost];
272
+ }
273
+ loweringExit(ctx) {
274
+ if (this.lyrics.length > 0) {
275
+ const { nodes, nameHost, frames } = ctx.endLoweringGroup(this);
276
+ ctx.addAttachment(new VoiceLyricsAttachment(nodes, nameHost, frames));
277
+ }
278
+ return [];
279
+ }
280
+ constructor(span, args, ctx, parent = null) {
281
+ super(span, parent);
282
+ this.size = ctx.variables.fontsize;
283
+ [this.content, this.name] = this.getArgValue(args, ctx);
284
+ this.content.parent = this;
285
+ this.font = ctx.variables.font;
286
+ args.delete(0);
287
+ args.delete("name");
288
+ args.delete(1);
289
+ this.lyrics = [];
290
+ for (const [key, value] of args) {
291
+ if (typeof value === "string") {
292
+ this.addLyric(key, value);
293
+ continue;
294
+ }
295
+ const arg = value;
296
+ const v = ctx.parseArgWithType(arg.valueSpan, "string", span.start);
297
+ if (v === null) {
298
+ ctx.diagnostics.push(new WarningDiagnostic("W_VOICE_INVALID_LYRIC", "@voice 的歌词参数值解析失败, 参数[{key}]将被忽略", arg.valueSpan, { key }));
299
+ }
300
+ else
301
+ this.addLyric(key, v);
302
+ }
303
+ }
304
+ addLyric(name, lyric, span = null, ctx = null) {
305
+ if (typeof name === "number")
306
+ name = "";
307
+ const tokens = parseLyric(lyric);
308
+ if (tokens.length === 0 && ctx && span) {
309
+ ctx.diagnostics.push(new WarningDiagnostic("W_EMPTY_LYRIC", "@voice的歌词{name}是空的", span, { name }));
310
+ }
311
+ this.lyrics.push({ name, tokens });
312
+ if (span) {
313
+ // 歌词是成节点之后才补上来的,祖先的 span 得一起长,否则按源码位置查节点会漏掉歌词那几行
314
+ for (let node = this; node; node = node.parent) {
315
+ node.sourceSpan.start = Math.min(span.start, node.sourceSpan.start);
316
+ node.sourceSpan.end = Math.max(span.end, node.sourceSpan.end);
317
+ }
318
+ }
319
+ }
320
+ toString(source) {
321
+ const parameters = [`${this.content.toString(source)},${quote(this.name)}`];
322
+ for (const lyric of this.lyrics) {
323
+ const text = serializeLyric(lyric.tokens);
324
+ parameters.push(lyric.name ? `${lyric.name}=${text}` : text);
325
+ }
326
+ return `@voice(\n\t${parameters.join(",\n\t")}\n)`;
327
+ }
328
+ }
329
+ export class VoiceNameTemporal extends TemporalNodeBase {
330
+ /** 名称右侧为大括号预留的横向空间,0 表示不需要 */
331
+ braceSpace;
332
+ preparedName = null;
333
+ constructor(ast, braceSpace) {
334
+ super();
335
+ this.ast = ast;
336
+ this.braceSpace = braceSpace;
337
+ this.mergeKey = -2;
338
+ // 既没有名称、也不需要括号空间和标签列时只保留不可见的占位事件:
339
+ // 它不进入可见对象,也不让空声部失去默认槽位高度
340
+ if (ast.name || braceSpace > 0 || ast.lyrics.some(lyric => lyric.name))
341
+ this.initLayoutBox();
342
+ }
343
+ prepareLayout(context) {
344
+ this.preparedName = this.ast.name
345
+ ? prepareRichLine(this.ast.name, voiceNameStyle(this.ast.size, this.ast.font), context.textMeasurer)
346
+ : null;
347
+ // 声部名和歌词行名称共用这一列,列宽取其中最宽的一个
348
+ let labelWidth = this.preparedName?.w ?? 0;
349
+ const lyricStyle = lyricNameStyle(this.ast.size, this.ast.font);
350
+ for (const lyric of this.ast.lyrics) {
351
+ if (!lyric.name)
352
+ continue;
353
+ labelWidth = Math.max(labelWidth, prepareRichLine(lyric.name, lyricStyle, context.textMeasurer).w);
354
+ }
355
+ // 没有大括号时也要在标签右侧留出与内容分离的空隙
356
+ const rightSpace = this.braceSpace > 0 ? this.braceSpace
357
+ : labelWidth > 0 ? this.ast.size * NAME_GAP_RATIO : 0;
358
+ // 对齐点放在标签右边界:同一列共享 `x + anchor`,因此长短不一的声部名会右对齐,
359
+ // 括号空间统一落在对齐点右侧
360
+ this.box.w = labelWidth + rightSpace;
361
+ this.box.h = this.preparedName?.h ?? 0;
362
+ this.box.anchor = labelWidth;
363
+ this.box.visualAxis = this.box.h / 2;
364
+ // 声部名与第一个音符之间需要稳定但可压缩的横向间距
365
+ this.springConfig.alpha_R = 0.45;
366
+ }
367
+ paint(painter) {
368
+ if (!this.preparedName)
369
+ return;
370
+ paintRichLine(painter, this.preparedName, this.box.x + this.box.anchor, this.box.y + this.preparedName.baseline);
371
+ }
372
+ }
373
+ export const VoiceNode = VoiceFunction;
@@ -0,0 +1,106 @@
1
+ import { ASTFunctionClass, ASTFunctionNode, ASTNodeBase, FunctionArgs, SourceSpan } from "../ASTtypes.js";
2
+ import type { LoweringContext } from "../../lowering/loweringContext.js";
3
+ import type { MeasureFn, Track } from "../../lowering/track.js";
4
+ import type { GrammarNode } from "../../parser/grammarType.js";
5
+ import { ParserContext } from "../../parser/parserContext.js";
6
+ import { VoiceFunction } from "./voice.js";
7
+ /**
8
+ * voices 块在宿主基线上局部居中:首末两条 voice 基线的中点对齐宿主轴
9
+ *
10
+ * 居中只看**基线**,不看成员的整体视觉边界,也不取所有基线的算术平均值。
11
+ * 因此嵌套的 stack、歌词、装饰只会撑开相邻基线的间距和行高,
12
+ * 不会把整个块相对于主旋律的语义中心挪走。
13
+ *
14
+ * 本行没有实质高度的成员(空声部,或内容都在上一行)仍然占一个默认高度的槽位,
15
+ * 声部数量因而保持稳定,居中结果也不会因为某一声部没写东西而跳变。
16
+ */
17
+ type VoicesMeasure = MeasureFn & {
18
+ size: number;
19
+ gap: number;
20
+ minGap: number;
21
+ };
22
+ export declare class VoicesFunction extends ASTFunctionNode {
23
+ static def: {
24
+ name: string[];
25
+ description: string;
26
+ details: string;
27
+ allowExtraArgs: boolean;
28
+ extraArgType: "content";
29
+ args: ({
30
+ name: string;
31
+ namedOnly: boolean;
32
+ type: "string";
33
+ default: string;
34
+ description: string;
35
+ } | {
36
+ name: string;
37
+ namedOnly: boolean;
38
+ type: "length";
39
+ default: {
40
+ value: number;
41
+ unit: "em";
42
+ };
43
+ description: string;
44
+ })[];
45
+ };
46
+ static deSugarAtom(source: string, start: number, end: number): {
47
+ next: number;
48
+ node: {
49
+ kind: "sugar";
50
+ data: {
51
+ name?: undefined;
52
+ class: typeof VoicesFunction;
53
+ kind: "line";
54
+ };
55
+ span: {
56
+ start: number;
57
+ end: number;
58
+ };
59
+ };
60
+ } | {
61
+ next: number;
62
+ node: {
63
+ kind: "sugar";
64
+ data: {
65
+ class: typeof VoicesFunction;
66
+ kind: "brace" | "bracket";
67
+ name: {
68
+ start: number;
69
+ end: number;
70
+ };
71
+ };
72
+ span: {
73
+ start: number;
74
+ end: number;
75
+ };
76
+ };
77
+ } | null;
78
+ static deSugarRelation(ctx: ParserContext, nodes: (GrammarNode | number)[], at: number): number | null;
79
+ voices: VoiceFunction[];
80
+ createdBySugar: boolean;
81
+ size: number;
82
+ readonly font: string;
83
+ gap: number;
84
+ minGap: number;
85
+ private readonly connect;
86
+ /** 声部名右侧为大括号预留的横向空间 */
87
+ get braceSpace(): number;
88
+ private get connectionSpecs();
89
+ get children(): VoiceFunction[];
90
+ timeFlowModel(): {
91
+ children: VoiceFunction[];
92
+ mode: "parallel";
93
+ tracks: {
94
+ laneKey: string;
95
+ hostIndex: null;
96
+ measure: VoicesMeasure;
97
+ };
98
+ };
99
+ /** 退出时按本块各声部的名称事件注册左侧连谱号,并合并同一组音轨的间距配置 */
100
+ loweringExit(ctx: LoweringContext, track: Track): never[];
101
+ constructor(span: SourceSpan, args: FunctionArgs, ctx: ParserContext, parent?: ASTNodeBase | null);
102
+ addVoice(v: VoiceFunction): void;
103
+ toString(source: string): string;
104
+ }
105
+ export declare const VoicesNode: ASTFunctionClass;
106
+ export {};