Metronome Programmatically
Posted: Mon Jun 22, 2020 12:09 pm
Hello All!
I've ran into a minor crossroads I need help with.
The tease I'm making is super-interactive and variable dependent and I would like to make a metronome function to make my life easier and the tease better. It could look something like this:
It's kind of a napkin code, I just made it up right now, what I had trouble with is playing the sound multiple times. I haven't tested the algorithm above. And sorry for my terrible javaScript. Any ideas how it could work or why it won't? I really don't want to use longer metronome sequences because it would be a pain in the ass to make them each time dependent on variables.
Thanks for each and every reply!
I've ran into a minor crossroads I need help with.
The tease I'm making is super-interactive and variable dependent and I would like to make a metronome function to make my life easier and the tease better. It could look something like this:
Code: Select all
function metronome(bmp,timeInSeconds=undefined,strokeCount=undefined,first,second,third,fourth,fifth,sixth,seventh,eighth)
{
var beep=Sound.get("metronomeSound"); //from a cached audio
var timeStart=DateTime.now();
var count=0;
if(timeInSeconds!=undefined)
{
while(timeStart+1000*timeInSeconds>DateTime.now())
{
if(first)
{
beep.play();
}
wait(1000*(60/bmp)); //if bmp is sixty waits a second
if(second)
{
beep.play();
}
wait(1000*(60/bmp));
if(third)
{
beep.play();
}
wait(1000*(60/bmp));
if(fourth)
{
beep.play();
}
wait(1000*(60/bmp));
if(fifth)
{
beep.play();
}
wait(1000*(60/bmp));
if(sixth)
{
beep.play();
}
wait(1000*(60/bmp));
if(seventh)
{
beep.play();
}
wait(1000*(60/bmp));
if(eighth)
{
beep.play();
}
wait(1000*(60/bmp));
}
}
else
{
while(count<strokeCount)
{
if(first)
{
beep.play();
count++;
}
wait(1000*(60/bmp));
if(second)
{
beep.play();
count++;
}
wait(1000*(60/bmp));
if(third)
{
beep.play();
count++;
}
wait(1000*(60/bmp));
if(fourth)
{
beep.play();
count++;
}
wait(1000*(60/bmp));
if(fifth)
{
beep.play();
count++;
}
wait(1000*(60/bmp));
if(sixth)
{
beep.play();
count++;
}
wait(1000*(60/bmp));
if(seventh)
{
beep.play();
count++;
}
wait(1000*(60/bmp));
if(eighth)
{
beep.play();
count++;
}
wait(1000*(60/bmp));
}
}
}
Thanks for each and every reply!