Tone.js is a comprehensive Web Audio framework designed for creating interactive music directly within the browser. It provides high-level abstractions over the Web Audio API, offering a wide array of instruments (like Synths, Samplers), effects (Reverb, Delay), and advanced signal processing tools for dynamic audio manipulation. Currently stable at version 15.1.22, the library has seen consistent development, including a significant transition to TypeScript in its 14.7.x series, enhancing type safety and developer experience. Its release cadence is moderate, with major updates introducing new features and improvements, while also addressing breaking changes through version increments. Key differentiators include its robust scheduling system (`Tone.Transport`), extensive collection of DSP modules, and focus on real-time interactive performance, making it a popular choice for web-based musical applications and installations.
npm install toneVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes Tone.js, creates a basic synthesizer, and schedules a short melody to play upon user interaction, demonstrating fundamental setup and event scheduling.
Use `Tone.connect(srcNode, destNode, [outputNum], [inputNum])` to connect native Web Audio nodes with Tone.js nodes. Ensure both nodes share the same AudioContext, which can be set using `Tone.setContext(audioContext)`.
Migrate time expressions to object notation or compose them using arithmetic. For example, instead of `Tone.Time('4n * 2 + 3t')`, use `Time('4n') * 2 + Time('3t')` or `{'4n': 1, '8t': 2}` for durations.Always call `await Tone.start();` (or `await start();` with named imports) inside an event listener (e.g., `click`, `keydown`) before attempting to play any audio.
Replace all instances of `Tone.Master` with `Tone.Destination` (or `Destination` when using named imports). Ensure your instruments are routed to `Destination`.
For JavaScript projects, ensure your bundler (e.g., Webpack, Rollup) is configured to handle ESM and potentially TypeScript outputs. For TypeScript projects, ensure `tsconfig.json` is correctly set up for module resolution (e.g., `"moduleResolution": "bundler"` or `"node"`).
Use the `Tone.connect()` helper function for connecting native Web Audio nodes with Tone.js nodes: `Tone.connect(nativeNode, toneNode);`.
Switch to ES Module import syntax: `import * as Tone from 'tone';` or `import { Synth } from 'tone';`. Ensure your `package.json` specifies `"type": "module"` if it's an ESM-only project.Update time expressions to use object notation or compose them arithmetically. For simple cases, `Tone.Time('4n')` would convert, or use `{ '4n': 1 }` directly as a duration parameter if the API accepts it.Wrap your `Tone.start()` call in a user-triggered event listener, such as a click handler: `document.getElementById('playButton').addEventListener('click', async () => { await Tone.start(); /* ... your audio code ... */ });`.No dependency data recorded yet.