Continuous music

I had a same thought as Nick for putting musicoverlap before he posted, but continuing the level without the music input will not play a song when you want to continue the game where you left off. For example, when you put musicoverlap 1 in the level set as Nicky said, you start with stage 1-1 which has music in it and you want it to continue playing without repeating the same song in another stage like stage 1-2. In stage 1-2, you don't use music file for playing because you want it to continue, but unfortunately, when you continue to where you left off by going to Load Game, no music is playing. That could be the problem. I just wish there was something that can continue playing music after loading the continuation.
 
Thank you NickyP and maxman. Now, taking into account the issue that maxman presents, I ask: is it possible to prevent OpenBOR from saving/loading specific levels?
 
To avoid loading a level and not having any background music.

Let me explain. Say level 1 is comprised of level 1-1 and level 1-2. Level 1 has a song playing in the background. Once players complete level 1-1, they start level 1-2. By using "music overlap", we prevent the music from stopping at the end of level 1-1, and allow it to continue into 1-2 (and that way create the feeling that you're still playing in the same stage).
However, by using this method, if players were to die or stop playing in level 1-2, when they load their game, they'll find that now level 1-2 has no music.
One way to prevent this is, I think, to set the game so that it doesn't save progress in sub-levels.
So if someone were to die in level 3-4, when they load their game, he/she would start at level 3-1.
 
Yo, @mersox! You should check out @Kratus's latest version of his Streets of Rage 2X mod if you wanna make the continuous music going for your levels. That is what you want and I was listening to music starting from the beginning of SOR2 stage 3 to its sub stages. As you finish stage 3-1, the music continues and the game loads for SOR2 stage 3-2, so the music is not starting all over again in the beginning at all. It keeps continuing in stage 3-2 and on since the very first level (e.g. SOR2 stage 3-1). I quit game and return to load game to listen to music again for hearing if there's music, and yes there is. It seems that the music part has to be done with script so you don't need to put music in a level txt.
 
Last edited:
@maxman , i will have to check this out. There are some other threads that meniton somtheing along the lines that a music stream can be paused & the position where it was can be "saved"
problem with this is that if your game crashes, the music "bookmark" wont be saved
so the next best thing is to have a script that goes like this:

if current stage music equals none (nothing is playing) then start playing music xxx.ogg from position xxx loop value yyyy
if music playing equals level4.ogg, then do nothing
 
@maxman , i will have to check this out. There are some other threads that meniton somtheing along the lines that a music stream can be paused & the position where it was can be "saved"
problem with this is that if your game crashes, the music "bookmark" wont be saved
so the next best thing is to have a script that goes like this:

if current stage music equals none (nothing is playing) then start playing music xxx.ogg from position xxx loop value yyyy
if music playing equals level4.ogg, then do nothing
I don't know if it can help, but I have a few scripts examples that may work.

This code will play a defined music and will save it in a global variable to be used by all other scripts.
C:
void musicPlay(void music, int loop)
{//Play defined music
    void mStyle = getglobalvar("musicStyle");
    void folder;
  
    //GET CURRENT MUSIC STYLE
    if(mStyle == "custom"){folder = "Musics/";}else{folder = "Data/music/"+mStyle+"/";}

    //SET LOOP TO ZERO IF NULL
    if(loop == NULL()){loop = 0;}

    //PLAY MUSIC
    playmusic(folder+music, loop);
    setglobalvar("musicPlaying", music);
}

This other code will get the save music variable and will "replay" it.
C:
void musicReplay()
{//Replay the current music if the style is changed in-game
    void music = getglobalvar("musicPlaying");
  
    if(music != NULL()){
        if(openborvariant("in_level")){musicPlay(music, 1);}
    }
}

I have other scripts to manage music in levels, but they are bigger than these two. I can post it later if the current codes don't work for you.
I didn't develop a code to detect and save the music offset, but I will post as soon as I create it. If I'm not wrong, there's no native function to detect the current music offset in real time.


@maxman
Yes, all the scripts related to musics are in the path "data/scripts/levelspawn". Don't forget to start the "musicStopped" variable with the flag 1, currently I'm starting it on the updated.c file.
 
Last edited:
@Kratus How about declaring an offset for playmusic? Would it be like this?

Code:
void musicPlay(void music, int loop, float offset)
{//Play defined music
    void mStyle = getglobalvar("musicStyle");
    void folder;
 
    //GET CURRENT MUSIC STYLE
    if(mStyle == "custom"){folder = "Musics/";}else{folder = "Data/music/"+mStyle+"/";}

    //SET LOOP TO ZERO IF NULL
    if(loop == NULL()){loop = 0;}

    //PLAY MUSIC
    playmusic(folder+music, loop, offset);
    setglobalvar("musicPlaying", music);

}

I might be wrong about it since I don't know where it could be declared with or without globalvar for looping to certain part instead of going back to the very beginning.
 
@Kratus How about declaring an offset for playmusic? Would it be like this?

Code:
void musicPlay(void music, int loop, float offset)
{//Play defined music
    void mStyle = getglobalvar("musicStyle");
    void folder;
 
    //GET CURRENT MUSIC STYLE
    if(mStyle == "custom"){folder = "Musics/";}else{folder = "Data/music/"+mStyle+"/";}

    //SET LOOP TO ZERO IF NULL
    if(loop == NULL()){loop = 0;}

    //PLAY MUSIC
    playmusic(folder+music, loop, offset);
    setglobalvar("musicPlaying", music);

}

I might be wrong about it since I don't know where it could be declared with or without globalvar for looping to certain part instead of going back to the very beginning.
@maxman

Yeah, the way you declared is correct, according to the manual. However, according to some tests I did, the offset will work only from the first loop and so on, but will not work on the first time the music is played.

In addition, to detect the offset you can use some sound editors, like Sound Forge. The "offset" is counted in "samples" and for a 44.100hz music, every 1 second is the same as 44.100 samples.

EDIT: You can also use custom "sample" values, to make the "loop" more accurate according to the music played.

Sem título.png

Sem título2.png

Sem título3.png
 
Back
Top Bottom