@dsebastien/music-notation 0.3.0 → 0.5.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.
- package/README.md +26 -2
- package/dist/blocks/block-source.d.ts +5 -0
- package/dist/blocks/renderers.d.ts +3 -0
- package/dist/chord/generate.d.ts +71 -0
- package/dist/chord/guitar.d.ts +4 -0
- package/dist/chord/transitions.d.ts +46 -0
- package/dist/chord/triads.d.ts +43 -0
- package/dist/convert/chord-sheet.d.ts +2 -0
- package/dist/convert/text-tab.d.ts +5 -0
- package/dist/fretboard/fretboard.d.ts +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +1884 -17
- package/dist/index.js.map +18 -11
- package/dist/keyboard/keyboard.d.ts +2 -0
- package/dist/music-notation.css +216 -0
- package/dist/music-notation.publish.min.js +239 -11
- package/dist/music-notation.tab.min.js +527 -0
- package/dist/playback/controls.d.ts +21 -0
- package/dist/playback/player.d.ts +50 -0
- package/dist/publish/auto.d.ts +3 -0
- package/dist/publish/index.js +1491 -16
- package/dist/publish/index.js.map +16 -11
- package/dist/tab/auto.d.ts +16 -0
- package/dist/tab/index.d.ts +97 -0
- package/dist/tab/index.js +1043 -0
- package/dist/tab/index.js.map +19 -0
- package/dist/voicings/index.js +3 -2
- package/dist/voicings/index.js.map +3 -3
- package/package.json +21 -2
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ labels: intervals
|
|
|
37
37
|
```
|
|
38
38
|
````
|
|
39
39
|
|
|
40
|
-
Chords in words or recognized from their frets, scale positions and modes:
|
|
40
|
+
Chords in words or recognized from their frets, every way to play a chord, triads, chord transitions, scale positions and modes:
|
|
41
41
|
|
|
42
42
|
````markdown
|
|
43
43
|
```chord
|
|
@@ -46,6 +46,21 @@ F Sharp Minor 7
|
|
|
46
46
|
frets: x02220
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
+
```chord
|
|
50
|
+
A Major
|
|
51
|
+
voicings: 6
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```chord
|
|
55
|
+
G
|
|
56
|
+
triads: 1-3
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```chord
|
|
60
|
+
from: C x32010
|
|
61
|
+
to: Am
|
|
62
|
+
```
|
|
63
|
+
|
|
49
64
|
```fretboard
|
|
50
65
|
A minor pentatonic
|
|
51
66
|
positions: all
|
|
@@ -56,6 +71,12 @@ modes: C major
|
|
|
56
71
|
```
|
|
57
72
|
````
|
|
58
73
|
|
|
74
|
+

|
|
75
|
+
|
|
76
|
+

|
|
77
|
+
|
|
78
|
+

|
|
79
|
+
|
|
59
80
|
Several diagrams side by side, separated by `---`, with shared settings first; vertical or horizontal, and left-handed:
|
|
60
81
|
|
|
61
82
|
````markdown
|
|
@@ -88,6 +109,9 @@ if (!result.ok) console.warn(result.error)
|
|
|
88
109
|
|
|
89
110
|
- `renderBlock(language, source, host, options)` appends the rendering to `host` and never throws. It returns `{ ok, el, error, destroy() }`.
|
|
90
111
|
- `@dsebastien/music-notation/voicings` adds about 1,800 guitar voicings, found by chord symbol (`chord` blocks with only a symbol). It's a separate entry point because the data weighs about 230 KB.
|
|
112
|
+
- **Hear the diagrams**: with the `play` option, a playback bar on each diagram (on hover): chords strum, scales go up and down, a click plays a note.
|
|
113
|
+
- **Tabs and scores**: `@dsebastien/music-notation/tab` draws `tab and `score blocks (alphaTex, or Guitar Pro and MusicXML files) with [alphaTab](https://alphatab.net), with a player; it also converts score files, text tabs and chord sheets, and exports Guitar Pro 7 and MIDI.
|
|
114
|
+
- `generateVoicings(symbol, options)` finds every playable voicing of a chord on any tuning, easiest first, with fingers and shape names; `fingerVoicing(frets)` fingers any voicing.
|
|
91
115
|
- The renderers (`renderGuitarDiagram`, `renderKeyboard`, `renderFretboard`, `renderChart`), the parsers and the theory helpers (`parseChord`, `transposeChord`, `chordNoteSet`, `scaleNoteSet`…) are exported too.
|
|
92
116
|
- Styles: `injectStyles(document)`, or ship `@dsebastien/music-notation/music-notation.css`. Colors follow Obsidian's theme variables, with fallbacks for any page.
|
|
93
117
|
|
|
@@ -97,7 +121,7 @@ Add this to your site's `publish.js`. It loads the bundle only on pages that hav
|
|
|
97
121
|
|
|
98
122
|
```js
|
|
99
123
|
;(() => {
|
|
100
|
-
const VERSION = '0.
|
|
124
|
+
const VERSION = '0.4.0'
|
|
101
125
|
const SELECTOR = ['chord', 'chords', 'keyboard', 'fretboard']
|
|
102
126
|
.map((l) => `pre > code.language-${l}`)
|
|
103
127
|
.join(', ')
|
|
@@ -10,6 +10,11 @@ export interface BlockSource {
|
|
|
10
10
|
export declare function parseBlockSource(source: string): BlockSource;
|
|
11
11
|
/** "5-8", "5", "0 - 12" → [from, to]; null when invalid. */
|
|
12
12
|
export declare function parseRange(text: string): [number, number] | null;
|
|
13
|
+
/**
|
|
14
|
+
* String numbers the way guitarists count them (1 = the highest): "1-3", "1 2 3", "2,4". Throws a
|
|
15
|
+
* message for the user when one is outside 1..count.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseStrings(text: string, count: number): number[];
|
|
13
18
|
/**
|
|
14
19
|
* The parts of a block whose diagrams are separated by `---` lines, without the empty ones;
|
|
15
20
|
* null when the block has no separator.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { VoicingLookup } from '../voicings/index.js';
|
|
2
|
+
import type { PlayOptions } from '../playback/controls.js';
|
|
2
3
|
import { type LayoutDefaults } from '../render/layout.js';
|
|
3
4
|
import { type BlockSource } from './block-source.js';
|
|
4
5
|
import type { Instrument, PropertyNames } from './properties.js';
|
|
@@ -17,6 +18,8 @@ export interface RenderOptions extends LayoutDefaults {
|
|
|
17
18
|
propertyNames?: Partial<PropertyNames>;
|
|
18
19
|
/** The note's instrument; from its tags when absent. */
|
|
19
20
|
instrument?: Instrument;
|
|
21
|
+
/** A playback bar on chord, keyboard and fretboard diagrams (true for the defaults). */
|
|
22
|
+
play?: boolean | PlayOptions;
|
|
20
23
|
}
|
|
21
24
|
export type Renderer = (doc: Document, source: string, options: RenderOptions) => Element;
|
|
22
25
|
/** Renders one diagram from a parsed block (the parts of a row share settings, see renderBlock). */
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every playable way to play a chord on a fretted instrument, ranked by ease (#18). Computed from
|
|
3
|
+
* the chord's notes and the tuning, so it works for any chord tonal knows, any tuning and any
|
|
4
|
+
* string count (up to 8). Strings in options and results count the way guitarists do: 1 is the
|
|
5
|
+
* highest string.
|
|
6
|
+
*/
|
|
7
|
+
import { type FrettedVoicing } from './guitar.js';
|
|
8
|
+
/** Shape names, as guitar teachers use them. */
|
|
9
|
+
export type VoicingShape = 'Open' | 'E-shape barre' | 'A-shape barre' | 'CAGED C' | 'CAGED A' | 'CAGED G' | 'CAGED E' | 'CAGED D' | 'Power chord' | 'Triad' | 'Shell' | 'Other barre';
|
|
10
|
+
export interface GeneratedVoicing extends FrettedVoicing {
|
|
11
|
+
fingers: (string | null)[];
|
|
12
|
+
baseFret: number;
|
|
13
|
+
/** The string the lowest note is on (1 = the highest string). */
|
|
14
|
+
bassString: number;
|
|
15
|
+
/** Which of the chord's notes is in the bass, in the order tonal lists them (0 the root, then
|
|
16
|
+
* usually the third, the fifth, the seventh); null for a slash chord's bass outside the chord. */
|
|
17
|
+
inversion: number | null;
|
|
18
|
+
shape: VoicingShape | null;
|
|
19
|
+
/** Lower is easier. */
|
|
20
|
+
difficulty: number;
|
|
21
|
+
/** What makes it harder: "barre", "stretch", "reach", "awkward fingering", "muted inner
|
|
22
|
+
* string", "open string inside the shape", "open strings far from the frets", "no fifth",
|
|
23
|
+
* "thin". */
|
|
24
|
+
reasons: string[];
|
|
25
|
+
}
|
|
26
|
+
export interface VoicingOptions {
|
|
27
|
+
/** Open-string pitches (MIDI), lowest string first; standard guitar by default. */
|
|
28
|
+
tuning?: number[];
|
|
29
|
+
/** Frets the fretted notes stay within ([5, 9]; 0 counts as 1), or 'open' for the first
|
|
30
|
+
* position (frets 1–4). */
|
|
31
|
+
area?: [number, number] | 'open';
|
|
32
|
+
/** The string the bass note is on (1 = the highest string). */
|
|
33
|
+
bassString?: number;
|
|
34
|
+
/** The strings allowed to sound (1 = the highest string); all by default. */
|
|
35
|
+
strings?: number[];
|
|
36
|
+
/** Which of the chord's notes is in the bass: 0 (the root), 1, 2 or 3 (usually the third, the
|
|
37
|
+
* fifth, the seventh), or 'any'. The root by default, any note on re-entrant tunings
|
|
38
|
+
* (ukulele). Slash chords keep their bass. */
|
|
39
|
+
inversion?: number | 'any';
|
|
40
|
+
/** Frets the hand covers, 4 by default (5 is a stretch, 6 at most). */
|
|
41
|
+
maxSpan?: number;
|
|
42
|
+
/** Open strings may sound; true by default. */
|
|
43
|
+
allowOpen?: boolean;
|
|
44
|
+
/** Fewest sounding strings: 4 by default (2 for power chords), fewer when fewer are allowed. */
|
|
45
|
+
minStrings?: number;
|
|
46
|
+
/** Muted strings between sounding ones; false by default. */
|
|
47
|
+
gaps?: boolean;
|
|
48
|
+
/** The highest fret used, 15 by default (up to 24); at least the area's last fret. */
|
|
49
|
+
maxFret?: number;
|
|
50
|
+
}
|
|
51
|
+
/** Generation explores every combination: more strings than this would be slow. */
|
|
52
|
+
export declare const MAX_GENERATED_STRINGS = 8;
|
|
53
|
+
/**
|
|
54
|
+
* Fingers for a fretted voicing (lowest string first, as frets are): any finger can hold a note or
|
|
55
|
+
* barre adjacent strings on one fret (every string under it sounding at that fret), only the index
|
|
56
|
+
* can lie over strings fretted higher, finger numbers go up with the frets, at most four fingers.
|
|
57
|
+
* The easiest such fingering; null when a hand can't play it.
|
|
58
|
+
*/
|
|
59
|
+
export declare function fingerVoicing(frets: readonly (number | null)[]): (string | null)[] | null;
|
|
60
|
+
/**
|
|
61
|
+
* The shape a voicing is played with: power chord, shell (root, third and seventh or sixth on three
|
|
62
|
+
* or four strings), triad (three adjacent strings, three notes), open (open strings, frets 1–4),
|
|
63
|
+
* E- or A-shape barre and the other CAGED shapes (in standard tuning: the open C, A, G, E or D
|
|
64
|
+
* chord moved up the neck), other barre. Null when it's none of them.
|
|
65
|
+
*/
|
|
66
|
+
export declare function voicingShape(frets: readonly (number | null)[], symbol: string, tuning?: readonly number[], fingers?: readonly (string | null)[] | null): VoicingShape | null;
|
|
67
|
+
/**
|
|
68
|
+
* Every playable voicing of a chord, easiest first; empty when the chord is unknown or nothing
|
|
69
|
+
* fits the options. See VoicingOptions for the filters.
|
|
70
|
+
*/
|
|
71
|
+
export declare function generateVoicings(symbol: string, options?: VoicingOptions): GeneratedVoicing[];
|
package/dist/chord/guitar.d.ts
CHANGED
|
@@ -19,6 +19,10 @@ export interface GuitarDiagramOptions {
|
|
|
19
19
|
orientation?: Orientation;
|
|
20
20
|
/** Left-handed: mirrored (the low string on the right, or the nut on the right). */
|
|
21
21
|
hand?: Hand;
|
|
22
|
+
/** Text in each string's dot instead of its finger (intervals, note names); null for none. */
|
|
23
|
+
labels?: (string | null)[];
|
|
24
|
+
/** Chord transitions: fingers that stay (anchor) or slide (guide), per string. */
|
|
25
|
+
marks?: ('anchor' | 'guide' | null)[];
|
|
22
26
|
}
|
|
23
27
|
/** "x02220", "x-10-12-12-11-10", "x 10 12 12 11 10" → frets; null when invalid. */
|
|
24
28
|
export declare function parseFrets(text: string): (number | null)[] | null;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chord transitions (#21): which voicing of the next chord the hand reaches most easily from the
|
|
3
|
+
* one it holds, and the voicings of a whole progression with the least movement. Fingers that stay
|
|
4
|
+
* on their fret (anchors) and slide along their string (guides) make changes clean.
|
|
5
|
+
*/
|
|
6
|
+
import { type GeneratedVoicing } from './generate.js';
|
|
7
|
+
export interface TransitionStep {
|
|
8
|
+
voicing: GeneratedVoicing;
|
|
9
|
+
/** Strings (indexes, lowest first) whose finger stays on the same fret. */
|
|
10
|
+
anchors: number[];
|
|
11
|
+
/** Strings whose finger slides along the string to another fret. */
|
|
12
|
+
guides: number[];
|
|
13
|
+
/** Frets the hand moves along the neck (between the lowest fretted notes). */
|
|
14
|
+
shift: number;
|
|
15
|
+
/** How much the hand moves: fingers lifted and placed, slides, the shift. Lower is easier. */
|
|
16
|
+
movement: number;
|
|
17
|
+
/** What to do, in plain words. */
|
|
18
|
+
tips: string[];
|
|
19
|
+
}
|
|
20
|
+
export interface TransitionOptions {
|
|
21
|
+
/** Open-string pitches (MIDI), lowest string first; standard guitar by default. */
|
|
22
|
+
tuning?: number[];
|
|
23
|
+
/** The fingers of the voicing held (worked out when absent). */
|
|
24
|
+
fromFingers?: (string | null)[];
|
|
25
|
+
/** How many of the next chord's easiest voicings to consider (30 by default). */
|
|
26
|
+
candidates?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The next chord's voicings, ranked by how easily the hand gets there from the one it holds:
|
|
30
|
+
* anchors and guides first, then a small move, then an easy shape. Empty when the chord is
|
|
31
|
+
* unknown.
|
|
32
|
+
*/
|
|
33
|
+
export declare function transition(from: readonly (number | null)[], toChord: string, options?: TransitionOptions): TransitionStep[];
|
|
34
|
+
export interface ProgressionStep extends Partial<Omit<TransitionStep, 'voicing'>> {
|
|
35
|
+
chord: string;
|
|
36
|
+
voicing: GeneratedVoicing;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The voicing of each chord that makes the whole progression easiest: the shapes' ease and the
|
|
40
|
+
* moves between them, together (each chord's easiest 12 voicings are weighed). The first step has
|
|
41
|
+
* no move. Empty when a chord is unknown.
|
|
42
|
+
*/
|
|
43
|
+
export declare function smoothProgression(chords: readonly string[], options?: {
|
|
44
|
+
tuning?: number[];
|
|
45
|
+
candidates?: number;
|
|
46
|
+
}): ProgressionStep[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type GeneratedVoicing } from './generate.js';
|
|
2
|
+
export interface Triad extends GeneratedVoicing {
|
|
3
|
+
/** 0 root position, 1 first inversion (third in the bass), 2 second (fifth in the bass). */
|
|
4
|
+
inversion: number;
|
|
5
|
+
/** The chord tone on top, as triad charts say it: R, 3, b3, 5… */
|
|
6
|
+
top: string;
|
|
7
|
+
}
|
|
8
|
+
export interface TriadOptions {
|
|
9
|
+
/** Three adjacent strings (1 = the highest): [1, 2, 3], [2, 3, 4]… */
|
|
10
|
+
strings: number[];
|
|
11
|
+
/** One inversion (0, 1, 2) or all of them (the default). */
|
|
12
|
+
inversion?: number | 'any';
|
|
13
|
+
/** Open-string pitches (MIDI), lowest string first; standard guitar by default. */
|
|
14
|
+
tuning?: number[];
|
|
15
|
+
/** The highest fret used, 15 by default. */
|
|
16
|
+
maxFret?: number;
|
|
17
|
+
}
|
|
18
|
+
/** The inversion's name: "root position", "1st inversion", "2nd inversion". */
|
|
19
|
+
export declare const inversionName: (inversion: number) => string;
|
|
20
|
+
/**
|
|
21
|
+
* Close triads (the three notes within four frets) of a three-note chord (major, minor, diminished, augmented, sus) on a string set,
|
|
22
|
+
* up the neck (then root position first). Empty for other chords or a string set that isn't three
|
|
23
|
+
* adjacent strings.
|
|
24
|
+
*/
|
|
25
|
+
export declare function triadVoicings(symbol: string, options: TriadOptions): Triad[];
|
|
26
|
+
export interface KeyTriad {
|
|
27
|
+
/** "I", "ii", "iii", "IV", "V", "vi", "vii°". */
|
|
28
|
+
numeral: string;
|
|
29
|
+
symbol: string;
|
|
30
|
+
triad: Triad;
|
|
31
|
+
}
|
|
32
|
+
/** "G major", "E minor" (natural minor): the tonic and the mode; null otherwise. */
|
|
33
|
+
export declare function parseKey(text: string): {
|
|
34
|
+
tonic: string;
|
|
35
|
+
minor: boolean;
|
|
36
|
+
} | null;
|
|
37
|
+
/**
|
|
38
|
+
* A key's seven triads on a string set, one inversion, moving up the neck: each one at or above
|
|
39
|
+
* the previous one when it can be. Null when the key can't be read.
|
|
40
|
+
*/
|
|
41
|
+
export declare function keyTriads(key: string, options: Omit<TriadOptions, 'inversion'> & {
|
|
42
|
+
inversion?: number;
|
|
43
|
+
}): KeyTriad[] | null;
|
|
@@ -15,5 +15,7 @@ export interface FretboardOptions {
|
|
|
15
15
|
/** Only these notes (a scale position); the frets shown follow them. */
|
|
16
16
|
cells?: Cell[];
|
|
17
17
|
marks?: NoteMarks;
|
|
18
|
+
/** Only notes on these strings (indexes, lowest first): triads on a string set. */
|
|
19
|
+
strings?: number[];
|
|
18
20
|
}
|
|
19
21
|
export declare function renderFretboard(doc: Document, set: NoteSet, options?: FretboardOptions): SVGElement;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,11 @@ export { parseOrientation, parseHand, layoutDefaults, type Orientation, type Han
|
|
|
3
3
|
export type { RenderOptions, NotationLanguage } from './blocks/renderers.js';
|
|
4
4
|
export { STYLES, injectStyles } from './styles.js';
|
|
5
5
|
export { renderGuitarDiagram, parseFrets, parseFingers, baseFretOf, STANDARD_TUNING, type FrettedVoicing, type GuitarDiagramOptions } from './chord/guitar.js';
|
|
6
|
+
export { generateVoicings, fingerVoicing, voicingShape, MAX_GENERATED_STRINGS, type GeneratedVoicing, type VoicingOptions, type VoicingShape } from './chord/generate.js';
|
|
7
|
+
export { sequenceOf, lengthOf, lightPlayer, pluckedString, pianoTone, DEFAULT_SEQUENCE, type NoteEvent, type NotePlayer, type PlayHandle, type PlayKind, type Sound, type SequenceOptions } from './playback/player.js';
|
|
8
|
+
export { attachPlayback, type PlayOptions } from './playback/controls.js';
|
|
9
|
+
export { transition, smoothProgression, type TransitionStep, type TransitionOptions, type ProgressionStep } from './chord/transitions.js';
|
|
10
|
+
export { triadVoicings, keyTriads, parseKey, inversionName, type Triad, type TriadOptions, type KeyTriad } from './chord/triads.js';
|
|
6
11
|
export { renderKeyboard, parseKeyRange, keyRangeOf, type KeyboardOptions } from './keyboard/keyboard.js';
|
|
7
12
|
export { renderFretboard, type FretboardOptions } from './fretboard/fretboard.js';
|
|
8
13
|
export { parseTuning } from './fretboard/tuning.js';
|
|
@@ -18,3 +23,5 @@ export { detectChordFromFrets, detectChordFromPitches, type DetectedChord } from
|
|
|
18
23
|
export { scaleName, modesOf, scaleTypes, characteristicIntervals, isScaleWithoutRoot } from './theory/scales.js';
|
|
19
24
|
export { scalePosition, positionCount, CAGED_SHAPES, type Cell, type PositionSystem } from './fretboard/positions.js';
|
|
20
25
|
export { blockFromProperties, instrumentOf, DEFAULT_PROPERTY_NAMES, type PropertyNames, type Instrument } from './blocks/properties.js';
|
|
26
|
+
export { textTabToAlphaTex } from './convert/text-tab.js';
|
|
27
|
+
export { chordSheetToChordPro } from './convert/chord-sheet.js';
|