Is anybody here adept at using Transport with the Tone.js library?
I have a table of melodies - each one has a play button. Using the Transport, I can have a melody play ONCE, but afterwards NONE of the melodies play. I've tried using Tone.Transport.cancel() after the last note, and that doesn't seem to do anything. I have code that doesn't use the Transport which works fine, but I had to refactor using the Transport because I want to use Tone.Draw since it coordinates DOM manipulation with the Audio Context. Here's the problematic function. Thanks in advance!
async function playMelody(melody) {
await Tone.start()
console.log("audio is ready")
Tone.Transport.bpm.value = 120;
Tone.Transport.schedule((time) => {
let t = time
for (let i = 0; i < melody.length; i++) {
let note = melody[i]
if (note[0] !== "rest") {
if (i == melody.length - 1) {
synth.triggerAttackRelease(note[0], Tone.Time(note[1]) - 0.1, t)
Tone.Transport.clear()
console.log("Transport cancelled")
} else {
synth.triggerAttackRelease(note[0], Tone.Time(note[1]) - 0.1, t)
}
}
t += Tone.Time(note[1])
}
}, 0)
Tone.Transport.start()
}
question from:
https://stackoverflow.com/questions/65648850/tone-transport-doesnt-work-on-subsequent-calls-to-function-tone-js 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…