[mod] Dynamic Background Music [dynamic_bgm]

Post Reply
User avatar
MisterE
Member
Posts: 693
Joined: Sun Feb 16, 2020 21:06
GitHub: MisterE123
IRC: MisterE
In-game: MisterE

[mod] Dynamic Background Music [dynamic_bgm]

by MisterE » Post

Dynamic Background Music is a mod that allows servers to have an unlimited number of background music tracks (without affecting login times),
send them to clients individually at appropriate times, and play them.

This mod is only for 5.5 dev + servers, not for any server version below that and not guaranteed to work for singleplayer. It will work just fine with 5.4 + clients. Anything below that will be unable to hear the background music.

It allows you to specify that a song should only be played when the following conditions are met:
  • light level
    positional range
    nearby nodes matching
    arbitrary custom checking functions
The way it works is that every interval (by default 4 min), the mod makes a list of songs that *could* be played, based on the conditions. It randomly chooses one, and then dynamically sends the music to that player only. Once the music is downloaded, it plays, and then the client forgets about it.

The api has functions that allow you to play a specific song to a specific player, and also to stop whatever song is playing currently (fades out over 2 seconds)

On the user interface side, there is a setting that can be toggled using /bgm to enable or disable the bgm.
Music is off by default, and a chat message is sent to players when they join, if bgm is disabled for them,

Code: Select all

Your background music is disabled. /bgm to enable it (Not recommended for slow connections.)
When it is disabled, the music is not sent to the client. Also disabling the music will stop whatever song is currently playing.

This mod only provides the api to send background music. I will post and link other mods that actually add music content, based on location, such as woodland_music, nether_music, cave_music, night_music, etc. Others are welcome and encouraged to make mods that add music, and if they post in this thread I will put a link on this post to their mod.

License: MIT
Author: MisterE
depends: none

Download: https://gitlab.com/mistere123.coding/dy ... master.zip
git: https://gitlab.com/mistere123.coding/dynamic_bgm


Mods that use dynamic_bgm:
minetest bgm modpack: viewtopic.php?f=9&t=27362

User avatar
Gael de Sailly
Member
Posts: 845
Joined: Sun Jan 26, 2014 17:01
GitHub: gaelysam
IRC: Gael-de-Sailly
In-game: Gael-de-Sailly gaelysam
Location: Voiron, France

Re: [mod] Dynamic Background Music [dynamic_bgm]

by Gael de Sailly » Post

Oh that looks amazing! A bit sad that it went unnoticed for more than 3 months.

Also it's one of the first times that I see a use of the new sound streaming features in Minetest. Ability to select the music based on the environment, as well as ambient sounds, would be a great enhancement.
I've looked a bit into the code and the possibility to play a music depending on the surrounding nodes is already great, but IMO the best would be to include biome data parameters.

And finally the only thing that's missing is a mod that adds music tracks! There was this old mod called ambience by Neuromancer featuring 4 tracks by Amethystium using the best that could be achieved with the Minetest sound API at the time, but I have no idea how they dealt with legal stuff as I don't think this kind of music has an open license.
EDIT: I didn't read all the post, my bad!
Last edited by Gael de Sailly on Sun Jan 16, 2022 21:21, edited 1 time in total.
Just realize how bored we would be if the world was perfect.

User avatar
MisterE
Member
Posts: 693
Joined: Sun Feb 16, 2020 21:06
GitHub: MisterE123
IRC: MisterE
In-game: MisterE

Re: [mod] Dynamic Background Music [dynamic_bgm]

by MisterE » Post

umm see the link at the bottom of the post. I spent a very long time gathering lots of music tracks and making a mod to add them.


minetest bgm modpack: viewtopic.php?f=9&t=27362

Its definitely not missing :P

I definitely intend to revisit this, probably around the time of the 5.5 release (since this requires a 5.5 server)
to include much better control over when the bgm is played, such as based on biome, or special mod-defined events, etc

ChristienChapman
Member
Posts: 117
Joined: Sat May 28, 2022 00:04

Re: [mod] Dynamic Background Music [dynamic_bgm]

by ChristienChapman » Post

Hello. I was really interested in your project since I see it can load music but reduce loading times. I would like to ask how I can call this program to play a song within code, I have a function here that calls the api but it does not seem to work. Any solutions?

I'm pretty sure I am using the wrong function. I need something to reduce load times and memory use for the Minetest Zombies Minigame which runs slow due to the over 44MB of music included. 0 . 0

Code: Select all

-- All glory to God, Jesus Christ, and the Holy Spirit.





local function OnboardMusic(inputa, inputb)
local m_name = inputa
local m_length = inputb

for _,player in ipairs (minetest.get_connected_players()) do 
local plname = player:get_player_name()

dbgm.send_music_to_player(plname,m_name,dbgm.path .. "/music/")

end
end










function GetSong()

if Map == "prison" then
selection = math.random(1,11)
if selection == 1 then
OnboardMusic("zombies", 104104)
end
if selection == 2 then
OnboardMusic("prison", 251)
end
if selection == 3 then
OnboardMusic("cell_outbreak", 217)
end
if selection == 4 then
OnboardMusic("zombies", 104)
end
if selection == 5 then
OnboardMusic("prison", 251)
end
if selection == 6 then
OnboardMusic("cell_outbreak", 217)
end

if selection == 7 then
OnboardMusic("zombies", 104)
end
if selection == 8 then
OnboardMusic("prison", 251)
end
if selection == 9 then
OnboardMusic("cell_outbreak", 217)
end
if selection == 10 then
OnboardMusic("prison", 251)
end

if selection == 11 then
OnboardMusic("surviving_for_a_while", 230)
end
end


if Map == "hotel" then
selection = math.random(1,11)
if selection == 1 then
OnboardMusic("zombies", 104)
end
if selection == 2 then
OnboardMusic("hotel", 102)
end
if selection == 3 then
OnboardMusic("hotel", 102)
end
if selection == 4 then
OnboardMusic("zombies", 104)
end
if selection == 5 then
OnboardMusic("hotel", 102)
end
if selection == 6 then
OnboardMusic("hotel", 102)
end

if selection == 7 then
OnboardMusic("zombies", 104)
end
if selection == 8 then
OnboardMusic("hotel", 102)
end
if selection == 9 then
OnboardMusic("hotel", 102)
end
if selection == 10 then
OnboardMusic("hotel", 102)
end

if selection == 11 then
OnboardMusic("surviving_for_a_while", 230)
end
end

if Map == "jungle" then
selection = math.random(1,11)
if selection == 1 then
OnboardMusic("zombies", 104)
end
if selection == 2 then
OnboardMusic("jungle", 167)
end
if selection == 3 then
OnboardMusic("jungle", 167)
end
if selection == 4 then
OnboardMusic("jungle", 167)
end
if selection == 5 then
OnboardMusic("jungle", 167)
end
if selection == 6 then
OnboardMusic("jungle", 167)
end

if selection == 7 then
OnboardMusic("zombies", 104)
end
if selection == 8 then
OnboardMusic("jungle", 167)
end
if selection == 9 then
OnboardMusic("jungle", 167)
end
if selection == 10 then
OnboardMusic("jungle", 167)
end

if selection == 11 then
OnboardMusic("surviving_for_a_while", 230)
end
end




if Map == "campsite" then
selection = math.random(1,11)
if selection == 1 then
OnboardMusic("zombies", 104)
end
if selection == 2 then
OnboardMusic("campsite", 188)
end
if selection == 3 then
OnboardMusic("campsite", 188)
end
if selection == 4 then
OnboardMusic("zombies", 104)
end
if selection == 5 then
OnboardMusic("campsite", 188)
end
if selection == 6 then
OnboardMusic("campsite", 188)
end

if selection == 7 then
OnboardMusic("zombies", 104)
end
if selection == 8 then
OnboardMusic("campsite", 188)
end
if selection == 9 then
OnboardMusic("campsite", 188)
end
if selection == 10 then
OnboardMusic("campsite", 188)
end

if selection == 11 then
OnboardMusic("surviving_for_a_while", 230)
end
end


if Map == "shelter" then
selection = math.random(1,11)
if selection == 1 then
OnboardMusic("zombies", 104)
end
if selection == 2 then
OnboardMusic("shelter", 240)
end
if selection == 3 then
OnboardMusic("shelter", 240)
end
if selection == 4 then
OnboardMusic("zombies", 104)
end
if selection == 5 then
OnboardMusic("shelter", 240)
end
if selection == 6 then
OnboardMusic("shelter", 240)
end

if selection == 7 then
OnboardMusic("zombies", 104)
end
if selection == 8 then
OnboardMusic("shelter", 240)
end
if selection == 9 then
OnboardMusic("shelter", 240)
end
if selection == 10 then
OnboardMusic("shelter", 240)
end

if selection == 11 then
OnboardMusic("surviving_for_a_while", 230)
end
end


if Map == "tomb" then
selection = math.random(1,11)
if selection == 1 then
OnboardMusic("the_swarm", 249)
end
if selection == 2 then
OnboardMusic("survival", 212)
end
if selection == 3 then
OnboardMusic("tomb", 453)
end
if selection == 4 then
OnboardMusic("the_swarm", 249)
end
if selection == 5 then
OnboardMusic("survival", 212)
end
if selection == 6 then
OnboardMusic("tomb", 453)
end

if selection == 7 then
OnboardMusic("the_swarm", 249)
end
if selection == 8 then
OnboardMusic("tomb", 453)
end
if selection == 9 then
OnboardMusic("tomb", 453)
end
if selection == 10 then
OnboardMusic("tomb", 453)
end

if selection == 11 then
OnboardMusic("surviving_for_a_while", 230)
end
end





if Map == "vanclerie" then
selection = math.random(1,11)
if selection == 1 then
OnboardMusic("the_swarm", 249)
end
if selection == 2 then
OnboardMusic("survival", 212)
end
if selection == 3 then
OnboardMusic("vanclerie", 116)
end
if selection == 4 then
OnboardMusic("the_swarm", 249)
end
if selection == 5 then
OnboardMusic("survival", 212)
end
if selection == 6 then
OnboardMusic("the_president_is_missing", 169)
end

if selection == 7 then
OnboardMusic("the_swarm", 249)
end
if selection == 8 then
OnboardMusic("vanclerie", 116)
end
if selection == 9 then
OnboardMusic("the_president_is_missing", 169)
end
if selection == 10 then
OnboardMusic("vanclerie", 116)
end

if selection == 11 then
OnboardMusic("surviving_for_a_while", 230)
end
end



if Map == "five" then
selection = math.random(1,11)
if selection == 1 then
OnboardMusic("the_swarm", 249)
end
if selection == 2 then
OnboardMusic("survival", 212)
end
if selection == 3 then
OnboardMusic("five", 121)
end
if selection == 4 then
OnboardMusic("five", 121)
end
if selection == 5 then
OnboardMusic("survival", 212)
end
if selection == 6 then
OnboardMusic("the_pentagon_is_under_attack", 154)
end

if selection == 7 then
OnboardMusic("the_swarm", 249)
end
if selection == 8 then
OnboardMusic("five", 121)
end
if selection == 9 then
OnboardMusic("the_pentagon_is_under_attack", 154)
end
if selection == 10 then
OnboardMusic("five", 121)
end

if selection == 11 then
OnboardMusic("surviving_for_a_while", 230)
end





-- added
end
-- added
end
God bless you.

List of releases:
Minetest Zombies Minigame - viewtopic.php?f=9&t=28442&p=412633#p412633

- > cdb_1d60e1a03f83

User avatar
MisterE
Member
Posts: 693
Joined: Sun Feb 16, 2020 21:06
GitHub: MisterE123
IRC: MisterE
In-game: MisterE

Re: [mod] Dynamic Background Music [dynamic_bgm]

by MisterE » Post

hi, please see the music modpack, how it is done there, but you will need dbgm.register_music. The mod will handle the rest. please note that I want to re-write this... and tbh, you may be better off implementing this functionality yourself until I do.

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot] and 15 guests