Tone Sequence Test

Callback called multiple times after second time.

by dirkk0

HTML

<script src="https://unpkg.com/[email protected]/build/Tone.js"></script>
<button class="play">
  Play
</button>

JavaScript

const notes = ['C4', 'E4', 'G4'];
const time = '16n';

const synth = new Tone.Synth().toMaster();

document.querySelector('.play').addEventListener('click', () => play(notes, time))

const seq = new Tone.Sequence((sequenceTime, note) => {
  console.log('note, seqTime', note, sequenceTime);
  synth.triggerAttackRelease(note, time);
}, notes, time);

function play(notes, time) {


  console.log('------------------------');

  seq.humanize = true;
  seq.loop = 0;
  Tone.Transport.loop = false;
  Tone.Transport.stop();
  Tone.Transport.start();

  seq.start().stop(Tone.Time(time) * notes.length);
}