jpfun 0.6.0 → 0.8.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 (134) hide show
  1. package/Bravura-LICENSE.txt +93 -0
  2. package/README.md +49 -146
  3. package/dist/Bravura-LICENSE.txt +93 -0
  4. package/dist/converter/midi/convert.d.ts +3 -11
  5. package/dist/converter/midi/convert.js +89 -67
  6. package/dist/converter/musicxml/features.d.ts +34 -12
  7. package/dist/converter/musicxml/features.js +131 -24
  8. package/dist/converter/musicxml/index.js +221 -54
  9. package/dist/converter/musicxml/model.d.ts +24 -0
  10. package/dist/core.d.ts +1 -0
  11. package/dist/core.js +1 -0
  12. package/dist/diagnostic.d.ts +7 -1
  13. package/dist/diagnostic.js +40 -88
  14. package/dist/fraction.js +3 -2
  15. package/dist/functions/ASTtypes.d.ts +2 -18
  16. package/dist/functions/ASTtypes.js +0 -16
  17. package/dist/functions/arpeggio/index.js +17 -22
  18. package/dist/functions/arpeggio/shape.d.ts +1 -1
  19. package/dist/functions/arpeggio/shape.js +27 -21
  20. package/dist/functions/bar/index.d.ts +8 -0
  21. package/dist/functions/bar/index.js +139 -36
  22. package/dist/functions/beam/auto.d.ts +1 -2
  23. package/dist/functions/beam/auto.js +44 -27
  24. package/dist/functions/beam/index.js +2 -3
  25. package/dist/functions/beam/layout.d.ts +1 -1
  26. package/dist/functions/beam/layout.js +16 -24
  27. package/dist/functions/br/index.d.ts +34 -2
  28. package/dist/functions/br/index.js +8 -8
  29. package/dist/functions/dash/index.js +6 -6
  30. package/dist/functions/default.js +10 -5
  31. package/dist/functions/div/index.d.ts +1 -0
  32. package/dist/functions/div/index.js +8 -4
  33. package/dist/functions/dot/index.js +2 -2
  34. package/dist/functions/dyn/index.js +49 -31
  35. package/dist/functions/gliss/index.d.ts +2 -0
  36. package/dist/functions/gliss/index.js +202 -0
  37. package/dist/functions/grace/index.d.ts +1 -7
  38. package/dist/functions/grace/index.js +11 -19
  39. package/dist/functions/head/index.js +41 -60
  40. package/dist/functions/key/index.js +8 -10
  41. package/dist/functions/meter/index.d.ts +56 -1
  42. package/dist/functions/meter/index.js +30 -24
  43. package/dist/functions/note/accidentals.js +10 -16
  44. package/dist/functions/note/index.js +18 -8
  45. package/dist/functions/note/noteName.d.ts +16 -0
  46. package/dist/functions/note/noteName.js +88 -0
  47. package/dist/functions/note/source-transform.js +6 -5
  48. package/dist/functions/ottava/index.d.ts +2 -0
  49. package/dist/functions/ottava/index.js +233 -0
  50. package/dist/functions/page/index.d.ts +1 -0
  51. package/dist/functions/page/index.js +22 -13
  52. package/dist/functions/pagebreak/index.d.ts +2 -0
  53. package/dist/functions/pagebreak/index.js +36 -0
  54. package/dist/functions/rest/index.js +15 -15
  55. package/dist/functions/set/index.js +4 -4
  56. package/dist/functions/slide/index.d.ts +2 -0
  57. package/dist/functions/slide/index.js +132 -0
  58. package/dist/functions/stack/index.js +8 -15
  59. package/dist/functions/symbol/index.d.ts +30 -2
  60. package/dist/functions/symbol/index.js +93 -19
  61. package/dist/functions/symbol/ornament.d.ts +1 -2
  62. package/dist/functions/symbol/ornament.js +14 -19
  63. package/dist/functions/symbol/shape.d.ts +6 -0
  64. package/dist/functions/symbol/shape.js +20 -4
  65. package/dist/functions/symbol/symbols/coda.d.ts +4 -0
  66. package/dist/functions/symbol/symbols/coda.js +56 -0
  67. package/dist/functions/symbol/symbols/dynamics.d.ts +1 -1
  68. package/dist/functions/symbol/symbols/dynamics.js +18 -8
  69. package/dist/functions/symbol/symbols/fine.js +1 -1
  70. package/dist/functions/symbol/symbols/harmonic.d.ts +2 -0
  71. package/dist/functions/symbol/symbols/harmonic.js +11 -0
  72. package/dist/functions/symbol/symbols/marcato.d.ts +2 -0
  73. package/dist/functions/symbol/symbols/marcato.js +22 -0
  74. package/dist/functions/symbol/symbols/staccato.d.ts +2 -0
  75. package/dist/functions/symbol/symbols/staccato.js +24 -0
  76. package/dist/functions/symbol/symbols/tenuto.d.ts +2 -0
  77. package/dist/functions/symbol/symbols/tenuto.js +11 -0
  78. package/dist/functions/symbol/symbols/tocoda.d.ts +2 -0
  79. package/dist/functions/symbol/symbols/tocoda.js +16 -0
  80. package/dist/functions/symbol/symbols/tr.js +46 -1
  81. package/dist/functions/symbol/symbols/turn.d.ts +3 -0
  82. package/dist/functions/symbol/symbols/turn.js +50 -0
  83. package/dist/functions/symbol/symbols/wheel.d.ts +2 -0
  84. package/dist/functions/symbol/symbols/wheel.js +36 -0
  85. package/dist/functions/temporal.d.ts +17 -6
  86. package/dist/functions/temporal.js +17 -6
  87. package/dist/functions/text/index.js +15 -6
  88. package/dist/functions/tie/index.js +64 -30
  89. package/dist/functions/tremolo/index.d.ts +2 -0
  90. package/dist/functions/tremolo/index.js +319 -0
  91. package/dist/functions/tuplet/index.js +4 -8
  92. package/dist/functions/up/index.js +7 -9
  93. package/dist/functions/voice/connections.js +7 -5
  94. package/dist/functions/voice/index.js +19 -11
  95. package/dist/functions/volta/index.js +41 -21
  96. package/dist/jpfun.core.min.js +64 -80
  97. package/dist/jpfun.from-midi.min.js +5 -5
  98. package/dist/jpfun.from-musicxml.min.js +8 -8
  99. package/dist/jpfun.min.js +69 -85
  100. package/dist/layout/default.d.ts +0 -1
  101. package/dist/layout/default.js +0 -1
  102. package/dist/layout/engine.d.ts +1 -0
  103. package/dist/layout/engine.js +42 -11
  104. package/dist/layout/page.d.ts +3 -2
  105. package/dist/layout/page.js +6 -5
  106. package/dist/layout/types.d.ts +4 -0
  107. package/dist/lowering/loweringContext.d.ts +11 -13
  108. package/dist/lowering/loweringContext.js +30 -197
  109. package/dist/lowering/types.d.ts +1 -3
  110. package/dist/parser/parse-utils/note-utils.d.ts +1 -1
  111. package/dist/parser/parse-utils/note-utils.js +8 -9
  112. package/dist/parser/parse-utils/string-utils.d.ts +3 -2
  113. package/dist/parser/parse-utils/string-utils.js +16 -3
  114. package/dist/parser/parserContext.d.ts +2 -0
  115. package/dist/parser/parserContext.js +36 -8
  116. package/dist/pipeline.js +0 -1
  117. package/dist/playback/compile.js +131 -72
  118. package/dist/playback/event.d.ts +1 -1
  119. package/dist/playback/event.js +9 -9
  120. package/dist/playback/time.js +42 -31
  121. package/dist/playback/types.d.ts +7 -3
  122. package/dist/render/canvas.d.ts +2 -0
  123. package/dist/render/canvas.js +25 -22
  124. package/dist/render/recording.js +1 -4
  125. package/dist/render/svg.js +1 -0
  126. package/dist/render/text.d.ts +1 -1
  127. package/dist/render/text.js +3 -2
  128. package/dist/render/translate.d.ts +0 -1
  129. package/dist/render/translate.js +6 -23
  130. package/dist/render/types.d.ts +1 -0
  131. package/grammar.md +52 -25
  132. package/package.json +3 -3
  133. package/dist/functions/note/noteNameFSM.d.ts +0 -8
  134. package/dist/functions/note/noteNameFSM.js +0 -181
@@ -1,3 +1,4 @@
1
+ const PLACEHOLDER_RE = /\{(\w+)\}/g;
1
2
  export class Diagnostic {
2
3
  /** 诊断代码 */
3
4
  code;
@@ -5,10 +6,24 @@ export class Diagnostic {
5
6
  message;
6
7
  /** 诊断位置,指示问题在源代码中的位置 */
7
8
  span;
8
- constructor(code, message, span) {
9
+ /** 诊断消息中的结构化参数(构造时复制并字符串化,不修改或持有原对象) */
10
+ params;
11
+ // 多语言支持:仅需要替换此函数
12
+ static format(code, message, params) {
13
+ return params
14
+ ? message.replace(PLACEHOLDER_RE, (match, k) => Object.hasOwn(params, k) ? params[k] : match)
15
+ : message;
16
+ }
17
+ constructor(code, message, span, params) {
9
18
  this.code = code;
10
- this.message = message;
11
19
  this.span = span;
20
+ if (params) {
21
+ const dict = {};
22
+ for (const key of Object.keys(params))
23
+ dict[key] = String(params[key]);
24
+ this.params = dict;
25
+ }
26
+ this.message = Diagnostic.format(code, message, this.params);
12
27
  }
13
28
  toLineCol(lineStarts) {
14
29
  const start = Diagnostic.offsetToLineCol(this.span.start, lineStarts);
@@ -47,98 +62,35 @@ export class Diagnostic {
47
62
  static error;
48
63
  static warning;
49
64
  }
65
+ const formatArg = (arg) => typeof arg === "number" ? `[${arg}]` : `"${arg}"`;
50
66
  // 两个基类区分 Warning 和 Error
51
67
  export class ErrorDiagnostic extends Diagnostic {
52
68
  }
53
- ;
54
69
  export class WarningDiagnostic extends Diagnostic {
55
70
  }
56
- ;
57
71
  Diagnostic.error = {
58
- Bug: (message, span) => {
59
- return new ErrorDiagnostic("E_BUG", `解析器错误: ${message},请联系开发者修复这个问题`, span);
60
- },
61
- MissingArg: (functionName, argumentName, span) => {
62
- const argname = typeof argumentName === "number" ? `[${argumentName}]` : `"${argumentName}"`;
63
- return new ErrorDiagnostic("E_MISSING_REQUIRED_ARG", `函数@${functionName} 缺少必需的参数 ${argname}`, span);
64
- },
65
- InvalidArgType: (functionName, argumentName, expectedType, actualType, span) => {
66
- const argname = typeof argumentName === "number" ? `[${argumentName}]` : `"${argumentName}"`;
67
- return new ErrorDiagnostic("E_WRONG_ARG_TYPE", `函数 @${functionName} 的参数 ${argname} 类型错误: 得到了 ${actualType},但期望 ${expectedType}`, span);
68
- },
69
- PosAfterNamedArg: (functionName, span) => {
70
- return new ErrorDiagnostic("E_POSARG_AFTER_KWARG", `函数 @${functionName} 的位置参数出现在命名参数之后,这是不允许的`, span);
71
- },
72
- EmptyContent: (functionName, argumentName, span) => {
73
- const argname = typeof argumentName === "number" ? `[${argumentName}]` : `"${argumentName}"`;
74
- return new ErrorDiagnostic("E_EMPTY_CONTENT", `函数 @${functionName} 的参数 ${argname} 内容为空(或无可用内容);请提供有效内容`, span);
75
- },
76
- UnterminatedCall: (functionName, span) => {
77
- return new ErrorDiagnostic("E_UNTERMINATED_CALL", `函数调用未闭合: @${functionName}(...)`, span);
78
- },
79
- UnterminatedString: (span) => {
80
- return new ErrorDiagnostic("E_UNTERMINATED_String", `引号未闭合`, span);
81
- },
82
- UnknownFunction: (functionName, span) => {
83
- return new ErrorDiagnostic("E_UNKNOWN_FUNCTION", `未知函数: @${functionName},请检查拼写`, span);
84
- },
85
- UnknownLabel: (labelName, span) => {
86
- return new ErrorDiagnostic("E_UNKNOWN_LABEL", `未知标签: "${labelName}"`, span);
87
- },
88
- InvalidTonality: (tonality, span) => {
89
- return new ErrorDiagnostic("E_INVALID_TONALITY", `无效的调性: "${tonality}",请提供有效的调性名称,必须 [一个大写字母][变音记号#bn只能一个][绝对八度数字],后二者可选`, span);
90
- },
91
- BreakInsideEvent: (span) => {
92
- return new ErrorDiagnostic("E_BREAK_INSIDE_EVENT", `换行切断了一个仍在持续的事件;请把长音写成多个事件,或调整 @br 的位置`, span);
93
- },
94
- InvalidPageConfig: (message, span) => {
95
- return new ErrorDiagnostic("E_INVALID_PAGE_CONFIG", message, span);
96
- },
97
- PageOverflow: (required, available, span) => {
98
- return new ErrorDiagnostic("E_PAGE_OVERFLOW", `谱面行需要 ${required}px 高度,但页面内容区只有 ${available}px`, span);
99
- }
72
+ Bug: (message, span) => new ErrorDiagnostic("E_BUG", "解析器错误: {message},请联系开发者修复这个问题", span, { message }),
73
+ MissingArg: (functionName, argumentName, span) => new ErrorDiagnostic("E_MISSING_REQUIRED_ARG", "函数@{fn} 缺少必需的参数 {arg}", span, { fn: functionName, arg: formatArg(argumentName) }),
74
+ PosAfterNamedArg: (functionName, span) => new ErrorDiagnostic("E_POSARG_AFTER_KWARG", "函数 @{fn} 的位置参数出现在命名参数之后,这是不允许的", span, { fn: functionName }),
75
+ EmptyContent: (functionName, argumentName, span) => new ErrorDiagnostic("E_EMPTY_CONTENT", "函数 @{fn} 的参数 {arg} 内容为空(或无可用内容);请提供有效内容", span, { fn: functionName, arg: formatArg(argumentName) }),
76
+ UnterminatedCall: (functionName, span) => new ErrorDiagnostic("E_UNTERMINATED_CALL", "函数调用未闭合: @{fn}(...)", span, { fn: functionName }),
77
+ UnknownFunction: (functionName, span) => new ErrorDiagnostic("E_UNKNOWN_FUNCTION", "未知函数: @{fn},请检查拼写", span, { fn: functionName }),
78
+ UnknownLabel: (labelName, span) => new ErrorDiagnostic("E_UNKNOWN_LABEL", '未知标签: "{label}"', span, { label: labelName }),
79
+ BreakInsideEvent: (span) => new ErrorDiagnostic("E_BREAK_INSIDE_EVENT", "换行或换页切断了一个仍在持续的事件;请把长音写成多个事件,或调整换行、换页的位置", span),
80
+ PageOverflow: (required, available, span) => new ErrorDiagnostic("E_PAGE_OVERFLOW", "谱面行需要 {required}px 高度,但页面内容区只有 {available}px", span, { required, available }),
100
81
  };
101
82
  Diagnostic.warning = {
102
- UnknownFunction: (functionName, span) => {
103
- return new WarningDiagnostic("W_UNKNOWN_FUNCTION", `未知函数: @${functionName},将被当作普通文本处理`, span);
104
- },
105
- UnknownNamedArg: (functionName, argumentName, span) => {
106
- return new WarningDiagnostic("W_UNKNOWN_NAMED_ARG", `函数 @${functionName} 收到未知的命名参数 "${argumentName}"`, span);
107
- },
108
- TooManyPosArgs: (functionName, expected, actual, span) => {
109
- return new WarningDiagnostic("W_TOO_MANY_POS_ARGS", `函数 @${functionName} 接收了过多的位置参数,期望 ${expected} 个但得到了 ${actual} 个`, span);
110
- },
111
- InvalidNumber: (value, span) => {
112
- return new WarningDiagnostic("W_INVALID_NUMBER", `无效的数字: "${value}";将使用默认值(若存在)`, span);
113
- },
114
- InvalidBoolean: (value, span) => {
115
- return new WarningDiagnostic("W_INVALID_BOOL", `无效的布尔值: "${value}": 应为 'true' 或 'false';将使用默认值(若存在)`, span);
116
- },
117
- InvalidLength: (value, span) => {
118
- return new WarningDiagnostic("W_INVALID_LENGTH", `无效的长度值: "${value}";请提供有效的长度值,例如 "10px" 或 "2em";将使用默认值(若存在)`, span);
119
- },
120
- InvalidLengthUnit: (unit, span) => {
121
- return new WarningDiagnostic("W_INVALID_LENGTH_UNIT", `无效的长度单位: "${unit}";仅支持 "px" 和 "em";请检查函数参数或变量定义;将使用默认值(若存在)`, span);
122
- },
123
- InvalidContent: (span) => {
124
- return new WarningDiagnostic("W_INVALID_CONTENT", `内容解析失败,错误原因见上;将使用默认值(但往往不存在,极有可能导致错误)`, span);
125
- },
126
- EmptyContent: (functionName, argumentName, span) => {
127
- return new WarningDiagnostic("W_EMPTY_CONTENT", `函数 @${functionName} 的参数 "${argumentName}" 内容为空(或无可用内容)`, span);
128
- },
129
- UnmatchedBrace: (span) => {
130
- return new WarningDiagnostic("W_UNMATCHED_BRACE", `未匹配的大括号: 缺少右大括号'}';将尝试自动修复`, span);
131
- },
132
- LabelWithoutTarget: (labelName, span) => {
133
- return new WarningDiagnostic("W_LABEL_WITHOUT_TARGET", `标签 "${labelName}" 没有可绑定的目标;标签将被忽略`, span);
134
- },
135
- TargetAlreadyLabeled: (newLabel, oldLabel, span) => {
136
- return new WarningDiagnostic("W_TARGET_ALREADY_LABELED", `目标已标注为 "${oldLabel}","${newLabel}" 将被忽略`, span);
137
- },
138
- UnresolvedEndpoint: (functionName, span) => {
139
- return new WarningDiagnostic("W_UNRESOLVED_ENDPOINT", `@${functionName} 有端点找不到对应的谱面对象;该关系将被忽略`, span);
140
- },
141
- ZeroTimeTrack: (span, trackOrder) => {
142
- return new WarningDiagnostic("W_ZERO_TIME_TRACK", `第${trackOrder}个子轨道的时长为0`, span);
143
- },
83
+ InvalidUnicodeEscape: (span) => new WarningDiagnostic("W_STRING_INVALID_UNICODE_ESCAPE", "无效的 Unicode 转义:请使用 \\uXXXX(四位十六进制数字);将保留该字符串原文", span),
84
+ UnknownFunction: (functionName, span) => new WarningDiagnostic("W_UNKNOWN_FUNCTION", "未知函数: @{fn},将被当作普通文本处理", span, { fn: functionName }),
85
+ TooManyPosArgs: (functionName, expected, actual, span) => new WarningDiagnostic("W_TOO_MANY_POS_ARGS", "函数 @{fn} 接收了过多的位置参数,期望 {expected} 个但得到了 {actual} 个", span, { fn: functionName, expected, actual }),
86
+ InvalidNumber: (value, span) => new WarningDiagnostic("W_INVALID_NUMBER", '无效的数字: "{value}";将使用默认值(若存在)', span, { value }),
87
+ InvalidBoolean: (value, span) => new WarningDiagnostic("W_INVALID_BOOL", '无效的布尔值: "{value}": 应为 \'true\' 或 \'false\';将使用默认值(若存在)', span, { value }),
88
+ InvalidLength: (value, span) => new WarningDiagnostic("W_INVALID_LENGTH", '无效的长度值: "{value}";请提供有效的长度值,例如 "10px" 或 "2em";将使用默认值(若存在)', span, { value }),
89
+ InvalidLengthUnit: (unit, span) => new WarningDiagnostic("W_INVALID_LENGTH_UNIT", '无效的长度单位: "{unit}";仅支持 "px" 和 "em";请检查函数参数或变量定义;将使用默认值(若存在)', span, { unit }),
90
+ InvalidContent: (span) => new WarningDiagnostic("W_INVALID_CONTENT", "内容解析失败,错误原因见上;将使用默认值(但往往不存在,极有可能导致错误)", span),
91
+ UnmatchedBrace: (span) => new WarningDiagnostic("W_UNMATCHED_BRACE", "未匹配的大括号: 缺少右大括号'}';将尝试自动修复", span),
92
+ LabelWithoutTarget: (labelName, span) => new WarningDiagnostic("W_LABEL_WITHOUT_TARGET", '标签 "{label}" 没有可绑定的目标;标签将被忽略', span, { label: labelName }),
93
+ TargetAlreadyLabeled: (newLabel, oldLabel, span) => new WarningDiagnostic("W_TARGET_ALREADY_LABELED", '目标已标注为 "{oldLabel}","{newLabel}" 将被忽略', span, { oldLabel, newLabel }),
94
+ UnresolvedEndpoint: (functionName, span) => new WarningDiagnostic("W_UNRESOLVED_ENDPOINT", "@{fn} 有端点找不到对应的谱面对象;该关系将被忽略", span, { fn: functionName }),
95
+ ZeroTimeTrack: (span, trackOrder) => new WarningDiagnostic("W_ZERO_TIME_TRACK", "第{track}个子轨道的时长为0", span, { track: trackOrder }),
144
96
  };
package/dist/fraction.js CHANGED
@@ -15,7 +15,8 @@ export class Fraction {
15
15
  _numerator = 0;
16
16
  _denominator = 1;
17
17
  constructor(numerator = 0, denominator = 1) {
18
- this.set(numerator, denominator);
18
+ if (numerator !== 0 || denominator !== 1)
19
+ this.set(numerator, denominator);
19
20
  }
20
21
  get numerator() {
21
22
  return this._numerator;
@@ -44,7 +45,7 @@ export class Fraction {
44
45
  return this;
45
46
  }
46
47
  clone() {
47
- return new Fraction(this._numerator, this._denominator);
48
+ return new Fraction().copyFrom(this);
48
49
  }
49
50
  add(value, denominator = 1) {
50
51
  let numerator;
@@ -2,7 +2,7 @@ import type { SourceSpan, LengthValue, deSugarAtomFunction, deSugarRelationFunct
2
2
  import type { CallArgumentInfo } from "../parser/grammarType.js";
3
3
  import type { ParserContext } from "../parser/parserContext.js";
4
4
  import type { Fraction } from "../fraction.js";
5
- import type { LoweringAugmenter, LoweringFinalizer, TimeFlowModel } from "../lowering/types.js";
5
+ import type { TimeFlowModel } from "../lowering/types.js";
6
6
  import type { TemporalNodeBase } from "./temporal.js";
7
7
  import type { LoweringContext } from "../lowering/loweringContext.js";
8
8
  import type { Track } from "../lowering/track.js";
@@ -101,22 +101,6 @@ export declare class ASTFunctionNode extends ASTNodeBase {
101
101
  get deSugarRelation(): deSugarRelationFunction;
102
102
  getArgValue(args: FunctionArgs, ctx: ParserContext): paramValue[];
103
103
  toString(source: string): string;
104
- /**
105
- * lowering 固化后的 attachment 生成钩子
106
- *
107
- * 普通 loweringEnter/loweringExit 在递归遍历 AST 时执行,
108
- * 此时尚未完成锚点归并,事件的 t、track 和 layoutLine 不可用,因此需要观察完整事件流的功能不能在普通 hook 中可靠决定分组。
109
- * 该 hook 读取 LoweringResult 并返回新建的 LoweringAttachment,LoweringContext 将返回值追加到当前文档或 fragment 的 attachments,不会把它们放入时间列或推进时间。
110
- *
111
- * 例:autobeam 扫描最终列,按轨道、谱面行、拍点和显式 beam 端点决定分组,再生成 BeamLayoutAttachment
112
- */
113
- static loweringAugment?: LoweringAugmenter;
114
- /**
115
- * 所有 loweringAugment 结果追加完成后的最终处理;此时已经得到了完整的 lowering 语义
116
- * 所有派生 attachment 追加完成后,按函数注册顺序处理完整结果
117
- * 可以进行校验(如 beam 和 tie)或者修改某些值
118
- */
119
- static loweringFinalize?: LoweringFinalizer;
120
104
  /**
121
105
  * 装饰函数可选的排版声明
122
106
  * layout 引擎按 key 收集,不需要识别具体函数类
@@ -136,4 +120,4 @@ export declare class ASTFunctionNode extends ASTNodeBase {
136
120
  */
137
121
  static findLastFuncContentIndex(nodes: ASTNodeBase[], i: number): number;
138
122
  }
139
- export type ASTFunctionClass = (new (sourceSpan: SourceSpan, args: FunctionArgs, ctx: ParserContext, parent: ASTNodeBase | null) => ASTFunctionNode) & Pick<typeof ASTFunctionNode, "prototype" | "def" | "deSugarAtom" | "deSugarRelation" | "loweringAugment" | "loweringFinalize" | "layoutDecorationHandler">;
123
+ export type ASTFunctionClass = (new (sourceSpan: SourceSpan, args: FunctionArgs, ctx: ParserContext, parent: ASTNodeBase | null) => ASTFunctionNode) & Pick<typeof ASTFunctionNode, "prototype" | "def" | "deSugarAtom" | "deSugarRelation" | "layoutDecorationHandler">;
@@ -162,22 +162,6 @@ export class ASTFunctionNode extends ASTNodeBase {
162
162
  return super.toString(source);
163
163
  return `@${name} `;
164
164
  }
165
- /**
166
- * lowering 固化后的 attachment 生成钩子
167
- *
168
- * 普通 loweringEnter/loweringExit 在递归遍历 AST 时执行,
169
- * 此时尚未完成锚点归并,事件的 t、track 和 layoutLine 不可用,因此需要观察完整事件流的功能不能在普通 hook 中可靠决定分组。
170
- * 该 hook 读取 LoweringResult 并返回新建的 LoweringAttachment,LoweringContext 将返回值追加到当前文档或 fragment 的 attachments,不会把它们放入时间列或推进时间。
171
- *
172
- * 例:autobeam 扫描最终列,按轨道、谱面行、拍点和显式 beam 端点决定分组,再生成 BeamLayoutAttachment
173
- */
174
- static loweringAugment;
175
- /**
176
- * 所有 loweringAugment 结果追加完成后的最终处理;此时已经得到了完整的 lowering 语义
177
- * 所有派生 attachment 追加完成后,按函数注册顺序处理完整结果
178
- * 可以进行校验(如 beam 和 tie)或者修改某些值
179
- */
180
- static loweringFinalize;
181
165
  /**
182
166
  * 装饰函数可选的排版声明
183
167
  * layout 引擎按 key 收集,不需要识别具体函数类
@@ -2,7 +2,7 @@ import { ErrorDiagnostic, WarningDiagnostic } from "../../diagnostic.js";
2
2
  import { Fraction } from "../../fraction.js";
3
3
  import { getLayoutBounds, prepareLayoutHost } from "../../layout/engine.js";
4
4
  import { ASTFunctionNode, } from "../ASTtypes.js";
5
- import { TemporalNodeBase } from "../temporal.js";
5
+ import { transferFunctionAddons, TemporalNodeBase } from "../temporal.js";
6
6
  import { prepareArpeggioShape } from "./shape.js";
7
7
  /** Fold 保持模块私有;琶音只在自己的边界读取它已经公开在实例上的结构。 */
8
8
  function readFold(node) {
@@ -79,7 +79,8 @@ class ArpeggioFunction extends ASTFunctionNode {
79
79
  export const ArpeggioNode = ArpeggioFunction;
80
80
  class ArpeggioTemporal extends TemporalNodeBase {
81
81
  host;
82
- playbackMembers;
82
+ /** 槽位取自成员顺序;无声成员也占槽,不能按实际发声音符重新编号 */
83
+ slots;
83
84
  hostX = 0;
84
85
  markX = 0;
85
86
  markCommands = [];
@@ -93,7 +94,8 @@ class ArpeggioTemporal extends TemporalNodeBase {
93
94
  host.members[0],
94
95
  ...host.members.slice(1, aboveCount),
95
96
  ];
96
- this.playbackMembers = ast.direction === "down" ? bottomToTop.reverse() : bottomToTop;
97
+ const members = ast.direction === "down" ? bottomToTop.reverse() : bottomToTop;
98
+ this.slots = new Map(members.map((member, index) => [member, index]));
97
99
  this.T.copyFrom(host.T);
98
100
  this.mergeKey = host.mergeKey;
99
101
  this.initLayoutBox();
@@ -115,10 +117,7 @@ class ArpeggioTemporal extends TemporalNodeBase {
115
117
  this.host.prepareHorizontal?.(line);
116
118
  }
117
119
  prepareLayout(context) {
118
- if (this.addon) {
119
- this.host.addon = this.addon;
120
- this.addon = void 0;
121
- }
120
+ transferFunctionAddons(this, this.host);
122
121
  prepareLayoutHost(this.host, context);
123
122
  this.springConfig = { ...this.host.springConfig, ...this.springConfig };
124
123
  const em = this.ast.size;
@@ -152,28 +151,24 @@ class ArpeggioTemporal extends TemporalNodeBase {
152
151
  const total = emitter.end.clone().sub(emitter.start);
153
152
  const step = new Fraction(1, 8);
154
153
  // 短音段限制总延迟,让最后一个成员仍保留至少一半的宿主窗口。
155
- const maxStep = total.clone().div(2).div(this.playbackMembers.length - 1);
154
+ const maxStep = total.clone().div(2).div(this.slots.size - 1);
156
155
  if (step.compare(maxStep) > 0)
157
156
  step.copyFrom(maxStep);
158
- // 槽位取自成员顺序;无声成员也占槽,不能按实际发声音符重新编号。
159
- const slots = new Map(this.playbackMembers.map((member, index) => [member, index]));
157
+ const { slots } = this;
160
158
  const owner = this;
161
159
  emitter.defer(context => {
162
160
  let rootOrigin;
163
- // 反向锁定最近一次宿主访问的来源身份,避免修改前一遍反复留下的区间。
161
+ // 宿主刚在上面发布,其全部子区间连续排在 spans 末尾;命中后处理完同组即停。
164
162
  for (let index = context.spans.length - 1; index >= 0; index--) {
165
163
  const note = context.spans[index];
166
- if (!note.origins.some(origin => origin.node === owner))
167
- continue;
168
- rootOrigin = note.origins[0];
169
- break;
170
- }
171
- if (!rootOrigin)
172
- return;
173
- // 先限制到同一次顶层访问,再由成员来源筛出本宿主的全部有声、无声子区间。
174
- for (const note of context.spans) {
175
- if (note.origins[0] !== rootOrigin)
176
- continue;
164
+ if (!rootOrigin) {
165
+ if (!note.origins.some(origin => origin.node === owner))
166
+ continue;
167
+ rootOrigin = note.origins[0];
168
+ }
169
+ else if (note.origins[0] !== rootOrigin) {
170
+ break;
171
+ }
177
172
  const member = note.origins.find(origin => slots.has(origin.node))?.node;
178
173
  const slot = member ? slots.get(member) : undefined;
179
174
  if (!slot)
@@ -1,6 +1,6 @@
1
1
  import type { Rect } from "../../layout/types.js";
2
2
  import type { PathCommand } from "../../render/types.js";
3
- /** 按 MuseScore 的原始重叠比例铺满指定高度,并一次性返回最终边界。 */
3
+ /** 按 MuseScore 的原始重叠比例铺满指定高度,并一次性返回最终边界 */
4
4
  export declare function prepareArpeggioShape(height: number, em: number, direction: "" | "up" | "down"): {
5
5
  commands: PathCommand[];
6
6
  bounds: Rect;
@@ -6,7 +6,7 @@ const ARROW_HEIGHT = 93.6719;
6
6
  const ARROW_X = -27.4688;
7
7
  const ARROW_Y = -7.9375;
8
8
  const ARROW_BOTTOM = ARROW_Y + ARROW_HEIGHT;
9
- /** MuseScore 4.7.4 导出的琶音波形块,已旋转到自上而下的局部坐标。 */
9
+ /** MuseScore 4.7.4 导出的琶音波形块,已旋转到自上而下的局部坐标 */
10
10
  const TILE = [
11
11
  { op: "M", x: 28.1406, y: 86.06255 },
12
12
  { op: "C", cx1: 28.1406, cy1: 86.06255, cx2: 30.4531, cy2: 84.07815, x: 32.7656, y: 81.42185 },
@@ -60,9 +60,9 @@ const DOWN_ARROW = [
60
60
  { op: "C", cx1: 58.9063, cy1: 93.6719, cx2: 61.8907, cy2: 92.3438, x: 63.2188, y: 90.3594 },
61
61
  { op: "L", x: 111.8751, y: 21.5156 },
62
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;
63
+ function appendShape(output, shape, offsetX, offsetY, scale, reverse) {
64
+ const x = (value) => offsetX + (reverse ? TILE_WIDTH - value : value) * scale;
65
+ const y = (value) => offsetY + (reverse ? TILE_HEIGHT - value : value) * scale;
66
66
  for (const command of shape) {
67
67
  if (command.op === "Z")
68
68
  output.push(command);
@@ -83,7 +83,7 @@ function appendShape(output, shape, width, height, offsetX, offsetY, scale, reve
83
83
  output.push({ op: command.op, x: x(command.x), y: y(command.y) });
84
84
  }
85
85
  }
86
- /** 按 MuseScore 的原始重叠比例铺满指定高度,并一次性返回最终边界。 */
86
+ /** 按 MuseScore 的原始重叠比例铺满指定高度,并一次性返回最终边界 */
87
87
  export function prepareArpeggioShape(height, em, direction) {
88
88
  const arrow = direction === "up" || direction === "down";
89
89
  const segments = Math.max(1, Math.round(height / (em * 0.3)));
@@ -94,29 +94,35 @@ export function prepareArpeggioShape(height, em, direction) {
94
94
  const scale = height / naturalHeight;
95
95
  const commands = [];
96
96
  for (let index = 0; index < regularCount; index++) {
97
- appendShape(commands, TILE, TILE_WIDTH, TILE_HEIGHT, 0, index * TILE_STEP * scale, scale, direction === "");
97
+ appendShape(commands, TILE, 0, index * TILE_STEP * scale, scale, direction === "");
98
98
  }
99
99
  if (arrow) {
100
- appendShape(commands, DOWN_ARROW, 113.5313, ARROW_HEIGHT, ARROW_X * scale, (regularCount * TILE_STEP + ARROW_Y) * scale, scale, false);
100
+ appendShape(commands, DOWN_ARROW, ARROW_X * scale, (regularCount * TILE_STEP + ARROW_Y) * scale, scale, false);
101
101
  }
102
102
  const bounds = pathBounds(commands);
103
103
  if (direction !== "up")
104
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
- });
105
+ const right = bounds.x + bounds.w;
106
+ const mirrorX = (value) => right - (value - bounds.x);
107
+ // 命令尚未发布,直接镜像,避免再分配整条路径及每个命令对象
108
+ for (const command of commands) {
109
+ if (command.op === "Z")
110
+ continue;
111
+ if (command.op === "C") {
112
+ command.cx1 = mirrorX(command.cx1);
113
+ command.cy1 = height - command.cy1;
114
+ command.cx2 = mirrorX(command.cx2);
115
+ command.cy2 = height - command.cy2;
116
+ }
117
+ else if (command.op === "Q") {
118
+ command.cx = mirrorX(command.cx);
119
+ command.cy = height - command.cy;
120
+ }
121
+ command.x = mirrorX(command.x);
122
+ command.y = height - command.y;
123
+ }
118
124
  return {
119
- commands: rotated,
125
+ commands,
120
126
  bounds: { x: bounds.x, y: height - bounds.y - bounds.h, w: bounds.w, h: bounds.h },
121
127
  };
122
128
  }
@@ -1,5 +1,13 @@
1
1
  import { ASTFunctionClass } from "../ASTtypes.js";
2
+ import type { LoweringContext } from "../../lowering/loweringContext.js";
2
3
  import type { PlaybackCursor } from "../../playback/types.js";
4
+ /**
5
+ * 按需注册行首小节号:统计从第二行起每条谱面行首小节的序号,并生成行首小节号附件
6
+ *
7
+ * 小节边界仅在正时值事件之后遇到 ANCHOR_KEY 时推进(兼容 @rest 补入的虚拟边界,且曲首 |: 不多计);
8
+ * 若上一行末尾未写小节线,当前小节跨行延续,新行行首因 measureRecorded 为 true 不重复标号。
9
+ */
10
+ export declare function registerBarNumbering(ctx: LoweringContext, pattern: string, font: string): void;
3
11
  export declare const BarNode: ASTFunctionClass;
4
12
  /**
5
13
  * 某一列此刻处在所属反复段的第几遍