jpfun 1.1.0 → 1.2.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/diagnostic.d.ts +1 -0
- package/dist/diagnostic.js +1 -0
- package/dist/functions/ASTtypes.d.ts +2 -3
- package/dist/functions/ASTtypes.js +2 -3
- package/dist/functions/adjust/index.js +15 -67
- package/dist/functions/bar/index.js +8 -7
- package/dist/functions/beam/auto.js +15 -11
- package/dist/functions/beam/layout.js +22 -48
- package/dist/functions/br/index.d.ts +9 -3
- package/dist/functions/br/index.js +20 -16
- package/dist/functions/dash/index.js +13 -11
- package/dist/functions/div/index.d.ts +2 -2
- package/dist/functions/div/index.js +5 -9
- package/dist/functions/dot/index.js +5 -9
- package/dist/functions/dyn/index.js +125 -53
- package/dist/functions/grace/index.d.ts +2 -2
- package/dist/functions/grace/index.js +5 -9
- package/dist/functions/head/index.js +6 -7
- package/dist/functions/meter/index.js +7 -5
- package/dist/functions/note/index.js +5 -7
- package/dist/functions/ottava/index.js +8 -7
- package/dist/functions/page/index.js +8 -12
- package/dist/functions/pagebreak/index.js +2 -1
- package/dist/functions/rest/index.js +5 -5
- package/dist/functions/stack/index.js +1 -3
- package/dist/functions/symbol/symbols/dynamics.d.ts +3 -0
- package/dist/functions/symbol/symbols/dynamics.js +10 -1
- package/dist/functions/tempo/index.js +8 -3
- package/dist/functions/temporal.d.ts +18 -6
- package/dist/functions/temporal.js +1 -1
- package/dist/functions/text/index.js +1 -3
- package/dist/functions/up/index.js +29 -28
- package/dist/functions/voice/voice.d.ts +2 -1
- package/dist/functions/voice/voice.js +7 -13
- package/dist/functions/voice/voices.d.ts +4 -3
- package/dist/functions/voice/voices.js +8 -8
- package/dist/jpfun.min.js +48 -45
- package/dist/layout/engine.js +224 -211
- package/dist/layout/page.d.ts +2 -2
- package/dist/layout/page.js +8 -22
- package/dist/layout/types.d.ts +2 -4
- package/dist/lowering/loweringContext.d.ts +12 -7
- package/dist/lowering/loweringContext.js +50 -51
- package/dist/lowering/types.d.ts +2 -3
- package/dist/parser/grammarType.d.ts +4 -3
- package/dist/parser/parse-utils/brace-utils.js +4 -3
- package/dist/parser/parse-utils/call-utils.js +7 -7
- package/dist/parser/parserContext.d.ts +5 -9
- package/dist/parser/parserContext.js +24 -36
- package/dist/parser/types.d.ts +2 -1
- package/dist/playback/compile.js +23 -13
- package/dist/playback/types.d.ts +0 -1
- package/grammar.md +7 -6
- package/package.json +2 -2
package/dist/playback/compile.js
CHANGED
|
@@ -34,7 +34,7 @@ function linearizeColumns(lowering, diagnostics, maxFlowSteps) {
|
|
|
34
34
|
const finish = at.t.clone().add(at.T);
|
|
35
35
|
let end = index;
|
|
36
36
|
// 用顺序向后找而不是二分因为基本就在后一个(@rest除外)
|
|
37
|
-
while (end + 1 < columns.length && columns[end + 1]
|
|
37
|
+
while (end + 1 < columns.length && columns[end + 1].t.compare(finish) < 0)
|
|
38
38
|
end++;
|
|
39
39
|
return end;
|
|
40
40
|
}
|
|
@@ -172,6 +172,13 @@ export function compilePlayback(lowering, options) {
|
|
|
172
172
|
const notes = [];
|
|
173
173
|
const transforms = new Map();
|
|
174
174
|
const activePrograms = new Map();
|
|
175
|
+
let lastSignature;
|
|
176
|
+
/** 与上一个拍号相同则跳过,避免跳转补发与目标列自身拍号重复 */
|
|
177
|
+
const emitTimeSignature = (event) => {
|
|
178
|
+
if (lastSignature?.numerator === event.numerator && lastSignature.denominator === event.denominator)
|
|
179
|
+
return;
|
|
180
|
+
events.push(lastSignature = { ...event, at: event.at.clone() });
|
|
181
|
+
};
|
|
175
182
|
let nextNoteId = 0;
|
|
176
183
|
const changes = [{ kind: "initial", at: new Fraction(), origins: [] }];
|
|
177
184
|
const factors = new Map();
|
|
@@ -223,15 +230,12 @@ export function compilePlayback(lowering, options) {
|
|
|
223
230
|
spanScales.set(span, inheritedScales);
|
|
224
231
|
return span;
|
|
225
232
|
}
|
|
226
|
-
//
|
|
233
|
+
// 每次访问都恢复记谱位置固化的音轨音色,回跳不继承上一遍结束时的状态
|
|
227
234
|
const program = node.playbackState?.program;
|
|
228
235
|
if (program !== undefined && activePrograms.get(track) !== program) {
|
|
229
236
|
activePrograms.set(track, program);
|
|
230
237
|
events.push({ kind: "program-change", at: start.clone(), track, program });
|
|
231
238
|
}
|
|
232
|
-
const bpm = node.playbackState?.bpm;
|
|
233
|
-
if (bpm !== undefined)
|
|
234
|
-
scheduleControl(start, lineage, state => { state.bpm = bpm; });
|
|
235
239
|
node.emitPlayback?.({
|
|
236
240
|
start,
|
|
237
241
|
end: start.clone().add(duration),
|
|
@@ -266,7 +270,7 @@ export function compilePlayback(lowering, options) {
|
|
|
266
270
|
spanScales.set(span, scales);
|
|
267
271
|
span.end.add(duration);
|
|
268
272
|
},
|
|
269
|
-
emit:
|
|
273
|
+
emit: emitTimeSignature,
|
|
270
274
|
control: (at, apply) => scheduleControl(at, lineage, apply),
|
|
271
275
|
/** 只登记效果身份和比例,范围等结构与连接确定后再计算 */
|
|
272
276
|
scaleFollowingBpm(key, numerator, denominator = 1, options) {
|
|
@@ -293,7 +297,7 @@ export function compilePlayback(lowering, options) {
|
|
|
293
297
|
hook(structureContext);
|
|
294
298
|
}
|
|
295
299
|
const order = linearizeColumns(lowering, diagnostics, maxFlowSteps);
|
|
296
|
-
const firstScore = lowering.columns[order[0]]?.
|
|
300
|
+
const firstScore = lowering.columns[order[0]]?.t.clone() ?? new Fraction();
|
|
297
301
|
const scoreMap = [{
|
|
298
302
|
performance: new Fraction(), // 演奏时间0
|
|
299
303
|
score: firstScore // 记谱时间0
|
|
@@ -303,20 +307,26 @@ export function compilePlayback(lowering, options) {
|
|
|
303
307
|
const performanceEnd = new Fraction();
|
|
304
308
|
for (let step = 0; step < order.length; step++) {
|
|
305
309
|
const index = order[step];
|
|
310
|
+
const column = lowering.columns[index];
|
|
306
311
|
// 同列各顶层访问共享演奏坐标,但分别建立自己的效果作用域
|
|
307
|
-
for (const node of
|
|
312
|
+
for (const node of column) {
|
|
308
313
|
if (!node.playbackState && !node.emitPlayback)
|
|
309
314
|
continue;
|
|
310
|
-
play(node, [], [],
|
|
315
|
+
play(node, [], [], column.t.clone().add(shift), node.T.clone());
|
|
311
316
|
}
|
|
312
|
-
const boundary = lowering.columns[index + 1]?.
|
|
317
|
+
const boundary = lowering.columns[index + 1]?.t ?? lowering.duration; // 当前列的控制终点
|
|
313
318
|
performanceEnd.copyFrom(boundary).add(shift);
|
|
314
319
|
const next = order[step + 1];
|
|
315
320
|
if (next === undefined || next === index + 1)
|
|
316
321
|
continue;
|
|
317
|
-
// 离开记谱顺序时 performance
|
|
318
|
-
const
|
|
322
|
+
// 离开记谱顺序时 performance 不跳,只改变接下来对应的 score 坐标并恢复目标列速度
|
|
323
|
+
const nextColumn = lowering.columns[next];
|
|
324
|
+
const resume = nextColumn.t.clone();
|
|
319
325
|
shift.add(boundary).sub(resume);
|
|
326
|
+
scheduleControl(performanceEnd, [{ node: nextColumn[0] }], state => { state.bpm = nextColumn.bpm; });
|
|
327
|
+
const { timeSignature } = nextColumn;
|
|
328
|
+
if (timeSignature)
|
|
329
|
+
emitTimeSignature({ kind: "time-signature", at: performanceEnd, ...timeSignature });
|
|
320
330
|
const point = { performance: performanceEnd.clone(), score: resume };
|
|
321
331
|
const previous = scoreMap[scoreMap.length - 1];
|
|
322
332
|
// 同一个演奏时刻指向后面最近的谱面时刻
|
|
@@ -386,7 +396,7 @@ export function compilePlayback(lowering, options) {
|
|
|
386
396
|
}
|
|
387
397
|
}
|
|
388
398
|
const system = {
|
|
389
|
-
bpm: DEFAULT_BPM,
|
|
399
|
+
bpm: lowering.columns[order[0]]?.bpm ?? DEFAULT_BPM,
|
|
390
400
|
bpmScale: new Fraction(1),
|
|
391
401
|
};
|
|
392
402
|
const activeCounts = new Map();
|
package/dist/playback/types.d.ts
CHANGED
package/grammar.md
CHANGED
|
@@ -58,10 +58,9 @@ sidebar:
|
|
|
58
58
|
|
|
59
59
|
### 页面与谱头
|
|
60
60
|
|
|
61
|
-
- `@page(width, height, top, bottom, left, right,
|
|
61
|
+
- `@page(width, height, top, bottom, left, right, numbering, barNumbering, font, fillRatio)`:页面布局。
|
|
62
62
|
- 仅顶层首次声明有效,其余警告并忽略;`em` 按声明时字号计算。
|
|
63
|
-
- 默认:宽 `794px`、高 `0px`、上 `45px`、下 `48px`、左右 `40px
|
|
64
|
-
- `gap` 为上一行下沿到下一行主旋律上沿(基线减半字高)的标准行距;顶部外扩图形优先借用行距,但与上一行下沿至少保留 `minGap`(不超过 `gap`)。
|
|
63
|
+
- 默认:宽 `794px`、高 `0px`、上 `45px`、下 `48px`、左右 `40px`、`fillRatio=0.5`。行距由 [`@br`](#换行) 设置。
|
|
65
64
|
- `height <= 0` 不自动分页,仍可手动换页;正值按整行分页,单行超高报错。自动封页均分剩余高度,末页保持自然行距。
|
|
66
65
|
- `fillRatio`:自然宽度达到版心宽度的该比例时撑满;负值始终撑满,`>= 1` 不自动拉开。
|
|
67
66
|
- `numbering`:页码格式,如 `"1/1"`,默认 `""` 不显示;`font`:页码/小节号字体,默认 `""` 沿用当前字体。
|
|
@@ -129,9 +128,11 @@ sidebar:
|
|
|
129
128
|
- 有限页高下默认分配当前页的剩余空间;`justify=false` 只保留最小行距。无限页高按自然高度结束,不拉伸。
|
|
130
129
|
- 同时刻的并行调用只换一次页,任一 `justify=false` 则不拉伸;同轨连续调用分别执行。
|
|
131
130
|
|
|
132
|
-
- `@br(
|
|
131
|
+
- `@br(gap=1em, minGap=0.4em)`:换到下一谱面行,并设置与上一行的行距。
|
|
133
132
|
- 顶层空行(连续至少两个换行)等价于一次 `@br()`;普通源码换行及块内空行不换谱面行。
|
|
134
|
-
-
|
|
133
|
+
- 同轨连续调用累加,`@br() @br()` 产生一条高 0 的空行,即叠加两段行距;同时刻的并行调用只换一次行,行距取较大值。
|
|
134
|
+
- `gap` 为上一行下沿到下一行主旋律上沿(基线减半字高)的标准行距;顶部外扩图形优先借用行距,但与上一行下沿至少保留 `minGap`(不超过 `gap`)。负值允许行与行重叠,`em` 按调用处字号计算;用 `@set(br.gap=...)` 设置后续默认行距。
|
|
135
|
+
- 换页后的首行没有行距,`gap` 不生效。
|
|
135
136
|
|
|
136
137
|
### 声部与歌词
|
|
137
138
|
|
|
@@ -250,5 +251,5 @@ sidebar:
|
|
|
250
251
|
|
|
251
252
|
## 5. 预处理规则(换行与注释)
|
|
252
253
|
- **注释**:字符串外 `%` 至行末;`\%` 不能阻止注释。
|
|
253
|
-
- **换行**:支持 `\n`、`\r\n
|
|
254
|
+
- **换行**:支持 `\n`、`\r\n`。
|
|
254
255
|
- **续行**:忽略行尾空白后,末尾连续 `\` 每对保留一个;总数为奇数则合并下一行,偶数则保留换行。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jpfun",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A functional numbered musical notation typesetting engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"author": "madderscientist",
|
|
48
48
|
"license": "Apache-2.0",
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@types/node": "^26.
|
|
50
|
+
"@types/node": "^26.6.11",
|
|
51
51
|
"esbuild": "^0.28.2",
|
|
52
52
|
"tsx": "^4.23.13",
|
|
53
53
|
"typescript": "^7.0.2"
|