Hello!
How to change the current music pattern, while maintaining tempo?
In my game, I have my music looping pattern 0,1,2. When an enemy enters the map, I would like the pattern 4 to play, without loosing tempo. Ideally, the pattern change would happen on bar.
I have succeeded using function stat(407) to read the last track of my pattern and detect the beats. However, when I call music(4) inside _update() to switch the current music, the transition happens too late, and I hear shortly the beginning of the next bar of the current music, and then first note of the new music. In short, when stat(407) returns 1, it is too late to schedule a music change.
I would need a hook or callback in the music sync code to peek the timing, and post the music change exactly at the right moment to have smooth transitions. How to do that?
Thanks!
Maybe you could move the check one note earlier and then set a timer for just under the duration of the note?
OK, I got a bit closer. By querying which row and tick are the current, I am able to detect I am near the end of a row, and schedule a music change just in time.
row = stat(400 + 0, 9) -- channel row
tick = stat(400 + 0, 10) -- channel row tick
is_transition_time = (row % 8 == 7 and tick >= 21)
however, since the music sync is at ~1/120s and update rate is only 1/60s, I can't get the exact resolution needed.
Also, it seems the music loop is not in sync with the _update calls. My music is a speed 24, and the last tick I can query inside _update is sometime 21, sometime 22, sometime 23. Not quite predictable.
I would need a mecanism or hook inside the music loop.
[Please log in to post a comment]