Tonejs / Tone.js

A Web Audio framework for making interactive music in the browser.
https://tonejs.github.io
MIT License
13.45k stars 977 forks source link

schedule events with Tone.Transport.position #1171

Closed cristianofigo closed 1 year ago

cristianofigo commented 1 year ago

Hello, i'm Trying to schedule some events with Tone.Transport.position and it works, but with some mistakes. My sample code:

clock_global = Tone.Transport.position;
console.log(clock_global);
if (clock_global > "0:0" && clock_global < "1:0") {
   console.log("compasso 1");
 }
if (clock_global > "3:0" && clock_global < "6:0") {
   console.log("compasso 2");
     }
if (clock_global > "10:0" && clock_global < "12:0") {
   console.log("compasso 3");
    }

The problem is that after "clock_global" crosses "40:0:0" it starts to trigger "compasso 2" in the console, i'm missing something here. My live example is in: https://github.com/cristianofigo/MusicaMovel_waveform_template Thank you!

dirkk0 commented 1 year ago

because you are comparing strings like numbers.

cristianofigo commented 1 year ago

Thanks @dirkk0, i've managed to transform the string in a array and choose only the bars that i wanted like this:

clock_global = Tone.Transport.position;
myArray = clock_global.split(":");
let bar = myArray[0];

if (bar > 0 && bar < 1 ) {
   console.log("compasso 1");
 }
if (bar > 3 && bar < 6) {
   console.log("compasso 2");
     }
if (bar > 10 && bar < 12) {
   console.log("compasso 3");
    }