@beatbax/engine 0.1.0 → 0.2.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.
package/README.md ADDED
@@ -0,0 +1,162 @@
1
+ # @beatbax/engine
2
+
3
+ > Live-coding language and runtime for retro console chiptunes.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@beatbax/engine.svg)](https://www.npmjs.com/package/@beatbax/engine)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## Overview
9
+
10
+ The BeatBax engine is a deterministic, tick-accurate audio engine for creating chiptune music. It currently provides a faithful 4-channel Game Boy APU emulation with support for:
11
+
12
+ - **Pulse 1 & 2** - Square wave channels with duty cycle and envelope control
13
+ - **Wave** - Custom wavetable playback (16×4-bit samples)
14
+ - **Noise** - LFSR-based noise generation with envelope
15
+
16
+ Additional chipsets will be added in the future.
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install @beatbax/engine
22
+ ```
23
+
24
+ ## Quick Start
25
+
26
+ ```typescript
27
+ import { parse } from '@beatbax/engine/parser';
28
+ import { resolveSong } from '@beatbax/engine/song';
29
+ import { play } from '@beatbax/engine/audio';
30
+
31
+ const source = `
32
+ chip gameboy
33
+ bpm 120
34
+
35
+ inst lead type=pulse1 duty=50 env=gb:12,down,1
36
+
37
+ pat melody = C4 E4 G4 C5
38
+
39
+ channel 1 => inst lead pat melody
40
+ `;
41
+
42
+ const ast = parse(source);
43
+ const song = resolveSong(ast);
44
+ await play(song);
45
+ ```
46
+
47
+ ## Features
48
+
49
+ ### Parser & Language
50
+ - Full BeatBax language parser
51
+ - Pattern and sequence definitions
52
+ - Inline effects and transforms
53
+ - Import/export support
54
+
55
+ ### Exports
56
+ ```typescript
57
+ import { exportJSON } from '@beatbax/engine/export';
58
+ import { exportMIDI } from '@beatbax/engine/export';
59
+ import { exportUGE } from '@beatbax/engine/export';
60
+
61
+ // Export to various formats
62
+ await exportJSON(song, 'output.json');
63
+ await exportMIDI(song, 'output.mid');
64
+ await exportUGE(song, 'output.uge');
65
+ ```
66
+
67
+ ### Imports
68
+ ```typescript
69
+ import { readUGE } from '@beatbax/engine/import';
70
+
71
+ // Import hUGETracker files (v1-v6)
72
+ const song = await readUGE('input.uge');
73
+ ```
74
+
75
+ ### Audio Playback
76
+ ```typescript
77
+ import { play } from '@beatbax/engine/audio';
78
+
79
+ // Play with controls
80
+ const player = await play(song);
81
+ player.pause();
82
+ player.resume();
83
+ player.stop();
84
+ ```
85
+
86
+ ## API Documentation
87
+
88
+ ### Core Modules
89
+
90
+ - **`@beatbax/engine/parser`** - Parse BeatBax source code
91
+ - **`@beatbax/engine/song`** - Song resolution and ISM generation
92
+ - **`@beatbax/engine/audio`** - WebAudio playback engine
93
+ - **`@beatbax/engine/export`** - Export to JSON, MIDI, UGE
94
+ - **`@beatbax/engine/import`** - Import UGE files
95
+ - **`@beatbax/engine/chips`** - Game Boy APU emulation
96
+ - **`@beatbax/engine/scheduler`** - Deterministic tick scheduler
97
+
98
+ ### Browser Support
99
+
100
+ The engine supports both Node.js and browser environments with conditional exports:
101
+
102
+ ```typescript
103
+ // Automatic browser-safe imports
104
+ import { resolveSong } from '@beatbax/engine/song'; // Uses browser version in browsers
105
+ ```
106
+
107
+ ## Examples
108
+
109
+ ### Using Effects
110
+
111
+ ```javascript
112
+ const source = `
113
+ inst lead type=pulse1 duty=50 env=gb:12,down,1
114
+
115
+ effect vibLead = vib:4,3
116
+ effect arpMinor = arp:3,7
117
+
118
+ pat melody = C4<vibLead> E4 G4<arpMinor>:2
119
+
120
+ channel 1 => inst lead pat melody
121
+ `;
122
+ ```
123
+
124
+ ### Export to hUGETracker
125
+
126
+ ```typescript
127
+ import { exportUGE } from '@beatbax/engine/export';
128
+
129
+ await exportUGE(song, 'song.uge', {
130
+ verbose: true // Show detailed export info
131
+ });
132
+ ```
133
+
134
+ ### Import and Transform
135
+
136
+ ```typescript
137
+ import { readUGE } from '@beatbax/engine/import';
138
+ import { exportMIDI } from '@beatbax/engine/export';
139
+
140
+ // Import UGE and export as MIDI
141
+ const song = await readUGE('input.uge');
142
+ await exportMIDI(song, 'output.mid');
143
+ ```
144
+
145
+ ## TypeScript Support
146
+
147
+ Full TypeScript definitions included:
148
+
149
+ ```typescript
150
+ import type { AST, Song, Pattern, Instrument } from '@beatbax/engine';
151
+ ```
152
+
153
+ ## Resources
154
+
155
+ - [GitHub Repository](https://github.com/kadraman/beatbax)
156
+ - [Full Documentation](https://github.com/kadraman/beatbax/tree/main/docs)
157
+ - [Tutorial](https://github.com/kadraman/beatbax/blob/main/TUTORIAL.md)
158
+ - [CLI Tool](https://www.npmjs.com/package/@beatbax/cli)
159
+
160
+ ## License
161
+
162
+ MIT © BeatBax Contributors