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.
Files changed (110) hide show
  1. package/Bravura-LICENSE.txt +93 -0
  2. package/README.md +49 -146
  3. package/dist/Bravura-LICENSE.txt +93 -0
  4. package/dist/converter/midi/convert.d.ts +0 -10
  5. package/dist/converter/midi/convert.js +11 -1
  6. package/dist/converter/musicxml/features.d.ts +15 -7
  7. package/dist/converter/musicxml/features.js +87 -18
  8. package/dist/converter/musicxml/index.js +80 -32
  9. package/dist/converter/musicxml/model.d.ts +9 -0
  10. package/dist/core.d.ts +1 -0
  11. package/dist/core.js +1 -0
  12. package/dist/diagnostic.d.ts +7 -1
  13. package/dist/diagnostic.js +40 -88
  14. package/dist/fraction.js +3 -2
  15. package/dist/functions/ASTtypes.d.ts +2 -18
  16. package/dist/functions/ASTtypes.js +0 -16
  17. package/dist/functions/arpeggio/index.js +15 -17
  18. package/dist/functions/bar/index.d.ts +8 -0
  19. package/dist/functions/bar/index.js +102 -0
  20. package/dist/functions/beam/auto.d.ts +1 -2
  21. package/dist/functions/beam/auto.js +30 -16
  22. package/dist/functions/beam/index.js +2 -3
  23. package/dist/functions/beam/layout.d.ts +1 -1
  24. package/dist/functions/beam/layout.js +1 -1
  25. package/dist/functions/br/index.d.ts +34 -2
  26. package/dist/functions/br/index.js +5 -4
  27. package/dist/functions/dash/index.js +6 -6
  28. package/dist/functions/default.js +2 -1
  29. package/dist/functions/div/index.d.ts +1 -0
  30. package/dist/functions/div/index.js +8 -4
  31. package/dist/functions/dot/index.js +2 -2
  32. package/dist/functions/dyn/index.js +49 -31
  33. package/dist/functions/gliss/index.js +75 -53
  34. package/dist/functions/grace/index.d.ts +1 -7
  35. package/dist/functions/grace/index.js +8 -13
  36. package/dist/functions/head/index.js +1 -1
  37. package/dist/functions/key/index.js +8 -10
  38. package/dist/functions/meter/index.d.ts +56 -1
  39. package/dist/functions/meter/index.js +12 -7
  40. package/dist/functions/note/index.js +5 -5
  41. package/dist/functions/note/noteName.d.ts +16 -0
  42. package/dist/functions/note/noteName.js +88 -0
  43. package/dist/functions/note/source-transform.js +6 -5
  44. package/dist/functions/ottava/index.js +24 -8
  45. package/dist/functions/page/index.d.ts +1 -0
  46. package/dist/functions/page/index.js +20 -11
  47. package/dist/functions/pagebreak/index.js +2 -2
  48. package/dist/functions/rest/index.js +3 -1
  49. package/dist/functions/set/index.js +4 -4
  50. package/dist/functions/symbol/index.d.ts +21 -2
  51. package/dist/functions/symbol/index.js +69 -24
  52. package/dist/functions/symbol/ornament.d.ts +1 -2
  53. package/dist/functions/symbol/shape.d.ts +6 -0
  54. package/dist/functions/symbol/shape.js +16 -3
  55. package/dist/functions/symbol/symbols/coda.d.ts +4 -0
  56. package/dist/functions/symbol/symbols/coda.js +56 -0
  57. package/dist/functions/symbol/symbols/dynamics.d.ts +1 -1
  58. package/dist/functions/symbol/symbols/dynamics.js +18 -8
  59. package/dist/functions/symbol/symbols/harmonic.d.ts +2 -0
  60. package/dist/functions/symbol/symbols/harmonic.js +11 -0
  61. package/dist/functions/symbol/symbols/marcato.d.ts +2 -0
  62. package/dist/functions/symbol/symbols/marcato.js +22 -0
  63. package/dist/functions/symbol/symbols/staccato.d.ts +2 -0
  64. package/dist/functions/symbol/symbols/staccato.js +24 -0
  65. package/dist/functions/symbol/symbols/tenuto.d.ts +2 -0
  66. package/dist/functions/symbol/symbols/tenuto.js +11 -0
  67. package/dist/functions/symbol/symbols/tocoda.d.ts +2 -0
  68. package/dist/functions/symbol/symbols/tocoda.js +16 -0
  69. package/dist/functions/symbol/symbols/turn.d.ts +3 -0
  70. package/dist/functions/symbol/symbols/turn.js +50 -0
  71. package/dist/functions/symbol/symbols/wheel.d.ts +2 -0
  72. package/dist/functions/symbol/symbols/wheel.js +36 -0
  73. package/dist/functions/temporal.d.ts +1 -0
  74. package/dist/functions/temporal.js +1 -0
  75. package/dist/functions/text/index.js +15 -6
  76. package/dist/functions/tie/index.js +30 -6
  77. package/dist/functions/tremolo/index.d.ts +2 -0
  78. package/dist/functions/tremolo/index.js +319 -0
  79. package/dist/functions/tuplet/index.js +4 -8
  80. package/dist/functions/up/index.js +2 -2
  81. package/dist/functions/voice/index.js +17 -10
  82. package/dist/jpfun.core.min.js +57 -49
  83. package/dist/jpfun.from-midi.min.js +5 -5
  84. package/dist/jpfun.from-musicxml.min.js +8 -8
  85. package/dist/jpfun.min.js +62 -54
  86. package/dist/layout/default.d.ts +0 -1
  87. package/dist/layout/default.js +0 -1
  88. package/dist/lowering/loweringContext.d.ts +11 -13
  89. package/dist/lowering/loweringContext.js +26 -33
  90. package/dist/lowering/types.d.ts +1 -3
  91. package/dist/parser/parse-utils/note-utils.d.ts +1 -1
  92. package/dist/parser/parse-utils/note-utils.js +8 -9
  93. package/dist/parser/parse-utils/string-utils.d.ts +3 -2
  94. package/dist/parser/parse-utils/string-utils.js +16 -3
  95. package/dist/parser/parserContext.js +9 -2
  96. package/dist/pipeline.js +0 -1
  97. package/dist/playback/compile.js +120 -70
  98. package/dist/playback/event.d.ts +1 -1
  99. package/dist/playback/event.js +9 -9
  100. package/dist/playback/time.js +42 -31
  101. package/dist/playback/types.d.ts +3 -1
  102. package/dist/render/canvas.d.ts +2 -0
  103. package/dist/render/canvas.js +25 -22
  104. package/dist/render/recording.js +1 -4
  105. package/dist/render/translate.d.ts +0 -1
  106. package/dist/render/translate.js +6 -23
  107. package/grammar.md +26 -20
  108. package/package.json +3 -3
  109. package/dist/functions/note/noteNameFSM.d.ts +0 -8
  110. package/dist/functions/note/noteNameFSM.js +0 -181
@@ -0,0 +1,56 @@
1
+ /** $tocoda 的跳转目标 */
2
+ export const CODA_MARK = "repeat.coda";
3
+ /*!
4
+ * Bravura coda (U+E048), Y axis flipped; https://github.com/steinbergmedia/bravura
5
+ * Copyright (c) 2026, Steinberg Media Technologies GmbH. Reserved Font Name "Bravura".
6
+ * SPDX-License-Identifier: OFL-1.1
7
+ * Full license: Bravura-LICENSE.txt in the package root and dist.
8
+ */
9
+ const codaPath = [
10
+ { op: "M", x: -4, y: -376 },
11
+ { op: "C", cx1: -4, cy1: -363, cx2: 0, cy2: -352, x: 14, y: -352 },
12
+ { op: "L", x: 146, y: -352 },
13
+ { op: "C", cx1: 157, cy1: -165, cx2: 296, cy2: -13, x: 458, y: 0 },
14
+ { op: "L", x: 458, y: 140 },
15
+ { op: "C", cx1: 458, cy1: 154, cx2: 469, cy2: 158, x: 482, y: 158 },
16
+ { op: "C", cx1: 495, cy1: 158, cx2: 506, cy2: 154, x: 506, y: 140 },
17
+ { op: "L", x: 506, y: 0 },
18
+ { op: "C", cx1: 668, cy1: -13, cx2: 808, cy2: -165, x: 818, y: -352 },
19
+ { op: "L", x: 937, y: -352 },
20
+ { op: "C", cx1: 951, cy1: -352, cx2: 955, cy2: -363, x: 955, y: -376 },
21
+ { op: "C", cx1: 955, cy1: -389, cx2: 951, cy2: -400, x: 937, y: -400 },
22
+ { op: "L", x: 818, y: -400 },
23
+ { op: "C", cx1: 808, cy1: -588, cx2: 668, cy2: -739, x: 506, y: -752 },
24
+ { op: "L", x: 506, y: -881 },
25
+ { op: "C", cx1: 506, cy1: -894, cx2: 495, cy2: -898, x: 482, y: -898 },
26
+ { op: "C", cx1: 469, cy1: -898, cx2: 458, cy2: -894, x: 458, y: -881 },
27
+ { op: "L", x: 458, y: -752 },
28
+ { op: "C", cx1: 296, cy1: -739, cx2: 157, cy2: -589, x: 146, y: -400 },
29
+ { op: "L", x: 14, y: -400 },
30
+ { op: "C", cx1: 0, cy1: -400, cx2: -4, cy2: -389, x: -4, y: -376 },
31
+ { op: "Z" },
32
+ { op: "M", x: 653, y: -400 },
33
+ { op: "L", x: 506, y: -400 },
34
+ { op: "L", x: 506, y: -696 },
35
+ { op: "C", cx1: 646, cy1: -684, cx2: 653, cy2: -562, x: 653, y: -400 },
36
+ { op: "Z" },
37
+ { op: "M", x: 506, y: -352 },
38
+ { op: "L", x: 653, y: -352 },
39
+ { op: "C", cx1: 650, cy1: -199, cx2: 631, cy2: -63, x: 506, y: -48 },
40
+ { op: "Z" },
41
+ { op: "M", x: 316, y: -400 },
42
+ { op: "C", cx1: 316, cy1: -562, cx2: 316, cy2: -684, x: 458, y: -696 },
43
+ { op: "L", x: 458, y: -400 },
44
+ { op: "Z" },
45
+ { op: "M", x: 458, y: -352 },
46
+ { op: "L", x: 458, y: -48 },
47
+ { op: "C", cx1: 329, cy1: -63, cx2: 317, cy2: -198, x: 316, y: -352 },
48
+ { op: "Z" },
49
+ ];
50
+ export const codaSymbol = {
51
+ name: "coda",
52
+ description: "尾声记号:$tocoda 的跳转目标",
53
+ weight: 1.15,
54
+ playbackMarks: () => [CODA_MARK],
55
+ shapes: [{ path: codaPath, style: { fill: "#000" } }],
56
+ };
@@ -1,3 +1,3 @@
1
1
  import type { SymbolDefinition } from "../index.js";
2
- /** 力度阶梯是 16 的整数倍,末级钳到 127;mf 恰好等于 DEFAULT_VELOCITY */
2
+ /** 默认力度与 MuseScore 一致;mf 恰好等于 DEFAULT_VELOCITY */
3
3
  export declare const dynamicSymbols: readonly SymbolDefinition[];
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 力度记号族:八个记号由 m / f / p 三个字母横向拼接而成
2
+ * 力度记号族:由 m / f / p 三个字母横向拼接而成
3
3
  *
4
4
  * 三个字母抠自同一套字体的 mp / mf 连字,坐标同属一套字体坐标系(共基线、同字号),
5
5
  * 所以拼接只需要横向位移,字距也是从连字上量出来的。
@@ -140,6 +140,8 @@ const ADVANCE = {
140
140
  const INK = { fill: "#000" };
141
141
  /** size 是 f 的全高;p 系没有升部、盒子只有 f 的这么高,不按此缩小就会被放大 1.26 倍 */
142
142
  const P_WEIGHT = 0.79341;
143
+ const P_VELOCITIES = [49, 33, 16, 10, 5, 1];
144
+ const F_VELOCITIES = [96, 112, 126, 127];
143
145
  function dynamic(name, velocity, description) {
144
146
  let dx = 0;
145
147
  const shapes = Array.from(name, (letter, index) => {
@@ -155,14 +157,22 @@ function dynamic(name, velocity, description) {
155
157
  onTimeState: state => { state.velocity = velocity; },
156
158
  };
157
159
  }
158
- /** 力度阶梯是 16 的整数倍,末级钳到 127;mf 恰好等于 DEFAULT_VELOCITY */
160
+ /** 默认力度与 MuseScore 一致;mf 恰好等于 DEFAULT_VELOCITY */
159
161
  export const dynamicSymbols = [
160
- dynamic("ppp", 16, "极弱"),
161
- dynamic("pp", 32, "很弱"),
162
- dynamic("p", 48, "弱"),
162
+ {
163
+ ...dynamic("p", P_VELOCITIES[0], "弱;支持 `$p`、`$pp`、`$ppp` 等连续 p,整体居中"),
164
+ pattern: {
165
+ regex: /^p+$/,
166
+ resolve: ([name]) => dynamic(name, P_VELOCITIES[Math.min(name.length, P_VELOCITIES.length) - 1], "弱力度记号"),
167
+ },
168
+ },
163
169
  dynamic("mp", 64, "中弱"),
164
170
  dynamic("mf", 80, "中强"),
165
- dynamic("f", 96, "强"),
166
- dynamic("ff", 112, "很强"),
167
- dynamic("fff", 127, "极强"),
171
+ {
172
+ ...dynamic("f", F_VELOCITIES[0], "强;支持 `$f`、`$ff`、`$fff` 等连续 f,整体居中"),
173
+ pattern: {
174
+ regex: /^f+$/,
175
+ resolve: ([name]) => dynamic(name, F_VELOCITIES[Math.min(name.length, F_VELOCITIES.length) - 1], "强力度记号"),
176
+ },
177
+ },
168
178
  ];
@@ -0,0 +1,2 @@
1
+ import type { SymbolDefinition } from "../index.js";
2
+ export declare const harmonicSymbol: SymbolDefinition;
@@ -0,0 +1,11 @@
1
+ export const harmonicSymbol = {
2
+ name: "harmonic",
3
+ description: "泛音",
4
+ weight: 0.5,
5
+ shapes: [
6
+ {
7
+ circle: { cx: 5, cy: 5, r: 4.5 },
8
+ style: { fill: "none", stroke: "#000", strokeWidth: 1 },
9
+ },
10
+ ],
11
+ };
@@ -0,0 +1,2 @@
1
+ import type { SymbolDefinition } from "../index.js";
2
+ export declare const marcatoSymbol: SymbolDefinition;
@@ -0,0 +1,22 @@
1
+ import { accentSymbol } from "./accent.js";
2
+ export const marcatoSymbol = {
3
+ name: "marcato",
4
+ description: "强调音:尖顶记号;播放同重音,所附着音符力度增加 20,最高 127",
5
+ weight: 0.65,
6
+ shapes: [
7
+ {
8
+ path: [
9
+ { op: "M", x: 0, y: 10 },
10
+ { op: "L", x: 4.5, y: 0 },
11
+ { op: "L", x: 5.5, y: 0 },
12
+ { op: "L", x: 10, y: 10 },
13
+ { op: "L", x: 8, y: 10 },
14
+ { op: "L", x: 5, y: 3 },
15
+ { op: "L", x: 2, y: 10 },
16
+ { op: "Z" },
17
+ ],
18
+ style: { fill: "#000" },
19
+ },
20
+ ],
21
+ emitPlayback: accentSymbol.emitPlayback,
22
+ };
@@ -0,0 +1,2 @@
1
+ import type { SymbolDefinition } from "../index.js";
2
+ export declare const staccatoSymbol: SymbolDefinition;
@@ -0,0 +1,24 @@
1
+ export const staccatoSymbol = {
2
+ name: "staccato",
3
+ description: "断奏:所附着音符的实际发声时长缩短为一半",
4
+ weight: 0.8,
5
+ shapes: [
6
+ {
7
+ path: [
8
+ { op: "M", x: 0, y: 0 },
9
+ { op: "L", x: 12, y: 0 },
10
+ { op: "L", x: 6, y: 13 },
11
+ { op: "Z" },
12
+ ],
13
+ style: { fill: "#000" },
14
+ },
15
+ ],
16
+ /** 将目标音段的实际发声区间压缩至前半段,保留原起点与子音相对比例 */
17
+ emitPlayback: emitter => emitter.affectFollowing((_context, notes) => {
18
+ const origin = notes[0].start.clone();
19
+ for (const note of notes) {
20
+ note.start.sub(origin).div(2).add(origin);
21
+ note.end.sub(origin).div(2).add(origin);
22
+ }
23
+ }),
24
+ };
@@ -0,0 +1,2 @@
1
+ import type { SymbolDefinition } from "../index.js";
2
+ export declare const tenutoSymbol: SymbolDefinition;
@@ -0,0 +1,11 @@
1
+ export const tenutoSymbol = {
2
+ name: "tenuto",
3
+ description: "保持音",
4
+ weight: 0.18,
5
+ shapes: [
6
+ {
7
+ line: { x1: 0, y1: 0, x2: 7.2, y2: 0 },
8
+ style: { stroke: "#000", strokeWidth: 1.8 },
9
+ },
10
+ ],
11
+ };
@@ -0,0 +1,2 @@
1
+ import type { SymbolDefinition } from "../index.js";
2
+ export declare const tocodaSymbol: SymbolDefinition;
@@ -0,0 +1,16 @@
1
+ import { CODA_MARK } from "./coda.js";
2
+ import { JUMP_MARK } from "./dc.js";
3
+ export const tocodaSymbol = {
4
+ name: "tocoda",
5
+ description: "跳至尾声:回跳之后经过这里就跳向最近的 $coda",
6
+ weight: 1.4,
7
+ text: { content: "To Coda", fontFamily: '"Times New Roman", serif', fontStyle: "italic" },
8
+ // 判据是后方回跳已经发生,不是“第二次经过”;否则写在 |: :| 里会被反复线提前触发
9
+ onVisit: (cursor, at) => {
10
+ const jump = cursor.seek(JUMP_MARK, at, 1);
11
+ const coda = cursor.seek(CODA_MARK, at, 1);
12
+ return jump !== undefined && cursor.visits(jump) > 0 && coda !== undefined
13
+ ? { kind: "jump", column: coda }
14
+ : undefined;
15
+ },
16
+ };
@@ -0,0 +1,3 @@
1
+ import type { SymbolDefinition } from "../index.js";
2
+ export declare const turnSymbol: SymbolDefinition;
3
+ export declare const iturnSymbol: SymbolDefinition;
@@ -0,0 +1,50 @@
1
+ import { ornament } from "../ornament.js";
2
+ /*!
3
+ * Bravura 1.482 ornamentTurn (U+E567), Y axis flipped; https://github.com/steinbergmedia/bravura
4
+ * Copyright (c) 2026, Steinberg Media Technologies GmbH. Reserved Font Name "Bravura".
5
+ * SPDX-License-Identifier: OFL-1.1
6
+ * Full license: Bravura-LICENSE.txt in the package root and dist.
7
+ */
8
+ const turnPath = [
9
+ { op: "M", x: 371, y: -218 },
10
+ { op: "C", cx1: 340, cy1: -218, cx2: 315, cy2: -204, x: 315, y: -174 },
11
+ { op: "C", cx1: 315, cy1: -152, cx2: 330, cy2: -138, x: 351, y: -138 },
12
+ { op: "C", cx1: 380, cy1: -138, cx2: 381, cy2: -161, x: 402, y: -161 },
13
+ { op: "C", cx1: 419, cy1: -161, cx2: 435, cy2: -140, x: 435, y: -114 },
14
+ { op: "C", cx1: 435, cy1: -71, cx2: 405, cy2: -50, x: 370, y: -50 },
15
+ { op: "C", cx1: 338, cy1: -50, cx2: 305, cy2: -77, x: 262, y: -125 },
16
+ { op: "C", cx1: 213, cy1: -179, cx2: 169, cy2: -217, x: 104, y: -217 },
17
+ { op: "C", cx1: 38, cy1: -217, cx2: 0, cy2: -167, x: 0, y: -103 },
18
+ { op: "C", cx1: 0, cy1: -31, cx2: 46, cy2: 0, x: 89, y: 0 },
19
+ { op: "C", cx1: 120, cy1: 0, cx2: 145, cy2: -14, x: 145, y: -44 },
20
+ { op: "C", cx1: 145, cy1: -66, cx2: 130, cy2: -80, x: 109, y: -80 },
21
+ { op: "C", cx1: 80, cy1: -80, cx2: 79, cy2: -57, x: 58, y: -57 },
22
+ { op: "C", cx1: 41, cy1: -57, cx2: 25, cy2: -78, x: 25, y: -104 },
23
+ { op: "C", cx1: 25, cy1: -147, cx2: 55, cy2: -168, x: 90, y: -168 },
24
+ { op: "C", cx1: 122, cy1: -168, cx2: 155, cy2: -141, x: 198, y: -93 },
25
+ { op: "C", cx1: 247, cy1: -39, cx2: 291, cy2: -1, x: 356, y: -1 },
26
+ { op: "C", cx1: 422, cy1: -1, cx2: 460, cy2: -51, x: 460, y: -115 },
27
+ { op: "C", cx1: 460, cy1: -187, cx2: 414, cy2: -218, x: 371, y: -218 },
28
+ { op: "Z" },
29
+ ];
30
+ const turnShape = { path: turnPath, style: { fill: "#000" } };
31
+ export const turnSymbol = {
32
+ name: "turn",
33
+ description: "回音",
34
+ weight: 0.55,
35
+ shapes: [turnShape],
36
+ emitPlayback: emitter => emitter.affectFollowing(ornament({ body: [1, 0, -1, 0] })),
37
+ };
38
+ export const iturnSymbol = {
39
+ name: "iturn",
40
+ description: "逆回音",
41
+ weight: 0.55 * 396 / 218,
42
+ shapes: [
43
+ turnShape,
44
+ {
45
+ line: { x1: 230, y1: -290, x2: 230, y2: 74 },
46
+ style: { stroke: "#000", strokeWidth: 32 },
47
+ },
48
+ ],
49
+ emitPlayback: emitter => emitter.affectFollowing(ornament({ body: [-1, 0, 1, 0] })),
50
+ };
@@ -0,0 +1,2 @@
1
+ import type { SymbolDefinition } from "../index.js";
2
+ export declare const wheelSymbol: SymbolDefinition;
@@ -0,0 +1,36 @@
1
+ export const wheelSymbol = {
2
+ name: "wheel",
3
+ description: "轮指",
4
+ shapes: [
5
+ {
6
+ path: [
7
+ { op: "M", x: 8.8, y: 0 },
8
+ { op: "L", x: 11.2, y: 0 },
9
+ { op: "L", x: 11.2, y: 6 },
10
+ { op: "L", x: 8.8, y: 6 },
11
+ { op: "Z" },
12
+ { op: "M", x: 13.43341, y: 7.62266 },
13
+ { op: "L", x: 19.13974, y: 5.76856 },
14
+ { op: "L", x: 19.88139, y: 8.0511 },
15
+ { op: "L", x: 14.17505, y: 9.9052 },
16
+ { op: "Z" },
17
+ { op: "M", x: 11.38032, y: 13.94141 },
18
+ { op: "L", x: 14.90703, y: 18.79551 },
19
+ { op: "L", x: 16.84867, y: 17.38483 },
20
+ { op: "L", x: 13.32196, y: 12.53073 },
21
+ { op: "Z" },
22
+ { op: "M", x: 8.61968, y: 13.94141 },
23
+ { op: "L", x: 5.09297, y: 18.79551 },
24
+ { op: "L", x: 3.15133, y: 17.38483 },
25
+ { op: "L", x: 6.67804, y: 12.53073 },
26
+ { op: "Z" },
27
+ { op: "M", x: 6.56659, y: 7.62266 },
28
+ { op: "L", x: 0.86026, y: 5.76856 },
29
+ { op: "L", x: 0.11861, y: 8.0511 },
30
+ { op: "L", x: 5.82495, y: 9.9052 },
31
+ { op: "Z" },
32
+ ],
33
+ style: { fill: "#000" },
34
+ },
35
+ ],
36
+ };
@@ -97,6 +97,7 @@ export declare class TemporalNodeBase implements TimeLineEvent {
97
97
  * - div.{level}.left / div.{level}.right:从 0 编号的减时线端点,由 div.place 发布,供 beam 接管。
98
98
  * - dot:附点起点;缺省为盒右边界与 visualAxis,音符覆盖为字形附近的位置。
99
99
  * - lyric:歌词对齐点(voice 只读 x);未提供则不作为歌词目标,note 在 finalizeLayout 发布。
100
+ * - bar.number:多声部连谱号顶部的行首小节号锚点。
100
101
  *
101
102
  * up、grace、arpeggio 转发宿主端口并换算局部坐标;端口不表达装饰是否存在。
102
103
  */
@@ -61,6 +61,7 @@ export class TemporalNodeBase {
61
61
  * - div.{level}.left / div.{level}.right:从 0 编号的减时线端点,由 div.place 发布,供 beam 接管。
62
62
  * - dot:附点起点;缺省为盒右边界与 visualAxis,音符覆盖为字形附近的位置。
63
63
  * - lyric:歌词对齐点(voice 只读 x);未提供则不作为歌词目标,note 在 finalizeLayout 发布。
64
+ * - bar.number:多声部连谱号顶部的行首小节号锚点。
64
65
  *
65
66
  * up、grace、arpeggio 转发宿主端口并换算局部坐标;端口不表达装饰是否存在。
66
67
  */
@@ -1,6 +1,6 @@
1
1
  import { ASTFunctionNode } from "../ASTtypes.js";
2
2
  import { ErrorDiagnostic } from "../../diagnostic.js";
3
- import { findClosingQuote, quote, removeQuote } from "../../parser/parse-utils/string-utils.js";
3
+ import { findClosingQuote, quote } from "../../parser/parse-utils/string-utils.js";
4
4
  import { DEFAULT_KEY, TemporalNodeBase } from "../temporal.js";
5
5
  class TextFunction extends ASTFunctionNode {
6
6
  static def = {
@@ -10,7 +10,9 @@ class TextFunction extends ASTFunctionNode {
10
10
  ~~~jpfun
11
11
  @text(进入主题, size=0.8em, align=center)
12
12
  ~~~
13
- **简写**:直接写双引号文本,如 \`"进入主题"\`;可跨行,双引号须配对`,
13
+ **简写**:直接写双引号文本,如 \`"进入主题"\`;可跨行,双引号须配对。
14
+
15
+ 支持 JSON 风格的 Unicode 转义,如 \`\\uE050\`;显示字面反斜杠须写 \`\\\\\`。`,
14
16
  allowExtraArgs: false,
15
17
  args: [
16
18
  {
@@ -54,15 +56,22 @@ class TextFunction extends ASTFunctionNode {
54
56
  if (close < 0)
55
57
  return null; // 未闭合就不去糖,与预处理“配对才算字符串”一致
56
58
  const node = {
57
- kind: "call",
58
- typed: true,
59
- name: "text",
60
- args: new Map([[0, removeQuote(source.slice(start, close + 1))]]),
59
+ kind: "sugar",
60
+ data: TextFunction,
61
61
  span: { start, end: close + 1 },
62
62
  syntaxKind: "string",
63
63
  };
64
64
  return { next: close + 1, node };
65
65
  }
66
+ static deSugarRelation(ctx, nodes, at) {
67
+ const node = nodes[at];
68
+ if (node.data !== TextFunction)
69
+ return null;
70
+ // 之所以不在 deSugarAtom 里直接解码返回 typed call,是因为字符串转义可能产生诊断(如非法 \u 转义):
71
+ // 第一轮 deSugarAtom 没有 ctx(抛异常则会中断词法扫描),放到第二轮才能复用 parseArgWithType 记录警告并回退原文
72
+ ctx.pushNode(new TextFunction(node.span, new Map([[0, ctx.parseArgWithType(node.span, "string")]]), ctx, null));
73
+ return at + 1;
74
+ }
66
75
  lines;
67
76
  size;
68
77
  lineAdvance;
@@ -3,6 +3,28 @@ import { Diagnostic, ErrorDiagnostic } from "../../diagnostic.js";
3
3
  import { isVisualTemporalNode, } from "../temporal.js";
4
4
  import { pathBounds } from "../../layout/path.js";
5
5
  import { getLayoutBounds } from "../../layout/engine.js";
6
+ /** 仅索引被 @tie 引用过的端点,避免为全谱无关音符分配数组与 Map 节点 */
7
+ const tieEndpoints = new WeakSet();
8
+ const notesByOriginNode = new WeakMap();
9
+ function endpointNotes(notes, endpoint) {
10
+ let index = notesByOriginNode.get(notes);
11
+ if (!index) {
12
+ index = new Map();
13
+ for (const note of notes) {
14
+ for (const { node } of note.origins) {
15
+ if (!tieEndpoints.has(node))
16
+ continue;
17
+ const group = index.get(node);
18
+ if (group)
19
+ group.push(note);
20
+ else
21
+ index.set(node, [note]);
22
+ }
23
+ }
24
+ notesByOriginNode.set(notes, index);
25
+ }
26
+ return index.get(endpoint) ?? [];
27
+ }
6
28
  /** 三次贝塞尔控制点的抬高系数:两个控制点同高时,实际弧高恰好是抬高的 3/4 */
7
29
  const CUBIC_LIFT = 4 / 3;
8
30
  /** 弧带中部最大厚度与字号之比 */
@@ -22,7 +44,7 @@ class TieFunction extends ASTFunctionNode {
22
44
  - **位置参数**:端点标签,可传多个,按顺序连接;省略时查找最近的可标记对象,包括增时线
23
45
  - **height**:仅命名的弧线高度参数,默认 \`0\`(自动);非正数按水平跨度自动调整,在 \`2.5em\` 跨度处平滑达到 \`0.5em\` 上限,正数指定固定弧高。em 相对调用处字号;可用 \`@set(tie.height=0.8em)\` 设置局部默认值,显式传参优先
24
46
 
25
- 同行端点用一条弧线连接,自动高度按水平跨度计算;跨行时自动拆成多段,自动模式下各段统一使用 \`0.45em\` 高度。同轨同音且时间连续的音段建立播放连接,各段保留自己的装饰,例如 \`1 ^ $tr 1 @tie()\` 的后一音段不继承颤音。涉及增时线的连接仅绘制,不合并播放音符。`,
47
+ 同行端点用一条弧线连接,自动高度按水平跨度计算;跨行时自动拆成多段,自动模式下各段统一使用 \`0.45em\` 高度。同轨同音且时间连续的音段建立播放连接:未另加修饰的后继音段并入前段共同展开(如 \`1 ^ $tr 1 @tie()\` 全程颤音),带独立修饰的后继音段从自身起点生效(如 \`1 1 ^ $tr @tie()\` 从第二拍开始颤音)。涉及增时线的连接仅绘制,不合并播放音符。`,
26
48
  allowExtraArgs: true,
27
49
  extraArgType: "label",
28
50
  args: [{
@@ -57,8 +79,9 @@ class TieFunction extends ASTFunctionNode {
57
79
  continue;
58
80
  this.endPoints.unshift(candidate);
59
81
  }
60
- if (this.endPoints.length < 2)
61
- throw new ErrorDiagnostic("E_NOT_ENOUGH_ARGS", "@tie 连音线需要至少两个端点", sourceSpan);
82
+ if (this.endPoints.length < 2) {
83
+ throw new ErrorDiagnostic("E_NOT_ENOUGH_ARGS", "@{fn} 连音线需要至少两个端点", sourceSpan, { fn: "tie" });
84
+ }
62
85
  this.height = Math.max(0, ctx.length2px(height));
63
86
  this.fontSize = ctx.variables.fontsize;
64
87
  }
@@ -99,6 +122,8 @@ class TieLayoutAttachment {
99
122
  thickness;
100
123
  constructor(endPoints, height, fontSize, sourceSpan) {
101
124
  this.endPoints = endPoints;
125
+ for (const endpoint of endPoints)
126
+ tieEndpoints.add(endpoint);
102
127
  this.height = height;
103
128
  this.fontSize = fontSize;
104
129
  this.sourceSpan = sourceSpan;
@@ -111,13 +136,12 @@ class TieLayoutAttachment {
111
136
  */
112
137
  applyPlayback(context) {
113
138
  // 整体端点可能包含和弦多个成员或多遍访问,每个首段分别寻找自己的连接链。
114
- for (const head of context.notes.filter(note => note.origins.some(origin => origin.node === this.endPoints[0]))) {
139
+ for (const head of endpointNotes(context.notes, this.endPoints[0])) {
115
140
  let previous = head;
116
141
  // 按显式端点顺序延续;某一端点没有相接音段就停止,不能跨过缺口连接。
117
142
  for (let index = 1; index < this.endPoints.length; index++) {
118
143
  // connect 同时认领候选:配对冲突时继续找其他成员,重复声明可复用原配对。
119
- const next = context.notes.find(note => note !== previous
120
- && note.origins.some(origin => origin.node === this.endPoints[index])
144
+ const next = endpointNotes(context.notes, this.endPoints[index]).find(note => note !== previous
121
145
  && note.track === previous.track
122
146
  && note.midi === previous.midi
123
147
  && note.percussion === previous.percussion
@@ -0,0 +1,2 @@
1
+ import { type ASTFunctionClass } from "../ASTtypes.js";
2
+ export declare const TremoloNode: ASTFunctionClass;