jpfun 0.3.0 → 0.4.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 +73 -1
- package/dist/converter/midi/convert.d.ts +50 -0
- package/dist/converter/midi/convert.js +700 -0
- package/dist/converter/midi/index.d.ts +5 -0
- package/dist/converter/midi/index.js +11 -0
- package/dist/converter/midi/json.d.ts +38 -0
- package/dist/converter/midi/json.js +1 -0
- package/dist/converter/midi/triplet.d.ts +30 -0
- package/dist/converter/midi/triplet.js +75 -0
- package/dist/converter/musicxml/dom.d.ts +25 -0
- package/dist/converter/musicxml/dom.js +65 -0
- package/dist/converter/musicxml/features.d.ts +51 -0
- package/dist/converter/musicxml/features.js +232 -0
- package/dist/converter/musicxml/index.d.ts +9 -0
- package/dist/converter/musicxml/index.js +1140 -0
- package/dist/converter/musicxml/model.d.ts +123 -0
- package/dist/converter/musicxml/model.js +1 -0
- package/dist/converter/source.d.ts +22 -0
- package/dist/converter/source.js +51 -0
- package/dist/core.d.ts +22 -0
- package/dist/core.js +22 -0
- package/dist/functions/ASTtypes.d.ts +28 -25
- package/dist/functions/ASTtypes.js +25 -23
- package/dist/functions/adjust/index.js +1 -1
- package/dist/functions/arpeggio/index.d.ts +2 -0
- package/dist/functions/arpeggio/index.js +180 -0
- package/dist/functions/arpeggio/shape.d.ts +7 -0
- package/dist/functions/arpeggio/shape.js +122 -0
- package/dist/functions/bar/index.js +23 -15
- package/dist/functions/beam/auto.d.ts +1 -1
- package/dist/functions/beam/auto.js +1 -1
- package/dist/functions/beam/layout.d.ts +2 -2
- package/dist/functions/beam/layout.js +1 -1
- package/dist/functions/box/index.js +2 -2
- package/dist/functions/br/index.js +1 -1
- package/dist/functions/dash/index.js +7 -6
- package/dist/functions/default.js +6 -2
- package/dist/functions/dot/index.js +12 -22
- package/dist/functions/dyn/index.d.ts +2 -0
- package/dist/functions/dyn/index.js +242 -0
- package/dist/functions/grace/index.d.ts +1 -1
- package/dist/functions/grace/index.js +2 -3
- package/dist/functions/head/index.js +149 -145
- package/dist/functions/key/index.js +5 -4
- package/dist/functions/meter/index.js +6 -5
- package/dist/functions/note/index.js +68 -21
- package/dist/functions/note/noteNameFSM.js +52 -63
- package/dist/functions/page/index.d.ts +2 -0
- package/dist/functions/page/index.js +22 -7
- package/dist/functions/program/index.d.ts +2 -0
- package/dist/functions/program/index.js +30 -0
- package/dist/functions/set/index.js +8 -5
- package/dist/functions/symbol/index.d.ts +13 -3
- package/dist/functions/symbol/index.js +61 -16
- package/dist/functions/symbol/shape.d.ts +2 -0
- package/dist/functions/symbol/shape.js +14 -10
- package/dist/functions/symbol/symbols/dc.d.ts +4 -0
- package/dist/functions/symbol/symbols/dc.js +82 -0
- package/dist/functions/symbol/symbols/{f.d.ts → ds.d.ts} +1 -1
- package/dist/functions/symbol/symbols/ds.js +93 -0
- package/dist/functions/symbol/symbols/dynamics.d.ts +3 -0
- package/dist/functions/symbol/symbols/dynamics.js +168 -0
- package/dist/functions/symbol/symbols/{p.d.ts → fine.d.ts} +1 -1
- package/dist/functions/symbol/symbols/fine.js +12 -0
- package/dist/functions/symbol/symbols/mordent.js +44 -31
- package/dist/functions/symbol/symbols/prall.d.ts +2 -0
- package/dist/functions/symbol/symbols/prall.js +42 -0
- package/dist/functions/symbol/symbols/segno.d.ts +4 -0
- package/dist/functions/symbol/symbols/segno.js +82 -0
- package/dist/functions/symbol/symbols/tr.js +0 -4
- package/dist/functions/tempo/index.js +5 -3
- package/dist/functions/temporal.d.ts +138 -0
- package/dist/functions/temporal.js +101 -0
- package/dist/functions/text/index.js +14 -7
- package/dist/functions/tie/index.js +37 -28
- package/dist/functions/tuplet/index.js +14 -7
- package/dist/functions/up/index.js +23 -21
- package/dist/functions/voice/index.js +121 -45
- package/dist/functions/volta/index.js +51 -48
- package/dist/iife/core.d.ts +1 -0
- package/dist/iife/core.js +3 -0
- package/dist/iife/from-midi.d.ts +1 -0
- package/dist/iife/from-midi.js +15 -0
- package/dist/iife/from-musicxml.d.ts +1 -0
- package/dist/iife/from-musicxml.js +3 -0
- package/dist/iife/full.d.ts +1 -0
- package/dist/iife/full.js +3 -0
- package/dist/index.d.ts +3 -21
- package/dist/index.js +3 -21
- package/dist/jpfun.core.min.js +153 -0
- package/dist/jpfun.from-midi.min.js +9 -0
- package/dist/jpfun.from-musicxml.min.js +12 -0
- package/dist/jpfun.min.js +71 -48
- package/dist/layout/default.js +2 -3
- package/dist/layout/engine.d.ts +2 -1
- package/dist/layout/engine.js +71 -26
- package/dist/layout/model.d.ts +4 -4
- package/dist/layout/model.js +15 -12
- package/dist/layout/page.js +5 -4
- package/dist/layout/path.js +3 -3
- package/dist/layout/types.d.ts +20 -2
- package/dist/lowering/loweringContext.d.ts +3 -1
- package/dist/lowering/loweringContext.js +28 -14
- package/dist/lowering/track.d.ts +4 -8
- package/dist/lowering/track.js +6 -1
- package/dist/lowering/types.d.ts +5 -128
- package/dist/lowering/types.js +1 -98
- package/dist/parser/parse-utils/string-utils.d.ts +2 -0
- package/dist/parser/parse-utils/string-utils.js +4 -0
- package/dist/parser/parserContext.d.ts +7 -8
- package/dist/parser/parserContext.js +41 -36
- package/dist/pipeline.d.ts +6 -5
- package/dist/pipeline.js +4 -5
- package/dist/playback/compile.d.ts +1 -1
- package/dist/playback/compile.js +15 -2
- package/dist/playback/event.d.ts +17 -3
- package/dist/playback/event.js +30 -12
- package/dist/playback/time.js +1 -1
- package/dist/playback/types.d.ts +5 -4
- package/dist/render/text.d.ts +6 -1
- package/dist/render/text.js +8 -1
- package/grammar.md +44 -8
- package/package.json +11 -2
- package/dist/functions/symbol/symbols/f.js +0 -55
- package/dist/functions/symbol/symbols/p.js +0 -61
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ANCHOR_KEY, isVisualTemporalNode, } from "
|
|
1
|
+
import { ANCHOR_KEY, isVisualTemporalNode, } from "../temporal.js";
|
|
2
2
|
import { repeatPass } from "../bar/index.js";
|
|
3
3
|
import { ASTFunctionNode, } from "../ASTtypes.js";
|
|
4
4
|
import { Diagnostic, ErrorDiagnostic } from "../../diagnostic.js";
|
|
@@ -40,6 +40,7 @@ pass 是遍数:整段谱面演奏到第几遍时才播这里,必填正整数
|
|
|
40
40
|
passes;
|
|
41
41
|
/** 区间没有可见宿主时括线的尺寸基准 */
|
|
42
42
|
size;
|
|
43
|
+
font;
|
|
43
44
|
/** volta 不推进时间,只把 AST 端点解析成稳定的 temporal 引用 */
|
|
44
45
|
loweringEnter(ctx) {
|
|
45
46
|
let from = ctx.getTemporalNodes(this.from).at(0);
|
|
@@ -58,6 +59,7 @@ pass 是遍数:整段谱面演奏到第几遍时才播这里,必填正整数
|
|
|
58
59
|
constructor(span, args, ctx, parent = null) {
|
|
59
60
|
super(span, parent);
|
|
60
61
|
const [from, to, pass] = this.getArgValue(args, ctx);
|
|
62
|
+
this.font = ctx.variables.numberfont;
|
|
61
63
|
// 第一个遍数走 def.args,其余的落在 extraArgType 里,按位置索引取
|
|
62
64
|
const passes = new Set([pass]);
|
|
63
65
|
for (let i = 3; args.has(i); i++)
|
|
@@ -65,7 +67,7 @@ pass 是遍数:整段谱面演奏到第几遍时才播这里,必填正整数
|
|
|
65
67
|
this.from = from;
|
|
66
68
|
this.to = to;
|
|
67
69
|
this.passes = [...passes].sort((a, b) => a - b);
|
|
68
|
-
this.size = ctx.
|
|
70
|
+
this.size = ctx.variables.fontsize;
|
|
69
71
|
if (this.passes.some(value => !Number.isSafeInteger(value) || value <= 0)) {
|
|
70
72
|
throw new ErrorDiagnostic("E_VOLTA_INVALID_PASS", "@volta 的遍数必须是正整数", span);
|
|
71
73
|
}
|
|
@@ -87,14 +89,6 @@ class VoltaAttachment {
|
|
|
87
89
|
from;
|
|
88
90
|
to;
|
|
89
91
|
layer = "foreground";
|
|
90
|
-
/** 首末端点列最上方的对象、区间最大字号与紧邻的小节线,横向准备时填入 */
|
|
91
|
-
head;
|
|
92
|
-
tail;
|
|
93
|
-
span = 0;
|
|
94
|
-
leftBar;
|
|
95
|
-
rightBar;
|
|
96
|
-
/** 逐行记下覆盖列内各轨的最高点,相对该轨视觉轴;轴要等纵向求解才知道 */
|
|
97
|
-
topsByLine = [];
|
|
98
92
|
constructor(ast, from, to) {
|
|
99
93
|
this.ast = ast;
|
|
100
94
|
this.from = from;
|
|
@@ -117,11 +111,12 @@ class VoltaAttachment {
|
|
|
117
111
|
: { kind: "jump", column: end + 1 },
|
|
118
112
|
};
|
|
119
113
|
}
|
|
120
|
-
|
|
121
|
-
if (!isVisualTemporalNode(this.from) || !isVisualTemporalNode(this.to))
|
|
122
|
-
return;
|
|
114
|
+
createGeometry(context) {
|
|
115
|
+
if (!isVisualTemporalNode(this.from) || !isVisualTemporalNode(this.to)) {
|
|
116
|
+
return { regions: [], paint() { } };
|
|
117
|
+
}
|
|
123
118
|
const locate = (node) => {
|
|
124
|
-
const view = lines[node.layoutLine];
|
|
119
|
+
const view = context.lines[node.layoutLine];
|
|
125
120
|
return { line: node.layoutLine, view, column: view.columnOf(node) };
|
|
126
121
|
};
|
|
127
122
|
// 两个标签谁写在前面不一定,按谱面顺序摆正
|
|
@@ -130,42 +125,29 @@ class VoltaAttachment {
|
|
|
130
125
|
[from, to] = [to, from];
|
|
131
126
|
}
|
|
132
127
|
if (from.column < 0 || to.column < 0)
|
|
133
|
-
return;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
128
|
+
return { regions: [], paint() { } };
|
|
129
|
+
const head = from.view.columns[from.column][0];
|
|
130
|
+
const tail = to.view.columns[to.column][0];
|
|
131
|
+
const leftBar = barIn(from.view.columns[from.column - 1]);
|
|
132
|
+
const rightBar = barIn(to.view.columns[to.column + 1]);
|
|
133
|
+
let span = 0;
|
|
134
|
+
const coverage = [];
|
|
140
135
|
// 括线盖住的是:首行从起点列向右、末行向左到终点列、中间行整行
|
|
141
136
|
for (let line = from.line; line <= to.line; line++) {
|
|
142
|
-
const view = lines[line];
|
|
137
|
+
const view = context.lines[line];
|
|
143
138
|
const start = line === from.line ? from.column : 0;
|
|
144
139
|
const end = line === to.line ? to.column : view.columns.length - 1;
|
|
145
|
-
const tops = new Map();
|
|
146
140
|
for (let column = start; column <= end; column++) {
|
|
147
|
-
|
|
148
|
-
this.span = Math.max(this.span, hosts[0].ast.size);
|
|
149
|
-
// 此刻 visualAxis 已冻结,纵向求解后 box.y 就是 该轨视觉轴 - visualAxis
|
|
150
|
-
for (const host of hosts) {
|
|
151
|
-
const top = -host.box.visualAxis;
|
|
152
|
-
const known = tops.get(host.track);
|
|
153
|
-
if (known === undefined || top < known)
|
|
154
|
-
tops.set(host.track, top);
|
|
155
|
-
}
|
|
141
|
+
span = Math.max(span, view.columns[column][0].ast.size);
|
|
156
142
|
}
|
|
157
|
-
|
|
143
|
+
coverage.push({ from: start, to: end, wholeLine: line !== from.line && line !== to.line });
|
|
158
144
|
}
|
|
159
|
-
}
|
|
160
|
-
createGeometry(context) {
|
|
161
|
-
const { head, tail, leftBar, rightBar } = this;
|
|
162
|
-
if (!head || !tail)
|
|
163
|
-
return { regions: [], paint() { } };
|
|
164
145
|
const firstLine = head.layoutLine;
|
|
165
146
|
const lastLine = tail.layoutLine;
|
|
166
|
-
const size =
|
|
147
|
+
const size = span || this.ast.size;
|
|
167
148
|
const style = {
|
|
168
149
|
fontSize: size * 0.6,
|
|
150
|
+
fontFamily: this.ast.font,
|
|
169
151
|
textAlign: "left",
|
|
170
152
|
fill: "#000",
|
|
171
153
|
};
|
|
@@ -179,17 +161,14 @@ class VoltaAttachment {
|
|
|
179
161
|
// 中间行可能没有本房子的可见对象,仍要补满,所以按行号连续遍历
|
|
180
162
|
const draws = Array.from({ length: lastLine - firstLine + 1 }, (_, offset) => {
|
|
181
163
|
const line = firstLine + offset;
|
|
182
|
-
// 跨行断开的那一侧一直画到页边,接上下一行
|
|
183
|
-
const left = line !== firstLine ? context.originX
|
|
184
|
-
: leftBar?.layoutLine === line ? leftBar.box.x + leftBar.box.anchor + 5 // 5是防止前后房子竖线重合
|
|
185
|
-
: head.box.x + (head.ports["body.left"]?.x ?? 0);
|
|
186
|
-
const right = line !== lastLine ? context.originX + context.width
|
|
187
|
-
: rightBar?.layoutLine === line ? rightBar.box.x + rightBar.box.anchor
|
|
188
|
-
: tail.box.x + (tail.ports["body.right"]?.x ?? tail.box.w);
|
|
189
164
|
let topTrack = head.track;
|
|
190
165
|
let hostTop = Infinity;
|
|
191
|
-
|
|
192
|
-
|
|
166
|
+
const range = coverage[offset];
|
|
167
|
+
const extents = range.wholeLine
|
|
168
|
+
? context.getRangeExtents(line)
|
|
169
|
+
: context.getRangeExtents(line, [range.from, range.to]);
|
|
170
|
+
for (const [track, extent] of extents) {
|
|
171
|
+
const y = context.getVisualAxis(line, track) + extent.top;
|
|
193
172
|
if (y < hostTop) {
|
|
194
173
|
topTrack = track;
|
|
195
174
|
hostTop = y;
|
|
@@ -198,6 +177,15 @@ class VoltaAttachment {
|
|
|
198
177
|
// 整行空白时没有主体可以参照,退到轨道轴上
|
|
199
178
|
if (hostTop === Infinity)
|
|
200
179
|
hostTop = context.getVisualAxis(line, topTrack);
|
|
180
|
+
// 换行断点跟随系统的视觉边界;空行没有主体时仍退到内容区页边
|
|
181
|
+
const rawLeft = line !== firstLine ? this.lineEntryX(context, line, topTrack)
|
|
182
|
+
: leftBar?.layoutLine === line ? leftBar.box.x + leftBar.box.anchor + 5 // 5是防止前后房子竖线重合
|
|
183
|
+
: head.box.x + (head.ports["body.left"]?.x ?? 0);
|
|
184
|
+
const rawRight = line !== lastLine ? this.lineRightX(context, line)
|
|
185
|
+
: rightBar?.layoutLine === line ? rightBar.box.x + rightBar.box.anchor
|
|
186
|
+
: tail.box.x + (tail.ports["body.right"]?.x ?? tail.box.w);
|
|
187
|
+
const left = Math.min(rawLeft, rawRight);
|
|
188
|
+
const right = Math.max(rawLeft, rawRight);
|
|
201
189
|
return { left, right, lineY: hostTop - size * 0.2 - hook, line, track: topTrack };
|
|
202
190
|
});
|
|
203
191
|
return {
|
|
@@ -224,4 +212,19 @@ class VoltaAttachment {
|
|
|
224
212
|
},
|
|
225
213
|
};
|
|
226
214
|
}
|
|
215
|
+
lineEntryX(context, line, track) {
|
|
216
|
+
const host = context.lines[line].trackRuns.get(track)?.find(item => !item.T.isZero());
|
|
217
|
+
return host?.box.x ?? context.originX;
|
|
218
|
+
}
|
|
219
|
+
lineRightX(context, line) {
|
|
220
|
+
const runs = context.lines[line].trackRuns;
|
|
221
|
+
if (runs.size === 0)
|
|
222
|
+
return context.originX + context.width;
|
|
223
|
+
let right = context.originX;
|
|
224
|
+
for (const run of runs.values()) {
|
|
225
|
+
for (const host of run)
|
|
226
|
+
right = Math.max(right, host.box.x + host.box.w);
|
|
227
|
+
}
|
|
228
|
+
return right;
|
|
229
|
+
}
|
|
227
230
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { convertMidiJsonToJpFun, } from "../converter/midi/convert.js";
|
|
2
|
+
const target = globalThis;
|
|
3
|
+
const api = target.jpfun ??= {};
|
|
4
|
+
Object.assign(api, {
|
|
5
|
+
midiJsonToJpFun(input, options = {}) {
|
|
6
|
+
const layoutCapability = (options.barsPerLine ?? 0) <= 0
|
|
7
|
+
? {
|
|
8
|
+
compileScore: api.compileScore,
|
|
9
|
+
anchorKey: api.ANCHOR_KEY,
|
|
10
|
+
page: api.DEFAULT_PAGE_CONFIG,
|
|
11
|
+
}
|
|
12
|
+
: undefined;
|
|
13
|
+
return convertMidiJsonToJpFun(input, options, layoutCapability);
|
|
14
|
+
},
|
|
15
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./diagnostic.js";
|
|
5
|
-
export * from "./fraction.js";
|
|
6
|
-
export * from "./parser/types.js";
|
|
7
|
-
export * from "./parser/grammarType.js";
|
|
8
|
-
export * from "./parser/parserContext.js";
|
|
9
|
-
export * from "./parser/preprocess.js";
|
|
10
|
-
export * from "./lowering/types.js";
|
|
11
|
-
export * from "./lowering/loweringContext.js";
|
|
12
|
-
export * from "./lowering/track.js";
|
|
13
|
-
export * from "./playback/types.js";
|
|
14
|
-
export * from "./playback/time.js";
|
|
15
|
-
export * from "./playback/compile.js";
|
|
16
|
-
export * from "./layout/types.js";
|
|
17
|
-
export * from "./layout/model.js";
|
|
18
|
-
export * from "./layout/default.js";
|
|
19
|
-
export * from "./layout/page.js";
|
|
20
|
-
export * from "./layout/engine.js";
|
|
21
|
-
export * from "./render/index.js";
|
|
1
|
+
export * from "./core.js";
|
|
2
|
+
export * from "./converter/midi/index.js";
|
|
3
|
+
export * from "./converter/musicxml/index.js";
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,3 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./diagnostic.js";
|
|
5
|
-
export * from "./fraction.js";
|
|
6
|
-
export * from "./parser/types.js";
|
|
7
|
-
export * from "./parser/grammarType.js";
|
|
8
|
-
export * from "./parser/parserContext.js";
|
|
9
|
-
export * from "./parser/preprocess.js";
|
|
10
|
-
export * from "./lowering/types.js";
|
|
11
|
-
export * from "./lowering/loweringContext.js";
|
|
12
|
-
export * from "./lowering/track.js";
|
|
13
|
-
export * from "./playback/types.js";
|
|
14
|
-
export * from "./playback/time.js";
|
|
15
|
-
export * from "./playback/compile.js";
|
|
16
|
-
export * from "./layout/types.js";
|
|
17
|
-
export * from "./layout/model.js";
|
|
18
|
-
export * from "./layout/default.js";
|
|
19
|
-
export * from "./layout/page.js";
|
|
20
|
-
export * from "./layout/engine.js";
|
|
21
|
-
export * from "./render/index.js";
|
|
1
|
+
export * from "./core.js";
|
|
2
|
+
export * from "./converter/midi/index.js";
|
|
3
|
+
export * from "./converter/musicxml/index.js";
|