A rough explanation on what the slide page is doing
Code: Select all
//Generate a difficulty between 1 and 3//random number between 1 and 3var difficulty = Number(comonFunctions.getRandom("(1..3)"));//do something based on the difficultyswitch(difficulty){ case 1: //put stuff for difficulty 1 here break; case 2: //put stuff for difficulty 2 here break; default: //put stuff for any other difficulty here //in this case we should only ever get here if difficulty was 3 //if we changed difficulty to (1..4) we would come here for 3 or 4}
Code: Select all
//straight BPM set loops to zero and rhythm to ""//this would give a steady bpm of between 20 and 60 beats per minutecase 1: overRide.image = "slow/*.*"; overRide.html = "Keep following the beat" var Metro = comonFunctions.getRandom("(20..60)"); jscriptLog("Metro " + Metro); overRide.setMetronome(Metro, "4", "0", ""); break;
Explanation of Rhythm
the 4 inputs are
1) BPM: (60 = 1 per second, 30 = 1 per 2 seconds, 120 = 2 per second)
2) beats: (number of "sub" beats)
60,4 would give a sub beat every 0.25 seconds (30,8 and 120,2 would give the same)
3) Loops: number of times to loop (1 would loop once i.e. play it twice)
4) Rhythm: a list of sub beats to trigger a sound
so if we do overRide.setMetronome("60", "4", "0", rhythm)
this gives us a base speed of 60 with 4 sub beats, so a sub beat every 0.25 seconds
to do 10 beats at 1 per second we can do any of the following
1) "1,5,9,13,17,21,25,29,33,36"
2) "2,6,10,14,18,22,26,30,34,37"
3) "3,7,11,15,19,23,27,31,35,38"
4) "4,8,12,16,20,24,28,32,36,39"
if we do overRide.setMetronome("30", "4", "0", rhythm)
this gives us a base speed of 30 with 4 sub beats, so a sub beat every 0.5 seconds
we can still generate the same rhythm with
"1,3,5,7,9,11,13,15,17,19"
To generate a more useful rhythm let's say 5 slow beats (1 per 3 seconds) then 20 faster (2 per second), 6 times
For overRide.setMetronome("60", "4", "5", rhythm)
For the first 5 we need 1 per 12 sub beats ("1,13,25,37,49")
For the next 20 we need 1 per 2 sub beats ("51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89")
so overRide.setMetronome("60", "4", "5", "1,13,25,37,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89")
would generate our desired rhythm
If we get two beats close together when it loops, we can offset the start of the sequence so starting 5,17 would force a 4 sub beat pause (1 second) between loops
This has kind of evolved whilst I was coding it rather than by design
. So if anyone wants to come up with a friendlier way of setting the rhythm I am open to suggestions.