"Resume" Music Script Help

Aerisetta

Active member
TLDR: I want stage BGM (background music) to be playing, a cutscene to play with different music (or a webm) and when the game resumes, the BGM resumes.
1. Ideal solution - Game can remember what music was playing as BGM, pause it, let other music play, then play the BGM again (even better if it resumes at the point it was paused.
2. Realistic (?) solution - a @cmd I can add to an animation to play stage music as defined in the stage txt file (music data/music/bgm.ogg)

I remember reading somewhere that "resuming" music after switching to another track is currently not available in the engine because the engine does not store what music was playing before.

I know how to script for playing a track if I had the path, but I want it to be the music as defined by the stage txt instead of giving a path since the cutscene I make may be triggered on different stages with different BGM.

Any help will be appreciated.

edit here is video showing the problem, the cutscene bgm continues to play after game resumes

 
Last edited:
@Aerisetta

even tho the engine might not be able to store the music, i think that it would be possible for the engine to take a record of the music's offset position before you make it stop

it would be a script where first you tell the engine to "see" where the current track is - interms of the offset - take the value, do the cutscene, and afer the cutscene, play the music NOT from the start , but from the offset value.. - but this idea seems more likely to Fit a scenario where you might want to continue the music when re-loading a stage after dying

another option is to see if there is a command to Just pause the music and after the cutscene just resume it

from the manual

pausemusic(toggle)


  • toggle: 1 or 0. 1 to pause music
playmusic(name, loop, offset)

  • Pauses the music abruptly. technically, it toggles the variable 'sound_pause_music', commonly used for the pause menu to stop the music while the pause menu is present.
 
Last edited:
Also, i have not tested, but have you tried making the music of the cutscene BE a sound (like a punch sound) instead of music? it might work if Openbor has no limit on what can you use as "sound"
(i am assuming this cutscene is an entity in the middle of a stage) like in your video
 
Also, i have not tested, but have you tried making the music of the cutscene BE a sound (like a punch sound) instead of music? it might work if Openbor has no limit on what can you use as "sound"
(i am assuming this cutscene is an entity in the middle of a stage) like in your video
i tried that before, i think there is a limit on how long a sound can be (8-10 seconds?)
 
i tried that before, i think there is a limit on how long a sound can be (8-10 seconds?)
Well, that really puts a damper on the whole "dynamic music" i was going to try to do....

then the original idea kind of still stands -
one script to:
find a way for the engine to "take note" of what point the music is at, then stop it ,then play the cinema entity tune
The cinema goes and before it finishes it runs another script to:
stop the cinema entity tune, start the music again from the offset recorded earlier & make sure to re-program the loop offset point again
(it would be cool to figure out if the engine could feature multiple offset for a music file, otherwise i am assuming the scripts have to exploit a single one & just "move" it around)
 
@Aerisetta,

It is true OpenBOR streams music instead of storing it to RAM, that's what any engine worth its salt does. However, it does keep an internal offset and there actually is a simple flag to continue music through stages. I can't for the life of me remember what it is and finding it in code is a needle in a stack of needles, but I'll poke around.

Edit: Found it. Musicoverlap 1. It's a levels.txt command that enables overlapping music for the stages in a set:

DC
 
@Aerisetta

1. Ideal solution - Game can remember what music was playing as BGM, pause it, let other music play, then play the BGM again (even better if it resumes at the point it was paused.
I've coded some scripts for the SORX that may be useful for you. However, I suggest replacing all the native engine music functions to the scripted methods, otherwise you can experience some issues.

Here's the custom music function I'm using to play any music. You can erase the offset table in case you don't need it, I leave it only to show some examples.
The fademusic function I'm using only to create a small interval between each music.
C:
void musicPlay(void music, int loop, int offset)
{//Play defined music
    void folder = "data/music/";
    
    //CHECK A OFFSET TABLE ACCORDING TO THE CURRENT MUSIC FOR A CUSTOM SCRIPTED LOOP POINT
    if(music == "03.ogg"){offset = 100315;}
    if(music == "10.ogg"){offset = 3606728;}
    if(music == "20.ogg"){offset = 1317068;}
    if(music == "26.ogg"){offset = 658224;}
    if(music == "33.ogg"){offset = 849408;}
    if(music == "34.ogg"){offset = 1974784;}

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

    //SET OFFSET TO ZERO IF NULL
    if(offset == NULL()){offset = 0;}

    //SAVE THE CURRENT MUSIC
    setglobalvar("musicPlaying", music);

    //PLAY MUSIC
    fademusic(0);
    playmusic(folder+music, loop, offset);
}

This is the function I'm using to replay any music. I don't know yet how to start a music from a defined point, but you can play the previous music with this script.
C:
void musicReplay()
{//Replay the current music if requested
    void music = getglobalvar("musicPlaying");
    
    if(music != NULL()){
        if(openborvariant("in_level")){musicPlay(music, 1);}
    }
}


@DCurrent
@Aerisetta,

It is true OpenBOR streams music instead of storing it to RAM, that's what any engine worth its salt does. However, it does keep an internal offset and there actually is a simple flag to continue music through stages. I can't for the life of me remember what it is and finding it in code is a needle in a stack of needles, but I'll poke around.

Edit: Found it. Musicoverlap 1. It's a levels.txt command that enables overlapping music for the stages in a set:

DC
Thanks buddy, it would be great if there's some hidden function to start a music from a defined point. Unfortunately the offset function works only from the first music loop and so on.
 
Thanks buddy, it would be great if there's some hidden function to start a music from a defined point. Unfortunately the offset function works only from the first music loop and so on.
There's no such function, for that kind of granular control you need script. The option I spoke of above just lets a track keep playing through levels.

DC
 
There's no such function, for that kind of granular control you need script. The option I spoke of above just lets a track keep playing through levels.

DC
Yeah, I meant some "script' function that isn't in the manual. The closest function is the "pausemusic", but it will not work in case you change the current track.
 
Hi! I tested the script because is a great function to play special music. However, as I used the musicReplay() command to return the previous saved music (doesn't matter if it replays from 0 for me), it keeps replaying instead the musicPlay() special command instead of returning to the normal music. Any ideas?

Anyway, this is the script I was looking for to change music during a Super! Thanks to everyone!
 
@Aerisetta


I've coded some scripts for the SORX that may be useful for you. However, I suggest replacing all the native engine music functions to the scripted methods, otherwise you can experience some issues.

Here's the custom music function I'm using to play any music. You can erase the offset table in case you don't need it, I leave it only to show some examples.
The fademusic function I'm using only to create a small interval between each music.
C:
void musicPlay(void music, int loop, int offset)
{//Play defined music
    void folder = "data/music/";
   
    //CHECK A OFFSET TABLE ACCORDING TO THE CURRENT MUSIC FOR A CUSTOM SCRIPTED LOOP POINT
    if(music == "03.ogg"){offset = 100315;}
    if(music == "10.ogg"){offset = 3606728;}
    if(music == "20.ogg"){offset = 1317068;}
    if(music == "26.ogg"){offset = 658224;}
    if(music == "33.ogg"){offset = 849408;}
    if(music == "34.ogg"){offset = 1974784;}

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

    //SET OFFSET TO ZERO IF NULL
    if(offset == NULL()){offset = 0;}

    //SAVE THE CURRENT MUSIC
    setglobalvar("musicPlaying", music);

    //PLAY MUSIC
    fademusic(0);
    playmusic(folder+music, loop, offset);
}

This is the function I'm using to replay any music. I don't know yet how to start a music from a defined point, but you can play the previous music with this script.
C:
void musicReplay()
{//Replay the current music if requested
    void music = getglobalvar("musicPlaying");
   
    if(music != NULL()){
        if(openborvariant("in_level")){musicPlay(music, 1);}
    }
}


@DCurrent

Thanks buddy, it would be great if there's some hidden function to start a music from a defined point. Unfortunately the offset function works only from the first music loop and so on.

I looked into this further, and unfortunately, there's no way at the moment to start music streams directly from an offset. It's also not a quick add we can just toss into the next release either - the playback system just wasn't coded to do that.

I'll add it to the feature wish list, but it's probably not something I can get done for a while.

DC
 
Back
Top Bottom