jpfun 0.7.0 → 0.8.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/Bravura-LICENSE.txt +93 -0
- package/README.md +49 -146
- package/dist/Bravura-LICENSE.txt +93 -0
- package/dist/converter/midi/convert.d.ts +0 -10
- package/dist/converter/midi/convert.js +11 -1
- package/dist/converter/musicxml/features.d.ts +15 -7
- package/dist/converter/musicxml/features.js +87 -18
- package/dist/converter/musicxml/index.js +80 -32
- package/dist/converter/musicxml/model.d.ts +9 -0
- package/dist/core.d.ts +1 -0
- package/dist/core.js +1 -0
- package/dist/diagnostic.d.ts +7 -1
- package/dist/diagnostic.js +40 -88
- package/dist/fraction.js +3 -2
- package/dist/functions/ASTtypes.d.ts +2 -18
- package/dist/functions/ASTtypes.js +0 -16
- package/dist/functions/arpeggio/index.js +15 -17
- package/dist/functions/bar/index.d.ts +8 -0
- package/dist/functions/bar/index.js +102 -0
- package/dist/functions/beam/auto.d.ts +1 -2
- package/dist/functions/beam/auto.js +30 -16
- package/dist/functions/beam/index.js +2 -3
- package/dist/functions/beam/layout.d.ts +1 -1
- package/dist/functions/beam/layout.js +1 -1
- package/dist/functions/br/index.d.ts +34 -2
- package/dist/functions/br/index.js +5 -4
- package/dist/functions/dash/index.js +6 -6
- package/dist/functions/default.js +2 -1
- package/dist/functions/div/index.d.ts +1 -0
- package/dist/functions/div/index.js +8 -4
- package/dist/functions/dot/index.js +2 -2
- package/dist/functions/dyn/index.js +49 -31
- package/dist/functions/gliss/index.js +75 -53
- package/dist/functions/grace/index.d.ts +1 -7
- package/dist/functions/grace/index.js +8 -13
- package/dist/functions/head/index.js +1 -1
- package/dist/functions/key/index.js +8 -10
- package/dist/functions/meter/index.d.ts +56 -1
- package/dist/functions/meter/index.js +12 -7
- package/dist/functions/note/index.js +5 -5
- package/dist/functions/note/noteName.d.ts +16 -0
- package/dist/functions/note/noteName.js +88 -0
- package/dist/functions/note/source-transform.js +6 -5
- package/dist/functions/ottava/index.js +24 -8
- package/dist/functions/page/index.d.ts +1 -0
- package/dist/functions/page/index.js +20 -11
- package/dist/functions/pagebreak/index.js +2 -2
- package/dist/functions/rest/index.js +3 -1
- package/dist/functions/set/index.js +4 -4
- package/dist/functions/symbol/index.d.ts +21 -2
- package/dist/functions/symbol/index.js +69 -24
- package/dist/functions/symbol/ornament.d.ts +1 -2
- package/dist/functions/symbol/shape.d.ts +6 -0
- package/dist/functions/symbol/shape.js +16 -3
- package/dist/functions/symbol/symbols/coda.d.ts +4 -0
- package/dist/functions/symbol/symbols/coda.js +56 -0
- package/dist/functions/symbol/symbols/dynamics.d.ts +1 -1
- package/dist/functions/symbol/symbols/dynamics.js +18 -8
- package/dist/functions/symbol/symbols/harmonic.d.ts +2 -0
- package/dist/functions/symbol/symbols/harmonic.js +11 -0
- package/dist/functions/symbol/symbols/marcato.d.ts +2 -0
- package/dist/functions/symbol/symbols/marcato.js +22 -0
- package/dist/functions/symbol/symbols/staccato.d.ts +2 -0
- package/dist/functions/symbol/symbols/staccato.js +24 -0
- package/dist/functions/symbol/symbols/tenuto.d.ts +2 -0
- package/dist/functions/symbol/symbols/tenuto.js +11 -0
- package/dist/functions/symbol/symbols/tocoda.d.ts +2 -0
- package/dist/functions/symbol/symbols/tocoda.js +16 -0
- package/dist/functions/symbol/symbols/turn.d.ts +3 -0
- package/dist/functions/symbol/symbols/turn.js +50 -0
- package/dist/functions/symbol/symbols/wheel.d.ts +2 -0
- package/dist/functions/symbol/symbols/wheel.js +36 -0
- package/dist/functions/temporal.d.ts +1 -0
- package/dist/functions/temporal.js +1 -0
- package/dist/functions/text/index.js +15 -6
- package/dist/functions/tie/index.js +30 -6
- package/dist/functions/tremolo/index.d.ts +2 -0
- package/dist/functions/tremolo/index.js +319 -0
- package/dist/functions/tuplet/index.js +4 -8
- package/dist/functions/up/index.js +2 -2
- package/dist/functions/voice/index.js +17 -10
- package/dist/jpfun.core.min.js +57 -49
- package/dist/jpfun.from-midi.min.js +5 -5
- package/dist/jpfun.from-musicxml.min.js +8 -8
- package/dist/jpfun.min.js +62 -54
- package/dist/layout/default.d.ts +0 -1
- package/dist/layout/default.js +0 -1
- package/dist/lowering/loweringContext.d.ts +11 -13
- package/dist/lowering/loweringContext.js +26 -33
- package/dist/lowering/types.d.ts +1 -3
- package/dist/parser/parse-utils/note-utils.d.ts +1 -1
- package/dist/parser/parse-utils/note-utils.js +8 -9
- package/dist/parser/parse-utils/string-utils.d.ts +3 -2
- package/dist/parser/parse-utils/string-utils.js +16 -3
- package/dist/parser/parserContext.js +9 -2
- package/dist/pipeline.js +0 -1
- package/dist/playback/compile.js +120 -70
- package/dist/playback/event.d.ts +1 -1
- package/dist/playback/event.js +9 -9
- package/dist/playback/time.js +42 -31
- package/dist/playback/types.d.ts +3 -1
- package/dist/render/canvas.d.ts +2 -0
- package/dist/render/canvas.js +25 -22
- package/dist/render/recording.js +1 -4
- package/dist/render/translate.d.ts +0 -1
- package/dist/render/translate.js +6 -23
- package/grammar.md +26 -20
- package/package.json +3 -3
- package/dist/functions/note/noteNameFSM.d.ts +0 -8
- package/dist/functions/note/noteNameFSM.js +0 -181
|
@@ -162,22 +162,6 @@ export class ASTFunctionNode extends ASTNodeBase {
|
|
|
162
162
|
return super.toString(source);
|
|
163
163
|
return `@${name} `;
|
|
164
164
|
}
|
|
165
|
-
/**
|
|
166
|
-
* lowering 固化后的 attachment 生成钩子
|
|
167
|
-
*
|
|
168
|
-
* 普通 loweringEnter/loweringExit 在递归遍历 AST 时执行,
|
|
169
|
-
* 此时尚未完成锚点归并,事件的 t、track 和 layoutLine 不可用,因此需要观察完整事件流的功能不能在普通 hook 中可靠决定分组。
|
|
170
|
-
* 该 hook 读取 LoweringResult 并返回新建的 LoweringAttachment,LoweringContext 将返回值追加到当前文档或 fragment 的 attachments,不会把它们放入时间列或推进时间。
|
|
171
|
-
*
|
|
172
|
-
* 例:autobeam 扫描最终列,按轨道、谱面行、拍点和显式 beam 端点决定分组,再生成 BeamLayoutAttachment
|
|
173
|
-
*/
|
|
174
|
-
static loweringAugment;
|
|
175
|
-
/**
|
|
176
|
-
* 所有 loweringAugment 结果追加完成后的最终处理;此时已经得到了完整的 lowering 语义
|
|
177
|
-
* 所有派生 attachment 追加完成后,按函数注册顺序处理完整结果
|
|
178
|
-
* 可以进行校验(如 beam 和 tie)或者修改某些值
|
|
179
|
-
*/
|
|
180
|
-
static loweringFinalize;
|
|
181
165
|
/**
|
|
182
166
|
* 装饰函数可选的排版声明
|
|
183
167
|
* layout 引擎按 key 收集,不需要识别具体函数类
|
|
@@ -79,7 +79,8 @@ class ArpeggioFunction extends ASTFunctionNode {
|
|
|
79
79
|
export const ArpeggioNode = ArpeggioFunction;
|
|
80
80
|
class ArpeggioTemporal extends TemporalNodeBase {
|
|
81
81
|
host;
|
|
82
|
-
|
|
82
|
+
/** 槽位取自成员顺序;无声成员也占槽,不能按实际发声音符重新编号 */
|
|
83
|
+
slots;
|
|
83
84
|
hostX = 0;
|
|
84
85
|
markX = 0;
|
|
85
86
|
markCommands = [];
|
|
@@ -93,7 +94,8 @@ class ArpeggioTemporal extends TemporalNodeBase {
|
|
|
93
94
|
host.members[0],
|
|
94
95
|
...host.members.slice(1, aboveCount),
|
|
95
96
|
];
|
|
96
|
-
|
|
97
|
+
const members = ast.direction === "down" ? bottomToTop.reverse() : bottomToTop;
|
|
98
|
+
this.slots = new Map(members.map((member, index) => [member, index]));
|
|
97
99
|
this.T.copyFrom(host.T);
|
|
98
100
|
this.mergeKey = host.mergeKey;
|
|
99
101
|
this.initLayoutBox();
|
|
@@ -149,28 +151,24 @@ class ArpeggioTemporal extends TemporalNodeBase {
|
|
|
149
151
|
const total = emitter.end.clone().sub(emitter.start);
|
|
150
152
|
const step = new Fraction(1, 8);
|
|
151
153
|
// 短音段限制总延迟,让最后一个成员仍保留至少一半的宿主窗口。
|
|
152
|
-
const maxStep = total.clone().div(2).div(this.
|
|
154
|
+
const maxStep = total.clone().div(2).div(this.slots.size - 1);
|
|
153
155
|
if (step.compare(maxStep) > 0)
|
|
154
156
|
step.copyFrom(maxStep);
|
|
155
|
-
|
|
156
|
-
const slots = new Map(this.playbackMembers.map((member, index) => [member, index]));
|
|
157
|
+
const { slots } = this;
|
|
157
158
|
const owner = this;
|
|
158
159
|
emitter.defer(context => {
|
|
159
160
|
let rootOrigin;
|
|
160
|
-
//
|
|
161
|
+
// 宿主刚在上面发布,其全部子区间连续排在 spans 末尾;命中后处理完同组即停。
|
|
161
162
|
for (let index = context.spans.length - 1; index >= 0; index--) {
|
|
162
163
|
const note = context.spans[index];
|
|
163
|
-
if (!
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
for (const note of context.spans) {
|
|
172
|
-
if (note.origins[0] !== rootOrigin)
|
|
173
|
-
continue;
|
|
164
|
+
if (!rootOrigin) {
|
|
165
|
+
if (!note.origins.some(origin => origin.node === owner))
|
|
166
|
+
continue;
|
|
167
|
+
rootOrigin = note.origins[0];
|
|
168
|
+
}
|
|
169
|
+
else if (note.origins[0] !== rootOrigin) {
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
174
172
|
const member = note.origins.find(origin => slots.has(origin.node))?.node;
|
|
175
173
|
const slot = member ? slots.get(member) : undefined;
|
|
176
174
|
if (!slot)
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { ASTFunctionClass } from "../ASTtypes.js";
|
|
2
|
+
import type { LoweringContext } from "../../lowering/loweringContext.js";
|
|
2
3
|
import type { PlaybackCursor } from "../../playback/types.js";
|
|
4
|
+
/**
|
|
5
|
+
* 按需注册行首小节号:统计从第二行起每条谱面行首小节的序号,并生成行首小节号附件
|
|
6
|
+
*
|
|
7
|
+
* 小节边界仅在正时值事件之后遇到 ANCHOR_KEY 时推进(兼容 @rest 补入的虚拟边界,且曲首 |: 不多计);
|
|
8
|
+
* 若上一行末尾未写小节线,当前小节跨行延续,新行行首因 measureRecorded 为 true 不重复标号。
|
|
9
|
+
*/
|
|
10
|
+
export declare function registerBarNumbering(ctx: LoweringContext, pattern: string, font: string): void;
|
|
3
11
|
export declare const BarNode: ASTFunctionClass;
|
|
4
12
|
/**
|
|
5
13
|
* 某一列此刻处在所属反复段的第几遍
|
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
import { ASTFunctionNode } from "../ASTtypes.js";
|
|
2
|
+
import { Fraction } from "../../fraction.js";
|
|
2
3
|
import { ANCHOR_KEY, isVisualTemporalNode, TemporalNodeBase } from "../temporal.js";
|
|
4
|
+
/**
|
|
5
|
+
* 按需注册行首小节号:统计从第二行起每条谱面行首小节的序号,并生成行首小节号附件
|
|
6
|
+
*
|
|
7
|
+
* 小节边界仅在正时值事件之后遇到 ANCHOR_KEY 时推进(兼容 @rest 补入的虚拟边界,且曲首 |: 不多计);
|
|
8
|
+
* 若上一行末尾未写小节线,当前小节跨行延续,新行行首因 measureRecorded 为 true 不重复标号。
|
|
9
|
+
*/
|
|
10
|
+
export function registerBarNumbering(ctx, pattern, font) {
|
|
11
|
+
ctx.deferFinalize(result => {
|
|
12
|
+
const items = [];
|
|
13
|
+
const measureStart = new Fraction();
|
|
14
|
+
let measureNumber = 1;
|
|
15
|
+
let measureRecorded = false;
|
|
16
|
+
let lastLine = -1;
|
|
17
|
+
for (const column of result.columns) {
|
|
18
|
+
const time = column[0].t;
|
|
19
|
+
if (column.some(node => node.mergeKey === ANCHOR_KEY)) {
|
|
20
|
+
// 只有当前小节已走过正时值才闭合进入下一小节
|
|
21
|
+
if (time.compare(measureStart) > 0) {
|
|
22
|
+
measureNumber++;
|
|
23
|
+
measureStart.copyFrom(time);
|
|
24
|
+
measureRecorded = false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else if (column.some(node => !node.T.isZero() && isVisualTemporalNode(node))) {
|
|
28
|
+
const line = column[0].layoutLine;
|
|
29
|
+
if (line !== lastLine) {
|
|
30
|
+
// 首行(lastLine < 0)与单行谱不标号;跨行未闭合的小节不重复标号
|
|
31
|
+
if (lastLine >= 0 && !measureRecorded)
|
|
32
|
+
items.push({ line, number: measureNumber });
|
|
33
|
+
lastLine = line;
|
|
34
|
+
}
|
|
35
|
+
measureRecorded = true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (items.length > 0) {
|
|
39
|
+
result.attachments.push(new BarNumberAttachment(items, pattern, font));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
3
43
|
class BarFunction extends ASTFunctionNode {
|
|
4
44
|
static def = {
|
|
5
45
|
name: ["bar", "|"],
|
|
@@ -79,6 +119,68 @@ class BarFunction extends ASTFunctionNode {
|
|
|
79
119
|
return `@bar(${this.type}, ${this.size}px)`;
|
|
80
120
|
}
|
|
81
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* 每行行首的小节号附件
|
|
124
|
+
*
|
|
125
|
+
* 多声部行首锚定在连谱号细竖线正上方居中(通过首声部名称宿主发布的 bar.number 端口);
|
|
126
|
+
* 单声部行首无连谱号时统一右对齐到版心左边界 originX 外侧,保证各行纵向对齐且不压住行首升降号或记号。
|
|
127
|
+
*/
|
|
128
|
+
class BarNumberAttachment {
|
|
129
|
+
items;
|
|
130
|
+
pattern;
|
|
131
|
+
font;
|
|
132
|
+
layer = "foreground";
|
|
133
|
+
sourceSpan = undefined;
|
|
134
|
+
constructor(items, pattern, font) {
|
|
135
|
+
this.items = items;
|
|
136
|
+
this.pattern = pattern;
|
|
137
|
+
this.font = font;
|
|
138
|
+
}
|
|
139
|
+
createGeometry(context) {
|
|
140
|
+
const draws = this.items.map(({ line, number }) => {
|
|
141
|
+
const firstCol = context.lines[line].columns[0];
|
|
142
|
+
// 选取行首列中视觉轴最靠上的宿主,确保小节号只挂在最顶层声部上方
|
|
143
|
+
const topHost = firstCol.reduce((top, host) => context.getVisualAxis(line, host.track) < context.getVisualAxis(line, top.track) ? host : top);
|
|
144
|
+
const fontSize = topHost.ast.size;
|
|
145
|
+
const port = topHost.ports["bar.number"];
|
|
146
|
+
const style = {
|
|
147
|
+
fontSize: fontSize * 0.5,
|
|
148
|
+
fontFamily: this.font,
|
|
149
|
+
textAlign: port ? "center" : "right",
|
|
150
|
+
fill: "#000",
|
|
151
|
+
};
|
|
152
|
+
// 仅将模板中的首个 1 替换为当前小节序号
|
|
153
|
+
const text = this.pattern.replace("1", String(number));
|
|
154
|
+
const metrics = context.textMeasurer.measureText(text, style);
|
|
155
|
+
const x = port ? topHost.box.x + port.x : context.originX - fontSize * 0.15;
|
|
156
|
+
const topY = port
|
|
157
|
+
? topHost.box.y + port.y
|
|
158
|
+
: Math.min(topHost.box.y, context.getVisualAxis(line, topHost.track) - fontSize * 0.5);
|
|
159
|
+
const baselineY = topY - fontSize * 0.04;
|
|
160
|
+
return {
|
|
161
|
+
text,
|
|
162
|
+
x,
|
|
163
|
+
y: baselineY,
|
|
164
|
+
style,
|
|
165
|
+
region: {
|
|
166
|
+
x: port ? x - metrics.w / 2 : x - metrics.w,
|
|
167
|
+
y: baselineY - metrics.baseline,
|
|
168
|
+
w: metrics.w,
|
|
169
|
+
h: metrics.baseline,
|
|
170
|
+
line,
|
|
171
|
+
track: topHost.track,
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
return {
|
|
176
|
+
regions: draws.map(draw => draw.region),
|
|
177
|
+
paint(painter) {
|
|
178
|
+
for (const draw of draws)
|
|
179
|
+
painter.drawText(draw.text, draw.x, draw.y, draw.style);
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
82
184
|
export const BarNode = BarFunction;
|
|
83
185
|
class BarTemporalNode extends TemporalNodeBase {
|
|
84
186
|
lines = [];
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { LoweringResult } from "../../lowering/types.js";
|
|
2
|
-
import type { LayoutAttachment } from "../../layout/types.js";
|
|
3
2
|
/** beam 域在 lowering 固化后统一生成作用域连接和相邻自动连接 */
|
|
4
|
-
export declare function createAutomaticBeamAttachments(result: LoweringResult):
|
|
3
|
+
export declare function createAutomaticBeamAttachments(result: LoweringResult): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ANCHOR_KEY, isVisualTemporalNode, } from "../temporal.js";
|
|
2
2
|
import { Fraction } from "../../fraction.js";
|
|
3
3
|
import { DIV_ADDON_KEY, DivNode, } from "../div/index.js";
|
|
4
|
+
import { meterChangeAt } from "../meter/index.js";
|
|
4
5
|
import { collectExplicitBeamEndpoints, createBeamLayoutAttachment, } from "./layout.js";
|
|
5
6
|
/** 只返回实际参与当前事件 div addon 的 div,先沿祖先链找,不够再按书写顺序向下补 */
|
|
6
7
|
function findActiveDivs(node) {
|
|
@@ -119,15 +120,12 @@ function createScopeBeams(scopes, nodeScopes, explicitEndpoints) {
|
|
|
119
120
|
}
|
|
120
121
|
return attachments;
|
|
121
122
|
}
|
|
122
|
-
function beatAt(time) {
|
|
123
|
-
return Math.floor(time.numerator / time.denominator);
|
|
124
|
-
}
|
|
125
123
|
/**
|
|
126
124
|
* 多个独立 div 的默认连接规则
|
|
127
125
|
*
|
|
128
126
|
* MuseScore 和 LilyPond 都以拍号的 beat structure 作为默认分组边界,并允许手工 beam 覆盖。
|
|
129
|
-
*
|
|
130
|
-
*
|
|
127
|
+
* 随当前生效的 @meter 分拍(缺省或散板按四分音符,复拍子及 3/8 按三个分母单位,其余短分母按一个分母单位)。
|
|
128
|
+
* 分组不跨轨道、逻辑行、拍点、小节线、拍号变更、时间间隙、普通长事件、开关边界或显式 beam。
|
|
131
129
|
*/
|
|
132
130
|
function createAdjacentBeams(result, nodeScopes, explicitEndpoints) {
|
|
133
131
|
const attachments = [];
|
|
@@ -135,6 +133,8 @@ function createAdjacentBeams(result, nodeScopes, explicitEndpoints) {
|
|
|
135
133
|
const lineStarts = new Map();
|
|
136
134
|
const measureStart = new Fraction();
|
|
137
135
|
const beatTime = new Fraction();
|
|
136
|
+
const beatDuration = new Fraction(1);
|
|
137
|
+
let candidateDuration = 1;
|
|
138
138
|
for (const column of result.columns) {
|
|
139
139
|
for (const node of column) {
|
|
140
140
|
const current = lineStarts.get(node.layoutLine);
|
|
@@ -151,14 +151,30 @@ function createAdjacentBeams(result, nodeScopes, explicitEndpoints) {
|
|
|
151
151
|
attachments.push(createAutoBeam(group.nodes, nodeScopes));
|
|
152
152
|
};
|
|
153
153
|
const flushAll = () => {
|
|
154
|
-
for (const track of
|
|
154
|
+
for (const track of groups.keys())
|
|
155
155
|
flush(track);
|
|
156
156
|
};
|
|
157
157
|
for (const column of result.columns) {
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
let meter;
|
|
159
|
+
let hasAnchor = false;
|
|
160
|
+
for (const node of column) {
|
|
161
|
+
meter = meterChangeAt(node) ?? meter;
|
|
162
|
+
if (node.mergeKey === ANCHOR_KEY)
|
|
163
|
+
hasAnchor = true;
|
|
164
|
+
}
|
|
165
|
+
if (meter || hasAnchor) {
|
|
160
166
|
flushAll();
|
|
161
|
-
measureStart.copyFrom(
|
|
167
|
+
measureStart.copyFrom(column[0].t);
|
|
168
|
+
}
|
|
169
|
+
if (meter) {
|
|
170
|
+
const { numerator, denominator } = meter;
|
|
171
|
+
if (numerator > 0 && denominator > 4) {
|
|
172
|
+
beatDuration.set(denominator >= 8 && numerator % 3 === 0 ? 12 : 4, denominator);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
beatDuration.set(1);
|
|
176
|
+
}
|
|
177
|
+
candidateDuration = beatDuration.compare(1) < 0 ? beatDuration : 1;
|
|
162
178
|
}
|
|
163
179
|
for (const node of column) {
|
|
164
180
|
if (node.mergeKey === ANCHOR_KEY)
|
|
@@ -169,7 +185,7 @@ function createAdjacentBeams(result, nodeScopes, explicitEndpoints) {
|
|
|
169
185
|
const isCandidate = isVisualTemporalNode(node)
|
|
170
186
|
&& isIndependentDiv
|
|
171
187
|
&& autoBeamEnabled
|
|
172
|
-
&& node.T.compare(
|
|
188
|
+
&& node.T.compare(candidateDuration) < 0
|
|
173
189
|
&& !explicitEndpoints.has(node);
|
|
174
190
|
if (!isCandidate) {
|
|
175
191
|
// 同轨可见元素必须打断相邻关系,即使它本身是零时长文本
|
|
@@ -180,7 +196,8 @@ function createAdjacentBeams(result, nodeScopes, explicitEndpoints) {
|
|
|
180
196
|
}
|
|
181
197
|
const lineStart = lineStarts.get(node.layoutLine) ?? node.t;
|
|
182
198
|
const activeStart = measureStart.compare(lineStart) >= 0 ? measureStart : lineStart;
|
|
183
|
-
|
|
199
|
+
beatTime.copyFrom(node.t).sub(activeStart);
|
|
200
|
+
const beat = Math.floor(beatTime.numerator * beatDuration.denominator / (beatTime.denominator * beatDuration.numerator));
|
|
184
201
|
const current = groups.get(node.track);
|
|
185
202
|
const isContinuous = current && node.t.equals(current.endTime);
|
|
186
203
|
if (!current || node.layoutLine !== current.line || beat !== current.beat || !isContinuous) {
|
|
@@ -204,10 +221,7 @@ function createAdjacentBeams(result, nodeScopes, explicitEndpoints) {
|
|
|
204
221
|
export function createAutomaticBeamAttachments(result) {
|
|
205
222
|
const { scopes, nodeScopes } = collectDivScopes(result);
|
|
206
223
|
if (scopes.length === 0)
|
|
207
|
-
return
|
|
224
|
+
return;
|
|
208
225
|
const explicitEndpoints = collectExplicitBeamEndpoints(result.attachments);
|
|
209
|
-
|
|
210
|
-
...createScopeBeams(scopes, nodeScopes, explicitEndpoints),
|
|
211
|
-
...createAdjacentBeams(result, nodeScopes, explicitEndpoints),
|
|
212
|
-
];
|
|
226
|
+
result.attachments.push(...createScopeBeams(scopes, nodeScopes, explicitEndpoints), ...createAdjacentBeams(result, nodeScopes, explicitEndpoints));
|
|
213
227
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { ASTFunctionNode } from "../ASTtypes.js";
|
|
2
2
|
import { Diagnostic, ErrorDiagnostic } from "../../diagnostic.js";
|
|
3
|
-
import { createAutomaticBeamAttachments } from "./auto.js";
|
|
4
3
|
import { createBeamLayoutAttachment, validateExplicitBeamAttachments, } from "./layout.js";
|
|
5
4
|
class BeamFunction extends ASTFunctionNode {
|
|
6
|
-
static loweringAugment = createAutomaticBeamAttachments;
|
|
7
5
|
static loweringFinalize = validateExplicitBeamAttachments;
|
|
8
6
|
static def = {
|
|
9
7
|
name: ["beam"],
|
|
@@ -37,7 +35,7 @@ class BeamFunction extends ASTFunctionNode {
|
|
|
37
35
|
this.endPoints.unshift(candidate);
|
|
38
36
|
}
|
|
39
37
|
if (this.endPoints.length < 2) {
|
|
40
|
-
throw new ErrorDiagnostic("E_NOT_ENOUGH_ARGS", "@
|
|
38
|
+
throw new ErrorDiagnostic("E_NOT_ENOUGH_ARGS", "@{fn} 至少需要两个端点", sourceSpan, { fn: "beam" });
|
|
41
39
|
}
|
|
42
40
|
}
|
|
43
41
|
/** 与 tie 一样,只注册不推进时间的关系排版对象 */
|
|
@@ -57,6 +55,7 @@ class BeamFunction extends ASTFunctionNode {
|
|
|
57
55
|
return [];
|
|
58
56
|
}
|
|
59
57
|
ctx.addAttachment(createBeamLayoutAttachment(endPoints, true, this.sourceSpan));
|
|
58
|
+
ctx.deferFinalize(BeamFunction.loweringFinalize);
|
|
60
59
|
return [];
|
|
61
60
|
}
|
|
62
61
|
}
|
|
@@ -6,5 +6,5 @@ import type { LoweringAttachment, LoweringResult } from "../../lowering/types.js
|
|
|
6
6
|
export declare function createBeamLayoutAttachment(endPoints: TemporalNodeBase[], explicit: boolean, sourceSpan: SourceSpan): LayoutAttachment;
|
|
7
7
|
/** 显式 beam 连接同轨同谱面行中的相邻可见主体,忽略零时长小节线 */
|
|
8
8
|
export declare function validateExplicitBeamAttachments(result: LoweringResult): void;
|
|
9
|
-
/**
|
|
9
|
+
/** 自动分组在收尾阶段读取已经注册的显式 beam 端点 */
|
|
10
10
|
export declare function collectExplicitBeamEndpoints(attachments: readonly LoweringAttachment[]): Set<TemporalNodeBase>;
|
|
@@ -47,7 +47,7 @@ export function validateExplicitBeamAttachments(result) {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
/**
|
|
50
|
+
/** 自动分组在收尾阶段读取已经注册的显式 beam 端点 */
|
|
51
51
|
export function collectExplicitBeamEndpoints(attachments) {
|
|
52
52
|
const result = new Set();
|
|
53
53
|
for (const attachment of attachments) {
|
|
@@ -1,2 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ASTNodeBase, FunctionArgs, SourceSpan, ASTFunctionNode } from "../ASTtypes.js";
|
|
2
|
+
import { ParserContext } from "../../parser/parserContext.js";
|
|
3
|
+
import { TemporalNodeBase } from "../temporal.js";
|
|
4
|
+
import type { LoweringContext } from "../../lowering/loweringContext.js";
|
|
5
|
+
import type { LoweringResult } from "../../lowering/types.js";
|
|
6
|
+
import { GrammarCallNodeTyped } from "../../parser/grammarType.js";
|
|
7
|
+
declare class BrFunction extends ASTFunctionNode {
|
|
8
|
+
static def: {
|
|
9
|
+
name: string[];
|
|
10
|
+
description: string;
|
|
11
|
+
details: string;
|
|
12
|
+
allowExtraArgs: boolean;
|
|
13
|
+
args: {
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
type: "number";
|
|
17
|
+
default: number;
|
|
18
|
+
}[];
|
|
19
|
+
};
|
|
20
|
+
static deSugarAtom(source: string, start: number, end: number, depth: number): {
|
|
21
|
+
next: number;
|
|
22
|
+
node: GrammarCallNodeTyped;
|
|
23
|
+
} | null;
|
|
24
|
+
readonly offset: number;
|
|
25
|
+
loweringEnter(ctx: LoweringContext): TemporalNodeBase[];
|
|
26
|
+
/**
|
|
27
|
+
* 换行与换页共享校验;边界会切开全谱,不能截断持续事件
|
|
28
|
+
*/
|
|
29
|
+
static loweringFinalize(result: LoweringResult): void;
|
|
30
|
+
constructor(span: SourceSpan, args: FunctionArgs, ctx: ParserContext, parent?: ASTNodeBase | null);
|
|
31
|
+
toString(): string;
|
|
32
|
+
}
|
|
33
|
+
export declare const BrNode: typeof BrFunction;
|
|
34
|
+
export {};
|
|
@@ -46,7 +46,8 @@ class BrFunction extends ASTFunctionNode {
|
|
|
46
46
|
return { next, node };
|
|
47
47
|
}
|
|
48
48
|
offset;
|
|
49
|
-
loweringEnter() {
|
|
49
|
+
loweringEnter(ctx) {
|
|
50
|
+
ctx.deferFinalize(BrFunction.loweringFinalize);
|
|
50
51
|
const br = new TemporalNodeBase();
|
|
51
52
|
br.ast = this;
|
|
52
53
|
br.mergeKey = -1;
|
|
@@ -56,7 +57,7 @@ class BrFunction extends ASTFunctionNode {
|
|
|
56
57
|
/**
|
|
57
58
|
* 换行与换页共享校验;边界会切开全谱,不能截断持续事件
|
|
58
59
|
*/
|
|
59
|
-
static loweringFinalize
|
|
60
|
+
static loweringFinalize(result) {
|
|
60
61
|
const latestEnd = new Fraction();
|
|
61
62
|
const candidateEnd = new Fraction();
|
|
62
63
|
let latestNode = null;
|
|
@@ -74,13 +75,13 @@ class BrFunction extends ASTFunctionNode {
|
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
|
-
}
|
|
78
|
+
}
|
|
78
79
|
constructor(span, args, ctx, parent = null) {
|
|
79
80
|
super(span, parent);
|
|
80
81
|
const [offset] = this.getArgValue(args, ctx);
|
|
81
82
|
this.offset = Number.isFinite(offset) ? Math.max(1, Math.floor(offset)) : 1;
|
|
82
83
|
if (this.offset !== offset) {
|
|
83
|
-
ctx.diagnostics.push(new WarningDiagnostic("W_BR_OFFSET",
|
|
84
|
+
ctx.diagnostics.push(new WarningDiagnostic("W_BR_OFFSET", "@br 的 offset 必须是大于等于 1 的整数,已被修正为 {offset}", this.sourceSpan, { offset: this.offset }));
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
toString() { return `@br(${this.offset})`; }
|
|
@@ -75,14 +75,13 @@ class DashTemporalNode extends TemporalNodeBase {
|
|
|
75
75
|
// 这里只查询已发布的结构前缀;装饰音尚未展开,不需要逐个修改子音。
|
|
76
76
|
emitter.defer(context => {
|
|
77
77
|
let rootOrigin;
|
|
78
|
-
|
|
78
|
+
let extended = false;
|
|
79
|
+
// 同轨最近一次顶层访问是唯一可能与当前起点相接的目标组;
|
|
79
80
|
// 来源身份限定了整组目标,防止延长更早的音符或另一遍反复中的同一节点。
|
|
80
81
|
for (let index = context.spans.length - 1; index >= 0; index--) {
|
|
81
82
|
const span = context.spans[index];
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
if (rootOrigin === undefined) {
|
|
85
|
-
if (!span.end.equals(start))
|
|
83
|
+
if (!rootOrigin) {
|
|
84
|
+
if (span.track !== track)
|
|
86
85
|
continue;
|
|
87
86
|
rootOrigin = span.origins[0];
|
|
88
87
|
}
|
|
@@ -92,9 +91,10 @@ class DashTemporalNode extends TemporalNodeBase {
|
|
|
92
91
|
// 一组目标可以含多个成员;extend 同时承接当前访问在新增部分上的速度效果。
|
|
93
92
|
if (span.end.equals(start)) {
|
|
94
93
|
emitter.extend(span);
|
|
94
|
+
extended = true;
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
if (
|
|
97
|
+
if (!extended) {
|
|
98
98
|
context.diagnostics.push(new WarningDiagnostic("W_PLAYBACK_SUSTAIN_WITHOUT_TARGET", "增时线前没有可延续的音段", sourceSpan));
|
|
99
99
|
}
|
|
100
100
|
});
|
|
@@ -26,13 +26,14 @@ import { SymbolNode } from "./symbol/index.js";
|
|
|
26
26
|
import { SetNode } from "./set/index.js";
|
|
27
27
|
import { TempoNode } from "./tempo/index.js";
|
|
28
28
|
import { TextNode } from "./text/index.js";
|
|
29
|
+
import { TremoloNode } from "./tremolo/index.js";
|
|
29
30
|
import { VoltaNode } from "./volta/index.js";
|
|
30
31
|
import { TieNode } from "./tie/index.js";
|
|
31
32
|
import { TupletNode } from "./tuplet/index.js";
|
|
32
33
|
import { VoiceNode, VoicesNode } from "./voice/index.js";
|
|
33
34
|
export const defaultFunctions = [
|
|
34
35
|
NoteNode, DashNode, RestNode, BarNode,
|
|
35
|
-
DivNode, DotNode, TupletNode, // 装饰性
|
|
36
|
+
DivNode, DotNode, TupletNode, TremoloNode, // 装饰性
|
|
36
37
|
VoiceNode, VoicesNode, // 歌词和声部
|
|
37
38
|
BrNode, PageBreakNode, // 排版
|
|
38
39
|
PageNode, HeadNode, // 文档页面与谱头
|
|
@@ -53,6 +53,7 @@ declare class DivFunction extends ASTFunctionNode {
|
|
|
53
53
|
static layoutDecorationHandler: LayoutDecorationHandler;
|
|
54
54
|
loweringEnter(ctx: LoweringContext): never[];
|
|
55
55
|
loweringExit(ctx: LoweringContext): never[];
|
|
56
|
+
private static loweringFinalize;
|
|
56
57
|
content: ASTNodeBase;
|
|
57
58
|
n: number;
|
|
58
59
|
/** parse 时冻结;只控制不同 div 之间的自动连接,不影响当前 div 内部连接 */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ASTFunctionNode, functionAddonKey } from "../ASTtypes.js";
|
|
2
2
|
import { WarningDiagnostic } from "../../diagnostic.js";
|
|
3
|
+
import { createAutomaticBeamAttachments } from "../beam/auto.js";
|
|
3
4
|
const DIV_FUNC_NAME = "div";
|
|
4
5
|
export const DIV_ADDON_KEY = functionAddonKey(DIV_FUNC_NAME);
|
|
5
6
|
/** div 暴露自己的线段端口,不依赖任何关系函数 */
|
|
@@ -174,10 +175,11 @@ class DivFunction extends ASTFunctionNode {
|
|
|
174
175
|
};
|
|
175
176
|
loweringEnter(ctx) {
|
|
176
177
|
const count = this.n;
|
|
178
|
+
if (count === 0)
|
|
179
|
+
return [];
|
|
180
|
+
ctx.deferFinalize(DivFunction.loweringFinalize, -5);
|
|
177
181
|
ctx.beginLoweringGroup(this, {
|
|
178
182
|
onTemporal(node) {
|
|
179
|
-
if (count === 0)
|
|
180
|
-
return;
|
|
181
183
|
const addon = node.addon ??= {};
|
|
182
184
|
addon[DIV_ADDON_KEY] = (Number(addon[DIV_ADDON_KEY]) || 0) + count;
|
|
183
185
|
node.T.divPow2(count);
|
|
@@ -186,9 +188,11 @@ class DivFunction extends ASTFunctionNode {
|
|
|
186
188
|
return [];
|
|
187
189
|
}
|
|
188
190
|
loweringExit(ctx) {
|
|
189
|
-
|
|
191
|
+
if (this.n > 0)
|
|
192
|
+
ctx.endLoweringGroup(this);
|
|
190
193
|
return [];
|
|
191
194
|
}
|
|
195
|
+
static loweringFinalize = createAutomaticBeamAttachments;
|
|
192
196
|
content;
|
|
193
197
|
n;
|
|
194
198
|
/** parse 时冻结;只控制不同 div 之间的自动连接,不影响当前 div 内部连接 */
|
|
@@ -207,7 +211,7 @@ class DivFunction extends ASTFunctionNode {
|
|
|
207
211
|
this.content.parent = this;
|
|
208
212
|
const n = Math.max(0, Math.trunc(this.n));
|
|
209
213
|
if (n !== this.n) {
|
|
210
|
-
ctx.diagnostics.push(new WarningDiagnostic("W_DIV_INVALID_N",
|
|
214
|
+
ctx.diagnostics.push(new WarningDiagnostic("W_DIV_INVALID_N", "@div 的数量参数 n 必须为非负整数,已被修正为 {n}", this.sourceSpan, { n }));
|
|
211
215
|
this.n = n;
|
|
212
216
|
}
|
|
213
217
|
}
|
|
@@ -130,7 +130,7 @@ class DotFunction extends ASTFunctionNode {
|
|
|
130
130
|
loweringExit(ctx) {
|
|
131
131
|
const group = ctx.endLoweringGroup(this);
|
|
132
132
|
if (group.temporalCount !== 1) {
|
|
133
|
-
throw new ErrorDiagnostic("E_DOT_INVALID_CONTENT",
|
|
133
|
+
throw new ErrorDiagnostic("E_DOT_INVALID_CONTENT", "函数 @dot 只能接收 1个元素,但找到了 {count} 个", this.sourceSpan, { count: group.temporalCount });
|
|
134
134
|
}
|
|
135
135
|
return [];
|
|
136
136
|
}
|
|
@@ -149,7 +149,7 @@ class DotFunction extends ASTFunctionNode {
|
|
|
149
149
|
this.content.parent = this;
|
|
150
150
|
const n = Math.max(0, Math.trunc(this.n));
|
|
151
151
|
if (n !== this.n) {
|
|
152
|
-
ctx.diagnostics.push(new WarningDiagnostic("W_DOT_INVALID_N",
|
|
152
|
+
ctx.diagnostics.push(new WarningDiagnostic("W_DOT_INVALID_N", "@dot 的数量参数 n 必须为非负整数,已被修正为 {n}", this.sourceSpan, { n }));
|
|
153
153
|
this.n = n;
|
|
154
154
|
}
|
|
155
155
|
}
|