Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.
I think you should be able to set it to memorize the bgm before the battle and then set battle conditions to restore the bgm...not sure if it will work but you could try it