Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tone.js Error: 'Start time must be strictly greater than previous start time'

I am having a hard time understanding why I am getting thrown this error:

Debug.ts:8 Uncaught Error: Start time must be strictly greater than previous start time

The weird part is that it only throws me this error about 4/5 times I refresh the page. There is a 1/5 chance roughly that it will work with no problem. Here is my code:

let synth = new Tone.MetalSynth({
  portamento: 0,
  volume: -15,
  envelope: {
    attack: 0.001,
    decay: 1.4,
    release: 1,
  },
  harmonicity: 18.1,
  modulationIndex: 12,
  resonance: 1000,
  octaves: 1.5,
});

synth.chain(Tone.Destination);

let notes = ['A2', 'B2', 'C3', 'D3', 'E3', 'F3', 'G#3'];
let html = '';
for (let i = 0; i < notes.length; i++) {
  html += `<div class="whitenote" onmouseover="noteDown(this)" data-note="${notes[i]}"></div>`;
}

document.querySelector('.container-4').innerHTML = html;

function noteDown(el) {
  let note = el.dataset.note;
  synth.triggerAttackRelease(note, '16n');
}
like image 344
charlieyin Avatar asked Sep 19 '20 17:09

charlieyin


1 Answers

I also had the same issue. You have to add the time to it.

This worked for me:

const synth = new Tone.Synth().toDestination();
        
melody.forEach(tune => {
      const now = Tone.now()
      synth.triggerAttackRelease(tune.note, tune.duration, now + tune.timing)
})

and my data (melody) looks like that:

[{ note: "E5", duration: "8n", timing: 0 },
{ note: "D#5", duration: "8n", timing: 0.25 },
{ note: "E5", duration: "8n", timing: 0.5 },
{ note: "D#5", duration: "8n", timing: 0.75 },
{ note: "E5", duration: "8n", timing: 1 },
{ note: "B4", duration: "8n", timing: 1.25 }]
like image 157
s1gr1d Avatar answered Nov 08 '22 00:11

s1gr1d