@dsebastien/music-notation 0.8.0 → 0.10.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 (40) hide show
  1. package/README.md +37 -5
  2. package/dist/chord/generate.d.ts +45 -9
  3. package/dist/chord/guitar.d.ts +23 -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 +61 -0
  7. package/dist/index.d.ts +9 -8
  8. package/dist/index.js +6427 -4316
  9. package/dist/index.js.map +34 -32
  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 +78 -5
  16. package/dist/music-notation.publish.min.js +101 -28
  17. package/dist/music-notation.tab.min.js +85 -9
  18. package/dist/playback/controls.d.ts +19 -2
  19. package/dist/playback/player.d.ts +69 -5
  20. package/dist/publish/index.js +4849 -3334
  21. package/dist/publish/index.js.map +33 -31
  22. package/dist/render/dom.d.ts +30 -1
  23. package/dist/strum/pattern.d.ts +31 -0
  24. package/dist/strum/play.d.ts +46 -5
  25. package/dist/strum/render.d.ts +5 -2
  26. package/dist/tab/index.d.ts +47 -2
  27. package/dist/tab/index.js +766 -77
  28. package/dist/tab/index.js.map +7 -7
  29. package/dist/tab/load.d.ts +10 -0
  30. package/dist/theory/detect.d.ts +6 -2
  31. package/dist/theory/find.d.ts +35 -7
  32. package/dist/theory/keys.d.ts +8 -2
  33. package/dist/theory/note-set.d.ts +5 -0
  34. package/dist/theory/numerals.d.ts +34 -7
  35. package/dist/voicings/check.d.ts +24 -0
  36. package/dist/voicings/curated.d.ts +10 -0
  37. package/dist/voicings/index.d.ts +1 -1
  38. package/dist/voicings/index.js +519 -111
  39. package/dist/voicings/index.js.map +10 -8
  40. package/package.json +1 -1
@@ -7,10 +7,39 @@ export declare function svg(doc: Document, tag: string, attrs?: Attributes, chil
7
7
  export declare function svgText(doc: Document, text: string, attrs?: Attributes): SVGElement;
8
8
  /** A <text> vertically centered on (x, y), for the 10–11px labels of diagrams. */
9
9
  export declare function svgLabel(doc: Document, text: string, [x, y]: [number, number], cls: string, anchor?: 'start' | 'middle' | 'end'): SVGElement;
10
+ /**
11
+ * The text in a note dot of radius `r`: a label of three characters or more (bb7, #11, b13) is
12
+ * smaller and squeezed to the dot's inner width, so it never passes the dot's edge (#73).
13
+ */
14
+ export declare function dotLabel(doc: Document, text: string, point: [number, number], r: number): SVGElement;
10
15
  /** A <line> between two points. */
11
16
  export declare function svgLine(doc: Document, [x1, y1]: [number, number], [x2, y2]: [number, number], cls: string): SVGElement;
12
17
  /** An HTML element with a class and optional text. */
13
18
  export declare function html<K extends keyof HTMLElementTagNameMap>(doc: Document, tag: K, cls?: string, text?: string): HTMLElementTagNameMap[K];
14
- /** A root <svg> sized by its viewBox, scaling with the container up to its natural width. */
19
+ /**
20
+ * A root <svg> sized by its viewBox, scaling with the container up to its natural width.
21
+ *
22
+ * Its name for screen readers (`label`) is a `<title>` inside `<defs>`, pointed at by
23
+ * `aria-labelledby` (role="img"). Never `aria-label` on SVG: Obsidian shows a tooltip for every
24
+ * element with one and calls HTMLElement-only methods on it, which throw on SVG elements. The
25
+ * title sits in `<defs>` (never drawn, never the parent of what the pointer is over) so browsers
26
+ * show no hover tooltip for it: the diagram's visible title already says what it is.
27
+ */
15
28
  export declare function svgRoot(doc: Document, width: number, height: number, cls: string, label: string): SVGElement;
29
+ /** A diagram's name for screen readers (its `aria-labelledby` text, else its `aria-label`). */
30
+ export declare function accessibleName(el: Element): string | null;
31
+ /** Renames a diagram made by `svgRoot` (or any element named with `aria-label`). */
32
+ export declare function setAccessibleName(el: Element, name: string): void;
33
+ /**
34
+ * A playable mark (a dot, an open-string circle) with its invisible hit area under it (#69), in one
35
+ * `.mn-mark` group: a click anywhere in the area plays the mark (the click handler looks up the
36
+ * group's `data-midi` element). The area is centered on the mark; renderers size it to the mark's
37
+ * own cell (its string's lane, its fret) so neighbors never share one.
38
+ */
39
+ export declare function playableMark(doc: Document, area: {
40
+ x: number;
41
+ y: number;
42
+ width: number;
43
+ height: number;
44
+ }, ...children: Element[]): SVGElement;
16
45
  export {};
@@ -17,6 +17,18 @@ export interface StrumPattern {
17
17
  subdivision: Subdivision;
18
18
  /** Slots in one beat (2 for 8ths in 4/4, 1 for 8ths in 6/8). */
19
19
  slotsPerBeat: number;
20
+ /**
21
+ * Compound time (6/8, 9/8, 12/8…): the beat felt and counted for the tempo is a dotted note,
22
+ * three of the written beats.
23
+ */
24
+ compound: boolean;
25
+ /** Slots in one counted beat: `slotsPerBeat`, three times that in compound time. */
26
+ slotsPerPulse: number;
27
+ /**
28
+ * Swung pairs of slots (`swing:`): where the second slot of each pair falls, as a fraction of
29
+ * the pair (2/3 for a triplet swing, a shuffle); null when straight.
30
+ */
31
+ swing: number | null;
20
32
  slotsPerBar: number;
21
33
  bars: number;
22
34
  /** The chord for the whole pattern (`chord:`), until a change. */
@@ -26,10 +38,18 @@ export interface StrumPattern {
26
38
  /** Open strings for playback (`tuning:`), as written; null for standard guitar. */
27
39
  tuning: string | null;
28
40
  title: string | null;
41
+ /**
42
+ * How strums written alone were read when the hand's motion placed them and the bar ends with
43
+ * whole beats of no strum (`D U D U` in triplets: `D - U D - U` and 2 empty beats), with what
44
+ * to write instead; null otherwise (#73).
45
+ */
46
+ note: string | null;
29
47
  }
30
48
  /** Bounds that keep a pattern quick to draw and to hear. */
31
49
  export declare const MAX_STRUM_BARS = 16;
32
50
  export declare const DEFAULT_TEMPO = 90;
51
+ /** The default tempo of compound time, in dotted quarters (8ths at 180 a minute). */
52
+ export declare const DEFAULT_COMPOUND_TEMPO = 60;
33
53
  export declare const MIN_TEMPO = 20;
34
54
  export declare const MAX_TEMPO = 240;
35
55
  /** "4/4", "6/8", "C" (common time), "cut" (2/2). Throws a message for the user. */
@@ -37,6 +57,17 @@ export declare function parseTime(text: string): {
37
57
  beatsPerBar: number;
38
58
  beatUnit: number;
39
59
  };
60
+ /**
61
+ * Compound time: 6, 9 or 12 (any multiple of 3 from 6) 8ths or 16ths a bar, felt in dotted
62
+ * beats of three (6/8 is two beats of three 8ths). 3/8 is counted in three.
63
+ */
64
+ export declare const isCompound: (beatsPerBar: number, beatUnit: number) => boolean;
65
+ /**
66
+ * `swing:` as where the second slot of each pair falls: yes (or on, shuffle, triplet) is 2/3, a
67
+ * triplet swing; a percentage from 50 (straight) to 75 is that much of the pair; no (or off,
68
+ * straight) is null. Throws a message.
69
+ */
70
+ export declare function parseSwing(text: string): number | null;
40
71
  /** "8ths", "eighths", "8"; "16ths", "sixteenths", "16"; "triplets". Throws a message. */
41
72
  export declare function parseSubdivision(text: string): Subdivision;
42
73
  /** Slots in one beat of the time signature. Throws when the subdivision can't divide the beat. */
@@ -11,6 +11,13 @@ export interface StrumScore {
11
11
  }[];
12
12
  slotsPerBeat: number;
13
13
  beatsPerBar: number;
14
+ /**
15
+ * Slots in one counted beat, the one the tempo counts: `slotsPerBeat` by default, three
16
+ * times that in compound time (a dotted quarter in 6/8).
17
+ */
18
+ slotsPerPulse?: number;
19
+ /** Where the second slot of each pair falls (2/3 for a triplet swing); straight when absent. */
20
+ swing?: number | null;
14
21
  }
15
22
  /**
16
23
  * Each slot's notes: the chord that starts there, else the one before it. Strums before the first
@@ -18,22 +25,56 @@ export interface StrumScore {
18
25
  */
19
26
  export declare function scoreOf(pattern: StrumPattern, voicing: (chord: string | null) => number[]): StrumScore;
20
27
  export interface StrumEventOptions {
21
- /** Beats a minute (the time signature's beat: a quarter in 4/4, an eighth in 6/8). */
28
+ /**
29
+ * Beats a minute: the counted beat (a quarter in 4/4, a dotted quarter in 6/8, 9/8 and
30
+ * 12/8, an eighth in 3/8).
31
+ */
22
32
  bpm?: number;
23
33
  /** A bar of clicks first. */
24
34
  countIn?: boolean;
25
35
  /** How long the last strum rings after the pattern, in seconds (0 when it loops). */
26
36
  tail?: number;
37
+ /** Varies the small differences between strums from pass to pass (the pass's number). */
38
+ seed?: number;
27
39
  }
28
- /** MIDI velocities: a normal strum, an accent, a ghost strum, a muted one. */
40
+ /**
41
+ * MIDI velocities: a down strum (`normal`), an up strum, an accent, a ghost strum, a muted one
42
+ * (a chuck, on the down motion). The beats add `STRUM_STRESS`; each strum varies a little.
43
+ */
29
44
  export declare const STRUM_VELOCITY: {
30
45
  normal: number;
46
+ up: number;
31
47
  accent: number;
32
48
  ghost: number;
33
49
  mute: number;
34
50
  };
35
- /** Beats a minute within bounds; the default when it isn't a number. */
36
- export declare const tempoOf: (bpm: number | null | undefined) => number;
51
+ /** Added on the bar's first beat, and on the other counted beats (1 and 4 in 6/8). */
52
+ export declare const STRUM_STRESS: {
53
+ first: number;
54
+ beat: number;
55
+ };
56
+ /**
57
+ * The app's tempo (quarter notes a minute, as for scales) as the pattern's counted beat, at the
58
+ * same quarter-note speed, rounded and within 20–240: halves in 2/2 (90 → 45), 8ths in 3/8
59
+ * (90 → 180), dotted quarters in x/8 compound time (90 → 60), dotted 8ths in x/16 (90 → 120).
60
+ * Undefined stays undefined.
61
+ */
62
+ export declare const countedTempoOf: (bpm: number | undefined, compound: boolean, beatUnit?: number) => number | undefined;
63
+ /**
64
+ * Beats a minute within bounds; the default when it isn't a number (90, or 60 dotted quarters in
65
+ * compound time).
66
+ */
67
+ export declare const tempoOf: (bpm: number | null | undefined, compound?: boolean) => number;
68
+ /**
69
+ * How hard a strum is played: down strums firmer than up strums, the bar's first beat and the
70
+ * other counted beats stressed (a groove), accents loud, ghost strums soft, a muted strum a firm
71
+ * chuck; then a little variation, so no two strums are the same.
72
+ */
73
+ export declare function strumVelocity(slot: {
74
+ stroke: Stroke;
75
+ accent: boolean;
76
+ ghost: boolean;
77
+ }, up: boolean, inBar: number, slotsPerPulse: number, seed?: number, index?: number): number;
37
78
  /** When a slot's strum is played in a pass: from its start, for one slot. */
38
79
  export interface StrumTiming {
39
80
  slot: number;
@@ -77,7 +118,7 @@ export interface StrumFollower {
77
118
  */
78
119
  export declare function runStrum(score: StrumScore, player: () => NotePlayer, settings: () => StrumSettings, timers: Pick<Window, 'setTimeout' | 'clearTimeout'>, onEnd?: () => void, follow?: (strums: StrumTiming[], player: NotePlayer) => StrumFollower): PlayHandle;
79
120
  export interface PlayStrumOptions {
80
- /** Beats a minute: the pattern's `tempo:`, else 90. */
121
+ /** Beats a minute: the pattern's `tempo:`, else 90 (60 dotted quarters in compound time). */
81
122
  bpm?: number;
82
123
  /** A chord symbol (or words), or the notes to strum, lowest string first. */
83
124
  chord?: string | readonly number[];
@@ -4,7 +4,10 @@ export interface StrumOptions {
4
4
  title?: string;
5
5
  /** The notes each chord sounds (lowest string first), for playback; see `strumVoicing`. */
6
6
  voicing?: (chord: string | null) => number[];
7
- /** Beats a minute playback starts at (the pattern's own tempo wins). */
7
+ /**
8
+ * Beats a minute playback starts at, counting the pattern's counted beat (a dotted quarter in
9
+ * compound time); the pattern's own tempo wins.
10
+ */
8
11
  bpm?: number;
9
12
  }
10
13
  /** The pattern's drawing, with what playback needs on its elements. */
@@ -14,4 +17,4 @@ export declare function renderStrum(doc: Document, pattern: StrumPattern, option
14
17
  * option's on a standard guitar, else generated ones, for the block's `tuning:`). Throws a
15
18
  * message for the user.
16
19
  */
17
- export declare function renderStrumBlock(doc: Document, source: string, options: RenderOptions): SVGElement;
20
+ export declare function renderStrumBlock(doc: Document, source: string, options: RenderOptions): Element;
@@ -33,10 +33,25 @@ export interface TabOptions {
33
33
  player?: boolean;
34
34
  /** Called once alphaTab's API exists (before the score is drawn). */
35
35
  onApi?: (api: AT.AlphaTabApi) => void;
36
+ /**
37
+ * The Tab / Score / Both control in the player bar (default true; Music Practice #83): a click
38
+ * draws the block again in that view, without changing its text. Shown when the score has a
39
+ * stringed staff (drums and piano have no tablature, so they have one view only).
40
+ */
41
+ views?: boolean;
42
+ /**
43
+ * Called by **Keep this view** with the view chosen, so the app writes `staves:` in the block.
44
+ * Without it, the control has no Keep this view.
45
+ */
46
+ onKeepView?: (staves: Staves) => void;
47
+ /** The view of a block with no `staves:` line (default: the block's language). */
48
+ defaultStaves?: Staves;
36
49
  }
37
50
  export type Staves = 'tab' | 'score' | 'both';
38
51
  export interface TabSource {
39
52
  staves: Staves;
53
+ /** Whether the block has a `staves:` line (else `staves` is the language's default). */
54
+ stavesWritten: boolean;
40
55
  /** A file to draw instead of alphaTex (`[[Song.gp]]` or a path). */
41
56
  file: string | null;
42
57
  /** Tracks to draw (1-based); all by default. */
@@ -45,13 +60,43 @@ export interface TabSource {
45
60
  tex: string;
46
61
  /** Lines of the block before the alphaTex (settings, blank lines), for error positions. */
47
62
  texLine: number;
63
+ /**
64
+ * Whether `tex` was converted from a plain-text tab written in the block (a tab pasted from
65
+ * the web, #71): `textTabToAlphaTex`, in memory, the block's text unchanged.
66
+ */
67
+ fromText: boolean;
48
68
  }
49
69
  /**
50
70
  * A tab block's own settings (lines `staves:`, `file:`, `tracks:` at the top, `//` comments
51
- * allowed among them), then its alphaTex. ```tab blocks show tablature, ```score blocks standard
52
- * notation, unless `staves:` says otherwise. Throws a message for the user.
71
+ * allowed among them), then its alphaTex, or a plain-text tab, converted (#71). ```tab blocks show
72
+ * tablature, ```score blocks standard notation, unless `staves:` says otherwise. Throws a message
73
+ * for the user.
53
74
  */
54
75
  export declare function parseTabSource(language: 'tab' | 'score', source: string): TabSource;
76
+ /** The part of alphaTab's score read and set to hide its default dynamics. */
77
+ interface DynamicsView {
78
+ stylesheet: {
79
+ hideDynamics: boolean;
80
+ };
81
+ tracks: {
82
+ staves: {
83
+ bars: {
84
+ voices: {
85
+ beats: {
86
+ dynamics: number;
87
+ isRest: boolean;
88
+ }[];
89
+ }[];
90
+ }[];
91
+ }[];
92
+ }[];
93
+ }
94
+ /**
95
+ * Hides the dynamics nobody wrote (#66): alphaTab gives every beat forte and draws an "f" at the
96
+ * start of each staff. They stay when a beat has another dynamic, or the alphaTex writes one
97
+ * (`{dy f}`) or `\showDynamics`.
98
+ */
99
+ export declare function hideDefaultDynamics(score: DynamicsView, tex: string | null): void;
55
100
  /** Prints a drawn score in black on white, whatever the theme. Throws when the app can't print. */
56
101
  export declare function printTab(result: TabResult): void;
57
102
  export interface TabResult {