tuneframes 0.1.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/LICENSE ADDED
@@ -0,0 +1,199 @@
1
+ http://www.apache.org/licenses/
2
+
3
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
4
+
5
+ 1. Definitions.
6
+
7
+ "License" shall mean the terms and conditions for use, reproduction,
8
+ and distribution as defined by Sections 1 through 9 of this document.
9
+
10
+ "Licensor" shall mean the copyright owner or entity authorized by
11
+ the copyright owner that is granting the License.
12
+
13
+ "Legal Entity" shall mean the union of the acting entity and all
14
+ other entities that control, are controlled by, or are under common
15
+ control with that entity. For the purposes of this definition,
16
+ "control" means (i) the power, direct or indirect, to cause the
17
+ direction or management of such entity, whether by contract or
18
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
19
+ outstanding shares, or (iii) beneficial ownership of such entity.
20
+
21
+ "You" (or "Your") shall mean an individual or Legal Entity
22
+ exercising permissions granted by this License.
23
+
24
+ "Source" form shall mean the preferred form for making modifications,
25
+ including but not limited to software source code, documentation
26
+ source, and configuration files.
27
+
28
+ "Object" form shall mean any form resulting from mechanical
29
+ transformation or translation of a Source form, including but
30
+ not limited to compiled object code, generated documentation,
31
+ and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or
34
+ Object form, made available under the License, as indicated by a
35
+ copyright notice that is included in or attached to the work
36
+ (an example is provided in the Appendix below).
37
+
38
+ "Derivative Works" shall mean any work, whether in Source or Object
39
+ form, that is based on (or derived from) the Work and for which the
40
+ editorial revisions, annotations, elaborations, or other modifications
41
+ represent, as a whole, an original work of authorship. For the purposes
42
+ of this License, Derivative Works shall not include works that remain
43
+ separable from, or merely link (or bind by name) to the interfaces of,
44
+ the Work and Derivative Works thereof.
45
+
46
+ "Contribution" shall mean any work of authorship, including
47
+ the original version of the Work and any modifications or additions
48
+ to that Work or Derivative Works thereof, that is intentionally
49
+ submitted to Licensor for inclusion in the Work by the copyright owner
50
+ or by an individual or Legal Entity authorized to submit on behalf of
51
+ the copyright owner. For the purposes of this definition, "submitted"
52
+ means any form of electronic, verbal, or written communication sent
53
+ to the Licensor or its representatives, including but not limited to
54
+ communication on electronic mailing lists, source code control systems,
55
+ and issue tracking systems that are managed by, or on behalf of, the
56
+ Licensor for the purpose of discussing and improving the Work, but
57
+ excluding communication that is conspicuously marked or otherwise
58
+ designated in writing by the copyright owner as "Not a Contribution."
59
+
60
+ "Contributor" shall mean Licensor and any individual or Legal Entity
61
+ on behalf of whom a Contribution has been received by Licensor and
62
+ subsequently incorporated within the Work.
63
+
64
+ 2. Grant of Copyright License. Subject to the terms and conditions of
65
+ this License, each Contributor hereby grants to You a perpetual,
66
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
67
+ copyright license to reproduce, prepare Derivative Works of,
68
+ publicly display, publicly perform, sublicense, and distribute the
69
+ Work and such Derivative Works in Source or Object form.
70
+
71
+ 3. Grant of Patent License. Subject to the terms and conditions of
72
+ this License, each Contributor hereby grants to You a perpetual,
73
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
74
+ (except as stated in this section) patent license to make, have made,
75
+ use, offer to sell, sell, import, and otherwise transfer the Work,
76
+ where such license applies only to those patent claims licensable
77
+ by such Contributor that are necessarily infringed by their
78
+ Contribution(s) alone or by combination of their Contribution(s)
79
+ with the Work to which such Contribution(s) was submitted. If You
80
+ institute patent litigation against any entity (including a
81
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
82
+ or a Contribution incorporated within the Work constitutes direct
83
+ or contributory patent infringement, then any patent licenses
84
+ granted to You under this License for that Work shall terminate
85
+ as of the date such litigation is filed.
86
+
87
+ 4. Redistribution. You may reproduce and distribute copies of the
88
+ Work or Derivative Works thereof in any medium, with or without
89
+ modifications, and in Source or Object form, provided that You
90
+ meet the following conditions:
91
+
92
+ (a) You must give any other recipients of the Work or
93
+ Derivative Works a copy of this License; and
94
+
95
+ (b) You must cause any modified files to carry prominent notices
96
+ stating that You changed the files; and
97
+
98
+ (c) You must retain, in the Source form of any Derivative Works
99
+ that You distribute, all copyright, patent, trademark, and
100
+ attribution notices from the Source form of the Work,
101
+ excluding those notices that do not pertain to any part of
102
+ the Derivative Works; and
103
+
104
+ (d) If the Work includes a "NOTICE" text file as part of its
105
+ distribution, then any Derivative Works that You distribute must
106
+ include a readable copy of the attribution notices contained
107
+ within such NOTICE file, excluding those notices that do not
108
+ pertain to any part of the Derivative Works, in at least one
109
+ of the following places: within a NOTICE text file distributed
110
+ as part of the Derivative Works; within the Source form or
111
+ documentation, if provided along with the Derivative Works; or,
112
+ within a display generated by the Derivative Works, if and
113
+ wherever such third-party notices normally appear. The contents
114
+ of the NOTICE file are for informational purposes only and
115
+ do not modify the License. You may add Your own attribution
116
+ notices within Derivative Works that You distribute, alongside
117
+ or as an addendum to the NOTICE text from the Work, provided
118
+ that such additional attribution notices cannot be construed
119
+ as modifying the License.
120
+
121
+ You may add Your own copyright statement to Your modifications and
122
+ may provide additional or different license terms and conditions
123
+ for use, reproduction, or distribution of Your modifications, or
124
+ for any such Derivative Works as a whole, provided Your use,
125
+ reproduction, and distribution of the Work otherwise complies with
126
+ the conditions stated in this License.
127
+
128
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
129
+ any Contribution intentionally submitted for inclusion in the Work
130
+ by You to the Licensor shall be under the terms and conditions of
131
+ this License, without any additional terms or conditions.
132
+ Notwithstanding the above, nothing herein shall supersede or modify
133
+ the terms of any separate license agreement you may have executed
134
+ with Licensor regarding such Contributions.
135
+
136
+ 6. Trademarks. This License does not grant permission to use the trade
137
+ names, trademarks, service marks, or product names of the Licensor,
138
+ except as required for reasonable and customary use in describing the
139
+ origin of the Work and reproducing the content of the NOTICE file.
140
+
141
+ 7. Disclaimer of Warranty. Unless required by applicable law or
142
+ agreed to in writing, Licensor provides the Work (and each
143
+ Contributor provides its Contributions) on an "AS IS" BASIS,
144
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
145
+ implied, including, without limitation, any warranties or conditions
146
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
147
+ PARTICULAR PURPOSE. You are solely responsible for determining the
148
+ appropriateness of using or redistributing the Work and assume any
149
+ risks associated with Your exercise of permissions under this License.
150
+
151
+ 8. Limitation of Liability. In no event and under no legal theory,
152
+ whether in tort (including negligence), contract, or otherwise,
153
+ unless required by applicable law (such as deliberate and grossly
154
+ negligent acts) or agreed to in writing, shall any Contributor be
155
+ liable to You for damages, including any direct, indirect, special,
156
+ incidental, or consequential damages of any character arising as a
157
+ result of this License or out of the use or inability to use the
158
+ Work (including but not limited to damages for loss of goodwill,
159
+ work stoppage, computer failure or malfunction, or any and all
160
+ other commercial damages or losses), even if such Contributor
161
+ has been advised of the possibility of such damages.
162
+
163
+ 9. Accepting Warranty or Additional Liability. While redistributing
164
+ the Work or Derivative Works thereof, You may choose to offer,
165
+ and charge a fee for, acceptance of support, warranty, indemnity,
166
+ or other liability obligations and/or rights consistent with this
167
+ License. However, in accepting such obligations, You may act only
168
+ on Your own behalf and on Your sole responsibility, not on behalf
169
+ of any other Contributor, and only if You agree to indemnify,
170
+ defend, and hold each Contributor harmless for any liability
171
+ incurred by, or claims asserted against, such Contributor by reason
172
+ of your accepting any such warranty or additional liability.
173
+
174
+ END OF TERMS AND CONDITIONS
175
+
176
+ APPENDIX: How to apply the Apache License to your work.
177
+
178
+ To apply the Apache License to your work, attach the following
179
+ boilerplate notice, with the fields enclosed by brackets "[]"
180
+ replaced with your own identifying information. (Don't include
181
+ the brackets!) The text should be enclosed in the appropriate
182
+ comment syntax for the file format. We also recommend that a
183
+ file or class name and description of purpose be included on the
184
+ same "printed page" as the copyright notice for easier
185
+ identification within third-party archives.
186
+
187
+ Copyright [yyyy] [name of copyright owner]
188
+
189
+ Licensed under the Apache License, Version 2.0 (the "License");
190
+ you may not use this file except in compliance with the License.
191
+ You may obtain a copy of the License at
192
+
193
+ http://www.apache.org/licenses/LICENSE-2.0
194
+
195
+ Unless required by applicable law or agreed to in writing, software
196
+ distributed under the License is distributed on an "AS IS" BASIS,
197
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
198
+ See the License for the specific language governing permissions and
199
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,160 @@
1
+ # TuneFrames — Agent-Native Music Generation
2
+
3
+ **Write music compositions in HTML. Render them to MP3 with one CLI command.**
4
+
5
+ TuneFrames brings the same portability model that Hyperframes (97K npm downloads/month) proved for video — to audio. Every AI agent, Claude Code session, and workflow tool can now compose music without a single line of native audio code.
6
+
7
+ ```bash
8
+ npx tuneframes init my-track
9
+ cd my-track && npx tuneframes render composition.html
10
+ # Done. my-track/output.mp3 is ready.
11
+ ```
12
+
13
+ ---
14
+
15
+ ## How It Works
16
+
17
+ 1. **Write HTML** with Tone.js — same API every web developer already knows
18
+ 2. **Add a metadata block** so TuneFrames knows the tempo and duration
19
+ 3. **Run `tuneframes render`** — Chromium headless renders the composition offline, FFmpeg encodes to MP3/WAV
20
+
21
+ ```html
22
+ <!DOCTYPE html>
23
+ <html>
24
+ <head>
25
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.8.49/Tone.js"></script>
26
+ </head>
27
+ <body>
28
+ <div id="tuneframes" style="display:none">{"bpm":120,"duration":"4n"}</div>
29
+ <script>
30
+ async function main() {
31
+ await Tone.start();
32
+ const synth = new Tone.Synth().toDestination();
33
+ synth.triggerAttackRelease('C4', '4n', 0);
34
+ synth.triggerAttackRelease('E4', '4n', Tone.Time('4n').toSeconds());
35
+ synth.triggerAttackRelease('G4', '4n', Tone.Time('4n').toSeconds() * 2);
36
+ }
37
+ </script>
38
+ </body>
39
+ </html>
40
+ ```
41
+
42
+ ---
43
+
44
+ ## Examples
45
+
46
+ | Example | Description | BPM | Duration |
47
+ |---------|-------------|-----|----------|
48
+ | `minimal` | Single synth melody — the simplest possible TuneFrames composition | 120 | 2s |
49
+ | `lofi` | Chord progression, melody, kick and snare — complete lo-fi hip-hop beat | 80 | 10s |
50
+ | `techno` | 4-on-the-floor kick, noise hihat, detuned bass, pad chords | 130 | 2s |
51
+ | `ambient` | Lush reverb pads, crystalline arpeggios — textural ambient | 60 | 2.5s |
52
+ | `orchestral` | Strings, brass, woodwinds in a layered orchestral arrangement | 72 | 2.5s |
53
+
54
+ Run any example:
55
+
56
+ ```bash
57
+ npx tuneframes render node_modules/tuneframes/examples/example-lofi.html
58
+ ```
59
+
60
+ ---
61
+
62
+ ## API Reference
63
+
64
+ ### Metadata Block
65
+
66
+ Add a `<div id="tuneframes">` to the page body to tell TuneFrames how to render:
67
+
68
+ ```json
69
+ {
70
+ "bpm": 120, // Beats per minute (default: 120)
71
+ "duration": "4n" // Render duration as Tone.js time (default: "4n")
72
+ }
73
+ ```
74
+
75
+ TuneFrames uses [Tone.js time notation](https://tonejs.github.io/docs/latest/modules/Core.html#Time) — `4n` (quarter note), `2n` (half note), `1n` (whole note), `8n` (eighth note), `16n` (sixteenth note), or any numeric value in seconds.
76
+
77
+ ### `main()` Function
78
+
79
+ Define an async `main()` function in a `<script>` tag. TuneFrames waits for it to complete, then renders the offline audio buffer.
80
+
81
+ ```js
82
+ async function main() {
83
+ await Tone.start();
84
+
85
+ const synth = new Tone.Synth().toDestination();
86
+ // Schedule all your notes, chords, and patterns here
87
+ synth.triggerAttackRelease('C4', '4n', 0);
88
+ // ...
89
+ }
90
+ ```
91
+
92
+ ### Instruments
93
+
94
+ Tone.js provides a complete instrument library:
95
+
96
+ - **Synth / MonoSynth / PolySynth** — basic tone generation
97
+ - **MembraneSynth** — kick drums, toms, bass drums
98
+ - **NoiseSynth** — white/pink/brown noise for hi-hats, snares, textures
99
+ - **MetalSynth** — metallic percussion (cymbals, shakers)
100
+ - **Sampler** — load your own WAV/MP3 samples
101
+
102
+ ### Effects
103
+
104
+ ```js
105
+ const reverb = new Tone.Reverb({ decay: 2.5, wet: 0.3 }).toDestination();
106
+ const comp = new Tone.Compressor(-12, 2).toDestination();
107
+ const delay = new Tone.FeedbackDelay('8n', 0.4).toDestination();
108
+ ```
109
+
110
+ ---
111
+
112
+ ## CLI
113
+
114
+ ```bash
115
+ # Render a composition to MP3
116
+ tuneframes render <file.html> [--output <out.mp3>]
117
+
118
+ # Render to WAV (no re-encoding)
119
+ tuneframes render <file.html> --format wav [--output <out.wav>]
120
+
121
+ # Preview in browser (dev mode with live reload)
122
+ tuneframes preview <file.html>
123
+
124
+ # Scaffold a new project
125
+ tuneframes init my-track
126
+ ```
127
+
128
+ ---
129
+
130
+ ## TuneFrames vs Hyperframes
131
+
132
+ TuneFrames is the audio sibling of [Hyperframes](https://github.com/cusidoc/hyperframes) — the same portability model, the same agent-first philosophy, but for music instead of video.
133
+
134
+ | | Hyperframes | TuneFrames |
135
+ |---|---|---|
136
+ | Output | MP4 video | MP3/WAV audio |
137
+ | Framework | Remotion (React) | Tone.js |
138
+ | Use case | Video generation, animation | Music composition, sound design |
139
+ | Deterministic | Yes | Yes |
140
+
141
+ ---
142
+
143
+ ## Architecture
144
+
145
+ ```
146
+ HTML + Tone.js → Chromium (headless, Tone.Offline)
147
+ → WAV ( PCM 44.1kHz mono )
148
+ → FFmpeg
149
+ → MP3 192kbps
150
+ ```
151
+
152
+ **Tone.Offline** is the key: it renders audio without audio hardware or a browser audio context, producing bit-for-bit identical output every time. Same input HTML = same output MP3, guaranteed.
153
+
154
+ ---
155
+
156
+ ## License
157
+
158
+ Apache 2.0 — use it in any project, commercial or open-source, no strings attached.
159
+
160
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
@@ -0,0 +1,63 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>TuneFrames — Ambient</title>
5
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.8.49/Tone.js"></script>
6
+ </head>
7
+ <body>
8
+ <div id="tuneframes" style="display:none">{"bpm":60,"duration":"1m"}</div>
9
+ <script>
10
+ async function main() {
11
+ await Tone.start();
12
+
13
+ const verb = new Tone.Reverb({ decay: 8, wet: 0.8 }).toDestination();
14
+ const delay = new Tone.PingPongDelay('4n', 0.3).toDestination();
15
+
16
+ // Warm pad
17
+ const pad = new Tone.PolySynth(Tone.Synth, {
18
+ oscillator: { type: 'sine' },
19
+ envelope: { attack: 3, decay: 1, sustain: 0.8, release: 4 }
20
+ }).connect(verb);
21
+ pad.volume.value = -8;
22
+
23
+ // Crystal high texture
24
+ const crystal = new Tone.PolySynth(Tone.Synth, {
25
+ oscillator: { type: 'sine' },
26
+ envelope: { attack: 4, decay: 0.5, sustain: 1, release: 3 }
27
+ }).connect(delay);
28
+ crystal.volume.value = -18;
29
+
30
+ // D minor progression — hypnotic and spacious
31
+ const chords = [
32
+ ['D3', 'F3', 'A3'], // Dm
33
+ ['C3', 'E3', 'G3'], // C
34
+ ['Bb2', 'D3', 'F3'], // Bb
35
+ ['A2', 'C3', 'E3'], // Am
36
+ ];
37
+
38
+ const beat = Tone.Time('1n').toSeconds();
39
+
40
+ chords.forEach((chord, i) => {
41
+ pad.triggerAttackRelease(chord, '1n', i * beat);
42
+ // Add crystal shimmer an octave up, delayed
43
+ crystal.triggerAttackRelease(
44
+ chord.map(n => {
45
+ const octave = parseInt(n.match(/\d/)[0]);
46
+ return n.replace(/\d/, octave + 1);
47
+ }),
48
+ '2n', i * beat + 0.05
49
+ );
50
+ });
51
+
52
+ // Slow bass drone
53
+ const drone = new Tone.MonoSynth({
54
+ oscillator: { type: 'sine' },
55
+ envelope: { attack: 2, decay: 0, sustain: 1, release: 3 }
56
+ }).toDestination();
57
+ drone.volume.value = -20;
58
+ drone.triggerAttackRelease('D1', '1n', 0);
59
+ drone.triggerAttackRelease('D1', '1n', beat * 2);
60
+ }
61
+ </script>
62
+ </body>
63
+ </html>
@@ -0,0 +1,45 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>TuneFrames — Lofi Example</title>
5
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.8.49/Tone.js"></script>
6
+ </head>
7
+ <body>
8
+ <div id="tuneframes" style="display:none">{"bpm":80,"duration":"1m"}</div>
9
+ <script>
10
+ async function main() {
11
+ await Tone.start();
12
+
13
+ const reverb = new Tone.Reverb({ decay: 4, wet: 0.6 }).toDestination();
14
+ const pad = new Tone.PolySynth(Tone.Synth, {
15
+ oscillator: { type: 'triangle' },
16
+ envelope: { attack: 0.5, decay: 0.3, sustain: 0.8, release: 2 }
17
+ }).connect(reverb);
18
+
19
+ // Am - F - C - G chord progression
20
+ const chords = [
21
+ ['A3', 'C4', 'E4'],
22
+ ['F3', 'A3', 'C4'],
23
+ ['C3', 'E3', 'G3'],
24
+ ['G3', 'B3', 'D4'],
25
+ ];
26
+
27
+ // Play each chord for 2 beats at 80 BPM
28
+ for (let i = 0; i < chords.length; i++) {
29
+ pad.triggerAttackRelease(chords[i], '2n', i * Tone.Time('2n').toSeconds());
30
+ }
31
+
32
+ // Simple melody
33
+ const melody = new Tone.Synth({
34
+ oscillator: { type: 'sine' },
35
+ envelope: { attack: 0.01, decay: 0.1, sustain: 0.3, release: 0.5 }
36
+ }).toDestination();
37
+
38
+ melody.triggerAttackRelease('C5', '8n', Tone.Time('2n').toSeconds() * 0.5);
39
+ melody.triggerAttackRelease('E5', '8n', Tone.Time('2n').toSeconds() * 1.5);
40
+ melody.triggerAttackRelease('G5', '8n', Tone.Time('2n').toSeconds() * 2.5);
41
+ melody.triggerAttackRelease('C5', '4n', Tone.Time('2n').toSeconds() * 3.5);
42
+ }
43
+ </script>
44
+ </body>
45
+ </html>
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>TuneFrames — Minimal Test</title>
5
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.8.49/Tone.js"></script>
6
+ </head>
7
+ <body>
8
+ <script>
9
+ // This must be a named async function for the renderer to call
10
+ async function main() {
11
+ // BPM set in #tuneframes metadata
12
+ await Tone.start();
13
+ const synth = new Tone.Synth().toDestination();
14
+ // Explicitly schedule at transport time 0
15
+ synth.triggerAttackRelease('C4', '4n', 0);
16
+ }
17
+ </script>
18
+ </body>
19
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>TuneFrames — Orchestral</title>
5
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.8.49/Tone.js"></script>
6
+ </head>
7
+ <body>
8
+ <div id="tuneframes" style="display:none">{"bpm":72,"duration":"1m"}</div>
9
+ <script>
10
+ async function main() {
11
+ await Tone.start();
12
+
13
+ const verb = new Tone.Reverb({ decay: 6, wet: 0.5 }).toDestination();
14
+
15
+ // Strings section
16
+ const strings = new Tone.PolySynth(Tone.Synth, {
17
+ oscillator: { type: 'sawtooth' },
18
+ envelope: { attack: 1.5, decay: 0.3, sustain: 0.9, release: 3 }
19
+ }).connect(verb);
20
+ strings.volume.value = -12;
21
+
22
+ // Brass
23
+ const brass = new Tone.PolySynth(Tone.Synth, {
24
+ oscillator: { type: 'sawtooth' },
25
+ envelope: { attack: 0.3, decay: 0.2, sustain: 0.7, release: 1.5 }
26
+ }).connect(verb);
27
+ brass.volume.value = -10;
28
+
29
+ // Timpani
30
+ const timpani = new Tone.MembraneSynth({
31
+ pitchDecay: 0.05,
32
+ octaves: 4,
33
+ oscillator: { type: 'sine' },
34
+ envelope: { attack: 0.001, decay: 1, sustain: 0, release: 2 }
35
+ }).toDestination();
36
+ timpani.volume.value = -8;
37
+
38
+ const beat = Tone.Time('1n').toSeconds();
39
+
40
+ // Strings: swell on every bar
41
+ const stringChords = [
42
+ ['D3', 'F3', 'A3', 'C4'], // Dm7
43
+ ['C3', 'E3', 'G3', 'B3'], // Cmaj7
44
+ ['Bb2', 'D3', 'F3', 'A3'], // Bbmaj7
45
+ ['A2', 'C3', 'E3', 'G3'], // Am7
46
+ ];
47
+ stringChords.forEach((chord, i) => {
48
+ strings.triggerAttackRelease(chord, '1n', i * beat);
49
+ });
50
+
51
+ // Brass: enters on bar 3 with fanfare
52
+ const fanfares = [
53
+ ['D4', 'F4', 'A4'],
54
+ ['C4', 'E4', 'G4'],
55
+ ];
56
+ fanfares.forEach((chord, i) => {
57
+ brass.triggerAttackRelease(chord, '2n', (i + 2) * beat);
58
+ });
59
+
60
+ // Timpani: tonic hits on bars 1 and 3
61
+ timpani.triggerAttackRelease('D2', '1n', 0);
62
+ timpani.triggerAttackRelease('D2', '1n', beat * 2);
63
+ timpani.triggerAttackRelease('A1', '2n', beat * 3.5);
64
+ }
65
+ </script>
66
+ </body>
67
+ </html>
@@ -0,0 +1,69 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>TuneFrames - Techno</title>
5
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.8.49/Tone.js"></script>
6
+ </head>
7
+ <body>
8
+ <div id="tuneframes" style="display:none">{"bpm":130,"duration":"2n"}</div>
9
+ <script>
10
+ async function main() {
11
+ await Tone.start();
12
+ const beat = Tone.Time('4n').toSeconds();
13
+
14
+ const comp = new Tone.Compressor(-18, 5).toDestination();
15
+ const verb = new Tone.Reverb({ decay: 1, wet: 0.3 }).toDestination();
16
+
17
+ // Kick - 4-on-the-floor
18
+ const kick = new Tone.MembraneSynth({
19
+ pitchDecay: 0.05, octaves: 6,
20
+ oscillator: { type: 'sine' },
21
+ envelope: { attack: 0.001, decay: 0.3, sustain: 0, release: 0.1 }
22
+ }).connect(comp);
23
+
24
+ // Hi-hat: NoiseSynth (white noise + filter envelope)
25
+ const hihat = new Tone.NoiseSynth({
26
+ noise: { type: 'white' },
27
+ envelope: { attack: 0.001, decay: 0.03, sustain: 0, release: 0.01 }
28
+ }).toDestination();
29
+ hihat.volume.value = -10;
30
+
31
+ // Bass: detuned saws
32
+ const bass = new Tone.MonoSynth({
33
+ oscillator: { type: 'sawtooth' },
34
+ filter: { Q: 3, type: 'lowpass', rolloff: -24 },
35
+ envelope: { attack: 0.005, decay: 0.15, sustain: 0.5, release: 0.1 },
36
+ filterEnvelope: { attack: 0.001, decay: 0.1, sustain: 0.3, release: 0.2, baseFrequency: 80, octaves: 4 }
37
+ }).connect(comp);
38
+
39
+ // Pad: parallel saw chords
40
+ const pad = new Tone.PolySynth(Tone.Synth, {
41
+ oscillator: { type: 'sawtooth' },
42
+ envelope: { attack: 0.2, decay: 0.4, sustain: 0.7, release: 0.8 }
43
+ }).connect(verb);
44
+ pad.volume.value = -14;
45
+
46
+ // Kick: 4-on-the-floor every beat
47
+ for (let i = 0; i < 8; i++) {
48
+ kick.triggerAttackRelease('C1', '8n', i * beat);
49
+ }
50
+
51
+ // Hi-hat: offbeat 16ths (16 events)
52
+ for (let i = 0; i < 16; i++) {
53
+ hihat.triggerAttackRelease('16n', (i + 0.5) * beat * 0.5);
54
+ }
55
+
56
+ // Bass: syncopated
57
+ const bassPat = ['E1', 'E1', null, 'G1', 'A1', null, 'B1', 'A1', 'G1', null, 'E1', 'E1'];
58
+ bassPat.forEach((note, i) => {
59
+ if (note) bass.triggerAttackRelease(note, '8n', i * beat * 0.5);
60
+ });
61
+
62
+ // Pad: slow chord stabs
63
+ pad.triggerAttackRelease(['E2', 'G2', 'B2'], '2n', 0);
64
+ pad.triggerAttackRelease(['C2', 'E2', 'G2'], '2n', beat * 4);
65
+ pad.triggerAttackRelease(['D2', 'F2', 'A2'], '2n', beat * 6);
66
+ }
67
+ </script>
68
+ </body>
69
+ </html>
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "tuneframes",
3
+ "version": "0.1.0",
4
+ "description": "Write HTML with Tone.js. Render music to MP3/WAV with one CLI command. Built for AI agents.",
5
+ "repository": "github:cusidoc/tuneframes",
6
+ "homepage": "https://github.com/cusidoc/tuneframes#readme",
7
+ "author": "Nick Shepherd <nick@moltos.org>",
8
+ "main": "src/cli.js",
9
+ "bin": {
10
+ "tuneframes": "src/cli.js"
11
+ },
12
+ "scripts": {
13
+ "render": "node src/render.js",
14
+ "test": "node src/cli.js render examples/example-minimal.html"
15
+ },
16
+ "keywords": ["music", "tone.js", "agent", "hyperframes", "ai"],
17
+ "license": "Apache-2.0",
18
+ "dependencies": {
19
+ "playwright": "^1.40.0"
20
+ },
21
+ "engines": {
22
+ "node": ">=18"
23
+ }
24
+ }
package/src/cli.js ADDED
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * TuneFrames CLI
4
+ *
5
+ * Commands:
6
+ * tuneframes render <file.html> [--output track.mp3]
7
+ * tuneframes init <project-name>
8
+ * tuneframes preview <file.html>
9
+ */
10
+
11
+ const { render } = require('./render');
12
+ const fs = require('fs');
13
+ const path = require('path');
14
+ const { spawn } = require('child_process');
15
+
16
+ async function main() {
17
+ const [,, cmd, ...args] = process.argv;
18
+
19
+ switch (cmd) {
20
+ case 'render': {
21
+ const inputFile = args[0];
22
+ const outputArg = args.find(a => a.startsWith('--output='));
23
+ const outputFile = outputArg
24
+ ? outputArg.split('=')[1]
25
+ : inputFile.replace(/\.html$/, '.mp3');
26
+
27
+ if (!inputFile) {
28
+ console.error('Usage: tuneframes render <file.html> [--output=track.mp3]');
29
+ process.exit(1);
30
+ }
31
+
32
+ if (!fs.existsSync(inputFile)) {
33
+ console.error(`File not found: ${inputFile}`);
34
+ process.exit(1);
35
+ }
36
+
37
+ console.log(`Rendering ${inputFile} → ${outputFile}`);
38
+ const result = await render(inputFile, outputFile);
39
+ console.log(`Done. Output: ${result.output}`);
40
+ break;
41
+ }
42
+
43
+ case 'init': {
44
+ const [projectName] = args;
45
+ if (!projectName) {
46
+ console.error('Usage: tuneframes init <project-name>');
47
+ process.exit(1);
48
+ }
49
+
50
+ const dir = path.join(process.cwd(), projectName);
51
+ fs.mkdirSync(dir, { recursive: true });
52
+
53
+ const example = fs.readFileSync(
54
+ path.join(__dirname, '../examples/example-lofi.html'), 'utf8'
55
+ );
56
+ fs.writeFileSync(path.join(dir, 'composition.html'), example);
57
+ fs.writeFileSync(path.join(dir, 'README.md'),
58
+ `# ${projectName}\n\nRun: tuneframes render composition.html\n`);
59
+
60
+ console.log(`Initialized ${projectName}/`);
61
+ break;
62
+ }
63
+
64
+ case 'preview': {
65
+ const inputFile = args[0];
66
+ if (!inputFile) {
67
+ console.error('Usage: tuneframes preview <file.html>');
68
+ process.exit(1);
69
+ }
70
+ // Open in default browser (or just tell user where the file is)
71
+ const url = `file://${path.resolve(inputFile)}`;
72
+ console.log(`Preview: ${url}`);
73
+ if (process.platform === 'darwin') {
74
+ spawn('open', [url]);
75
+ } else if (process.platform === 'linux') {
76
+ spawn('xdg-open', [url]);
77
+ }
78
+ break;
79
+ }
80
+
81
+ default:
82
+ console.log(`TuneFrames CLI\n\nCommands:\n tuneframes render <file.html> Render composition to MP3\n tuneframes init <name> Initialize new project\n tuneframes preview <file.html> Open in browser`);
83
+ }
84
+ }
85
+
86
+ main().catch(err => {
87
+ console.error('Error:', err.message);
88
+ process.exit(1);
89
+ });
package/src/render.js ADDED
@@ -0,0 +1,138 @@
1
+ const { chromium } = require('playwright');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const { spawn } = require('child_process');
5
+
6
+ const HELPER_SCRIPT = `
7
+ (function() {
8
+ if (window._helpersInjected) return;
9
+ window._helpersInjected = true;
10
+
11
+ function audioBufferToWav(buffer) {
12
+ const nc = buffer.numberOfChannels, sr = buffer.sampleRate;
13
+ const bitDepth = 16, bps = bitDepth / 8, blockAlign = nc * bps;
14
+ const ns = buffer.length, dataSize = ns * blockAlign;
15
+ const total = 44 + dataSize;
16
+ const wav = new ArrayBuffer(total);
17
+ const view = new DataView(wav);
18
+ const ws = (v, o, s) => { for (let i = 0; i < s.length; i++) v.setUint8(o + i, s.charCodeAt(i)); };
19
+ ws(view, 0, 'RIFF'); view.setUint32(4, total - 8, true);
20
+ ws(view, 8, 'WAVE'); ws(view, 12, 'fmt ');
21
+ view.setUint32(16, 16, true); view.setUint16(20, 1, true);
22
+ view.setUint16(22, nc, true); view.setUint32(24, sr, true);
23
+ view.setUint32(28, sr * blockAlign, true);
24
+ view.setUint16(32, blockAlign, true); view.setUint16(34, bitDepth, true);
25
+ ws(view, 36, 'data'); view.setUint32(40, dataSize, true);
26
+ const ch = []; for (let c = 0; c < nc; c++) ch.push(buffer.getChannelData(c));
27
+ let off = 44;
28
+ for (let i = 0; i < ns; i++) {
29
+ for (let c = 0; c < nc; c++) {
30
+ const s = Math.max(-1, Math.min(1, ch[c][i]));
31
+ view.setInt16(off, s < 0 ? s * 0x8000 : s * 0x7fff, true);
32
+ off += 2;
33
+ }
34
+ }
35
+ return wav;
36
+ }
37
+
38
+ window.audioBufferToWav = audioBufferToWav;
39
+
40
+ window.renderComposition = async function(wavPath) {
41
+ // Wait for Tone.js to be ready
42
+ let attempts = 0;
43
+ while (typeof Tone === 'undefined' && attempts < 50) {
44
+ await new Promise(r => setTimeout(r, 100));
45
+ attempts++;
46
+ }
47
+ if (typeof Tone === 'undefined') throw new Error('Tone not loaded');
48
+ if (typeof window.audioBufferToWav !== 'function') throw new Error('audioBufferToWav not injected');
49
+
50
+ let bpm = 120, duration = '4n';
51
+ const metaEl = document.getElementById('tuneframes');
52
+ if (metaEl) {
53
+ try {
54
+ const meta = JSON.parse(metaEl.textContent);
55
+ bpm = meta.bpm || 120;
56
+ duration = meta.duration || '4n';
57
+ } catch(e) {}
58
+ }
59
+
60
+ const durationSec = Math.max(Tone.Time(duration).toSeconds() + 0.5, 2);
61
+ console.log('TuneFrames: rendering', durationSec, 's at BPM', bpm);
62
+
63
+ const audioBuffer = await Tone.Offline(async () => {
64
+ if (typeof main === 'function') await main();
65
+ }, durationSec, 1, 44100, bpm);
66
+
67
+ console.log('TuneFrames: buffer ready', audioBuffer.duration, audioBuffer.length);
68
+
69
+ const wavBuf = audioBufferToWav(audioBuffer);
70
+ console.log('TuneFrames: wav size', wavBuf.byteLength);
71
+
72
+ window.writeFile(wavPath, Array.from(new Uint8Array(wavBuf)));
73
+ console.log('TuneFrames: file written');
74
+ return wavBuf.byteLength;
75
+ };
76
+ })();
77
+ `;
78
+
79
+ async function render(compositionPath, outputPath, format = 'mp3') {
80
+ const browser = await chromium.launch({ headless: true });
81
+ const page = await browser.newPage();
82
+
83
+ page.on('pageerror', err => console.error('BROWSER ERR:', err.message));
84
+ page.on('console', msg => console.log('BROWSER:', msg.type(), msg.text()));
85
+
86
+ // Inject writeFile bridge BEFORE page load
87
+ await page.exposeFunction('writeFile', (filePath, arrayBuffer) => {
88
+ fs.writeFileSync(filePath, Buffer.from(new Uint8Array(arrayBuffer)));
89
+ console.log('Node writeFile: wrote', arrayBuffer.length, 'bytes to', filePath);
90
+ });
91
+
92
+ // Inject helper scripts as an inline script tag before anything else loads
93
+ await page.addInitScript({ content: HELPER_SCRIPT });
94
+
95
+ await page.goto(`file://${path.resolve(compositionPath)}`, {
96
+ waitUntil: 'domcontentloaded', timeout: 30000
97
+ });
98
+
99
+ // Wait for Tone.js to actually be available
100
+ await page.waitForFunction(() => typeof Tone !== 'undefined', { timeout: 15000 });
101
+
102
+ // Also wait for our renderComposition to be defined
103
+ await page.waitForFunction(() => typeof window.renderComposition === 'function', { timeout: 15000 });
104
+
105
+ const wavPath = path.resolve(outputPath.replace(/\.[^.]+$/, '.wav'));
106
+
107
+ console.log('Starting render...');
108
+ const wavSize = await page.evaluate(async (wavPath) => {
109
+ return await window.renderComposition(wavPath);
110
+ }, wavPath);
111
+
112
+ console.log('Render complete, WAV size:', wavSize);
113
+ await browser.close();
114
+
115
+ if (!fs.existsSync(wavPath)) throw new Error(`WAV not written: ${wavPath}`);
116
+ const stats = fs.statSync(wavPath);
117
+ if (stats.size < 1000) throw new Error(`WAV too small: ${stats.size} bytes`);
118
+ console.log(`WAV on disk: ${stats.size} bytes`);
119
+
120
+ if (format === 'mp3') {
121
+ await new Promise((resolve, reject) => {
122
+ const ff = spawn('ffmpeg', [
123
+ '-y', '-hide_banner', '-loglevel', 'error',
124
+ '-i', wavPath, '-codec:a', 'libmp3lame', '-qscale:a', '2', outputPath
125
+ ]);
126
+ ff.on('close', code => {
127
+ if (code === 0) { fs.unlinkSync(wavPath); resolve(); }
128
+ else reject(new Error(`FFmpeg exited ${code}`));
129
+ });
130
+ ff.on('error', reject);
131
+ });
132
+ console.log(`MP3: ${fs.statSync(outputPath).size} bytes`);
133
+ }
134
+
135
+ return { output: outputPath };
136
+ }
137
+
138
+ module.exports = { render };