@dsebastien/music-notation 0.13.0 → 0.15.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.
@@ -1,5 +1,5 @@
1
1
  import type { Hand } from '../render/layout.js';
2
- import { type NotePlayer, type Sound } from './player.js';
2
+ import { type NotePlayer, type PlayKind, type Sound } from './player.js';
3
3
  export interface PlayOptions {
4
4
  /**
5
5
  * Plays the notes: a player, or a function returning one at each play (null for the default),
@@ -9,8 +9,12 @@ export interface PlayOptions {
9
9
  player?: NotePlayer | ((win: Window) => NotePlayer | null | undefined);
10
10
  /** Guitar or piano; by default the diagram's (piano for keyboards and piano chords). */
11
11
  sound?: Sound;
12
- /** 0 to 1, 0.8 by default. */
13
- volume?: number;
12
+ /**
13
+ * 0 to 1, 0.8 by default. The bars have no volume (#58): it is the app's setting. A function
14
+ * is read at each play (and each pass of a loop), so a setting changed in the app applies at
15
+ * once.
16
+ */
17
+ volume?: number | (() => number);
14
18
  /** Scales: notes per minute, 90 by default; also strum patterns' tempo when they have none. */
15
19
  bpm?: number;
16
20
  /**
@@ -61,15 +65,34 @@ export declare const clamp: (n: number | undefined, lo: number, hi: number, fall
61
65
  * so piano chords stay a block unless `{ piano }` is given.
62
66
  */
63
67
  export declare function strumsOf(strum: PlayOptions['strum']): Record<Sound, number>;
64
- /** Small icons, drawn so they look the same in every font. */
65
- declare const ICONS: Record<'play' | 'stop' | 'loop' | 'volume', string>;
66
- export declare function icon(doc: Document, name: keyof typeof ICONS): SVGElement;
68
+ export { icon } from './bar-parts.js';
67
69
  export declare function lightFor(win: Window): NotePlayer;
68
70
  /** The player apps passed (read at each play), else the light synthesizer. */
69
71
  export declare function playerFor(win: Window, options: PlayOptions): NotePlayer;
72
+ /** The diagram's own playback data, set by its renderer. */
73
+ export interface DiagramData {
74
+ kind: PlayKind;
75
+ pitches: number[];
76
+ sound: Sound;
77
+ /** The tonic's pitch class, from the root mark (scales start on it); null without one. */
78
+ root: number | null;
79
+ }
80
+ /** The pitch classes of a chord drawn over a scale (its tones), or undefined. */
81
+ export declare function tonesOf(drawing: Element): number[] | undefined;
82
+ /** The pitch class of a drawing's root mark (a root dot or key), or null. */
83
+ export declare function rootOf(drawing: Element): number | null;
84
+ export declare function dataOf(diagram: Element): DiagramData | null;
85
+ /**
86
+ * The same notes drawn for the other instrument: a keyboard for a guitar diagram or a fretboard,
87
+ * a fretboard for a keyboard. The diagram's own chord or scale with its exact pitches, so notes
88
+ * keep their spelling (Gm's Bb) and labels their meaning (C9's 9); a list rebuilt from its notes
89
+ * and root otherwise. With the title, the labels and the orientation (between fretboards and
90
+ * keyboards); null when nothing can be drawn (no note within a guitar's range).
91
+ */
92
+ export declare function redrawFor(doc: Document, diagram: Element, data: DiagramData, pageHand?: Hand): Element | null;
70
93
  /**
71
- * Wraps each playable diagram in `el` (an SVG with notes to play) with its playback bar. Returns
72
- * a function that stops whatever plays.
94
+ * Makes what `el` draws playable: each block's diagrams (an SVG with notes to play) get one bar
95
+ * below them, strumming and picking patterns, progressions and ChordPro charts their bar in time.
96
+ * Returns a function that stops whatever plays.
73
97
  */
74
98
  export declare function attachPlayback(el: HTMLElement, options?: PlayOptions): () => void;
75
- export {};
@@ -1,8 +1,9 @@
1
- import { type PlayOptions } from './controls.js';
1
+ import type { PlayOptions } from './controls.js';
2
+ import type { DiagramGroup } from './block-bar.js';
2
3
  import { type ProgressionBar } from './progression.js';
3
4
  /** The bars of a drawn progression or chart, in order, each with the elements that show it. */
4
5
  export declare function barsFromDrawing(drawing: Element): {
5
6
  bars: ProgressionBar[];
6
7
  marks: Element[][];
7
8
  };
8
- export declare function progressionBarFor(doc: Document, win: Window, drawing: Element, options: PlayOptions): () => void;
9
+ export declare function progressionBarFor(doc: Document, win: Window, drawing: Element, options: PlayOptions, diagrams?: DiagramGroup | null): () => void;
@@ -14,19 +14,19 @@ export declare function strumBarFor(doc: Document, win: Window, drawing: Element
14
14
  export interface TimedPiece {
15
15
  /** What it plays, for the app (#77). */
16
16
  kind: 'strum' | 'picking';
17
- /** The wrapper's own class, beside `mn-playable`. */
17
+ /** The wrapper's own class, beside `mn-timed`. */
18
18
  cls: string;
19
19
  /** The bar's name for screen readers. */
20
20
  label: string;
21
- /** Counted in dotted beats (6/8): the tempo slider shows ♩. */
21
+ /** Counted in dotted beats (6/8): the tempo counts dotted quarters. */
22
22
  compound: boolean;
23
23
  make: PassMaker;
24
24
  /** Shows a click (metronome) button, on or off at the start; none when absent. */
25
25
  click?: boolean;
26
26
  }
27
27
  /**
28
- * The bar of a piece played in time over a drawing whose slots are `[data-mn-beat]` elements:
29
- * play / stop, loop, count-in, click when asked, tempo, volume, sound. Each pass's slots light
28
+ * The bar of a piece played in time over a drawing whose slots are `[data-mn-beat]` elements,
29
+ * below it: play / stop, loop, count-in, click when asked, tempo, sound. Each pass's slots light
30
30
  * as they sound.
31
31
  */
32
32
  export declare function timedBarFor(doc: Document, win: Window, drawing: Element, options: PlayOptions, piece: TimedPiece): () => void;