jpfun 0.7.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.
- 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 +19 -56
- package/dist/converter/musicxml/features.d.ts +16 -8
- package/dist/converter/musicxml/features.js +88 -19
- package/dist/converter/musicxml/index.js +88 -50
- package/dist/converter/musicxml/model.d.ts +9 -0
- package/dist/converter/source.d.ts +4 -7
- package/dist/converter/source.js +11 -9
- 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 +3 -32
- package/dist/functions/ASTtypes.js +5 -52
- package/dist/functions/adjust/index.js +45 -33
- package/dist/functions/arpeggio/index.js +50 -55
- package/dist/functions/arpeggio/shape.d.ts +2 -3
- package/dist/functions/arpeggio/shape.js +20 -50
- package/dist/functions/bar/index.d.ts +8 -0
- package/dist/functions/bar/index.js +105 -8
- package/dist/functions/beam/auto.d.ts +1 -2
- package/dist/functions/beam/auto.js +80 -135
- package/dist/functions/beam/index.js +6 -12
- package/dist/functions/beam/layout.d.ts +1 -1
- package/dist/functions/beam/layout.js +1 -1
- package/dist/functions/box/index.js +0 -6
- package/dist/functions/br/index.d.ts +34 -2
- package/dist/functions/br/index.js +5 -4
- package/dist/functions/dash/index.js +9 -10
- package/dist/functions/default.js +2 -1
- package/dist/functions/div/index.d.ts +3 -4
- package/dist/functions/div/index.js +18 -14
- package/dist/functions/dot/index.js +5 -11
- package/dist/functions/dyn/index.js +55 -57
- package/dist/functions/gliss/index.js +131 -103
- package/dist/functions/grace/index.d.ts +3 -12
- package/dist/functions/grace/index.js +52 -102
- package/dist/functions/head/index.js +10 -7
- package/dist/functions/key/index.js +13 -15
- package/dist/functions/meter/index.d.ts +56 -1
- package/dist/functions/meter/index.js +15 -10
- package/dist/functions/note/index.js +6 -6
- package/dist/functions/note/noteName.d.ts +16 -0
- package/dist/functions/note/noteName.js +88 -0
- package/dist/functions/note/source-transform.js +8 -10
- package/dist/functions/ottava/index.js +35 -40
- package/dist/functions/page/index.d.ts +1 -0
- package/dist/functions/page/index.js +27 -21
- package/dist/functions/pagebreak/index.js +2 -2
- package/dist/functions/rest/index.js +5 -5
- package/dist/functions/set/index.js +4 -4
- package/dist/functions/slide/index.js +0 -1
- package/dist/functions/stack/index.js +8 -57
- 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 +3 -2
- package/dist/functions/temporal.js +8 -0
- package/dist/functions/text/index.js +38 -35
- package/dist/functions/tie/index.js +44 -43
- package/dist/functions/tremolo/index.d.ts +2 -0
- package/dist/functions/tremolo/index.js +318 -0
- package/dist/functions/tuplet/index.js +4 -14
- package/dist/functions/up/index.js +81 -85
- package/dist/functions/voice/connections.d.ts +2 -1
- package/dist/functions/voice/connections.js +48 -10
- package/dist/functions/voice/index.d.ts +2 -3
- package/dist/functions/voice/index.js +2 -963
- package/dist/functions/voice/lyrics.d.ts +30 -0
- package/dist/functions/voice/lyrics.js +289 -0
- package/dist/functions/voice/voice.d.ts +63 -0
- package/dist/functions/voice/voice.js +373 -0
- package/dist/functions/voice/voices.d.ts +106 -0
- package/dist/functions/voice/voices.js +423 -0
- package/dist/functions/volta/index.js +5 -23
- package/dist/jpfun.core.min.js +76 -59
- package/dist/jpfun.from-midi.min.js +5 -5
- package/dist/jpfun.from-musicxml.min.js +8 -8
- package/dist/jpfun.min.js +81 -64
- package/dist/layout/default.d.ts +0 -1
- package/dist/layout/default.js +0 -1
- package/dist/layout/engine.js +30 -18
- package/dist/layout/model.d.ts +0 -1
- package/dist/layout/model.js +1 -4
- package/dist/layout/page.d.ts +2 -1
- package/dist/layout/page.js +14 -14
- package/dist/layout/range.d.ts +7 -6
- package/dist/layout/range.js +23 -14
- package/dist/layout/types.d.ts +9 -28
- package/dist/lowering/loweringContext.d.ts +18 -23
- package/dist/lowering/loweringContext.js +33 -46
- package/dist/lowering/track.d.ts +8 -1
- package/dist/lowering/types.d.ts +13 -11
- package/dist/parser/parse-utils/call-utils.d.ts +1 -2
- package/dist/parser/parse-utils/call-utils.js +6 -34
- package/dist/parser/parse-utils/note-utils.d.ts +3 -3
- package/dist/parser/parse-utils/note-utils.js +21 -33
- package/dist/parser/parse-utils/string-utils.d.ts +3 -2
- package/dist/parser/parse-utils/string-utils.js +20 -5
- package/dist/parser/parserContext.d.ts +9 -9
- package/dist/parser/parserContext.js +62 -11
- package/dist/pipeline.js +2 -3
- package/dist/playback/compile.js +131 -82
- package/dist/playback/event.d.ts +6 -6
- package/dist/playback/event.js +13 -49
- package/dist/playback/time.js +42 -31
- package/dist/playback/types.d.ts +3 -1
- package/dist/render/canvas.js +4 -22
- package/dist/render/recording.js +1 -4
- package/dist/render/svg.d.ts +0 -1
- package/dist/render/svg.js +33 -31
- package/dist/render/text.d.ts +36 -1
- package/dist/render/text.js +134 -0
- package/dist/render/translate.d.ts +0 -1
- package/dist/render/translate.js +6 -23
- package/dist/render/types.d.ts +0 -2
- package/grammar.md +39 -30
- package/package.json +3 -3
- package/dist/functions/note/noteNameFSM.d.ts +0 -8
- package/dist/functions/note/noteNameFSM.js +0 -181
- package/dist/iife/core.d.ts +0 -1
- package/dist/iife/core.js +0 -3
- package/dist/iife/from-midi.d.ts +0 -1
- package/dist/iife/from-midi.js +0 -15
- package/dist/iife/from-musicxml.d.ts +0 -1
- package/dist/iife/from-musicxml.js +0 -3
- package/dist/iife/full.d.ts +0 -1
- package/dist/iife/full.js +0 -3
|
@@ -1,175 +1,126 @@
|
|
|
1
1
|
import { ANCHOR_KEY, isVisualTemporalNode, } from "../temporal.js";
|
|
2
2
|
import { Fraction } from "../../fraction.js";
|
|
3
|
-
import {
|
|
3
|
+
import { getDivOwner, } from "../div/index.js";
|
|
4
|
+
import { meterChangeAt } from "../meter/index.js";
|
|
4
5
|
import { collectExplicitBeamEndpoints, createBeamLayoutAttachment, } from "./layout.js";
|
|
5
|
-
/**
|
|
6
|
-
function findActiveDivs(node) {
|
|
7
|
-
let remainingLevels = Math.max(0, Math.floor(Number(node.addon?.[DIV_ADDON_KEY]) || 0));
|
|
8
|
-
if (remainingLevels <= 0)
|
|
9
|
-
return [];
|
|
10
|
-
const result = [];
|
|
11
|
-
const take = (div) => {
|
|
12
|
-
result.push(div);
|
|
13
|
-
remainingLevels -= Math.max(0, div.n);
|
|
14
|
-
};
|
|
15
|
-
let ast = node.ast.parent;
|
|
16
|
-
while (ast && remainingLevels > 0) {
|
|
17
|
-
if (ast instanceof DivNode)
|
|
18
|
-
take(ast);
|
|
19
|
-
ast = ast.parent;
|
|
20
|
-
}
|
|
21
|
-
if (remainingLevels <= 0)
|
|
22
|
-
return result;
|
|
23
|
-
// 复合节点(如 up)把代表成员的修饰提升成了自己的,提供层级的 div 在子树里
|
|
24
|
-
const descend = (parent) => {
|
|
25
|
-
for (const child of parent.children ?? []) {
|
|
26
|
-
if (remainingLevels <= 0)
|
|
27
|
-
return;
|
|
28
|
-
if (child instanceof DivNode)
|
|
29
|
-
take(child);
|
|
30
|
-
descend(child);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
descend(node.ast);
|
|
34
|
-
return result;
|
|
35
|
-
}
|
|
36
|
-
/** 收集每个 div 作用域内的可见事件,顺序与最终时间列一致 */
|
|
6
|
+
/** 按最外层 div 作用域收集可见事件,顺序与最终时间列一致 */
|
|
37
7
|
function collectDivScopes(result) {
|
|
38
|
-
const
|
|
39
|
-
const nodeScopes = new Map();
|
|
8
|
+
const scopes = new Map();
|
|
40
9
|
for (const column of result.columns) {
|
|
41
10
|
for (const node of column) {
|
|
42
11
|
if (!isVisualTemporalNode(node))
|
|
43
12
|
continue;
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
13
|
+
const owner = getDivOwner(node);
|
|
14
|
+
if (!owner)
|
|
46
15
|
continue;
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
scopesByOwner.set(owner, scope);
|
|
53
|
-
}
|
|
54
|
-
scope.nodes.push(node);
|
|
55
|
-
memberships.push(scope);
|
|
56
|
-
}
|
|
57
|
-
nodeScopes.set(node, memberships);
|
|
16
|
+
const nodes = scopes.get(owner);
|
|
17
|
+
if (nodes)
|
|
18
|
+
nodes.push(node);
|
|
19
|
+
else
|
|
20
|
+
scopes.set(owner, [node]);
|
|
58
21
|
}
|
|
59
22
|
}
|
|
60
|
-
return
|
|
61
|
-
scopes: [...scopesByOwner.values()],
|
|
62
|
-
nodeScopes,
|
|
63
|
-
};
|
|
23
|
+
return scopes;
|
|
64
24
|
}
|
|
65
|
-
|
|
66
|
-
function outermostScopes(scopes) {
|
|
67
|
-
const owners = new Set(scopes.map(scope => scope.owner));
|
|
68
|
-
return scopes.filter(scope => {
|
|
69
|
-
let parent = scope.owner.parent;
|
|
70
|
-
while (parent) {
|
|
71
|
-
if (parent instanceof DivNode && owners.has(parent))
|
|
72
|
-
return false;
|
|
73
|
-
parent = parent.parent;
|
|
74
|
-
}
|
|
75
|
-
return true;
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
function createAutoBeam(nodes, nodeScopes) {
|
|
25
|
+
function createAutoBeam(nodes) {
|
|
79
26
|
let start = Infinity;
|
|
80
27
|
let end = -Infinity;
|
|
81
28
|
for (const node of nodes) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
start = Math.min(start, owner.sourceSpan.start);
|
|
86
|
-
end = Math.max(end, owner.sourceSpan.end);
|
|
87
|
-
}
|
|
29
|
+
const owner = getDivOwner(node);
|
|
30
|
+
start = Math.min(start, node.ast.sourceSpan.start, owner.sourceSpan.start);
|
|
31
|
+
end = Math.max(end, node.ast.sourceSpan.end, owner.sourceSpan.end);
|
|
88
32
|
}
|
|
89
33
|
return createBeamLayoutAttachment(nodes, false, { start, end });
|
|
90
34
|
}
|
|
91
35
|
/** 同一个 div 内部始终按轨道连接,手工 beam 端点会截断自动片段 */
|
|
92
|
-
function createScopeBeams(scopes,
|
|
36
|
+
function createScopeBeams(scopes, explicitEndpoints) {
|
|
93
37
|
const attachments = [];
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
attachments.push(createAutoBeam(segment, nodeScopes));
|
|
108
|
-
segment = [];
|
|
109
|
-
};
|
|
110
|
-
for (const node of nodes) {
|
|
111
|
-
if (explicitEndpoints.has(node)) {
|
|
112
|
-
flush();
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
segment.push(node);
|
|
38
|
+
const segments = new Map();
|
|
39
|
+
const flush = (segment) => {
|
|
40
|
+
if (segment && segment.length >= 2)
|
|
41
|
+
attachments.push(createAutoBeam(segment));
|
|
42
|
+
};
|
|
43
|
+
for (const scopeNodes of scopes) {
|
|
44
|
+
if (scopeNodes.length < 2)
|
|
45
|
+
continue;
|
|
46
|
+
for (const node of scopeNodes) {
|
|
47
|
+
if (explicitEndpoints.has(node)) {
|
|
48
|
+
flush(segments.get(node.track));
|
|
49
|
+
segments.delete(node.track);
|
|
50
|
+
continue;
|
|
116
51
|
}
|
|
117
|
-
|
|
52
|
+
const segment = segments.get(node.track);
|
|
53
|
+
if (segment)
|
|
54
|
+
segment.push(node);
|
|
55
|
+
else
|
|
56
|
+
segments.set(node.track, [node]);
|
|
118
57
|
}
|
|
58
|
+
for (const segment of segments.values())
|
|
59
|
+
flush(segment);
|
|
60
|
+
segments.clear();
|
|
119
61
|
}
|
|
120
62
|
return attachments;
|
|
121
63
|
}
|
|
122
|
-
function beatAt(time) {
|
|
123
|
-
return Math.floor(time.numerator / time.denominator);
|
|
124
|
-
}
|
|
125
64
|
/**
|
|
126
65
|
* 多个独立 div 的默认连接规则
|
|
127
66
|
*
|
|
128
67
|
* MuseScore 和 LilyPond 都以拍号的 beat structure 作为默认分组边界,并允许手工 beam 覆盖。
|
|
129
|
-
*
|
|
130
|
-
*
|
|
68
|
+
* 随当前生效的 @meter 分拍(缺省或散板按四分音符,复拍子及 3/8 按三个分母单位,其余短分母按一个分母单位)。
|
|
69
|
+
* 分组不跨轨道、逻辑行、拍点、小节线、拍号变更、时间间隙、普通长事件、开关边界或显式 beam。
|
|
131
70
|
*/
|
|
132
|
-
function createAdjacentBeams(result,
|
|
71
|
+
function createAdjacentBeams(result, scopes, explicitEndpoints) {
|
|
133
72
|
const attachments = [];
|
|
134
73
|
const groups = new Map();
|
|
135
|
-
const
|
|
136
|
-
const measureStart = new Fraction();
|
|
74
|
+
const phaseStart = new Fraction();
|
|
137
75
|
const beatTime = new Fraction();
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (current === undefined || node.t.compare(current) < 0)
|
|
142
|
-
lineStarts.set(node.layoutLine, node.t);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
76
|
+
const beatDuration = new Fraction(1);
|
|
77
|
+
let candidateDuration = 1;
|
|
78
|
+
let currentLine = 0;
|
|
145
79
|
const flush = (track) => {
|
|
146
80
|
const group = groups.get(track);
|
|
147
81
|
if (!group)
|
|
148
82
|
return;
|
|
149
83
|
groups.delete(track);
|
|
150
84
|
if (group.nodes.length >= 2)
|
|
151
|
-
attachments.push(createAutoBeam(group.nodes
|
|
85
|
+
attachments.push(createAutoBeam(group.nodes));
|
|
152
86
|
};
|
|
153
87
|
const flushAll = () => {
|
|
154
|
-
for (const track of
|
|
88
|
+
for (const track of groups.keys())
|
|
155
89
|
flush(track);
|
|
156
90
|
};
|
|
157
91
|
for (const column of result.columns) {
|
|
158
|
-
const
|
|
159
|
-
|
|
92
|
+
const line = column[0].layoutLine;
|
|
93
|
+
let meter;
|
|
94
|
+
let hasAnchor = false;
|
|
95
|
+
for (const node of column) {
|
|
96
|
+
meter = meterChangeAt(node) ?? meter;
|
|
97
|
+
if (node.mergeKey === ANCHOR_KEY)
|
|
98
|
+
hasAnchor = true;
|
|
99
|
+
}
|
|
100
|
+
if (line !== currentLine || meter || hasAnchor) {
|
|
101
|
+
currentLine = line;
|
|
160
102
|
flushAll();
|
|
161
|
-
|
|
103
|
+
phaseStart.copyFrom(column[0].t);
|
|
104
|
+
}
|
|
105
|
+
if (meter) {
|
|
106
|
+
const { numerator, denominator } = meter;
|
|
107
|
+
if (numerator > 0 && denominator > 4) {
|
|
108
|
+
beatDuration.set(denominator >= 8 && numerator % 3 === 0 ? 12 : 4, denominator);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
beatDuration.set(1);
|
|
112
|
+
}
|
|
113
|
+
candidateDuration = beatDuration.compare(1) < 0 ? beatDuration : 1;
|
|
162
114
|
}
|
|
163
115
|
for (const node of column) {
|
|
164
116
|
if (node.mergeKey === ANCHOR_KEY)
|
|
165
117
|
continue;
|
|
166
|
-
const
|
|
167
|
-
const isIndependentDiv = memberships?.every(scope => scope.nodes.length === 1) ?? false;
|
|
168
|
-
const autoBeamEnabled = memberships?.every(scope => scope.owner.autoBeamEnabled) ?? false;
|
|
118
|
+
const owner = isVisualTemporalNode(node) ? getDivOwner(node) : undefined;
|
|
169
119
|
const isCandidate = isVisualTemporalNode(node)
|
|
170
|
-
&&
|
|
171
|
-
&& autoBeamEnabled
|
|
172
|
-
&&
|
|
120
|
+
&& owner !== undefined
|
|
121
|
+
&& owner.autoBeamEnabled
|
|
122
|
+
&& scopes.get(owner)?.length === 1
|
|
123
|
+
&& node.T.compare(candidateDuration) < 0
|
|
173
124
|
&& !explicitEndpoints.has(node);
|
|
174
125
|
if (!isCandidate) {
|
|
175
126
|
// 同轨可见元素必须打断相邻关系,即使它本身是零时长文本
|
|
@@ -178,16 +129,13 @@ function createAdjacentBeams(result, nodeScopes, explicitEndpoints) {
|
|
|
178
129
|
flush(node.track);
|
|
179
130
|
continue;
|
|
180
131
|
}
|
|
181
|
-
|
|
182
|
-
const
|
|
183
|
-
const beat = beatAt(beatTime.copyFrom(node.t).sub(activeStart));
|
|
132
|
+
beatTime.copyFrom(node.t).sub(phaseStart);
|
|
133
|
+
const beat = Math.floor(beatTime.numerator * beatDuration.denominator / (beatTime.denominator * beatDuration.numerator));
|
|
184
134
|
const current = groups.get(node.track);
|
|
185
|
-
|
|
186
|
-
if (!current || node.layoutLine !== current.line || beat !== current.beat || !isContinuous) {
|
|
135
|
+
if (!current || beat !== current.beat || !node.t.equals(current.endTime)) {
|
|
187
136
|
flush(node.track);
|
|
188
137
|
groups.set(node.track, {
|
|
189
138
|
nodes: [node],
|
|
190
|
-
line: node.layoutLine,
|
|
191
139
|
beat,
|
|
192
140
|
endTime: node.t.clone().add(node.T),
|
|
193
141
|
});
|
|
@@ -202,12 +150,9 @@ function createAdjacentBeams(result, nodeScopes, explicitEndpoints) {
|
|
|
202
150
|
}
|
|
203
151
|
/** beam 域在 lowering 固化后统一生成作用域连接和相邻自动连接 */
|
|
204
152
|
export function createAutomaticBeamAttachments(result) {
|
|
205
|
-
const
|
|
206
|
-
if (scopes.
|
|
207
|
-
return
|
|
153
|
+
const scopes = collectDivScopes(result);
|
|
154
|
+
if (scopes.size === 0)
|
|
155
|
+
return;
|
|
208
156
|
const explicitEndpoints = collectExplicitBeamEndpoints(result.attachments);
|
|
209
|
-
|
|
210
|
-
...createScopeBeams(scopes, nodeScopes, explicitEndpoints),
|
|
211
|
-
...createAdjacentBeams(result, nodeScopes, explicitEndpoints),
|
|
212
|
-
];
|
|
157
|
+
result.attachments.push(...createScopeBeams(scopes.values(), explicitEndpoints), ...createAdjacentBeams(result, scopes, explicitEndpoints));
|
|
213
158
|
}
|
|
@@ -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"],
|
|
@@ -21,12 +19,9 @@ class BeamFunction extends ASTFunctionNode {
|
|
|
21
19
|
endPoints = [];
|
|
22
20
|
constructor(sourceSpan, args, ctx, parent = null) {
|
|
23
21
|
super(sourceSpan, parent);
|
|
24
|
-
for (const [, value] of args) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
: ctx.parseArgWithType(value.valueSpan, "label", sourceSpan.start);
|
|
28
|
-
if (parsed instanceof ASTFunctionNode)
|
|
29
|
-
this.endPoints.push(parsed);
|
|
22
|
+
for (const [key, value] of args) {
|
|
23
|
+
if (typeof key === "number")
|
|
24
|
+
this.endPoints.push(value);
|
|
30
25
|
}
|
|
31
26
|
// 未显式给全时,回退到最近可标记对象,至少取两个。
|
|
32
27
|
let k = ctx.labelableNodes.length - 1;
|
|
@@ -37,7 +32,7 @@ class BeamFunction extends ASTFunctionNode {
|
|
|
37
32
|
this.endPoints.unshift(candidate);
|
|
38
33
|
}
|
|
39
34
|
if (this.endPoints.length < 2) {
|
|
40
|
-
throw new ErrorDiagnostic("E_NOT_ENOUGH_ARGS", "@
|
|
35
|
+
throw new ErrorDiagnostic("E_NOT_ENOUGH_ARGS", "@{fn} 至少需要两个端点", sourceSpan, { fn: "beam" });
|
|
41
36
|
}
|
|
42
37
|
}
|
|
43
38
|
/** 与 tie 一样,只注册不推进时间的关系排版对象 */
|
|
@@ -45,9 +40,7 @@ class BeamFunction extends ASTFunctionNode {
|
|
|
45
40
|
const endPoints = [];
|
|
46
41
|
for (const ast of this.endPoints) {
|
|
47
42
|
// 暂时只用最后一个;理应有且仅有一个
|
|
48
|
-
|
|
49
|
-
while (temporal?.foldedInto)
|
|
50
|
-
temporal = temporal.foldedInto;
|
|
43
|
+
const temporal = ctx.getTemporalNodes(ast).at(-1)?.rootHost;
|
|
51
44
|
if (!temporal)
|
|
52
45
|
continue;
|
|
53
46
|
endPoints.push(temporal);
|
|
@@ -57,6 +50,7 @@ class BeamFunction extends ASTFunctionNode {
|
|
|
57
50
|
return [];
|
|
58
51
|
}
|
|
59
52
|
ctx.addAttachment(createBeamLayoutAttachment(endPoints, true, this.sourceSpan));
|
|
53
|
+
ctx.deferFinalize(BeamFunction.loweringFinalize);
|
|
60
54
|
return [];
|
|
61
55
|
}
|
|
62
56
|
}
|
|
@@ -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) {
|
|
@@ -52,12 +52,6 @@ class BoxFunction extends ASTFunctionNode {
|
|
|
52
52
|
stroke;
|
|
53
53
|
width;
|
|
54
54
|
get children() { return [this.target]; }
|
|
55
|
-
timeFlowModel() {
|
|
56
|
-
return {
|
|
57
|
-
children: [this.target],
|
|
58
|
-
mode: "sequence",
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
55
|
/**
|
|
62
56
|
* box 不创建时间事件
|
|
63
57
|
* 进入目标内容前只开始收集所有成员矩形的引用
|
|
@@ -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})`; }
|
|
@@ -41,7 +41,6 @@ class DashFunction extends ASTFunctionNode {
|
|
|
41
41
|
export const DashNode = DashFunction;
|
|
42
42
|
class DashTemporalNode extends TemporalNodeBase {
|
|
43
43
|
lineWidth = 0;
|
|
44
|
-
lineY = 0;
|
|
45
44
|
constructor(ast) {
|
|
46
45
|
super();
|
|
47
46
|
this.ast = ast;
|
|
@@ -61,8 +60,7 @@ class DashTemporalNode extends TemporalNodeBase {
|
|
|
61
60
|
this.box.w = this.lineWidth;
|
|
62
61
|
this.box.h = size;
|
|
63
62
|
this.box.anchor = this.lineWidth / 2;
|
|
64
|
-
this.
|
|
65
|
-
this.box.visualAxis = this.lineY;
|
|
63
|
+
this.box.visualAxis = size * 0.5;
|
|
66
64
|
}
|
|
67
65
|
/**
|
|
68
66
|
* 在结构阶段延长前方同轨、时间相接的一组区间
|
|
@@ -75,14 +73,13 @@ class DashTemporalNode extends TemporalNodeBase {
|
|
|
75
73
|
// 这里只查询已发布的结构前缀;装饰音尚未展开,不需要逐个修改子音。
|
|
76
74
|
emitter.defer(context => {
|
|
77
75
|
let rootOrigin;
|
|
78
|
-
|
|
76
|
+
let extended = false;
|
|
77
|
+
// 同轨最近一次顶层访问是唯一可能与当前起点相接的目标组;
|
|
79
78
|
// 来源身份限定了整组目标,防止延长更早的音符或另一遍反复中的同一节点。
|
|
80
79
|
for (let index = context.spans.length - 1; index >= 0; index--) {
|
|
81
80
|
const span = context.spans[index];
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
if (rootOrigin === undefined) {
|
|
85
|
-
if (!span.end.equals(start))
|
|
81
|
+
if (!rootOrigin) {
|
|
82
|
+
if (span.track !== track)
|
|
86
83
|
continue;
|
|
87
84
|
rootOrigin = span.origins[0];
|
|
88
85
|
}
|
|
@@ -92,14 +89,16 @@ class DashTemporalNode extends TemporalNodeBase {
|
|
|
92
89
|
// 一组目标可以含多个成员;extend 同时承接当前访问在新增部分上的速度效果。
|
|
93
90
|
if (span.end.equals(start)) {
|
|
94
91
|
emitter.extend(span);
|
|
92
|
+
extended = true;
|
|
95
93
|
}
|
|
96
94
|
}
|
|
97
|
-
if (
|
|
95
|
+
if (!extended) {
|
|
98
96
|
context.diagnostics.push(new WarningDiagnostic("W_PLAYBACK_SUSTAIN_WITHOUT_TARGET", "增时线前没有可延续的音段", sourceSpan));
|
|
99
97
|
}
|
|
100
98
|
});
|
|
101
99
|
}
|
|
102
100
|
paint(painter) {
|
|
103
|
-
|
|
101
|
+
const y = this.box.y + this.box.visualAxis;
|
|
102
|
+
painter.drawLine(this.box.x, y, this.box.x + this.lineWidth, y, { stroke: "#000", strokeWidth: Math.max(1, this.ast.size * 0.1) });
|
|
104
103
|
}
|
|
105
104
|
}
|
|
@@ -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, // 文档页面与谱头
|
|
@@ -2,7 +2,9 @@ import { ASTNodeBase, FunctionArgs, SourceSpan, ParserContext, ASTFunctionNode }
|
|
|
2
2
|
import { GrammarNode, GrammarSugarNode } from "../../parser/grammarType.js";
|
|
3
3
|
import type { LayoutDecorationHandler, LayoutHost } from "../../layout/types.js";
|
|
4
4
|
import type { LoweringContext } from "../../lowering/loweringContext.js";
|
|
5
|
+
import type { TemporalNodeBase } from "../temporal.js";
|
|
5
6
|
export declare const DIV_ADDON_KEY: "@div";
|
|
7
|
+
export declare function getDivOwner(node: TemporalNodeBase): DivFunction | undefined;
|
|
6
8
|
/** div 暴露自己的线段端口,不依赖任何关系函数 */
|
|
7
9
|
export declare function divLinePortName(level: number, edge: "left" | "right"): string;
|
|
8
10
|
export declare function claimDivLine(host: LayoutHost, level: number): void;
|
|
@@ -53,15 +55,12 @@ declare class DivFunction extends ASTFunctionNode {
|
|
|
53
55
|
static layoutDecorationHandler: LayoutDecorationHandler;
|
|
54
56
|
loweringEnter(ctx: LoweringContext): never[];
|
|
55
57
|
loweringExit(ctx: LoweringContext): never[];
|
|
58
|
+
private static loweringFinalize;
|
|
56
59
|
content: ASTNodeBase;
|
|
57
60
|
n: number;
|
|
58
61
|
/** parse 时冻结;只控制不同 div 之间的自动连接,不影响当前 div 内部连接 */
|
|
59
62
|
autoBeamEnabled: boolean;
|
|
60
63
|
get children(): ASTNodeBase[];
|
|
61
|
-
timeFlowModel(): {
|
|
62
|
-
children: ASTNodeBase[];
|
|
63
|
-
mode: "sequence";
|
|
64
|
-
};
|
|
65
64
|
constructor(sourceSpan: SourceSpan, args: FunctionArgs, ctx: ParserContext, parent?: ASTNodeBase | null);
|
|
66
65
|
toString(source: string): string;
|
|
67
66
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
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);
|
|
6
|
+
const DIV_OWNER_KEY = Symbol("div.owner");
|
|
7
|
+
export function getDivOwner(node) {
|
|
8
|
+
return node.addon?.[DIV_OWNER_KEY];
|
|
9
|
+
}
|
|
5
10
|
/** div 暴露自己的线段端口,不依赖任何关系函数 */
|
|
6
11
|
export function divLinePortName(level, edge) {
|
|
7
12
|
return `div.${level}.${edge}`;
|
|
@@ -100,24 +105,24 @@ class DivFunction extends ASTFunctionNode {
|
|
|
100
105
|
const n = nodes[at++];
|
|
101
106
|
if (n.data?.class !== DivFunction)
|
|
102
107
|
return null;
|
|
103
|
-
const prevIndex =
|
|
108
|
+
const prevIndex = ctx.findLastOperandIndex();
|
|
104
109
|
if (prevIndex < 0)
|
|
105
110
|
return at; // 没有了 直接当作无效文本跳过
|
|
106
111
|
const prev = ctx.nodes[prevIndex];
|
|
107
112
|
if (prev instanceof DivFunction) {
|
|
108
113
|
// 已经是div了 继续加深
|
|
109
114
|
prev.n += n.data.n;
|
|
115
|
+
prev.sourceSpan.end = Math.max(prev.sourceSpan.end, n.span.end);
|
|
110
116
|
return at;
|
|
111
117
|
}
|
|
112
118
|
const argMap = new Map();
|
|
113
119
|
argMap.set(0, prev);
|
|
114
120
|
argMap.set("n", n.data.n);
|
|
115
121
|
const spanPrev = prev.sourceSpan;
|
|
116
|
-
|
|
122
|
+
ctx.nodes[prevIndex] = new DivFunction({
|
|
117
123
|
start: Math.min(spanPrev.start, n.span.start),
|
|
118
124
|
end: Math.max(spanPrev.end, n.span.end),
|
|
119
125
|
}, argMap, ctx, null);
|
|
120
|
-
ctx.nodes[prevIndex] = node;
|
|
121
126
|
return at;
|
|
122
127
|
}
|
|
123
128
|
/**
|
|
@@ -174,32 +179,31 @@ class DivFunction extends ASTFunctionNode {
|
|
|
174
179
|
};
|
|
175
180
|
loweringEnter(ctx) {
|
|
176
181
|
const count = this.n;
|
|
182
|
+
if (count === 0)
|
|
183
|
+
return [];
|
|
184
|
+
const self = this;
|
|
185
|
+
ctx.deferFinalize(DivFunction.loweringFinalize, -5);
|
|
177
186
|
ctx.beginLoweringGroup(this, {
|
|
178
187
|
onTemporal(node) {
|
|
179
|
-
|
|
180
|
-
return;
|
|
181
|
-
const addon = node.addon ??= {};
|
|
188
|
+
const addon = (node.addon ??= {});
|
|
182
189
|
addon[DIV_ADDON_KEY] = (Number(addon[DIV_ADDON_KEY]) || 0) + count;
|
|
190
|
+
addon[DIV_OWNER_KEY] = self;
|
|
183
191
|
node.T.divPow2(count);
|
|
184
192
|
},
|
|
185
193
|
});
|
|
186
194
|
return [];
|
|
187
195
|
}
|
|
188
196
|
loweringExit(ctx) {
|
|
189
|
-
|
|
197
|
+
if (this.n > 0)
|
|
198
|
+
ctx.endLoweringGroup(this);
|
|
190
199
|
return [];
|
|
191
200
|
}
|
|
201
|
+
static loweringFinalize = createAutomaticBeamAttachments;
|
|
192
202
|
content;
|
|
193
203
|
n;
|
|
194
204
|
/** parse 时冻结;只控制不同 div 之间的自动连接,不影响当前 div 内部连接 */
|
|
195
205
|
autoBeamEnabled;
|
|
196
206
|
get children() { return [this.content]; }
|
|
197
|
-
timeFlowModel() {
|
|
198
|
-
return {
|
|
199
|
-
children: [this.content],
|
|
200
|
-
mode: "sequence",
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
207
|
constructor(sourceSpan, args, ctx, parent = null) {
|
|
204
208
|
super(sourceSpan, parent);
|
|
205
209
|
[this.content, this.n, this.autoBeamEnabled] = this.getArgValue(args, ctx);
|
|
@@ -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
|
}
|