mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 08:38:00 +00:00
get/set the progress in seconds
This commit is contained in:
parent
e8178581c0
commit
682ec0e46e
2 changed files with 40 additions and 0 deletions
|
@ -542,6 +542,23 @@ function(Tone){
|
|||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* The Transport's position in seconds
|
||||
* Setting the value will jump to that position right away.
|
||||
* @memberOf Tone.Transport#
|
||||
* @type {Seconds}
|
||||
* @name seconds
|
||||
*/
|
||||
Object.defineProperty(Tone.Transport.prototype, "seconds", {
|
||||
get : function(){
|
||||
return Tone.TransportTime(this.ticks, "i").toSeconds();
|
||||
},
|
||||
set : function(progress){
|
||||
var ticks = this.toTicks(progress);
|
||||
this.ticks = ticks;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* The Transport's loop position as a normalized value. Always
|
||||
* returns 0 if the transport if loop is not true.
|
||||
|
|
|
@ -158,6 +158,29 @@ function (Test, Transport, Tone, Offline, TransportTime) {
|
|||
}, 0.1);
|
||||
});
|
||||
|
||||
it("can get the current position in seconds", function(done){
|
||||
Offline(function(dest, test, after){
|
||||
expect(Tone.Transport.seconds).to.equal(0);
|
||||
Tone.Transport.start();
|
||||
test(function(sample, time){
|
||||
expect(Tone.Transport.seconds).to.be.closeTo(time, 0.05);
|
||||
});
|
||||
after(function(){
|
||||
expect(Tone.Transport.seconds).to.be.closeTo(0.8, 0.05);
|
||||
Tone.Transport.stop();
|
||||
done();
|
||||
});
|
||||
}, 0.8);
|
||||
});
|
||||
|
||||
it("can set the current position in seconds", function(){
|
||||
expect(Tone.Transport.seconds).to.equal(0);
|
||||
Tone.Transport.seconds = 3;
|
||||
expect(Tone.Transport.seconds).to.be.closeTo(3, 0.05);
|
||||
Tone.Transport.seconds = 0;
|
||||
expect(Tone.Transport.seconds).to.equal(0);
|
||||
});
|
||||
|
||||
it("can set the current position in BarsBeatsSixteenths", function(){
|
||||
expect(Tone.Transport.position).to.equal("0:0:0");
|
||||
Tone.Transport.position = "3:0";
|
||||
|
|
Loading…
Reference in a new issue