vexflow 5.1.1 → 5.2.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 (96) hide show
  1. package/README.md +8 -6
  2. package/build/cjs/vexflow-bravura.js +2 -2
  3. package/build/cjs/vexflow-bravura.js.map +1 -1
  4. package/build/cjs/vexflow-core.js +2 -2
  5. package/build/cjs/vexflow-core.js.map +1 -1
  6. package/build/cjs/vexflow-debug-with-tests.js +2916 -484
  7. package/build/cjs/vexflow-debug-with-tests.js.map +1 -1
  8. package/build/cjs/vexflow-debug.js +2761 -451
  9. package/build/cjs/vexflow-debug.js.map +1 -1
  10. package/build/cjs/vexflow.js +2 -2
  11. package/build/cjs/vexflow.js.map +1 -1
  12. package/build/esm/src/accidental.js +3 -0
  13. package/build/esm/src/articulation.js +27 -14
  14. package/build/esm/src/beam.js +12 -2
  15. package/build/esm/src/chordkerning.js +98 -0
  16. package/build/esm/src/chordsymbol.js +108 -27
  17. package/build/esm/src/clef.js +3 -0
  18. package/build/esm/src/clefnote.js +5 -1
  19. package/build/esm/src/dot.js +1 -1
  20. package/build/esm/src/easyscore/composition.js +297 -0
  21. package/build/esm/src/easyscore/elementindex.js +81 -0
  22. package/build/esm/src/easyscore/elements.js +324 -0
  23. package/build/esm/src/easyscore/policies.js +69 -0
  24. package/build/esm/src/easyscore/rhythm.js +42 -0
  25. package/build/esm/src/easyscore.js +448 -26
  26. package/build/esm/src/element.js +13 -2
  27. package/build/esm/src/factory.js +256 -60
  28. package/build/esm/src/formatter.js +32 -4
  29. package/build/esm/src/keysignature.js +9 -1
  30. package/build/esm/src/keysignote.js +2 -2
  31. package/build/esm/src/note.js +5 -0
  32. package/build/esm/src/parenthesis.js +1 -1
  33. package/build/esm/src/parser.js +6 -1
  34. package/build/esm/src/proportionalformatter.js +186 -0
  35. package/build/esm/src/registry.js +27 -0
  36. package/build/esm/src/sheet.js +20 -3
  37. package/build/esm/src/stave.js +9 -2
  38. package/build/esm/src/stavenote.js +12 -12
  39. package/build/esm/src/stemmablenote.js +6 -1
  40. package/build/esm/src/tickable.js +5 -0
  41. package/build/esm/src/tuplet.js +3 -2
  42. package/build/esm/src/version.js +3 -3
  43. package/build/esm/src/vexflow.js +2 -1
  44. package/build/esm/tests/beam_tests.js +35 -0
  45. package/build/esm/tests/easyscore_tests.js +40 -0
  46. package/build/esm/tests/easyscore_types.js +65 -0
  47. package/build/esm/tests/formatter_tests.js +41 -0
  48. package/build/esm/tests/node/chord-kerning-tests.mjs +173 -0
  49. package/build/esm/tests/node/easyscore-rendering-tests.mjs +332 -0
  50. package/build/esm/tests/node/easyscore-tests.mjs +953 -0
  51. package/build/esm/tests/node/proportional-spacing-tests.mjs +214 -0
  52. package/build/esm/tests/node/tool-security-tests.mjs +85 -0
  53. package/build/esm/tools/easyscore-api-audit.mjs +58 -0
  54. package/build/esm/tools/easyscore-composition.mjs +62 -0
  55. package/build/esm/tools/easyscore-example.mjs +16 -0
  56. package/build/esm/tools/easyscore-families.mjs +61 -0
  57. package/build/esm/tools/easyscore-references-example.mjs +26 -0
  58. package/build/esm/tools/easyscore-rhythm.mjs +58 -0
  59. package/build/esm/tools/easyscore-structure.mjs +88 -0
  60. package/build/esm/tools/explorer/catalog/entries.mjs +6 -0
  61. package/build/esm/tools/explorer/catalog/expression.mjs +68 -0
  62. package/build/esm/tools/explorer/catalog/helpers.mjs +29 -0
  63. package/build/esm/tools/explorer/catalog/layout.mjs +109 -0
  64. package/build/esm/tools/explorer/catalog/notes.mjs +61 -0
  65. package/build/esm/tools/explorer/catalog/staves.mjs +85 -0
  66. package/build/esm/tools/explorer/catalog/strings.mjs +25 -0
  67. package/build/esm/tools/explorer/catalog.mjs +14 -0
  68. package/build/types/src/accidental.d.ts +2 -0
  69. package/build/types/src/articulation.d.ts +6 -0
  70. package/build/types/src/beam.d.ts +2 -0
  71. package/build/types/src/chordkerning.d.ts +42 -0
  72. package/build/types/src/chordsymbol.d.ts +19 -0
  73. package/build/types/src/clef.d.ts +2 -0
  74. package/build/types/src/easyscore/composition.d.ts +107 -0
  75. package/build/types/src/easyscore/elementindex.d.ts +30 -0
  76. package/build/types/src/easyscore/elements.d.ts +156 -0
  77. package/build/types/src/easyscore/policies.d.ts +12 -0
  78. package/build/types/src/easyscore/rhythm.d.ts +9 -0
  79. package/build/types/src/easyscore.d.ts +153 -11
  80. package/build/types/src/element.d.ts +5 -1
  81. package/build/types/src/factory.d.ts +91 -8
  82. package/build/types/src/formatter.d.ts +7 -1
  83. package/build/types/src/keysignature.d.ts +3 -0
  84. package/build/types/src/keysignote.d.ts +1 -1
  85. package/build/types/src/note.d.ts +2 -0
  86. package/build/types/src/parser.d.ts +5 -0
  87. package/build/types/src/proportionalformatter.d.ts +30 -0
  88. package/build/types/src/registry.d.ts +4 -0
  89. package/build/types/src/stave.d.ts +2 -0
  90. package/build/types/src/stavenote.d.ts +1 -1
  91. package/build/types/src/stemmablenote.d.ts +6 -1
  92. package/build/types/src/tickable.d.ts +2 -0
  93. package/build/types/src/vexflow.d.ts +2 -1
  94. package/changelog/CHANGELOG.md +57 -0
  95. package/package.json +19 -7
  96. package/tests/flow.html +10 -3
@@ -0,0 +1,324 @@
1
+ import { Articulation } from '../articulation.js';
2
+ import { Note } from '../note.js';
3
+ import { StaveNote } from '../stavenote.js';
4
+ import { StemmableNote } from '../stemmablenote.js';
5
+ import { Tables } from '../tables.js';
6
+ import { TabNote } from '../tabnote.js';
7
+ import { RuntimeError } from '../util.js';
8
+ export class EasyScoreElements {
9
+ constructor(host) {
10
+ this.host = host;
11
+ }
12
+ get factory() {
13
+ return this.host.factory();
14
+ }
15
+ stave(...args) {
16
+ return this.host.manage(() => this.factory.Stave(...args));
17
+ }
18
+ tabStave(...args) {
19
+ return this.host.manage(() => this.factory.TabStave(...args));
20
+ }
21
+ glyphNote(...args) {
22
+ return this.host.manage(() => this.factory.GlyphNote(...args));
23
+ }
24
+ repeatNote(...args) {
25
+ return this.host.manage(() => this.factory.RepeatNote(...args));
26
+ }
27
+ barNote(...args) {
28
+ return this.host.manage(() => this.factory.BarNote(...args));
29
+ }
30
+ clefNote(...args) {
31
+ return this.host.manage(() => this.factory.ClefNote(...args));
32
+ }
33
+ keySigNote(...args) {
34
+ return this.host.manage(() => this.factory.KeySigNote(...args));
35
+ }
36
+ timeSigNote(...args) {
37
+ return this.host.manage(() => this.factory.TimeSigNote(...args));
38
+ }
39
+ clef(...args) {
40
+ return this.host.manage(() => this.factory.Clef(...args));
41
+ }
42
+ keySignature(...args) {
43
+ return this.host.manage(() => this.factory.KeySignature(...args));
44
+ }
45
+ timeSignature(...args) {
46
+ return this.host.manage(() => this.factory.TimeSignature(...args));
47
+ }
48
+ barline(...args) {
49
+ return this.host.manage(() => this.factory.Barline(...args));
50
+ }
51
+ repetition(...args) {
52
+ return this.host.manage(() => this.factory.Repetition(...args));
53
+ }
54
+ volta(...args) {
55
+ return this.host.manage(() => this.factory.Volta(...args));
56
+ }
57
+ section(...args) {
58
+ return this.host.manage(() => this.factory.StaveSection(...args));
59
+ }
60
+ tempo(...args) {
61
+ return this.host.manage(() => this.factory.StaveTempo(...args));
62
+ }
63
+ staveText(...args) {
64
+ return this.host.manage(() => this.factory.StaveText(...args));
65
+ }
66
+ tabPositions(options) {
67
+ if (!options.positions.length)
68
+ throw new RuntimeError('BadArguments', 'Tab notes need positions.');
69
+ for (const { str, fret } of options.positions) {
70
+ if (!Number.isSafeInteger(str) ||
71
+ str < 1 ||
72
+ (typeof fret === 'number' ? !Number.isFinite(fret) || fret < 0 : typeof fret !== 'string' || !fret.length))
73
+ throw new RuntimeError('BadArguments', 'Invalid tablature position.');
74
+ }
75
+ }
76
+ tabNote(options, drawStem = false) {
77
+ this.tabPositions(options);
78
+ return this.host.manage(() => this.factory.TabNote(options, drawStem));
79
+ }
80
+ graceTabNote(options) {
81
+ this.tabPositions(options);
82
+ return this.host.manage(() => this.factory.GraceTabNote(options));
83
+ }
84
+ bend(...args) {
85
+ if (!args[0].length || args[0].some((part) => part.type !== 0 && part.type !== 1))
86
+ throw new RuntimeError('BadArguments', 'A bend needs valid phrase directions.');
87
+ return this.host.manage(() => this.factory.Bend(...args));
88
+ }
89
+ tabEndpoints(notes) {
90
+ var _a, _b;
91
+ this.endpoints(notes.firstNote, notes.lastNote, true);
92
+ const first = (_a = notes.firstIndexes) !== null && _a !== void 0 ? _a : [0], last = (_b = notes.lastIndexes) !== null && _b !== void 0 ? _b : [0];
93
+ if (!first.length || first.length !== last.length)
94
+ throw new RuntimeError('BadArguments', 'Tab span index lists must match.');
95
+ for (const [note, indices] of [
96
+ [notes.firstNote, first],
97
+ [notes.lastNote, last],
98
+ ]) {
99
+ if (!note)
100
+ continue;
101
+ if (!(note instanceof TabNote))
102
+ throw new RuntimeError('BadArguments', 'Tab spans need tab notes.');
103
+ indices.forEach((index) => this.host.checkIndex(note, index));
104
+ }
105
+ }
106
+ tabTie(...args) {
107
+ this.tabEndpoints(args[0]);
108
+ return this.host.manage(() => this.factory.TabTie(...args));
109
+ }
110
+ tabSlide(...args) {
111
+ this.tabEndpoints(args[0]);
112
+ if ((args[1] !== undefined && args[1] !== 1 && args[1] !== -1) ||
113
+ (args[1] === undefined && (!args[0].firstNote || !args[0].lastNote)))
114
+ throw new RuntimeError('BadArguments', 'Partial tab slides need direction 1 or -1.');
115
+ return this.host.manage(() => this.factory.TabSlide(...args));
116
+ }
117
+ connector(params) {
118
+ this.host.owned(params.topStave);
119
+ this.host.owned(params.bottomStave);
120
+ return this.host.manage(() => this.factory.StaveConnector(params));
121
+ }
122
+ multiMeasureRest(params) {
123
+ var _a;
124
+ if (!Number.isSafeInteger(params.numberOfMeasures) || ((_a = params.numberOfMeasures) !== null && _a !== void 0 ? _a : 0) < 1)
125
+ throw new RuntimeError('BadArguments', 'A multi-measure rest needs a positive measure count.');
126
+ return this.host.manage(() => this.factory.MultiMeasureRest(params));
127
+ }
128
+ note(options) {
129
+ return this.host.manage(() => this.factory.StaveNote(Object.assign(Object.assign(Object.assign({}, this.host.noteDefaults()), (options.stemDirection !== undefined && options.autoStem === undefined ? { autoStem: false } : {})), options)));
130
+ }
131
+ annotation(...args) {
132
+ return this.host.manage(() => this.factory.Annotation(...args));
133
+ }
134
+ ghostNote(...args) {
135
+ return this.host.manage(() => this.factory.GhostNote(...args));
136
+ }
137
+ graceNote(options) {
138
+ return this.host.manage(() => this.factory.GraceNote(Object.assign(Object.assign(Object.assign({}, this.host.noteDefaults()), (options.stemDirection !== undefined && options.autoStem === undefined ? { autoStem: false } : {})), options)));
139
+ }
140
+ accidental(...args) {
141
+ return this.host.manage(() => this.factory.Accidental(...args));
142
+ }
143
+ articulation(options = {}) {
144
+ var _a;
145
+ const marks = Articulation.parseEasyScore((_a = options.type) !== null && _a !== void 0 ? _a : 'staccato');
146
+ if (marks.length !== 1)
147
+ throw new RuntimeError('BadArguments', 'Create one articulation per helper call.');
148
+ return this.host.manage(() => this.factory.Articulation(Object.assign(Object.assign(Object.assign({}, marks[0]), options), { type: marks[0].type })));
149
+ }
150
+ ornament(...args) {
151
+ return this.host.manage(() => this.factory.Ornament(...args));
152
+ }
153
+ dot(...args) {
154
+ return this.host.manage(() => this.factory.Dot(...args));
155
+ }
156
+ parenthesis(...args) {
157
+ return this.host.manage(() => this.factory.Parenthesis(...args));
158
+ }
159
+ stroke(...args) {
160
+ return this.host.manage(() => this.factory.Stroke(...args));
161
+ }
162
+ tremolo(...args) {
163
+ return this.host.manage(() => this.factory.Tremolo(...args));
164
+ }
165
+ vibrato(...args) {
166
+ return this.host.manage(() => this.factory.Vibrato(...args));
167
+ }
168
+ chordSymbol(...args) {
169
+ return this.host.manage(() => this.factory.ChordSymbol(...args));
170
+ }
171
+ textNote(...args) {
172
+ return this.host.manage(() => this.factory.TextNote(...args));
173
+ }
174
+ fingering(...args) {
175
+ return this.host.manage(() => this.factory.Fingering(...args));
176
+ }
177
+ stringNumber(...args) {
178
+ return this.host.manage(() => this.factory.StringNumber(...args));
179
+ }
180
+ graceNoteGroup(options) {
181
+ options.notes.forEach((note) => this.host.owned(note));
182
+ return this.host.manage(() => this.factory.groupNotes(options.notes, () => this.factory.GraceNoteGroup(Object.assign(Object.assign({}, options), { notes: options.notes.slice() }))));
183
+ }
184
+ noteSubGroup(options) {
185
+ options.notes.forEach((note) => this.host.owned(note));
186
+ return this.host.manage(() => this.factory.groupNotes(options.notes, () => this.factory.NoteSubGroup({ notes: options.notes.slice() })));
187
+ }
188
+ tie(options) {
189
+ var _a, _b;
190
+ const { from, to } = options;
191
+ this.endpoints(from, to, true);
192
+ const first = (_a = options.firstIndexes) !== null && _a !== void 0 ? _a : [0];
193
+ const last = (_b = options.lastIndexes) !== null && _b !== void 0 ? _b : [0];
194
+ if (!first.length || first.length !== last.length) {
195
+ throw new RuntimeError('BadArguments', 'Tie index lists must be nonempty and have the same length.');
196
+ }
197
+ for (const [note, indices] of [
198
+ [from, first],
199
+ [to, last],
200
+ ]) {
201
+ if (!note)
202
+ continue;
203
+ this.host.owned(note);
204
+ indices.forEach((index) => this.host.checkIndex(note, index));
205
+ }
206
+ return this.host.manage(() => this.factory.StaveTie(options));
207
+ }
208
+ endpoints(from, to, partial = false) {
209
+ if ((!from && !to) || (!partial && (!from || !to)))
210
+ throw new RuntimeError('BadArguments', 'Missing span endpoint.');
211
+ for (const note of [from, to]) {
212
+ if (!note)
213
+ continue;
214
+ if (!(note instanceof Note))
215
+ throw new RuntimeError('BadArguments', 'Span endpoints must be notes.');
216
+ this.host.owned(note);
217
+ }
218
+ }
219
+ beam(params) {
220
+ var _a, _b, _c;
221
+ const { notes, options } = params;
222
+ if (notes.length < 2 || new Set(notes).size !== notes.length)
223
+ throw new RuntimeError('BadArguments', 'A beam needs at least two distinct notes.');
224
+ notes.forEach((note) => {
225
+ if (!(note instanceof StemmableNote))
226
+ throw new RuntimeError('BadArguments', 'Beam endpoints must be stemmable notes.');
227
+ this.host.owned(note);
228
+ if (note.hasBeam())
229
+ throw new RuntimeError('BadArguments', 'Note already belongs to a beam.');
230
+ if (note.getIntrinsicTicks() >= Tables.durationToTicks('4'))
231
+ throw new RuntimeError('BadArguments', 'Beamed notes must be shorter than a quarter note.');
232
+ });
233
+ for (const index of (_a = options === null || options === void 0 ? void 0 : options.secondaryBeamBreaks) !== null && _a !== void 0 ? _a : [])
234
+ this.noteIndex(notes.length, index);
235
+ for (const [index, direction] of Object.entries((_b = options === null || options === void 0 ? void 0 : options.partialBeamDirections) !== null && _b !== void 0 ? _b : {})) {
236
+ this.noteIndex(notes.length, Number(index));
237
+ if (!['L', 'R', 'B'].includes(direction))
238
+ throw new RuntimeError('BadArguments', 'Invalid partial beam direction.');
239
+ }
240
+ const autoStem = (_c = options === null || options === void 0 ? void 0 : options.autoStem) !== null && _c !== void 0 ? _c : this.host.beamStems(notes);
241
+ return this.host.manage(() => this.factory.Beam({ notes, options: Object.assign(Object.assign({}, options), { autoStem }) }));
242
+ }
243
+ noteIndex(length, index) {
244
+ if (!Number.isInteger(index) || index < 0 || index >= length)
245
+ throw new RuntimeError('BadArguments', 'Invalid beam note index.');
246
+ }
247
+ tuplet(params) {
248
+ var _a, _b;
249
+ const { notes, options } = params;
250
+ if (!notes.length || new Set(notes).size !== notes.length)
251
+ throw new RuntimeError('BadArguments', 'A tuplet needs distinct notes.');
252
+ notes.forEach((note) => {
253
+ if (!(note instanceof Note))
254
+ throw new RuntimeError('BadArguments', 'Tuplets require notes.');
255
+ this.host.owned(note);
256
+ let voiced = false;
257
+ try {
258
+ note.getVoice();
259
+ voiced = true;
260
+ }
261
+ catch (error) {
262
+ if (!(error instanceof RuntimeError) || error.code !== 'NoVoice')
263
+ throw error;
264
+ }
265
+ if (voiced)
266
+ throw new RuntimeError('BadArguments', 'Create tuplets before inserting notes into a voice.');
267
+ });
268
+ for (const ratio of [(_a = options === null || options === void 0 ? void 0 : options.numNotes) !== null && _a !== void 0 ? _a : notes.length, (_b = options === null || options === void 0 ? void 0 : options.notesOccupied) !== null && _b !== void 0 ? _b : 2]) {
269
+ if (!Number.isSafeInteger(ratio) || ratio <= 0)
270
+ throw new RuntimeError('BadArguments', 'Tuplet ratios must be positive integers.');
271
+ }
272
+ return this.host.manage(() => this.factory.Tuplet(params));
273
+ }
274
+ curve(params) {
275
+ this.endpoints(params.from, params.to, true);
276
+ return this.host.manage(() => { var _a; return this.factory.Curve({ from: params.from, to: params.to, options: (_a = params.options) !== null && _a !== void 0 ? _a : {} }); });
277
+ }
278
+ hairpin(params) {
279
+ this.endpoints(params.from, params.to);
280
+ if (![1, 2].includes(params.type))
281
+ throw new RuntimeError('BadArguments', 'Unknown hairpin type.');
282
+ return this.host.manage(() => this.factory.StaveHairpin(params));
283
+ }
284
+ line(params) {
285
+ this.endpoints(params.from, params.to);
286
+ if (!(params.from instanceof StaveNote) || !(params.to instanceof StaveNote))
287
+ throw new RuntimeError('BadArguments', 'Lines require staff notes.');
288
+ if (!params.firstIndexes.length || params.firstIndexes.length !== params.lastIndexes.length)
289
+ throw new RuntimeError('BadArguments', 'Line index lists must be nonempty and matched.');
290
+ params.firstIndexes.forEach((index) => this.host.checkIndex(params.from, index));
291
+ params.lastIndexes.forEach((index) => this.host.checkIndex(params.to, index));
292
+ return this.host.manage(() => this.factory.StaveLine(params));
293
+ }
294
+ textBracket(params) {
295
+ this.endpoints(params.from, params.to);
296
+ return this.host.manage(() => this.factory.TextBracket(params));
297
+ }
298
+ vibratoBracket(params) {
299
+ this.endpoints(params.from, params.to, true);
300
+ return this.host.manage(() => this.factory.VibratoBracket(params));
301
+ }
302
+ pedalMarking(params) {
303
+ var _a, _b;
304
+ if (!params.notes.length)
305
+ throw new RuntimeError('BadArguments', 'Pedal markings need notes.');
306
+ params.notes.forEach((note) => {
307
+ if (!(note instanceof StaveNote))
308
+ throw new RuntimeError('BadArguments', 'Pedal points must be staff notes.');
309
+ this.host.owned(note);
310
+ });
311
+ if (!['text', 'bracket', 'mixed'].includes((_b = (_a = params.options) === null || _a === void 0 ? void 0 : _a.style) !== null && _b !== void 0 ? _b : 'mixed'))
312
+ throw new RuntimeError('BadArguments', 'Unknown pedal style.');
313
+ return this.host.manage(() => this.factory.PedalMarking(params));
314
+ }
315
+ textDynamics(params = {}) {
316
+ var _a;
317
+ if (!/^[pmfsrz]*$/i.test((_a = params.text) !== null && _a !== void 0 ? _a : 'p'))
318
+ throw new RuntimeError('BadArguments', 'Unknown dynamics glyph.');
319
+ return this.host.manage(() => this.factory.TextDynamics(params));
320
+ }
321
+ crescendo(...args) {
322
+ return this.host.manage(() => this.factory.Crescendo(...args));
323
+ }
324
+ }
@@ -0,0 +1,69 @@
1
+ import { Accidental } from '../accidental.js';
2
+ import { Fraction } from '../fraction.js';
3
+ import { Music } from '../music.js';
4
+ import { StaveNote } from '../stavenote.js';
5
+ export function applyCompositionAccidentals(score, voices, key, changes, generated, stave) {
6
+ var _a, _b;
7
+ const music = new Music();
8
+ let scale = music.createScaleMap(key);
9
+ const state = new Map();
10
+ const positions = new Map();
11
+ for (const voice of voices) {
12
+ const at = new Fraction(0, 1);
13
+ for (const note of voice.getTickables()) {
14
+ if (note.shouldIgnoreTicks())
15
+ continue;
16
+ const id = at.clone().simplify().toString();
17
+ const group = (_a = positions.get(id)) !== null && _a !== void 0 ? _a : { at: at.clone(), notes: [] };
18
+ if (note instanceof StaveNote && !note.isRest() && note.getStave() === stave)
19
+ group.notes.push(note);
20
+ positions.set(id, group);
21
+ at.add(note.getTicks());
22
+ }
23
+ }
24
+ let changeIndex = 0;
25
+ const sorted = [...positions.values()].sort((a, b) => (a.at.equals(b.at) ? 0 : a.at.lessThan(b.at) ? -1 : 1));
26
+ for (const group of sorted) {
27
+ while (changeIndex < changes.length && !changes[changeIndex].at.greaterThan(group.at)) {
28
+ scale = music.createScaleMap(changes[changeIndex++].key);
29
+ state.clear();
30
+ }
31
+ const simultaneous = new Map();
32
+ for (const note of group.notes)
33
+ for (const written of note.getKeys()) {
34
+ const [name, octave] = written.split('/');
35
+ const parts = music.getNoteParts(name);
36
+ const id = `${parts.root}/${octave}`;
37
+ const values = (_b = simultaneous.get(id)) !== null && _b !== void 0 ? _b : new Set();
38
+ values.add(parts.accidental || 'n');
39
+ simultaneous.set(id, values);
40
+ }
41
+ const updates = new Map();
42
+ for (const note of group.notes) {
43
+ note.getKeys().forEach((written, index) => {
44
+ var _a, _b, _c, _d;
45
+ const [name, octave] = written.split('/');
46
+ const parts = music.getNoteParts(name);
47
+ const accidental = parts.accidental || 'n';
48
+ const pitch = parts.root + accidental;
49
+ const id = `${parts.root}/${octave}`;
50
+ const previous = (_a = state.get(id)) !== null && _a !== void 0 ? _a : scale[parts.root];
51
+ const marks = note
52
+ .getModifiers()
53
+ .filter((mark) => mark instanceof Accidental && mark.getIndex() === index);
54
+ const explicit = marks.filter((mark) => !generated.has(mark) || mark.isCautionary() || !Music.accidentals.includes(mark.type));
55
+ for (const mark of marks) {
56
+ if (!explicit.includes(mark))
57
+ note.getModifiers().splice(note.getModifiers().indexOf(mark), 1);
58
+ }
59
+ if (!explicit.length && (previous !== pitch || ((_c = (_b = simultaneous.get(id)) === null || _b === void 0 ? void 0 : _b.size) !== null && _c !== void 0 ? _c : 0) > 1))
60
+ score.attach(note, score.make.accidental({ type: accidental }), index);
61
+ const value = explicit.some((mark) => !Music.accidentals.includes(mark.type)) ? 'microtonal' : pitch;
62
+ const values = (_d = updates.get(id)) !== null && _d !== void 0 ? _d : new Set();
63
+ values.add(value);
64
+ updates.set(id, values);
65
+ });
66
+ }
67
+ updates.forEach((values, id) => state.set(id, values.size === 1 ? [...values][0] : 'ambiguous'));
68
+ }
69
+ }
@@ -0,0 +1,42 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { Beam } from '../beam.js';
13
+ import { Factory } from '../factory.js';
14
+ import { Fraction } from '../fraction.js';
15
+ import { StemmableNote } from '../stemmablenote.js';
16
+ import { Tables } from '../tables.js';
17
+ import { RuntimeError } from '../util.js';
18
+ export function autoBeam(score, notes, options) {
19
+ var _a, _b;
20
+ if (new Set(notes).size !== notes.length)
21
+ throw new RuntimeError('BadArguments', 'Beam notes must be distinct.');
22
+ notes.forEach((note) => {
23
+ if (!(note instanceof StemmableNote) || Factory.getOwner(note) !== score.factory)
24
+ throw new RuntimeError('BadArguments', 'Beam notes must belong to this Factory.');
25
+ if (note.hasBeam())
26
+ throw new RuntimeError('BadArguments', 'Note already belongs to a beam.');
27
+ });
28
+ const time = (_a = score.defaults.time) !== null && _a !== void 0 ? _a : '4/4';
29
+ const signature = typeof time === 'string' ? time : `${time.numBeats}/${time.beatValue}`;
30
+ const groups = (_b = options.groups) !== null && _b !== void 0 ? _b : Beam.getDefaultBeamGroups(signature);
31
+ if (!groups.length ||
32
+ groups.some((group) => !(group instanceof Fraction) || !Number.isFinite(group.value()) || group.value() <= 0)) {
33
+ throw new RuntimeError('BadArguments', 'Beam groups must be positive finite Fractions.');
34
+ }
35
+ if (options.secondaryBreaks !== undefined)
36
+ Tables.durationToTicks(options.secondaryBreaks);
37
+ if (options.stemDirection !== undefined && ![1, -1].includes(options.stemDirection))
38
+ throw new RuntimeError('BadArguments', 'Invalid beam stem direction.');
39
+ const { autoStem } = options, native = __rest(options, ["autoStem"]);
40
+ const stemPolicy = autoStem === false ? 'preserve' : autoStem === true || options.stemDirection !== undefined ? 'auto' : 'explicit';
41
+ return score.build(() => Beam.generateBeams(notes, Object.assign(Object.assign({}, native), { groups: groups.map((group) => group.clone()), stemPolicy })).map((beam) => score.adopt(beam, 'drawable')));
42
+ }