@dsebastien/music-notation 0.10.1 → 0.12.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.
@@ -0,0 +1,124 @@
1
+ import type { VoicingLookup } from '../voicings/index.js';
2
+ import { type StrumPattern } from '../strum/pattern.js';
3
+ import { type Pass, type StrumFollower, type StrumSettings, type StrumTiming } from '../strum/play.js';
4
+ import { type NotePlayer, type PlayHandle, type Sound } from './player.js';
5
+ /** How each bar's chord is played. */
6
+ export type ProgressionStrum = 'beats' | 'bar' | 'arpeggio';
7
+ export declare const PROGRESSION_STRUMS: readonly ProgressionStrum[];
8
+ /**
9
+ * One chord of a progression: its name (as shown, null when unnamed), the notes it sounds (lowest
10
+ * first) and how long it lasts: `beats` of the time signature as written (quarters in 4/4,
11
+ * eighths in 6/8), a bar when absent (#75). The last chord fills the last bar.
12
+ */
13
+ export interface ProgressionBar {
14
+ chord: string | null;
15
+ pitches: readonly number[];
16
+ beats?: number;
17
+ }
18
+ export interface ProgressionEventOptions {
19
+ /** Counted beats a minute (a quarter in 4/4; a dotted quarter with a 6/8 pattern); 90. */
20
+ bpm?: number;
21
+ /** Beats in a bar, 1 to 16; 4 by default. A pattern's own time signature wins. */
22
+ beatsPerBar?: number;
23
+ /** The note that counts as a beat (4 by default; 8 in 6/8, counted in dotted quarters). */
24
+ beatUnit?: number;
25
+ /** `beats` (a down strum on each beat, by default), `bar` (one strum a bar), `arpeggio`. */
26
+ strum?: ProgressionStrum;
27
+ /** A strumming pattern played in each bar instead (its bars in turn, its chords ignored). */
28
+ pattern?: StrumPattern | null;
29
+ /** The most time between the strings of a strum, in seconds: 0.012 by default, 0 a block. */
30
+ spread?: number;
31
+ /** A metronome click on every beat; on by default. */
32
+ click?: boolean;
33
+ /** A bar of clicks first. */
34
+ countIn?: boolean;
35
+ /** How long the last chord rings after the progression, in seconds (0 when it loops). */
36
+ tail?: number;
37
+ /** Varies the small differences between strums from pass to pass. */
38
+ seed?: number;
39
+ }
40
+ /**
41
+ * The notes of one pass of a progression (the count-in first when asked), its length in seconds,
42
+ * and when each bar is played (`strums`, one a bar: `slot` is the bar's index), to light it.
43
+ */
44
+ export declare function progressionEvents(bars: readonly ProgressionBar[], options?: ProgressionEventOptions): Pass;
45
+ /** The chord sounding at the start of each bar (its index in the progression). */
46
+ export declare function chordOfBars(bars: readonly ProgressionBar[], beatsPerBar: number): number[];
47
+ /**
48
+ * A chord to play: a symbol (or words), or an object with its name to show, its notes (lowest
49
+ * first; from the name when absent) and how long it lasts (`beats` as written, a bar by default).
50
+ */
51
+ export type ProgressionChordInput = string | {
52
+ chord?: string | null;
53
+ pitches?: readonly number[];
54
+ beats?: number;
55
+ };
56
+ export interface PlayProgressionOptions {
57
+ /** Counted beats a minute (a quarter in 4/4, a dotted quarter with a 6/8 pattern); 90. */
58
+ bpm?: number;
59
+ /** Beats in a bar, 1 to 16; 4 by default. A pattern's time signature wins. */
60
+ beatsPerBar?: number;
61
+ /** The note that counts as a beat: 4 by default; 8 in 6/8 (counted in dotted quarters). */
62
+ beatUnit?: number;
63
+ /** `beats` (by default), `bar` or `arpeggio`. */
64
+ strum?: ProgressionStrum;
65
+ /** A strumming pattern (a ```strum block's text, or parsed) played in every bar. */
66
+ pattern?: string | StrumPattern;
67
+ /** A metronome click on every beat; on by default. */
68
+ click?: boolean;
69
+ /** A bar of clicks first; off by default. */
70
+ countIn?: boolean;
71
+ loop?: boolean;
72
+ /** Open strings (MIDI, lowest first) or a tuning name, for chord symbols; standard. */
73
+ tuning?: readonly number[] | string;
74
+ /** Finds guitar voicings for chord symbols (see `/voicings`); generated ones otherwise. */
75
+ voicings?: VoicingLookup;
76
+ /** The light synthesizer of `window` by default. */
77
+ player?: NotePlayer;
78
+ /** The window to play in (popouts have their own); the global one by default. */
79
+ window?: Window;
80
+ /** Guitar by default; piano plays piano voicings of chord symbols, as blocks. */
81
+ sound?: Sound;
82
+ /** 0 to 1, 0.8 by default. */
83
+ volume?: number;
84
+ /** Called as each bar starts sounding: its index, the chord sounding, the pass (from 1). */
85
+ onBar?: (bar: number, chord: string | null, pass: number) => void;
86
+ /** Called as each chord starts sounding: its index in `chords`, its name, the pass (#75). */
87
+ onChord?: (index: number, chord: string | null, pass: number) => void;
88
+ /** Called once the progression is over (not after stop). */
89
+ onEnd?: () => void;
90
+ }
91
+ /** What can change while a progression plays; it applies from the next pass. */
92
+ export interface ProgressionChanges {
93
+ bpm?: number;
94
+ loop?: boolean;
95
+ click?: boolean;
96
+ volume?: number;
97
+ sound?: Sound;
98
+ }
99
+ export interface ProgressionHandle extends PlayHandle {
100
+ /** Changes the tempo, loop, click, volume or sound from the next pass. */
101
+ update(changes: ProgressionChanges): void;
102
+ }
103
+ /** At most this many bars a progression (a long chart plays its first ones). */
104
+ export declare const MAX_PROGRESSION_BARS = 256;
105
+ /** The notes of a chord symbol: a guitar voicing (the strum's), or a piano voicing on piano. */
106
+ export declare function progressionPitches(chord: string, sound?: Sound, tuning?: readonly number[], voicings?: VoicingLookup): number[];
107
+ /** Calls `call(i)` as each timing starts, from `heard()` (or `wait` ms after it's made). */
108
+ export declare function followTimes(win: Pick<Window, 'setTimeout' | 'clearTimeout'>, times: readonly StrumTiming[], call: (timing: StrumTiming) => void, wait?: number): StrumFollower;
109
+ /** The settings of a progression player, read at each pass. */
110
+ export interface ProgressionSettings extends StrumSettings {
111
+ click: boolean;
112
+ }
113
+ /**
114
+ * Plays `bars` pass after pass (see `runStrum` for the timing), from `settings()` read at each
115
+ * pass. `follow` gets each pass's bars (`slot` is the bar's index), to light them.
116
+ */
117
+ export declare function runProgression(bars: readonly ProgressionBar[], options: Pick<ProgressionEventOptions, 'beatsPerBar' | 'beatUnit' | 'strum' | 'pattern'>, player: () => NotePlayer, settings: () => ProgressionSettings, timers: Pick<Window, 'setTimeout' | 'clearTimeout'>, onEnd?: () => void, follow?: (chords: StrumTiming[], player: NotePlayer, pass: number, made: Pass) => StrumFollower): PlayHandle;
118
+ /**
119
+ * Plays chords in time, one a bar (#46): strummed on the beats by default, with a metronome
120
+ * click, a count-in when asked, and a loop. Chord symbols take the strum's guitar voicing (a piano
121
+ * voicing with `sound: 'piano'`); given notes play as given. Throws on a chord it can't read, an
122
+ * unknown tuning, or a pattern with a mistake.
123
+ */
124
+ export declare function playProgression(chords: readonly ProgressionChordInput[], options?: PlayProgressionOptions): ProgressionHandle;
@@ -1,5 +1,32 @@
1
- import { type StrumScore } from '../strum/play.js';
1
+ import { type PassMaker, type StrumScore } from '../strum/play.js';
2
2
  import { type PlayOptions } from './controls.js';
3
+ import type { NotePlayer } from './player.js';
3
4
  /** The score of a drawn pattern; null when it has no slots. */
4
5
  export declare function scoreFromDrawing(drawing: Element): StrumScore | null;
6
+ /**
7
+ * The app's player in the window `wrap` is in now (a host may move it to a popout), the light
8
+ * synthesizer when that one fails. It says when its notes start like the player it wraps (the
9
+ * light one does too), or once the player it wraps was seen saying it, here or on another bar.
10
+ */
11
+ export declare function barPlayer(wrap: Element, win: Window, options: PlayOptions): NotePlayer;
5
12
  export declare function strumBarFor(doc: Document, win: Window, drawing: Element, options: PlayOptions): () => void;
13
+ /** What a timed bar plays: its passes, and how it's counted. */
14
+ export interface TimedPiece {
15
+ /** What it plays, for the app (#77). */
16
+ kind: 'strum' | 'picking';
17
+ /** The wrapper's own class, beside `mn-playable`. */
18
+ cls: string;
19
+ /** The bar's name for screen readers. */
20
+ label: string;
21
+ /** Counted in dotted beats (6/8): the tempo slider shows ♩. */
22
+ compound: boolean;
23
+ make: PassMaker;
24
+ /** Shows a click (metronome) button, on or off at the start; none when absent. */
25
+ click?: boolean;
26
+ }
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
30
+ * as they sound.
31
+ */
32
+ export declare function timedBarFor(doc: Document, win: Window, drawing: Element, options: PlayOptions, piece: TimedPiece): () => void;