@dsebastien/music-notation 0.23.1 → 0.25.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.
@@ -2,6 +2,7 @@ import { type Language } from '../i18n/language.js';
2
2
  import type { Hand } from '../render/layout.js';
3
3
  import { type NotePlayer, type PlayKind, type Sound } from './player.js';
4
4
  import { type Engine } from './engine.js';
5
+ import { type GuitarTone } from './guitar-tone.js';
5
6
  export interface PlayOptions {
6
7
  /**
7
8
  * The language of the bars' texts and of the diagrams they redraw (#136): `'en'` or `'fr'`.
@@ -26,6 +27,12 @@ export interface PlayOptions {
26
27
  engine?: Engine;
27
28
  /** Guitar or piano; by default the diagram's (piano for keyboards and piano chords). */
28
29
  sound?: Sound;
30
+ /**
31
+ * Which guitar plays the guitar sound (#103): `steel` (a steel-string acoustic, the default),
32
+ * `nylon`, `clean` (an electric) or `overdrive`. A function is read at each play, so a setting
33
+ * changed in the app is heard at the next Play. A block's `guitar:` line comes first.
34
+ */
35
+ guitar?: GuitarTone | (() => GuitarTone | null | undefined);
29
36
  /**
30
37
  * 0 to 1, 0.8 by default. The bars have no volume (#58): it is the app's setting. A function
31
38
  * is read at each play (and each pass of a loop), so a setting changed in the app applies at
@@ -100,6 +107,16 @@ export declare function lightFor(win: Window): NotePlayer;
100
107
  * fallback order; the light synthesizer when it has none.
101
108
  */
102
109
  export declare function playerFor(win: Window, options: PlayOptions, el?: Element | null): NotePlayer;
110
+ /**
111
+ * `player` playing the guitar an element asks for (#103); `player` itself when nothing names a
112
+ * guitar, so an app that names none gets exactly the player it gave.
113
+ */
114
+ export declare function toned(player: NotePlayer, options: PlayOptions, el?: Element | null): NotePlayer;
115
+ /**
116
+ * The guitar that plays for an element: the one its reader chose in a bar's Sound menu, else its
117
+ * block's `guitar:` line, else the app's or page's.
118
+ */
119
+ export declare function guitarFor(options: PlayOptions, el?: Element | null): GuitarTone | null;
103
120
  /** The diagram's own playback data, set by its renderer. */
104
121
  export interface DiagramData {
105
122
  kind: PlayKind;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Which guitar plays the diagrams (#103): a steel-string acoustic (the default), a nylon-string
3
+ * classical guitar, a clean electric or an overdriven electric. The reader's side chooses (a
4
+ * page's or an app's `guitar`); a block may say `guitar:`; the reader may choose another one in a
5
+ * play bar's Sound menu. It changes the guitar sound only: a piano stays a piano, and tabs and
6
+ * scores keep the instruments their tracks name.
7
+ */
8
+ /** The guitars, the default first. */
9
+ export declare const GUITAR_TONES: readonly ["steel", "nylon", "clean", "overdrive"];
10
+ export type GuitarTone = (typeof GUITAR_TONES)[number];
11
+ export declare const DEFAULT_GUITAR_TONE: GuitarTone;
12
+ /** The General MIDI program of each guitar, for the players that play a soundfont. */
13
+ export declare const GUITAR_PROGRAMS: Readonly<Record<GuitarTone, number>>;
14
+ /** A guitar's name from a page option, a setting or a block line; null when it isn't one. */
15
+ export declare function guitarToneOf(value: unknown): GuitarTone | null;
16
+ /**
17
+ * A block's `guitar:` line (the last one wins; `{guitar: …}` in a ChordPro chart), taken out of
18
+ * its source so that no block parser has to know it. Throws a message for the user when the value
19
+ * isn't a guitar.
20
+ */
21
+ export declare function blockGuitar(source: string, chart?: boolean): {
22
+ guitar: GuitarTone | null;
23
+ source: string;
24
+ };
25
+ /** The guitar of the block an element is in (`data-mn-guitar`, set from its `guitar:` line). */
26
+ export declare function guitarWish(el: Element | null | undefined): GuitarTone | null;
27
+ /** The guitar a reader chose on a play bar of the block an element is in; null without one. */
28
+ export declare function guitarChoice(el: Element | null | undefined): GuitarTone | null;
29
+ /**
30
+ * Keeps the guitar a reader chose on a play bar: on the block an element is in, so every bar and
31
+ * diagram of the block plays it, else on the element itself. It lasts as long as the drawing.
32
+ */
33
+ export declare function chooseGuitar(el: Element, guitar: GuitarTone): void;
34
+ /** A page's guitar (`play: { guitar }` in `window.musicNotationOptions`), when it names one. */
35
+ export declare function pageGuitar(options: unknown): GuitarTone | undefined;
@@ -3,6 +3,7 @@
3
3
  * light synthesizer to play them (a plucked string for guitar, a simple piano), with no download.
4
4
  * Apps can pass another NotePlayer (a soundfont one) for realistic sound.
5
5
  */
6
+ import { type GuitarTone } from './guitar-tone.js';
6
7
  export type Sound = 'guitar' | 'piano';
7
8
  export interface NoteEvent {
8
9
  midi: number;
@@ -35,6 +36,11 @@ export interface NotePlayer {
35
36
  volume: number;
36
37
  onEnd?: () => void;
37
38
  onStart?: () => void;
39
+ /**
40
+ * Which guitar plays when `sound` is guitar (#103): steel-string by default. A player
41
+ * that doesn't know it plays its own guitar.
42
+ */
43
+ guitar?: GuitarTone;
38
44
  }): PlayHandle;
39
45
  /**
40
46
  * True when `play` calls `onStart`: the bar then waits for it before it lights notes.
@@ -96,6 +102,12 @@ export interface PluckOptions {
96
102
  pick?: number;
97
103
  /** How fast the string loses its energy, times the usual (1 by default). */
98
104
  damping?: number;
105
+ /**
106
+ * How hard an amplifier is driven (0, the default: not at all). The string's wave is pressed
107
+ * against a soft ceiling, which adds harmonics and holds the level while the string fades, as
108
+ * an overdriven amplifier does.
109
+ */
110
+ drive?: number;
99
111
  }
100
112
  /**
101
113
  * A plucked string (Karplus-Strong): a burst of noise through a delay line one period long,
@@ -6,4 +6,9 @@ export declare function barsFromDrawing(drawing: Element): {
6
6
  bars: ProgressionBar[];
7
7
  marks: Element[][];
8
8
  };
9
- export declare function progressionBarFor(doc: Document, win: Window, drawing: Element, options: PlayOptions, diagrams?: DiagramGroup | null): () => void;
9
+ export declare function progressionBarFor(doc: Document, win: Window, drawing: Element, options: PlayOptions, diagrams?: DiagramGroup | null,
10
+ /**
11
+ * Gives the group of the drawing's diagrams again, after the chart was drawn again (#45): the
12
+ * caller frees the old one.
13
+ */
14
+ regroup?: () => DiagramGroup | null): () => void;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The Sound menu of the play bars (#103): the four guitars, then the piano. A guitar chosen here
3
+ * comes before the block's `guitar:` line and the app's or page's guitar, for the block the bar
4
+ * is in, until it is drawn again. Nothing is stored.
5
+ */
6
+ import type { Translator } from '../i18n/translate.js';
7
+ import { type PlayOptions } from './controls.js';
8
+ import { type GuitarTone } from './guitar-tone.js';
9
+ import type { Sound } from './player.js';
10
+ /** An entry of the menu: a guitar, or the piano. */
11
+ export type SoundChoice = GuitarTone | 'piano';
12
+ export interface SoundMenu {
13
+ el: HTMLSelectElement;
14
+ /** Shows what plays now: the piano, or the guitar in effect (an app's setting may have changed). */
15
+ show(): void;
16
+ }
17
+ /**
18
+ * The menu of a bar that plays `played` (the drawing, or each diagram's wrapper). `sound` is the
19
+ * bar's sound now; `set` gives it the instrument chosen.
20
+ */
21
+ export declare function soundMenu(doc: Document, tr: Translator, options: PlayOptions, played: () => Element[], sound: () => Sound, set: (sound: Sound) => void): SoundMenu;