@dsebastien/music-notation 0.6.0 → 0.8.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 +28 -2
- package/dist/blocks/note-set-field.d.ts +3 -1
- package/dist/blocks/progression.d.ts +6 -0
- package/dist/blocks/renderers.d.ts +12 -1
- package/dist/blocks/scales-for.d.ts +16 -0
- package/dist/chord/capo.d.ts +26 -0
- package/dist/chord/guitar.d.ts +20 -0
- package/dist/chord/transitions.d.ts +15 -7
- package/dist/chords/chart-diagrams.d.ts +46 -0
- package/dist/chords/chart.d.ts +16 -0
- package/dist/chords/chordpro.d.ts +17 -1
- package/dist/chords/defines.d.ts +38 -0
- package/dist/circle/circle.d.ts +21 -0
- package/dist/cli.js +2 -2
- package/dist/convert/text-tab.d.ts +4 -2
- package/dist/fretboard/fretboard.d.ts +11 -0
- package/dist/fretboard/positions.d.ts +12 -5
- package/dist/index.d.ts +20 -5
- package/dist/index.js +5958 -1831
- package/dist/index.js.map +40 -23
- package/dist/keyboard/keyboard.d.ts +2 -0
- package/dist/keyboard/piano-chord.d.ts +44 -0
- package/dist/keyboard/voice-leading.d.ts +6 -0
- package/dist/music-notation.css +339 -0
- package/dist/music-notation.publish.min.js +362 -21
- package/dist/music-notation.tab.min.js +343 -4
- package/dist/playback/controls.d.ts +10 -1
- package/dist/playback/follow.d.ts +45 -0
- package/dist/playback/player.d.ts +16 -6
- package/dist/playback/strum-bar.d.ts +5 -0
- package/dist/publish/index.js +5283 -1760
- package/dist/publish/index.js.map +39 -22
- package/dist/strum/pattern.d.ts +49 -0
- package/dist/strum/play.d.ts +106 -0
- package/dist/strum/render.d.ts +17 -0
- package/dist/strum/voicing.d.ts +10 -0
- package/dist/tab/index.d.ts +2 -1
- package/dist/tab/index.js +353 -80
- package/dist/tab/index.js.map +7 -7
- package/dist/theory/chord-symbol.d.ts +2 -0
- package/dist/theory/find.d.ts +82 -0
- package/dist/theory/keys.d.ts +79 -0
- package/dist/theory/note-set.d.ts +2 -0
- package/dist/theory/numerals.d.ts +40 -0
- package/dist/theory/pitch.d.ts +4 -1
- package/dist/theory/transpose.d.ts +16 -4
- package/dist/voicings/index.js +58 -14
- package/dist/voicings/index.js.map +5 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,6 +71,23 @@ modes: C major
|
|
|
71
71
|
```
|
|
72
72
|
````
|
|
73
73
|
|
|
74
|
+
Progressions in roman numerals or Nashville numbers, the circle of fifths, and the scale that fits a song's chords:
|
|
75
|
+
|
|
76
|
+
````markdown
|
|
77
|
+
```progression
|
|
78
|
+
I V vi IV
|
|
79
|
+
key: G
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```circle
|
|
83
|
+
key: E minor
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
```fretboard
|
|
87
|
+
scales-for: G D Em C
|
|
88
|
+
```
|
|
89
|
+
````
|
|
90
|
+
|
|
74
91
|

|
|
75
92
|
|
|
76
93
|

|
|
@@ -110,6 +127,7 @@ if (!result.ok) console.warn(result.error)
|
|
|
110
127
|
- `renderBlock(language, source, host, options)` appends the rendering to `host` and never throws. It returns `{ ok, el, error, destroy() }`.
|
|
111
128
|
- `@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
129
|
- **Hear the diagrams**: the `play` option adds a playback bar to each diagram, shown on hover. Chords strum, scales go up and down, and a click plays a note.
|
|
130
|
+
- **Strumming patterns**: `strum` blocks draw a pattern (`D DU UDU`, `D - D U - U D U`) on a beat grid with counts, accents, muted and ghost strums and chord changes; with playback on, they play over their chords, with loop, tempo and a count-in. `playStrum(pattern, { bpm, chord, tuning })` plays one from code.
|
|
113
131
|
- **Tabs and scores**: `@dsebastien/music-notation/tab` draws `tab` and `score` blocks (alphaTex, or Guitar Pro and MusicXML files) with [alphaTab](https://alphatab.net), and adds a player. It also converts score files, text tabs and chord sheets, and exports Guitar Pro 7 and MIDI.
|
|
114
132
|
- `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.
|
|
115
133
|
- The renderers (`renderGuitarDiagram`, `renderKeyboard`, `renderFretboard`, `renderChart`), the parsers and the theory helpers (`parseChord`, `transposeChord`, `chordNoteSet`, `scaleNoteSet`…) are exported too.
|
|
@@ -131,10 +149,18 @@ Add this to your site's `publish.js`. It loads the bundle only on pages that hav
|
|
|
131
149
|
|
|
132
150
|
```js
|
|
133
151
|
;(() => {
|
|
134
|
-
const VERSION = '0.
|
|
152
|
+
const VERSION = '0.7.0'
|
|
135
153
|
const CDN = `https://cdn.jsdelivr.net/npm/@dsebastien/music-notation@${VERSION}/dist`
|
|
136
154
|
const selector = (languages) => languages.map((l) => `pre > code.language-${l}`).join(', ')
|
|
137
|
-
const BLOCKS = selector([
|
|
155
|
+
const BLOCKS = selector([
|
|
156
|
+
'chord',
|
|
157
|
+
'chords',
|
|
158
|
+
'keyboard',
|
|
159
|
+
'fretboard',
|
|
160
|
+
'strum',
|
|
161
|
+
'progression',
|
|
162
|
+
'circle'
|
|
163
|
+
])
|
|
138
164
|
const TABS = selector(['tab', 'score'])
|
|
139
165
|
const requested = new Set()
|
|
140
166
|
const load = (file) => {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/** Shared by keyboard and fretboard blocks: which notes to show and how to label them. */
|
|
2
2
|
import type { BlockSource } from './block-source.js';
|
|
3
3
|
import { type NoteLabel, type NoteMarks, type NoteSet } from '../theory/note-set.js';
|
|
4
|
+
/** The chord of `chord:` or `arpeggio:` (they name the same thing: both is a mistake). */
|
|
5
|
+
export declare function chordField(block: BlockSource): string | undefined;
|
|
4
6
|
/**
|
|
5
|
-
* `scale:`, `chord:` or `notes:`; a shorthand first line is tried as each, in that order. `root:`
|
|
7
|
+
* `scale:`, `chord:` (or `arpeggio:`) or `notes:`; a shorthand first line is tried as each, in that order. `root:`
|
|
6
8
|
* gives a list its intervals and degrees; a shorthand line with a root is read as a list first.
|
|
7
9
|
*/
|
|
8
10
|
export declare function noteSetOf(block: BlockSource): NoteSet;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DiagramRenderer, RenderOptions } from './renderers.js';
|
|
2
|
+
/**
|
|
3
|
+
* The `progression` block. Diagrams are drawn by the chord block's renderer, passed in (so this
|
|
4
|
+
* module doesn't import the registry that lists it).
|
|
5
|
+
*/
|
|
6
|
+
export declare function renderProgression(doc: Document, source: string, options: RenderOptions, renderChord: DiagramRenderer): Element;
|
|
@@ -3,6 +3,7 @@ import type { PlayOptions } from '../playback/controls.js';
|
|
|
3
3
|
import { type LayoutDefaults } from '../render/layout.js';
|
|
4
4
|
import { type BlockSource } from './block-source.js';
|
|
5
5
|
import type { Instrument, PropertyNames } from './properties.js';
|
|
6
|
+
import { renderStrumBlock } from '../strum/render.js';
|
|
6
7
|
export interface RenderOptions extends LayoutDefaults {
|
|
7
8
|
/** Finds guitar voicings for chord blocks that only give a symbol (see `/voicings`). */
|
|
8
9
|
voicings?: VoicingLookup;
|
|
@@ -18,8 +19,13 @@ export interface RenderOptions extends LayoutDefaults {
|
|
|
18
19
|
propertyNames?: Partial<PropertyNames>;
|
|
19
20
|
/** The note's instrument; from its tags when absent. */
|
|
20
21
|
instrument?: Instrument;
|
|
21
|
-
/** A playback bar on chord, keyboard and fretboard diagrams (true for the defaults). */
|
|
22
|
+
/** A playback bar on chord, keyboard and fretboard diagrams and strum patterns (true for the defaults). */
|
|
22
23
|
play?: boolean | PlayOptions;
|
|
24
|
+
/**
|
|
25
|
+
* The chords used row of `chords` blocks, when a chart has no `{diagrams}`: `'top'`,
|
|
26
|
+
* `'bottom'` or `'off'` (the default). Guitar or piano diagrams follow `instrument`.
|
|
27
|
+
*/
|
|
28
|
+
chartDiagrams?: 'top' | 'bottom' | 'off';
|
|
23
29
|
}
|
|
24
30
|
export type Renderer = (doc: Document, source: string, options: RenderOptions) => Element;
|
|
25
31
|
/** Renders one diagram from a parsed block (the parts of a row share settings, see renderBlock). */
|
|
@@ -28,6 +34,8 @@ export type DiagramRenderer = (doc: Document, block: BlockSource, options: Rende
|
|
|
28
34
|
export type DiagramLanguage = 'chord' | 'keyboard' | 'fretboard';
|
|
29
35
|
/** Keys a row's shared settings may hold, per language (plus `columns`, for the row itself). */
|
|
30
36
|
export declare const SHARED_KEYS: Record<DiagramLanguage, readonly string[]>;
|
|
37
|
+
/** root: in a chord block (or a row it expands into): it only applies to note lists. */
|
|
38
|
+
export declare const ROOT_FOR_LISTS_ONLY = "root only applies to lists of notes on fretboards and keyboards (notes: C E G with root: C): a chord has its own root";
|
|
31
39
|
/** Diagram languages and their renderers. */
|
|
32
40
|
export declare const DIAGRAMS: Record<DiagramLanguage, DiagramRenderer>;
|
|
33
41
|
/** Block languages (code fence names) and their renderers. */
|
|
@@ -36,5 +44,8 @@ export declare const RENDERERS: {
|
|
|
36
44
|
chords: Renderer;
|
|
37
45
|
keyboard: Renderer;
|
|
38
46
|
fretboard: Renderer;
|
|
47
|
+
strum: typeof renderStrumBlock;
|
|
48
|
+
progression: (doc: Document, source: string, options: RenderOptions) => Element;
|
|
49
|
+
circle: Renderer;
|
|
39
50
|
};
|
|
40
51
|
export type NotationLanguage = keyof typeof RENDERERS;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `scales-for: G D Em C` (chords) or `scales-for-notes: C D E G A` on a keyboard or fretboard: the
|
|
3
|
+
* best scale for them, drawn like `scale:` (#42).
|
|
4
|
+
*/
|
|
5
|
+
import { type BlockSource } from './block-source.js';
|
|
6
|
+
import type { DiagramRenderer } from './renderers.js';
|
|
7
|
+
/** The block with `scales-for` replaced by the best scale and a title naming it. */
|
|
8
|
+
export declare function scalesForBlock(block: BlockSource): BlockSource;
|
|
9
|
+
/**
|
|
10
|
+
* A whole block's source with `scales-for` replaced by its scale, for the keys that split a block
|
|
11
|
+
* into a row before it reaches the renderer (`positions:`, `modes:`): `positions: all` draws the
|
|
12
|
+
* found scale's positions, `modes:` is refused by scalesForBlock. The source as it was otherwise.
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveScalesFor(source: string): string;
|
|
15
|
+
/** A keyboard or fretboard renderer that also reads `scales-for`. */
|
|
16
|
+
export declare const withScalesFor: (render: DiagramRenderer) => DiagramRenderer;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** The highest fret a capo goes on. */
|
|
2
|
+
export declare const MAX_CAPO = 12;
|
|
3
|
+
/** Where frets are counted from when a capo is on: the capo (default) or the nut. */
|
|
4
|
+
export type FretsFrom = 'capo' | 'nut';
|
|
5
|
+
/** `capo:` → its fret (0 is no capo); throws a message that says what to write. */
|
|
6
|
+
export declare function parseCapo(text: string): number;
|
|
7
|
+
/** `frets-from:` → capo (default) or nut; throws a message that says what to write. */
|
|
8
|
+
export declare function parseFretsFrom(text: string | undefined): FretsFrom;
|
|
9
|
+
/**
|
|
10
|
+
* The chord a shape sounds with a capo: "A" with a capo on 2 → "B". Spelled the way the new key is
|
|
11
|
+
* usually written (a capo on 1 turns C into Db, Am into Bbm); text that isn't a chord symbol comes
|
|
12
|
+
* back unchanged.
|
|
13
|
+
*/
|
|
14
|
+
export declare function soundingChord(shape: string, capo: number): string;
|
|
15
|
+
/**
|
|
16
|
+
* Frets counted from the nut → counted from the capo; null when a sounding string is behind the
|
|
17
|
+
* capo (it can't sound there).
|
|
18
|
+
*/
|
|
19
|
+
export declare function fretsFromCapo(frets: (number | null)[], capo: number): (number | null)[] | null;
|
|
20
|
+
/** Open-string pitches with the capo on: each string sounds `capo` semitones higher. */
|
|
21
|
+
export declare const capoTuning: (tuning: number[], capo: number) => number[];
|
|
22
|
+
/**
|
|
23
|
+
* Whether `written` names the chord `shape` sounds with the capo (same root and notes, any
|
|
24
|
+
* spelling: A#m and Bbm alike). Unknown chords can't be checked: true.
|
|
25
|
+
*/
|
|
26
|
+
export declare function soundsLike(written: string, shape: string, capo: number): boolean;
|
package/dist/chord/guitar.d.ts
CHANGED
|
@@ -23,6 +23,24 @@ export interface GuitarDiagramOptions {
|
|
|
23
23
|
labels?: (string | null)[];
|
|
24
24
|
/** Chord transitions: fingers that stay (anchor) or slide (guide), per string. */
|
|
25
25
|
marks?: ('anchor' | 'guide' | null)[];
|
|
26
|
+
/**
|
|
27
|
+
* A capo on this fret: drawn as a bar, open strings sound at it, and a caption says "Capo N".
|
|
28
|
+
* Frets are counted from the capo (as players read them) unless `fretsFrom` is `nut`.
|
|
29
|
+
*/
|
|
30
|
+
capo?: number;
|
|
31
|
+
/**
|
|
32
|
+
* `capo` (default): the frets count from the capo, which sits where the nut is drawn. `nut`:
|
|
33
|
+
* the frets count from the nut, the capo is drawn on its fret, and strings at that fret are
|
|
34
|
+
* played by the capo (a ring on it).
|
|
35
|
+
*/
|
|
36
|
+
fretsFrom?: 'capo' | 'nut';
|
|
37
|
+
/** The chord the shape sounds with the capo, added to the caption ("Capo 2, sounds B"). */
|
|
38
|
+
sounds?: string;
|
|
39
|
+
/**
|
|
40
|
+
* false: no caption under the diagram (a row of shapes with one caption for the capo, such as
|
|
41
|
+
* a chart's chords used); the capo bar and the sounding pitches stay.
|
|
42
|
+
*/
|
|
43
|
+
caption?: boolean;
|
|
26
44
|
}
|
|
27
45
|
/** "x02220", "x-10-12-12-11-10", "x 10 12 12 11 10" → frets; null when invalid. */
|
|
28
46
|
export declare function parseFrets(text: string): (number | null)[] | null;
|
|
@@ -30,4 +48,6 @@ export declare function parseFrets(text: string): (number | null)[] | null;
|
|
|
30
48
|
export declare function parseFingers(text: string): (string | null)[];
|
|
31
49
|
/** The first fret shown: 1 when the chord fits in the first 4 frets, else its lowest fretted fret. */
|
|
32
50
|
export declare function baseFretOf(frets: (number | null)[]): number;
|
|
51
|
+
/** "Capo 2", "Capo 2, sounds B": what a diagram with a capo says under it. */
|
|
52
|
+
export declare const capoCaption: (capo: number, sounds?: string) => string;
|
|
33
53
|
export declare function renderGuitarDiagram(doc: Document, voicing: FrettedVoicing, options?: GuitarDiagramOptions): SVGElement;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* on their fret (anchors) and slide along their string (guides) make changes clean.
|
|
5
5
|
*/
|
|
6
6
|
import { type GeneratedVoicing } from './generate.js';
|
|
7
|
+
import type { VoicingLookup } from '../voicings/index.js';
|
|
7
8
|
export interface TransitionStep {
|
|
8
9
|
voicing: GeneratedVoicing;
|
|
9
10
|
/** Strings (indexes, lowest first) whose finger stays on the same fret. */
|
|
@@ -35,12 +36,19 @@ export interface ProgressionStep extends Partial<Omit<TransitionStep, 'voicing'>
|
|
|
35
36
|
chord: string;
|
|
36
37
|
voicing: GeneratedVoicing;
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
|
|
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?: {
|
|
39
|
+
export interface ProgressionOptions {
|
|
40
|
+
/** Open-string pitches (MIDI), lowest string first; standard guitar by default. */
|
|
44
41
|
tuning?: number[];
|
|
42
|
+
/** How many of each chord's easiest voicings to weigh (12 by default). */
|
|
45
43
|
candidates?: number;
|
|
46
|
-
|
|
44
|
+
/** The voicing database (see `/voicings`): its voicings of each chord are weighed too, and
|
|
45
|
+
* preferred. Only used in standard tuning. */
|
|
46
|
+
voicings?: VoicingLookup;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The voicing of each chord that makes the whole progression easiest: the shapes and the moves
|
|
50
|
+
* between them, together (each chord's easiest 12 voicings are weighed, and the voicing database's
|
|
51
|
+
* when given). Shapes near the nut, full shapes and the database's standard ones are preferred.
|
|
52
|
+
* The first step has no move. Empty when a chord is unknown.
|
|
53
|
+
*/
|
|
54
|
+
export declare function smoothProgression(chords: readonly string[], options?: ProgressionOptions): ProgressionStep[];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Hand, LayoutDefaults } from '../render/layout.js';
|
|
2
|
+
import { type KeyMove } from '../theory/transpose.js';
|
|
3
|
+
import type { VoicingLookup } from '../voicings/index.js';
|
|
4
|
+
import type { Song } from './chordpro.js';
|
|
5
|
+
import { type ChordDefinition } from './defines.js';
|
|
6
|
+
export type ChartInstrument = 'guitar' | 'piano';
|
|
7
|
+
export interface ChordDrawing {
|
|
8
|
+
instrument: ChartInstrument;
|
|
9
|
+
/** Guitar voicings for chords the song doesn't define (see `/voicings`). */
|
|
10
|
+
voicings?: VoicingLookup;
|
|
11
|
+
orientation?: LayoutDefaults['orientation'];
|
|
12
|
+
hand?: Hand;
|
|
13
|
+
/** The song's capo: guitar shapes get its bar and sound (and root marks) at it. */
|
|
14
|
+
capo?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Chord names as written in the lyrics, in order of first appearance, without repeats. Names
|
|
18
|
+
* that can't be chords (N.C., %, *Coda annotations) are left out.
|
|
19
|
+
*/
|
|
20
|
+
export declare function chordsUsed(song: Song): string[];
|
|
21
|
+
/**
|
|
22
|
+
* One chord's diagram: `shown` is the name the chart prints (transposed), `definition` the song's
|
|
23
|
+
* shape for the chord as written, moved by `semitones`. Null when there's nothing to draw.
|
|
24
|
+
*/
|
|
25
|
+
export declare function chordDiagram(doc: Document, shown: string, definition: ChordDefinition | undefined, semitones: number, drawing: ChordDrawing): SVGElement | null;
|
|
26
|
+
/** What to write for chords with no diagram. */
|
|
27
|
+
export declare function missingMessage(names: readonly string[], instrument: ChartInstrument): string;
|
|
28
|
+
export interface ChordsUsedOptions extends ChordDrawing {
|
|
29
|
+
/** Semitones the chart moves chords by. */
|
|
30
|
+
semitones: number;
|
|
31
|
+
/** Spell transposed chords with flats or sharps, by the move between two keys (letters kept),
|
|
32
|
+
* or as written when absent. */
|
|
33
|
+
spelling?: boolean | KeyMove;
|
|
34
|
+
/**
|
|
35
|
+
* A "Capo N" caption over guitar shapes (default true). Charts leave it out when the row is
|
|
36
|
+
* right under the chart's own line that says the capo.
|
|
37
|
+
*/
|
|
38
|
+
capoCaption?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The "chords used" row: every chord of the lyrics, in order of first appearance, as the chart
|
|
42
|
+
* prints it (transposed), with the song's shapes first. With a capo, guitar shapes are the ones
|
|
43
|
+
* played (the names above the lyrics) under a "Capo N" caption, and piano diagrams the chords that
|
|
44
|
+
* sound ("G (sounds A)"). Null when no chord is used.
|
|
45
|
+
*/
|
|
46
|
+
export declare function renderChordsUsed(doc: Document, song: Song, options: ChordsUsedOptions): HTMLElement | null;
|
package/dist/chords/chart.d.ts
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import type { Song } from './chordpro.js';
|
|
2
|
+
import type { Hand, LayoutDefaults } from '../render/layout.js';
|
|
3
|
+
import type { VoicingLookup } from '../voicings/index.js';
|
|
4
|
+
import { type ChartInstrument } from './chart-diagrams.js';
|
|
2
5
|
export interface ChartOptions {
|
|
3
6
|
/** Semitones added to the song's own `{transpose}`. */
|
|
4
7
|
transpose?: number;
|
|
8
|
+
/**
|
|
9
|
+
* The chords used row, when the song has no `{diagrams}`: `'top'`, `'bottom'` or `'off'`
|
|
10
|
+
* (the default).
|
|
11
|
+
*/
|
|
12
|
+
diagrams?: 'top' | 'bottom' | 'off';
|
|
13
|
+
/** Guitar (default) or piano diagrams, when the song has no `{instrument}`. */
|
|
14
|
+
instrument?: ChartInstrument;
|
|
15
|
+
/** Guitar voicings for chords the song doesn't define (see `/voicings`). */
|
|
16
|
+
voicings?: VoicingLookup;
|
|
17
|
+
/** Diagram orientation: `chord` for guitar, `keyboard` for piano. */
|
|
18
|
+
orientation?: LayoutDefaults['orientation'];
|
|
19
|
+
/** Left-handed guitar diagrams. */
|
|
20
|
+
hand?: Hand;
|
|
5
21
|
}
|
|
6
22
|
export declare function renderChart(doc: Document, song: Song, options?: ChartOptions): HTMLElement;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A ChordPro subset: metadata directives, sections (verse, chorus, bridge, tab, grid), comments,
|
|
3
|
-
* `[C]` chords inside lyrics, `{transpose: n}
|
|
3
|
+
* `[C]` chords inside lyrics, `{transpose: n}`, chord definitions (`{define}`, `{chord}`) and the
|
|
4
|
+
* chords used row (`{diagrams}`). Unknown directives are ignored.
|
|
4
5
|
*/
|
|
6
|
+
import { type ChordDefinition } from './defines.js';
|
|
7
|
+
export type { ChordDefinition } from './defines.js';
|
|
5
8
|
export interface Segment {
|
|
6
9
|
chord: string | null;
|
|
7
10
|
text: string;
|
|
@@ -17,6 +20,11 @@ export type Line = {
|
|
|
17
20
|
text: string;
|
|
18
21
|
} | {
|
|
19
22
|
kind: 'empty';
|
|
23
|
+
}
|
|
24
|
+
/** `{chord: …}`: a chord diagram drawn in place. */
|
|
25
|
+
| {
|
|
26
|
+
kind: 'chord';
|
|
27
|
+
definition: ChordDefinition;
|
|
20
28
|
};
|
|
21
29
|
export interface Section {
|
|
22
30
|
kind: 'verse' | 'chorus' | 'bridge' | 'tab' | 'grid' | 'none';
|
|
@@ -33,6 +41,14 @@ export interface Song {
|
|
|
33
41
|
time: string | null;
|
|
34
42
|
transpose: number;
|
|
35
43
|
sections: Section[];
|
|
44
|
+
/** `{define: …}` shapes, in order (a later one of the same name wins). */
|
|
45
|
+
definitions: ChordDefinition[];
|
|
46
|
+
/** `{diagrams}`: where the chords used row goes; null when the song doesn't say. */
|
|
47
|
+
diagrams: 'top' | 'bottom' | 'off' | null;
|
|
48
|
+
/** `{instrument: piano}` (not part of ChordPro): which diagrams the chart draws. */
|
|
49
|
+
instrument: 'guitar' | 'piano' | null;
|
|
50
|
+
/** Directives the chart couldn't read, each with what to write instead. */
|
|
51
|
+
warnings: string[];
|
|
36
52
|
}
|
|
37
53
|
/** Split "[C]Hello [G]world" into chord/text segments. */
|
|
38
54
|
export declare function parseLyrics(line: string): Segment[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface ChordDefinition {
|
|
2
|
+
/** The chord's name, without brackets. */
|
|
3
|
+
name: string;
|
|
4
|
+
/** Written in brackets (`{chord: [Am]}`): transposed with the song. */
|
|
5
|
+
transposable: boolean;
|
|
6
|
+
/** The fret the frets count from (1 when not given). */
|
|
7
|
+
baseFret: number | null;
|
|
8
|
+
/** As written, lowest string first: relative to the base fret, 0 open, null muted. */
|
|
9
|
+
frets: (number | null)[] | null;
|
|
10
|
+
/** Finger per string, as written; null for none. */
|
|
11
|
+
fingers: (string | null)[] | null;
|
|
12
|
+
/** Keyboard keys: semitones above the root. */
|
|
13
|
+
keys: number[] | null;
|
|
14
|
+
/** The name to show instead of `name`. */
|
|
15
|
+
display: string | null;
|
|
16
|
+
/** False with `diagram off`: no diagram for this chord. */
|
|
17
|
+
diagram: boolean;
|
|
18
|
+
/** A chord to copy the shape from that the song doesn't define (the voicing database). */
|
|
19
|
+
copy: string | null;
|
|
20
|
+
}
|
|
21
|
+
/** One name for every spelling of a chord (A#7 and Bb7, Cmaj7 and CM7); the name itself otherwise. */
|
|
22
|
+
export declare function chordKey(name: string): string;
|
|
23
|
+
/** The definition of a chord among earlier ones: the last of its name, else of its spelling. */
|
|
24
|
+
export declare function findDefinition(definitions: readonly ChordDefinition[], name: string): ChordDefinition | undefined;
|
|
25
|
+
export interface ParsedDefinition {
|
|
26
|
+
/** Null when the directive has no name. */
|
|
27
|
+
definition: ChordDefinition | null;
|
|
28
|
+
/** What was wrong and what to write instead; the rest of the definition still counts. */
|
|
29
|
+
problems: string[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A `{define}` or `{chord}` value. `earlier` holds the song's definitions so far: `copy` and
|
|
33
|
+
* `copyall` take their shape from there (or, for a chord the song doesn't define, from the voicing
|
|
34
|
+
* database when drawn).
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseDefinition(value: string, earlier?: readonly ChordDefinition[], directive?: string): ParsedDefinition;
|
|
37
|
+
/** A definition's frets as absolute frets (the base fret's frets counted from the nut). */
|
|
38
|
+
export declare function absoluteFrets(definition: ChordDefinition): (number | null)[] | null;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Renderer } from '../blocks/renderers.js';
|
|
2
|
+
import { type MusicalKey } from '../theory/keys.js';
|
|
3
|
+
export interface CircleOptions {
|
|
4
|
+
/** The key to mark; C major by default. */
|
|
5
|
+
key?: MusicalKey;
|
|
6
|
+
/** Seventh chords instead of triads, for the marked chords. */
|
|
7
|
+
sevenths?: boolean;
|
|
8
|
+
/** Set the IV and V chords (iv and v in minor) apart; true by default. */
|
|
9
|
+
neighbours?: boolean;
|
|
10
|
+
title?: string;
|
|
11
|
+
}
|
|
12
|
+
/** "F#" → "F♯", "Bbm7b5" → "B♭ø7", "Cdim" → "C°": names as the wheel shows them. */
|
|
13
|
+
export declare function pretty(symbol: string): string;
|
|
14
|
+
/** A chord's pitches around middle C: the root from G3 to F#4, the other notes stacked above. */
|
|
15
|
+
export declare function chordPitches(symbol: string): number[];
|
|
16
|
+
export declare function renderCircle(doc: Document, options?: CircleOptions): SVGElement;
|
|
17
|
+
/**
|
|
18
|
+
* The `circle` block: `key:` (or a shorthand line: G, E minor, D dorian), `mode:` (major, minor or
|
|
19
|
+
* a church mode), `chords: triads | sevenths`, `neighbours: yes | no`, `title:`.
|
|
20
|
+
*/
|
|
21
|
+
export declare const renderCircleBlock: Renderer;
|