jpfun 0.4.1 → 0.5.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 (73) hide show
  1. package/README.md +53 -113
  2. package/dist/converter/midi/convert.js +14 -7
  3. package/dist/converter/musicxml/features.d.ts +57 -16
  4. package/dist/converter/musicxml/features.js +204 -42
  5. package/dist/converter/musicxml/index.d.ts +7 -2
  6. package/dist/converter/musicxml/index.js +256 -268
  7. package/dist/converter/musicxml/model.d.ts +36 -7
  8. package/dist/converter/musicxml/resolve.d.ts +10 -0
  9. package/dist/converter/musicxml/resolve.js +152 -0
  10. package/dist/core.d.ts +1 -0
  11. package/dist/core.js +1 -0
  12. package/dist/fraction.js +7 -1
  13. package/dist/functions/ASTtypes.d.ts +2 -3
  14. package/dist/functions/ASTtypes.js +5 -9
  15. package/dist/functions/adjust/index.js +4 -48
  16. package/dist/functions/arpeggio/index.js +21 -13
  17. package/dist/functions/box/index.js +81 -82
  18. package/dist/functions/dash/index.js +20 -11
  19. package/dist/functions/div/index.d.ts +1 -1
  20. package/dist/functions/div/index.js +7 -7
  21. package/dist/functions/dot/index.js +4 -5
  22. package/dist/functions/dyn/index.js +28 -32
  23. package/dist/functions/grace/index.d.ts +19 -6
  24. package/dist/functions/grace/index.js +123 -115
  25. package/dist/functions/key/index.js +1 -1
  26. package/dist/functions/meter/index.js +14 -1
  27. package/dist/functions/note/index.d.ts +6 -1
  28. package/dist/functions/note/index.js +37 -14
  29. package/dist/functions/note/source-transform.d.ts +21 -0
  30. package/dist/functions/note/source-transform.js +164 -0
  31. package/dist/functions/page/index.d.ts +5 -0
  32. package/dist/functions/page/index.js +8 -5
  33. package/dist/functions/set/index.js +5 -1
  34. package/dist/functions/symbol/index.d.ts +2 -0
  35. package/dist/functions/symbol/index.js +1 -1
  36. package/dist/functions/symbol/ornament.d.ts +3 -3
  37. package/dist/functions/symbol/ornament.js +21 -35
  38. package/dist/functions/symbol/symbols/accent.js +5 -5
  39. package/dist/functions/symbol/symbols/fermata.js +5 -4
  40. package/dist/functions/tie/index.js +22 -32
  41. package/dist/functions/tuplet/index.js +19 -23
  42. package/dist/functions/up/index.js +9 -9
  43. package/dist/functions/voice/index.js +4 -3
  44. package/dist/functions/volta/index.js +7 -12
  45. package/dist/jpfun.core.min.js +40 -37
  46. package/dist/jpfun.from-midi.min.js +5 -5
  47. package/dist/jpfun.from-musicxml.min.js +8 -8
  48. package/dist/jpfun.min.js +49 -46
  49. package/dist/layout/engine.d.ts +11 -1
  50. package/dist/layout/engine.js +299 -96
  51. package/dist/layout/page.js +2 -0
  52. package/dist/layout/range.d.ts +26 -0
  53. package/dist/layout/range.js +75 -0
  54. package/dist/layout/types.d.ts +33 -4
  55. package/dist/lowering/types.d.ts +5 -0
  56. package/dist/parser/parse-utils/length-utils.js +2 -0
  57. package/dist/parser/parse-utils/note-utils.d.ts +2 -0
  58. package/dist/parser/parse-utils/note-utils.js +6 -2
  59. package/dist/parser/parserContext.js +1 -1
  60. package/dist/playback/compile.d.ts +2 -9
  61. package/dist/playback/compile.js +297 -186
  62. package/dist/playback/event.d.ts +8 -16
  63. package/dist/playback/event.js +13 -3
  64. package/dist/playback/types.d.ts +76 -18
  65. package/dist/playback/types.js +1 -0
  66. package/dist/render/index.d.ts +1 -1
  67. package/dist/render/index.js +1 -1
  68. package/dist/render/recording.d.ts +1 -0
  69. package/dist/render/recording.js +21 -0
  70. package/dist/render/translate.d.ts +14 -0
  71. package/dist/render/translate.js +48 -0
  72. package/grammar.md +13 -6
  73. package/package.json +4 -4
@@ -2,7 +2,7 @@ import { ASTNodeBase, ASTFunctionNode, ASTTextNode, ASTLabelNode, ASTBraceNode }
2
2
  import { ErrorDiagnostic } from "../../diagnostic.js";
3
3
  import { ANCHOR_KEY, DEFAULT_KEY, isVisualTemporalNode, TemporalNodeBase, } from "../temporal.js";
4
4
  import { Fraction } from "../../fraction.js";
5
- import { prepareLayoutHost } from "../../layout/engine.js";
5
+ import { layoutLocalSequence } from "../../layout/engine.js";
6
6
  /**
7
7
  * `@up` / `@down` 共用的折叠容器,不导出
8
8
  *
@@ -295,7 +295,7 @@ class FoldTemporal extends TemporalNodeBase {
295
295
  * 宿主留在轨道基线上,其余成员按书写顺序向上或向下叠放
296
296
  *
297
297
  * 成员不进入全局 columns,因此它们的准备、定位和绘制都由本节点负责;
298
- * 准备直接复用引擎的 prepareLayoutHost,保证成员的装饰、端口与顶层对象完全一致。
298
+ * 每个成员独立执行局部横排,宿主继承含框约束的占位,其余成员仍沿宿主锚点悬挂。
299
299
  */
300
300
  prepareLayout(context) {
301
301
  // lowering 期间修饰挂在折叠体上(augmenter 要看到整体节奏),渲染时交给宿主:
@@ -304,18 +304,19 @@ class FoldTemporal extends TemporalNodeBase {
304
304
  this.members[0].addon = this.addon;
305
305
  this.addon = void 0;
306
306
  }
307
- for (const member of this.members)
308
- prepareLayoutHost(member, context);
309
307
  const first = this.members[0];
310
308
  if (!first) {
311
309
  this.box.w = this.box.h = 0;
312
310
  this.box.anchor = this.box.visualAxis = 0;
313
311
  return;
314
312
  }
313
+ this.box.w = layoutLocalSequence([first], context);
314
+ for (let index = 1; index < this.members.length; index++)
315
+ layoutLocalSequence([this.members[index]], context);
315
316
  this.springConfig = { ...first.springConfig, ...this.springConfig };
316
317
  // 横向完全等于宿主:上下的标记(变速、注释、力度)常常比音符宽得多,
317
318
  // 让它们撑宽盒子会把右邻推开一大截;它们画在基线外侧,伸出盒外也不会碰撞
318
- const anchor = first.box.anchor;
319
+ const anchor = first.box.x + first.box.anchor;
319
320
  const gap = this.ast.size * 0.12;
320
321
  this.verticalOffsets.length = this.members.length;
321
322
  this.verticalOffsets.fill(0);
@@ -333,7 +334,6 @@ class FoldTemporal extends TemporalNodeBase {
333
334
  }
334
335
  for (let i = 0; i < this.verticalOffsets.length; i++)
335
336
  this.verticalOffsets[i] -= top;
336
- this.box.w = first.box.w;
337
337
  this.box.h = bottom - top;
338
338
  this.box.anchor = anchor;
339
339
  // 宿主对齐轨道基线,两侧成员各自向外撑开行高
@@ -343,11 +343,11 @@ class FoldTemporal extends TemporalNodeBase {
343
343
  const firstOffset = this.verticalOffsets[0];
344
344
  for (const name in first.ports) {
345
345
  const port = first.ports[name];
346
- this.ports[name] = { x: port.x, y: firstOffset + port.y };
346
+ this.ports[name] = { ...port, x: first.box.x + port.x, y: firstOffset + port.y };
347
347
  }
348
348
  // 代表成员没声明核心范围时退回它的整个盒子
349
- this.ports["body.left"] ??= { x: 0, y: this.box.visualAxis };
350
- this.ports["body.right"] ??= { x: first.box.w, y: this.box.visualAxis };
349
+ this.ports["body.left"] ??= { x: first.box.x, y: this.box.visualAxis };
350
+ this.ports["body.right"] ??= { x: first.box.x + first.box.w, y: this.box.visualAxis };
351
351
  // 唯一的例外:连音线要接到最上面那个成员的顶部
352
352
  const topIndex = this.aboveCount - 1;
353
353
  const topOffset = this.verticalOffsets[topIndex];
@@ -354,7 +354,8 @@ L: la la la
354
354
  token = "";
355
355
  };
356
356
  for (let i = 0; i < value.length; i++) {
357
- const ch = value[i];
357
+ const ch = String.fromCodePoint(value.codePointAt(i));
358
+ i += ch.length - 1;
358
359
  if (ch === "\\" && i + 1 < value.length && /[\\{}@-]/.test(value[i + 1])) {
359
360
  token += value[++i];
360
361
  }
@@ -481,8 +482,8 @@ L: la la la
481
482
  const names = [];
482
483
  ctx.beginLoweringGroup(this, {
483
484
  attachment: new VoicesBraceAttachment(names, this),
484
- onTemporal(node) {
485
- if (node instanceof VoiceNameTemporal)
485
+ onTemporal: node => {
486
+ if (node instanceof VoiceNameTemporal && node.ast.parent === this)
486
487
  names.push(node);
487
488
  },
488
489
  });
@@ -19,13 +19,13 @@ class VoltaFunction extends ASTFunctionNode {
19
19
  args: [
20
20
  {
21
21
  name: "from",
22
- description: "区间首音的标签,区间允许跨谱面行",
22
+ description: "区间起点的标签,区间允许跨谱面行",
23
23
  type: "label",
24
24
  default: null,
25
25
  },
26
26
  {
27
27
  name: "to",
28
- description: "区间末音的标签",
28
+ description: "区间终点的标签",
29
29
  type: "label",
30
30
  default: null,
31
31
  },
@@ -99,6 +99,7 @@ class VoltaAttachment {
99
99
  this.to = to;
100
100
  }
101
101
  get sourceSpan() { return this.ast.sourceSpan; }
102
+ get endPoints() { return [this.from, this.to]; }
102
103
  /** 房子只决定跳不跳过本列;遍数怎么数、什么时候回跳都归小节线 */
103
104
  playbackFlow(columnOf) {
104
105
  const from = columnOf(this.from);
@@ -135,16 +136,11 @@ class VoltaAttachment {
135
136
  const leftBar = barIn(from.view.columns[from.column - 1]);
136
137
  const rightBar = barIn(to.view.columns[to.column + 1]);
137
138
  let span = 0;
138
- const coverage = [];
139
139
  // 括线盖住的是:首行从起点列向右、末行向左到终点列、中间行整行
140
140
  for (let line = from.line; line <= to.line; line++) {
141
- const view = context.lines[line];
142
- const start = line === from.line ? from.column : 0;
143
- const end = line === to.line ? to.column : view.columns.length - 1;
144
- for (let column = start; column <= end; column++) {
145
- span = Math.max(span, view.columns[column][0].ast.size);
141
+ for (const column of context.getRangeColumns(line, [head, tail])) {
142
+ span = Math.max(span, column[0].ast.size);
146
143
  }
147
- coverage.push({ from: start, to: end, wholeLine: line !== from.line && line !== to.line });
148
144
  }
149
145
  const firstLine = head.layoutLine;
150
146
  const lastLine = tail.layoutLine;
@@ -167,10 +163,9 @@ class VoltaAttachment {
167
163
  const line = firstLine + offset;
168
164
  let topTrack = head.track;
169
165
  let hostTop = Infinity;
170
- const range = coverage[offset];
171
- const extents = range.wholeLine
166
+ const extents = line !== firstLine && line !== lastLine
172
167
  ? context.getRangeExtents(line)
173
- : context.getRangeExtents(line, [range.from, range.to]);
168
+ : context.getRangeExtents(line, [head, tail]);
174
169
  for (const [track, extent] of extents) {
175
170
  const y = context.getVisualAxis(line, track) + extent.top;
176
171
  if (y < hostTop) {