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
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { Diagnostic, ErrorDiagnostic } from "../../diagnostic.js";
|
|
2
|
-
const LETTER_NOTE_START_RE = /^[A-GXZ]/;
|
|
3
|
-
const NUM_NOTE_START_RE = /^[0-9]/;
|
|
4
|
-
const SHARP_RE = /^[#bn]+/;
|
|
5
|
-
const ABS_OCTAVE_RE = /^[+-]?\d+/;
|
|
6
|
-
const RELATIVE_OCTAVE_RE = /^[,']+/;
|
|
7
|
-
export function parseNoteName(str, start = 0, end = str.length) {
|
|
8
|
-
if ((end - start) === 0)
|
|
9
|
-
return new ErrorDiagnostic("E_WRONG_NOTE_NAME", `函数 @note 的参数 [0]:"name" 不能为空`, { start, end });
|
|
10
|
-
// 用状态机解决 详细信息查看FSM.drawio
|
|
11
|
-
let state = 0;
|
|
12
|
-
let name = null, acc = null, octave = null, absOctave = false;
|
|
13
|
-
let match;
|
|
14
|
-
for (let pos = start; pos < end; pos++) {
|
|
15
|
-
const ch = str[pos];
|
|
16
|
-
switch (state) {
|
|
17
|
-
case 0:
|
|
18
|
-
if (LETTER_NOTE_START_RE.test(ch)) {
|
|
19
|
-
name = ch;
|
|
20
|
-
absOctave = true;
|
|
21
|
-
state = 1;
|
|
22
|
-
}
|
|
23
|
-
else if (NUM_NOTE_START_RE.test(ch)) {
|
|
24
|
-
name = ch;
|
|
25
|
-
absOctave = false;
|
|
26
|
-
state = 3;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
const match = str.slice(pos, end).match(SHARP_RE);
|
|
30
|
-
if (match) {
|
|
31
|
-
acc = match[0];
|
|
32
|
-
pos += acc.length - 1;
|
|
33
|
-
absOctave = false;
|
|
34
|
-
state = 2;
|
|
35
|
-
}
|
|
36
|
-
else
|
|
37
|
-
return new ErrorDiagnostic("E_WRONG_NOTE_NAME", `函数 @note 的参数 [0]:"name" 格式错误: 首字符 "${ch}" 不合法,期望 A-G (a-g)、0-9、X 或 Z 开头,或在开头直接使用升降号(#/b/n)`, { start: pos, end: pos + 1 });
|
|
38
|
-
}
|
|
39
|
-
break;
|
|
40
|
-
case 1: // [字母模式] 已获得音名
|
|
41
|
-
const subs = str.slice(pos, end);
|
|
42
|
-
match = subs.match(ABS_OCTAVE_RE);
|
|
43
|
-
if (match) {
|
|
44
|
-
octave = parseInt(match[0], 10);
|
|
45
|
-
pos += match[0].length - 1;
|
|
46
|
-
state = 4;
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
match = subs.match(SHARP_RE);
|
|
50
|
-
if (match) {
|
|
51
|
-
acc = match[0];
|
|
52
|
-
pos += acc.length - 1;
|
|
53
|
-
state = 5;
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
return {
|
|
57
|
-
name: name,
|
|
58
|
-
next: pos,
|
|
59
|
-
acc: null,
|
|
60
|
-
octave: null,
|
|
61
|
-
absOctave,
|
|
62
|
-
};
|
|
63
|
-
case 2: // [数字模式] 已获得升降号
|
|
64
|
-
if (NUM_NOTE_START_RE.test(ch)) {
|
|
65
|
-
name = ch;
|
|
66
|
-
state = 6;
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
else
|
|
70
|
-
return new ErrorDiagnostic("E_WRONG_NOTE_NAME", `函数 @note 的参数 [0]:"name" 格式错误: 在升降号开头时,应该接数字音名,但发现字符 "${ch}"`, { start: pos, end: pos + 1 });
|
|
71
|
-
case 3: // [数字模式] 已获得音名
|
|
72
|
-
match = str.slice(pos, end).match(RELATIVE_OCTAVE_RE);
|
|
73
|
-
if (match) {
|
|
74
|
-
const octave_str = match[0];
|
|
75
|
-
octave = relativeOctaveFromString(octave_str);
|
|
76
|
-
return {
|
|
77
|
-
name: name,
|
|
78
|
-
next: pos + octave_str.length,
|
|
79
|
-
acc,
|
|
80
|
-
octave: octave,
|
|
81
|
-
absOctave,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
match = str.slice(pos, end).match(SHARP_RE);
|
|
85
|
-
if (match && !NUM_NOTE_START_RE.test(str[pos + match[0].length] ?? "")) {
|
|
86
|
-
const accidental = match[0];
|
|
87
|
-
acc = accidental;
|
|
88
|
-
pos += accidental.length - 1;
|
|
89
|
-
state = 6;
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
name: name,
|
|
94
|
-
next: pos,
|
|
95
|
-
acc,
|
|
96
|
-
octave: octave,
|
|
97
|
-
absOctave,
|
|
98
|
-
};
|
|
99
|
-
case 4: // [字母模式] 已获得音名和八度
|
|
100
|
-
match = str.slice(pos, end).match(SHARP_RE);
|
|
101
|
-
if (match && !NUM_NOTE_START_RE.test(str[pos + match[0].length] ?? "")) {
|
|
102
|
-
const accidental = match[0];
|
|
103
|
-
acc = accidental;
|
|
104
|
-
return {
|
|
105
|
-
name: name,
|
|
106
|
-
next: pos + accidental.length,
|
|
107
|
-
acc,
|
|
108
|
-
octave,
|
|
109
|
-
absOctave,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
return {
|
|
113
|
-
name: name,
|
|
114
|
-
next: pos,
|
|
115
|
-
acc: null,
|
|
116
|
-
octave,
|
|
117
|
-
absOctave,
|
|
118
|
-
};
|
|
119
|
-
case 5: // [字母模式] 已获得音名和半音
|
|
120
|
-
match = str.slice(pos, end).match(ABS_OCTAVE_RE);
|
|
121
|
-
if (match) {
|
|
122
|
-
octave = parseInt(match[0], 10);
|
|
123
|
-
return {
|
|
124
|
-
name: name,
|
|
125
|
-
next: pos + match[0].length,
|
|
126
|
-
acc,
|
|
127
|
-
octave,
|
|
128
|
-
absOctave,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
return {
|
|
132
|
-
name: name,
|
|
133
|
-
next: pos,
|
|
134
|
-
acc: acc,
|
|
135
|
-
octave: null,
|
|
136
|
-
absOctave,
|
|
137
|
-
};
|
|
138
|
-
case 6: // [数字模式] 已获得升降号和音名
|
|
139
|
-
match = str.slice(pos, end).match(RELATIVE_OCTAVE_RE);
|
|
140
|
-
if (match) {
|
|
141
|
-
const octave_str = match[0];
|
|
142
|
-
octave = relativeOctaveFromString(octave_str);
|
|
143
|
-
return {
|
|
144
|
-
name: name,
|
|
145
|
-
next: pos + octave_str.length,
|
|
146
|
-
acc,
|
|
147
|
-
octave,
|
|
148
|
-
absOctave,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
name: name,
|
|
153
|
-
next: pos,
|
|
154
|
-
acc,
|
|
155
|
-
octave,
|
|
156
|
-
absOctave,
|
|
157
|
-
};
|
|
158
|
-
default:
|
|
159
|
-
return Diagnostic.error.Bug("音符名称解析状态机进入了未定义的状态", { start: pos, end });
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if (name === null)
|
|
163
|
-
return new ErrorDiagnostic("E_WRONG_NOTE_NAME", `函数 @note 的参数 [0]:"name" 格式错误: 在升降号开头时,应该接数字音名,但输入已结束`, { start, end });
|
|
164
|
-
return {
|
|
165
|
-
name,
|
|
166
|
-
next: end,
|
|
167
|
-
acc,
|
|
168
|
-
octave,
|
|
169
|
-
absOctave
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
function relativeOctaveFromString(octaveStr) {
|
|
173
|
-
let octave = 0;
|
|
174
|
-
for (let i = 0; i < octaveStr.length; i++) {
|
|
175
|
-
if (octaveStr[i] === ',')
|
|
176
|
-
octave--;
|
|
177
|
-
else if (octaveStr[i] === "'")
|
|
178
|
-
octave++;
|
|
179
|
-
}
|
|
180
|
-
return octave;
|
|
181
|
-
}
|