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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Thor Whalen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,85 @@
|
|
|
1
|
-
#
|
|
1
|
+
# accompy (TypeScript)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Chord charts to accompaniment note events (drums, bass, piano), in the browser or Node. The TypeScript twin of the Python package [accompy](https://github.com/thorwhalen/accompy): same charts in, same events out, held identical by shared golden cases.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { generateEvents, beatsToSeconds } from "accompy";
|
|
7
|
+
|
|
8
|
+
const events = generateEvents("| Dm7 | G7 | Cmaj7 | A7b9 |", { style: "bossa" });
|
|
9
|
+
// [{ time: 0, channel: 9, note: 37, velocity: 56, duration: 0.25 }, ...]
|
|
10
|
+
const seconds = beatsToSeconds(events[0].time, 120);
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
It produces note events and no sound: play them with Web Audio, a sampler, a soundfont player or Web MIDI. No runtime dependencies; about 12 KB gzipped.
|
|
14
|
+
|
|
15
|
+
## The note event
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
interface NoteEvent {
|
|
19
|
+
time: number; // start, in beats from the beginning
|
|
20
|
+
channel: number; // 9 drums, 0 bass, 1 piano (CHANNELS)
|
|
21
|
+
note: number; // MIDI note (General MIDI percussion on channel 9)
|
|
22
|
+
velocity: number; // 0-127
|
|
23
|
+
duration: number; // in beats
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This is Python's `accompy.MidiEvent`, field for field.
|
|
28
|
+
|
|
29
|
+
**Guarantees.** Events are a function of the chart, style, repeats, instruments and volumes only:
|
|
30
|
+
|
|
31
|
+
- **Tempo-free**: nothing in generation reads a tempo; convert beats to seconds at play time (`beatsToSeconds`), so one set of events plays at any tempo.
|
|
32
|
+
- **Stateless across chords**: each chord's events depend only on that chord's notes, start and length (no walking-line continuity, voice leading or fills), so rendering a chart a bar at a time with `chordEvents` gives exactly the events of the whole chart.
|
|
33
|
+
- **Deterministic**: no randomness.
|
|
34
|
+
|
|
35
|
+
Events come in generation order (chord by chord; drums, bass, then piano within a chord). Sort by `time` if your scheduler needs it.
|
|
36
|
+
|
|
37
|
+
## Charts
|
|
38
|
+
|
|
39
|
+
`generateEvents` and `ensureScore` read every form Python's `ensure_score` reads:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
generateEvents("| C Am | F G |"); // chart text: bars, chords split the bar
|
|
43
|
+
generateEvents("C Am F G"); // one chord per bar
|
|
44
|
+
generateEvents([["C", "Am"], ["F"], ["G7"]]); // measures
|
|
45
|
+
generateEvents(["C", "Am", "F", "G7"]); // symbols, one per bar
|
|
46
|
+
generateEvents([["C", 2], ["G", 2], ["F", 4]]); // [chord, beats] pairs
|
|
47
|
+
generateEvents("irealb://..."); // an iReal Pro URL (first tune)
|
|
48
|
+
generateEvents("| C | G |", { style: "waltz", timeSignature: [3, 4] });
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`%` and `x` repeat the previous chord; `N.C.` is silent. Symbols are rewritten to iReal spellings (`Cm7` becomes `C-7`, `Cmaj7` becomes `C^7`), and resolved to notes with the tables of the Python `tonal` package.
|
|
52
|
+
|
|
53
|
+
## One chord at a time
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { chordEvents, tonalResolver } from "accompy";
|
|
57
|
+
|
|
58
|
+
chordEvents(tonalResolver("D-7"), { style: "swing", startBeat: 8, duration: 4 });
|
|
59
|
+
chordEvents([50, 53, 57, 60], { style: "bossa", startBeat: 0, duration: 2 }); // notes, root first
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Styles, patterns and seams
|
|
63
|
+
|
|
64
|
+
`STYLES` lists the builtin styles (swing, bossa, rock, funk, ballad, latin, waltz, blues); `getPatterns(style)` returns their drum, bass and comping patterns as data. `registerStyle(name, { drums, bass, comp })` adds one, or pass your own `PatternRegistry` as `patternSource`. `chordResolver` replaces the chord-to-notes step. Rhythmic skeletons (`resolveSkeleton`, `applySkeleton`, `listSkeletons`, `registerSkeleton`) restrike `[chord, beats]` pairs on a rhythm such as `"tresillo"` or `"charleston"`.
|
|
65
|
+
|
|
66
|
+
## Demo
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
cd ts && npm install && npm run demo # http://localhost:5174/demo/
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
A chart box, a style menu and a Play button, with a tiny Web Audio synth (oscillators and noise) that is part of the demo, not the package.
|
|
73
|
+
|
|
74
|
+
## Parity with Python
|
|
75
|
+
|
|
76
|
+
- The tables (patterns, skeletons, chord spellings, tonal's chord qualities) are generated from Python into `src/data.generated.ts` by `python -m accompy._codegen`; a Python test fails when that file is stale.
|
|
77
|
+
- The golden cases in `../fixtures/cases.json` (about 740 calls over every function above, errors and odd meters included) are recorded from Python by `python -m accompy._fixtures` and run by both `pytest` and `vitest`, compared as JSON text.
|
|
78
|
+
- Python quirks are kept on purpose, so both sides agree; fixes go to the Python side first, then both twins. A symbol the resolver cannot read plays a major triad on its root (`fallbackChordNotes`).
|
|
79
|
+
- Out of scope: the MMA backend, audio rendering, and the Python converter pipeline's ChordPro, Roman-numeral and Nashville parsers and its pychord/music21/mingus resolvers.
|
|
80
|
+
|
|
81
|
+
Names are camelCase; Python's keyword arguments are a trailing options object. Errors carry Python's exception name: `ValueError`, `KeyError` and `ZeroDivisionError` (exported; all subclasses of `RangeError`) and `TypeError`.
|
|
82
|
+
|
|
83
|
+
## Licence
|
|
84
|
+
|
|
85
|
+
MIT.
|