jpfun 0.2.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 (167) hide show
  1. package/README.md +141 -11
  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/diagnostic.js +5 -2
  23. package/dist/fraction.d.ts +24 -0
  24. package/dist/fraction.js +132 -0
  25. package/dist/functions/ASTtypes.d.ts +51 -31
  26. package/dist/functions/ASTtypes.js +59 -38
  27. package/dist/functions/adjust/index.d.ts +2 -0
  28. package/dist/functions/adjust/index.js +193 -0
  29. package/dist/functions/arpeggio/index.d.ts +2 -0
  30. package/dist/functions/arpeggio/index.js +180 -0
  31. package/dist/functions/arpeggio/shape.d.ts +7 -0
  32. package/dist/functions/arpeggio/shape.js +122 -0
  33. package/dist/functions/bar/index.d.ts +8 -0
  34. package/dist/functions/bar/index.js +62 -25
  35. package/dist/functions/beam/auto.d.ts +1 -1
  36. package/dist/functions/beam/auto.js +33 -16
  37. package/dist/functions/beam/index.js +10 -6
  38. package/dist/functions/beam/layout.d.ts +4 -3
  39. package/dist/functions/beam/layout.js +43 -65
  40. package/dist/functions/box/index.js +37 -36
  41. package/dist/functions/br/index.js +10 -8
  42. package/dist/functions/dash/index.js +40 -7
  43. package/dist/functions/default.js +19 -8
  44. package/dist/functions/div/index.d.ts +16 -0
  45. package/dist/functions/div/index.js +45 -17
  46. package/dist/functions/dot/index.js +23 -25
  47. package/dist/functions/dyn/index.d.ts +2 -0
  48. package/dist/functions/dyn/index.js +242 -0
  49. package/dist/functions/grace/index.d.ts +8 -11
  50. package/dist/functions/grace/index.js +84 -79
  51. package/dist/functions/head/index.d.ts +2 -0
  52. package/dist/functions/head/index.js +496 -0
  53. package/dist/functions/key/index.js +98 -3
  54. package/dist/functions/meter/index.d.ts +2 -0
  55. package/dist/functions/meter/index.js +155 -0
  56. package/dist/functions/note/accidentals.d.ts +24 -3
  57. package/dist/functions/note/accidentals.js +31 -1
  58. package/dist/functions/note/index.js +106 -79
  59. package/dist/functions/note/noteNameFSM.js +52 -63
  60. package/dist/functions/page/index.d.ts +11 -2
  61. package/dist/functions/page/index.js +65 -4
  62. package/dist/functions/program/index.d.ts +2 -0
  63. package/dist/functions/program/index.js +30 -0
  64. package/dist/functions/set/index.js +43 -32
  65. package/dist/functions/stack/index.js +26 -22
  66. package/dist/functions/symbol/index.d.ts +31 -0
  67. package/dist/functions/symbol/index.js +139 -0
  68. package/dist/functions/symbol/ornament.d.ts +15 -0
  69. package/dist/functions/symbol/ornament.js +73 -0
  70. package/dist/functions/symbol/shape.d.ts +24 -0
  71. package/dist/functions/symbol/shape.js +52 -0
  72. package/dist/functions/symbol/symbols/accent.d.ts +2 -0
  73. package/dist/functions/symbol/symbols/accent.js +24 -0
  74. package/dist/functions/symbol/symbols/dc.d.ts +4 -0
  75. package/dist/functions/symbol/symbols/dc.js +82 -0
  76. package/dist/functions/symbol/symbols/ds.d.ts +2 -0
  77. package/dist/functions/symbol/symbols/ds.js +93 -0
  78. package/dist/functions/symbol/symbols/dynamics.d.ts +3 -0
  79. package/dist/functions/symbol/symbols/dynamics.js +168 -0
  80. package/dist/functions/symbol/symbols/fermata.d.ts +2 -0
  81. package/dist/functions/symbol/symbols/fermata.js +24 -0
  82. package/dist/functions/symbol/symbols/fine.d.ts +2 -0
  83. package/dist/functions/symbol/symbols/fine.js +12 -0
  84. package/dist/functions/symbol/symbols/mordent.d.ts +2 -0
  85. package/dist/functions/symbol/symbols/mordent.js +56 -0
  86. package/dist/functions/symbol/symbols/prall.d.ts +2 -0
  87. package/dist/functions/symbol/symbols/prall.js +42 -0
  88. package/dist/functions/symbol/symbols/segno.d.ts +4 -0
  89. package/dist/functions/symbol/symbols/segno.js +82 -0
  90. package/dist/functions/symbol/symbols/tr.d.ts +2 -0
  91. package/dist/functions/symbol/symbols/tr.js +71 -0
  92. package/dist/functions/tempo/glyph.d.ts +12 -0
  93. package/dist/functions/tempo/glyph.js +30 -0
  94. package/dist/functions/tempo/index.js +57 -4
  95. package/dist/functions/temporal.d.ts +138 -0
  96. package/dist/functions/temporal.js +101 -0
  97. package/dist/functions/text/index.js +86 -27
  98. package/dist/functions/tie/index.js +136 -152
  99. package/dist/functions/tuplet/index.d.ts +2 -0
  100. package/dist/functions/tuplet/index.js +218 -0
  101. package/dist/functions/up/index.d.ts +1 -0
  102. package/dist/functions/up/index.js +258 -182
  103. package/dist/functions/voice/index.js +203 -109
  104. package/dist/functions/volta/index.d.ts +2 -0
  105. package/dist/functions/volta/index.js +230 -0
  106. package/dist/iife/core.d.ts +1 -0
  107. package/dist/iife/core.js +3 -0
  108. package/dist/iife/from-midi.d.ts +1 -0
  109. package/dist/iife/from-midi.js +15 -0
  110. package/dist/iife/from-musicxml.d.ts +1 -0
  111. package/dist/iife/from-musicxml.js +3 -0
  112. package/dist/iife/full.d.ts +1 -0
  113. package/dist/iife/full.js +3 -0
  114. package/dist/index.d.ts +3 -17
  115. package/dist/index.js +3 -17
  116. package/dist/jpfun.core.min.js +153 -0
  117. package/dist/jpfun.from-midi.min.js +9 -0
  118. package/dist/jpfun.from-musicxml.min.js +12 -0
  119. package/dist/jpfun.min.js +166 -0
  120. package/dist/layout/default.js +2 -3
  121. package/dist/layout/engine.d.ts +6 -12
  122. package/dist/layout/engine.js +115 -64
  123. package/dist/layout/model.d.ts +12 -5
  124. package/dist/layout/model.js +31 -18
  125. package/dist/layout/page.js +5 -4
  126. package/dist/layout/path.d.ts +19 -0
  127. package/dist/layout/path.js +101 -0
  128. package/dist/layout/types.d.ts +71 -20
  129. package/dist/layout/types.js +3 -1
  130. package/dist/lowering/loweringContext.d.ts +20 -20
  131. package/dist/lowering/loweringContext.js +153 -101
  132. package/dist/lowering/track.d.ts +5 -9
  133. package/dist/lowering/track.js +7 -2
  134. package/dist/lowering/types.d.ts +26 -112
  135. package/dist/lowering/types.js +1 -92
  136. package/dist/parser/parse-utils/call-utils.d.ts +0 -2
  137. package/dist/parser/parse-utils/call-utils.js +0 -6
  138. package/dist/parser/parse-utils/note-utils.d.ts +8 -0
  139. package/dist/parser/parse-utils/note-utils.js +35 -13
  140. package/dist/parser/parse-utils/string-utils.d.ts +10 -0
  141. package/dist/parser/parse-utils/string-utils.js +24 -0
  142. package/dist/parser/parserContext.d.ts +11 -9
  143. package/dist/parser/parserContext.js +65 -55
  144. package/dist/parser/preprocess.js +17 -11
  145. package/dist/pipeline.d.ts +6 -5
  146. package/dist/pipeline.js +4 -5
  147. package/dist/playback/compile.d.ts +18 -0
  148. package/dist/playback/compile.js +414 -0
  149. package/dist/playback/event.d.ts +105 -0
  150. package/dist/playback/event.js +105 -0
  151. package/dist/playback/time.d.ts +14 -0
  152. package/dist/playback/time.js +81 -0
  153. package/dist/playback/types.d.ts +129 -0
  154. package/dist/playback/types.js +3 -0
  155. package/dist/render/canvas.d.ts +4 -4
  156. package/dist/render/canvas.js +20 -5
  157. package/dist/render/index.d.ts +1 -0
  158. package/dist/render/index.js +1 -0
  159. package/dist/render/paint.d.ts +8 -0
  160. package/dist/render/paint.js +101 -0
  161. package/dist/render/svg.d.ts +3 -3
  162. package/dist/render/svg.js +10 -8
  163. package/dist/render/text.d.ts +22 -0
  164. package/dist/render/text.js +42 -0
  165. package/dist/render/types.d.ts +1 -1
  166. package/grammar.md +132 -13
  167. package/package.json +19 -6
@@ -0,0 +1,139 @@
1
+ import { ErrorDiagnostic, WarningDiagnostic } from "../../diagnostic.js";
2
+ import { DEFAULT_KEY, TemporalNodeBase } from "../temporal.js";
3
+ import { ASTFunctionNode, } from "../ASTtypes.js";
4
+ import { paintSymbol, symbolBounds } from "./shape.js";
5
+ import { accentSymbol } from "./symbols/accent.js";
6
+ import { dcSymbol } from "./symbols/dc.js";
7
+ import { dsSymbol } from "./symbols/ds.js";
8
+ import { dynamicSymbols } from "./symbols/dynamics.js";
9
+ import { fermataSymbol } from "./symbols/fermata.js";
10
+ import { fineSymbol } from "./symbols/fine.js";
11
+ import { mordentSymbol } from "./symbols/mordent.js";
12
+ import { prallSymbol } from "./symbols/prall.js";
13
+ import { segnoSymbol } from "./symbols/segno.js";
14
+ import { trSymbol } from "./symbols/tr.js";
15
+ const symbolTable = new Map([trSymbol, fermataSymbol, prallSymbol, mordentSymbol, accentSymbol, ...dynamicSymbols,
16
+ dcSymbol, dsSymbol, segnoSymbol, fineSymbol]
17
+ .map(definition => [definition.name.toLowerCase(), definition]));
18
+ class SymbolFunction extends ASTFunctionNode {
19
+ static def = {
20
+ name: ["symbol", "$"],
21
+ description: "创建一个乐谱符号",
22
+ example: [
23
+ "@symbol(name, size)",
24
+ "语法糖: $name",
25
+ "内置:",
26
+ ...[...symbolTable.values()].map(item => ` $${item.name} ${item.description}`),
27
+ ].join("\n"),
28
+ allowExtraArgs: false,
29
+ args: [
30
+ {
31
+ name: "name",
32
+ type: "string",
33
+ default: null
34
+ },
35
+ {
36
+ name: "size",
37
+ type: "length",
38
+ default: { value: 0.5, unit: "em" },
39
+ },
40
+ ],
41
+ };
42
+ static deSugarAtom(source, start, end) {
43
+ if (source[start] !== "$" || !/[A-Za-z]/.test(source[start + 1] ?? ""))
44
+ return null;
45
+ let next = start + 2;
46
+ while (next < end && /[A-Za-z0-9_-]/.test(source[next]))
47
+ next++;
48
+ const name = source.slice(start + 1, next);
49
+ const node = {
50
+ kind: "call",
51
+ typed: true,
52
+ name: "symbol",
53
+ args: new Map([[0, name]]),
54
+ span: { start, end: next },
55
+ syntaxKind: "atom",
56
+ };
57
+ return { next, node };
58
+ }
59
+ size;
60
+ definition;
61
+ constructor(sourceSpan, args, ctx, parent = null) {
62
+ super(sourceSpan, parent);
63
+ const [name, size] = this.getArgValue(args, ctx);
64
+ this.size = ctx.length2px(size);
65
+ const definition = symbolTable.get(name.toLowerCase());
66
+ if (!definition) {
67
+ const message = `@symbol: 未知符号: $${name}`;
68
+ if (ctx.variables.strict)
69
+ throw new ErrorDiagnostic("E_UNKNOWN_SYMBOL", message, sourceSpan);
70
+ ctx.diagnostics.push(new WarningDiagnostic("W_UNKNOWN_SYMBOL", message, sourceSpan));
71
+ return;
72
+ }
73
+ this.definition = definition;
74
+ }
75
+ loweringEnter() {
76
+ return [this.definition
77
+ ? new SymbolTemporal(this)
78
+ : new TemporalNodeBase()];
79
+ }
80
+ toString(source) {
81
+ return this.definition ? `@symbol(${this.definition.name})` : super.toString(source);
82
+ }
83
+ }
84
+ export const SymbolNode = SymbolFunction;
85
+ class SymbolTemporal extends TemporalNodeBase {
86
+ /** 符号自身坐标系里的固有包围盒,与布局轮次无关 */
87
+ bounds;
88
+ height;
89
+ /** 文字记号的内容与字号,图形记号为空 */
90
+ label;
91
+ scale = 1;
92
+ baseline = 0;
93
+ constructor(ast) {
94
+ super();
95
+ this.ast = ast;
96
+ this.mergeKey = DEFAULT_KEY;
97
+ this.onTimeState = ast.definition.onTimeState;
98
+ this.emitPlayback = ast.definition.emitPlayback;
99
+ this.playbackMarks = ast.definition.playbackMarks;
100
+ this.bounds = symbolBounds(ast.definition.shapes ?? []);
101
+ this.height = ast.size * (ast.definition.weight ?? 1);
102
+ const text = ast.definition.text;
103
+ // 文字记号的字号也是 size × weight,所以与图形记号视觉等高
104
+ this.label = text && {
105
+ content: text.content,
106
+ style: { fontSize: this.height, fontFamily: text.fontFamily },
107
+ };
108
+ this.initLayoutBox();
109
+ }
110
+ prepareLayout(context) {
111
+ if (this.label) {
112
+ const metrics = context.textMeasurer.measureText(this.label.content, this.label.style);
113
+ this.box.w = metrics.w;
114
+ this.box.h = metrics.h;
115
+ this.baseline = metrics.baseline;
116
+ }
117
+ else {
118
+ this.scale = this.height / this.bounds.h;
119
+ this.box.w = this.bounds.w * this.scale;
120
+ this.box.h = this.height;
121
+ }
122
+ this.box.anchor = this.box.w / 2;
123
+ this.box.visualAxis = this.box.h / 2;
124
+ }
125
+ paint(painter) {
126
+ if (this.label)
127
+ painter.drawText(this.label.content, this.box.x, this.box.y + this.baseline, this.label.style);
128
+ else
129
+ paintSymbol(painter, this.ast.definition.shapes ?? [], this.bounds, this.box, this.scale);
130
+ }
131
+ /** 控制流在生成事件之前展开,emitPlayback 够不到,所以单独接一次 */
132
+ playbackFlow(columnOf) {
133
+ const onVisit = this.ast.definition.onVisit;
134
+ if (!onVisit)
135
+ return;
136
+ const at = columnOf(this);
137
+ return at === undefined ? undefined : { range: [at, at], run: cursor => onVisit(cursor, at) };
138
+ }
139
+ }
@@ -0,0 +1,15 @@
1
+ import type { PlaybackTransform } from "../../playback/types.js";
2
+ interface OrnamentPattern {
3
+ /** 调内音级偏移序列,0 表示本音 */
4
+ readonly body: readonly number[];
5
+ /** 主体是否重复到填满宿主时值 */
6
+ readonly repeat?: boolean;
7
+ }
8
+ /**
9
+ * 把一个音按固定音级模式展开成装饰音序列
10
+ *
11
+ * 密度按发声时的速度决定而不是固定的记谱时值:固定 1/8 四分音符在慢速下
12
+ * 每秒只有两三次,听起来根本不是颤音。默认速度下仍然恰好是 1/8 四分音符。
13
+ */
14
+ export declare function ornament(pattern: OrnamentPattern): PlaybackTransform;
15
+ export {};
@@ -0,0 +1,73 @@
1
+ /** 每个四分音符的名义子音数 */
2
+ const NOMINAL_RATE = 8;
3
+ /** 密度只在极端速度下偏离名义值:区间内 bpm 会在算式里精确抵消 */
4
+ const MIN_BPM = 60;
5
+ const MAX_BPM = 480;
6
+ /** 一个装饰音能展开的子音上限;防的是 `@tempo(0.01)` 这类手滑 */
7
+ const MAX_SUBNOTES = 256;
8
+ /**
9
+ * 把一个音按固定音级模式展开成装饰音序列
10
+ *
11
+ * 密度按发声时的速度决定而不是固定的记谱时值:固定 1/8 四分音符在慢速下
12
+ * 每秒只有两三次,听起来根本不是颤音。默认速度下仍然恰好是 1/8 四分音符。
13
+ */
14
+ export function ornament(pattern) {
15
+ return (context, owned) => {
16
+ const noteOffs = new Map();
17
+ for (const event of owned) {
18
+ if (event.kind === "note-off")
19
+ noteOffs.set(event.noteId, event);
20
+ }
21
+ const removed = new Set();
22
+ const added = [];
23
+ for (const note of owned) {
24
+ if (note.kind !== "note-on" || !note.transpose)
25
+ continue;
26
+ const off = noteOffs.get(note.noteId);
27
+ if (!off)
28
+ continue;
29
+ const duration = off.at.clone().sub(note.at);
30
+ const bpm = context.stateAt(note.at).effectiveBpm;
31
+ const steps = pattern.repeat ? repeatToFill(pattern.body, duration.toNumber(), bpm) : pattern.body;
32
+ const step = duration.div(steps.length);
33
+ removed.add(note);
34
+ removed.add(off);
35
+ for (let index = 0; index < steps.length; index++) {
36
+ const offset = steps[index];
37
+ const noteId = context.nextNoteId();
38
+ const at = note.at.clone().add(step.clone().mul(index));
39
+ const order = note.order + index / steps.length;
40
+ const on = {
41
+ ...note,
42
+ at,
43
+ noteId,
44
+ order,
45
+ // 本音保留主体的临时升降号,只有偏移音才走调内换算
46
+ midi: offset === 0 ? note.midi : note.transpose(offset),
47
+ // 后续 ornament 要从这个派生音继续移调,不能仍以最初的宿主为基准
48
+ transpose: delta => note.transpose(offset + delta),
49
+ origins: [...note.origins],
50
+ sourceSpans: note.sourceSpans.map(span => ({ ...span })),
51
+ };
52
+ added.push(on, {
53
+ ...off,
54
+ at: at.clone().add(step),
55
+ noteId,
56
+ order,
57
+ origins: [...off.origins],
58
+ });
59
+ }
60
+ }
61
+ return [...owned.filter(event => !removed.has(event)), ...added];
62
+ };
63
+ }
64
+ function repeatToFill(body, duration, bpm) {
65
+ // 名义密度与速度无关(秒数里的 bpm 与频率里的 bpm 恰好抵消),只在 bpm 越界时按比例修正
66
+ const ratio = Math.min(MAX_BPM, Math.max(MIN_BPM, bpm)) / bpm;
67
+ const limit = Math.floor(MAX_SUBNOTES / body.length);
68
+ const cycles = Math.min(limit, Math.max(1, Math.round(duration * NOMINAL_RATE * ratio / body.length)));
69
+ const result = [];
70
+ for (let i = 0; i < cycles; i++)
71
+ result.push(...body);
72
+ return result;
73
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * 符号自身坐标系与布局坐标系之间的换算
3
+ *
4
+ * `symbolBounds` 量出图元在符号自身坐标系里的固有包围盒,布局据此定 box;
5
+ * `paintSymbol` 反过来把同一批图元放到最终 box 上。两者必须读同一份 bounds,
6
+ * 否则墨迹会偏出框——符号原点不一定落在墨迹左上角。
7
+ */
8
+ import type { LayoutBox, Rect } from "../../layout/types.js";
9
+ import type { PaintStyle, Painter, PathCommand } from "../../render/types.js";
10
+ /** 符号的一个图元;坐标在符号自身坐标系里,缩放由布局决定 */
11
+ export interface SymbolShape {
12
+ readonly path?: readonly PathCommand[];
13
+ readonly circle?: {
14
+ readonly cx: number;
15
+ readonly cy: number;
16
+ readonly r: number;
17
+ };
18
+ /** 横向偏移,用来把同一份字形重复拼成 ff、ppp 这类由字母组成的符号 */
19
+ readonly dx?: number;
20
+ readonly style: PaintStyle;
21
+ }
22
+ /** 全体图元的并集;宽高钳到正数,否则纯横线或纯竖线的符号会让缩放比例除零 */
23
+ export declare function symbolBounds(shapes: readonly SymbolShape[]): Rect;
24
+ export declare function paintSymbol(painter: Painter, shapes: readonly SymbolShape[], bounds: Rect, box: Readonly<LayoutBox>, scale: number): void;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * 符号自身坐标系与布局坐标系之间的换算
3
+ *
4
+ * `symbolBounds` 量出图元在符号自身坐标系里的固有包围盒,布局据此定 box;
5
+ * `paintSymbol` 反过来把同一批图元放到最终 box 上。两者必须读同一份 bounds,
6
+ * 否则墨迹会偏出框——符号原点不一定落在墨迹左上角。
7
+ */
8
+ import { pathBounds } from "../../layout/path.js";
9
+ /** 全体图元的并集;宽高钳到正数,否则纯横线或纯竖线的符号会让缩放比例除零 */
10
+ export function symbolBounds(shapes) {
11
+ let left = Infinity;
12
+ let top = Infinity;
13
+ let right = -Infinity;
14
+ let bottom = -Infinity;
15
+ const merge = (x, y, w, h) => {
16
+ left = Math.min(left, x);
17
+ top = Math.min(top, y);
18
+ right = Math.max(right, x + w);
19
+ bottom = Math.max(bottom, y + h);
20
+ };
21
+ for (const shape of shapes) {
22
+ const dx = shape.dx ?? 0;
23
+ if (shape.circle) {
24
+ const { cx, cy, r } = shape.circle;
25
+ merge(cx + dx - r, cy - r, 2 * r, 2 * r);
26
+ }
27
+ if (shape.path?.length) {
28
+ const rect = pathBounds(shape.path);
29
+ merge(rect.x + dx, rect.y, rect.w, rect.h);
30
+ }
31
+ }
32
+ return Number.isFinite(left)
33
+ ? { x: left, y: top, w: Math.max(1e-9, right - left), h: Math.max(1e-9, bottom - top) }
34
+ : { x: 0, y: 0, w: 1e-9, h: 1e-9 };
35
+ }
36
+ export function paintSymbol(painter, shapes, bounds, box, scale) {
37
+ const originX = box.x - bounds.x * scale;
38
+ const originY = box.y - bounds.y * scale;
39
+ for (const shape of shapes) {
40
+ const style = shape.style;
41
+ const scaled = style.strokeWidth === undefined
42
+ ? style
43
+ : { ...style, strokeWidth: style.strokeWidth * scale };
44
+ const x = originX + (shape.dx ?? 0) * scale;
45
+ if (shape.path) {
46
+ painter.drawPath(shape.path, scaled, { x, y: originY, scaleX: scale, scaleY: scale });
47
+ }
48
+ if (shape.circle) {
49
+ painter.drawCircle(x + shape.circle.cx * scale, originY + shape.circle.cy * scale, shape.circle.r * scale, scaled);
50
+ }
51
+ }
52
+ }
@@ -0,0 +1,2 @@
1
+ import type { SymbolDefinition } from "../index.js";
2
+ export declare const accentSymbol: SymbolDefinition;
@@ -0,0 +1,24 @@
1
+ const ACCENT_BOOST = 20;
2
+ const MAX_VELOCITY = 127;
3
+ export const accentSymbol = {
4
+ name: "accent",
5
+ description: "重音",
6
+ weight: 0.5,
7
+ shapes: [
8
+ {
9
+ path: [
10
+ { op: "M", x: 0.21413, y: 0.4818 },
11
+ { op: "L", x: 8.21413, y: 3.72071 },
12
+ { op: "L", x: 0.29494, y: 6.92724 },
13
+ ],
14
+ style: { stroke: "#000", strokeWidth: 1 },
15
+ },
16
+ ],
17
+ emitPlayback: emitter => emitter.affectFollowing((_context, events) => {
18
+ for (const event of events) {
19
+ if (event.kind === "note-on") {
20
+ event.velocity = Math.min(MAX_VELOCITY, event.velocity + ACCENT_BOOST);
21
+ }
22
+ }
23
+ }),
24
+ };
@@ -0,0 +1,4 @@
1
+ import type { SymbolDefinition } from "../index.js";
2
+ /** 回跳点;`$fine` 靠它判断整曲是否已经回过一次头 */
3
+ export declare const JUMP_MARK = "repeat.jump";
4
+ export declare const dcSymbol: SymbolDefinition;
@@ -0,0 +1,82 @@
1
+ /** 回跳点;`$fine` 靠它判断整曲是否已经回过一次头 */
2
+ export const JUMP_MARK = "repeat.jump";
3
+ export const dcSymbol = {
4
+ name: "dc",
5
+ description: "从头反复:跳回曲首再演一遍",
6
+ weight: 0.9,
7
+ shapes: [
8
+ {
9
+ path: [
10
+ { op: "M", x: 1.06974, y: 7.0752 },
11
+ { op: "L", x: 2.69184, y: 1.21499 },
12
+ { op: "C", cx1: 2.69184, cy1: 1.1221, cx2: 2.73825, cy2: 0.93022, x: 2.73825, y: 0.86039 },
13
+ { op: "C", cx1: 2.73825, cy1: 0.48248, cx2: 2.4825, cy2: 0.33152, x: 1.7614, y: 0.23838 },
14
+ { op: "L", x: 1.7614, y: 0.04641 },
15
+ { op: "L", x: 4.88344, y: 0.04641 },
16
+ { op: "C", cx1: 7.64477, cy1: 0.04641, cx2: 9.02278, cy2: 1.18018, x: 9.02278, y: 3.45323 },
17
+ { op: "C", cx1: 9.02278, cy1: 4.47649, cx2: 8.74941, cy2: 5.36592, x: 8.20888, y: 6.11596 },
18
+ { op: "C", cx1: 7.6681, cy1: 6.86578, cx2: 6.95303, cy2: 7.4297, x: 6.05765, y: 7.81334 },
19
+ { op: "C", cx1: 5.16823, cy1: 8.19125, cx2: 4.22074, cy2: 8.38316, x: 3.21493, y: 8.38316 },
20
+ { op: "L", x: 0, y: 8.38316 },
21
+ { op: "L", x: 0, y: 8.19119 },
22
+ { op: "C", cx1: 0.64542, cy1: 8.19126, cx2: 0.91275, cy2: 7.81343, x: 1.06974, y: 7.07521 },
23
+ { op: "L", x: 1.06974, y: 7.0752 },
24
+ { op: "Z" },
25
+ { op: "M", x: 4.09864, y: 0.66867 },
26
+ { op: "L", x: 2.2848, y: 7.35998 },
27
+ { op: "C", cx1: 2.2848, cy1: 7.42409, cx2: 2.26718, cy2: 7.48786, x: 2.23815, y: 7.55197 },
28
+ { op: "C", cx1: 2.29051, cy1: 7.84841, cx2: 2.58133, cy2: 7.99961, x: 3.12179, y: 7.99961 },
29
+ { op: "C", cx1: 3.97639, cy1: 7.99961, cx2: 4.74389, cy2: 7.79034, x: 5.42397, y: 7.37165 },
30
+ { op: "C", cx1: 6.10429, cy1: 6.94733, cx2: 6.62746, cy2: 6.37751, x: 7.00538, y: 5.65666 },
31
+ { op: "C", cx1: 7.3833, cy1: 4.92994, cx2: 7.5752, cy2: 4.1334, x: 7.5752, y: 3.26134 },
32
+ { op: "C", cx1: 7.5752, cy1: 1.372, cx2: 6.69156, cy2: 0.43029, x: 4.92984, y: 0.43029 },
33
+ { op: "C", cx1: 4.53471, cy1: 0.43029, cx2: 4.25555, cy2: 0.51151, x: 4.09864, y: 0.66869 },
34
+ { op: "L", x: 4.09864, y: 0.66867 },
35
+ { op: "Z" },
36
+ { op: "M", x: 18.35961, y: 0.04641 },
37
+ { op: "L", x: 17.90593, y: 2.62204 },
38
+ { op: "L", x: 17.66755, y: 2.62204 },
39
+ { op: "C", cx1: 17.563, cy1: 1.19183, cx2: 16.91187, cy2: 0.47678, x: 15.71418, y: 0.47678 },
40
+ { op: "C", cx1: 14.96437, cy1: 0.47678, cx2: 14.29564, cy2: 0.73848, x: 13.70274, y: 1.26165 },
41
+ { op: "C", cx1: 13.11556, cy1: 1.77911, cx2: 12.65617, cy2: 2.43578, x: 12.33664, y: 3.22668 },
42
+ { op: "C", cx1: 12.01679, cy1: 4.01155, cx2: 11.85988, cy2: 4.77302, x: 11.85988, y: 5.49984 },
43
+ { op: "C", cx1: 11.85988, cy1: 6.26131, cx2: 12.03424, cy2: 6.90076, x: 12.37734, y: 7.41814 },
44
+ { op: "C", cx1: 12.72598, cy1: 7.9356, cx2: 13.24931, cy2: 8.19126, x: 13.95279, y: 8.19126 },
45
+ { op: "C", cx1: 15.08622, cy1: 8.19126, cx2: 16.11543, cy2: 7.68548, x: 17.02818, y: 6.66825 },
46
+ { op: "L", x: 17.21412, y: 6.86023 },
47
+ { op: "C", cx1: 16.26663, cy1: 8.16232, cx2: 15.08051, cy2: 8.81352, x: 13.66775, y: 8.81352 },
48
+ { op: "C", cx1: 13.034, cy1: 8.81352, cx2: 12.47014, cy2: 8.65637, x: 11.97608, y: 8.34254 },
49
+ { op: "C", cx1: 11.48195, cy1: 8.02864, cx2: 11.10411, cy2: 7.60432, x: 10.83074, y: 7.06925 },
50
+ { op: "C", cx1: 10.56333, cy1: 6.53442, cx2: 10.42974, cy2: 5.94748, x: 10.42974, y: 5.31357 },
51
+ { op: "C", cx1: 10.42974, cy1: 4.43581, cx2: 10.67383, cy2: 3.58692, x: 11.15655, y: 2.7616 },
52
+ { op: "C", cx1: 11.63894, cy1: 1.93602, cx2: 12.28427, cy2: 1.26738, x: 13.09223, y: 0.76158 },
53
+ { op: "C", cx1: 13.90042, cy1: 0.25578, cx2: 14.74336, cy2: 0.00003, x: 15.62137, y: 0.00003 },
54
+ { op: "C", cx1: 15.88283, cy1: 0.00003, cx2: 16.12121, cy2: 0.0174, x: 16.33651, y: 0.0581 },
55
+ { op: "C", cx1: 16.55157, cy1: 0.09886, cx2: 16.79557, cy2: 0.15122, x: 17.05729, y: 0.21501 },
56
+ { op: "C", cx1: 17.31875, cy1: 0.2791, cx2: 17.51072, cy2: 0.31979, x: 17.62123, y: 0.33717 },
57
+ { op: "C", cx1: 17.85961, cy1: 0.2557, cx2: 18.03389, cy2: 0.15694, x: 18.14432, y: 0.04643 },
58
+ { op: "L", x: 18.35962, y: 0.04643 },
59
+ { op: "L", x: 18.35961, y: 0.04644 },
60
+ { op: "Z" },
61
+ { op: "M", x: 8.19134, y: 7.69151 },
62
+ { op: "C", cx1: 8.19134, cy1: 7.5169, cx2: 8.25544, cy2: 7.36596, x: 8.38894, y: 7.2322 },
63
+ { op: "C", cx1: 8.52277, cy1: 7.09838, cx2: 8.69134, cy2: 7.0288, x: 8.88332, y: 7.0288 },
64
+ { op: "C", cx1: 9.0519, cy1: 7.0288, cx2: 9.19722, cy2: 7.09838, x: 9.3251, y: 7.2322 },
65
+ { op: "C", cx1: 9.45893, cy1: 7.36603, cx2: 9.5227, cy2: 7.52294, x: 9.5227, y: 7.69151 },
66
+ { op: "C", cx1: 9.5227, cy1: 8.0925, cx2: 9.23221, cy2: 8.38324, x: 8.88332, y: 8.38324 },
67
+ { op: "C", cx1: 8.48803, cy1: 8.38324, cx2: 8.19134, cy2: 8.10416, x: 8.19134, y: 7.69151 },
68
+ { op: "Z" },
69
+ { op: "M", x: 18.00469, y: 7.79028 },
70
+ { op: "C", cx1: 18.00469, cy1: 7.40068, cx2: 18.27814, cy2: 7.12162, x: 18.64432, y: 7.12162 },
71
+ { op: "C", cx1: 19.03969, cy1: 7.12162, cx2: 19.31298, cy2: 7.39507, x: 19.31298, y: 7.79028 },
72
+ { op: "C", cx1: 19.31298, cy1: 8.15653, cx2: 19.0339, cy2: 8.42965, x: 18.64432, y: 8.42965 },
73
+ { op: "C", cx1: 18.28972, cy1: 8.42965, cx2: 18.00469, cy2: 8.14486, x: 18.00469, y: 7.79028 },
74
+ { op: "Z" },
75
+ ],
76
+ style: { fill: "#000" },
77
+ },
78
+ ],
79
+ // 只在第一次到达时回跳,第二次经过就正常收尾,所以整首曲子恰好演两遍
80
+ playbackMarks: () => [JUMP_MARK],
81
+ onVisit: (cursor, at) => cursor.visits(at) > 1 ? undefined : { kind: "jump", column: 0 },
82
+ };
@@ -0,0 +1,2 @@
1
+ import type { SymbolDefinition } from "../index.js";
2
+ export declare const dsSymbol: SymbolDefinition;
@@ -0,0 +1,93 @@
1
+ import { JUMP_MARK } from "./dc.js";
2
+ import { SEGNO_MARK } from "./segno.js";
3
+ export const dsSymbol = {
4
+ name: "ds",
5
+ description: "从记号处反复:跳回最近的 $segno",
6
+ weight: 0.9,
7
+ shapes: [
8
+ {
9
+ path: [
10
+ { op: "M", x: 3.30971, y: 8.58253 },
11
+ { op: "L", x: 0, y: 8.58253 },
12
+ { op: "L", x: 0, y: 8.38492 },
13
+ { op: "C", cx1: 0.66434, cy1: 8.38492, cx2: 0.93964, cy2: 7.9959, x: 1.10119, y: 7.23595 },
14
+ { op: "L", x: 2.77112, y: 1.20293 },
15
+ { op: "C", cx1: 2.77112, cy1: 1.10732, cx2: 2.81892, cy2: 0.90973, x: 2.81892, y: 0.83791 },
16
+ { op: "C", cx1: 2.81892, cy1: 0.44886, cx2: 2.55564, cy2: 0.29345, x: 1.81333, y: 0.19758 },
17
+ { op: "L", x: 1.81333, y: 0 },
18
+ { op: "L", x: 5.02743, y: 0 },
19
+ { op: "C", cx1: 7.87013, cy1: 0, cx2: 9.28879, cy2: 1.16713, x: 9.28879, y: 3.50729 },
20
+ { op: "C", cx1: 9.28879, cy1: 4.56066, cx2: 9.00736, cy2: 5.47632, x: 8.45088, y: 6.24853 },
21
+ { op: "C", cx1: 7.89416, cy1: 7.02049, cx2: 7.15799, cy2: 7.60099, x: 6.23624, y: 7.9959 },
22
+ { op: "C", cx1: 5.32063, cy1: 8.38492, cx2: 4.34519, cy2: 8.58253, x: 3.3097, y: 8.58253 },
23
+ { op: "L", x: 3.30971, y: 8.58253 },
24
+ { op: "Z" },
25
+ { op: "M", x: 4.21944, y: 0.64057 },
26
+ { op: "L", x: 2.35218, y: 7.52917 },
27
+ { op: "C", cx1: 2.35218, cy1: 7.59509, cx2: 2.33403, cy2: 7.66079, x: 2.30413, y: 7.72673 },
28
+ { op: "C", cx1: 2.35806, cy1: 8.03196, cx2: 2.65738, cy2: 8.18763, x: 3.21387, y: 8.18763 },
29
+ { op: "C", cx1: 4.71023, cy1: 8.18763, cx2: 5.84745, cy2: 7.75053, x: 6.6253, y: 6.88271 },
30
+ { op: "C", cx1: 7.40952, cy1: 6.00899, cx2: 7.79857, cy2: 4.81807, x: 7.79857, y: 3.30973 },
31
+ { op: "C", cx1: 7.79857, cy1: 1.36475, cx2: 6.88883, cy2: 0.39519, x: 5.07525, y: 0.39519 },
32
+ { op: "C", cx1: 4.66831, cy1: 0.39517, cx2: 4.38101, cy2: 0.47876, x: 4.21945, y: 0.64056 },
33
+ { op: "L", x: 4.21944, y: 0.64056 },
34
+ { op: "Z" },
35
+ { op: "M", x: 17.3325, y: 0.00001 },
36
+ { op: "L", x: 16.81794, y: 2.54976 },
37
+ { op: "L", x: 16.57254, y: 2.54976 },
38
+ { op: "C", cx1: 16.57254, cy1: 1.14312, cx2: 16.03984, cy2: 0.44299, x: 14.98033, y: 0.44299 },
39
+ { op: "C", cx1: 14.57337, cy1: 0.44299, cx2: 14.24416, cy2: 0.56262, x: 13.98698, y: 0.80212 },
40
+ { op: "C", cx1: 13.72958, cy1: 1.04139, cx2: 13.60383, cy2: 1.35272, x: 13.60383, y: 1.74176 },
41
+ { op: "C", cx1: 13.60383, cy1: 2.10677, cx2: 13.70556, cy2: 2.424, x: 13.91516, y: 2.70518 },
42
+ { op: "C", cx1: 14.12452, cy1: 2.98048, cx2: 14.45375, cy2: 3.34575, x: 14.91464, y: 3.7946 },
43
+ { op: "C", cx1: 15.37551, cy1: 4.24346, cx2: 15.72261, cy2: 4.65626, x: 15.9619, y: 5.03332 },
44
+ { op: "C", cx1: 16.20729, cy1: 5.40444, cx2: 16.32715, cy2: 5.83541, x: 16.32715, y: 6.32621 },
45
+ { op: "C", cx1: 16.35708, cy1: 7.82844, cx2: 15.01635, cy2: 8.89386, x: 13.70558, y: 8.87572 },
46
+ { op: "C", cx1: 13.47219, cy1: 8.87572, cx2: 13.12508, cy2: 8.79188, x: 12.65219, y: 8.63033 },
47
+ { op: "C", cx1: 12.17955, cy1: 8.46874, cx2: 11.86231, cy2: 8.38489, x: 11.69463, y: 8.38489 },
48
+ { op: "C", cx1: 11.45538, cy1: 8.38489, cx2: 11.25778, cy2: 8.60652, x: 11.20385, y: 8.82787 },
49
+ { op: "L", x: 10.95848, y: 8.82787 },
50
+ { op: "L", x: 11.40145, y: 6.00895 },
51
+ { op: "L", x: 11.69464, y: 6.00895 },
52
+ { op: "C", cx1: 11.69464, cy1: 6.12272, cx2: 11.67678, cy2: 6.24847, x: 11.64684, y: 6.374 },
53
+ { op: "C", cx1: 11.67065, cy1: 6.93075, cx2: 11.85619, cy2: 7.40948, x: 12.20332, y: 7.82232 },
54
+ { op: "C", cx1: 12.55657, cy1: 8.22948, cx2: 13.00544, cy2: 8.43297, x: 13.55603, y: 8.43297 },
55
+ { op: "C", cx1: 14.02891, cy1: 8.43297, cx2: 14.42384, cy2: 8.26529, x: 14.74108, y: 7.92405 },
56
+ { op: "C", cx1: 15.06418, cy1: 7.58305, cx2: 15.22573, cy2: 7.18198, x: 15.22573, y: 6.72112 },
57
+ { op: "C", cx1: 15.22573, cy1: 6.34406, cx2: 15.11223, cy2: 6.00313, x: 14.89062, y: 5.69764 },
58
+ { op: "C", cx1: 14.66925, cy1: 5.39246, cx2: 14.32802, cy2: 5.00951, x: 13.85538, y: 4.54279 },
59
+ { op: "C", cx1: 13.38247, cy1: 4.07579, cx2: 13.03535, cy2: 3.67473, x: 12.80197, y: 3.33374 },
60
+ { op: "C", cx1: 12.56858, cy1: 2.99248, cx2: 12.45484, cy2: 2.59756, x: 12.45484, y: 2.16072 },
61
+ { op: "C", cx1: 12.45484, cy1: 1.53216, cx2: 12.67621, cy2: 1.01761, x: 13.12509, y: 0.61042 },
62
+ { op: "C", cx1: 13.57395, cy1: 0.20348, cx2: 14.11864, cy2: 0.00002, x: 14.75896, y: 0.00002 },
63
+ { op: "C", cx1: 15.18993, cy1: 0.00002, cx2: 15.55495, cy2: 0.05983, x: 15.86016, y: 0.17358 },
64
+ { op: "C", cx1: 16.16536, cy1: 0.28733, cx2: 16.38697, cy2: 0.34714, x: 16.52452, y: 0.34714 },
65
+ { op: "C", cx1: 16.6922, cy1: 0.34714, cx2: 16.86576, cy2: 0.23339, x: 17.03932, y: 0.00002 },
66
+ { op: "L", x: 17.33249, y: 0.00002 },
67
+ { op: "L", x: 17.3325, y: 0.00001 },
68
+ { op: "Z" },
69
+ { op: "M", x: 8.43275, y: 7.87042 },
70
+ { op: "C", cx1: 8.43275, cy1: 7.69072, cx2: 8.4987, cy2: 7.5353, x: 8.63622, y: 7.3975 },
71
+ { op: "C", cx1: 8.774, cy1: 7.25976, cx2: 8.94755, cy2: 7.18816, x: 9.14514, y: 7.18816 },
72
+ { op: "C", cx1: 9.3187, cy1: 7.18816, cx2: 9.46824, cy2: 7.25975, x: 9.59988, y: 7.3975 },
73
+ { op: "C", cx1: 9.73766, cy1: 7.53529, cx2: 9.80338, cy2: 7.69685, x: 9.80338, y: 7.87042 },
74
+ { op: "C", cx1: 9.80338, cy1: 8.28325, cx2: 9.5043, cy2: 8.58254, x: 9.14514, y: 8.58254 },
75
+ { op: "C", cx1: 8.7382, cy1: 8.58254, cx2: 8.43275, cy2: 8.29521, x: 8.43275, y: 7.87042 },
76
+ { op: "Z" },
77
+ { op: "M", x: 16.88952, y: 7.9721 },
78
+ { op: "C", cx1: 16.88952, cy1: 7.57106, cx2: 17.21875, cy2: 7.28373, x: 17.62569, y: 7.28373 },
79
+ { op: "C", cx1: 18.00297, cy1: 7.28373, cx2: 18.29003, cy2: 7.56516, x: 18.29003, y: 7.9721 },
80
+ { op: "C", cx1: 18.29003, cy1: 8.34914, cx2: 17.99096, cy2: 8.63036, x: 17.62569, y: 8.63036 },
81
+ { op: "C", cx1: 17.42219, cy1: 8.63036, cx2: 17.24863, cy2: 8.56461, x: 17.105, y: 8.43887 },
82
+ { op: "C", cx1: 16.96135, cy1: 8.31309, cx2: 16.88952, cy2: 8.1577, x: 16.88952, y: 7.9721 },
83
+ { op: "Z" },
84
+ ],
85
+ style: { fill: "#000" },
86
+ },
87
+ ],
88
+ // 只在第一次到达时回跳;没有 $segno 时退回曲首,与 D.C. 一致
89
+ playbackMarks: () => [JUMP_MARK],
90
+ onVisit: (cursor, at) => cursor.visits(at) > 1
91
+ ? undefined
92
+ : { kind: "jump", column: cursor.seek(SEGNO_MARK, at, -1) ?? 0 },
93
+ };
@@ -0,0 +1,3 @@
1
+ import type { SymbolDefinition } from "../index.js";
2
+ /** 力度阶梯是 16 的整数倍,末级钳到 127;mf 恰好等于 DEFAULT_VELOCITY */
3
+ export declare const dynamicSymbols: readonly SymbolDefinition[];