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.
Files changed (152) 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 +19 -56
  6. package/dist/converter/musicxml/features.d.ts +16 -8
  7. package/dist/converter/musicxml/features.js +88 -19
  8. package/dist/converter/musicxml/index.js +88 -50
  9. package/dist/converter/musicxml/model.d.ts +9 -0
  10. package/dist/converter/source.d.ts +4 -7
  11. package/dist/converter/source.js +11 -9
  12. package/dist/core.d.ts +1 -0
  13. package/dist/core.js +1 -0
  14. package/dist/diagnostic.d.ts +7 -1
  15. package/dist/diagnostic.js +40 -88
  16. package/dist/fraction.js +3 -2
  17. package/dist/functions/ASTtypes.d.ts +3 -32
  18. package/dist/functions/ASTtypes.js +5 -52
  19. package/dist/functions/adjust/index.js +45 -33
  20. package/dist/functions/arpeggio/index.js +50 -55
  21. package/dist/functions/arpeggio/shape.d.ts +2 -3
  22. package/dist/functions/arpeggio/shape.js +20 -50
  23. package/dist/functions/bar/index.d.ts +8 -0
  24. package/dist/functions/bar/index.js +105 -8
  25. package/dist/functions/beam/auto.d.ts +1 -2
  26. package/dist/functions/beam/auto.js +80 -135
  27. package/dist/functions/beam/index.js +6 -12
  28. package/dist/functions/beam/layout.d.ts +1 -1
  29. package/dist/functions/beam/layout.js +1 -1
  30. package/dist/functions/box/index.js +0 -6
  31. package/dist/functions/br/index.d.ts +34 -2
  32. package/dist/functions/br/index.js +5 -4
  33. package/dist/functions/dash/index.js +9 -10
  34. package/dist/functions/default.js +2 -1
  35. package/dist/functions/div/index.d.ts +3 -4
  36. package/dist/functions/div/index.js +18 -14
  37. package/dist/functions/dot/index.js +5 -11
  38. package/dist/functions/dyn/index.js +55 -57
  39. package/dist/functions/gliss/index.js +131 -103
  40. package/dist/functions/grace/index.d.ts +3 -12
  41. package/dist/functions/grace/index.js +52 -102
  42. package/dist/functions/head/index.js +10 -7
  43. package/dist/functions/key/index.js +13 -15
  44. package/dist/functions/meter/index.d.ts +56 -1
  45. package/dist/functions/meter/index.js +15 -10
  46. package/dist/functions/note/index.js +6 -6
  47. package/dist/functions/note/noteName.d.ts +16 -0
  48. package/dist/functions/note/noteName.js +88 -0
  49. package/dist/functions/note/source-transform.js +8 -10
  50. package/dist/functions/ottava/index.js +35 -40
  51. package/dist/functions/page/index.d.ts +1 -0
  52. package/dist/functions/page/index.js +27 -21
  53. package/dist/functions/pagebreak/index.js +2 -2
  54. package/dist/functions/rest/index.js +5 -5
  55. package/dist/functions/set/index.js +4 -4
  56. package/dist/functions/slide/index.js +0 -1
  57. package/dist/functions/stack/index.js +8 -57
  58. package/dist/functions/symbol/index.d.ts +21 -2
  59. package/dist/functions/symbol/index.js +69 -24
  60. package/dist/functions/symbol/ornament.d.ts +1 -2
  61. package/dist/functions/symbol/shape.d.ts +6 -0
  62. package/dist/functions/symbol/shape.js +16 -3
  63. package/dist/functions/symbol/symbols/coda.d.ts +4 -0
  64. package/dist/functions/symbol/symbols/coda.js +56 -0
  65. package/dist/functions/symbol/symbols/dynamics.d.ts +1 -1
  66. package/dist/functions/symbol/symbols/dynamics.js +18 -8
  67. package/dist/functions/symbol/symbols/harmonic.d.ts +2 -0
  68. package/dist/functions/symbol/symbols/harmonic.js +11 -0
  69. package/dist/functions/symbol/symbols/marcato.d.ts +2 -0
  70. package/dist/functions/symbol/symbols/marcato.js +22 -0
  71. package/dist/functions/symbol/symbols/staccato.d.ts +2 -0
  72. package/dist/functions/symbol/symbols/staccato.js +24 -0
  73. package/dist/functions/symbol/symbols/tenuto.d.ts +2 -0
  74. package/dist/functions/symbol/symbols/tenuto.js +11 -0
  75. package/dist/functions/symbol/symbols/tocoda.d.ts +2 -0
  76. package/dist/functions/symbol/symbols/tocoda.js +16 -0
  77. package/dist/functions/symbol/symbols/turn.d.ts +3 -0
  78. package/dist/functions/symbol/symbols/turn.js +50 -0
  79. package/dist/functions/symbol/symbols/wheel.d.ts +2 -0
  80. package/dist/functions/symbol/symbols/wheel.js +36 -0
  81. package/dist/functions/temporal.d.ts +3 -2
  82. package/dist/functions/temporal.js +8 -0
  83. package/dist/functions/text/index.js +38 -35
  84. package/dist/functions/tie/index.js +44 -43
  85. package/dist/functions/tremolo/index.d.ts +2 -0
  86. package/dist/functions/tremolo/index.js +318 -0
  87. package/dist/functions/tuplet/index.js +4 -14
  88. package/dist/functions/up/index.js +81 -85
  89. package/dist/functions/voice/connections.d.ts +2 -1
  90. package/dist/functions/voice/connections.js +48 -10
  91. package/dist/functions/voice/index.d.ts +2 -3
  92. package/dist/functions/voice/index.js +2 -963
  93. package/dist/functions/voice/lyrics.d.ts +30 -0
  94. package/dist/functions/voice/lyrics.js +289 -0
  95. package/dist/functions/voice/voice.d.ts +63 -0
  96. package/dist/functions/voice/voice.js +373 -0
  97. package/dist/functions/voice/voices.d.ts +106 -0
  98. package/dist/functions/voice/voices.js +423 -0
  99. package/dist/functions/volta/index.js +5 -23
  100. package/dist/jpfun.core.min.js +76 -59
  101. package/dist/jpfun.from-midi.min.js +5 -5
  102. package/dist/jpfun.from-musicxml.min.js +8 -8
  103. package/dist/jpfun.min.js +81 -64
  104. package/dist/layout/default.d.ts +0 -1
  105. package/dist/layout/default.js +0 -1
  106. package/dist/layout/engine.js +30 -18
  107. package/dist/layout/model.d.ts +0 -1
  108. package/dist/layout/model.js +1 -4
  109. package/dist/layout/page.d.ts +2 -1
  110. package/dist/layout/page.js +14 -14
  111. package/dist/layout/range.d.ts +7 -6
  112. package/dist/layout/range.js +23 -14
  113. package/dist/layout/types.d.ts +9 -28
  114. package/dist/lowering/loweringContext.d.ts +18 -23
  115. package/dist/lowering/loweringContext.js +33 -46
  116. package/dist/lowering/track.d.ts +8 -1
  117. package/dist/lowering/types.d.ts +13 -11
  118. package/dist/parser/parse-utils/call-utils.d.ts +1 -2
  119. package/dist/parser/parse-utils/call-utils.js +6 -34
  120. package/dist/parser/parse-utils/note-utils.d.ts +3 -3
  121. package/dist/parser/parse-utils/note-utils.js +21 -33
  122. package/dist/parser/parse-utils/string-utils.d.ts +3 -2
  123. package/dist/parser/parse-utils/string-utils.js +20 -5
  124. package/dist/parser/parserContext.d.ts +9 -9
  125. package/dist/parser/parserContext.js +62 -11
  126. package/dist/pipeline.js +2 -3
  127. package/dist/playback/compile.js +131 -82
  128. package/dist/playback/event.d.ts +6 -6
  129. package/dist/playback/event.js +13 -49
  130. package/dist/playback/time.js +42 -31
  131. package/dist/playback/types.d.ts +3 -1
  132. package/dist/render/canvas.js +4 -22
  133. package/dist/render/recording.js +1 -4
  134. package/dist/render/svg.d.ts +0 -1
  135. package/dist/render/svg.js +33 -31
  136. package/dist/render/text.d.ts +36 -1
  137. package/dist/render/text.js +134 -0
  138. package/dist/render/translate.d.ts +0 -1
  139. package/dist/render/translate.js +6 -23
  140. package/dist/render/types.d.ts +0 -2
  141. package/grammar.md +39 -30
  142. package/package.json +3 -3
  143. package/dist/functions/note/noteNameFSM.d.ts +0 -8
  144. package/dist/functions/note/noteNameFSM.js +0 -181
  145. package/dist/iife/core.d.ts +0 -1
  146. package/dist/iife/core.js +0 -3
  147. package/dist/iife/from-midi.d.ts +0 -1
  148. package/dist/iife/from-midi.js +0 -15
  149. package/dist/iife/from-musicxml.d.ts +0 -1
  150. package/dist/iife/from-musicxml.js +0 -3
  151. package/dist/iife/full.d.ts +0 -1
  152. package/dist/iife/full.js +0 -3
@@ -1,51 +1,95 @@
1
1
  import { ErrorDiagnostic, WarningDiagnostic } from "../../diagnostic.js";
2
2
  import { DEFAULT_KEY, TemporalNodeBase } from "../temporal.js";
3
3
  import { ASTFunctionNode, } from "../ASTtypes.js";
4
+ import { ornament } from "./ornament.js";
4
5
  import { paintSymbol, symbolBounds } from "./shape.js";
5
6
  import { accentSymbol } from "./symbols/accent.js";
7
+ import { codaSymbol } from "./symbols/coda.js";
6
8
  import { dcSymbol } from "./symbols/dc.js";
7
9
  import { dsSymbol } from "./symbols/ds.js";
8
10
  import { dynamicSymbols } from "./symbols/dynamics.js";
9
11
  import { fermataSymbol } from "./symbols/fermata.js";
10
12
  import { fineSymbol } from "./symbols/fine.js";
13
+ import { harmonicSymbol } from "./symbols/harmonic.js";
14
+ import { marcatoSymbol } from "./symbols/marcato.js";
11
15
  import { mordentSymbol } from "./symbols/mordent.js";
12
16
  import { prallSymbol } from "./symbols/prall.js";
13
17
  import { segnoSymbol } from "./symbols/segno.js";
18
+ import { staccatoSymbol } from "./symbols/staccato.js";
19
+ import { tenutoSymbol } from "./symbols/tenuto.js";
20
+ import { tocodaSymbol } from "./symbols/tocoda.js";
14
21
  import { trSymbol } from "./symbols/tr.js";
22
+ import { iturnSymbol, turnSymbol } from "./symbols/turn.js";
23
+ import { wheelSymbol } from "./symbols/wheel.js";
15
24
  const symbolTable = new Map();
16
- const symbolPatterns = [];
17
- for (const definition of [trSymbol, fermataSymbol, prallSymbol, mordentSymbol, accentSymbol,
18
- ...dynamicSymbols, dcSymbol, dsSymbol, segnoSymbol, fineSymbol]) {
19
- const name = definition.name.toLowerCase();
20
- if (symbolTable.has(name))
21
- throw new Error(`Duplicate symbol name: ${definition.name}`);
22
- symbolTable.set(name, definition);
23
- const pattern = definition.pattern;
24
- if (!pattern)
25
- continue;
26
- const { regex } = pattern;
27
- if (regex.global || regex.sticky)
28
- throw new Error(`Symbol pattern must not use g or y flags: ${name}`);
29
- symbolPatterns.push(regex.ignoreCase ? pattern
30
- : { ...pattern, regex: new RegExp(regex.source, `${regex.flags}i`) });
31
- }
25
+ const symbolPatterns = new Map();
26
+ export const symbols = Object.freeze({
27
+ /** 内置符号的只读备份列表 */
28
+ core: Object.freeze([
29
+ trSymbol, fermataSymbol, prallSymbol, mordentSymbol, accentSymbol, wheelSymbol, harmonicSymbol,
30
+ tenutoSymbol, marcatoSymbol, staccatoSymbol, turnSymbol, iturnSymbol,
31
+ ...dynamicSymbols, dcSymbol, dsSymbol, segnoSymbol, fineSymbol, codaSymbol, tocodaSymbol,
32
+ ]),
33
+ /** 当前注册表的只读视图 */
34
+ table: symbolTable,
35
+ /** 注册或同名覆盖一个或多个符号定义 */
36
+ register: (...definitions) => {
37
+ const entries = definitions.map(definition => {
38
+ const name = definition.name.toLowerCase();
39
+ let pattern = definition.pattern;
40
+ if (pattern) {
41
+ const { regex } = pattern;
42
+ if (regex.global || regex.sticky) {
43
+ throw new Error(`Symbol pattern must not use g or y flags: ${name}`);
44
+ }
45
+ if (!regex.ignoreCase)
46
+ pattern = { ...pattern, regex: new RegExp(regex.source, `${regex.flags}i`) };
47
+ }
48
+ return { name, definition, pattern };
49
+ });
50
+ for (const { name, definition, pattern } of entries) {
51
+ symbolTable.set(name, definition);
52
+ if (pattern)
53
+ symbolPatterns.set(name, pattern);
54
+ else
55
+ symbolPatterns.delete(name);
56
+ }
57
+ },
58
+ /** 清空所有已注册符号(含内置符号) */
59
+ clear: () => {
60
+ symbolTable.clear();
61
+ symbolPatterns.clear();
62
+ },
63
+ /** 清空并恢复到最初的 symbols.core 状态 */
64
+ reset: () => {
65
+ symbols.clear();
66
+ symbols.register(...symbols.core);
67
+ },
68
+ /** 装饰音播放展开工具 */
69
+ ornament,
70
+ /** 计算符号图元在自身坐标系中的固有包围盒 */
71
+ bounds: symbolBounds,
72
+ });
73
+ symbols.reset();
32
74
  class SymbolFunction extends ASTFunctionNode {
33
75
  static def = {
34
76
  name: ["symbol", "$"],
35
77
  description: "创建一个乐谱符号",
36
- details: `\
78
+ get details() {
79
+ return `\
37
80
  ~~~jpfun
38
81
  1 ^ @symbol(p, size=0.5em)
39
82
  ~~~
40
83
  **简写**:\`$name\`,如 \`1 ^ $p\`。名称读取到下一个空白或当前内容区间末尾,连续的标点也属于名称。
41
84
 
42
- **内置记号**
43
- ${[...symbolTable.values()].map(item => `- \`$${item.name}\`:${item.description}`).join("\n")}`,
85
+ **已注册记号**
86
+ ${[...symbolTable.values()].map(item => `- \`$${item.name}\`:${item.description}`).join("\n")}`;
87
+ },
44
88
  allowExtraArgs: false,
45
89
  args: [
46
90
  {
47
91
  name: "name",
48
- description: "内置记号名称,见函数说明中的记号列表",
92
+ description: "已注册记号名称,见函数说明中的记号列表",
49
93
  type: "string",
50
94
  default: null
51
95
  },
@@ -84,7 +128,7 @@ ${[...symbolTable.values()].map(item => `- \`$${item.name}\`:${item.descriptio
84
128
  let definition = symbolTable.get(normalized);
85
129
  if (!definition) {
86
130
  let matched;
87
- for (const pattern of symbolPatterns) {
131
+ for (const pattern of symbolPatterns.values()) {
88
132
  const match = pattern.regex.exec(normalized);
89
133
  if (!match || match.index !== 0 || match[0] !== normalized)
90
134
  continue;
@@ -95,10 +139,11 @@ ${[...symbolTable.values()].map(item => `- \`$${item.name}\`:${item.descriptio
95
139
  definition = matched?.pattern.resolve(matched.match);
96
140
  }
97
141
  if (!definition) {
98
- const message = `@symbol: 未知符号: $${name}`;
142
+ const message = "@symbol: 未知符号: ${name}";
143
+ const params = { name };
99
144
  if (ctx.variables.strict)
100
- throw new ErrorDiagnostic("E_UNKNOWN_SYMBOL", message, sourceSpan);
101
- ctx.diagnostics.push(new WarningDiagnostic("W_UNKNOWN_SYMBOL", message, sourceSpan));
145
+ throw new ErrorDiagnostic("E_UNKNOWN_SYMBOL", message, sourceSpan, params);
146
+ ctx.diagnostics.push(new WarningDiagnostic("W_UNKNOWN_SYMBOL", message, sourceSpan, params));
102
147
  return;
103
148
  }
104
149
  this.definition = definition;
@@ -1,5 +1,5 @@
1
1
  import type { PlaybackTransform } from "../../playback/types.js";
2
- interface OrnamentPattern {
2
+ export interface OrnamentPattern {
3
3
  /** 调内音级偏移序列,0 表示本音 */
4
4
  readonly body: readonly number[];
5
5
  /** 主体是否重复到填满宿主时值 */
@@ -12,4 +12,3 @@ interface OrnamentPattern {
12
12
  * 派生音段继承轨道和来源,仍只声明音段,不直接发布 NoteOn/NoteOff。
13
13
  */
14
14
  export declare function ornament(pattern: OrnamentPattern): PlaybackTransform;
15
- export {};
@@ -10,6 +10,12 @@ import type { PaintStyle, Painter, PathCommand } from "../../render/types.js";
10
10
  /** 符号的一个图元;坐标在符号自身坐标系里,缩放由布局决定 */
11
11
  export interface SymbolShape {
12
12
  readonly path?: readonly PathCommand[];
13
+ readonly line?: {
14
+ readonly x1: number;
15
+ readonly y1: number;
16
+ readonly x2: number;
17
+ readonly y2: number;
18
+ };
13
19
  readonly circle?: {
14
20
  readonly cx: number;
15
21
  readonly cy: number;
@@ -22,9 +22,17 @@ export function symbolBounds(shapes) {
22
22
  };
23
23
  for (const shape of shapes) {
24
24
  const dx = shape.dx ?? 0;
25
+ if (shape.line) {
26
+ const { x1, y1, x2, y2 } = shape.line;
27
+ const halfStroke = (shape.style.strokeWidth ?? 1) / 2;
28
+ merge(Math.min(x1, x2) + dx - halfStroke, Math.min(y1, y2) - halfStroke, Math.abs(x2 - x1) + halfStroke * 2, Math.abs(y2 - y1) + halfStroke * 2);
29
+ }
25
30
  if (shape.circle) {
26
31
  const { cx, cy, r } = shape.circle;
27
- merge(cx + dx - r, cy - r, 2 * r, 2 * r);
32
+ const stroke = shape.style.stroke && shape.style.stroke !== "none"
33
+ ? (shape.style.strokeWidth ?? 1) / 2 : 0;
34
+ const outer = r + stroke;
35
+ merge(cx + dx - outer, cy - outer, 2 * outer, 2 * outer);
28
36
  }
29
37
  if (shape.path?.length) {
30
38
  const rect = pathBoundsCache.get(shape.path) ?? pathBounds(shape.path);
@@ -41,10 +49,15 @@ export function paintSymbol(painter, shapes, bounds, box, scale) {
41
49
  const originY = box.y - bounds.y * scale;
42
50
  for (const shape of shapes) {
43
51
  const style = shape.style;
44
- const scaled = style.strokeWidth === undefined
52
+ const strokeWidth = style.strokeWidth ?? (shape.line || shape.circle ? 1 : undefined);
53
+ const scaled = strokeWidth === undefined
45
54
  ? style
46
- : { ...style, strokeWidth: style.strokeWidth * scale };
55
+ : { ...style, strokeWidth: strokeWidth * scale };
47
56
  const x = originX + (shape.dx ?? 0) * scale;
57
+ if (shape.line) {
58
+ const { x1, y1, x2, y2 } = shape.line;
59
+ painter.drawLine(x + x1 * scale, originY + y1 * scale, x + x2 * scale, originY + y2 * scale, scaled);
60
+ }
48
61
  if (shape.path) {
49
62
  painter.drawPath(shape.path, scaled, { x, y: originY, scaleX: scale, scaleY: scale });
50
63
  }
@@ -0,0 +1,4 @@
1
+ import type { SymbolDefinition } from "../index.js";
2
+ /** $tocoda 的跳转目标 */
3
+ export declare const CODA_MARK = "repeat.coda";
4
+ export declare const codaSymbol: SymbolDefinition;
@@ -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
+ };
@@ -23,8 +23,6 @@ export interface TimeState {
23
23
  program: number;
24
24
  /** 当前小节时长(QN);尚无显式拍号或散板时为 undefined */
25
25
  meter?: Fraction;
26
- /** 当前执行的全局事件;复合体内部回调共用该位置 */
27
- currentEvent?: TemporalNodeBase;
28
26
  [key: string]: any;
29
27
  }
30
28
  export declare const DEFAULT_BPM = 120;
@@ -75,6 +73,8 @@ export declare class TemporalNodeBase implements TimeLineEvent {
75
73
  * 按全局事件工作的消费者可以沿链上溯到宿主。
76
74
  */
77
75
  foldedInto?: TemporalNodeBase;
76
+ /** 沿 foldedInto 上溯到最外层宿主(未折叠时返回自身) */
77
+ get rootHost(): TemporalNodeBase;
78
78
  /** 由 LoweringContext 在列归并后固化的谱面行号 */
79
79
  layoutLine: number;
80
80
  /** 不可见状态事件保持 undefined */
@@ -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
  */
@@ -41,6 +41,13 @@ export class TemporalNodeBase {
41
41
  * 按全局事件工作的消费者可以沿链上溯到宿主。
42
42
  */
43
43
  foldedInto;
44
+ /** 沿 foldedInto 上溯到最外层宿主(未折叠时返回自身) */
45
+ get rootHost() {
46
+ let host = this;
47
+ while (host.foldedInto)
48
+ host = host.foldedInto;
49
+ return host;
50
+ }
44
51
  /** 由 LoweringContext 在列归并后固化的谱面行号 */
45
52
  layoutLine = 0;
46
53
  /** 不可见状态事件保持 undefined */
@@ -61,6 +68,7 @@ export class TemporalNodeBase {
61
68
  * - div.{level}.left / div.{level}.right:从 0 编号的减时线端点,由 div.place 发布,供 beam 接管。
62
69
  * - dot:附点起点;缺省为盒右边界与 visualAxis,音符覆盖为字形附近的位置。
63
70
  * - lyric:歌词对齐点(voice 只读 x);未提供则不作为歌词目标,note 在 finalizeLayout 发布。
71
+ * - bar.number:多声部连谱号顶部的行首小节号锚点。
64
72
  *
65
73
  * up、grace、arpeggio 转发宿主端口并换算局部坐标;端口不表达装饰是否存在。
66
74
  */