Estoy trabajando en un secuenciador de pasos en Tone.js Enlace aquí: https://glitch.com/edit/#!/sustaining-lunar-chard Todo funciona bien, pero parece que no puedo entender por qué el tiempo esta apagado. La primera nota se dispara bien si hace clic en la primera columna, pero después de hacer clic en varias notas, parece salirse de control.
Código relacionado para activar audio:
// Here is where we actually play the audio function onSequenceStep(time, column) { // We build up a list of notes, which will equal // the numRows. This gets passed into our PolySynth let notesToPlay = []; // console.log(column) // output the current column // Go through each row data.forEach((row, rowIndex) => { // See if the note is "on" const isOn = row[column] == 1; // If its on, add it to the list of notes to play if (isOn) { const note = notes[rowIndex]; notesToPlay.push(note); } }); // Trigger a note const velocity = random(0.5, 1); synth.triggerAttackRelease(notesToPlay, noteInterval, time, velocity); Tone.Draw.schedule(function() { currentColumn = column; }, time); } // Code to assist in conversion of shapesList data into format of data array function splitArrayIntoChunksOfLen(arr, len) { var chunks = [], i = 0, n = arr.length; while (i < n) { chunks.push(arr.slice(i, i += len)); } return chunks; } function inputSequencerData() { /* 1. Get shapesList active data into same format as data array ✅ 2. Set value of data array to array of shapesList active data ✅ */ // console.log(data); let shapesListSplit = splitArrayIntoChunksOfLen(shapesList, 16); for (let i = 0; i < shapesListSplit.length; i++) { // console.log(shapesListSplit[i]); // Log all rows of values // Loop over each shapesListSplit[i] and check if shapes are active for (let j = 0; j < shapesListSplit[i].length; j++) { if (shapesListSplit[i][j].active == true) { data[i][j] = 1; } else { data[i][j] = 0; } } } }Este es el código de audio que se activa en la función dibujar().
// Clear canvas and redraw for (let i = 0; i < shapesList.length; i++) { shapesList[i].show(); inputSequencerData(); }Se basa en este ejemplo: https://glitch.com/edit/#!/tone-example-sequencer?path=sketch.js%3A223%3A27
¿Alguien sabe qué puede estar pasando aquí? Cualquier ayuda sería muy apreciada