pepperscore 0.3.0 → 0.4.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.
@@ -19,7 +19,11 @@ export declare const soundingKeyOf: (part: Part, measure: Measure, note: ScoreNo
19
19
  export declare function linkTabParts(score: Score): Score;
20
20
  /** A guitar part: GM programs 25-32 (1-based; nylon to guitar harmonics), the guitar sound, or "guitar" in its name. */
21
21
  export declare const isGuitarPart: (part: Part) => boolean;
22
- /** Notation parts that take TAB: every guitar part (and every part an imported TAB doubles), else the first pitched part. */
22
+ /**
23
+ * Notation parts that take TAB: every guitar part (and every part an imported TAB doubles), else the first pitched
24
+ * part. A part switched to another instrument (instrument-view.ts) takes TAB only if its new instrument is a guitar
25
+ * (its name and its imported TAB no longer count).
26
+ */
23
27
  export declare function tabParts(score: Score): Part[];
24
28
  /** Whether the Notation / TAB / Both switch has anything to switch. */
25
29
  export declare const canShowTab: (score: Score) => boolean;
@@ -45,7 +49,9 @@ export declare function hiddenReaderParts(score: Score, parts: Record<string, Pa
45
49
  * Plan a view: `staffOf` maps parts to baseline staff numbers, `hiddenIds` are parts the reader hid, `stale` is true
46
50
  * when the view moves sounding pitches (transposition: imported `tab.fret`s no longer match, so imported TAB is replaced
47
51
  * by generated TAB and a TAB-only staff is re-fingered). A concert view moves written notes to the pitches they already
48
- * sound, so it never makes TAB stale. `sounding` lists staves whose spelled notes are at sounding pitch (their
52
+ * sound, so it never makes TAB stale. A part of the Score's instrument view (switched or octave-moved,
53
+ * `score.instrumentView`) makes its own TAB stale: generated (its fingerings not fixed) while it is a guitar, else
54
+ * none (it is no longer a TAB part, and its imported TAB staff is hidden). `sounding` lists staves whose spelled notes are at sounding pitch (their
49
55
  * `trans.semi` no longer applies).
50
56
  */
51
57
  export declare function planTab(score: Score, staffOf: Map<string, string>, view: TabView, options: {
@@ -28,8 +28,9 @@ export declare function viewProfile(part: Part, view: ScorePitchView): SpellingP
28
28
  */
29
29
  export declare function scoreForView(score: Score, view: ScorePitchView, semitones: number, flip?: boolean): Score;
30
30
  /**
31
- * The worker's spelling plan for a Score view (`scoreForView`'s result) with its staff numbers: the same interval,
32
- * flip, per-staff profiles and moved staves, and which staves are percussion (never given a key signature).
31
+ * The worker's spelling plan for a Score view (`scoreForView`'s result, optionally instrument-switched by
32
+ * `applyInstrumentView`) with its staff numbers: the same interval, flip, per-staff profiles and moved staves, which
33
+ * staves are percussion (never given a key signature), and the switched staves' shift, clef and octave moves.
33
34
  */
34
35
  export declare function spellingSpecFor(score: Score, staffOf: Map<string, string>): SpellingSpec;
35
36
  /** The key of a measure in a (view) Score, for app-side pitch text such as inferred chord symbols. */
@@ -0,0 +1,468 @@
1
+ //#region src/lib/instrument-model.ts
2
+ var e = [
3
+ "piano",
4
+ "guitar",
5
+ "bassguitar",
6
+ "double-bass",
7
+ "drum-kit",
8
+ "alto-saxophone",
9
+ "tenor-saxophone",
10
+ "bari-saxophone",
11
+ "flute",
12
+ "clarinet",
13
+ "trumpet",
14
+ "trombone",
15
+ "violin",
16
+ "viola",
17
+ "cello",
18
+ "microphone"
19
+ ], t = [
20
+ "beginner",
21
+ "intermediate",
22
+ "advanced"
23
+ ], n = (e, t, n) => Object.freeze({
24
+ beginner: Object.freeze({
25
+ low: e[0],
26
+ high: e[1]
27
+ }),
28
+ intermediate: Object.freeze({
29
+ low: t[0],
30
+ high: t[1]
31
+ }),
32
+ advanced: Object.freeze({
33
+ low: n[0],
34
+ high: n[1]
35
+ })
36
+ }), r = Object.freeze({
37
+ semitones: 0,
38
+ diatonic: 0
39
+ }), i = Object.freeze({
40
+ semitones: 12,
41
+ diatonic: 7
42
+ }), a = Object.freeze({
43
+ semitones: 2,
44
+ diatonic: 1
45
+ }), o = {
46
+ piano: {
47
+ id: "piano",
48
+ label: "Piano",
49
+ gmProgram: 1,
50
+ clef: "treble",
51
+ transposition: r,
52
+ ranges: n([21, 108], [21, 108], [21, 108])
53
+ },
54
+ guitar: {
55
+ id: "guitar",
56
+ label: "Guitar",
57
+ gmProgram: 25,
58
+ clef: "treble",
59
+ transposition: i,
60
+ ranges: n([40, 64], [40, 76], [40, 88])
61
+ },
62
+ bassguitar: {
63
+ id: "bassguitar",
64
+ label: "Bass Guitar",
65
+ gmProgram: 34,
66
+ clef: "bass",
67
+ transposition: i,
68
+ ranges: n([28, 48], [28, 55], [28, 60])
69
+ },
70
+ "double-bass": {
71
+ id: "double-bass",
72
+ label: "Double Bass",
73
+ gmProgram: 33,
74
+ clef: "bass",
75
+ transposition: i,
76
+ ranges: n([28, 48], [28, 55], [28, 64])
77
+ },
78
+ "drum-kit": {
79
+ id: "drum-kit",
80
+ label: "Drum Kit",
81
+ gmProgram: 1,
82
+ clef: "percussion",
83
+ transposition: r
84
+ },
85
+ "alto-saxophone": {
86
+ id: "alto-saxophone",
87
+ label: "Alto Saxophone",
88
+ short: "Alto Sax",
89
+ gmProgram: 66,
90
+ clef: "treble",
91
+ transposition: {
92
+ semitones: 9,
93
+ diatonic: 5
94
+ },
95
+ ranges: n([49, 69], [49, 77], [49, 81])
96
+ },
97
+ "tenor-saxophone": {
98
+ id: "tenor-saxophone",
99
+ label: "Tenor Saxophone",
100
+ short: "Tenor Sax",
101
+ gmProgram: 67,
102
+ clef: "treble",
103
+ transposition: {
104
+ semitones: 14,
105
+ diatonic: 8
106
+ },
107
+ ranges: n([44, 64], [44, 72], [44, 76])
108
+ },
109
+ "bari-saxophone": {
110
+ id: "bari-saxophone",
111
+ label: "Baritone Saxophone",
112
+ short: "Bari Sax",
113
+ gmProgram: 68,
114
+ clef: "treble",
115
+ transposition: {
116
+ semitones: 21,
117
+ diatonic: 12
118
+ },
119
+ ranges: n([37, 57], [37, 65], [36, 69])
120
+ },
121
+ flute: {
122
+ id: "flute",
123
+ label: "Flute",
124
+ gmProgram: 74,
125
+ clef: "treble",
126
+ transposition: r,
127
+ ranges: n([60, 84], [60, 91], [59, 96])
128
+ },
129
+ clarinet: {
130
+ id: "clarinet",
131
+ label: "Clarinet",
132
+ gmProgram: 72,
133
+ clef: "treble",
134
+ transposition: a,
135
+ ranges: n([50, 74], [50, 82], [50, 91])
136
+ },
137
+ trumpet: {
138
+ id: "trumpet",
139
+ label: "Trumpet",
140
+ gmProgram: 57,
141
+ clef: "treble",
142
+ transposition: a,
143
+ ranges: n([55, 72], [54, 79], [52, 86])
144
+ },
145
+ trombone: {
146
+ id: "trombone",
147
+ label: "Trombone",
148
+ gmProgram: 58,
149
+ clef: "bass",
150
+ transposition: r,
151
+ ranges: n([46, 65], [40, 70], [34, 77])
152
+ },
153
+ violin: {
154
+ id: "violin",
155
+ label: "Violin",
156
+ gmProgram: 41,
157
+ clef: "treble",
158
+ transposition: r,
159
+ ranges: n([55, 81], [55, 91], [55, 105])
160
+ },
161
+ viola: {
162
+ id: "viola",
163
+ label: "Viola",
164
+ gmProgram: 42,
165
+ clef: "alto",
166
+ transposition: r,
167
+ ranges: n([48, 76], [48, 84], [48, 96])
168
+ },
169
+ cello: {
170
+ id: "cello",
171
+ label: "Cello",
172
+ gmProgram: 43,
173
+ clef: "bass",
174
+ transposition: r,
175
+ ranges: n([36, 64], [36, 76], [36, 88])
176
+ },
177
+ microphone: {
178
+ id: "microphone",
179
+ label: "Voice",
180
+ gmProgram: 54,
181
+ clef: "treble",
182
+ transposition: r,
183
+ ranges: n([48, 72], [45, 76], [40, 81])
184
+ }
185
+ };
186
+ for (let e of Object.values(o)) Object.freeze(e.transposition), Object.freeze(e);
187
+ var s = Object.freeze(o), c = (e) => s[e].short ?? s[e].label, l = [
188
+ [
189
+ 1,
190
+ 24,
191
+ "piano"
192
+ ],
193
+ [
194
+ 25,
195
+ 32,
196
+ "guitar"
197
+ ],
198
+ [
199
+ 33,
200
+ 33,
201
+ "double-bass"
202
+ ],
203
+ [
204
+ 34,
205
+ 40,
206
+ "bassguitar"
207
+ ],
208
+ [
209
+ 41,
210
+ 41,
211
+ "violin"
212
+ ],
213
+ [
214
+ 42,
215
+ 42,
216
+ "viola"
217
+ ],
218
+ [
219
+ 43,
220
+ 43,
221
+ "cello"
222
+ ],
223
+ [
224
+ 44,
225
+ 44,
226
+ "double-bass"
227
+ ],
228
+ [
229
+ 45,
230
+ 52,
231
+ "violin"
232
+ ],
233
+ [
234
+ 53,
235
+ 55,
236
+ "microphone"
237
+ ],
238
+ [
239
+ 57,
240
+ 57,
241
+ "trumpet"
242
+ ],
243
+ [
244
+ 58,
245
+ 59,
246
+ "trombone"
247
+ ],
248
+ [
249
+ 60,
250
+ 60,
251
+ "trumpet"
252
+ ],
253
+ [
254
+ 61,
255
+ 61,
256
+ "trombone"
257
+ ],
258
+ [
259
+ 62,
260
+ 64,
261
+ "trumpet"
262
+ ],
263
+ [
264
+ 65,
265
+ 66,
266
+ "alto-saxophone"
267
+ ],
268
+ [
269
+ 67,
270
+ 67,
271
+ "tenor-saxophone"
272
+ ],
273
+ [
274
+ 68,
275
+ 68,
276
+ "bari-saxophone"
277
+ ],
278
+ [
279
+ 69,
280
+ 72,
281
+ "clarinet"
282
+ ],
283
+ [
284
+ 73,
285
+ 80,
286
+ "flute"
287
+ ]
288
+ ];
289
+ function u(e) {
290
+ return s[l.find(([t, n]) => e >= t && e <= n)?.[2] ?? "piano"];
291
+ }
292
+ var d = [
293
+ "C",
294
+ "D",
295
+ "E",
296
+ "F",
297
+ "G",
298
+ "A",
299
+ "B"
300
+ ], f = [
301
+ "F",
302
+ "C",
303
+ "G",
304
+ "D",
305
+ "A",
306
+ "E",
307
+ "B"
308
+ ], p = {
309
+ C: 0,
310
+ D: 2,
311
+ E: 4,
312
+ F: 5,
313
+ G: 7,
314
+ A: 9,
315
+ B: 11
316
+ }, m = (e) => (e.octave + 1) * 12 + p[e.step] + e.alter;
317
+ function h(e, t) {
318
+ return t > 0 ? +(f.indexOf(e) < t) : t < 0 && f.length - 1 - f.indexOf(e) < -t ? -1 : 0;
319
+ }
320
+ function g(e, t, n) {
321
+ let r = [];
322
+ for (let t of d) for (let n = Math.floor(e / 12) - 2; n <= Math.floor(e / 12); n++) {
323
+ let i = e - m({
324
+ step: t,
325
+ octave: n,
326
+ alter: 0
327
+ });
328
+ i >= -2 && i <= 2 && r.push({
329
+ step: t,
330
+ octave: n,
331
+ alter: i
332
+ });
333
+ }
334
+ let i = n >= 0 ? 1 : -1, a = (e) => e.alter === h(e.step, t) ? 0 : e.alter === 0 ? 1 : e.alter === i ? 2 : e.alter === -i ? 3 : 4;
335
+ return r.sort((e, t) => a(e) - a(t))[0];
336
+ }
337
+ function _(e, t) {
338
+ return m(e) - t.semitones;
339
+ }
340
+ function v(e, t, n) {
341
+ return g(e + t.semitones, n, n < 0 ? -1 : 1);
342
+ }
343
+ function y(e, t, n) {
344
+ let r = e.octave * 7 + d.indexOf(e.step) + t.diatonic, i = Math.floor(r / 7), a = d[r - i * 7], o = m(e) + t.semitones, s = o - m({
345
+ step: a,
346
+ octave: i,
347
+ alter: 0
348
+ });
349
+ return Math.abs(s) <= 2 ? {
350
+ pitch: {
351
+ step: a,
352
+ octave: i,
353
+ alter: s
354
+ },
355
+ respelled: !1
356
+ } : {
357
+ pitch: v(o, {
358
+ semitones: 0,
359
+ diatonic: 0
360
+ }, n),
361
+ respelled: !0
362
+ };
363
+ }
364
+ var b = (e, t) => y(e, t, 0).pitch;
365
+ function x(e, t) {
366
+ let n = (7 * t.semitones % 12 + 12) % 12;
367
+ n > 6 && (n -= 12);
368
+ let r = e + n;
369
+ return r > 7 ? r - 12 : r < -7 ? r + 12 : r;
370
+ }
371
+ var S = Object.freeze([
372
+ "alto-saxophone",
373
+ "tenor-saxophone",
374
+ "bari-saxophone",
375
+ "trumpet",
376
+ "trombone",
377
+ "flute",
378
+ "clarinet",
379
+ "violin",
380
+ "viola",
381
+ "cello",
382
+ "double-bass"
383
+ ]);
384
+ //#endregion
385
+ //#region src/lib/range-fit-core.ts
386
+ function C(e, t) {
387
+ let n = /* @__PURE__ */ new Map();
388
+ e.forEach((e, t) => e.forEach((e) => n.set(e, t)));
389
+ let r = e.map((e, t) => t), i = (e) => r[e] === e ? e : r[e] = i(r[e]);
390
+ for (let [e, a] of t) {
391
+ let t = n.get(e), o = n.get(a);
392
+ if (t === void 0 || o === void 0) continue;
393
+ let [s, c] = [i(t), i(o)];
394
+ s !== c && (r[Math.max(s, c)] = Math.min(s, c));
395
+ }
396
+ let a = /* @__PURE__ */ new Map();
397
+ return e.forEach((e, t) => {
398
+ let n = i(t);
399
+ a.set(n, [...a.get(n) ?? [], ...e]);
400
+ }), [...a.values()];
401
+ }
402
+ function w(e, t) {
403
+ let n = /* @__PURE__ */ new Map(), r = (e) => {
404
+ let t = e;
405
+ for (; n.has(t);) t = n.get(t);
406
+ return t;
407
+ }, i = [], a = /* @__PURE__ */ new Set(), o = (e) => {
408
+ a.has(e) || (a.add(e), i.push(e));
409
+ };
410
+ for (let [t, i] of e) {
411
+ o(t), o(i);
412
+ let [e, a] = [r(t), r(i)];
413
+ e !== a && n.set(a, e);
414
+ }
415
+ let s = /* @__PURE__ */ new Map();
416
+ for (let e of i) {
417
+ let t = r(e);
418
+ s.set(t, [...s.get(t) ?? [], e]);
419
+ }
420
+ if (t) {
421
+ let e = new Map(t.map((e, t) => [e, t]));
422
+ for (let t of s.values()) t.sort((t, n) => (e.get(t) ?? Infinity) - (e.get(n) ?? Infinity));
423
+ }
424
+ return (e) => a.has(e) ? s.get(r(e)) : [e];
425
+ }
426
+ function T(e, t, n) {
427
+ let r = {}, i = [], a = [];
428
+ for (let t of e) for (let e of t) r[e.id] = 0;
429
+ if (!n || !t) return {
430
+ shifts: r,
431
+ bothWays: i,
432
+ stillOut: a
433
+ };
434
+ let o = (e) => ({
435
+ below: e.some((e) => e < t.low),
436
+ above: e.some((e) => e > t.high)
437
+ });
438
+ for (let t of e) {
439
+ let e = t.flatMap((e) => e.midi), n = t.map((e) => e.id), { below: s, above: c } = o(e);
440
+ if (s && c) {
441
+ i.push(n);
442
+ continue;
443
+ }
444
+ if (!s && !c) continue;
445
+ let l = s ? 12 : -12;
446
+ for (let e of n) r[e] = l;
447
+ let u = o(e.map((e) => e + l));
448
+ (u.below || u.above) && a.push(n);
449
+ }
450
+ return {
451
+ shifts: r,
452
+ bothWays: i,
453
+ stillOut: a
454
+ };
455
+ }
456
+ function E(e, t, n) {
457
+ let r = { ...e };
458
+ for (let e of Object.keys(t)) {
459
+ if (t[e] === void 0) continue;
460
+ let i = n(e), a = i.find((e) => t[e] !== void 0);
461
+ for (let e of i) r[e] = t[a];
462
+ }
463
+ return r;
464
+ }
465
+ //#endregion
466
+ export { x as _, S as a, t as c, h as d, m as f, y as g, b as h, w as i, u as l, _ as m, C as n, s as o, g as p, T as r, e as s, E as t, c as u, v };
467
+
468
+ //# sourceMappingURL=range-fit-core-B1rMWdI4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"range-fit-core-B1rMWdI4.js","names":["INSTRUMENT_IDS","LEVELS","ranges","beginner","intermediate","advanced","CONCERT","OCTAVE","B_FLAT","INSTRUMENT_TABLE","info","INSTRUMENTS","instrumentName","id","GM_BLOCKS","instrumentFor","low","high","gmProgram","STEPS","SHARP_ORDER","SEMITONES","pitchMidi","p","keyAlter","fifths","step","spellMidi","candidates","octave","target","alter","single","direction","rank","a","b","spelledSoundingMidi","pitch","transposition","writtenPitch","soundingMidi","keyFifths","transposePitchSpelled","index","transposePitch","writtenKeyFifths","shift","concertFifths","EMBED_INSTRUMENTS","joinRuns","runOf","run","i","parent","runs","root","from","to","ties","ra","rb","merged","r","tieChainOf","appearance","seen","note","groups","order","chain","x","y","planShifts","shifts","bothWays","stillOut","phrase","phrases","autoRange","range","outside","midis","m","ids","below","above","after","applyOverrides","out","overrides","chainOf","owner"],"sources":["../src/lib/instrument-model.ts","../src/lib/range-fit-core.ts"],"sourcesContent":["/** The instrument model shared by the reader, the embeds and the editor (`pepperscore/instruments`); framework-free. */\n\n/** The viewer's instrument ids. */\nexport const INSTRUMENT_IDS = [\n 'piano', 'guitar', 'bassguitar', 'double-bass', 'drum-kit', 'alto-saxophone', 'tenor-saxophone', 'bari-saxophone',\n 'flute', 'clarinet', 'trumpet', 'trombone', 'violin', 'viola', 'cello', 'microphone',\n] as const;\nexport const LEVELS = ['beginner', 'intermediate', 'advanced'] as const;\n\nexport type InstrumentId = typeof INSTRUMENT_IDS[number];\nexport type RangeLevel = typeof LEVELS[number];\n/** An instrument a pitched part can be switched to: any but the drum kit (unpitched). */\nexport type SwitchInstrumentId = Exclude<InstrumentId, 'drum-kit'>;\nexport type Transposition = { semitones: number; diatonic: number };\nexport type InstrumentClef = 'treble' | 'bass' | 'alto' | 'tenor' | 'percussion' | 'treble8vb';\nexport type SpelledPitch = { step: 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G'; octave: number; alter: number };\nexport type InstrumentInfo = {\n id: InstrumentId;\n label: string;\n /** The name the editor's controls and status line use when shorter than `label` (\"Alto Sax\"). */\n short?: string;\n /** 1-based GM program (the viewer's voice program); the drum kit plays on channel 10, not a program. */\n gmProgram: number;\n clef: InstrumentClef;\n /** Written minus sounding. */\n transposition: Transposition;\n /** Playable range per level in sounding MIDI, inclusive; absent for unpitched instruments. */\n ranges?: Record<RangeLevel, { low: number; high: number }>;\n};\n\ntype Span = [number, number];\nconst ranges = (beginner: Span, intermediate: Span, advanced: Span): InstrumentInfo['ranges'] => Object.freeze({\n beginner: Object.freeze({ low: beginner[0], high: beginner[1] }),\n intermediate: Object.freeze({ low: intermediate[0], high: intermediate[1] }),\n advanced: Object.freeze({ low: advanced[0], high: advanced[1] }),\n});\nconst CONCERT: Transposition = Object.freeze({ semitones: 0, diatonic: 0 });\nconst OCTAVE: Transposition = Object.freeze({ semitones: 12, diatonic: 7 });\nconst B_FLAT: Transposition = Object.freeze({ semitones: 2, diatonic: 1 });\n\nconst INSTRUMENT_TABLE: Record<InstrumentId, InstrumentInfo> = {\n piano: { id: 'piano', label: 'Piano', gmProgram: 1, clef: 'treble', transposition: CONCERT, ranges: ranges([21, 108], [21, 108], [21, 108]) },\n guitar: { id: 'guitar', label: 'Guitar', gmProgram: 25, clef: 'treble', transposition: OCTAVE, ranges: ranges([40, 64], [40, 76], [40, 88]) },\n bassguitar: { id: 'bassguitar', label: 'Bass Guitar', gmProgram: 34, clef: 'bass', transposition: OCTAVE, ranges: ranges([28, 48], [28, 55], [28, 60]) },\n 'double-bass': { id: 'double-bass', label: 'Double Bass', gmProgram: 33, clef: 'bass', transposition: OCTAVE, ranges: ranges([28, 48], [28, 55], [28, 64]) },\n 'drum-kit': { id: 'drum-kit', label: 'Drum Kit', gmProgram: 1, clef: 'percussion', transposition: CONCERT },\n 'alto-saxophone': { id: 'alto-saxophone', label: 'Alto Saxophone', short: 'Alto Sax', gmProgram: 66, clef: 'treble', transposition: { semitones: 9, diatonic: 5 }, ranges: ranges([49, 69], [49, 77], [49, 81]) },\n 'tenor-saxophone': { id: 'tenor-saxophone', label: 'Tenor Saxophone', short: 'Tenor Sax', gmProgram: 67, clef: 'treble', transposition: { semitones: 14, diatonic: 8 }, ranges: ranges([44, 64], [44, 72], [44, 76]) },\n 'bari-saxophone': { id: 'bari-saxophone', label: 'Baritone Saxophone', short: 'Bari Sax', gmProgram: 68, clef: 'treble', transposition: { semitones: 21, diatonic: 12 }, ranges: ranges([37, 57], [37, 65], [36, 69]) },\n flute: { id: 'flute', label: 'Flute', gmProgram: 74, clef: 'treble', transposition: CONCERT, ranges: ranges([60, 84], [60, 91], [59, 96]) },\n clarinet: { id: 'clarinet', label: 'Clarinet', gmProgram: 72, clef: 'treble', transposition: B_FLAT, ranges: ranges([50, 74], [50, 82], [50, 91]) },\n trumpet: { id: 'trumpet', label: 'Trumpet', gmProgram: 57, clef: 'treble', transposition: B_FLAT, ranges: ranges([55, 72], [54, 79], [52, 86]) },\n trombone: { id: 'trombone', label: 'Trombone', gmProgram: 58, clef: 'bass', transposition: CONCERT, ranges: ranges([46, 65], [40, 70], [34, 77]) },\n violin: { id: 'violin', label: 'Violin', gmProgram: 41, clef: 'treble', transposition: CONCERT, ranges: ranges([55, 81], [55, 91], [55, 105]) },\n viola: { id: 'viola', label: 'Viola', gmProgram: 42, clef: 'alto', transposition: CONCERT, ranges: ranges([48, 76], [48, 84], [48, 96]) },\n cello: { id: 'cello', label: 'Cello', gmProgram: 43, clef: 'bass', transposition: CONCERT, ranges: ranges([36, 64], [36, 76], [36, 88]) },\n microphone: { id: 'microphone', label: 'Voice', gmProgram: 54, clef: 'treble', transposition: CONCERT, ranges: ranges([48, 72], [45, 76], [40, 81]) },\n};\nfor (const info of Object.values(INSTRUMENT_TABLE)) { Object.freeze(info.transposition); Object.freeze(info); }\n/** The model's instruments by id (frozen). */\nexport const INSTRUMENTS: Readonly<Record<InstrumentId, Readonly<InstrumentInfo>>> = Object.freeze(INSTRUMENT_TABLE);\n\n/** The instrument's short name for controls and the status line (`short`, else `label`). */\nexport const instrumentName = (id: InstrumentId): string => INSTRUMENTS[id].short ?? INSTRUMENTS[id].label;\n\n/**\n * GM program blocks (1-based, inclusive) and the instrument nearest each, after the viewer's\n * GM manifest; programs outside every block (synths, ethnic, effects) fall back to piano.\n */\nconst GM_BLOCKS: [number, number, InstrumentId][] = [\n [1, 24, 'piano'], [25, 32, 'guitar'], [33, 33, 'double-bass'], [34, 40, 'bassguitar'],\n [41, 41, 'violin'], [42, 42, 'viola'], [43, 43, 'cello'], [44, 44, 'double-bass'], [45, 52, 'violin'],\n [53, 55, 'microphone'], [57, 57, 'trumpet'], [58, 59, 'trombone'], [60, 60, 'trumpet'], [61, 61, 'trombone'], [62, 64, 'trumpet'],\n [65, 66, 'alto-saxophone'], [67, 67, 'tenor-saxophone'], [68, 68, 'bari-saxophone'], [69, 72, 'clarinet'], [73, 80, 'flute'],\n];\n\n/** The instrument nearest a 1-based GM program; piano when none is near. */\nexport function instrumentFor(gmProgram: number): Readonly<InstrumentInfo> {\n const block = GM_BLOCKS.find(([low, high]) => gmProgram >= low && gmProgram <= high);\n return INSTRUMENTS[block?.[2] ?? 'piano'];\n}\n\nconst STEPS = ['C', 'D', 'E', 'F', 'G', 'A', 'B'] as const;\nconst SHARP_ORDER = ['F', 'C', 'G', 'D', 'A', 'E', 'B'];\nconst SEMITONES: Record<SpelledPitch['step'], number> = { C: 0, D: 2, E: 4, F: 5, G: 7, A: 9, B: 11 };\n\n/** The MIDI number of a pitch (C4 = 60). */\nexport const pitchMidi = (p: SpelledPitch): number => (p.octave + 1) * 12 + SEMITONES[p.step] + p.alter;\n\n/** The alteration the key signature (`fifths`) gives `step`. */\nexport function keyAlter(step: SpelledPitch['step'], fifths: number): number {\n if (fifths > 0) return SHARP_ORDER.indexOf(step) < fifths ? 1 : 0;\n if (fifths < 0) return SHARP_ORDER.length - 1 - SHARP_ORDER.indexOf(step) < -fifths ? -1 : 0;\n return 0;\n}\n\n/**\n * The spelling of MIDI note `target`: the key signature's (`fifths`) spelling if it has one, else the\n * natural, else a sharp going up (`direction` >= 0) or a flat going down, else the other single\n * accidental, else a double.\n */\nexport function spellMidi(target: number, fifths: number, direction: number): SpelledPitch | undefined {\n const candidates: SpelledPitch[] = [];\n for (const step of STEPS) {\n for (let octave = Math.floor(target / 12) - 2; octave <= Math.floor(target / 12); octave++) {\n const alter = target - pitchMidi({ step, octave, alter: 0 });\n if (alter >= -2 && alter <= 2) candidates.push({ step, octave, alter });\n }\n }\n const single = direction >= 0 ? 1 : -1;\n const rank = (p: SpelledPitch) => (p.alter === keyAlter(p.step, fifths) ? 0 : p.alter === 0 ? 1 : p.alter === single ? 2 : p.alter === -single ? 3 : 4);\n return candidates.sort((a, b) => rank(a) - rank(b))[0];\n}\n\n/** The sounding MIDI number of a written pitch on an instrument with `transposition` (written minus sounding). */\nexport function spelledSoundingMidi(pitch: SpelledPitch, transposition: { semitones: number }): number {\n return pitchMidi(pitch) - transposition.semitones;\n}\n\n/**\n * The written pitch of sounding MIDI `soundingMidi` for an instrument with `transposition`, spelled for the\n * written key `keyFifths`: the key's own accidentals first, then naturals, then sharps for chromatic notes in\n * sharp keys and C major, flats in flat keys. Only `semitones` is used: a MIDI number carries no spelling to\n * move by the diatonic interval.\n */\nexport function writtenPitch(soundingMidi: number, transposition: Transposition, keyFifths: number): SpelledPitch {\n const target = soundingMidi + transposition.semitones;\n // Every MIDI number has a natural or single-accidental spelling, so spellMidi always finds one.\n return spellMidi(target, keyFifths, keyFifths < 0 ? -1 : 1)!;\n}\n\n/**\n * `pitch` moved by `t`, keeping its spelling: the step moves by `diatonic` (carrying the octave) and the alter\n * is whatever makes the MIDI number move by `semitones`. When that alter would pass a double accidental the\n * note is respelled with `writtenPitch` for the key `keyFifths` and `respelled` is true.\n */\nexport function transposePitchSpelled(pitch: SpelledPitch, t: Transposition, keyFifths: number): { pitch: SpelledPitch; respelled: boolean } {\n const index = pitch.octave * 7 + STEPS.indexOf(pitch.step) + t.diatonic;\n const octave = Math.floor(index / 7);\n const step = STEPS[index - octave * 7];\n const target = pitchMidi(pitch) + t.semitones;\n const alter = target - pitchMidi({ step, octave, alter: 0 });\n if (Math.abs(alter) <= 2) return { pitch: { step, octave, alter }, respelled: false };\n return { pitch: writtenPitch(target, { semitones: 0, diatonic: 0 }, keyFifths), respelled: true };\n}\n\n/** `pitch` moved by `t`, keeping its spelling (see `transposePitchSpelled`; the fallback spells for C major). */\nexport const transposePitch = (pitch: SpelledPitch, t: Transposition): SpelledPitch => transposePitchSpelled(pitch, t, 0).pitch;\n\n/**\n * The written key (fifths) of music in concert key `concertFifths` shown with `transposition` (written minus\n * sounding): the transposition as fifths, `(7 * semitones) mod 12` normalised to -6..6, added and wrapped\n * back into -7..7. Alto sax (+9 semitones) is +3 fifths; a B-flat instrument +2.\n */\nexport function writtenKeyFifths(concertFifths: number, transposition: Transposition): number {\n let shift = (((7 * transposition.semitones) % 12) + 12) % 12;\n if (shift > 6) shift -= 12;\n const fifths = concertFifths + shift;\n return fifths > 7 ? fifths - 12 : fifths < -7 ? fifths + 12 : fifths;\n}\n\n/** The instruments the embeds offer, in switch order (frozen). */\nexport const EMBED_INSTRUMENTS: readonly InstrumentId[] = Object.freeze([\n 'alto-saxophone', 'tenor-saxophone', 'bari-saxophone', 'trumpet', 'trombone', 'flute', 'clarinet', 'violin', 'viola', 'cello', 'double-bass',\n] as const);\n","// Schema-free range-fit rules shared by the editor and the reader: both build phrases and ties from their\n// own score model and hand them here as plain event ids and MIDI numbers.\n\nexport type Shift = 0 | 12 | -12;\n/** One event (note or chord): its notes' judged MIDI (sounding plus interval). */\nexport type FitEvent = { id: string; midi: number[] };\n\n/** Merges runs of event ids that a tie links (`[from, to]`), keeping the first run's position. */\nexport function joinRuns(runs: string[][], ties: [string, string][]): string[][] {\n const runOf = new Map<string, number>();\n runs.forEach((run, i) => run.forEach((id) => runOf.set(id, i)));\n const parent = runs.map((_, i) => i);\n const root = (i: number): number => (parent[i] === i ? i : (parent[i] = root(parent[i])));\n for (const [from, to] of ties) {\n const a = runOf.get(from), b = runOf.get(to);\n if (a === undefined || b === undefined) continue;\n const [ra, rb] = [root(a), root(b)];\n if (ra !== rb) parent[Math.max(ra, rb)] = Math.min(ra, rb);\n }\n const merged = new Map<number, string[]>();\n runs.forEach((run, i) => {\n const r = root(i);\n merged.set(r, [...(merged.get(r) ?? []), ...run]);\n });\n return [...merged.values()];\n}\n\n/** The ordered chain of events the ties link around `id` (itself alone when untied), in `order` (event order) when given, else by first appearance in the ties. */\nexport function tieChainOf(ties: [string, string][], order?: string[]): (id: string) => string[] {\n const parent = new Map<string, string>();\n const root = (id: string): string => { let r = id; while (parent.has(r)) r = parent.get(r)!; return r; };\n const appearance: string[] = [];\n const seen = new Set<string>();\n const note = (id: string) => { if (!seen.has(id)) { seen.add(id); appearance.push(id); } };\n for (const [from, to] of ties) {\n note(from); note(to);\n const [a, b] = [root(from), root(to)];\n if (a !== b) parent.set(b, a);\n }\n const groups = new Map<string, string[]>();\n for (const id of appearance) {\n const r = root(id);\n groups.set(r, [...(groups.get(r) ?? []), id]);\n }\n if (order) {\n const rank = new Map(order.map((id, i) => [id, i]));\n for (const chain of groups.values()) chain.sort((x, y) => (rank.get(x) ?? Infinity) - (rank.get(y) ?? Infinity));\n }\n return (id) => (seen.has(id) ? groups.get(root(id))! : [id]);\n}\n\nexport type ShiftPlan = { shifts: Record<string, Shift>; bothWays: string[][]; stillOut: string[][] };\n\n/**\n * Plans an octave per phrase: any note below the range moves every event up, above moves it down, both\n * leaves the phrase (listed in `bothWays`); a phrase still out after its move keeps it (listed in\n * `stillOut`). A chord is out when any of its notes is. No range or `autoRange` off plans no shifts.\n */\nexport function planShifts(phrases: FitEvent[][], range: { low: number; high: number } | undefined, autoRange: boolean): ShiftPlan {\n const shifts: Record<string, Shift> = {};\n const bothWays: string[][] = [];\n const stillOut: string[][] = [];\n for (const phrase of phrases) for (const e of phrase) shifts[e.id] = 0;\n if (!autoRange || !range) return { shifts, bothWays, stillOut };\n const outside = (midis: number[]) => ({ below: midis.some((m) => m < range.low), above: midis.some((m) => m > range.high) });\n for (const phrase of phrases) {\n const midis = phrase.flatMap((e) => e.midi);\n const ids = phrase.map((e) => e.id);\n const { below, above } = outside(midis);\n if (below && above) { bothWays.push(ids); continue; }\n if (!below && !above) continue;\n const shift: Shift = below ? 12 : -12;\n for (const id of ids) shifts[id] = shift;\n const after = outside(midis.map((m) => m + shift));\n if (after.below || after.above) stillOut.push(ids);\n }\n return { shifts, bothWays, stillOut };\n}\n\n/** Sets single events from the user's overrides, each extended along its tie chain (the first override on a chain wins); overrides beat planned shifts. */\nexport function applyOverrides(shifts: Record<string, Shift>, overrides: Record<string, Shift>, chainOf: (id: string) => string[]): Record<string, Shift> {\n const out = { ...shifts };\n for (const id of Object.keys(overrides)) {\n if (overrides[id] === undefined) continue;\n const chain = chainOf(id);\n const owner = chain.find((e) => overrides[e] !== undefined)!;\n for (const e of chain) out[e] = overrides[owner];\n }\n return out;\n}\n"],"mappings":";AAGA,IAAaA,IAAiB;CAC5B;CAAS;CAAU;CAAc;CAAe;CAAY;CAAkB;CAAmB;CACjG;CAAS;CAAY;CAAW;CAAY;CAAU;CAAS;CAAS;AAC1E,GACaC,IAAS;CAAC;CAAY;CAAgB;AAAU,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