JSFiddle - React, Tailwind, and code Playground

by yotammann

HTML

<script src="https://unpkg.com/tone@next"></script>
<p>
This demo shows how sometimes a Tone.Sequence skips the first note.
</p>
<p>
Expected behavior: clicking start should play C5 first.
</p>
<p>
Instead: sometimes C5 is skipped, and the next note is played.
</p>
<button>
  start
</button>
<p>Notes played:
</p>
<pre></pre>

JavaScript

Tone.Transport.start()

const synth = new Tone.Synth().toMaster()
const pre = document.querySelector('pre')

const seq = new Tone.Sequence((time, note) => {
  pre.innerText += ' ' + note
	synth.triggerAttackRelease(note, '8n', time)
}, ['C5', 'C4', 'C3', 'C2'], '4n')

document.querySelector('button').addEventListener('click', e => {
  if (e.target.innerText === 'start') {
  	seq.start()
    e.target.innerText = 'stop'
    pre.innerText = ''
  } else {
  	seq.stop()
	  e.target.innerText = 'start'
  }
})