Merge branch 'dev' into typescript

This commit is contained in:
Yotam Mann 2019-07-15 09:46:22 -04:00
commit ada1423bd4
6 changed files with 137 additions and 9 deletions

View file

@ -4,7 +4,7 @@ If you're looking for ideas for where to get started, consider jumping in on any
### Examples
To contribute examples, please follow the current style of the examples. Add your example's title and file name to `ExampleList.js` file for it to appear in the examples list on the index page.
To contribute examples, please follow the current style of the examples. Add your example's title and file name to `examples/js/ExampleList.json` for it to appear in the examples list on the index page.
### Docs
@ -32,4 +32,4 @@ You can also take a look at Tone.js' [code coverage](https://coveralls.io/github
### Synths/Effects
If you'd like to contribute a cool and expressive synth or effect, i'd love to hear it. Please send me an example that i can play with along with the PR.
If you'd like to contribute a cool and expressive synth or effect, i'd love to hear it. Please send me an example that i can play with along with the PR.

View file

@ -146,7 +146,7 @@ Tone.Event.prototype._rescheduleEvents = function(after){
Tone.Transport.clear(event.id);
}
var startTick = event.time + Math.round(this.startOffset / this._playbackRate);
if (this._loop){
if (this._loop === true || Tone.isNumber(this._loop) && this._loop > 1){
duration = Infinity;
if (Tone.isNumber(this._loop)){
duration = (this._loop) * this._getLoopDuration();
@ -321,9 +321,12 @@ Tone.Event.prototype._getLoopDuration = function(){
/**
* If the note should loop or not
* between Tone.Event.loopStart and
* Tone.Event.loopEnd. An integer
* value corresponds to the number of
* loops the Event does after it starts.
* Tone.Event.loopEnd. If set to true,
* the event will loop indefinitely,
* if set to a number greater than 1
* it will play a specific number of
* times, if set to false, 0 or 1, the
* part will only play once.
* @memberOf Tone.Event#
* @type {Boolean|Positive}
* @name loop

View file

@ -405,9 +405,12 @@ Object.defineProperty(Tone.Part.prototype, "humanize", {
/**
* If the part should loop or not
* between Tone.Part.loopStart and
* Tone.Part.loopEnd. An integer
* value corresponds to the number of
* loops the Part does after it starts.
* Tone.Part.loopEnd. If set to true,
* the part will loop indefinitely,
* if set to a number greater than 1
* it will play a specific number of
* times, if set to false, 0 or 1, the
* part will only play once.
* @memberOf Tone.Part#
* @type {Boolean|Positive}
* @name loop

23
examples/README.md Normal file
View file

@ -0,0 +1,23 @@
These examples use web components (e.g. `<tone-example>`) which are defined in the [Tonejs/ui](https://github.com/Tonejs/ui) repository.
### Running examples locally
Check out the repository, and from the root run:
```
$ npm install
...
$ npm run build
```
Once this is done, you can start a local server with Python:
```
$ python -m SimpleHTTPServer 8000
```
Then, from a browser visit http://localhost:8000/examples. (See also: [installation instructions on the wiki](https://github.com/Tonejs/Tone.js/wiki/Installation#newbie-macos-quickstart-to-get-examples-running))
### Adding examples
To contribute examples, please follow the current style of the examples. Add your example's title and file name to `js/ExampleList.json` file for it to appear in the examples list on the index page. (cf. [CONTRIBUTING.md](https://github.com/Tonejs/Tone.js/blob/dev/.github/CONTRIBUTING.md))

View file

@ -306,6 +306,54 @@ describe("Event", function(){
});
});
it("plays once when loop is 1", function(){
var callCount = 0;
return Offline(function(Transport){
new Event({
"loopEnd" : 0.125,
"loop" : 1,
"callback" : function(){
callCount++;
}
}).start(0);
Transport.start();
}, 0.8).then(function(){
expect(callCount).to.equal(1);
});
});
it("plays once when loop is 0", function(){
var callCount = 0;
return Offline(function(Transport){
new Event({
"loopEnd" : 0.125,
"loop" : 0,
"callback" : function(){
callCount++;
}
}).start(0);
Transport.start();
}, 0.8).then(function(){
expect(callCount).to.equal(1);
});
});
it("plays once when loop is false", function(){
var callCount = 0;
return Offline(function(Transport){
new Event({
"loopEnd" : 0.125,
"loop" : false,
"callback" : function(){
callCount++;
}
}).start(0);
Transport.start();
}, 0.8).then(function(){
expect(callCount).to.equal(1);
});
});
it("can be started and stopped multiple times", function(){
return Offline(function(Transport){
var eventTimes = [0.3, 0.4, 0.9, 1.0, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9];

View file

@ -562,6 +562,57 @@ describe("Part", function(){
});
});
it("plays once when loop is 1", function(){
var callCount = 0;
return Offline(function(Transport){
new Part({
"loopEnd" : 0.125,
"loop" : 1,
"callback" : function(){
callCount++;
},
"events" : [0, 0.1]
}).start(0.1);
Transport.start();
}, 0.8).then(function(){
expect(callCount).to.equal(2);
});
});
it("plays once when loop is 0", function(){
var callCount = 0;
return Offline(function(Transport){
new Part({
"loopEnd" : 0.125,
"loop" : 0,
"callback" : function(){
callCount++;
},
"events" : [0, 0.1]
}).start(0.1);
Transport.start();
}, 0.8).then(function(){
expect(callCount).to.equal(2);
});
});
it("plays once when loop is false", function(){
var callCount = 0;
return Offline(function(Transport){
new Part({
"loopEnd" : 0.125,
"loop" : false,
"callback" : function(){
callCount++;
},
"events" : [0, 0.1]
}).start(0.1);
Transport.start();
}, 0.8).then(function(){
expect(callCount).to.equal(2);
});
});
it("can loop between loopStart and loopEnd", function(){
var invoked = false;
return Offline(function(Transport){