Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions js/__tests__/logo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ global.Synth = jest.fn().mockImplementation(() => ({
get isAvailable() {
return typeof global.Tone !== "undefined" && !!global.Tone.Transport;
},
get state() {
if (this.isAvailable) return global.Tone.Transport.state;
return "stopped";
},
get isClockRunning() {
return this.isAvailable;
},
start() {
if (this.isAvailable) global.Tone.Transport.start();
},
Expand Down Expand Up @@ -157,6 +164,9 @@ function makeSynth() {
get isAvailable() {
return false;
},
get isClockRunning() {
return false;
},
cancel: jest.fn(),
get seconds() {
return 0;
Expand Down Expand Up @@ -1001,6 +1011,9 @@ describe("Logo doStopTurtles", () => {
get isAvailable() {
return typeof global.Tone !== "undefined" && !!global.Tone.Transport;
},
get isClockRunning() {
return this.isAvailable;
},
cancel() {
if (
this.isAvailable &&
Expand Down Expand Up @@ -1284,9 +1297,15 @@ describe("Logo runFromBlock", () => {
});
global.Tone = {
...savedTone,
context: {
get state() {
return "running";
}
},
Transport: {
start: jest.fn(),
stop: jest.fn(),
state: "started",
schedule: scheduleSpy,
cancel: jest.fn(),
getSecondsAtTime: getSecondsAtTimeMock,
Expand Down
7 changes: 6 additions & 1 deletion js/logo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1695,9 +1695,14 @@ class Logo {
logo.turtleDelay === 0 &&
delay > 0 &&
logo.synth.transport.isAvailable &&
logo.synth.transport.state === "started" &&
logo.synth.transport.isClockRunning &&
tur._transportTime !== null
) {
const transportTime = tur._transportTime + delay / 1000;
const transportTime = Math.max(
tur._transportTime + delay / 1000,
logo.synth.transport.seconds
);
tur.delayParameters = { blk: blk, flow: isflow, arg: receivedArg };
tur._transportEventId = logo.synth.transport.schedule(audioContextTime => {
const tur2 = logo.activity.turtles.ithTurtle(turtle);
Expand Down
10 changes: 10 additions & 0 deletions js/utils/synthutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,16 @@ const transport = {
get isAvailable() {
return typeof Tone !== "undefined" && Tone.Transport;
},
get state() {
if (this.isAvailable) return Tone.Transport.state;
return "stopped";
},
get isClockRunning() {
if (this.isAvailable && typeof Tone !== "undefined" && Tone.context) {
return Tone.context.state === "running";
}
return false;
},
start() {
if (this.isAvailable) Tone.Transport.start();
},
Expand Down
Loading