@dsebastien/music-notation 0.8.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.
Files changed (39) hide show
  1. package/README.md +37 -5
  2. package/dist/chord/generate.d.ts +34 -9
  3. package/dist/chord/guitar.d.ts +18 -0
  4. package/dist/circle/circle.d.ts +8 -2
  5. package/dist/cli.js +1 -1
  6. package/dist/convert/text-tab.d.ts +56 -0
  7. package/dist/index.d.ts +9 -8
  8. package/dist/index.js +6599 -4673
  9. package/dist/index.js.map +32 -30
  10. package/dist/keyboard/keyboard.d.ts +17 -2
  11. package/dist/keyboard/piano-chord.d.ts +28 -3
  12. package/dist/keyboard/play-voicing.d.ts +10 -0
  13. package/dist/keyboard/scale-fingering.d.ts +41 -0
  14. package/dist/keyboard/voice-leading.d.ts +55 -4
  15. package/dist/music-notation.css +68 -5
  16. package/dist/music-notation.publish.min.js +91 -28
  17. package/dist/music-notation.tab.min.js +72 -9
  18. package/dist/playback/controls.d.ts +13 -2
  19. package/dist/playback/player.d.ts +69 -5
  20. package/dist/publish/index.js +5306 -3909
  21. package/dist/publish/index.js.map +31 -29
  22. package/dist/render/dom.d.ts +25 -1
  23. package/dist/strum/pattern.d.ts +25 -0
  24. package/dist/strum/play.d.ts +46 -5
  25. package/dist/strum/render.d.ts +4 -1
  26. package/dist/tab/index.d.ts +39 -0
  27. package/dist/tab/index.js +683 -75
  28. package/dist/tab/index.js.map +6 -6
  29. package/dist/theory/detect.d.ts +6 -2
  30. package/dist/theory/find.d.ts +35 -7
  31. package/dist/theory/keys.d.ts +8 -2
  32. package/dist/theory/note-set.d.ts +5 -0
  33. package/dist/theory/numerals.d.ts +34 -7
  34. package/dist/voicings/check.d.ts +17 -0
  35. package/dist/voicings/curated.d.ts +10 -0
  36. package/dist/voicings/index.d.ts +1 -1
  37. package/dist/voicings/index.js +429 -109
  38. package/dist/voicings/index.js.map +10 -8
  39. package/package.json +1 -1
@@ -12,11 +12,26 @@ export interface KeyboardOptions {
12
12
  marks?: NoteMarks;
13
13
  /** How playback plays the highlighted keys: together (a chord) or one by one (a scale). */
14
14
  playAs?: 'chord' | 'scale';
15
- /** Which hand plays each key (MIDI → left or right): an L or R row past the keys. */
15
+ /** Which hand plays each key (MIDI → left or right): a bracket and LH or RH under each hand's keys. */
16
16
  hands?: Map<number, 'left' | 'right'>;
17
17
  }
18
18
  /** "C3-B4" → MIDI range; null when invalid. */
19
19
  export declare function parseKeyRange(text: string): [number, number] | null;
20
- /** Whole octaves around the notes: exact pitches, or two octaves from C4 for pitch classes. */
20
+ /**
21
+ * Where a scale or mode drawn without a range starts: its tonic, from G3 up to F#4, so its two
22
+ * octaves sit nearest middle C's (C major C4-C6, A minor pentatonic A3-A5, F# major F#4-F#6).
23
+ * `octave: -1` for the left hand, an octave lower. Null for anything else than a scale of pitch
24
+ * classes (chords, lists, exact pitches).
25
+ */
26
+ export declare function scaleTonicOf(set: NoteSet, octave?: number): number | null;
27
+ /** A pitch class from G3 up to F#4 (MIDI), `octave` octaves up or down: where a scale or an
28
+ * arpeggio drawn without a range starts. */
29
+ export declare function tonicNearMiddleC(chroma: number, octave?: number): number;
30
+ /** A scale's keys over two octaves, from its tonic up to the tonic two octaves above. */
31
+ export declare function scaleKeysFrom(set: NoteSet, tonic: number): number[];
32
+ /**
33
+ * The keys shown by default: a scale's two octaves from tonic to tonic (see `scaleTonicOf`);
34
+ * whole octaves around exact pitches; two octaves from C4 for other pitch classes.
35
+ */
21
36
  export declare function keyRangeOf(set: NoteSet): [number, number];
22
37
  export declare function renderKeyboard(doc: Document, set: NoteSet, options?: KeyboardOptions): SVGElement;
@@ -1,6 +1,8 @@
1
1
  import { type NoteSet } from '../theory/note-set.js';
2
2
  export type PianoVoicingStyle = 'close' | 'open' | 'shell' | 'rootless';
3
3
  export type RootlessForm = 'A' | 'B';
4
+ /** Shell forms: R-3 (root, third, seventh) or R-7 (root, seventh, third a tenth above the root). */
5
+ export type ShellForm = 'R-3' | 'R-7';
4
6
  export type PianoHands = 'right' | 'left' | 'left+right';
5
7
  export interface PianoVoicingOptions {
6
8
  /** The chord's note in the bass: 0 (root position, default), 1 (first inversion)… */
@@ -10,8 +12,18 @@ export interface PianoVoicingOptions {
10
12
  voicing?: PianoVoicingStyle;
11
13
  /** Rootless voicings: form A (3 5 7 9, default) or B (7 9 3 5). */
12
14
  rootless?: RootlessForm;
15
+ /** Shell voicings: form R-3 (R 3 7, default) or R-7 (R 7 3). */
16
+ shell?: ShellForm;
13
17
  /** Which hand plays what; unset draws no hands. */
14
18
  hands?: PianoHands;
19
+ /**
20
+ * Rootless voicings in a key: its pitch classes (C = 0). A dominant's 9th and 13th and a
21
+ * half-diminished chord's 9th are the key's (G7 in C minor: Ab and Eb), natural when it has
22
+ * neither.
23
+ */
24
+ key?: readonly number[];
25
+ /** Rootless voicings: the chord a dominant resolves to (a fifth below): a minor one flattens its 13th. */
26
+ resolvesTo?: string;
15
27
  }
16
28
  export interface PianoVoicing {
17
29
  /** Every key, low to high (MIDI). */
@@ -22,17 +34,30 @@ export interface PianoVoicing {
22
34
  right: number[];
23
35
  style: PianoVoicingStyle;
24
36
  inversion: number;
37
+ /** How many notes the chord has (3 for a triad, 4 for a seventh chord), a slash bass outside it not counted. */
38
+ tones: number;
25
39
  hands?: PianoHands;
26
40
  }
41
+ /**
42
+ * Whether two neighbouring notes of a voicing (pitches low to high) sit below their low interval
43
+ * limit, so the chord sounds muddy: A2 C3 (a minor third under C3) does, A2 G3 C4 doesn't.
44
+ */
45
+ export declare function belowLowIntervalLimit(pitches: readonly number[]): boolean;
27
46
  /**
28
47
  * A chord's piano voicing (see the module comment for each style). Null when the chord is
29
48
  * unknown; throws an Error saying what to write when an option doesn't fit the chord.
30
49
  */
31
50
  export declare function pianoVoicing(symbol: string, options?: PianoVoicingOptions): PianoVoicing | null;
32
51
  /**
33
- * Fingers for a close triad (`fingering: auto`), low to high: the right hand 1 3 5 in root position
34
- * and second inversion, 1 2 5 in first; the left hand 5 3 1 in root position and first inversion,
35
- * 5 2 1 in second; a left-hand bass under a right-hand chord gets 5. Null for anything else.
52
+ * Fingers for a close triad or seventh chord (`fingering: auto`), low to high. Triads: the right
53
+ * hand 1 3 5 in root position and second inversion, 1 2 5 in first; the left hand 5 3 1 in root
54
+ * position and first inversion, 5 2 1 in second; a left-hand bass under a right-hand chord gets 5.
55
+ * With both hands, the right hand plays the triad in root position over any bass: 1 3 5 (D/F#:
56
+ * F#3 5 + D4 F#4 A4 1 3 5). Four-note chords (sevenths, sixths) by their spacing (`spacedFingers`): the
57
+ * right hand's three or four notes (C7 with both hands: root position C3 + 1 2 3 5, first inversion
58
+ * E3 + G4 Bb4 C5 1 3 4, second G3 + 1 2 3 5, third Bb3 + C5 E5 G5 1 3 5; C7/E: E3 + C G Bb 1 3 5),
59
+ * the left hand alone mirrored (5 3 2 1, 5 4 2 1 with a second at the bottom). Null for anything
60
+ * else.
36
61
  */
37
62
  export declare function triadFingering(voicing: PianoVoicing): Map<number, string> | null;
38
63
  /** Piano voicing of a chord as a note set: close root position from octave 4, a slash chord's bass in octave 3. */
@@ -0,0 +1,10 @@
1
+ import type { NoteSet } from '../theory/note-set.js';
2
+ /**
3
+ * One voicing of a chord within the keys `from`–`to` (MIDI), struck as a block: root position
4
+ * from the lowest root drawn (G7: G B D F, C9: C E G Bb D), each note an octave lower when it
5
+ * would pass the last key. A slash chord takes its lowest bass key, then the chord's other notes
6
+ * in close position above it (C/E: E G C). Null when the set has exact pitches (they play as
7
+ * drawn), no root, no root key within the range, or when the range is too narrow for a voicing
8
+ * with every chord tone (C/G within C4-C5 has no room for E above G4): the lit keys play then.
9
+ */
10
+ export declare function chordVoicingIn(set: NoteSet, from: number, to: number): number[] | null;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Piano scale fingerings (#68): the standard method-book fingerings of the major, harmonic minor,
3
+ * melodic minor (going up) and natural minor scales for each hand, and fingers for every octave of a keyboard.
4
+ *
5
+ * A fingering is written for one octave going up, root to root (8 fingers for a 7-note scale).
6
+ * Over several octaves the pattern repeats and the root where two octaves meet takes the finger
7
+ * that continues the pattern (junctionFinger): the right hand's C major is
8
+ * 1 2 3 1 2 3 4 | 1 2 3 1 2 3 4 | 5, the left hand's 5 4 3 2 1 3 2 | 1 4 3 2 1 3 2 | 1. Only the
9
+ * lowest and highest roots take the octave's first and last fingers.
10
+ */
11
+ export type ScaleHand = 'right' | 'left';
12
+ /** The scale types with standard fingerings, as tonal names them ('minor' is the natural minor). */
13
+ export declare const FINGERED_SCALES: readonly ["major", "harmonic minor", "melodic minor", "minor"];
14
+ /**
15
+ * The standard fingering of a major, harmonic minor, melodic minor (going up) or natural minor
16
+ * scale for one octave going up, root to root ("1 2 3 1 2 3 4 5" as 8 fingers); null for another
17
+ * scale.
18
+ */
19
+ export declare function standardScaleFingering(tonic: number, type: string, hand: ScaleHand): string[] | null;
20
+ /**
21
+ * Fingers for every key of a scale in a stretch of the keyboard (`pitches`, low to high), from a
22
+ * one-octave fingering (`octave`: one finger per scale note going up from the root, and the root
23
+ * above). Each note takes its degree's finger; a root takes junctionFinger's where two octaves meet, the
24
+ * octave's first finger when it is the lowest key and its last when it is the highest.
25
+ */
26
+ export declare function scaleFingers(pitches: readonly number[], root: number, chromas: readonly number[], octave: readonly string[]): Map<number, string>;
27
+ /**
28
+ * The finger on a root where two octaves meet: the one that continues the pattern, as method
29
+ * books write two octaves. It follows the 7th degree's finger and leads to the 2nd degree's (Bb
30
+ * major with 2 1 2 3 1 2 3 4: A 3, Bb 4, C 1; C major: B 4, C 1, D 2). The hand is the one the
31
+ * octave's own steps fit. A pattern no hand plays falls back to the thumb when one end has it,
32
+ * else the first finger.
33
+ */
34
+ export declare function junctionFinger(octave: readonly string[]): string;
35
+ /** A finger list as written ("1 2 3", "5-3-1"): each finger 1 (thumb) to 5; throws otherwise. */
36
+ export declare function parseFingerList(text: string): string[];
37
+ /**
38
+ * `fingering: auto` and its hands: "auto", "auto left", "left hand", "right"… The hand, or null
39
+ * when the value is a list of fingers.
40
+ */
41
+ export declare function autoFingeringHand(text: string): ScaleHand | null;
@@ -1,6 +1,57 @@
1
+ import { belowLowIntervalLimit, type PianoHands, type PianoVoicingOptions, type RootlessForm, type ShellForm } from './piano-chord.js';
2
+ export { belowLowIntervalLimit };
1
3
  /**
2
- * MIDI pitches for each chord, low to high: the first in root position from middle C's octave,
3
- * each next one in the close-position inversion that moves least from the one before (ties go to
4
- * the lower one). A slash chord's bass sounds below. Null for a chord that doesn't read.
4
+ * The smallest total distance, in semitones, when each note of the smaller chord moves to its own
5
+ * note of the larger one; the larger one's other notes each count their distance to the nearest
6
+ * note. Pitches low to high.
5
7
  */
6
- export declare function voiceLead(symbols: readonly string[]): (number[] | null)[];
8
+ export declare function voiceMotion(a: readonly number[], b: readonly number[]): number;
9
+ export interface CloseLeadOptions {
10
+ /**
11
+ * Open voicings: each inversion with its second note from the bottom an octave up (C G E),
12
+ * the lowest note within C3–C4.
13
+ */
14
+ open?: boolean;
15
+ /**
16
+ * A bass for the left hand under every chord (the pop texture): the root, or a slash chord's
17
+ * bass, at least a fourth under the chord, from octave 3 down; a slash chord's bass, and the
18
+ * next chord's, the nearest to the bass before (C C7/Bb F/A: C3 Bb2 A2), not below C2. The
19
+ * chord keeps a root or fifth bass doubled.
20
+ */
21
+ bass?: boolean;
22
+ }
23
+ /**
24
+ * MIDI pitches for each chord, low to high: the first in root position nearest middle C, each next
25
+ * one in the close-position inversion that moves least from the one before (see the module
26
+ * comment), its lowest note within F3–G4 (open voicings: see CloseLeadOptions). A slash chord's
27
+ * bass sounds below (its third or seventh not doubled in the chord). Null for a chord that doesn't
28
+ * read.
29
+ */
30
+ export declare function voiceLead(symbols: readonly string[], options?: CloseLeadOptions): (number[] | null)[];
31
+ export interface VoiceLeadOptions {
32
+ voicing: 'shell' | 'rootless';
33
+ /** The first chord's form (rootless A, shell R-3 by default); the next ones move least. */
34
+ form?: RootlessForm | ShellForm;
35
+ /** Moves the range by octaves: 3 (the default) keeps it around middle C. */
36
+ octave?: number;
37
+ hands?: PianoHands;
38
+ /** The key's pitch classes, for rootless voicings' 9ths and 13ths (see pianoVoicing). */
39
+ key?: readonly number[];
40
+ }
41
+ export interface LedVoicing {
42
+ /** The chord's voicing options: style, form, octave (and hands). */
43
+ options: PianoVoicingOptions;
44
+ /** Every key, low to high (MIDI). */
45
+ pitches: number[];
46
+ }
47
+ /**
48
+ * Shell or rootless voicings for each chord of a progression, low to high: the first chord in its
49
+ * form (rootless A, shell R-3 unless `form` says) at the bottom of its range, each next one in
50
+ * the form and octave that moves least from the one before (shells count their third and seventh:
51
+ * the root is the bass's and leaps). A shell whose notes, as played, would sit below their low
52
+ * interval limit (`belowLowIntervalLimit`) takes the other form: Am7 R-3 is A2 C3 G3, a minor third
53
+ * under C3, so it is played R-7, A2 G3 C4 (the first chord too, whatever `form` says). With both
54
+ * hands the third sounds a tenth above the root (A2 + C4 G4), so R-3 stays. Null for a chord that
55
+ * doesn't read or can't take the voicing (a triad has no seventh for a shell).
56
+ */
57
+ export declare function voiceLeadVoicings(symbols: readonly string[], options: VoiceLeadOptions): (LedVoicing | null)[];
@@ -18,6 +18,10 @@
18
18
  /* Piano keys keep their real colors in every theme. */
19
19
  --mn-key-white: #fafafa;
20
20
  --mn-key-black: #222;
21
+ /* Faint keys (a compared scale's notes, a chord's notes outside the scale): a pale white key, a
22
+ mid-grey black key, in every theme. */
23
+ --mn-key-white-faint: #d4d4d8;
24
+ --mn-key-black-faint: #8c8c8c;
21
25
  font-family: var(--font-interface, system-ui, sans-serif);
22
26
  }
23
27
 
@@ -219,10 +223,19 @@
219
223
  background: var(--mn-accent);
220
224
  }
221
225
 
222
- .mn-playable [data-midi] {
226
+ .mn-playable [data-midi],
227
+ .mn-playable .mn-hit {
223
228
  cursor: pointer;
224
229
  }
225
230
 
231
+ /* A playable mark's hit area: invisible, but it takes clicks and taps (an open string's circle is
232
+ only a ring), centered on the mark. */
233
+ .mn-svg .mn-hit {
234
+ fill: transparent;
235
+ stroke: none;
236
+ pointer-events: all;
237
+ }
238
+
226
239
  /* A finger number or note name over a dot or key lets the click reach it. */
227
240
  .mn-playable .mn-svg text {
228
241
  pointer-events: none;
@@ -304,6 +317,25 @@
304
317
  opacity: 0.8;
305
318
  }
306
319
 
320
+ /* The view control (Tab, Score, Both): one segmented group, the view drawn in the accent color. */
321
+ .mn-tab-views {
322
+ display: inline-flex;
323
+ align-items: center;
324
+ gap: 1px;
325
+ padding-left: 6px;
326
+ border-left: 1px solid var(--mn-faint);
327
+ }
328
+
329
+ .mn-play .mn-tab-views .mn-tab-keep {
330
+ margin-left: 4px;
331
+ text-decoration: underline;
332
+ text-underline-offset: 2px;
333
+ }
334
+
335
+ .mn-play .mn-tab-views .mn-tab-keep[hidden] {
336
+ display: none;
337
+ }
338
+
307
339
  .mn-tab-hidden {
308
340
  position: absolute;
309
341
  width: 1px;
@@ -341,9 +373,17 @@
341
373
  stroke-dasharray: 2 2;
342
374
  }
343
375
 
344
- .mn-svg .mn-key-white.mn-ghost,
376
+ /* Piano keys keep their colors in every theme (the border color would turn a white key dark grey
377
+ and hide a black key in dark themes). */
378
+ .mn-svg .mn-key-white.mn-ghost {
379
+ fill: var(--mn-key-white-faint);
380
+ stroke: #6b6b6b;
381
+ stroke-dasharray: 3 2;
382
+ }
383
+
345
384
  .mn-svg .mn-key-black.mn-ghost {
346
- fill: var(--mn-faint);
385
+ fill: var(--mn-key-black-faint);
386
+ stroke: var(--mn-key-black-faint);
347
387
  stroke-dasharray: none;
348
388
  }
349
389
 
@@ -363,6 +403,14 @@
363
403
  stroke: var(--mn-root);
364
404
  }
365
405
 
406
+ /* A muted string: an x as big and as dark as an open string's circle. */
407
+ .mn-svg .mn-muted {
408
+ fill: none;
409
+ stroke: var(--mn-fg);
410
+ stroke-width: 1.5;
411
+ stroke-linecap: round;
412
+ }
413
+
366
414
  /* A capo: a bar across the strings, in the text color but lighter than the dots. */
367
415
  .mn-svg .mn-capo {
368
416
  fill: var(--mn-fg);
@@ -384,7 +432,6 @@
384
432
  fill: var(--mn-muted);
385
433
  }
386
434
 
387
- .mn-svg .mn-muted,
388
435
  .mn-svg .mn-base-fret,
389
436
  .mn-svg .mn-fret-number,
390
437
  .mn-svg .mn-string-name {
@@ -434,7 +481,8 @@
434
481
  font-weight: 600;
435
482
  }
436
483
 
437
- /* Which hand plays each key of a piano chord (hands: left+right): L or R under the keys. */
484
+ /* Which hand plays the keys of a piano chord (hands: left+right): a bracket under each hand's
485
+ keys, LH or RH under it. */
438
486
  .mn-svg .mn-key-hand {
439
487
  font-size: 10px;
440
488
  font-weight: 600;
@@ -445,6 +493,15 @@
445
493
  fill: var(--mn-fg);
446
494
  }
447
495
 
496
+ .mn-svg .mn-hand-bracket {
497
+ stroke: var(--mn-muted);
498
+ stroke-width: 1.2;
499
+ }
500
+
501
+ .mn-svg .mn-hand-bracket.mn-hand-left {
502
+ stroke: var(--mn-fg);
503
+ }
504
+
448
505
  /* Several diagrams in one block: a row that wraps, or a grid of at most `columns` columns that
449
506
  also wraps on narrow screens rather than shrinking diagrams to nothing. */
450
507
  .mn-block .mn-row {
@@ -686,6 +743,12 @@
686
743
  font-weight: 600;
687
744
  }
688
745
 
746
+ .mn-svg .mn-strum-feel {
747
+ fill: var(--mn-fg);
748
+ font-size: 12px;
749
+ font-style: italic;
750
+ }
751
+
689
752
  .mn-svg .mn-strum-chord {
690
753
  fill: var(--mn-accent);
691
754
  font-size: 12px;