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
@@ -24,11 +24,6 @@ function tracePath(context, commands, x = 0, y = 0, scaleX = 1, scaleY = 1) {
24
24
  context.bezierCurveTo(x + command.cx1 * scaleX, y + command.cy1 * scaleY, x + command.cx2 * scaleX, y + command.cy2 * scaleY, x + command.x * scaleX, y + command.y * scaleY);
25
25
  }
26
26
  }
27
- function applyOpacity(context, style) {
28
- if (style?.opacity === void 0)
29
- return;
30
- context.globalAlpha *= style.opacity;
31
- }
32
27
  /**
33
28
  * CanvasRenderingContext2D 的 Painter 适配器
34
29
  *
@@ -41,18 +36,13 @@ export class CanvasPainter {
41
36
  this.context = context;
42
37
  }
43
38
  drawText(text, x, y, style) {
44
- this.context.save();
45
- applyOpacity(this.context, style);
46
39
  this.context.fillStyle = style.fill ?? "#000";
47
40
  this.context.font = canvasFont(style);
48
41
  this.context.textAlign = style.textAlign ?? "left";
49
42
  this.context.textBaseline = "alphabetic";
50
43
  this.context.fillText(text, x, y);
51
- this.context.restore();
52
44
  }
53
45
  drawLine(x1, y1, x2, y2, style) {
54
- this.context.save();
55
- applyOpacity(this.context, style);
56
46
  this.context.beginPath();
57
47
  this.context.moveTo(x1, y1);
58
48
  this.context.lineTo(x2, y2);
@@ -60,13 +50,10 @@ export class CanvasPainter {
60
50
  this.context.lineWidth = style?.strokeWidth ?? 1;
61
51
  this.context.lineCap = "round";
62
52
  this.context.stroke();
63
- this.context.restore();
64
53
  }
65
54
  drawRect(x, y, w, h, style) {
66
55
  if (w < 0 || h < 0)
67
56
  return;
68
- this.context.save();
69
- applyOpacity(this.context, style);
70
57
  if (style?.fill) {
71
58
  this.context.fillStyle = style.fill;
72
59
  this.context.fillRect(x, y, w, h);
@@ -74,19 +61,18 @@ export class CanvasPainter {
74
61
  if (style?.stroke) {
75
62
  this.context.strokeStyle = style.stroke;
76
63
  this.context.lineWidth = style.strokeWidth ?? 1;
64
+ this.context.lineJoin = "miter";
77
65
  this.context.strokeRect(x, y, w, h);
78
66
  }
79
- this.context.restore();
80
67
  }
81
68
  drawCircle(cx, cy, r, style) {
82
69
  if (r < 0)
83
70
  return;
84
- this.context.save();
85
- applyOpacity(this.context, style);
86
71
  this.context.beginPath();
87
72
  this.context.arc(cx, cy, r, 0, Math.PI * 2);
88
- if (style?.fill ?? true) {
89
- this.context.fillStyle = style?.fill ?? "#000";
73
+ const fill = style?.fill ?? "#000";
74
+ if (fill && fill !== "none") {
75
+ this.context.fillStyle = fill;
90
76
  this.context.fill();
91
77
  }
92
78
  if (style?.stroke) {
@@ -94,13 +80,10 @@ export class CanvasPainter {
94
80
  this.context.lineWidth = style.strokeWidth ?? 1;
95
81
  this.context.stroke();
96
82
  }
97
- this.context.restore();
98
83
  }
99
84
  drawPath(commands, style, transform) {
100
85
  if (commands.length === 0)
101
86
  return;
102
- this.context.save();
103
- applyOpacity(this.context, style);
104
87
  tracePath(this.context, commands, transform?.x, transform?.y, transform?.scaleX, transform?.scaleY);
105
88
  if (style?.fill) {
106
89
  this.context.fillStyle = style.fill;
@@ -113,7 +96,6 @@ export class CanvasPainter {
113
96
  this.context.lineJoin = "round";
114
97
  this.context.stroke();
115
98
  }
116
- this.context.restore();
117
99
  }
118
100
  }
119
101
  /** 使用 Canvas 后端把一个布局结果一次绘制到独立页面 context */
@@ -70,9 +70,6 @@ function transformPathCommand(command, transform) {
70
70
  return { ...command };
71
71
  const x = (value) => transform.x + value * transform.scaleX;
72
72
  const y = (value) => transform.y + value * transform.scaleY;
73
- if (command.op === "M" || command.op === "L") {
74
- return { op: command.op, x: x(command.x), y: y(command.y) };
75
- }
76
73
  if (command.op === "Q") {
77
74
  return {
78
75
  op: "Q",
@@ -93,5 +90,5 @@ function transformPathCommand(command, transform) {
93
90
  y: y(command.y),
94
91
  };
95
92
  }
96
- return { ...command };
93
+ return { op: command.op, x: x(command.x), y: y(command.y) };
97
94
  }
@@ -1,7 +1,6 @@
1
1
  import type { DocumentLayoutResult } from "../layout/engine.js";
2
2
  import type { PaintStyle, Painter, PathCommand, PathTransform, TextStyle } from "./types.js";
3
3
  export interface SvgRenderOptions {
4
- padding?: number;
5
4
  background?: string;
6
5
  }
7
6
  /** 生成独立 SVG 字符串的 Painter;路径直接输出最终坐标 */
@@ -1,5 +1,5 @@
1
1
  import { layoutPageBounds, paintLayoutPages } from "./paint.js";
2
- import { DEFAULT_TEXT_FONT } from "./text.js";
2
+ import { DEFAULT_TEXT_FONT, JIANPU_NUMBER_FONT } from "./text.js";
3
3
  function number(value) {
4
4
  if (!Number.isFinite(value))
5
5
  return "0";
@@ -10,9 +10,9 @@ function escapeXml(value) {
10
10
  .replace(/&/g, "&amp;")
11
11
  .replace(/</g, "&lt;")
12
12
  .replace(/>/g, "&gt;")
13
- .replace(/"/g, "&quot;")
14
- .replace(/'/g, "&apos;");
13
+ .replace(/"/g, "&quot;");
15
14
  }
15
+ const DEFAULT_SVG_FONT_ATTR = escapeXml(JIANPU_NUMBER_FONT);
16
16
  /**
17
17
  * 把结构化路径命令转换为 SVG path data
18
18
  * 可选缩放和平移用于直接生成最终坐标
@@ -47,11 +47,6 @@ function pathCommandsToSvg(commands, transform) {
47
47
  }
48
48
  return parts.join(" ");
49
49
  }
50
- function opacityAttribute(style) {
51
- if (style?.opacity === void 0)
52
- return "";
53
- return ` opacity="${number(style.opacity)}"`;
54
- }
55
50
  /** 生成独立 SVG 字符串的 Painter;路径直接输出最终坐标 */
56
51
  export class SvgPainter {
57
52
  body = [];
@@ -62,38 +57,42 @@ export class SvgPainter {
62
57
  const textAnchor = style.textAlign === "center"
63
58
  ? "middle"
64
59
  : style.textAlign === "right" ? "end" : "start";
65
- this.body.push(`<text x="${number(x)}" y="${number(y)}" `
66
- + `font-family="${escapeXml(family)}" font-size="${number(style.fontSize)}" `
67
- + `font-weight="${escapeXml(String(weight))}" text-anchor="${textAnchor}" `
68
- + (style.fontStyle ? `font-style="${escapeXml(style.fontStyle)}" ` : "")
69
- + `fill="${escapeXml(fill)}" xml:space="preserve"`
70
- + `${opacityAttribute(style)}>${escapeXml(text)}</text>`);
60
+ this.body.push(`<text x="${number(x)}" y="${number(y)}"`
61
+ + (family !== JIANPU_NUMBER_FONT ? ` font-family="${escapeXml(family)}"` : "")
62
+ + ` font-size="${number(style.fontSize)}"`
63
+ + (weight !== "normal" ? ` font-weight="${escapeXml(String(weight))}"` : "")
64
+ + (textAnchor !== "start" ? ` text-anchor="${textAnchor}"` : "")
65
+ + (style.fontStyle && style.fontStyle !== "normal" ? ` font-style="${escapeXml(style.fontStyle)}"` : "")
66
+ + (fill !== "#000" ? ` fill="${escapeXml(fill)}"` : "")
67
+ + (/\s/.test(text) ? ` xml:space="preserve"` : "")
68
+ + `>${escapeXml(text)}</text>`);
71
69
  }
72
70
  drawLine(x1, y1, x2, y2, style) {
73
71
  const stroke = style?.stroke ?? style?.fill ?? "#000";
74
72
  const strokeWidth = style?.strokeWidth ?? 1;
75
73
  this.body.push(`<line x1="${number(x1)}" y1="${number(y1)}" `
76
74
  + `x2="${number(x2)}" y2="${number(y2)}" `
77
- + `stroke="${escapeXml(stroke)}" stroke-width="${number(strokeWidth)}" stroke-linecap="round"`
78
- + `${opacityAttribute(style)} />`);
75
+ + `stroke="${escapeXml(stroke)}" stroke-width="${number(strokeWidth)}" stroke-linecap="round" />`);
79
76
  }
80
77
  drawRect(x, y, w, h, style) {
81
78
  const fill = style?.fill ?? "none";
82
79
  const stroke = style?.stroke ?? "none";
83
80
  const strokeWidth = style?.strokeWidth ?? 1;
84
81
  this.body.push(`<rect x="${number(x)}" y="${number(y)}" `
85
- + `width="${number(Math.max(0, w))}" height="${number(Math.max(0, h))}" `
86
- + `fill="${escapeXml(fill)}" stroke="${escapeXml(stroke)}" stroke-width="${number(strokeWidth)}"`
87
- + `${opacityAttribute(style)} />`);
82
+ + `width="${number(Math.max(0, w))}" height="${number(Math.max(0, h))}"`
83
+ + (fill !== "#000" ? ` fill="${escapeXml(fill)}"` : "")
84
+ + (stroke !== "none" ? ` stroke="${escapeXml(stroke)}" stroke-width="${number(strokeWidth)}"` : "")
85
+ + ` />`);
88
86
  }
89
87
  drawCircle(cx, cy, r, style) {
90
88
  const fill = style?.fill ?? "#000";
91
89
  const stroke = style?.stroke ?? "none";
92
90
  const strokeWidth = style?.strokeWidth ?? 1;
93
91
  this.body.push(`<circle cx="${number(cx)}" cy="${number(cy)}" `
94
- + `r="${number(Math.max(0, r))}" fill="${escapeXml(fill)}" `
95
- + `stroke="${escapeXml(stroke)}" stroke-width="${number(strokeWidth)}"`
96
- + `${opacityAttribute(style)} />`);
92
+ + `r="${number(Math.max(0, r))}"`
93
+ + (fill !== "#000" ? ` fill="${escapeXml(fill)}"` : "")
94
+ + (stroke !== "none" ? ` stroke="${escapeXml(stroke)}" stroke-width="${number(strokeWidth)}"` : "")
95
+ + ` />`);
97
96
  }
98
97
  drawPath(commands, style, transform) {
99
98
  if (commands.length === 0)
@@ -102,21 +101,24 @@ export class SvgPainter {
102
101
  const fill = style?.fill ?? "none";
103
102
  const stroke = style?.stroke ?? "none";
104
103
  const strokeWidth = style?.strokeWidth ?? 1;
105
- this.body.push(`<path d="${d}" fill="${escapeXml(fill)}" stroke="${escapeXml(stroke)}" `
106
- + `stroke-width="${number(strokeWidth)}" stroke-linecap="round" stroke-linejoin="round"`
107
- + `${opacityAttribute(style)} />`);
104
+ this.body.push(`<path d="${d}"`
105
+ + (fill !== "#000" ? ` fill="${escapeXml(fill)}"` : "")
106
+ + (stroke !== "none"
107
+ ? ` stroke="${escapeXml(stroke)}" stroke-width="${number(strokeWidth)}" stroke-linecap="round" stroke-linejoin="round"`
108
+ : "")
109
+ + ` />`);
108
110
  }
109
111
  toSvg(bounds, options = {}) {
110
- const padding = Math.max(0, options.padding ?? 0);
111
- const left = bounds.x - padding;
112
- const top = bounds.y - padding;
113
- const width = Math.max(1, bounds.w + padding * 2);
114
- const height = Math.max(1, bounds.h + padding * 2);
112
+ const left = bounds.x;
113
+ const top = bounds.y;
114
+ const width = Math.max(1, bounds.w);
115
+ const height = Math.max(1, bounds.h);
115
116
  const background = options.background
116
117
  ? `<rect x="${number(left)}" y="${number(top)}" width="${number(width)}" height="${number(height)}" fill="${escapeXml(options.background)}" />`
117
118
  : "";
118
119
  return `<svg xmlns="http://www.w3.org/2000/svg" width="${number(width)}" height="${number(height)}" `
119
- + `viewBox="${number(left)} ${number(top)} ${number(width)} ${number(height)}">`
120
+ + `viewBox="${number(left)} ${number(top)} ${number(width)} ${number(height)}" `
121
+ + `font-family="${DEFAULT_SVG_FONT_ATTR}" font-weight="normal" fill="#000">`
120
122
  + `${background}${this.body.join("")}</svg>`;
121
123
  }
122
124
  }
@@ -1,8 +1,43 @@
1
- import type { GlyphMetrics, TextMeasurer, TextStyle } from "./types.js";
1
+ import type { GlyphMetrics, Painter, TextMeasurer, TextStyle } from "./types.js";
2
2
  /** 未指定字体族时,普通文本使用的字体栈 */
3
3
  export declare const DEFAULT_TEXT_FONT = "sans-serif";
4
4
  /** 简谱数字及同类谱面数字使用的字体栈 */
5
5
  export declare const JIANPU_NUMBER_FONT = "'Cascadia Mono', Consolas, 'Liberation Mono', 'Noto Sans Mono', monospace";
6
+ /** 同一行内具有相同样式掩码的连续纯文本片段 */
7
+ export interface RichTextRun {
8
+ text: string;
9
+ mask: number;
10
+ }
11
+ /** 向片段序列末尾追加字符;掩码相同时原地合并 */
12
+ export declare function appendRun(runs: RichTextRun[], text: string, mask: number): void;
13
+ /**
14
+ * 按状态机扫描 `**`、`*`、`_`、`^` 样式开关并逐字符回调 `(ch, mask, escaped)`。
15
+ * 遇到标记即异或切换对应样式位;若未闭合则后续文本(含跨行、跨音符槽)持续保持该样式。
16
+ */
17
+ export declare function scanMarkdown(source: string, onChar: (ch: string, mask: number, escaped: boolean) => void, escapable?: string): void;
18
+ /** 解析多行富文本:单遍跨行扫描样式状态,遇换行切分为每行的片段列表 */
19
+ export declare function parseRichText(source: string): RichTextRun[][];
20
+ /** 将前一片段与下一片段的样式掩码差值(`prevMask ^ nextMask`)还原为状态切换标记 */
21
+ export declare function markdownToggles(maskDiff: number): string;
22
+ /** 单行富文本的完整排版结果,供布局与绘制阶段直接复用 */
23
+ export interface PreparedRichLine extends GlyphMetrics {
24
+ runs: (RichTextRun & {
25
+ style: TextStyle;
26
+ w: number;
27
+ })[];
28
+ style: TextStyle;
29
+ }
30
+ /**
31
+ * 度量单行富文本(可传原始字符串或已解析片段)并汇总整行尺寸。
32
+ * 行高 h 与 baseline 始终取基准字号(非上标)的度量,避免行内含有上标时导致同行基线错位。
33
+ */
34
+ export declare function prepareRichLine(source: string | readonly RichTextRun[], baseStyle: TextStyle, measurer: TextMeasurer): PreparedRichLine;
35
+ /**
36
+ * 绘制已度量的单行富文本及其下划线装饰。
37
+ * 单片段时保留原 textAlign 直接绘制;多片段时从整行左缘起按段累加推进,
38
+ * 并将同一基线高度上相邻的下划线片段合并为单条连续线段。
39
+ */
40
+ export declare function paintRichLine(painter: Painter, line: PreparedRichLine, x: number, baselineY: number): void;
6
41
  /** Canvas 的 font 简写;测量与绘制必须用同一份,否则量到的不是将要画出的字形 */
7
42
  export declare function canvasFont(style: TextStyle): string;
8
43
  /** 默认文本测量保持确定性,不依赖浏览器和操作系统字体。 */
@@ -2,6 +2,140 @@
2
2
  export const DEFAULT_TEXT_FONT = "sans-serif";
3
3
  /** 简谱数字及同类谱面数字使用的字体栈 */
4
4
  export const JIANPU_NUMBER_FONT = "'Cascadia Mono', Consolas, 'Liberation Mono', 'Noto Sans Mono', monospace";
5
+ /** 富文本样式位掩码:四种内联样式正交叠加,通过异或翻转状态 */
6
+ const STYLE_BOLD = 1;
7
+ const STYLE_ITALIC = 2;
8
+ const STYLE_UNDERLINE = 4;
9
+ const STYLE_SUP = 8;
10
+ /** 向片段序列末尾追加字符;掩码相同时原地合并 */
11
+ export function appendRun(runs, text, mask) {
12
+ const last = runs.at(-1);
13
+ if (last && last.mask === mask)
14
+ last.text += text;
15
+ else
16
+ runs.push({ text, mask });
17
+ }
18
+ /**
19
+ * 按状态机扫描 `**`、`*`、`_`、`^` 样式开关并逐字符回调 `(ch, mask, escaped)`。
20
+ * 遇到标记即异或切换对应样式位;若未闭合则后续文本(含跨行、跨音符槽)持续保持该样式。
21
+ */
22
+ export function scanMarkdown(source, onChar, escapable = "\\*_^") {
23
+ let mask = 0;
24
+ for (let i = 0; i < source.length; i++) {
25
+ const ch = String.fromCodePoint(source.codePointAt(i));
26
+ i += ch.length - 1;
27
+ if (ch === "\\" && i + 1 < source.length && escapable.includes(source[i + 1])) {
28
+ onChar(source[++i], mask, true);
29
+ continue;
30
+ }
31
+ if (ch === "*") {
32
+ mask ^= source[i + 1] === "*" ? (i++, STYLE_BOLD) : STYLE_ITALIC;
33
+ continue;
34
+ }
35
+ if (ch === "_") {
36
+ mask ^= STYLE_UNDERLINE;
37
+ continue;
38
+ }
39
+ if (ch === "^") {
40
+ mask ^= STYLE_SUP;
41
+ continue;
42
+ }
43
+ onChar(ch, mask, false);
44
+ }
45
+ }
46
+ /** 解析多行富文本:单遍跨行扫描样式状态,遇换行切分为每行的片段列表 */
47
+ export function parseRichText(source) {
48
+ const lines = [[]];
49
+ scanMarkdown(source, (ch, mask) => {
50
+ if (ch === "\n")
51
+ lines.push([]);
52
+ else
53
+ appendRun(lines.at(-1), ch, mask);
54
+ });
55
+ return lines;
56
+ }
57
+ /** 将前一片段与下一片段的样式掩码差值(`prevMask ^ nextMask`)还原为状态切换标记 */
58
+ export function markdownToggles(maskDiff) {
59
+ return (maskDiff & STYLE_BOLD ? "**" : "")
60
+ + (maskDiff & STYLE_ITALIC ? "*" : "")
61
+ + (maskDiff & STYLE_UNDERLINE ? "_" : "")
62
+ + (maskDiff & STYLE_SUP ? "^" : "");
63
+ }
64
+ /** 上标相对基准字号的缩放比例与基线上移比例 */
65
+ const SUP_SCALE = 0.7;
66
+ const SUP_SHIFT = 0.35;
67
+ /**
68
+ * 度量单行富文本(可传原始字符串或已解析片段)并汇总整行尺寸。
69
+ * 行高 h 与 baseline 始终取基准字号(非上标)的度量,避免行内含有上标时导致同行基线错位。
70
+ */
71
+ export function prepareRichLine(source, baseStyle, measurer) {
72
+ const runs = [];
73
+ if (typeof source === "string")
74
+ scanMarkdown(source, (ch, mask) => appendRun(runs, ch, mask));
75
+ else
76
+ runs.push(...source);
77
+ let totalW = 0;
78
+ let lineMetrics;
79
+ const forceLeft = runs.length > 1 && baseStyle.textAlign && baseStyle.textAlign !== "left";
80
+ const preparedRuns = runs.map(run => {
81
+ const style = !forceLeft && (run.mask & (STYLE_BOLD | STYLE_ITALIC | STYLE_SUP)) === 0
82
+ ? baseStyle
83
+ : {
84
+ ...baseStyle,
85
+ ...(forceLeft ? { textAlign: "left" } : {}),
86
+ ...(run.mask & STYLE_SUP ? { fontSize: baseStyle.fontSize * SUP_SCALE } : {}),
87
+ ...(run.mask & STYLE_BOLD ? { fontWeight: "bold" } : {}),
88
+ ...(run.mask & STYLE_ITALIC ? { fontStyle: "italic" } : {}),
89
+ };
90
+ const metrics = measurer.measureText(run.text, style);
91
+ if ((run.mask & STYLE_SUP) === 0)
92
+ lineMetrics ??= metrics;
93
+ totalW += metrics.w;
94
+ return { ...run, style, w: metrics.w };
95
+ });
96
+ lineMetrics ??= measurer.measureText("", baseStyle);
97
+ return {
98
+ runs: preparedRuns,
99
+ style: baseStyle,
100
+ w: runs.length ? totalW : lineMetrics.w,
101
+ h: lineMetrics.h,
102
+ baseline: lineMetrics.baseline,
103
+ };
104
+ }
105
+ /**
106
+ * 绘制已度量的单行富文本及其下划线装饰。
107
+ * 单片段时保留原 textAlign 直接绘制;多片段时从整行左缘起按段累加推进,
108
+ * 并将同一基线高度上相邻的下划线片段合并为单条连续线段。
109
+ */
110
+ export function paintRichLine(painter, line, x, baselineY) {
111
+ const { runs, style: baseStyle, w } = line;
112
+ const { textAlign } = baseStyle;
113
+ const leftX = textAlign === "center" ? x - w / 2 : textAlign === "right" ? x - w : x;
114
+ const runY = (mask) => mask & STYLE_SUP ? baselineY - baseStyle.fontSize * SUP_SHIFT : baselineY;
115
+ let cursorX = leftX;
116
+ for (const run of runs) {
117
+ painter.drawText(run.text, runs.length === 1 ? x : cursorX, runY(run.mask), run.style);
118
+ cursorX += run.w;
119
+ }
120
+ // Canvas 2D 原生不支持 text-decoration,统一用 drawLine 绘制下划线以保证 SVG/Canvas 一致
121
+ for (let i = 0, cursor = leftX; i < runs.length;) {
122
+ const { mask, style, w: runW } = runs[i++];
123
+ if (!(mask & STYLE_UNDERLINE)) {
124
+ cursor += runW;
125
+ continue;
126
+ }
127
+ let endX = cursor + runW;
128
+ while (i < runs.length && (runs[i].mask & (STYLE_UNDERLINE | STYLE_SUP)) === (mask & (STYLE_UNDERLINE | STYLE_SUP))) {
129
+ endX += runs[i++].w;
130
+ }
131
+ const y = runY(mask) + style.fontSize * 0.12;
132
+ painter.drawLine(cursor, y, endX, y, {
133
+ stroke: baseStyle.fill ?? "#000",
134
+ strokeWidth: Math.max(1, style.fontSize * 0.06),
135
+ });
136
+ cursor = endX;
137
+ }
138
+ }
5
139
  /** Canvas 的 font 简写;测量与绘制必须用同一份,否则量到的不是将要画出的字形 */
6
140
  export function canvasFont(style) {
7
141
  const slant = style.fontStyle ? `${style.fontStyle} ` : "";
@@ -10,5 +10,4 @@ export declare class TranslatingPainter implements Painter {
10
10
  drawRect(x: number, y: number, w: number, h: number, style?: PaintStyle): void;
11
11
  drawCircle(cx: number, cy: number, r: number, style?: PaintStyle): void;
12
12
  drawPath(commands: readonly PathCommand[], style?: PaintStyle, transform?: PathTransform): void;
13
- private translateCommand;
14
13
  }
@@ -21,28 +21,11 @@ export class TranslatingPainter {
21
21
  this.target.drawCircle(cx + this.dx, cy + this.dy, r, style);
22
22
  }
23
23
  drawPath(commands, style, transform) {
24
- if (transform) {
25
- const moved = { ...transform, x: transform.x + this.dx, y: transform.y + this.dy };
26
- this.target.drawPath(commands, style, moved);
27
- return;
28
- }
29
- this.target.drawPath(commands.map(command => this.translateCommand(command)), style);
30
- }
31
- translateCommand(command) {
32
- switch (command.op) {
33
- case "Z": return command;
34
- case "Q": return {
35
- op: "Q",
36
- cx: command.cx + this.dx, cy: command.cy + this.dy,
37
- x: command.x + this.dx, y: command.y + this.dy,
38
- };
39
- case "C": return {
40
- op: "C",
41
- cx1: command.cx1 + this.dx, cy1: command.cy1 + this.dy,
42
- cx2: command.cx2 + this.dx, cy2: command.cy2 + this.dy,
43
- x: command.x + this.dx, y: command.y + this.dy,
44
- };
45
- default: return { op: command.op, x: command.x + this.dx, y: command.y + this.dy };
46
- }
24
+ this.target.drawPath(commands, style, {
25
+ x: (transform?.x ?? 0) + this.dx,
26
+ y: (transform?.y ?? 0) + this.dy,
27
+ scaleX: transform?.scaleX ?? 1,
28
+ scaleY: transform?.scaleY ?? 1,
29
+ });
47
30
  }
48
31
  }
@@ -18,7 +18,6 @@ export interface PaintStyle {
18
18
  fill?: string;
19
19
  stroke?: string;
20
20
  strokeWidth?: number;
21
- opacity?: number;
22
21
  }
23
22
  /**
24
23
  * 任意文本的排版样式
@@ -33,7 +32,6 @@ export interface TextStyle {
33
32
  fontStyle?: "normal" | "italic" | "oblique";
34
33
  textAlign?: "left" | "center" | "right";
35
34
  fill?: string;
36
- opacity?: number;
37
35
  }
38
36
  /**
39
37
  * 通用路径命令
package/grammar.md CHANGED
@@ -20,14 +20,15 @@ sidebar:
20
20
  | [换行](#换行) | `@br` `@pagebreak` / `@pb` |
21
21
  | [声部与歌词](#声部与歌词) | `@voice` `@voices` |
22
22
  | [堆叠与和弦](#堆叠与和弦) | `@stack` `@up` `@down` |
23
- | [琶音倚音与连音](#琶音倚音与连音) | `@arp` `@grace` `@tuplet` |
24
- | [外框与微调](#外框与微调) | `@box` `@adjust` |
23
+ | [琶音倚音与连音](#琶音倚音与连音) | `@arp` `@grace` `@tremolo` `@tuplet` |
24
+ | [外框与微调](#外框与微调) | `@box` `@adjust` `@slide` |
25
25
  | [关系型:连线、反复房子、八度号、渐强渐弱](#关系型) | `@beam` `@tie` `@gliss` `@volta` `@ottava` `@dyn` |
26
26
 
27
27
  ## 2. 基本类型
28
- - **字符串**:双引号 `"..."`,无歧义时可省;含分隔符须加引号,如 `@note("b6,")`。
28
+ - **字符串**:双引号 `"..."`,无歧义时可省;含分隔符须加引号,如 `@note("b6,")`。有无引号共享同一套转义规则:
29
29
  - 可跨行;引号须配对,孤立 `"` 按普通字符处理。
30
- - `\` 转义后一个字符,如 `\"`;不支持 `\n` 等语义转义。
30
+ - 支持 JSON 风格的 Unicode 转义:`\uXXXX` 为恰好四位十六进制码元,例如 `"\uE050"`;补充平面字符用 `"\uD834\uDD1E"` 这样的代理对表示。
31
+ - 用 `\"`、`\\` 输入双引号和反斜杠,用 `\*`、`\_`、`\^`、`\-`、`\@`、`\{`、`\}` 显示符号本身;不支持 `\n`、`\t`,换行和制表符直接输入。转义只处理一次,`"\\uE050"` 显示 `\uE050`。
31
32
  - **布尔值**:`true` / `false`。
32
33
  - **数字**:有限整数或小数。
33
34
  - **长度**:数字加 `px`(默认)或 `em`(相对当前字号)。
@@ -57,12 +58,14 @@ sidebar:
57
58
 
58
59
  ### 页面与谱头
59
60
 
60
- - `@page(width, height, top, bottom, left, right, gap, numbering, font, fillRatio)`:页面布局。
61
+ - `@page(width, height, top, bottom, left, right, gap, minGap, numbering, barNumbering, font, fillRatio)`:页面布局。
61
62
  - 仅顶层首次声明有效,其余警告并忽略;`em` 按声明时字号计算。
62
- - 默认:宽 `794px`、高 `0px`、上 `45px`、下 `48px`、左右 `40px`、行距 `1em`、`fillRatio=0.5`。
63
- - `height <= 0` 不自动分页,仍可手动换页;正值按整行分页,单行超高报错。自动封页均分剩余高度,末页保持最小行距。
63
+ - 默认:宽 `794px`、高 `0px`、上 `45px`、下 `48px`、左右 `40px`、行距 `1em`、最小行距 `0.5em`、`fillRatio=0.5`。
64
+ - `gap` 为上一行下沿到下一行主旋律上沿(基线减半字高)的标准行距;顶部外扩图形优先借用行距,但与上一行下沿至少保留 `minGap`(不超过 `gap`)。
65
+ - `height <= 0` 不自动分页,仍可手动换页;正值按整行分页,单行超高报错。自动封页均分剩余高度,末页保持自然行距。
64
66
  - `fillRatio`:自然宽度达到版心宽度的该比例时撑满;负值始终撑满,`>= 1` 不自动拉开。
65
- - `numbering`:页码格式,如 `"1/1"`,默认 `""` 不显示;`font`:页码字体,默认 `""` 沿用当前字体。
67
+ - `numbering`:页码格式,如 `"1/1"`,默认 `""` 不显示;`font`:页码/小节号字体,默认 `""` 沿用当前字体。
68
+ - `barNumbering`:从第二行起每行行首的小节号格式,如 `"1"`、`"(1)"`,默认 `""` 不显示。
66
69
 
67
70
  - `@head(left={}, center={}, right={}, gap=5px)`:谱头,`gap` 为栏内行距。
68
71
  - 只接受零时长内容;可嵌套,不自动换行。
@@ -85,8 +88,8 @@ sidebar:
85
88
  - 基本时值:一个四分音符(`1 QN`);先减时线、后附点,与嵌套顺序无关。
86
89
 
87
90
  - `@div(内容, n=1, autobeam=true)` / `@/(...)`:减时线,后缀 `/`;每条时值减半。
88
- - 内部始终连梁;独立 `div` 在同轨、同谱面行、同四分音符拍内连续时自动连梁。
89
- - 拍边界、小节线、换行、时间间隙、非候选可见元素、开关变化或手工 `@beam` 截断自动连接。
91
+ - 内部始终连梁;独立 `div` 在同轨、同谱面行、同一拍内连续且短于一拍时自动连梁(未设拍号、散板或分母 $\le 4$ 按 `1 QN`;分母 $\ge 8$ 且分子为 3 的倍数按 3 个分母单位;其余分母 $> 4$ 按 1 个分母单位)。
92
+ - 拍边界、小节线、拍号变更、换行、时间间隙、非候选可见元素、开关变化或手工 `@beam` 截断自动连接。
90
93
  - `autobeam=false` 只关闭与周围 `div` 的自动连接。
91
94
 
92
95
  - `@dot(内容, n=1)` / `@.(...)`:附点,后缀 `.`;单附点 ×1.5,双附点 ×1.75,如 `1/.`。
@@ -102,21 +105,22 @@ sidebar:
102
105
 
103
106
  ### 文本与符号
104
107
 
105
- - `@text(字符串, size=1em, lineheight=1.25, align=left)`:文本标记。
108
+ - `@text(字符串, size=1em, lineheight=1.25, align=left, font="")`:文本标记。
106
109
  - 简写 `"渐强"`;可直接换行,`lineheight` 为自身字号的倍数。
107
110
  - `align=left/center/right`:左对齐 / 居中 / 右对齐,锚点为首行首字中心 / 整块中心 / 首行末字中心。
111
+ - 文字样式:`*斜体*`、`**粗体**`、`_下划线_`、`^上标^`(再次出现即关闭,不关闭则一直生效;写 `\*`、`\_`、`\^` 显示原字符。谱头、歌词与各类名称同样支持)。
112
+ - `font` 指定字体,空值沿用当前字体。宿主加载音乐字体后可写 `@text("\uE050", font="Bravura")`;Unicode 转义只决定字符,不会自动选择或加载字体。
108
113
 
109
114
  - `@symbol(name, size=0.5em)` / `@$(...)`:乐谱符号,简写 `$name`。
110
115
  - 名称按小写精确查表,未命中时尝试各符号的可选正则,要求完整匹配;未知名称警告,严格模式报错。
111
116
  - `$` 后连续的非空白文本作为完整名称,直到空白或当前内容区间末尾。
112
- - 装饰:`$tr` 颤音、`$prall` 上波音、`$mordent` 下波音、`$accent` 重音;附在 `^` / `_` 上才影响播放,独立写出仅绘制。
113
- - 颤音尾巴:`$tr+`、`$tr++`、`$tr+++`,每个紧接的 `+` 添加一截波浪尾巴,只有视觉效果。
114
- - 延长:`$fermata`,目标区间速度减半,记谱时值不变。
115
- - 力度:`$ppp` `$pp` `$p` `$mp` `$mf` `$f` `$ff` `$fff`,默认 `$mf`;同轨持续至下一记号,反复时恢复目标位置的力度。
116
- - 新声部继承分叉处力度,开始发声后不再跟随父轨变化。
117
- - 跳转:`$dc` 回曲首;`$ds` 回此前最近的 `$segno`,无记号则回曲首。均只跳一次,回跳后忽略 `|: :|`。
118
- - 终止:`$fine` 仅在其后最近的 `$dc` / `$ds` 已回跳时生效。
119
- - `$dc`、`$ds`、`$fine` 应附在小节线上,如 `| _$dc`;执行跳转或终止时,该时间列不发声。
117
+ - 装饰:`$tr` 颤音、`$prall` 上波音、`$mordent` 下波音、`$turn` 回音、`$iturn` 逆回音。
118
+ - 奏法:`$accent` 重音、`$marcato` 强调音、`$staccato` 断奏、`$tenuto` 保持音。
119
+ - 技法:`$wheel` 轮指、`$harmonic` 泛音。
120
+ - 颤音尾巴:`$tr+`、`$tr++`、`$tr+++` 等。
121
+ - 延长:`$fermata` 延长号。
122
+ - 力度:`$ppp`、`$pp`、`$p`、`$mp`、`$mf`、`$f`、`$ff`、`$fff` 等。
123
+ - 跳转:`$dc` 回曲首、`$ds` 回标记、`$segno` 标记、`$fine` 终止、`$tocoda` 跳尾声、`$coda` 尾声标记。
120
124
 
121
125
  ### 换行
122
126
 
@@ -134,14 +138,16 @@ sidebar:
134
138
  - 简写:`N(声部名): 内容`、`L(歌词行名): 歌词`,名称均可省。
135
139
  - `N:` 到同层换行、下一条 `N/L/V` 或块末结束;跨源码行须用 `{}` 包裹。
136
140
  - `name` 后每个字符串参数或 `L:` 对应一行歌词;命名参数名为歌词行名。`L:` 属于前一声部,无所属声部则报错。
137
- - 按空格、连字符和非 ASCII 字符分词;`{你好}` 合为一个音符槽,显示时去掉花括号。
141
+ - 按空格、连字符和非 ASCII 字符分词;`{你好}` 合为一个音符槽,显示时去掉花括号。`*`、`**`、`_`、`^` 样式可跨多个音符(如 `L: *春眠不觉晓*`),标记本身不占音符位置。
138
142
 
139
- - `@voices(...声部, connect="[-]")` / `@vs(...)`:声部按书写顺序自上而下并行。
143
+ - `@voices(...声部, connect="[-]", gap=0.75em, minGap=0.35em)` / `@vs(...)`:声部按书写顺序自上而下并行。
140
144
  - 位置参数须为 `@voice`,各占独立音轨;连续 `N:` 及所属 `L:` 自动成组,空行、作用域结束或普通非成员内容结束组。
145
+ - **gap / minGap(仅命名传参)**:`gap` 为上一声部下沿到下一声部主旋律上沿(基线减半字高)的标准间距(默认 `0.75em`);顶部外扩记号优先借用这段间距,但与上一声部下沿至少保留 `minGap`(默认 `0.35em`,不超过 `gap`);两者均须为非负有限长度。同一宿主下声部数相同的组始终复用音轨,间距不一致时取较大值并产生警告。
141
146
  - **connect(仅命名传参)**:只改外观。`"[-]"` 全组带钩括线,`"{-}"` 全组大括号,`""` 或纯空白字符串仅公共细连谱线;单声部组不画连接。
142
147
  - 范围可组合,如 `"[1-4]{5-7}"`;从 1 编号,只数直接声部,含两端,省略端点取首 / 末声部。
143
148
  - 端点为正整数,不可反向或越界;单成员可写 `[3]` 或 `{3}`,分别等价于 `[3-3]` 或 `{3-3}`;可重叠,不自动嵌套或避让。
144
- - **连接声明**:`V{}:` 大括号、`V[]:` 带钩括线、`V|:` 仅细线;不限行首,后须有 `N:`,可同行或换行。
149
+ - 范围后可用 `:名称` 指定分组总名称(如 `"{1-2:钢琴}[3-4:合唱]"`、`"{-:钢琴}"`、`"{3:独奏}"`),含 `[]{}:`、引号、换行或首尾空白时用双引号包裹;显示在对应连谱号垂直中心左侧,组内有声部名或歌词行名时自动向左错开,重叠连谱号各自按自身中心绘制、不相互避让。
150
+ - **连接声明**:`V{}:`(或 `V{组名}:`)大括号、`V[]:`(或 `V[组名]:`)带钩括线、`V|:` 仅细线;不限行首,后须有 `N:`,可同行或换行。
145
151
  - 到下一 `V` 或组末结束,不拆分并行组;相邻同形声明仍独立,`L:` 不跨声明寻找声部。
146
152
  - **默认值**:省略 `connect` 时取 `@set` 预设或内置 `"[-]"`;显式参数或本组 `V` 声明优先。任一 `V` 完整替换本组预设,未声明部分仅细线,不影响后续组。
147
153
 
@@ -151,11 +157,11 @@ sidebar:
151
157
  - 各分支同时开始、独立计时,可含旋律;首分支留在宿主轨,其余使用分支轨并依次向上排列。
152
158
  - 与 `@up` 不同,整体不能作为单个连音线端点。
153
159
 
154
- - `@up(...)`:和弦,简写 `^`,自下而上排列。
155
- - 折叠为一个事件,时值、对齐和减时线取首成员(宿主);每个参数须恰好产生一个可见对象。
160
+ - `@up(..., gap=0.12em)`:和弦,简写 `^`,自下而上排列。
161
+ - 折叠为一个事件,时值、对齐和减时线取首成员(宿主);每个参数须恰好产生一个可见对象;仅命名参数 `gap` 指定相邻成员间距(默认 `0.12em`,须为非负有限长度)。
156
162
  - 至少一个成员可标注时,整体才可标注;`{1@x ^ 3}` 定位成员,`{1 ^ 3}@x` 定位整体,后者的连音线从最上方成员起跳。
157
163
 
158
- - `@down(...)`:向下堆叠,简写 `_`,与 `^` 共用宿主及折叠规则。
164
+ - `@down(..., gap=0.12em)`:向下堆叠,简写 `_`,与 `^` 共用宿主及折叠规则。
159
165
  - `1^2_3^4_5`:宿主 `1`,上方 `2 4`,下方 `3 5`;横向占位取宿主,附属成员撑开行高。
160
166
  - `1 ^ $accent`、`1 _ $accent` 均修饰宿主,`$accent ^ 1` 无效。
161
167
  - `1 ^ $p`、`1 _ $p` 从宿主生效;`$p ^ 1` 的宿主力度不变,之后的音才改变。
@@ -171,9 +177,13 @@ sidebar:
171
177
  - `2>1` 前倚音(`pre`),`1<2` 后倚音(`post`),**箭头指向宿主**;多倚音用 `{3 2}>1`。
172
178
  - 宿主须为一个可见事件;倚音至少一个可见对象,可含和弦、连音、多声部及状态设置,不可换行。
173
179
  - 倚音默认八分音符,后缀 `/` 变十六分;相邻减时线自动连接。
174
- - 不增正文时值;借宿主实际时值的比例为 `min(倚音字面总时长 / 1 QN, 0.75)`,多声部取最长分支,在宿主轨同步起奏。
175
180
  - 可嵌套,`>` 左结合、`<` 右结合,字号逐层缩小;成员标签保留,调用后的标签绑定宿主。
176
181
 
182
+ - `@tremolo(content, n=3)`:震音。
183
+ - `n`:斜杠数量,取 `1..3` 的整数,默认 `3`。
184
+ - **单音震音**:`content` 为单个发声音符或和弦(后可接增时线 `-`),斜杠记在最末元素右下角,按 `1 / 2^n QN` 同音重复。
185
+ - **双音震音**:`content` 为两个同轨、同谱面行、等时值的相邻发声音符或和弦,斜杠记在两音之间,在两音总时值内按 `1 / 2^n QN` 交替发声。
186
+
177
187
  - `@tuplet(content, normal)`:多连音。
178
188
  - 显示数字 `actual = 原总时值 / 最短正时值`,须为不小于 2 的整数;所有时值乘以 `normal / actual`。
179
189
  - 如 `@tuplet({1/ 2 3}, 4)` 显示 5,总长 `2 QN`。
@@ -196,13 +206,12 @@ sidebar:
196
206
  - `up/down` 表示随时间上行/下行;四种组合分别为低处滑入、高处滑入、向高处滑出、向低处滑出。
197
207
 
198
208
  ### 关系型
199
- - `@gliss(标签1, 标签2)`:滑音斜直箭头,仅绘制,不改变时值或播放;两个位置标签必填,不接受命名参数。
209
+ - `@gliss(标签1, 标签2)`:滑音斜直箭头,不改变记谱时值;两个位置标签必填,不接受命名参数。
200
210
  - 标签顺序不限,按谱面时间自动确定起点和终点;`@gliss(a,b)` 与 `@gliss(b,a)` 等价,同时刻端点不合法。
201
211
  - 端点不限对象类型,但须具有排版盒子。优先读取端点自身的 `resolvedMidi`;没有该属性时沿同轨向前找第一个带该属性的对象,可跨时间缺口和谱面行,找到后即停止,空值不继续追溯。
202
- - 两端音高均为有限数值时,同轨按音高绘制;无法比较音高时发出 `W_GLISS_NO_PITCH` 警告并画水平箭头,每条关系只警告一次。
212
+ - 两端音高均为有限数值时,同轨按音高绘制,并在起点(或所标增时线及其后续延音)区间内按半音阶离散步进至终点音高;无法比较音高时发出 `W_GLISS_NO_PITCH` 警告并画水平箭头,每条关系只警告一次。
203
213
  - 从被标记对象右侧连接到终点左侧,避让附点与升降号,不自动移至最后一根增时线。
204
- - 如 `1 - -@a 5@b @gliss(a,b)`;增时线缺少自身音高时,由 gliss 查找前方音高,不改变增时线本身或播放行为。
205
- - 同一谱面行内可跨轨;跨轨始终连接实际端点,斜率不代表音高方向。不支持跨行、跨页、同一倚音组内部连接或复杂绕障。
214
+ - 如 `1 - -@a 5@b @gliss(a,b)`;增时线缺少自身音高时,由 gliss 查找前方音高,并从该增时线起点开始半音步进。
206
215
  - `@beam(...端点标签)`:手工连梁,不受 `div.autobeam` 影响。
207
216
  - 端点须按时间顺序指向同轨、同谱面行的相邻可见元素,可跨零时长小节线;和弦仅宿主参与。
208
217
  - `@tie(...端点标签, height=0)`:连音线 / 延音线。