I am a newbie. Say I have a song that is 3:00 minutes in length. Every x number seconds I would like to have a different pattern execute. I want to determine when the pattern change takes place based on a change in the musical phrasing, chorus, etc. The LED patterns vary in length for example from 2 - 10 seconds before they repeat/loop. For example I would like the “sparkfire” pattern to keep looping for 12-seconds after which “Plasma 3D” would execute for 8-seconds followed by “sinus” for 15-seconds.
You’re pretty much there. Create one pattern and put all your patterns within it, then use a chain of IF statements to determine which one to use based on the timing.
Looks like you are all on the right track, I just want to give a heads up that the maximum value that can be stored in the 16.16 variables is ± 32767. The same is true for literal numbers as well.
If you accumulate milliseconds from the delta in beforeRender you’ll only get up to about 32 seconds before it wraps. It’s super precise for animations, but for timekeeping you might want to convert to another unit, like seconds, which would give you about 9 hours of time before it wraps.
Using minutes would still give you pretty good resolution since variables hold fractional values, and would take 22 days before wrapping. Here’s some code that counts in minutes and updates every second:
export var minutes
export var milliseconds
export function beforeRender(delta) {
milliseconds += delta;
if (milliseconds >= 1000) {
milliseconds -= 1000
minutes += 1/60
}
}