mirror of
https://github.com/Tonejs/Tone.js
synced 2025-01-14 04:43:54 +00:00
testing synced player source
This commit is contained in:
parent
f28c4b4a84
commit
9f5ed8ef2e
2 changed files with 20 additions and 1 deletions
|
@ -244,6 +244,25 @@ describe("Source", () => {
|
|||
}, 0.6);
|
||||
});
|
||||
|
||||
it("can schedule multiple starts", () => {
|
||||
return Offline(({ transport }) => {
|
||||
const buff = ToneAudioBuffer.fromArray(new Float32Array(1024).map(v => 1));
|
||||
const source = new Player(buff);
|
||||
source.sync().start(0.1).start(0.3);
|
||||
transport.start(0);
|
||||
expect(source.state).to.equal("stopped");
|
||||
|
||||
return [
|
||||
atTime(0.11, () => {
|
||||
expect(source.state).to.equal("started");
|
||||
}),
|
||||
atTime(0.31, () => {
|
||||
expect(source.state).to.equal("started");
|
||||
}),
|
||||
];
|
||||
}, 0.6);
|
||||
});
|
||||
|
||||
it("has correct offset when the transport is started with an offset", () => {
|
||||
return Offline(({ transport }) => {
|
||||
const source = new Oscillator();
|
||||
|
|
|
@ -185,7 +185,7 @@ export abstract class Source<Options extends SourceOptions> extends ToneAudioNod
|
|||
let computedTime = isUndef(time) && this._synced ? this.context.transport.seconds : this.toSeconds(time);
|
||||
computedTime = this._clampToCurrentTime(computedTime);
|
||||
// if it's started, stop it and restart it
|
||||
if (this._state.getValueAtTime(computedTime) === "started") {
|
||||
if (!this._synced && this._state.getValueAtTime(computedTime) === "started") {
|
||||
// time should be strictly greater than the previous start time
|
||||
assert(GT(computedTime, (this._state.get(computedTime) as StateTimelineEvent).time), "Start time must be strictly greater than previous start time");
|
||||
this._state.cancel(computedTime);
|
||||
|
|
Loading…
Reference in a new issue