Forum

How to make music loop differently depending on a variable?

12 January 2016 15:23
I would like to create a game level in which the background music's melody is different depending on which area of the map the player is in. Instead of transitioning suddenly I would like to cue up the next melody to be triggered using a variable, so that when a certain measure of music has been reached it will start the melody for that zone of the map.

Before trying to build the level, first I want to test this concept with a simple switch system of four cubes. When cube #1 is clicked it will cue up melody pattern #1, when cube #2 is clicked it will cue up melody pattern #2, etc… I have prepared four melody patterns as separate audio loops, and a drum pattern to go in sync with them that will not change.

I have started setting this up in the Logic Editor, using a Switch Select node and four Variable Store nodes. What I'm not sure about is how to call the stored variable and have it determine which audio sample will be used. Also I need to somehow create a delay that is the length of one bar of music in time, so that it triggers the next sample at the transition between bars.

Here's a screen shot of my Logic Editor node setup so far. Please help.

12 January 2016 15:58
I have started setting this up in the Logic Editor, using a Switch Select node and four Variable Store nodes. What I'm not sure about is how to call the stored variable and have it determine which audio sample will be used.

Hello!

For this purpose you can use "Conditional Jump" node to sequentially check variable value.
Blend4Web Team - developer
Twitter
LinkedIn
12 January 2016 16:20

Also I need to somehow create a delay that is the length of one bar of music in time, so that it triggers the next sample at the transition between bars.

If I correctly understand your question:
You can set separate sequences of "Play Sound" nodes with "Do Now Wait" set to False for each value of your stored variable to play samples one after another.
Blend4Web Team - developer
Twitter
LinkedIn
12 January 2016 17:35
Thank you for your explanation and example node setup! That helps a lot.

As for getting the samples to play one after another, I'm guessing something will have to come next after the Play Sound nodes to get the engine to check the variable again and find out which loop to play next. This is just a guess, I need to experiment with it.

To better explain what I want to do, here is a screen shot of what the loops look like in Ableton Live:

The green arrows indicate that the drum loop (left), and the first melody loop (right), are playing. If pattern #2 (in yellow) gets clicked the melody will switch to pattern #2 when the next bar begins.
I want to cue loops in a similar way, by interacting with objects in the .blend.
13 January 2016 12:55
Looks like the logic editor is in great demand so far. Can't wait to see your game finished.
The Founder | Twitter | Facebook | Linkedin
13 January 2016 12:58

As for getting the samples to play one after another, I'm guessing something will have to come next after the Play Sound nodes to get the engine to check the variable again and find out which loop to play next.

I thought about your question and it seems to me that it is impossible (or veeeeeery tricky) to solve this task only with logic nodes without JavaScript coding due to the asynchronous nature of the problem.

Your project ideas are really interesting, good luck with them!

P.S. We are working hard on improving and adding new functionality to our logic node editor so I hope soon your task may be done smoothly and easily. Stay tune for updates
Blend4Web Team - developer
Twitter
LinkedIn
16 January 2016 19:12
@Yuri Thank you! I can't wait to see my game started, haha. I'm still experimenting in the learning stages.
But yes, the Logic Editor is a great help, because I don't have much experience with javascript, but I am very comfortable with Blender's node system.

@Konstantin Thanks! It will be so cool if this can be done easily in the future! Also, it would be useful if we could have synced loops that can be made to fade in or fade out according to the player's proximity to an empty… if I can slip in that feature request. ;-)
 
Please register or log in to leave a reply.