jpfun 0.6.0 → 0.7.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/dist/converter/midi/convert.d.ts +3 -1
- package/dist/converter/midi/convert.js +78 -66
- package/dist/converter/musicxml/features.d.ts +19 -5
- package/dist/converter/musicxml/features.js +46 -8
- package/dist/converter/musicxml/index.js +142 -23
- package/dist/converter/musicxml/model.d.ts +15 -0
- package/dist/diagnostic.js +1 -1
- package/dist/functions/arpeggio/index.js +2 -5
- package/dist/functions/arpeggio/shape.d.ts +1 -1
- package/dist/functions/arpeggio/shape.js +27 -21
- package/dist/functions/bar/index.js +37 -36
- package/dist/functions/beam/auto.js +16 -13
- package/dist/functions/beam/layout.js +15 -23
- package/dist/functions/br/index.js +3 -4
- package/dist/functions/default.js +8 -4
- package/dist/functions/gliss/index.d.ts +2 -0
- package/dist/functions/gliss/index.js +180 -0
- package/dist/functions/grace/index.js +3 -6
- package/dist/functions/head/index.js +40 -59
- package/dist/functions/meter/index.js +19 -18
- package/dist/functions/note/accidentals.js +10 -16
- package/dist/functions/note/index.js +13 -3
- package/dist/functions/ottava/index.d.ts +2 -0
- package/dist/functions/ottava/index.js +217 -0
- package/dist/functions/page/index.js +3 -3
- package/dist/functions/pagebreak/index.d.ts +2 -0
- package/dist/functions/pagebreak/index.js +36 -0
- package/dist/functions/rest/index.js +12 -14
- package/dist/functions/slide/index.d.ts +2 -0
- package/dist/functions/slide/index.js +132 -0
- package/dist/functions/stack/index.js +8 -15
- package/dist/functions/symbol/index.d.ts +9 -0
- package/dist/functions/symbol/index.js +41 -12
- package/dist/functions/symbol/ornament.js +14 -19
- package/dist/functions/symbol/shape.js +4 -1
- package/dist/functions/symbol/symbols/fine.js +1 -1
- package/dist/functions/symbol/symbols/tr.js +46 -1
- package/dist/functions/temporal.d.ts +16 -6
- package/dist/functions/temporal.js +16 -6
- package/dist/functions/tie/index.js +35 -25
- package/dist/functions/up/index.js +5 -7
- package/dist/functions/voice/connections.js +7 -5
- package/dist/functions/voice/index.js +2 -1
- package/dist/functions/volta/index.js +41 -21
- package/dist/jpfun.core.min.js +44 -68
- package/dist/jpfun.from-midi.min.js +5 -5
- package/dist/jpfun.from-musicxml.min.js +8 -8
- package/dist/jpfun.min.js +53 -77
- package/dist/layout/engine.d.ts +1 -0
- package/dist/layout/engine.js +42 -11
- package/dist/layout/page.d.ts +3 -2
- package/dist/layout/page.js +6 -5
- package/dist/layout/types.d.ts +4 -0
- package/dist/lowering/loweringContext.js +7 -167
- package/dist/parser/parserContext.d.ts +2 -0
- package/dist/parser/parserContext.js +27 -6
- package/dist/playback/compile.js +11 -2
- package/dist/playback/types.d.ts +4 -2
- package/dist/render/svg.js +1 -0
- package/dist/render/text.d.ts +1 -1
- package/dist/render/text.js +3 -2
- package/dist/render/types.d.ts +1 -0
- package/grammar.md +30 -9
- package/package.json +1 -1
|
@@ -13,7 +13,8 @@ class VoltaFunction extends ASTFunctionNode {
|
|
|
13
13
|
~~~
|
|
14
14
|
- **额外位置参数**:更多遍数;例如 \`@volta(a, b, 1, 2)\` 让前两遍共用一个房子。遍数顺序不限,谱面按升序显示。
|
|
15
15
|
|
|
16
|
-
本例第一遍演奏 \`a\` 到 \`b\`,第二遍演奏 \`c\` 到 \`d
|
|
16
|
+
本例第一遍演奏 \`a\` 到 \`b\`,第二遍演奏 \`c\` 到 \`d\`。
|
|
17
|
+
播放区间包含终点事件的完整时值,但不包含其结束时刻的小节线或后续事件。`,
|
|
17
18
|
allowExtraArgs: true,
|
|
18
19
|
extraArgType: "number",
|
|
19
20
|
args: [
|
|
@@ -42,7 +43,7 @@ class VoltaFunction extends ASTFunctionNode {
|
|
|
42
43
|
to;
|
|
43
44
|
/** 进入本房子的遍数,升序去重 */
|
|
44
45
|
passes;
|
|
45
|
-
/**
|
|
46
|
+
/** 调用时的字号,作为数字与括线的尺寸基准 */
|
|
46
47
|
size;
|
|
47
48
|
font;
|
|
48
49
|
/** volta 不推进时间,只把 AST 端点解析成稳定的 temporal 引用 */
|
|
@@ -107,7 +108,11 @@ class VoltaAttachment {
|
|
|
107
108
|
if (from === undefined || to === undefined)
|
|
108
109
|
return;
|
|
109
110
|
const start = Math.min(from, to);
|
|
110
|
-
const
|
|
111
|
+
const tail = (this.from.t.compare(this.to.t) || this.from.T.compare(this.to.T)) > 0
|
|
112
|
+
? this.from : this.to;
|
|
113
|
+
const end = columnOf(tail, "end");
|
|
114
|
+
if (end === undefined)
|
|
115
|
+
return;
|
|
111
116
|
return {
|
|
112
117
|
range: [start, end],
|
|
113
118
|
// 这里还是会和 bar 耦合。但只有bar有反复功能,不值得抽取为系统机制
|
|
@@ -135,16 +140,9 @@ class VoltaAttachment {
|
|
|
135
140
|
const tail = to.view.columns[to.column][0];
|
|
136
141
|
const leftBar = barIn(from.view.columns[from.column - 1]);
|
|
137
142
|
const rightBar = barIn(to.view.columns[to.column + 1]);
|
|
138
|
-
let span = 0;
|
|
139
|
-
// 括线盖住的是:首行从起点列向右、末行向左到终点列、中间行整行
|
|
140
|
-
for (let line = from.line; line <= to.line; line++) {
|
|
141
|
-
for (const column of context.getRangeColumns(line, [head, tail])) {
|
|
142
|
-
span = Math.max(span, column[0].ast.size);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
143
|
const firstLine = head.layoutLine;
|
|
146
144
|
const lastLine = tail.layoutLine;
|
|
147
|
-
const size =
|
|
145
|
+
const size = this.ast.size;
|
|
148
146
|
const style = {
|
|
149
147
|
fontSize: size * 0.6,
|
|
150
148
|
fontFamily: this.ast.font,
|
|
@@ -157,7 +155,11 @@ class VoltaAttachment {
|
|
|
157
155
|
const halfStroke = strokeWidth / 2;
|
|
158
156
|
const hook = metrics.h * 1.2;
|
|
159
157
|
// 标签在下折钩的高度里垂直居中
|
|
160
|
-
const
|
|
158
|
+
const textX = size * 0.15;
|
|
159
|
+
const textY = (hook - metrics.h) / 2 + metrics.baseline + 2;
|
|
160
|
+
const startWidth = Math.max(strokeWidth, halfStroke + textX + metrics.w);
|
|
161
|
+
const startBottom = Math.max(hook + halfStroke, textY - metrics.baseline + metrics.h);
|
|
162
|
+
const gap = size * 0.2;
|
|
161
163
|
// 中间行可能没有本房子的可见对象,仍要补满,所以按行号连续遍历
|
|
162
164
|
const draws = Array.from({ length: lastLine - firstLine + 1 }, (_, offset) => {
|
|
163
165
|
const line = firstLine + offset;
|
|
@@ -185,17 +187,35 @@ class VoltaAttachment {
|
|
|
185
187
|
: tail.box.x + (tail.ports["body.right"]?.x ?? tail.box.w);
|
|
186
188
|
const left = Math.min(rawLeft, rawRight);
|
|
187
189
|
const right = Math.max(rawLeft, rawRight);
|
|
188
|
-
|
|
190
|
+
const part = (x, w, bottom) => ({
|
|
191
|
+
x, y: -halfStroke, w, h: bottom + halfStroke, line, track: topTrack,
|
|
192
|
+
});
|
|
193
|
+
const parts = [part(left - halfStroke, right - left + strokeWidth, halfStroke)];
|
|
194
|
+
if (line === firstLine) {
|
|
195
|
+
parts.push(part(left - halfStroke, startWidth, startBottom));
|
|
196
|
+
}
|
|
197
|
+
if (line === lastLine) {
|
|
198
|
+
parts.push(part(right - halfStroke, strokeWidth, hook + halfStroke));
|
|
199
|
+
}
|
|
200
|
+
let lineY = Infinity;
|
|
201
|
+
for (const part of parts) {
|
|
202
|
+
for (const [track, extent] of context.getHorizontalExtents(line, part.x, part.x + part.w)) {
|
|
203
|
+
lineY = Math.min(lineY, context.getVisualAxis(line, track) + extent.top - gap - (part.y + part.h));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (lineY === Infinity)
|
|
207
|
+
lineY = hostTop - gap - halfStroke;
|
|
208
|
+
for (const part of parts)
|
|
209
|
+
part.y += lineY;
|
|
210
|
+
return { left, right, lineY, line, parts };
|
|
189
211
|
});
|
|
190
212
|
return {
|
|
191
|
-
regions: draws.map(({
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
h: hook + strokeWidth,
|
|
196
|
-
line,
|
|
197
|
-
track,
|
|
213
|
+
regions: draws.map(({ parts }) => ({
|
|
214
|
+
...parts[0],
|
|
215
|
+
w: Math.max(...parts.map(part => part.x + part.w)) - parts[0].x,
|
|
216
|
+
h: Math.max(...parts.map(part => part.h)),
|
|
198
217
|
})),
|
|
218
|
+
occupancy: draws.flatMap(draw => draw.parts),
|
|
199
219
|
paint(painter) {
|
|
200
220
|
const lineStyle = { stroke: "#000", strokeWidth };
|
|
201
221
|
for (const { left, right, lineY, line } of draws) {
|
|
@@ -203,7 +223,7 @@ class VoltaAttachment {
|
|
|
203
223
|
// 只有房子真正开始和结束的那一端才下折
|
|
204
224
|
if (line === firstLine) {
|
|
205
225
|
painter.drawLine(left, lineY, left, lineY + hook, lineStyle);
|
|
206
|
-
painter.drawText(text, left +
|
|
226
|
+
painter.drawText(text, left + textX, lineY + textY, style);
|
|
207
227
|
}
|
|
208
228
|
if (line === lastLine)
|
|
209
229
|
painter.drawLine(right, lineY, right, lineY + hook, lineStyle);
|