accompy 0.0.0-stage → 0.3.24
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/LICENSE +21 -0
- package/README.md +84 -2
- package/dist/index.cjs +1041 -0
- package/dist/index.d.cts +331 -0
- package/dist/index.d.ts +331 -0
- package/dist/index.js +980 -0
- package/package.json +83 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/** A chord chart: measures of chord symbols (a measure's chords share it evenly). */
|
|
2
|
+
interface Score {
|
|
3
|
+
measures: string[][];
|
|
4
|
+
title: string;
|
|
5
|
+
composer: string;
|
|
6
|
+
key: string;
|
|
7
|
+
timeSignature: [number, number];
|
|
8
|
+
}
|
|
9
|
+
/** A chord and how many beats it lasts. */
|
|
10
|
+
type ChordSpec = [chord: string, beats: number];
|
|
11
|
+
/** Options shared by the chart readers (Python's keyword-only arguments). */
|
|
12
|
+
interface ChartOptions {
|
|
13
|
+
title?: string;
|
|
14
|
+
key?: string;
|
|
15
|
+
timeSignature?: [number, number];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Rewrite a chord symbol to iReal spelling (`Cmaj7` -> `C^7`, `Dm7b5` -> `Dh7`,
|
|
19
|
+
* `Cdim7` -> `Co7`): each `/`-separated part has its longest matching suffix from
|
|
20
|
+
* `CHORD_SYMBOL_REPLACEMENTS` rewritten, once.
|
|
21
|
+
*/
|
|
22
|
+
declare function normalizeChordSymbol(symbol: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Measures of normalised chord symbols from a chart string.
|
|
25
|
+
*
|
|
26
|
+
* With bar lines (`| C Am | F G |`), each bar is a measure and `%` or `x` repeats the
|
|
27
|
+
* previous chord; without, each whitespace-separated symbol is a bar.
|
|
28
|
+
*/
|
|
29
|
+
declare function parseChordString(chordString: string): string[][];
|
|
30
|
+
/** `"3/4"` -> `[3, 4]`; anything unreadable (or empty) -> `[4, 4]`. */
|
|
31
|
+
declare function parseTimeSig(ts: string | [number, number] | null | undefined): [number, number];
|
|
32
|
+
/**
|
|
33
|
+
* A Score from `[chord, beats]` pairs: whole bars become bars, shorter chords are grouped
|
|
34
|
+
* into bars (durations that do not fill bars exactly are approximated). No-chord symbols
|
|
35
|
+
* and non-positive durations are dropped.
|
|
36
|
+
*/
|
|
37
|
+
declare function scoreFromChordSpecs(chords: Iterable<ChordSpec>, opts?: ChartOptions): Score;
|
|
38
|
+
/** The Score as `[chord, beats]` pairs, each chord taking its share of the bar. */
|
|
39
|
+
declare function scoreToChordSequence(score: Score): ChordSpec[];
|
|
40
|
+
/**
|
|
41
|
+
* Coerce any chart form to a {@link Score}: a Score (returned as is), a chart string or an
|
|
42
|
+
* iReal URL (`irealb://`, `irealbook://`), measures (`[["C", "Am"], ["F"]]`), chord
|
|
43
|
+
* symbols one per bar, or `[chord, beats]` pairs. Anything else throws a TypeError.
|
|
44
|
+
*/
|
|
45
|
+
declare function ensureScore(chords: unknown, opts?: ChartOptions): Score;
|
|
46
|
+
/** Transpose a note name (`C`, `Eb`, `F#`); flats by default when going down. */
|
|
47
|
+
declare function transposeNote(name: string, semitones: number, opts?: {
|
|
48
|
+
useFlat?: boolean | null;
|
|
49
|
+
}): string;
|
|
50
|
+
/** Transpose a chord symbol's root (and slash bass); the quality is kept as written. */
|
|
51
|
+
declare function transposeChord(chord: string, semitones: number, opts?: {
|
|
52
|
+
useFlat?: boolean | null;
|
|
53
|
+
}): string;
|
|
54
|
+
/** The Score in `targetKey` (spelled with flats for flat keys), titled `"<title> (<key>)"`. */
|
|
55
|
+
declare function transposeScore(score: Score, targetKey: string): Score;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* iReal Pro URL decoding: the twin of `accompy.ireal` (and of `accompy.util.parse_ireal_url`
|
|
59
|
+
* on top of it). Its unscrambling and chord-string cleanup started from pyRealParser (MIT,
|
|
60
|
+
* notice below), with the changes listed in `accompy/ireal.py`'s docstring.
|
|
61
|
+
*
|
|
62
|
+
* Python semantics are kept where JS differs: `\s`, `\d`, `\w` and `str.strip` are
|
|
63
|
+
* Unicode-aware as in `re`, `.` excludes only `\n`, string indices count code points, and
|
|
64
|
+
* `urllib.parse.unquote` is lenient (bad escapes stay literal, bad UTF-8 becomes U+FFFD).
|
|
65
|
+
*/
|
|
66
|
+
/*! Parts of accompy's iReal decoding derive from pyRealParser, under this licence:
|
|
67
|
+
|
|
68
|
+
MIT License
|
|
69
|
+
|
|
70
|
+
Copyright (c) 2018 Daniel Stephan
|
|
71
|
+
|
|
72
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
73
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
74
|
+
in the Software without restriction, including without limitation the rights
|
|
75
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
76
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
77
|
+
furnished to do so, subject to the following conditions:
|
|
78
|
+
|
|
79
|
+
The above copyright notice and this permission notice shall be included in all
|
|
80
|
+
copies or substantial portions of the Software.
|
|
81
|
+
|
|
82
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
83
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
84
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
85
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
86
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
87
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
88
|
+
SOFTWARE.
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Parse an iReal Pro URL (`irealb://` or `irealbook://`) into a Score, as
|
|
93
|
+
* `accompy.util.parse_ireal_url` does: the first tune with chords, each bar the list of
|
|
94
|
+
* its chords as written.
|
|
95
|
+
* Throws `ValueError` when no tune has chords.
|
|
96
|
+
*/
|
|
97
|
+
declare function parseIrealUrl(url: string): Score;
|
|
98
|
+
|
|
99
|
+
/** Chord symbol -> MIDI notes, root first. The renderer's chord-resolution seam. */
|
|
100
|
+
type ChordResolver = (symbol: string) => number[];
|
|
101
|
+
/** The MIDI notes of `symbol`, root first; throws ValueError (a RangeError) for an unknown root or quality. */
|
|
102
|
+
declare function tonalResolver(symbol: string, opts?: {
|
|
103
|
+
transpose?: number;
|
|
104
|
+
}): number[];
|
|
105
|
+
|
|
106
|
+
/** A drum hit: beat in the bar (0-based), GM percussion note, velocity 0-127. */
|
|
107
|
+
interface DrumHit {
|
|
108
|
+
beat: number;
|
|
109
|
+
drum: number;
|
|
110
|
+
velocity: number;
|
|
111
|
+
}
|
|
112
|
+
/** A drum pattern for one bar of `beatsPerBar` beats. */
|
|
113
|
+
interface DrumPattern {
|
|
114
|
+
name: string;
|
|
115
|
+
beatsPerBar: number;
|
|
116
|
+
hits: DrumHit[];
|
|
117
|
+
}
|
|
118
|
+
/** A bass note: beat, semitones above the chord root (resolved against the chord), beats, velocity. */
|
|
119
|
+
interface BassNote {
|
|
120
|
+
beat: number;
|
|
121
|
+
pitchOffset: number;
|
|
122
|
+
duration: number;
|
|
123
|
+
velocity: number;
|
|
124
|
+
}
|
|
125
|
+
/** A bass pattern: notes relative to the chord root. */
|
|
126
|
+
interface BassPattern {
|
|
127
|
+
name: string;
|
|
128
|
+
notes: BassNote[];
|
|
129
|
+
}
|
|
130
|
+
/** A comping pattern: `[beat, duration, velocity]` hits, each playing the whole chord. */
|
|
131
|
+
interface CompingPattern {
|
|
132
|
+
name: string;
|
|
133
|
+
hits: [beat: number, duration: number, velocity: number][];
|
|
134
|
+
}
|
|
135
|
+
/** What a style plays: the renderer takes the first of each list (drums: by time signature). */
|
|
136
|
+
interface StylePatterns {
|
|
137
|
+
drums: DrumPattern[];
|
|
138
|
+
bass: BassPattern[];
|
|
139
|
+
comp: CompingPattern[];
|
|
140
|
+
}
|
|
141
|
+
/** Where the renderer gets a style's patterns (Python's PatternSource protocol). */
|
|
142
|
+
interface PatternSource {
|
|
143
|
+
getPatterns(style: string): StylePatterns;
|
|
144
|
+
}
|
|
145
|
+
/** Styles by name, starting with the builtin ones. Twin of Python's PatternRegistry. */
|
|
146
|
+
declare class PatternRegistry implements PatternSource {
|
|
147
|
+
#private;
|
|
148
|
+
/** A registry holding the builtin styles (`builtins: false` for an empty one). */
|
|
149
|
+
constructor({ builtins }?: {
|
|
150
|
+
builtins?: boolean;
|
|
151
|
+
});
|
|
152
|
+
/** The style's patterns; throws KeyError (a RangeError) for an unknown style. */
|
|
153
|
+
getPatterns(style: string): StylePatterns;
|
|
154
|
+
/** Add or replace a style. */
|
|
155
|
+
register(style: string, patterns: StylePatterns): void;
|
|
156
|
+
/** Remove a style; returns whether it was there. */
|
|
157
|
+
unregister(style: string): boolean;
|
|
158
|
+
/** The style names, in registration order. */
|
|
159
|
+
styles(): string[];
|
|
160
|
+
}
|
|
161
|
+
/** The shared registry the renderer uses by default. */
|
|
162
|
+
declare function getPatternRegistry(): PatternRegistry;
|
|
163
|
+
/** A style's patterns from the shared registry. */
|
|
164
|
+
declare function getPatterns(style: string): StylePatterns;
|
|
165
|
+
/** Register a style in the shared registry. */
|
|
166
|
+
declare function registerStyle(style: string, patterns: StylePatterns): void;
|
|
167
|
+
/** The builtin style names (swing, bossa, rock, funk, ballad, latin, waltz, blues). */
|
|
168
|
+
declare const STYLES: readonly string[];
|
|
169
|
+
/**
|
|
170
|
+
* The `[drums, bass, comp]` patterns the renderer plays from a style's lists: the first
|
|
171
|
+
* drum pattern whose `beatsPerBar` matches (else the first), the first bass and comping
|
|
172
|
+
* pattern; `null` where a list is empty.
|
|
173
|
+
*/
|
|
174
|
+
declare function selectPatterns(patterns: StylePatterns, beatsPerBar: number): [DrumPattern | null, BassPattern | null, CompingPattern | null];
|
|
175
|
+
|
|
176
|
+
/** One note: Python's `MidiEvent`. Channel 9 is drums, 0 bass, 1 piano. */
|
|
177
|
+
interface NoteEvent {
|
|
178
|
+
/** Start, in beats from the beginning. */
|
|
179
|
+
time: number;
|
|
180
|
+
channel: number;
|
|
181
|
+
/** MIDI note number (for drums, the GM percussion sound). */
|
|
182
|
+
note: number;
|
|
183
|
+
/** 0-127. */
|
|
184
|
+
velocity: number;
|
|
185
|
+
/** Length, in beats. */
|
|
186
|
+
duration: number;
|
|
187
|
+
}
|
|
188
|
+
/** Which instruments play (`drums`, `bass`, `piano`); a missing one plays. */
|
|
189
|
+
type Instruments = Record<string, boolean>;
|
|
190
|
+
/** Volume per instrument, 0-1, scaling pattern velocities; missing ones use the defaults. */
|
|
191
|
+
type Volumes = Record<string, number>;
|
|
192
|
+
/** MIDI channels of the parts. */
|
|
193
|
+
declare const CHANNELS: Readonly<{
|
|
194
|
+
drums: 9;
|
|
195
|
+
bass: 0;
|
|
196
|
+
piano: 1;
|
|
197
|
+
}>;
|
|
198
|
+
/** Seconds from beats at `tempo` beats per minute. */
|
|
199
|
+
declare function beatsToSeconds(beats: number, tempo: number): number;
|
|
200
|
+
/**
|
|
201
|
+
* What the renderer plays for a symbol its resolver cannot read: a major triad on the
|
|
202
|
+
* symbol's leading note name, either case, `#`/`b` or `♯`/`♭` (`G#13(b9)` -> G# major), or
|
|
203
|
+
* on C without one; a minor triad when the symbol says minor (`-`, `m`, not `maj`: `E#m` -> F minor).
|
|
204
|
+
*/
|
|
205
|
+
declare function fallbackChordNotes(symbol: string): number[];
|
|
206
|
+
/** The distinct pitch classes (0-11) of MIDI notes, ascending. */
|
|
207
|
+
declare function pitchClasses(notes: Iterable<number>): number[];
|
|
208
|
+
/**
|
|
209
|
+
* The semitone offset a pattern asks for, resolved against a chord: kept when the chord
|
|
210
|
+
* has it, else a requested 3rd (3 or 4) becomes the chord's own 3rd when it has one.
|
|
211
|
+
*/
|
|
212
|
+
declare function resolvePitchOffset({ rootPc, chordPcs, targetOffset, }: {
|
|
213
|
+
rootPc: number;
|
|
214
|
+
chordPcs: readonly number[];
|
|
215
|
+
targetOffset: number;
|
|
216
|
+
}): number;
|
|
217
|
+
/** The bass note a pattern's `pitchOffset` plays: the chord root moved to C2-B2, plus the resolved offset. */
|
|
218
|
+
declare function bassPitch(root: number, chordNotes: readonly number[], pitchOffset: number): number;
|
|
219
|
+
/** The notes the piano plays for a chord: its first four notes moved into C4-B4 (none: a C major triad). */
|
|
220
|
+
declare function compVoicing(chordNotes: readonly number[]): number[];
|
|
221
|
+
/** Options of {@link chordEvents}. */
|
|
222
|
+
interface ChordEventsOptions {
|
|
223
|
+
style?: string;
|
|
224
|
+
startBeat?: number;
|
|
225
|
+
duration?: number;
|
|
226
|
+
beatsPerBar?: number;
|
|
227
|
+
instruments?: Instruments;
|
|
228
|
+
volumes?: Volumes;
|
|
229
|
+
patternSource?: PatternSource;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* The drum, bass and piano events `style` plays over one chord, given the chord's MIDI
|
|
233
|
+
* notes (root first, as a {@link ChordResolver} returns them). One step of
|
|
234
|
+
* {@link generateEvents}: call it per chord to render a chart a bar at a time.
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* chordEvents([48, 52, 55], { style: "bossa", startBeat: 4, duration: 4 });
|
|
238
|
+
*/
|
|
239
|
+
declare function chordEvents(chordNotes: readonly number[], opts?: ChordEventsOptions): NoteEvent[];
|
|
240
|
+
/** Options of {@link generateEvents}. */
|
|
241
|
+
interface GenerateOptions {
|
|
242
|
+
style?: string;
|
|
243
|
+
/** How many times the chart is played (default 1). */
|
|
244
|
+
repeats?: number;
|
|
245
|
+
/** For chart forms that carry none (default: the style's, see {@link styleTimeSignature}). */
|
|
246
|
+
timeSignature?: [number, number];
|
|
247
|
+
instruments?: Instruments;
|
|
248
|
+
volumes?: Volumes;
|
|
249
|
+
patternSource?: PatternSource;
|
|
250
|
+
chordResolver?: ChordResolver;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* The note events of a whole chart (any form {@link ensureScore} reads), in the order the
|
|
254
|
+
* builtin backend generates them: chord by chord, drums then bass then piano. The chords of a
|
|
255
|
+
* bar share its beats ({@link barChordSpans}); no-chord symbols are silent; a symbol the
|
|
256
|
+
* resolver cannot read plays a major triad on its root ({@link fallbackChordNotes}).
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* const events = generateEvents("| Dm7 | G7 | C^7 |", { style: "swing" });
|
|
260
|
+
*/
|
|
261
|
+
declare function generateEvents(chords: string | Score | unknown, opts?: GenerateOptions): NoteEvent[];
|
|
262
|
+
|
|
263
|
+
/** A skeleton's entry: its durations (beats), display name, measure length and styles. */
|
|
264
|
+
interface Skeleton {
|
|
265
|
+
pattern: number[];
|
|
266
|
+
name: string;
|
|
267
|
+
beatsPerMeasure: number;
|
|
268
|
+
styles: string[];
|
|
269
|
+
}
|
|
270
|
+
/** The skeletons by key, builtin ones first; {@link registerSkeleton} adds to it. */
|
|
271
|
+
declare const RHYTHMIC_SKELETONS: Map<string, Skeleton>;
|
|
272
|
+
/**
|
|
273
|
+
* A skeleton's durations from a duration list (returned as is), a key (`"tresillo"`), a
|
|
274
|
+
* name, case-insensitively (`"Dotted half + quarter"`), or a style (`"reggae"`: its first
|
|
275
|
+
* skeleton). Throws KeyError (a RangeError) when nothing matches, TypeError for
|
|
276
|
+
* anything but a string or an array.
|
|
277
|
+
*/
|
|
278
|
+
declare function resolveSkeleton(skeleton: string | readonly number[]): number[];
|
|
279
|
+
/**
|
|
280
|
+
* Restrike `[chord, beats]` pairs on a skeleton: each strike of each measure plays the
|
|
281
|
+
* chord active at that beat, split where a chord changes under it.
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* applySkeleton([["Dm7", 4], ["G7", 4]], "tresillo");
|
|
285
|
+
* // [["Dm7", 1.5], ["Dm7", 1.5], ["Dm7", 1], ["G7", 1.5], ["G7", 1.5], ["G7", 1]]
|
|
286
|
+
*/
|
|
287
|
+
declare function applySkeleton(chords: readonly ChordSpec[], skeleton: string | readonly number[]): ChordSpec[];
|
|
288
|
+
/** Add (or replace) a skeleton; its measure length defaults to the sum of its durations. */
|
|
289
|
+
declare function registerSkeleton(key: string, pattern: readonly number[], opts?: {
|
|
290
|
+
name?: string;
|
|
291
|
+
beatsPerMeasure?: number;
|
|
292
|
+
styles?: string[];
|
|
293
|
+
}): void;
|
|
294
|
+
/** Skeleton keys, optionally only those of a measure length and/or a style. */
|
|
295
|
+
declare function listSkeletons(opts?: {
|
|
296
|
+
beatsPerMeasure?: number;
|
|
297
|
+
style?: string;
|
|
298
|
+
}): string[];
|
|
299
|
+
|
|
300
|
+
declare const DRUMS: {
|
|
301
|
+
readonly KICK: 36;
|
|
302
|
+
readonly SNARE: 38;
|
|
303
|
+
readonly SIDE_STICK: 37;
|
|
304
|
+
readonly CLOSED_HIHAT: 42;
|
|
305
|
+
readonly OPEN_HIHAT: 46;
|
|
306
|
+
readonly PEDAL_HIHAT: 44;
|
|
307
|
+
readonly RIDE: 51;
|
|
308
|
+
readonly RIDE_BELL: 53;
|
|
309
|
+
readonly CRASH: 49;
|
|
310
|
+
readonly LOW_TOM: 45;
|
|
311
|
+
readonly MID_TOM: 47;
|
|
312
|
+
readonly HIGH_TOM: 50;
|
|
313
|
+
readonly COWBELL: 56;
|
|
314
|
+
readonly CLAVES: 75;
|
|
315
|
+
readonly SHAKER: 70;
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
/** Python's `ValueError` (a RangeError whose `name` is the Python one). */
|
|
319
|
+
declare class ValueError extends RangeError {
|
|
320
|
+
name: string;
|
|
321
|
+
}
|
|
322
|
+
/** Python's `KeyError`: an unknown style or skeleton (a RangeError named after Python's). */
|
|
323
|
+
declare class KeyError extends RangeError {
|
|
324
|
+
name: string;
|
|
325
|
+
}
|
|
326
|
+
/** Python's `ZeroDivisionError` (a RangeError named after Python's). */
|
|
327
|
+
declare class ZeroDivisionError extends RangeError {
|
|
328
|
+
name: string;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export { type BassNote, type BassPattern, CHANNELS, type ChartOptions, type ChordEventsOptions, type ChordResolver, type ChordSpec, type CompingPattern, DRUMS, type DrumHit, type DrumPattern, type GenerateOptions, type Instruments, KeyError, type NoteEvent, PatternRegistry, type PatternSource, RHYTHMIC_SKELETONS, STYLES, type Score, type Skeleton, type StylePatterns, ValueError, type Volumes, ZeroDivisionError, applySkeleton, bassPitch, beatsToSeconds, chordEvents, compVoicing, ensureScore, fallbackChordNotes, generateEvents, getPatternRegistry, getPatterns, listSkeletons, normalizeChordSymbol, parseChordString, parseIrealUrl, parseTimeSig, pitchClasses, registerSkeleton, registerStyle, resolvePitchOffset, resolveSkeleton, scoreFromChordSpecs, scoreToChordSequence, selectPatterns, tonalResolver, transposeChord, transposeNote, transposeScore };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/** A chord chart: measures of chord symbols (a measure's chords share it evenly). */
|
|
2
|
+
interface Score {
|
|
3
|
+
measures: string[][];
|
|
4
|
+
title: string;
|
|
5
|
+
composer: string;
|
|
6
|
+
key: string;
|
|
7
|
+
timeSignature: [number, number];
|
|
8
|
+
}
|
|
9
|
+
/** A chord and how many beats it lasts. */
|
|
10
|
+
type ChordSpec = [chord: string, beats: number];
|
|
11
|
+
/** Options shared by the chart readers (Python's keyword-only arguments). */
|
|
12
|
+
interface ChartOptions {
|
|
13
|
+
title?: string;
|
|
14
|
+
key?: string;
|
|
15
|
+
timeSignature?: [number, number];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Rewrite a chord symbol to iReal spelling (`Cmaj7` -> `C^7`, `Dm7b5` -> `Dh7`,
|
|
19
|
+
* `Cdim7` -> `Co7`): each `/`-separated part has its longest matching suffix from
|
|
20
|
+
* `CHORD_SYMBOL_REPLACEMENTS` rewritten, once.
|
|
21
|
+
*/
|
|
22
|
+
declare function normalizeChordSymbol(symbol: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Measures of normalised chord symbols from a chart string.
|
|
25
|
+
*
|
|
26
|
+
* With bar lines (`| C Am | F G |`), each bar is a measure and `%` or `x` repeats the
|
|
27
|
+
* previous chord; without, each whitespace-separated symbol is a bar.
|
|
28
|
+
*/
|
|
29
|
+
declare function parseChordString(chordString: string): string[][];
|
|
30
|
+
/** `"3/4"` -> `[3, 4]`; anything unreadable (or empty) -> `[4, 4]`. */
|
|
31
|
+
declare function parseTimeSig(ts: string | [number, number] | null | undefined): [number, number];
|
|
32
|
+
/**
|
|
33
|
+
* A Score from `[chord, beats]` pairs: whole bars become bars, shorter chords are grouped
|
|
34
|
+
* into bars (durations that do not fill bars exactly are approximated). No-chord symbols
|
|
35
|
+
* and non-positive durations are dropped.
|
|
36
|
+
*/
|
|
37
|
+
declare function scoreFromChordSpecs(chords: Iterable<ChordSpec>, opts?: ChartOptions): Score;
|
|
38
|
+
/** The Score as `[chord, beats]` pairs, each chord taking its share of the bar. */
|
|
39
|
+
declare function scoreToChordSequence(score: Score): ChordSpec[];
|
|
40
|
+
/**
|
|
41
|
+
* Coerce any chart form to a {@link Score}: a Score (returned as is), a chart string or an
|
|
42
|
+
* iReal URL (`irealb://`, `irealbook://`), measures (`[["C", "Am"], ["F"]]`), chord
|
|
43
|
+
* symbols one per bar, or `[chord, beats]` pairs. Anything else throws a TypeError.
|
|
44
|
+
*/
|
|
45
|
+
declare function ensureScore(chords: unknown, opts?: ChartOptions): Score;
|
|
46
|
+
/** Transpose a note name (`C`, `Eb`, `F#`); flats by default when going down. */
|
|
47
|
+
declare function transposeNote(name: string, semitones: number, opts?: {
|
|
48
|
+
useFlat?: boolean | null;
|
|
49
|
+
}): string;
|
|
50
|
+
/** Transpose a chord symbol's root (and slash bass); the quality is kept as written. */
|
|
51
|
+
declare function transposeChord(chord: string, semitones: number, opts?: {
|
|
52
|
+
useFlat?: boolean | null;
|
|
53
|
+
}): string;
|
|
54
|
+
/** The Score in `targetKey` (spelled with flats for flat keys), titled `"<title> (<key>)"`. */
|
|
55
|
+
declare function transposeScore(score: Score, targetKey: string): Score;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* iReal Pro URL decoding: the twin of `accompy.ireal` (and of `accompy.util.parse_ireal_url`
|
|
59
|
+
* on top of it). Its unscrambling and chord-string cleanup started from pyRealParser (MIT,
|
|
60
|
+
* notice below), with the changes listed in `accompy/ireal.py`'s docstring.
|
|
61
|
+
*
|
|
62
|
+
* Python semantics are kept where JS differs: `\s`, `\d`, `\w` and `str.strip` are
|
|
63
|
+
* Unicode-aware as in `re`, `.` excludes only `\n`, string indices count code points, and
|
|
64
|
+
* `urllib.parse.unquote` is lenient (bad escapes stay literal, bad UTF-8 becomes U+FFFD).
|
|
65
|
+
*/
|
|
66
|
+
/*! Parts of accompy's iReal decoding derive from pyRealParser, under this licence:
|
|
67
|
+
|
|
68
|
+
MIT License
|
|
69
|
+
|
|
70
|
+
Copyright (c) 2018 Daniel Stephan
|
|
71
|
+
|
|
72
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
73
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
74
|
+
in the Software without restriction, including without limitation the rights
|
|
75
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
76
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
77
|
+
furnished to do so, subject to the following conditions:
|
|
78
|
+
|
|
79
|
+
The above copyright notice and this permission notice shall be included in all
|
|
80
|
+
copies or substantial portions of the Software.
|
|
81
|
+
|
|
82
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
83
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
84
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
85
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
86
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
87
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
88
|
+
SOFTWARE.
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Parse an iReal Pro URL (`irealb://` or `irealbook://`) into a Score, as
|
|
93
|
+
* `accompy.util.parse_ireal_url` does: the first tune with chords, each bar the list of
|
|
94
|
+
* its chords as written.
|
|
95
|
+
* Throws `ValueError` when no tune has chords.
|
|
96
|
+
*/
|
|
97
|
+
declare function parseIrealUrl(url: string): Score;
|
|
98
|
+
|
|
99
|
+
/** Chord symbol -> MIDI notes, root first. The renderer's chord-resolution seam. */
|
|
100
|
+
type ChordResolver = (symbol: string) => number[];
|
|
101
|
+
/** The MIDI notes of `symbol`, root first; throws ValueError (a RangeError) for an unknown root or quality. */
|
|
102
|
+
declare function tonalResolver(symbol: string, opts?: {
|
|
103
|
+
transpose?: number;
|
|
104
|
+
}): number[];
|
|
105
|
+
|
|
106
|
+
/** A drum hit: beat in the bar (0-based), GM percussion note, velocity 0-127. */
|
|
107
|
+
interface DrumHit {
|
|
108
|
+
beat: number;
|
|
109
|
+
drum: number;
|
|
110
|
+
velocity: number;
|
|
111
|
+
}
|
|
112
|
+
/** A drum pattern for one bar of `beatsPerBar` beats. */
|
|
113
|
+
interface DrumPattern {
|
|
114
|
+
name: string;
|
|
115
|
+
beatsPerBar: number;
|
|
116
|
+
hits: DrumHit[];
|
|
117
|
+
}
|
|
118
|
+
/** A bass note: beat, semitones above the chord root (resolved against the chord), beats, velocity. */
|
|
119
|
+
interface BassNote {
|
|
120
|
+
beat: number;
|
|
121
|
+
pitchOffset: number;
|
|
122
|
+
duration: number;
|
|
123
|
+
velocity: number;
|
|
124
|
+
}
|
|
125
|
+
/** A bass pattern: notes relative to the chord root. */
|
|
126
|
+
interface BassPattern {
|
|
127
|
+
name: string;
|
|
128
|
+
notes: BassNote[];
|
|
129
|
+
}
|
|
130
|
+
/** A comping pattern: `[beat, duration, velocity]` hits, each playing the whole chord. */
|
|
131
|
+
interface CompingPattern {
|
|
132
|
+
name: string;
|
|
133
|
+
hits: [beat: number, duration: number, velocity: number][];
|
|
134
|
+
}
|
|
135
|
+
/** What a style plays: the renderer takes the first of each list (drums: by time signature). */
|
|
136
|
+
interface StylePatterns {
|
|
137
|
+
drums: DrumPattern[];
|
|
138
|
+
bass: BassPattern[];
|
|
139
|
+
comp: CompingPattern[];
|
|
140
|
+
}
|
|
141
|
+
/** Where the renderer gets a style's patterns (Python's PatternSource protocol). */
|
|
142
|
+
interface PatternSource {
|
|
143
|
+
getPatterns(style: string): StylePatterns;
|
|
144
|
+
}
|
|
145
|
+
/** Styles by name, starting with the builtin ones. Twin of Python's PatternRegistry. */
|
|
146
|
+
declare class PatternRegistry implements PatternSource {
|
|
147
|
+
#private;
|
|
148
|
+
/** A registry holding the builtin styles (`builtins: false` for an empty one). */
|
|
149
|
+
constructor({ builtins }?: {
|
|
150
|
+
builtins?: boolean;
|
|
151
|
+
});
|
|
152
|
+
/** The style's patterns; throws KeyError (a RangeError) for an unknown style. */
|
|
153
|
+
getPatterns(style: string): StylePatterns;
|
|
154
|
+
/** Add or replace a style. */
|
|
155
|
+
register(style: string, patterns: StylePatterns): void;
|
|
156
|
+
/** Remove a style; returns whether it was there. */
|
|
157
|
+
unregister(style: string): boolean;
|
|
158
|
+
/** The style names, in registration order. */
|
|
159
|
+
styles(): string[];
|
|
160
|
+
}
|
|
161
|
+
/** The shared registry the renderer uses by default. */
|
|
162
|
+
declare function getPatternRegistry(): PatternRegistry;
|
|
163
|
+
/** A style's patterns from the shared registry. */
|
|
164
|
+
declare function getPatterns(style: string): StylePatterns;
|
|
165
|
+
/** Register a style in the shared registry. */
|
|
166
|
+
declare function registerStyle(style: string, patterns: StylePatterns): void;
|
|
167
|
+
/** The builtin style names (swing, bossa, rock, funk, ballad, latin, waltz, blues). */
|
|
168
|
+
declare const STYLES: readonly string[];
|
|
169
|
+
/**
|
|
170
|
+
* The `[drums, bass, comp]` patterns the renderer plays from a style's lists: the first
|
|
171
|
+
* drum pattern whose `beatsPerBar` matches (else the first), the first bass and comping
|
|
172
|
+
* pattern; `null` where a list is empty.
|
|
173
|
+
*/
|
|
174
|
+
declare function selectPatterns(patterns: StylePatterns, beatsPerBar: number): [DrumPattern | null, BassPattern | null, CompingPattern | null];
|
|
175
|
+
|
|
176
|
+
/** One note: Python's `MidiEvent`. Channel 9 is drums, 0 bass, 1 piano. */
|
|
177
|
+
interface NoteEvent {
|
|
178
|
+
/** Start, in beats from the beginning. */
|
|
179
|
+
time: number;
|
|
180
|
+
channel: number;
|
|
181
|
+
/** MIDI note number (for drums, the GM percussion sound). */
|
|
182
|
+
note: number;
|
|
183
|
+
/** 0-127. */
|
|
184
|
+
velocity: number;
|
|
185
|
+
/** Length, in beats. */
|
|
186
|
+
duration: number;
|
|
187
|
+
}
|
|
188
|
+
/** Which instruments play (`drums`, `bass`, `piano`); a missing one plays. */
|
|
189
|
+
type Instruments = Record<string, boolean>;
|
|
190
|
+
/** Volume per instrument, 0-1, scaling pattern velocities; missing ones use the defaults. */
|
|
191
|
+
type Volumes = Record<string, number>;
|
|
192
|
+
/** MIDI channels of the parts. */
|
|
193
|
+
declare const CHANNELS: Readonly<{
|
|
194
|
+
drums: 9;
|
|
195
|
+
bass: 0;
|
|
196
|
+
piano: 1;
|
|
197
|
+
}>;
|
|
198
|
+
/** Seconds from beats at `tempo` beats per minute. */
|
|
199
|
+
declare function beatsToSeconds(beats: number, tempo: number): number;
|
|
200
|
+
/**
|
|
201
|
+
* What the renderer plays for a symbol its resolver cannot read: a major triad on the
|
|
202
|
+
* symbol's leading note name, either case, `#`/`b` or `♯`/`♭` (`G#13(b9)` -> G# major), or
|
|
203
|
+
* on C without one; a minor triad when the symbol says minor (`-`, `m`, not `maj`: `E#m` -> F minor).
|
|
204
|
+
*/
|
|
205
|
+
declare function fallbackChordNotes(symbol: string): number[];
|
|
206
|
+
/** The distinct pitch classes (0-11) of MIDI notes, ascending. */
|
|
207
|
+
declare function pitchClasses(notes: Iterable<number>): number[];
|
|
208
|
+
/**
|
|
209
|
+
* The semitone offset a pattern asks for, resolved against a chord: kept when the chord
|
|
210
|
+
* has it, else a requested 3rd (3 or 4) becomes the chord's own 3rd when it has one.
|
|
211
|
+
*/
|
|
212
|
+
declare function resolvePitchOffset({ rootPc, chordPcs, targetOffset, }: {
|
|
213
|
+
rootPc: number;
|
|
214
|
+
chordPcs: readonly number[];
|
|
215
|
+
targetOffset: number;
|
|
216
|
+
}): number;
|
|
217
|
+
/** The bass note a pattern's `pitchOffset` plays: the chord root moved to C2-B2, plus the resolved offset. */
|
|
218
|
+
declare function bassPitch(root: number, chordNotes: readonly number[], pitchOffset: number): number;
|
|
219
|
+
/** The notes the piano plays for a chord: its first four notes moved into C4-B4 (none: a C major triad). */
|
|
220
|
+
declare function compVoicing(chordNotes: readonly number[]): number[];
|
|
221
|
+
/** Options of {@link chordEvents}. */
|
|
222
|
+
interface ChordEventsOptions {
|
|
223
|
+
style?: string;
|
|
224
|
+
startBeat?: number;
|
|
225
|
+
duration?: number;
|
|
226
|
+
beatsPerBar?: number;
|
|
227
|
+
instruments?: Instruments;
|
|
228
|
+
volumes?: Volumes;
|
|
229
|
+
patternSource?: PatternSource;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* The drum, bass and piano events `style` plays over one chord, given the chord's MIDI
|
|
233
|
+
* notes (root first, as a {@link ChordResolver} returns them). One step of
|
|
234
|
+
* {@link generateEvents}: call it per chord to render a chart a bar at a time.
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* chordEvents([48, 52, 55], { style: "bossa", startBeat: 4, duration: 4 });
|
|
238
|
+
*/
|
|
239
|
+
declare function chordEvents(chordNotes: readonly number[], opts?: ChordEventsOptions): NoteEvent[];
|
|
240
|
+
/** Options of {@link generateEvents}. */
|
|
241
|
+
interface GenerateOptions {
|
|
242
|
+
style?: string;
|
|
243
|
+
/** How many times the chart is played (default 1). */
|
|
244
|
+
repeats?: number;
|
|
245
|
+
/** For chart forms that carry none (default: the style's, see {@link styleTimeSignature}). */
|
|
246
|
+
timeSignature?: [number, number];
|
|
247
|
+
instruments?: Instruments;
|
|
248
|
+
volumes?: Volumes;
|
|
249
|
+
patternSource?: PatternSource;
|
|
250
|
+
chordResolver?: ChordResolver;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* The note events of a whole chart (any form {@link ensureScore} reads), in the order the
|
|
254
|
+
* builtin backend generates them: chord by chord, drums then bass then piano. The chords of a
|
|
255
|
+
* bar share its beats ({@link barChordSpans}); no-chord symbols are silent; a symbol the
|
|
256
|
+
* resolver cannot read plays a major triad on its root ({@link fallbackChordNotes}).
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* const events = generateEvents("| Dm7 | G7 | C^7 |", { style: "swing" });
|
|
260
|
+
*/
|
|
261
|
+
declare function generateEvents(chords: string | Score | unknown, opts?: GenerateOptions): NoteEvent[];
|
|
262
|
+
|
|
263
|
+
/** A skeleton's entry: its durations (beats), display name, measure length and styles. */
|
|
264
|
+
interface Skeleton {
|
|
265
|
+
pattern: number[];
|
|
266
|
+
name: string;
|
|
267
|
+
beatsPerMeasure: number;
|
|
268
|
+
styles: string[];
|
|
269
|
+
}
|
|
270
|
+
/** The skeletons by key, builtin ones first; {@link registerSkeleton} adds to it. */
|
|
271
|
+
declare const RHYTHMIC_SKELETONS: Map<string, Skeleton>;
|
|
272
|
+
/**
|
|
273
|
+
* A skeleton's durations from a duration list (returned as is), a key (`"tresillo"`), a
|
|
274
|
+
* name, case-insensitively (`"Dotted half + quarter"`), or a style (`"reggae"`: its first
|
|
275
|
+
* skeleton). Throws KeyError (a RangeError) when nothing matches, TypeError for
|
|
276
|
+
* anything but a string or an array.
|
|
277
|
+
*/
|
|
278
|
+
declare function resolveSkeleton(skeleton: string | readonly number[]): number[];
|
|
279
|
+
/**
|
|
280
|
+
* Restrike `[chord, beats]` pairs on a skeleton: each strike of each measure plays the
|
|
281
|
+
* chord active at that beat, split where a chord changes under it.
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* applySkeleton([["Dm7", 4], ["G7", 4]], "tresillo");
|
|
285
|
+
* // [["Dm7", 1.5], ["Dm7", 1.5], ["Dm7", 1], ["G7", 1.5], ["G7", 1.5], ["G7", 1]]
|
|
286
|
+
*/
|
|
287
|
+
declare function applySkeleton(chords: readonly ChordSpec[], skeleton: string | readonly number[]): ChordSpec[];
|
|
288
|
+
/** Add (or replace) a skeleton; its measure length defaults to the sum of its durations. */
|
|
289
|
+
declare function registerSkeleton(key: string, pattern: readonly number[], opts?: {
|
|
290
|
+
name?: string;
|
|
291
|
+
beatsPerMeasure?: number;
|
|
292
|
+
styles?: string[];
|
|
293
|
+
}): void;
|
|
294
|
+
/** Skeleton keys, optionally only those of a measure length and/or a style. */
|
|
295
|
+
declare function listSkeletons(opts?: {
|
|
296
|
+
beatsPerMeasure?: number;
|
|
297
|
+
style?: string;
|
|
298
|
+
}): string[];
|
|
299
|
+
|
|
300
|
+
declare const DRUMS: {
|
|
301
|
+
readonly KICK: 36;
|
|
302
|
+
readonly SNARE: 38;
|
|
303
|
+
readonly SIDE_STICK: 37;
|
|
304
|
+
readonly CLOSED_HIHAT: 42;
|
|
305
|
+
readonly OPEN_HIHAT: 46;
|
|
306
|
+
readonly PEDAL_HIHAT: 44;
|
|
307
|
+
readonly RIDE: 51;
|
|
308
|
+
readonly RIDE_BELL: 53;
|
|
309
|
+
readonly CRASH: 49;
|
|
310
|
+
readonly LOW_TOM: 45;
|
|
311
|
+
readonly MID_TOM: 47;
|
|
312
|
+
readonly HIGH_TOM: 50;
|
|
313
|
+
readonly COWBELL: 56;
|
|
314
|
+
readonly CLAVES: 75;
|
|
315
|
+
readonly SHAKER: 70;
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
/** Python's `ValueError` (a RangeError whose `name` is the Python one). */
|
|
319
|
+
declare class ValueError extends RangeError {
|
|
320
|
+
name: string;
|
|
321
|
+
}
|
|
322
|
+
/** Python's `KeyError`: an unknown style or skeleton (a RangeError named after Python's). */
|
|
323
|
+
declare class KeyError extends RangeError {
|
|
324
|
+
name: string;
|
|
325
|
+
}
|
|
326
|
+
/** Python's `ZeroDivisionError` (a RangeError named after Python's). */
|
|
327
|
+
declare class ZeroDivisionError extends RangeError {
|
|
328
|
+
name: string;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export { type BassNote, type BassPattern, CHANNELS, type ChartOptions, type ChordEventsOptions, type ChordResolver, type ChordSpec, type CompingPattern, DRUMS, type DrumHit, type DrumPattern, type GenerateOptions, type Instruments, KeyError, type NoteEvent, PatternRegistry, type PatternSource, RHYTHMIC_SKELETONS, STYLES, type Score, type Skeleton, type StylePatterns, ValueError, type Volumes, ZeroDivisionError, applySkeleton, bassPitch, beatsToSeconds, chordEvents, compVoicing, ensureScore, fallbackChordNotes, generateEvents, getPatternRegistry, getPatterns, listSkeletons, normalizeChordSymbol, parseChordString, parseIrealUrl, parseTimeSig, pitchClasses, registerSkeleton, registerStyle, resolvePitchOffset, resolveSkeleton, scoreFromChordSpecs, scoreToChordSequence, selectPatterns, tonalResolver, transposeChord, transposeNote, transposeScore };
|