mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 08:38:00 +00:00
trying out new defaults
API
This commit is contained in:
parent
a53357c505
commit
aea6c80f09
2 changed files with 25 additions and 7 deletions
|
@ -47,7 +47,8 @@ define(["Tone/core/Tone", "Tone/core/Emitter", "Tone/type/Type"], function(Tone)
|
|||
*/
|
||||
Tone.Buffer = function(){
|
||||
|
||||
var options = this.optionsObject(arguments, ["url", "onload", "onerror"], Tone.Buffer.defaults);
|
||||
Tone.call(this);
|
||||
var options = this.defaults(arguments, ["url", "onload", "onerror"]);
|
||||
|
||||
/**
|
||||
* stores the loaded AudioBuffer
|
||||
|
@ -158,7 +159,7 @@ define(["Tone/core/Tone", "Tone/core/Emitter", "Tone/type/Type"], function(Tone)
|
|||
* @returns {Tone.Buffer} this
|
||||
*/
|
||||
Tone.Buffer.prototype.dispose = function(){
|
||||
Tone.Emitter.prototype.dispose.call(this);
|
||||
Tone.prototype.dispose.call(this);
|
||||
this._buffer = null;
|
||||
if (this._xhr){
|
||||
Tone.Buffer._currentDownloads--;
|
||||
|
|
|
@ -23,7 +23,14 @@ define(["Tone/core/Tone", "Tone/core/Buffer"], function (Tone) {
|
|||
* });
|
||||
*
|
||||
*/
|
||||
Tone.Buffers = function(urls, onload, baseUrl){
|
||||
Tone.Buffers = function(urls){
|
||||
|
||||
//remove the urls from the options
|
||||
if (arguments.length === 1 && !arguments[0].hasOwnProperty("urls")){
|
||||
urls = { "urls" : urls };
|
||||
}
|
||||
Tone.apply(this, arguments);
|
||||
var options = this.defaults(arguments, ["urls", "onload", "baseUrl"]);
|
||||
|
||||
/**
|
||||
* All of the buffers
|
||||
|
@ -36,19 +43,28 @@ define(["Tone/core/Tone", "Tone/core/Buffer"], function (Tone) {
|
|||
* A path which is prefixed before every url.
|
||||
* @type {String}
|
||||
*/
|
||||
this.baseUrl = this.defaultArg(baseUrl, "");
|
||||
this.baseUrl = options.baseUrl;
|
||||
|
||||
urls = this._flattenUrls(urls);
|
||||
options.urls = this._flattenUrls(options.urls);
|
||||
this._loadingCount = 0;
|
||||
//add each one
|
||||
for (var key in urls){
|
||||
for (var key in options.urls){
|
||||
this._loadingCount++;
|
||||
this.add(key, urls[key], this._bufferLoaded.bind(this, onload));
|
||||
this.add(key, options.urls[key], this._bufferLoaded.bind(this, options.onload));
|
||||
}
|
||||
};
|
||||
|
||||
Tone.extend(Tone.Buffers);
|
||||
|
||||
/**
|
||||
* Defaults
|
||||
* @type {Object}
|
||||
*/
|
||||
Tone.Buffers.defaults = {
|
||||
"onload" : Tone.noOp,
|
||||
"baseUrl" : ""
|
||||
};
|
||||
|
||||
/**
|
||||
* True if the buffers object has a buffer by that name.
|
||||
* @param {String|Number} name The key or index of the
|
||||
|
@ -157,6 +173,7 @@ define(["Tone/core/Tone", "Tone/core/Buffer"], function (Tone) {
|
|||
* @return {Tone.Buffers} this
|
||||
*/
|
||||
Tone.Buffers.prototype.dispose = function(){
|
||||
Tone.prototype.dispose.call(this);
|
||||
for (var name in this._buffers){
|
||||
this._buffers[name].dispose();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue