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,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
- }