jpfun 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/README.md +73 -1
  2. package/dist/converter/midi/convert.d.ts +50 -0
  3. package/dist/converter/midi/convert.js +700 -0
  4. package/dist/converter/midi/index.d.ts +5 -0
  5. package/dist/converter/midi/index.js +11 -0
  6. package/dist/converter/midi/json.d.ts +38 -0
  7. package/dist/converter/midi/json.js +1 -0
  8. package/dist/converter/midi/triplet.d.ts +30 -0
  9. package/dist/converter/midi/triplet.js +75 -0
  10. package/dist/converter/musicxml/dom.d.ts +25 -0
  11. package/dist/converter/musicxml/dom.js +65 -0
  12. package/dist/converter/musicxml/features.d.ts +51 -0
  13. package/dist/converter/musicxml/features.js +232 -0
  14. package/dist/converter/musicxml/index.d.ts +9 -0
  15. package/dist/converter/musicxml/index.js +1140 -0
  16. package/dist/converter/musicxml/model.d.ts +123 -0
  17. package/dist/converter/musicxml/model.js +1 -0
  18. package/dist/converter/source.d.ts +22 -0
  19. package/dist/converter/source.js +51 -0
  20. package/dist/core.d.ts +22 -0
  21. package/dist/core.js +22 -0
  22. package/dist/functions/ASTtypes.d.ts +28 -25
  23. package/dist/functions/ASTtypes.js +25 -23
  24. package/dist/functions/adjust/index.js +1 -1
  25. package/dist/functions/arpeggio/index.d.ts +2 -0
  26. package/dist/functions/arpeggio/index.js +180 -0
  27. package/dist/functions/arpeggio/shape.d.ts +7 -0
  28. package/dist/functions/arpeggio/shape.js +122 -0
  29. package/dist/functions/bar/index.js +23 -15
  30. package/dist/functions/beam/auto.d.ts +1 -1
  31. package/dist/functions/beam/auto.js +1 -1
  32. package/dist/functions/beam/layout.d.ts +2 -2
  33. package/dist/functions/beam/layout.js +1 -1
  34. package/dist/functions/box/index.js +2 -2
  35. package/dist/functions/br/index.js +1 -1
  36. package/dist/functions/dash/index.js +7 -6
  37. package/dist/functions/default.js +6 -2
  38. package/dist/functions/dot/index.js +12 -22
  39. package/dist/functions/dyn/index.d.ts +2 -0
  40. package/dist/functions/dyn/index.js +242 -0
  41. package/dist/functions/grace/index.d.ts +1 -1
  42. package/dist/functions/grace/index.js +2 -3
  43. package/dist/functions/head/index.js +149 -145
  44. package/dist/functions/key/index.js +5 -4
  45. package/dist/functions/meter/index.js +6 -5
  46. package/dist/functions/note/index.js +68 -21
  47. package/dist/functions/note/noteNameFSM.js +52 -63
  48. package/dist/functions/page/index.d.ts +2 -0
  49. package/dist/functions/page/index.js +22 -7
  50. package/dist/functions/program/index.d.ts +2 -0
  51. package/dist/functions/program/index.js +30 -0
  52. package/dist/functions/set/index.js +8 -5
  53. package/dist/functions/symbol/index.d.ts +13 -3
  54. package/dist/functions/symbol/index.js +61 -16
  55. package/dist/functions/symbol/shape.d.ts +2 -0
  56. package/dist/functions/symbol/shape.js +14 -10
  57. package/dist/functions/symbol/symbols/dc.d.ts +4 -0
  58. package/dist/functions/symbol/symbols/dc.js +82 -0
  59. package/dist/functions/symbol/symbols/{f.d.ts → ds.d.ts} +1 -1
  60. package/dist/functions/symbol/symbols/ds.js +93 -0
  61. package/dist/functions/symbol/symbols/dynamics.d.ts +3 -0
  62. package/dist/functions/symbol/symbols/dynamics.js +168 -0
  63. package/dist/functions/symbol/symbols/{p.d.ts → fine.d.ts} +1 -1
  64. package/dist/functions/symbol/symbols/fine.js +12 -0
  65. package/dist/functions/symbol/symbols/mordent.js +44 -31
  66. package/dist/functions/symbol/symbols/prall.d.ts +2 -0
  67. package/dist/functions/symbol/symbols/prall.js +42 -0
  68. package/dist/functions/symbol/symbols/segno.d.ts +4 -0
  69. package/dist/functions/symbol/symbols/segno.js +82 -0
  70. package/dist/functions/symbol/symbols/tr.js +0 -4
  71. package/dist/functions/tempo/index.js +5 -3
  72. package/dist/functions/temporal.d.ts +138 -0
  73. package/dist/functions/temporal.js +101 -0
  74. package/dist/functions/text/index.js +14 -7
  75. package/dist/functions/tie/index.js +37 -28
  76. package/dist/functions/tuplet/index.js +14 -7
  77. package/dist/functions/up/index.js +23 -21
  78. package/dist/functions/voice/index.js +121 -45
  79. package/dist/functions/volta/index.js +51 -48
  80. package/dist/iife/core.d.ts +1 -0
  81. package/dist/iife/core.js +3 -0
  82. package/dist/iife/from-midi.d.ts +1 -0
  83. package/dist/iife/from-midi.js +15 -0
  84. package/dist/iife/from-musicxml.d.ts +1 -0
  85. package/dist/iife/from-musicxml.js +3 -0
  86. package/dist/iife/full.d.ts +1 -0
  87. package/dist/iife/full.js +3 -0
  88. package/dist/index.d.ts +3 -21
  89. package/dist/index.js +3 -21
  90. package/dist/jpfun.core.min.js +153 -0
  91. package/dist/jpfun.from-midi.min.js +9 -0
  92. package/dist/jpfun.from-musicxml.min.js +12 -0
  93. package/dist/jpfun.min.js +71 -48
  94. package/dist/layout/default.js +2 -3
  95. package/dist/layout/engine.d.ts +2 -1
  96. package/dist/layout/engine.js +71 -26
  97. package/dist/layout/model.d.ts +4 -4
  98. package/dist/layout/model.js +15 -12
  99. package/dist/layout/page.js +5 -4
  100. package/dist/layout/path.js +3 -3
  101. package/dist/layout/types.d.ts +20 -2
  102. package/dist/lowering/loweringContext.d.ts +3 -1
  103. package/dist/lowering/loweringContext.js +28 -14
  104. package/dist/lowering/track.d.ts +4 -8
  105. package/dist/lowering/track.js +6 -1
  106. package/dist/lowering/types.d.ts +5 -128
  107. package/dist/lowering/types.js +1 -98
  108. package/dist/parser/parse-utils/string-utils.d.ts +2 -0
  109. package/dist/parser/parse-utils/string-utils.js +4 -0
  110. package/dist/parser/parserContext.d.ts +7 -8
  111. package/dist/parser/parserContext.js +41 -36
  112. package/dist/pipeline.d.ts +6 -5
  113. package/dist/pipeline.js +4 -5
  114. package/dist/playback/compile.d.ts +1 -1
  115. package/dist/playback/compile.js +15 -2
  116. package/dist/playback/event.d.ts +17 -3
  117. package/dist/playback/event.js +30 -12
  118. package/dist/playback/time.js +1 -1
  119. package/dist/playback/types.d.ts +5 -4
  120. package/dist/render/text.d.ts +6 -1
  121. package/dist/render/text.js +8 -1
  122. package/grammar.md +44 -8
  123. package/package.json +11 -2
  124. package/dist/functions/symbol/symbols/f.js +0 -55
  125. package/dist/functions/symbol/symbols/p.js +0 -61
@@ -0,0 +1,122 @@
1
+ import { pathBounds } from "../../layout/path.js";
2
+ const TILE_WIDTH = 54.2813;
3
+ const TILE_HEIGHT = 87.37505;
4
+ const TILE_STEP = 72.8125;
5
+ const ARROW_HEIGHT = 93.6719;
6
+ const ARROW_X = -27.4688;
7
+ const ARROW_Y = -7.9375;
8
+ const ARROW_BOTTOM = ARROW_Y + ARROW_HEIGHT;
9
+ /** MuseScore 4.7.4 导出的琶音波形块,已旋转到自上而下的局部坐标。 */
10
+ const TILE = [
11
+ { op: "M", x: 28.1406, y: 86.06255 },
12
+ { op: "C", cx1: 28.1406, cy1: 86.06255, cx2: 30.4531, cy2: 84.07815, x: 32.7656, y: 81.42185 },
13
+ { op: "C", cx1: 33.7656, cy1: 80.43755, cx2: 34.0938, cy2: 79.10935, x: 34.0938, y: 78.10935 },
14
+ { op: "C", cx1: 34.0938, cy1: 77.12505, cx2: 33.7656, cy2: 76.45315, x: 33.0938, y: 75.79685 },
15
+ { op: "L", x: 29.4531, y: 72.15625 },
16
+ { op: "C", cx1: 28.7969, cy1: 71.50005, cx2: 28.4688, cy2: 70.82815, x: 28.4688, y: 70.17185 },
17
+ { op: "C", cx1: 28.4688, cy1: 68.84375, cx2: 29.4531, cy2: 68.18755, x: 29.4531, y: 68.18755 },
18
+ { op: "C", cx1: 29.4531, cy1: 68.18755, cx2: 47.6563, cy2: 47.00005, x: 50.6406, y: 43.68755 },
19
+ { op: "C", cx1: 53.2969, cy1: 40.04685, cx2: 54.2813, cy2: 36.40625, x: 54.2813, y: 33.09375 },
20
+ { op: "C", cx1: 54.2813, cy1: 26.14065, cx2: 50.3125, cy2: 19.85935, x: 47.3281, y: 17.21875 },
21
+ { op: "L", x: 31.4375, y: 1.32812 },
22
+ { op: "C", cx1: 30.4531, cy1: 0.32812, cx2: 29.7969, cy2: 0, x: 28.7969, y: 0 },
23
+ { op: "C", cx1: 27.1406, cy1: 0, cx2: 25.8125, cy2: 1.32812, x: 25.8125, y: 1.32812 },
24
+ { op: "C", cx1: 25.8125, cy1: 1.32812, cx2: 23.5, cy2: 3.3125, x: 21.1875, y: 5.95312 },
25
+ { op: "C", cx1: 20.1875, cy1: 6.95313, cx2: 19.8594, cy2: 7.9375, x: 19.8594, y: 8.9375 },
26
+ { op: "C", cx1: 19.8594, cy1: 9.92188, cx2: 20.1875, cy2: 10.59375, x: 20.8594, y: 11.25 },
27
+ { op: "L", x: 24.5, y: 14.89063 },
28
+ { op: "C", cx1: 25.1563, cy1: 15.5625, cx2: 25.4844, cy2: 16.21875, x: 25.4844, y: 16.875 },
29
+ { op: "C", cx1: 25.4844, cy1: 18.20315, cx2: 24.5, cy2: 19.20315, x: 24.5, y: 19.20315 },
30
+ { op: "C", cx1: 24.5, cy1: 19.20315, cx2: 6.625, cy2: 40.37505, x: 3.64063, y: 43.68755 },
31
+ { op: "C", cx1: 1, cy1: 47.32815, cx2: 0, cy2: 50.96875, x: 0, y: 54.28125 },
32
+ { op: "C", cx1: 0, cy1: 61.23435, cx2: 3.96875, cy2: 67.51565, x: 6.95313, y: 70.17185 },
33
+ { op: "L", x: 22.8438, y: 86.06255 },
34
+ { op: "C", cx1: 23.8281, cy1: 87.04685, cx2: 24.8281, cy2: 87.37505, x: 25.4844, y: 87.37505 },
35
+ { op: "C", cx1: 27.1406, cy1: 87.37505, cx2: 28.1406, cy2: 86.06255, x: 28.1406, y: 86.06255 },
36
+ ];
37
+ /** MuseScore 下行琶音的末端箭头轮廓,坐标方向同 TILE。 */
38
+ const DOWN_ARROW = [
39
+ { op: "M", x: 111.8751, y: 21.5156 },
40
+ { op: "C", cx1: 112.5313, cy1: 20.1875, cx2: 113.5313, cy2: 18.2031, x: 113.5313, y: 16.875 },
41
+ { op: "C", cx1: 113.5313, cy1: 12.23438, cx2: 109.8907, cy2: 8.9375, x: 105.2501, y: 8.9375 },
42
+ { op: "C", cx1: 103.9219, cy1: 8.9375, cx2: 101.6094, cy2: 9.26563, x: 100.2813, y: 10.25 },
43
+ { op: "L", x: 72.1563, y: 31.7656 },
44
+ { op: "L", x: 72.1563, y: 28.4531 },
45
+ { op: "C", cx1: 72.1563, cy1: 16.54688, cx2: 66.8594, cy2: 8.26563, x: 58.2501, y: 0.98437 },
46
+ { op: "C", cx1: 57.2657, cy1: 0.32812, cx2: 55.9376, cy2: 0, x: 55.2657, y: 0 },
47
+ { op: "C", cx1: 53.6251, cy1: 0, cx2: 52.9532, cy2: 0.98437, x: 52.9532, y: 0.98437 },
48
+ { op: "C", cx1: 51.6251, cy1: 2.3125, cx2: 49.3126, cy2: 4.29687, x: 48.3282, y: 5.625 },
49
+ { op: "C", cx1: 47.3282, cy1: 6.9375, cx2: 47.0001, cy2: 7.9375, x: 47.0001, y: 8.9375 },
50
+ { op: "C", cx1: 47.0001, cy1: 9.92188, cx2: 47.3282, cy2: 10.57813, x: 47.6563, y: 11.25 },
51
+ { op: "C", cx1: 49.9688, cy1: 13.5625, cx2: 50.9688, cy2: 16.21875, x: 50.9688, y: 18.8594 },
52
+ { op: "C", cx1: 50.9688, cy1: 24.8125, cx2: 46.3282, cy2: 30.1094, x: 41.0469, y: 30.1094 },
53
+ { op: "C", cx1: 39.3907, cy1: 30.1094, cx2: 37.7344, cy2: 29.4531, x: 36.4063, y: 28.4531 },
54
+ { op: "L", x: 12.9063, y: 10.57813 },
55
+ { op: "C", cx1: 11.5782, cy1: 9.59375, cx2: 9.5938, cy2: 8.9375, x: 7.9375, y: 8.9375 },
56
+ { op: "C", cx1: 3.6407, cy1: 8.9375, cx2: 0, cy2: 12.57813, x: 0, y: 16.875 },
57
+ { op: "C", cx1: 0, cy1: 18.2031, cx2: 0.6563, cy2: 20.1875, x: 1.3125, y: 21.5156 },
58
+ { op: "L", x: 49.9688, y: 90.3594 },
59
+ { op: "C", cx1: 51.2969, cy1: 92.3438, cx2: 54.2813, cy2: 93.6719, x: 56.5938, y: 93.6719 },
60
+ { op: "C", cx1: 58.9063, cy1: 93.6719, cx2: 61.8907, cy2: 92.3438, x: 63.2188, y: 90.3594 },
61
+ { op: "L", x: 111.8751, y: 21.5156 },
62
+ ];
63
+ function appendShape(output, shape, width, height, offsetX, offsetY, scale, reverse) {
64
+ const x = (value) => offsetX + (reverse ? width - value : value) * scale;
65
+ const y = (value) => offsetY + (reverse ? height - value : value) * scale;
66
+ for (const command of shape) {
67
+ if (command.op === "Z")
68
+ output.push(command);
69
+ else if (command.op === "C")
70
+ output.push({
71
+ op: "C",
72
+ cx1: x(command.cx1), cy1: y(command.cy1),
73
+ cx2: x(command.cx2), cy2: y(command.cy2),
74
+ x: x(command.x), y: y(command.y),
75
+ });
76
+ else if (command.op === "Q")
77
+ output.push({
78
+ op: "Q",
79
+ cx: x(command.cx), cy: y(command.cy),
80
+ x: x(command.x), y: y(command.y),
81
+ });
82
+ else
83
+ output.push({ op: command.op, x: x(command.x), y: y(command.y) });
84
+ }
85
+ }
86
+ /** 按 MuseScore 的原始重叠比例铺满指定高度,并一次性返回最终边界。 */
87
+ export function prepareArpeggioShape(height, em, direction) {
88
+ const arrow = direction === "up" || direction === "down";
89
+ const segments = Math.max(1, Math.round(height / (em * 0.3)));
90
+ const regularCount = arrow ? Math.max(0, segments - 1) : segments;
91
+ const naturalHeight = !arrow
92
+ ? TILE_HEIGHT + TILE_STEP * (regularCount - 1)
93
+ : ARROW_BOTTOM + TILE_STEP * regularCount;
94
+ const scale = height / naturalHeight;
95
+ const commands = [];
96
+ for (let index = 0; index < regularCount; index++) {
97
+ appendShape(commands, TILE, TILE_WIDTH, TILE_HEIGHT, 0, index * TILE_STEP * scale, scale, direction === "");
98
+ }
99
+ if (arrow) {
100
+ appendShape(commands, DOWN_ARROW, 113.5313, ARROW_HEIGHT, ARROW_X * scale, (regularCount * TILE_STEP + ARROW_Y) * scale, scale, false);
101
+ }
102
+ const bounds = pathBounds(commands);
103
+ if (direction !== "up")
104
+ return { commands, bounds };
105
+ const rotated = commands.map(command => command.op === "Z" ? command : command.op === "C" ? {
106
+ op: "C",
107
+ cx1: bounds.x + bounds.w - (command.cx1 - bounds.x), cy1: height - command.cy1,
108
+ cx2: bounds.x + bounds.w - (command.cx2 - bounds.x), cy2: height - command.cy2,
109
+ x: bounds.x + bounds.w - (command.x - bounds.x), y: height - command.y,
110
+ } : command.op === "Q" ? {
111
+ op: "Q",
112
+ cx: bounds.x + bounds.w - (command.cx - bounds.x), cy: height - command.cy,
113
+ x: bounds.x + bounds.w - (command.x - bounds.x), y: height - command.y,
114
+ } : {
115
+ op: command.op,
116
+ x: bounds.x + bounds.w - (command.x - bounds.x), y: height - command.y,
117
+ });
118
+ return {
119
+ commands: rotated,
120
+ bounds: { x: bounds.x, y: height - bounds.y - bounds.h, w: bounds.w, h: bounds.h },
121
+ };
122
+ }
@@ -1,5 +1,5 @@
1
1
  import { ASTFunctionNode } from "../ASTtypes.js";
2
- import { ANCHOR_KEY, TemporalNodeBase } from "../../lowering/types.js";
2
+ import { ANCHOR_KEY, isVisualTemporalNode, TemporalNodeBase } from "../temporal.js";
3
3
  class BarFunction extends ASTFunctionNode {
4
4
  static def = {
5
5
  name: ["bar", "|"],
@@ -94,12 +94,17 @@ class BarTemporalNode extends TemporalNodeBase {
94
94
  * 给 bar 两侧的相邻元素增加 mu,避免被压缩到一起
95
95
  */
96
96
  prepareHorizontal(line) {
97
- const run = line.trackRuns.get(this.track);
98
- const index = run?.indexOf(this) ?? -1;
97
+ let host = this;
98
+ while (host.foldedInto)
99
+ host = host.foldedInto;
100
+ if (!isVisualTemporalNode(host))
101
+ return;
102
+ const run = line.trackRuns.get(host.track);
103
+ const index = run?.indexOf(host) ?? -1;
99
104
  if (!run || index < 0)
100
105
  return;
101
- line.registerHorizontalLayoutHook(this, this, ({ columns, start }) => {
102
- const current = columns[start].find(element => element.time === this);
106
+ line.registerHorizontalLayoutHook(host, host, ({ columns, start }) => {
107
+ const current = columns[start].find(element => element.time === host);
103
108
  if (!current)
104
109
  return;
105
110
  const elementOf = (node) => {
@@ -114,7 +119,7 @@ class BarTemporalNode extends TemporalNodeBase {
114
119
  const rightNode = run[index + 1];
115
120
  const right = rightNode ? elementOf(rightNode) : undefined;
116
121
  // 相邻两个 bar 的中间 gap 由右侧 bar 处理,避免重复增强
117
- if (right && !(rightNode instanceof BarTemporalNode)) {
122
+ if (right && rightNode.mergeKey !== ANCHOR_KEY) {
118
123
  current.config.mu_R *= 4;
119
124
  right.config.mu_L *= 4;
120
125
  }
@@ -123,7 +128,7 @@ class BarTemporalNode extends TemporalNodeBase {
123
128
  prepareLayout() {
124
129
  const { type, size } = this.ast;
125
130
  this.lines.length = 0;
126
- this.repeatDots.length = 0;
131
+ const repeatDots = [];
127
132
  const h = size;
128
133
  const thin = Math.max(1, size * 0.065);
129
134
  const thick = thin * 2.6;
@@ -151,27 +156,30 @@ class BarTemporalNode extends TemporalNodeBase {
151
156
  }
152
157
  if (hasLeftDots) {
153
158
  const dotX = dotRadius;
154
- this.repeatDots.push({ x: dotX, y: h * 0.38 });
155
- this.repeatDots.push({ x: dotX, y: h * 0.62 });
159
+ repeatDots.push({ x: dotX, y: h * 0.38 });
160
+ repeatDots.push({ x: dotX, y: h * 0.62 });
156
161
  }
157
162
  if (hasRightDots) {
158
163
  const dotX = x + dotGap;
159
- this.repeatDots.push({ x: dotX, y: h * 0.38 });
160
- this.repeatDots.push({ x: dotX, y: h * 0.62 });
164
+ repeatDots.push({ x: dotX, y: h * 0.38 });
165
+ repeatDots.push({ x: dotX, y: h * 0.62 });
161
166
  x = dotX + dotRadius;
162
167
  }
163
168
  this.box.w = x;
164
169
  this.box.h = h;
165
- this.box.anchor = x / 2;
170
+ const anchorLine = type >= 2 ? this.lines[0] : undefined;
171
+ this.box.anchor = anchorLine ? anchorLine.x + anchorLine.w / 2 : x / 2;
166
172
  this.box.visualAxis = h / 2;
173
+ for (const line of this.lines)
174
+ line.x -= this.box.anchor;
175
+ this.repeatDots = repeatDots.map(dot => ({ x: dot.x - this.box.anchor, y: dot.y, r: dotRadius }));
167
176
  }
168
177
  paint(painter) {
169
178
  for (const line of this.lines) {
170
- painter.drawRect(this.box.x + line.x, this.box.y, line.w, this.box.h, { fill: "#000" });
179
+ painter.drawRect(this.box.x + this.box.anchor + line.x, this.box.y, line.w, this.box.h, { fill: "#000" });
171
180
  }
172
- const radius = Math.max(1, this.box.w * 0.06);
173
181
  for (const dot of this.repeatDots) {
174
- painter.drawCircle(this.box.x + dot.x, this.box.y + dot.y, radius, { fill: "#000" });
182
+ painter.drawCircle(this.box.x + this.box.anchor + dot.x, this.box.y + dot.y, dot.r, { fill: "#000" });
175
183
  }
176
184
  }
177
185
  }
@@ -1,4 +1,4 @@
1
- import { type LoweringResult } from "../../lowering/types.js";
1
+ import type { LoweringResult } from "../../lowering/types.js";
2
2
  import type { LayoutAttachment } from "../../layout/types.js";
3
3
  /** beam 域在 lowering 固化后统一生成作用域连接和相邻自动连接 */
4
4
  export declare function createAutomaticBeamAttachments(result: LoweringResult): LayoutAttachment[];
@@ -1,4 +1,4 @@
1
- import { ANCHOR_KEY, isVisualTemporalNode, } from "../../lowering/types.js";
1
+ import { ANCHOR_KEY, isVisualTemporalNode, } from "../temporal.js";
2
2
  import { Fraction } from "../../fraction.js";
3
3
  import { DIV_ADDON_KEY, DivNode, } from "../div/index.js";
4
4
  import { collectExplicitBeamEndpoints, createBeamLayoutAttachment, } from "./layout.js";
@@ -1,7 +1,7 @@
1
- import { type LoweringResult, type TemporalNodeBase } from "../../lowering/types.js";
1
+ import { type TemporalNodeBase } from "../temporal.js";
2
2
  import type { SourceSpan } from "../../parser/types.js";
3
3
  import type { LayoutAttachment } from "../../layout/types.js";
4
- import type { LoweringAttachment } from "../../lowering/types.js";
4
+ import type { LoweringAttachment, LoweringResult } from "../../lowering/types.js";
5
5
  /** 显式和自动分组共享同一个几何对象 */
6
6
  export declare function createBeamLayoutAttachment(endPoints: TemporalNodeBase[], explicit: boolean, sourceSpan: SourceSpan): LayoutAttachment;
7
7
  /** 显式 beam 必须严格连接最终同轨同谱面行中的相邻可见主体 */
@@ -1,4 +1,4 @@
1
- import { isVisualTemporalNode, } from "../../lowering/types.js";
1
+ import { isVisualTemporalNode, } from "../temporal.js";
2
2
  import { ErrorDiagnostic } from "../../diagnostic.js";
3
3
  import { claimDivLine, divLinePortName, divLineRuns, divLineWidth, } from "../div/index.js";
4
4
  /** 显式和自动分组共享同一个几何对象 */
@@ -1,5 +1,5 @@
1
1
  import { ASTFunctionNode } from "../ASTtypes.js";
2
- import { isVisualTemporalNode } from "../../lowering/types.js";
2
+ import { isVisualTemporalNode } from "../temporal.js";
3
3
  import { ErrorDiagnostic } from "../../diagnostic.js";
4
4
  import { unionLayoutBoxes } from "../../layout/engine.js";
5
5
  import { layoutHorizontalRegion } from "../../layout/model.js";
@@ -154,7 +154,7 @@ class BoxLayoutAttachment {
154
154
  throw new ErrorDiagnostic("E_BOX_CONSTRAINT_CROSSING", "定宽 @box 可以嵌套,但不能部分交叉", this.owner.sourceSpan);
155
155
  }
156
156
  const regionX = X.subarray(start, end + 1);
157
- layoutHorizontalRegion(columns.slice(start, end + 1), rows, regionX, fixed.subarray(start, end), this.owner.width, options, true);
157
+ layoutHorizontalRegion(columns.slice(start, end + 1), rows, regionX, fixed.subarray(start, end), this.owner.width, options, 0);
158
158
  const actualWidth = regionX[regionX.length - 1] - regionX[0] + leftInset + rightInset;
159
159
  if (Math.abs(actualWidth - this.owner.width) > 1e-6) {
160
160
  throw new ErrorDiagnostic("E_BOX_CONSTRAINT_CONFLICT", "多个 @box 为相同内容指定了不同宽度", this.owner.sourceSpan);
@@ -1,6 +1,6 @@
1
1
  import { ASTFunctionNode } from "../ASTtypes.js";
2
2
  import { skipSpaces, skipSpacesBack } from "../../parser/parserContext.js";
3
- import { TemporalNodeBase } from "../../lowering/types.js";
3
+ import { TemporalNodeBase } from "../temporal.js";
4
4
  import { Diagnostic, WarningDiagnostic } from "../../diagnostic.js";
5
5
  import { Fraction } from "../../fraction.js";
6
6
  class BrFunction extends ASTFunctionNode {
@@ -1,5 +1,5 @@
1
1
  import { ASTFunctionNode } from "../ASTtypes.js";
2
- import { DEFAULT_KEY, TemporalNodeBase } from "../../lowering/types.js";
2
+ import { DEFAULT_KEY, TemporalNodeBase } from "../temporal.js";
3
3
  import { WarningDiagnostic } from "../../diagnostic.js";
4
4
  class DashFunction extends ASTFunctionNode {
5
5
  static def = {
@@ -28,7 +28,7 @@ class DashFunction extends ASTFunctionNode {
28
28
  size;
29
29
  constructor(span, _args, ctx, parent = null) {
30
30
  super(span, parent);
31
- this.size = ctx.fontSize;
31
+ this.size = ctx.variables.fontsize;
32
32
  }
33
33
  loweringEnter() {
34
34
  return [new DashTemporalNode(this)];
@@ -37,6 +37,7 @@ class DashFunction extends ASTFunctionNode {
37
37
  }
38
38
  export const DashNode = DashFunction;
39
39
  class DashTemporalNode extends TemporalNodeBase {
40
+ lineWidth = 0;
40
41
  lineY = 0;
41
42
  constructor(ast) {
42
43
  super();
@@ -50,12 +51,12 @@ class DashTemporalNode extends TemporalNodeBase {
50
51
  }
51
52
  prepareLayout() {
52
53
  const size = this.ast.size;
53
- const width = size * 0.5;
54
+ this.lineWidth = size * 0.42;
54
55
  // dash 与数字音符共享视觉中心和完整字号高度
55
56
  // 线本身位于数字视觉中心,不使用极小的 glyph 高度作为轨道高度
56
- this.box.w = width;
57
+ this.box.w = this.lineWidth;
57
58
  this.box.h = size;
58
- this.box.anchor = width / 2;
59
+ this.box.anchor = this.lineWidth / 2;
59
60
  this.lineY = size * 0.5;
60
61
  this.box.visualAxis = this.lineY;
61
62
  }
@@ -88,6 +89,6 @@ class DashTemporalNode extends TemporalNodeBase {
88
89
  });
89
90
  }
90
91
  paint(painter) {
91
- painter.drawLine(this.box.x, this.box.y + this.lineY, this.box.x + this.box.w, this.box.y + this.lineY, { stroke: "#000", strokeWidth: Math.max(1, this.ast.size * 0.1) });
92
+ painter.drawLine(this.box.x, this.box.y + this.lineY, this.box.x + this.lineWidth, this.box.y + this.lineY, { stroke: "#000", strokeWidth: Math.max(1, this.ast.size * 0.1) });
92
93
  }
93
94
  }
@@ -1,10 +1,12 @@
1
1
  import { AdjustNode } from "./adjust/index.js";
2
+ import { ArpeggioNode } from "./arpeggio/index.js";
2
3
  import { BarNode } from "./bar/index.js";
3
4
  import { BeamNode } from "./beam/index.js";
4
5
  import { BoxNode } from "./box/index.js";
5
6
  import { DashNode } from "./dash/index.js";
6
7
  import { DivNode } from "./div/index.js";
7
8
  import { DotNode } from "./dot/index.js";
9
+ import { DynNode } from "./dyn/index.js";
8
10
  import { GraceNode } from "./grace/index.js";
9
11
  import { HeadNode } from "./head/index.js";
10
12
  import { KeyNode } from "./key/index.js";
@@ -13,6 +15,7 @@ import { BrNode } from "./br/index.js";
13
15
  import { NoteNode } from "./note/index.js";
14
16
  import { UpNode, DownNode } from "./up/index.js";
15
17
  import { PageNode } from "./page/index.js";
18
+ import { ProgramNode } from "./program/index.js";
16
19
  import { StackNode } from "./stack/index.js";
17
20
  import { SymbolNode } from "./symbol/index.js";
18
21
  import { SetNode } from "./set/index.js";
@@ -30,10 +33,11 @@ export const defaultFunctions = [
30
33
  PageNode, HeadNode, // 文档页面与谱头
31
34
  StackNode, // 时间同步
32
35
  UpNode, DownNode,
36
+ ArpeggioNode,
33
37
  GraceNode, // 倚音
34
- TieNode, BeamNode,
38
+ TieNode, BeamNode, DynNode,
35
39
  BoxNode, VoltaNode,
36
40
  AdjustNode, // 手工微调
37
- SetNode, KeyNode, MeterNode, TempoNode, // 设置
41
+ SetNode, KeyNode, MeterNode, TempoNode, ProgramNode, // 设置
38
42
  TextNode, SymbolNode,
39
43
  ];
@@ -11,10 +11,10 @@ class DotFunction extends ASTFunctionNode {
11
11
  name: [DOT_FUNC_NAME, "."],
12
12
  description: "附点",
13
13
  example: `@dot(C1, 2): C1右侧创建2个点 仅接收一个可接收元素
14
- 语法糖:在音符后加斜杠'.',可以多个
14
+ 语法糖:在目标后加'.',可以多个
15
15
  @dot(C1, 2) === C1..
16
- @dot(C1 C2/ @dash(), 2) 报错 因为点只能接收一个元素
17
- 设置命名参数前缀: dot
16
+ {1^2}. === {1.^2}
17
+ @dot(C1 C2/ @dash(), 2) 报错 因为点只能接收一个可见时间元素
18
18
  `,
19
19
  allowExtraArgs: false,
20
20
  args: [
@@ -107,8 +107,10 @@ class DotFunction extends ASTFunctionNode {
107
107
  };
108
108
  loweringEnter(ctx) {
109
109
  const count = this.n;
110
- ctx.beginLoweringGroup(this, {
110
+ const group = {
111
+ temporalCount: 0,
111
112
  onTemporal(node) {
113
+ group.temporalCount++;
112
114
  if (count === 0)
113
115
  return;
114
116
  const addon = node.addon ??= {};
@@ -119,11 +121,15 @@ class DotFunction extends ASTFunctionNode {
119
121
  node.T.mul(totalNumerator * currentDenominator, totalDenominator * currentNumerator);
120
122
  addon[DOT_ADDON_KEY] = total;
121
123
  },
122
- });
124
+ };
125
+ ctx.beginLoweringGroup(this, group);
123
126
  return [];
124
127
  }
125
128
  loweringExit(ctx) {
126
- ctx.endLoweringGroup(this);
129
+ const group = ctx.endLoweringGroup(this);
130
+ if (group.temporalCount !== 1) {
131
+ throw new ErrorDiagnostic("E_DOT_INVALID_CONTENT", `函数 @dot 只能接收 1个元素,但找到了 ${group.temporalCount} 个`, this.sourceSpan);
132
+ }
127
133
  return [];
128
134
  }
129
135
  timeFlowModel() {
@@ -138,10 +144,6 @@ class DotFunction extends ASTFunctionNode {
138
144
  constructor(sourceSpan, args, ctx, parent = null) {
139
145
  super(sourceSpan, parent);
140
146
  [this.content, this.n] = this.getArgValue(args, ctx);
141
- const contentJudge = DotFunction.leafNum(this.content);
142
- if (contentJudge !== 1) {
143
- throw new ErrorDiagnostic("E_DOT_INVALID_CONTENT", `函数 @dot 只能接收 1个元素,但找到了 ${contentJudge} 个`, sourceSpan);
144
- }
145
147
  this.content.parent = this;
146
148
  const n = Math.max(0, Math.trunc(this.n));
147
149
  if (n !== this.n) {
@@ -152,17 +154,5 @@ class DotFunction extends ASTFunctionNode {
152
154
  toString(source) {
153
155
  return `@dot(${this.content.toString(source)}, ${this.n})`;
154
156
  }
155
- // 判断叶节点数量
156
- static leafNum(node) {
157
- let count = 0;
158
- const chs = node.children;
159
- if (chs) { // 不是叶节点
160
- for (const child of chs)
161
- count += DotFunction.leafNum(child);
162
- }
163
- else
164
- count++;
165
- return count;
166
- }
167
157
  }
168
158
  export const DotNode = DotFunction;
@@ -0,0 +1,2 @@
1
+ import { type ASTFunctionClass } from "../ASTtypes.js";
2
+ export declare const DynNode: ASTFunctionClass;