jpfun 0.4.0 → 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 (83) 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 +4 -4
  14. package/dist/functions/ASTtypes.js +5 -9
  15. package/dist/functions/adjust/index.js +16 -53
  16. package/dist/functions/arpeggio/index.js +27 -15
  17. package/dist/functions/bar/index.js +7 -8
  18. package/dist/functions/beam/index.js +6 -1
  19. package/dist/functions/beam/layout.d.ts +1 -1
  20. package/dist/functions/beam/layout.js +5 -3
  21. package/dist/functions/box/index.js +88 -82
  22. package/dist/functions/br/index.js +9 -5
  23. package/dist/functions/dash/index.js +24 -13
  24. package/dist/functions/div/index.d.ts +5 -2
  25. package/dist/functions/div/index.js +15 -14
  26. package/dist/functions/dot/index.js +13 -11
  27. package/dist/functions/dyn/index.js +35 -39
  28. package/dist/functions/grace/index.d.ts +19 -6
  29. package/dist/functions/grace/index.js +136 -121
  30. package/dist/functions/head/index.js +19 -14
  31. package/dist/functions/key/index.js +8 -4
  32. package/dist/functions/meter/index.js +22 -2
  33. package/dist/functions/note/index.d.ts +6 -1
  34. package/dist/functions/note/index.js +48 -30
  35. package/dist/functions/note/source-transform.d.ts +21 -0
  36. package/dist/functions/note/source-transform.js +164 -0
  37. package/dist/functions/page/index.d.ts +8 -1
  38. package/dist/functions/page/index.js +23 -13
  39. package/dist/functions/program/index.js +11 -2
  40. package/dist/functions/set/index.js +14 -8
  41. package/dist/functions/stack/index.js +7 -5
  42. package/dist/functions/symbol/index.d.ts +2 -0
  43. package/dist/functions/symbol/index.js +11 -7
  44. package/dist/functions/symbol/ornament.d.ts +3 -3
  45. package/dist/functions/symbol/ornament.js +21 -35
  46. package/dist/functions/symbol/symbols/accent.js +5 -5
  47. package/dist/functions/symbol/symbols/fermata.js +5 -4
  48. package/dist/functions/tempo/index.js +7 -1
  49. package/dist/functions/text/index.js +11 -3
  50. package/dist/functions/tie/index.js +28 -32
  51. package/dist/functions/tuplet/index.js +26 -24
  52. package/dist/functions/up/index.js +24 -21
  53. package/dist/functions/voice/index.js +36 -26
  54. package/dist/functions/volta/index.js +16 -17
  55. package/dist/jpfun.core.min.js +98 -129
  56. package/dist/jpfun.from-midi.min.js +5 -5
  57. package/dist/jpfun.from-musicxml.min.js +8 -8
  58. package/dist/jpfun.min.js +107 -138
  59. package/dist/layout/engine.d.ts +11 -1
  60. package/dist/layout/engine.js +299 -96
  61. package/dist/layout/page.js +2 -0
  62. package/dist/layout/range.d.ts +26 -0
  63. package/dist/layout/range.js +75 -0
  64. package/dist/layout/types.d.ts +33 -4
  65. package/dist/lowering/types.d.ts +5 -0
  66. package/dist/parser/parse-utils/length-utils.js +2 -0
  67. package/dist/parser/parse-utils/note-utils.d.ts +2 -0
  68. package/dist/parser/parse-utils/note-utils.js +6 -2
  69. package/dist/parser/parserContext.js +1 -1
  70. package/dist/playback/compile.d.ts +2 -9
  71. package/dist/playback/compile.js +297 -186
  72. package/dist/playback/event.d.ts +8 -16
  73. package/dist/playback/event.js +13 -3
  74. package/dist/playback/types.d.ts +76 -18
  75. package/dist/playback/types.js +1 -0
  76. package/dist/render/index.d.ts +1 -1
  77. package/dist/render/index.js +1 -1
  78. package/dist/render/recording.d.ts +1 -0
  79. package/dist/render/recording.js +21 -0
  80. package/dist/render/translate.d.ts +14 -0
  81. package/dist/render/translate.js +48 -0
  82. package/grammar.md +103 -78
  83. package/package.json +4 -4
@@ -5,30 +5,34 @@ import { Diagnostic, ErrorDiagnostic } from "../../diagnostic.js";
5
5
  class VoltaFunction extends ASTFunctionNode {
6
6
  static def = {
7
7
  name: ["volta"],
8
- description: "反复房子",
9
- example: `@volta(from, to, pass, ...) 只在指定遍数演奏的一段区间
10
- from 和 to 是区间首末音符的标签,因此房子可以横跨谱面行
11
- pass 是遍数:整段谱面演奏到第几遍时才播这里,必填正整数
12
- 再写几个遍数就是几遍共用一个房子,顺序随意,标签按升序写成 1.2.
13
-
8
+ description: "反复的跳房子",
9
+ details: `\
10
+ ~~~jpfun
14
11
  |: 1 2 | 3@a 4@b :| 5@c 6@d | 7
15
- @volta(a, b, 1) @volta(c, d, 2)`,
12
+ @volta(a, b, 1) @volta(c, d, 2)
13
+ ~~~
14
+ - **额外位置参数**:更多遍数;例如 \`@volta(a, b, 1, 2)\` 让前两遍共用一个房子。遍数顺序不限,谱面按升序显示。
15
+
16
+ 本例第一遍演奏 \`a\` 到 \`b\`,第二遍演奏 \`c\` 到 \`d\`。`,
16
17
  allowExtraArgs: true,
17
18
  extraArgType: "number",
18
19
  args: [
19
20
  {
20
21
  name: "from",
22
+ description: "区间起点的标签,区间允许跨谱面行",
21
23
  type: "label",
22
24
  default: null,
23
25
  },
24
26
  {
25
27
  name: "to",
28
+ description: "区间终点的标签",
26
29
  type: "label",
27
30
  default: null,
28
31
  },
29
32
  {
30
33
  // 不给默认值:房子上的数字本来就是谱面的一部分,漏写会让整段被静默跳过
31
34
  name: "pass",
35
+ description: "进入此区间的演奏遍数,须为正整数",
32
36
  type: "number",
33
37
  default: null,
34
38
  },
@@ -95,6 +99,7 @@ class VoltaAttachment {
95
99
  this.to = to;
96
100
  }
97
101
  get sourceSpan() { return this.ast.sourceSpan; }
102
+ get endPoints() { return [this.from, this.to]; }
98
103
  /** 房子只决定跳不跳过本列;遍数怎么数、什么时候回跳都归小节线 */
99
104
  playbackFlow(columnOf) {
100
105
  const from = columnOf(this.from);
@@ -131,16 +136,11 @@ class VoltaAttachment {
131
136
  const leftBar = barIn(from.view.columns[from.column - 1]);
132
137
  const rightBar = barIn(to.view.columns[to.column + 1]);
133
138
  let span = 0;
134
- const coverage = [];
135
139
  // 括线盖住的是:首行从起点列向右、末行向左到终点列、中间行整行
136
140
  for (let line = from.line; line <= to.line; line++) {
137
- const view = context.lines[line];
138
- const start = line === from.line ? from.column : 0;
139
- const end = line === to.line ? to.column : view.columns.length - 1;
140
- for (let column = start; column <= end; column++) {
141
- 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);
142
143
  }
143
- coverage.push({ from: start, to: end, wholeLine: line !== from.line && line !== to.line });
144
144
  }
145
145
  const firstLine = head.layoutLine;
146
146
  const lastLine = tail.layoutLine;
@@ -163,10 +163,9 @@ class VoltaAttachment {
163
163
  const line = firstLine + offset;
164
164
  let topTrack = head.track;
165
165
  let hostTop = Infinity;
166
- const range = coverage[offset];
167
- const extents = range.wholeLine
166
+ const extents = line !== firstLine && line !== lastLine
168
167
  ? context.getRangeExtents(line)
169
- : context.getRangeExtents(line, [range.from, range.to]);
168
+ : context.getRangeExtents(line, [head, tail]);
170
169
  for (const [track, extent] of extents) {
171
170
  const y = context.getVisualAxis(line, track) + extent.top;
172
171
  if (y < hostTop) {