@dsebastien/music-notation 0.1.1 → 0.1.2
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.
- package/README.md +1 -1
- package/dist/chunks/{index-k43yt97c.js → index-26cddyf5.js} +36 -3
- package/dist/chunks/{index-k43yt97c.js.map → index-26cddyf5.js.map} +5 -4
- package/dist/music-notation.publish.min.js +3 -3
- package/dist/publish/index.js +11 -3
- package/dist/publish/index.js.map +5 -5
- package/dist/theory/suffix.d.ts +1 -0
- package/dist/voicings/index.js +7 -25
- package/dist/voicings/index.js.map +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ labels: intervals
|
|
|
37
37
|
```
|
|
38
38
|
````
|
|
39
39
|
|
|
40
|
-
The full syntax is in the [guide](https://dsebastien.github.io/music-notation/). Mistakes show an inline message and leave the source untouched.
|
|
40
|
+
The full syntax is in the [guide](https://dsebastien.github.io/music-notation/), with [live examples](https://dsebastien.github.io/music-notation/examples.html) and a [playground](https://dsebastien.github.io/music-notation/playground.html). Mistakes show an inline message and leave the source untouched.
|
|
41
41
|
|
|
42
42
|
## Install
|
|
43
43
|
|
|
@@ -43,7 +43,40 @@ function splitChordSymbol(symbol) {
|
|
|
43
43
|
}
|
|
44
44
|
var isFlat = (name) => /^[A-Ga-g][b♭]/.test(name.trim());
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
// src/theory/suffix.ts
|
|
47
|
+
var CANONICAL = new Map([
|
|
48
|
+
["M", ""],
|
|
49
|
+
["maj", ""],
|
|
50
|
+
["min", "m"],
|
|
51
|
+
["-", "m"],
|
|
52
|
+
["M7", "maj7"],
|
|
53
|
+
["Δ", "maj7"],
|
|
54
|
+
["Δ7", "maj7"],
|
|
55
|
+
["M9", "maj9"],
|
|
56
|
+
["Δ9", "maj9"],
|
|
57
|
+
["min6", "m6"],
|
|
58
|
+
["-6", "m6"],
|
|
59
|
+
["min7", "m7"],
|
|
60
|
+
["-7", "m7"],
|
|
61
|
+
["min9", "m9"],
|
|
62
|
+
["-9", "m9"],
|
|
63
|
+
["ø", "m7b5"],
|
|
64
|
+
["ø7", "m7b5"],
|
|
65
|
+
["m7-5", "m7b5"],
|
|
66
|
+
["mmaj7", "mMaj7"],
|
|
67
|
+
["mM7", "mMaj7"],
|
|
68
|
+
["m(maj7)", "mMaj7"],
|
|
69
|
+
["-(maj7)", "mMaj7"],
|
|
70
|
+
["°", "dim"],
|
|
71
|
+
["°7", "dim7"],
|
|
72
|
+
["+", "aug"],
|
|
73
|
+
["sus", "sus4"],
|
|
74
|
+
["add2", "add9"],
|
|
75
|
+
["69", "6/9"]
|
|
76
|
+
]);
|
|
77
|
+
var canonicalSuffix = (suffix) => CANONICAL.get(suffix) ?? suffix;
|
|
47
78
|
|
|
48
|
-
|
|
49
|
-
|
|
79
|
+
export { chromaOf, midiOf, nameOf, splitChordSymbol, isFlat, canonicalSuffix };
|
|
80
|
+
|
|
81
|
+
//# debugId=CC145C48B0360EE764756E2164756E21
|
|
82
|
+
//# sourceMappingURL=index-26cddyf5.js.map
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/theory/pitch.ts"],
|
|
3
|
+
"sources": ["../src/theory/pitch.ts", "../src/theory/suffix.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * Pitch classes and note names. A pitch class is a chroma: 0 = C … 11 = B. Names accept ASCII\n * (`#`, `b`) and Unicode (`♯`, `♭`) accidentals.\n */\n\nexport const SHARP_NAMES = [\n 'C',\n 'C#',\n 'D',\n 'D#',\n 'E',\n 'F',\n 'F#',\n 'G',\n 'G#',\n 'A',\n 'A#',\n 'B'\n] as const\nexport const FLAT_NAMES = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B'] as const\n\nconst LETTER_CHROMA: Record<string, number> = { C: 0, D: 2, E: 4, F: 5, G: 7, A: 9, B: 11 }\n\n/** \"C#\", \"Db\", \"D♭\", \"E\" → 0..11; null when it isn't a note name. */\nexport function chromaOf(name: string): number | null {\n const m = /^([A-Ga-g])([#♯b♭]*)$/.exec(name.trim())\n if (!m) return null\n let chroma = LETTER_CHROMA[m[1]!.toUpperCase()]!\n for (const accidental of m[2]!) chroma += accidental === '#' || accidental === '♯' ? 1 : -1\n return ((chroma % 12) + 12) % 12\n}\n\n/** A note with its octave, scientific pitch notation (\"C4\" = MIDI 60); null when invalid. */\nexport function midiOf(note: string): number | null {\n const m = /^([A-Ga-g][#♯b♭]*)(-?\\d)$/.exec(note.trim())\n if (!m) return null\n const chroma = chromaOf(m[1]!)\n if (chroma === null) return null\n // B#3 is C4 and Cb4 is B3: the letter decides the octave, the accidental can cross it.\n const letter = LETTER_CHROMA[m[1]![0]!.toUpperCase()]!\n const shift = Math.round((chroma - letter) / 12)\n return (Number(m[2]) + 1) * 12 + chroma - shift * 12\n}\n\n/** Name of a pitch class, with sharps or flats. Non-integers are rounded. */\nexport const nameOf = (chroma: number, preferFlats = false): string =>\n (preferFlats ? FLAT_NAMES : SHARP_NAMES)[(((Math.round(chroma) || 0) % 12) + 12) % 12]!\n\nexport interface ChordSymbolParts {\n root: string\n /** Everything between the root and the bass: \"m7\", \"6/9\", \"\". */\n suffix: string\n bass: string | null\n}\n\n/**\n * \"F♯m7/C#\" → root F#, suffix m7, bass C#. A slash starts a bass only when a note name follows\n * (\"C6/9\" has no bass). ♯ and ♭ become # and b.\n */\nexport function splitChordSymbol(symbol: string): ChordSymbolParts | null {\n const normalized = symbol.trim().replace(/♯/g, '#').replace(/♭/g, 'b')\n const m = /^([A-G][#b]?)(.*?)(?:\\/([A-G][#b]?))?$/.exec(normalized)\n return m ? { root: m[1]!, suffix: m[2]!, bass: m[3] ?? null } : null\n}\n\n/** \"C4\" for MIDI 60. */\nexport const noteOf = (midi: number, preferFlats = false): string =>\n `${nameOf(midi, preferFlats)}${Math.floor(midi / 12) - 1}`\n\n/** Whether a name is spelled with a flat (\"Bb\", \"E♭\"). */\nexport const isFlat = (name: string): boolean => /^[A-Ga-g][b♭]/.test(name.trim())\n"
|
|
5
|
+
"/**\n * Pitch classes and note names. A pitch class is a chroma: 0 = C … 11 = B. Names accept ASCII\n * (`#`, `b`) and Unicode (`♯`, `♭`) accidentals.\n */\n\nexport const SHARP_NAMES = [\n 'C',\n 'C#',\n 'D',\n 'D#',\n 'E',\n 'F',\n 'F#',\n 'G',\n 'G#',\n 'A',\n 'A#',\n 'B'\n] as const\nexport const FLAT_NAMES = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B'] as const\n\nconst LETTER_CHROMA: Record<string, number> = { C: 0, D: 2, E: 4, F: 5, G: 7, A: 9, B: 11 }\n\n/** \"C#\", \"Db\", \"D♭\", \"E\" → 0..11; null when it isn't a note name. */\nexport function chromaOf(name: string): number | null {\n const m = /^([A-Ga-g])([#♯b♭]*)$/.exec(name.trim())\n if (!m) return null\n let chroma = LETTER_CHROMA[m[1]!.toUpperCase()]!\n for (const accidental of m[2]!) chroma += accidental === '#' || accidental === '♯' ? 1 : -1\n return ((chroma % 12) + 12) % 12\n}\n\n/** A note with its octave, scientific pitch notation (\"C4\" = MIDI 60); null when invalid. */\nexport function midiOf(note: string): number | null {\n const m = /^([A-Ga-g][#♯b♭]*)(-?\\d)$/.exec(note.trim())\n if (!m) return null\n const chroma = chromaOf(m[1]!)\n if (chroma === null) return null\n // B#3 is C4 and Cb4 is B3: the letter decides the octave, the accidental can cross it.\n const letter = LETTER_CHROMA[m[1]![0]!.toUpperCase()]!\n const shift = Math.round((chroma - letter) / 12)\n return (Number(m[2]) + 1) * 12 + chroma - shift * 12\n}\n\n/** Name of a pitch class, with sharps or flats. Non-integers are rounded. */\nexport const nameOf = (chroma: number, preferFlats = false): string =>\n (preferFlats ? FLAT_NAMES : SHARP_NAMES)[(((Math.round(chroma) || 0) % 12) + 12) % 12]!\n\nexport interface ChordSymbolParts {\n root: string\n /** Everything between the root and the bass: \"m7\", \"6/9\", \"\". */\n suffix: string\n bass: string | null\n}\n\n/**\n * \"F♯m7/C#\" → root F#, suffix m7, bass C#. A slash starts a bass only when a note name follows\n * (\"C6/9\" has no bass). ♯ and ♭ become # and b.\n */\nexport function splitChordSymbol(symbol: string): ChordSymbolParts | null {\n const normalized = symbol.trim().replace(/♯/g, '#').replace(/♭/g, 'b')\n const m = /^([A-G][#b]?)(.*?)(?:\\/([A-G][#b]?))?$/.exec(normalized)\n return m ? { root: m[1]!, suffix: m[2]!, bass: m[3] ?? null } : null\n}\n\n/** \"C4\" for MIDI 60. */\nexport const noteOf = (midi: number, preferFlats = false): string =>\n `${nameOf(midi, preferFlats)}${Math.floor(midi / 12) - 1}`\n\n/** Whether a name is spelled with a flat (\"Bb\", \"E♭\"). */\nexport const isFlat = (name: string): boolean => /^[A-Ga-g][b♭]/.test(name.trim())\n",
|
|
6
|
+
"/**\n * Chord suffixes are written many ways (\"Δ7\", \"M7\", \"maj7\"). One spelling per chord, the one tonal\n * and the voicing data understand, so every spelling the symbol parser accepts also draws.\n */\nconst CANONICAL = new Map<string, string>([\n ['M', ''],\n ['maj', ''],\n ['min', 'm'],\n ['-', 'm'],\n ['M7', 'maj7'],\n ['Δ', 'maj7'],\n ['Δ7', 'maj7'],\n ['M9', 'maj9'],\n ['Δ9', 'maj9'],\n ['min6', 'm6'],\n ['-6', 'm6'],\n ['min7', 'm7'],\n ['-7', 'm7'],\n ['min9', 'm9'],\n ['-9', 'm9'],\n ['ø', 'm7b5'],\n ['ø7', 'm7b5'],\n ['m7-5', 'm7b5'],\n ['mmaj7', 'mMaj7'],\n ['mM7', 'mMaj7'],\n ['m(maj7)', 'mMaj7'],\n ['-(maj7)', 'mMaj7'],\n ['°', 'dim'],\n ['°7', 'dim7'],\n ['+', 'aug'],\n ['sus', 'sus4'],\n ['add2', 'add9'],\n ['69', '6/9']\n])\n\nexport const canonicalSuffix = (suffix: string): string => CAN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