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.
- package/Bravura-LICENSE.txt +93 -0
- package/README.md +49 -146
- package/dist/Bravura-LICENSE.txt +93 -0
- package/dist/converter/midi/convert.d.ts +3 -11
- package/dist/converter/midi/convert.js +89 -67
- package/dist/converter/musicxml/features.d.ts +34 -12
- package/dist/converter/musicxml/features.js +131 -24
- package/dist/converter/musicxml/index.js +221 -54
- package/dist/converter/musicxml/model.d.ts +24 -0
- package/dist/core.d.ts +1 -0
- package/dist/core.js +1 -0
- package/dist/diagnostic.d.ts +7 -1
- package/dist/diagnostic.js +40 -88
- package/dist/fraction.js +3 -2
- package/dist/functions/ASTtypes.d.ts +2 -18
- package/dist/functions/ASTtypes.js +0 -16
- package/dist/functions/arpeggio/index.js +17 -22
- package/dist/functions/arpeggio/shape.d.ts +1 -1
- package/dist/functions/arpeggio/shape.js +27 -21
- package/dist/functions/bar/index.d.ts +8 -0
- package/dist/functions/bar/index.js +139 -36
- package/dist/functions/beam/auto.d.ts +1 -2
- package/dist/functions/beam/auto.js +44 -27
- package/dist/functions/beam/index.js +2 -3
- package/dist/functions/beam/layout.d.ts +1 -1
- package/dist/functions/beam/layout.js +16 -24
- package/dist/functions/br/index.d.ts +34 -2
- package/dist/functions/br/index.js +8 -8
- package/dist/functions/dash/index.js +6 -6
- package/dist/functions/default.js +10 -5
- package/dist/functions/div/index.d.ts +1 -0
- package/dist/functions/div/index.js +8 -4
- package/dist/functions/dot/index.js +2 -2
- package/dist/functions/dyn/index.js +49 -31
- package/dist/functions/gliss/index.d.ts +2 -0
- package/dist/functions/gliss/index.js +202 -0
- package/dist/functions/grace/index.d.ts +1 -7
- package/dist/functions/grace/index.js +11 -19
- package/dist/functions/head/index.js +41 -60
- package/dist/functions/key/index.js +8 -10
- package/dist/functions/meter/index.d.ts +56 -1
- package/dist/functions/meter/index.js +30 -24
- package/dist/functions/note/accidentals.js +10 -16
- package/dist/functions/note/index.js +18 -8
- package/dist/functions/note/noteName.d.ts +16 -0
- package/dist/functions/note/noteName.js +88 -0
- package/dist/functions/note/source-transform.js +6 -5
- package/dist/functions/ottava/index.d.ts +2 -0
- package/dist/functions/ottava/index.js +233 -0
- package/dist/functions/page/index.d.ts +1 -0
- package/dist/functions/page/index.js +22 -13
- package/dist/functions/pagebreak/index.d.ts +2 -0
- package/dist/functions/pagebreak/index.js +36 -0
- package/dist/functions/rest/index.js +15 -15
- package/dist/functions/set/index.js +4 -4
- package/dist/functions/slide/index.d.ts +2 -0
- package/dist/functions/slide/index.js +132 -0
- package/dist/functions/stack/index.js +8 -15
- package/dist/functions/symbol/index.d.ts +30 -2
- package/dist/functions/symbol/index.js +93 -19
- package/dist/functions/symbol/ornament.d.ts +1 -2
- package/dist/functions/symbol/ornament.js +14 -19
- package/dist/functions/symbol/shape.d.ts +6 -0
- package/dist/functions/symbol/shape.js +20 -4
- package/dist/functions/symbol/symbols/coda.d.ts +4 -0
- package/dist/functions/symbol/symbols/coda.js +56 -0
- package/dist/functions/symbol/symbols/dynamics.d.ts +1 -1
- package/dist/functions/symbol/symbols/dynamics.js +18 -8
- package/dist/functions/symbol/symbols/fine.js +1 -1
- package/dist/functions/symbol/symbols/harmonic.d.ts +2 -0
- package/dist/functions/symbol/symbols/harmonic.js +11 -0
- package/dist/functions/symbol/symbols/marcato.d.ts +2 -0
- package/dist/functions/symbol/symbols/marcato.js +22 -0
- package/dist/functions/symbol/symbols/staccato.d.ts +2 -0
- package/dist/functions/symbol/symbols/staccato.js +24 -0
- package/dist/functions/symbol/symbols/tenuto.d.ts +2 -0
- package/dist/functions/symbol/symbols/tenuto.js +11 -0
- package/dist/functions/symbol/symbols/tocoda.d.ts +2 -0
- package/dist/functions/symbol/symbols/tocoda.js +16 -0
- package/dist/functions/symbol/symbols/tr.js +46 -1
- package/dist/functions/symbol/symbols/turn.d.ts +3 -0
- package/dist/functions/symbol/symbols/turn.js +50 -0
- package/dist/functions/symbol/symbols/wheel.d.ts +2 -0
- package/dist/functions/symbol/symbols/wheel.js +36 -0
- package/dist/functions/temporal.d.ts +17 -6
- package/dist/functions/temporal.js +17 -6
- package/dist/functions/text/index.js +15 -6
- package/dist/functions/tie/index.js +64 -30
- package/dist/functions/tremolo/index.d.ts +2 -0
- package/dist/functions/tremolo/index.js +319 -0
- package/dist/functions/tuplet/index.js +4 -8
- package/dist/functions/up/index.js +7 -9
- package/dist/functions/voice/connections.js +7 -5
- package/dist/functions/voice/index.js +19 -11
- package/dist/functions/volta/index.js +41 -21
- package/dist/jpfun.core.min.js +64 -80
- package/dist/jpfun.from-midi.min.js +5 -5
- package/dist/jpfun.from-musicxml.min.js +8 -8
- package/dist/jpfun.min.js +69 -85
- package/dist/layout/default.d.ts +0 -1
- package/dist/layout/default.js +0 -1
- package/dist/layout/engine.d.ts +1 -0
- package/dist/layout/engine.js +42 -11
- package/dist/layout/page.d.ts +3 -2
- package/dist/layout/page.js +6 -5
- package/dist/layout/types.d.ts +4 -0
- package/dist/lowering/loweringContext.d.ts +11 -13
- package/dist/lowering/loweringContext.js +30 -197
- package/dist/lowering/types.d.ts +1 -3
- package/dist/parser/parse-utils/note-utils.d.ts +1 -1
- package/dist/parser/parse-utils/note-utils.js +8 -9
- package/dist/parser/parse-utils/string-utils.d.ts +3 -2
- package/dist/parser/parse-utils/string-utils.js +16 -3
- package/dist/parser/parserContext.d.ts +2 -0
- package/dist/parser/parserContext.js +36 -8
- package/dist/pipeline.js +0 -1
- package/dist/playback/compile.js +131 -72
- package/dist/playback/event.d.ts +1 -1
- package/dist/playback/event.js +9 -9
- package/dist/playback/time.js +42 -31
- package/dist/playback/types.d.ts +7 -3
- package/dist/render/canvas.d.ts +2 -0
- package/dist/render/canvas.js +25 -22
- package/dist/render/recording.js +1 -4
- package/dist/render/svg.js +1 -0
- package/dist/render/text.d.ts +1 -1
- package/dist/render/text.js +3 -2
- package/dist/render/translate.d.ts +0 -1
- package/dist/render/translate.js +6 -23
- package/dist/render/types.d.ts +1 -0
- package/grammar.md +52 -25
- package/package.json +3 -3
- package/dist/functions/note/noteNameFSM.d.ts +0 -8
- package/dist/functions/note/noteNameFSM.js +0 -181
package/dist/diagnostic.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
},
|
|
114
|
-
|
|
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
|
-
|
|
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(
|
|
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 {
|
|
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" | "
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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 (!
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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,
|
|
64
|
-
const x = (value) => offsetX + (reverse ?
|
|
65
|
-
const y = (value) => offsetY + (reverse ?
|
|
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,
|
|
97
|
+
appendShape(commands, TILE, 0, index * TILE_STEP * scale, scale, direction === "");
|
|
98
98
|
}
|
|
99
99
|
if (arrow) {
|
|
100
|
-
appendShape(commands, DOWN_ARROW,
|
|
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
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
op
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
|
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
|
* 某一列此刻处在所属反复段的第几遍
|