jpfun 0.7.0 → 0.9.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 +0 -10
- package/dist/converter/midi/convert.js +19 -56
- package/dist/converter/musicxml/features.d.ts +16 -8
- package/dist/converter/musicxml/features.js +88 -19
- package/dist/converter/musicxml/index.js +88 -50
- package/dist/converter/musicxml/model.d.ts +9 -0
- package/dist/converter/source.d.ts +4 -7
- package/dist/converter/source.js +11 -9
- 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 +3 -32
- package/dist/functions/ASTtypes.js +5 -52
- package/dist/functions/adjust/index.js +45 -33
- package/dist/functions/arpeggio/index.js +50 -55
- package/dist/functions/arpeggio/shape.d.ts +2 -3
- package/dist/functions/arpeggio/shape.js +20 -50
- package/dist/functions/bar/index.d.ts +8 -0
- package/dist/functions/bar/index.js +105 -8
- package/dist/functions/beam/auto.d.ts +1 -2
- package/dist/functions/beam/auto.js +80 -135
- package/dist/functions/beam/index.js +6 -12
- package/dist/functions/beam/layout.d.ts +1 -1
- package/dist/functions/beam/layout.js +1 -1
- package/dist/functions/box/index.js +0 -6
- package/dist/functions/br/index.d.ts +34 -2
- package/dist/functions/br/index.js +5 -4
- package/dist/functions/dash/index.js +9 -10
- package/dist/functions/default.js +2 -1
- package/dist/functions/div/index.d.ts +3 -4
- package/dist/functions/div/index.js +18 -14
- package/dist/functions/dot/index.js +5 -11
- package/dist/functions/dyn/index.js +55 -57
- package/dist/functions/gliss/index.js +131 -103
- package/dist/functions/grace/index.d.ts +3 -12
- package/dist/functions/grace/index.js +52 -102
- package/dist/functions/head/index.js +10 -7
- package/dist/functions/key/index.js +13 -15
- package/dist/functions/meter/index.d.ts +56 -1
- package/dist/functions/meter/index.js +15 -10
- package/dist/functions/note/index.js +6 -6
- package/dist/functions/note/noteName.d.ts +16 -0
- package/dist/functions/note/noteName.js +88 -0
- package/dist/functions/note/source-transform.js +8 -10
- package/dist/functions/ottava/index.js +35 -40
- package/dist/functions/page/index.d.ts +1 -0
- package/dist/functions/page/index.js +27 -21
- package/dist/functions/pagebreak/index.js +2 -2
- package/dist/functions/rest/index.js +5 -5
- package/dist/functions/set/index.js +4 -4
- package/dist/functions/slide/index.js +0 -1
- package/dist/functions/stack/index.js +8 -57
- package/dist/functions/symbol/index.d.ts +21 -2
- package/dist/functions/symbol/index.js +69 -24
- package/dist/functions/symbol/ornament.d.ts +1 -2
- package/dist/functions/symbol/shape.d.ts +6 -0
- package/dist/functions/symbol/shape.js +16 -3
- 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/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/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 +3 -2
- package/dist/functions/temporal.js +8 -0
- package/dist/functions/text/index.js +38 -35
- package/dist/functions/tie/index.js +44 -43
- package/dist/functions/tremolo/index.d.ts +2 -0
- package/dist/functions/tremolo/index.js +318 -0
- package/dist/functions/tuplet/index.js +4 -14
- package/dist/functions/up/index.js +81 -85
- package/dist/functions/voice/connections.d.ts +2 -1
- package/dist/functions/voice/connections.js +48 -10
- package/dist/functions/voice/index.d.ts +2 -3
- package/dist/functions/voice/index.js +2 -963
- package/dist/functions/voice/lyrics.d.ts +30 -0
- package/dist/functions/voice/lyrics.js +289 -0
- package/dist/functions/voice/voice.d.ts +63 -0
- package/dist/functions/voice/voice.js +373 -0
- package/dist/functions/voice/voices.d.ts +106 -0
- package/dist/functions/voice/voices.js +423 -0
- package/dist/functions/volta/index.js +5 -23
- package/dist/jpfun.core.min.js +76 -59
- package/dist/jpfun.from-midi.min.js +5 -5
- package/dist/jpfun.from-musicxml.min.js +8 -8
- package/dist/jpfun.min.js +81 -64
- package/dist/layout/default.d.ts +0 -1
- package/dist/layout/default.js +0 -1
- package/dist/layout/engine.js +30 -18
- package/dist/layout/model.d.ts +0 -1
- package/dist/layout/model.js +1 -4
- package/dist/layout/page.d.ts +2 -1
- package/dist/layout/page.js +14 -14
- package/dist/layout/range.d.ts +7 -6
- package/dist/layout/range.js +23 -14
- package/dist/layout/types.d.ts +9 -28
- package/dist/lowering/loweringContext.d.ts +18 -23
- package/dist/lowering/loweringContext.js +33 -46
- package/dist/lowering/track.d.ts +8 -1
- package/dist/lowering/types.d.ts +13 -11
- package/dist/parser/parse-utils/call-utils.d.ts +1 -2
- package/dist/parser/parse-utils/call-utils.js +6 -34
- package/dist/parser/parse-utils/note-utils.d.ts +3 -3
- package/dist/parser/parse-utils/note-utils.js +21 -33
- package/dist/parser/parse-utils/string-utils.d.ts +3 -2
- package/dist/parser/parse-utils/string-utils.js +20 -5
- package/dist/parser/parserContext.d.ts +9 -9
- package/dist/parser/parserContext.js +62 -11
- package/dist/pipeline.js +2 -3
- package/dist/playback/compile.js +131 -82
- package/dist/playback/event.d.ts +6 -6
- package/dist/playback/event.js +13 -49
- package/dist/playback/time.js +42 -31
- package/dist/playback/types.d.ts +3 -1
- package/dist/render/canvas.js +4 -22
- package/dist/render/recording.js +1 -4
- package/dist/render/svg.d.ts +0 -1
- package/dist/render/svg.js +33 -31
- package/dist/render/text.d.ts +36 -1
- package/dist/render/text.js +134 -0
- package/dist/render/translate.d.ts +0 -1
- package/dist/render/translate.js +6 -23
- package/dist/render/types.d.ts +0 -2
- package/grammar.md +39 -30
- package/package.json +3 -3
- package/dist/functions/note/noteNameFSM.d.ts +0 -8
- package/dist/functions/note/noteNameFSM.js +0 -181
- package/dist/iife/core.d.ts +0 -1
- package/dist/iife/core.js +0 -3
- package/dist/iife/from-midi.d.ts +0 -1
- package/dist/iife/from-midi.js +0 -15
- package/dist/iife/from-musicxml.d.ts +0 -1
- package/dist/iife/from-musicxml.js +0 -3
- package/dist/iife/full.d.ts +0 -1
- package/dist/iife/full.js +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jpfun",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "A functional numbered musical notation typesetting engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"dist",
|
|
28
28
|
"README.md",
|
|
29
29
|
"LICENSE",
|
|
30
|
+
"Bravura-LICENSE.txt",
|
|
30
31
|
"grammar.md"
|
|
31
32
|
],
|
|
32
33
|
"engines": {
|
|
@@ -50,8 +51,7 @@
|
|
|
50
51
|
"build:bundle": "node ../../scripts/build-jpfun-bundles.mjs && node --test ../../scripts/test-jpfun-bundles.mjs",
|
|
51
52
|
"prepack": "pnpm run build",
|
|
52
53
|
"typecheck": "tsc -p test/tsconfig.json",
|
|
53
|
-
"test": "node --import tsx --test \"test/*.test.ts\""
|
|
54
|
-
"test:update": "node --import tsx --test \"test/*.test.ts\""
|
|
54
|
+
"test": "node --import tsx --test \"test/*.test.ts\""
|
|
55
55
|
},
|
|
56
56
|
"keywords": [
|
|
57
57
|
"numbered-musical-notation",
|
|
@@ -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
|
-
}
|
package/dist/iife/core.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/iife/core.js
DELETED
package/dist/iife/from-midi.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/iife/from-midi.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { convertMidiJsonToJpFun, } from "../converter/midi/convert.js";
|
|
2
|
-
const target = globalThis;
|
|
3
|
-
const api = target.jpfun ??= {};
|
|
4
|
-
Object.assign(api, {
|
|
5
|
-
midiJsonToJpFun(input, options = {}) {
|
|
6
|
-
const layoutCapability = (options.barsPerLine ?? 0) <= 0
|
|
7
|
-
? {
|
|
8
|
-
compileScore: api.compileScore,
|
|
9
|
-
anchorKey: api.ANCHOR_KEY,
|
|
10
|
-
page: api.DEFAULT_PAGE_CONFIG,
|
|
11
|
-
}
|
|
12
|
-
: undefined;
|
|
13
|
-
return convertMidiJsonToJpFun(input, options, layoutCapability);
|
|
14
|
-
},
|
|
15
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/iife/full.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/iife/full.js
DELETED