-
Notifications
You must be signed in to change notification settings - Fork 996
Installation
Tone.js can be used like any other script or library by dropping the into the
of your page. A global calledTone
will be added to the window
.
<script type="text/javascript" src="path/to/Tone.js"></script>
or from the Tone's CDN:
<script type="text/javascript" src="http://cdn.tonejs.org/latest/Tone.min.js"></script>
Note: it's always safer to use a specific version rather than "latest"
Internally, Tone uses AMD for dependency management. But the build process adds a UMD footer to the built file which makes it compatible with both AMD and CommonJS.
You can include the build file (which is available from one of the links above) like any other dependency using either AMD or CommonJS style:
require(["Tone"], function(Tone){
var synth = new Tone.MonoSynth();
//...etc
or with CommonJS:
var MonoSynth = require("Tone").MonoSynth;
var synth = new MonoSynth();
Using individual files with a module loader can bring your package size down significantly since it will only include the modules used in your code. You'll have to familiarize yourself with Tone.js' directory structure since files have to be referenced with their full path.
To use the individual files, you'll need a require
framework which supports AMD like RequireJS, webpack, or deAMDify for browserify.
The path to the root Tone folder needs to be in the search path so that internal dependencies can resolve.
require.config({
baseUrl: "./base",
paths: {
"Tone" : "path/to/Tone.js/Tone"
}
});
require(["Tone/core/Transport"], function(Transport){
//...
module.exports = {
resolve: {
root: __dirname,
modulesDirectories : ["path/to/Tone.js/"],
},
//...
footer