jpfun 0.5.0 → 0.7.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 (79) hide show
  1. package/dist/converter/midi/convert.d.ts +3 -1
  2. package/dist/converter/midi/convert.js +78 -66
  3. package/dist/converter/musicxml/features.d.ts +19 -5
  4. package/dist/converter/musicxml/features.js +46 -8
  5. package/dist/converter/musicxml/index.js +142 -23
  6. package/dist/converter/musicxml/model.d.ts +15 -0
  7. package/dist/diagnostic.js +1 -1
  8. package/dist/functions/ASTtypes.d.ts +4 -0
  9. package/dist/functions/ASTtypes.js +25 -14
  10. package/dist/functions/adjust/index.js +6 -2
  11. package/dist/functions/arpeggio/index.js +21 -17
  12. package/dist/functions/arpeggio/shape.d.ts +1 -1
  13. package/dist/functions/arpeggio/shape.js +27 -21
  14. package/dist/functions/bar/index.js +37 -36
  15. package/dist/functions/beam/auto.js +18 -24
  16. package/dist/functions/beam/layout.js +15 -23
  17. package/dist/functions/box/index.js +52 -1
  18. package/dist/functions/br/index.js +3 -4
  19. package/dist/functions/default.js +10 -5
  20. package/dist/functions/div/index.js +2 -3
  21. package/dist/functions/gliss/index.d.ts +2 -0
  22. package/dist/functions/gliss/index.js +180 -0
  23. package/dist/functions/grace/index.d.ts +4 -2
  24. package/dist/functions/grace/index.js +19 -11
  25. package/dist/functions/head/index.js +50 -62
  26. package/dist/functions/meter/index.js +45 -24
  27. package/dist/functions/meter/shape.d.ts +3 -0
  28. package/dist/functions/meter/shape.js +43 -0
  29. package/dist/functions/note/accidentals.js +10 -16
  30. package/dist/functions/note/index.js +38 -48
  31. package/dist/functions/ottava/index.d.ts +2 -0
  32. package/dist/functions/ottava/index.js +217 -0
  33. package/dist/functions/page/index.js +3 -3
  34. package/dist/functions/pagebreak/index.d.ts +2 -0
  35. package/dist/functions/pagebreak/index.js +36 -0
  36. package/dist/functions/rest/index.d.ts +2 -0
  37. package/dist/functions/rest/index.js +231 -0
  38. package/dist/functions/slide/index.d.ts +2 -0
  39. package/dist/functions/slide/index.js +132 -0
  40. package/dist/functions/stack/index.js +8 -15
  41. package/dist/functions/symbol/index.d.ts +9 -0
  42. package/dist/functions/symbol/index.js +41 -12
  43. package/dist/functions/symbol/ornament.js +15 -20
  44. package/dist/functions/symbol/shape.js +4 -1
  45. package/dist/functions/symbol/symbols/fine.js +1 -1
  46. package/dist/functions/symbol/symbols/tr.js +46 -1
  47. package/dist/functions/temporal.d.ts +36 -12
  48. package/dist/functions/temporal.js +29 -9
  49. package/dist/functions/tie/index.js +46 -32
  50. package/dist/functions/tuplet/index.js +1 -1
  51. package/dist/functions/up/index.js +51 -33
  52. package/dist/functions/voice/connections.d.ts +19 -0
  53. package/dist/functions/voice/connections.js +90 -0
  54. package/dist/functions/voice/index.js +245 -99
  55. package/dist/functions/volta/index.js +41 -21
  56. package/dist/jpfun.core.min.js +48 -55
  57. package/dist/jpfun.from-midi.min.js +5 -5
  58. package/dist/jpfun.from-musicxml.min.js +8 -8
  59. package/dist/jpfun.min.js +57 -64
  60. package/dist/layout/engine.d.ts +4 -1
  61. package/dist/layout/engine.js +232 -75
  62. package/dist/layout/model.js +22 -66
  63. package/dist/layout/page.d.ts +3 -2
  64. package/dist/layout/page.js +7 -6
  65. package/dist/layout/types.d.ts +34 -45
  66. package/dist/lowering/loweringContext.d.ts +1 -1
  67. package/dist/lowering/loweringContext.js +41 -171
  68. package/dist/parser/parserContext.d.ts +2 -0
  69. package/dist/parser/parserContext.js +31 -14
  70. package/dist/parser/preprocess.js +4 -6
  71. package/dist/playback/compile.js +12 -3
  72. package/dist/playback/types.d.ts +4 -2
  73. package/dist/render/paint.js +1 -1
  74. package/dist/render/svg.js +1 -0
  75. package/dist/render/text.d.ts +1 -1
  76. package/dist/render/text.js +3 -2
  77. package/dist/render/types.d.ts +1 -0
  78. package/grammar.md +221 -257
  79. package/package.json +1 -1
@@ -13,7 +13,8 @@ class VoltaFunction extends ASTFunctionNode {
13
13
  ~~~
14
14
  - **额外位置参数**:更多遍数;例如 \`@volta(a, b, 1, 2)\` 让前两遍共用一个房子。遍数顺序不限,谱面按升序显示。
15
15
 
16
- 本例第一遍演奏 \`a\` 到 \`b\`,第二遍演奏 \`c\` 到 \`d\`。`,
16
+ 本例第一遍演奏 \`a\` 到 \`b\`,第二遍演奏 \`c\` 到 \`d\`。
17
+ 播放区间包含终点事件的完整时值,但不包含其结束时刻的小节线或后续事件。`,
17
18
  allowExtraArgs: true,
18
19
  extraArgType: "number",
19
20
  args: [
@@ -42,7 +43,7 @@ class VoltaFunction extends ASTFunctionNode {
42
43
  to;
43
44
  /** 进入本房子的遍数,升序去重 */
44
45
  passes;
45
- /** 区间没有可见宿主时括线的尺寸基准 */
46
+ /** 调用时的字号,作为数字与括线的尺寸基准 */
46
47
  size;
47
48
  font;
48
49
  /** volta 不推进时间,只把 AST 端点解析成稳定的 temporal 引用 */
@@ -107,7 +108,11 @@ class VoltaAttachment {
107
108
  if (from === undefined || to === undefined)
108
109
  return;
109
110
  const start = Math.min(from, to);
110
- const end = Math.max(from, to);
111
+ const tail = (this.from.t.compare(this.to.t) || this.from.T.compare(this.to.T)) > 0
112
+ ? this.from : this.to;
113
+ const end = columnOf(tail, "end");
114
+ if (end === undefined)
115
+ return;
111
116
  return {
112
117
  range: [start, end],
113
118
  // 这里还是会和 bar 耦合。但只有bar有反复功能,不值得抽取为系统机制
@@ -135,16 +140,9 @@ class VoltaAttachment {
135
140
  const tail = to.view.columns[to.column][0];
136
141
  const leftBar = barIn(from.view.columns[from.column - 1]);
137
142
  const rightBar = barIn(to.view.columns[to.column + 1]);
138
- let span = 0;
139
- // 括线盖住的是:首行从起点列向右、末行向左到终点列、中间行整行
140
- for (let line = from.line; line <= to.line; line++) {
141
- for (const column of context.getRangeColumns(line, [head, tail])) {
142
- span = Math.max(span, column[0].ast.size);
143
- }
144
- }
145
143
  const firstLine = head.layoutLine;
146
144
  const lastLine = tail.layoutLine;
147
- const size = span || this.ast.size;
145
+ const size = this.ast.size;
148
146
  const style = {
149
147
  fontSize: size * 0.6,
150
148
  fontFamily: this.ast.font,
@@ -157,7 +155,11 @@ class VoltaAttachment {
157
155
  const halfStroke = strokeWidth / 2;
158
156
  const hook = metrics.h * 1.2;
159
157
  // 标签在下折钩的高度里垂直居中
160
- const textY = (hook - metrics.h) / 2 + metrics.baseline;
158
+ const textX = size * 0.15;
159
+ const textY = (hook - metrics.h) / 2 + metrics.baseline + 2;
160
+ const startWidth = Math.max(strokeWidth, halfStroke + textX + metrics.w);
161
+ const startBottom = Math.max(hook + halfStroke, textY - metrics.baseline + metrics.h);
162
+ const gap = size * 0.2;
161
163
  // 中间行可能没有本房子的可见对象,仍要补满,所以按行号连续遍历
162
164
  const draws = Array.from({ length: lastLine - firstLine + 1 }, (_, offset) => {
163
165
  const line = firstLine + offset;
@@ -185,17 +187,35 @@ class VoltaAttachment {
185
187
  : tail.box.x + (tail.ports["body.right"]?.x ?? tail.box.w);
186
188
  const left = Math.min(rawLeft, rawRight);
187
189
  const right = Math.max(rawLeft, rawRight);
188
- return { left, right, lineY: hostTop - size * 0.2 - hook, line, track: topTrack };
190
+ const part = (x, w, bottom) => ({
191
+ x, y: -halfStroke, w, h: bottom + halfStroke, line, track: topTrack,
192
+ });
193
+ const parts = [part(left - halfStroke, right - left + strokeWidth, halfStroke)];
194
+ if (line === firstLine) {
195
+ parts.push(part(left - halfStroke, startWidth, startBottom));
196
+ }
197
+ if (line === lastLine) {
198
+ parts.push(part(right - halfStroke, strokeWidth, hook + halfStroke));
199
+ }
200
+ let lineY = Infinity;
201
+ for (const part of parts) {
202
+ for (const [track, extent] of context.getHorizontalExtents(line, part.x, part.x + part.w)) {
203
+ lineY = Math.min(lineY, context.getVisualAxis(line, track) + extent.top - gap - (part.y + part.h));
204
+ }
205
+ }
206
+ if (lineY === Infinity)
207
+ lineY = hostTop - gap - halfStroke;
208
+ for (const part of parts)
209
+ part.y += lineY;
210
+ return { left, right, lineY, line, parts };
189
211
  });
190
212
  return {
191
- regions: draws.map(({ left, right, lineY, line, track }) => ({
192
- x: left - halfStroke,
193
- y: lineY - halfStroke,
194
- w: right - left + strokeWidth,
195
- h: hook + strokeWidth,
196
- line,
197
- track,
213
+ regions: draws.map(({ parts }) => ({
214
+ ...parts[0],
215
+ w: Math.max(...parts.map(part => part.x + part.w)) - parts[0].x,
216
+ h: Math.max(...parts.map(part => part.h)),
198
217
  })),
218
+ occupancy: draws.flatMap(draw => draw.parts),
199
219
  paint(painter) {
200
220
  const lineStyle = { stroke: "#000", strokeWidth };
201
221
  for (const { left, right, lineY, line } of draws) {
@@ -203,7 +223,7 @@ class VoltaAttachment {
203
223
  // 只有房子真正开始和结束的那一端才下折
204
224
  if (line === firstLine) {
205
225
  painter.drawLine(left, lineY, left, lineY + hook, lineStyle);
206
- painter.drawText(text, left + size * 0.15, lineY + textY + 2, style);
226
+ painter.drawText(text, left + textX, lineY + textY, style);
207
227
  }
208
228
  if (line === lastLine)
209
229
  painter.drawLine(right, lineY, right, lineY + hook, lineStyle);