@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
@@ -4,7 +4,11 @@ export interface DetectedChord {
4
4
  /** Every reading, the preferred one first. */
5
5
  readings: string[];
6
6
  }
7
- /** The chord played by these pitches (MIDI); null when no chord fits. */
8
- export declare function detectChordFromPitches(pitches: number[]): DetectedChord | null;
7
+ /**
8
+ * The chord played by these pitches (MIDI); null when no chord fits. With `names`, the notes as
9
+ * written (Db, F, B, Eb), the name follows their spelling: Db9, not C#9; and G B F Ab Eb is
10
+ * G7b9b13 (Eb is a flat 13th), G B F Ab D# G7#5b9.
11
+ */
12
+ export declare function detectChordFromPitches(pitches: number[], names?: readonly string[]): DetectedChord | null;
9
13
  /** The chord played by these frets (lowest string first; null = muted); null when no chord fits. */
10
14
  export declare function detectChordFromFrets(frets: (number | null)[], tuning?: number[]): DetectedChord | null;
@@ -16,7 +16,8 @@ export interface FindScalesOptions {
16
16
  /**
17
17
  * How to read the items: note names or chord symbols. By default, chords when any item isn't
18
18
  * a plain note name (G D Em C); "G C D" reads as three notes unless you say chords. Notes with
19
- * octaves (C4 E4 G4) are notes, unless every one could be a power chord (A5 D5 E5).
19
+ * octaves (C4 E4 G4) are notes, unless every one could be a power chord (A5 D5 E5) or a seventh
20
+ * chord (A7 D7 E7).
20
21
  */
21
22
  as?: 'notes' | 'chords';
22
23
  /** Scales with up to this many outside notes are listed too (after the others); 1 by default. */
@@ -26,12 +27,25 @@ export interface FindScalesOptions {
26
27
  }
27
28
  /**
28
29
  * The scales that hold some notes, or the tones of some chords, best first: fewer outside notes
29
- * first, major and minor before their modes, then pentatonic and blues scales, then the harmonic
30
- * and melodic minor and their modes, the others last; a tonic on the first chord's root (or the
31
- * first note) first. Each match lists its missing notes (in the scale, not played) and outside
30
+ * first, a usual scale with exactly the notes played before larger ones (C D E G A: C major
31
+ * pentatonic), major and minor before their modes, then pentatonic and blues scales, then the
32
+ * harmonic and melodic minor and their modes, the others last; the tonic from the first chord's
33
+ * root (or the first note), then the last chord's and a V → I move's (Dm C G: D dorian; Dm7 G7
34
+ * Cmaj7: C major). Over a blues (see bluesTonic), the blues scale, the minor pentatonic and the
35
+ * mixolydian first. Each match lists its missing notes (in the scale, not played) and outside
32
36
  * notes (played, not in the scale). Empty when an item doesn't read.
33
37
  */
34
38
  export declare function findScales(input: string | readonly string[], options?: FindScalesOptions): ScaleMatch[];
39
+ /** The scales a teacher suggests over a blues, in order: the blues scale (tonal's "minor
40
+ * blues"), the minor pentatonic, the mixolydian. */
41
+ export declare const BLUES_SCALES: string[];
42
+ /**
43
+ * The tonic of a dominant-seventh blues, as written (A7 D7 E7 A7: A): dominant seventh chords on
44
+ * I and IV, and every chord on I, IV or V (or a jazz blues' ii, #iv°7 and VI7). The first chord's
45
+ * root wins when several could be. Null when the chords aren't a blues (C C7 F: IV isn't a
46
+ * seventh; D7 G7 C: C isn't a blues chord in D).
47
+ */
48
+ export declare function bluesTonic(chords: string | readonly string[]): string | null;
35
49
  /**
36
50
  * Scales to play over a chord (chord-scale): the scales on its root that hold every chord tone,
37
51
  * best first (Cmaj7: C major, C lydian, C major pentatonic…; Dm7: D minor, D dorian, D phrygian…).
@@ -70,13 +84,27 @@ export interface FoundKey extends KeyCandidate {
70
84
  candidates: KeyCandidate[];
71
85
  /** False when another key scores about as well (C major and A minor for C F G Am). */
72
86
  clear: boolean;
87
+ /**
88
+ * A dominant-seventh blues on the key's tonic (A7 D7 E7 A7 in A major): its I7 and IV7 are
89
+ * the key's own chords.
90
+ */
91
+ blues?: boolean;
92
+ /**
93
+ * The mode the chords play in, when it isn't plain major or minor: dorian for a minor key
94
+ * whose chords use the major 6th, not the minor one nor the raised 7th of a V7 (Dm C G: D
95
+ * dorian; Dm G A7 Dm stays D minor), mixolydian for a
96
+ * major key whose chords use the minor 7th and not the major one (C Bb F C: C mixolydian).
97
+ */
98
+ modal?: MusicalKey;
73
99
  }
74
100
  /** Whether every tone of a chord is in the key (a minor key's V and vii° included). */
75
101
  export declare function inKey(symbol: string, key: MusicalKey): boolean;
76
102
  /**
77
103
  * The most likely key of a progression: the key whose chords are in it most (a chord borrowed
78
- * from the parallel key or a secondary dominant counts a little), with the first and last chords
79
- * on its tonic and dominant-to-tonic moves as evidence. The tonic is spelled as the chords spell
80
- * it (Gb major for Gb Db Ebm Cb), else the usual way. Null when a chord doesn't read.
104
+ * from the parallel key or a secondary dominant counts a little), with the first chord (most) and
105
+ * the last chord on its tonic and dominant-to-tonic moves (V7 → I more than V → I) as evidence.
106
+ * A dominant-seventh blues (A7 D7 E7 A7) is in the major key of its tonic, its I7 and IV7 counted
107
+ * in the key. The tonic is spelled as the chords spell it (Gb major for Gb Db Ebm Cb), else the
108
+ * usual way. Null when a chord doesn't read.
81
109
  */
82
110
  export declare function findKey(chords: string | readonly string[]): FoundKey | null;
@@ -57,10 +57,16 @@ export declare function degreeOf(tonic: string, note: string, minorKey?: boolean
57
57
  /** The numeral's text for a chord on a degree: "bVII", "ii7", "vii°", "V7". */
58
58
  export declare function romanText(degree: Degree, suffix: string): string;
59
59
  /**
60
- * The Nashville number for a chord on a degree: "b7", "6m", "2m7", and "5⁷" (a seventh right after
61
- * the number is raised, as charts write it, so it doesn't read as 57).
60
+ * The Nashville number for a chord on a degree: "b7", "6m", "2m⁷", "1maj⁷" and "5⁷" (every number
61
+ * of the chord's quality is raised, as charts write it, so 57 doesn't read as fifty-seven).
62
62
  */
63
63
  export declare function nashvilleText(degree: Degree, suffix: string): string;
64
+ /**
65
+ * A typed Nashville number as charts print it: every number after the degree is raised, "57" →
66
+ * "5⁷", "2-7" → "2-⁷", "1maj7" → "1maj⁷", "57sus4" → "5⁷sus⁴", "b713" → "b7¹³"; a bass after a
67
+ * slash ("5/3") and roman numerals stay as written.
68
+ */
69
+ export declare const raisedNashville: (token: string) => string;
64
70
  /** "5⁷" → "57": superscript digits as plain ones. */
65
71
  export declare const plainDigits: (text: string) => string;
66
72
  export interface KeyChord {
@@ -46,6 +46,11 @@ export declare function intervalLabel(interval: string): string;
46
46
  export declare function labelOf(member: NoteSetMember, label: NoteLabel, finger?: string): string;
47
47
  /** Notes of a chord symbol ("Cmaj7", "C/G"); null when tonal doesn't know it. */
48
48
  export declare function chordNoteSet(symbol: string): NoteSet | null;
49
+ /**
50
+ * Notes given with a chord symbol take the chord's root and its spelling (Cdim7 over C Eb Gb A:
51
+ * the A is written Bbb, as the symbol spells it); notes the chord doesn't have keep theirs.
52
+ */
53
+ export declare function respell(set: NoteSet, chord: NoteSet): void;
49
54
  /** Notes of a scale ("A minor pentatonic", "D dorian"); null when tonal doesn't know it. */
50
55
  export declare function scaleNoteSet(name: string): NoteSet | null;
51
56
  /** A root written for a list ("C", "f#", "E♭", "A3"): its name ("C", "F#", "Eb"), else null. */
@@ -1,6 +1,16 @@
1
1
  import { type MusicalKey } from './keys.js';
2
2
  /** What a chord does in its key. */
3
- export type HarmonicFunction = 'tonic' | 'subdominant' | 'dominant' | 'secondary dominant' | 'borrowed' | 'chromatic';
3
+ export type HarmonicFunction = 'tonic' | 'subdominant' | 'dominant' | 'secondary dominant' | 'neapolitan' | 'borrowed' | 'chromatic' | 'tonicization' | 'passing';
4
+ /** How to read the chords of a progression. */
5
+ export interface NumeralOptions {
6
+ /**
7
+ * A dominant-seventh blues (see `bluesTonic`): a dominant seventh on I or IV is the key's own
8
+ * chord (A7 is I7 and tonic in an A blues, not V7/IV), as blues players read it.
9
+ */
10
+ blues?: boolean;
11
+ /** The numeral by degree only, never as a secondary dominant (Ebdim7 in C: biii°7). */
12
+ byDegree?: boolean;
13
+ }
4
14
  export interface ProgressionChord {
5
15
  /** As written: "V7/V", "6m", "Em". */
6
16
  written: string;
@@ -20,14 +30,18 @@ export interface ProgressionChord {
20
30
  * with m or - (6-, 2-7), b7, 5/3 (bass).
21
31
  */
22
32
  export declare function readNumeral(token: string, key: string | MusicalKey): string | null;
23
- /** What a chord does in a key: its diatonic function, or secondary dominant, borrowed, chromatic. */
24
- export declare function harmonicFunction(symbol: string, key: string | MusicalKey): HarmonicFunction | null;
33
+ /**
34
+ * What a chord does in a key: its diatonic function, or secondary dominant (leading-tone chords
35
+ * included: F#dim in C leads to G), neapolitan (bII), borrowed, chromatic.
36
+ */
37
+ export declare function harmonicFunction(symbol: string, key: string | MusicalKey, options?: NumeralOptions): HarmonicFunction | null;
25
38
  /**
26
39
  * A chord's numeral in a key: "bVII", "ii7", "vii°" (in minor too: the leading tone), a
27
- * secondary dominant as "V7/V", a bass as a degree ("I/3"). Roman numerals by default, or
28
- * Nashville numbers ("b7", "2m7", "1/3"). Null when the chord or the key doesn't read.
40
+ * secondary dominant as "V7/V" and a secondary leading-tone chord as "vii°7/V", a bass as a
41
+ * degree ("I/3"). Roman numerals by default, or Nashville numbers ("b7", "2m7", "1/3"). In a
42
+ * blues (see NumeralOptions), A7 in A is I7. Null when the chord or the key doesn't read.
29
43
  */
30
- export declare function numeralOf(symbol: string, key: string | MusicalKey, style?: 'roman' | 'nashville'): string | null;
44
+ export declare function numeralOf(symbol: string, key: string | MusicalKey, style?: 'roman' | 'nashville', options?: NumeralOptions): string | null;
31
45
  /** Tokens of a progression: spaces, commas and bar lines separate them. */
32
46
  export declare const progressionTokens: (text: string) => string[];
33
47
  /**
@@ -36,5 +50,18 @@ export declare const progressionTokens: (text: string) => string[];
36
50
  * Nashville number and function. Null when the key or a token doesn't read.
37
51
  */
38
52
  export declare function progressionChords(numerals: string | readonly string[], key: string | MusicalKey): ProgressionChord[] | null;
53
+ /**
54
+ * Local tonicizations, read from each chord and the next: a dominant seventh going to a major or
55
+ * minor chord a fifth below, other than the tonic, is that chord's V7 (secondary dominant), even
56
+ * when the key has it (G7 to C in A minor: V7/bIII, not bVII7) or the chord it goes to is outside
57
+ * the key (Ab7 to Dbmaj7 in C minor: V7/bII). A minor seventh or half-diminished chord outside the
58
+ * key right before it is its ii (Ebm7 Ab7 Dbmaj7 in C minor: ii7/bII V7/bII), and a chord outside
59
+ * the key that is tonicized so is a tonicization (not neapolitan or chromatic). Numerals change only
60
+ * for chord names (a written numeral stays as written); a dominant the key already reads as a
61
+ * secondary dominant keeps its numeral (E7 A7 in C: V7/vi). A blues is left alone.
62
+ */
63
+ export declare function withTonicizations(chords: readonly ProgressionChord[], key: MusicalKey, options?: NumeralOptions): ProgressionChord[];
64
+ /** Whether chords are a dominant-seventh blues on a major key's tonic (A7 D7 E7 in A). */
65
+ export declare function isBluesIn(symbols: readonly string[], key: MusicalKey): boolean;
39
66
  /** One token of a progression (see progressionChords); null when it doesn't read. */
40
- export declare function progressionChord(written: string, key: MusicalKey): ProgressionChord | null;
67
+ export declare function progressionChord(written: string, key: MusicalKey, options?: NumeralOptions): ProgressionChord | null;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * What's wrong with a standard-tuning voicing (lowest string first, null muted) of a chord, in
3
+ * words; null when it plays the chord: every required tone (root, third or sus note, seventh or
4
+ * sixth, altered notes, the highest extension; the perfect fifth and lower extensions may be left
5
+ * out), no other note, the root (a slash chord's bass; any note of a dim7) lowest, and a hand can
6
+ * finger it. An altered dominant (7alt) sounds the root, third and seventh and at least one of b5,
7
+ * #5, b9, #9.
8
+ */
9
+ export declare function voicingProblem(symbol: string, frets: readonly (number | null)[]): string | null;
10
+ /**
11
+ * What's wrong with the fingers of a voicing; null when they're fine: one finger (1–4) on each
12
+ * fretted string and none elsewhere, a finger on several strings only as a barre (one fret, the
13
+ * index or the ring finger, every string under it sounding at that fret or higher, or the pinky on
14
+ * the two highest strings), and higher
15
+ * fingers never on lower frets.
16
+ */
17
+ export declare function fingeringProblem(frets: readonly (number | null)[], fingers: readonly (string | null)[]): string | null;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The standard shapes guitar teachers expect first (#62), ahead of the database's voicings. Keys
3
+ * are chord symbols with canonical suffixes, the lookup's root names (C C# D Eb E F F# G Ab A Bb B) and
4
+ * the database's bass names (C# D# F# G# Bb): "Cmaj7", "Am/G", "E/G#", "C#7alt";
5
+ * values are frets, lowest string first ("x32000", "x-9-8-9-10-x" past fret 9), each optionally
6
+ * followed by its fingers ("xx0211 ---211", "-" for none); without fingers, the generator's
7
+ * fingering. Every entry must pass the same checks as the database (voicings.spec.ts). Our own data
8
+ * (MIT), not taken from chords-db.
9
+ */
10
+ export declare const CURATED: Record<string, readonly string[]>;
@@ -1,4 +1,4 @@
1
- import type { FrettedVoicing } from '../chord/guitar.js';
1
+ import { type FrettedVoicing } from '../chord/guitar.js';
2
2
  /** Finds the n-th voicing (0-based) of a chord symbol; null when unknown. Chords the database
3
3
  * doesn't have get the generator's easiest voicings. */
4
4
  export type VoicingLookup = (symbol: string, index: number) => FrettedVoicing | null;