Hi again, if you want to check our code, everything is in this Github depot, feel free to use any piece of code there: https://github.com/leolefebvre/GMTK-2019 (the code is a bit dirty-but-it-works because of Game Jam).
The specific piece of code that handles the sound and the queue is here : https://github.com/leolefebvre/GMTK-2019/blob/master/GTMK-2019-UnityProject/Assets/Script/Managers/SoundManager.cs
To answer your questions: the queue doesn't wait for the song compass. it just wait 0.05 seconds before launching the next sound in the queue and your brain is just playing :)
I was planning on doing something that waits for the song compass, but because it was a game jam I decided to go for the easy solution and it was enough to do the trick ^^
More detail on the implementation:
- When a sound arrives, the manager checks if the sound source is open (I just used a Boolean as a gate).
- If the sound source is open, it plays the sound right away, closes the game (Boolean set to false), and launch a coroutine that will handle the next sound source opening (more on that later). If the sound source is closed, the sound is added to the queue.
- The coroutine waits for a fixed time (here it's 0.05 seconds), then there is a piece of code that check if there is something in the queue. If there is, it plays the first sound in the queue, then remove it and launch the coroutine again. If the queue is empty it opens the gate.
Finally after testing we added some details:
- There is a maximum count in the queue (if a sound arrives and the queue is full, it is ignored). before you could stack a lot of sounds in the queue if you just kept selecting and de-selecting super fast. Problems were that sounds could go on for a long time (that was weird but still funny), and I was afraid that someone could overload the memory with it since the queue was getting bigger and bigger
- The keys to play were stored in a list. The manager chooses the key to play based on the number of pieces selected (at the time a piece is selected). When the number of key is higher than the number of key in the list, I added a piece of code to repeat the last two keys.
A trivia about the last one: The first version was just repeating everything from the start (it was just a modulo that you can still see commented ^^). It did not sound good so I added the code explain before.
This code actually allows to repeat the next x key (but only ascending, I didn't took the time to write an equation so that it makes "waves", as in up and down). So we played with it a little bit (what if we play the last 3 keys? only the last 1 key?) and then settled on the last 2 keys.
It was quite fascinating to try those different effects and see what would work best, and it can take quite a while to make it make it right (we had to choose fast because Game Jam).
I hope I answered all your questions, and I am sure you can find resources online to help you find what you need!