Jump to content
Noyemi

Noyemi K's Simple Dynamic Music

Recommended Posts

Noyemi K's Dynamic Music System
Version: 1.0
Author: Noyemi K
Date: February 16, 2015

Version History




 
  • Version 1.0: Original Script

Planned Future Versions


  • None (though perhaps it can be extended to include menu music too and have more user-friendly ways to add variations)
     

Description




This script allows you to switch between various versions of a BGM, dynamically. For example, you have a version of the track that's just a backbeat, a version with the bass and the backbeat, and a version with all of that plus the melody. It switches between them without restarting the track, just by using a Control Variable event. An easy, customizable naming convention allows you to get more descriptive, but the default uses numbers.

I made this with adventure games and ABS RPGs in mind, but it could work with anything really.
 

Features


  • Switch between different variations on one BGM using a variable that you specify in the script
  • Easy editing of variation names
  • Works with auto-start BGM on maps
  • Works only with OGG files or PCM (WAVs)

Instructions

Place this into its own script above main. You can look in the script for additional instructions.
 

Script


#---------------------------------------------------
# Noyemi K's Dynamic Music System
#---------------------------------------------------
# Description:
# A dynamic music system that switches tracks on-the-fly
# without restarts. Useful for creating ambience that
# builds throughout various situations in an area.
#---------------------------------------------------
module DynamicMusicSystem
 
#---------------------------------------------------
# Editable Region
#---------------------------------------------------

# Specify the variable ID used to store the song variation variable.

 SONG_VARIATION_ID = 1

# Specify the variation extensions
# "0", "1", "2", "3"], ["Normal", "Tense", "Puzzle"], etc. Can accomodate any
# number of variations up to the variable limit.
# ALSO: MAKE SURE YOUR FILENAMES CORRESPOND TO THIS ARRAY
# For example, for variations on "Forest.ogg", you might want to use
# "ForestNormal.ogg", "ForestCombat.ogg", or "ForestPuzzle.ogg"

 VARIATION_EXTENSIONS = ['', '1', '2', '3']

end
#---------------------------------------------------
# Engine Region. DO NOT mess with anything beyond this point.
#---------------------------------------------------

class MusicVariations
  def initialize
    super
    @extensions = DynamicMusicSystem::VARIATION_EXTENSIONS
    #msgbox(@extensions) #DEBUG
  end
 
  def cache_BGM
    @variationID = $game_variables[DynamicMusicSystem::SONG_VARIATION_ID]
    @songpos = Audio.bgm_pos
    if @variationID == 0
      $bgm_name = ('Audio/BGM/' + RPG::BGM.last.name)
    end
  end
 
  def check_variations
    if @extensions[@variationID] == nil
      @play = @last
    else
      @play = $bgm_name + @extensions[@variationID]
      @last = @play
    end
    Audio.bgm_play(@play, 100, 100, @songpos)
  end
end


#---------------------------------------------------
# Starts the engine at the title
#---------------------------------------------------

class Scene_Title
  #-------------------------------------------------------------------------
  # * Alias Main to initialize the data class upon startup
  #-------------------------------------------------------------------------
  alias start_dms start
  def start
    start_dms
    # Initialize
    $dms = MusicVariations.new
  end
end

class Game_Player
 
  alias update_dms update
  def update
    update_dms
    $dms.cache_BGM
    $dms.check_variations
  end
end

Credit




 

Support




Let me know if there are any bugs or improvements and I will update the script to reflect that.
 

Known Compatibility Issues

There shouldn't be any compatibility issues, unless some other script uses $bgm_name as a global variable.
 

Demo




Check Here
 

Author's Notes

I got the idea for this script from Soul Reaver's sound design, and I wanted to make that possible and modular and easy to use for RMVXA developers!

  • Like 1

Share this post


Link to post
Share on other sites

It might work in battles too, though if it needs more support in that area I'll see what I can do!

Share this post


Link to post
Share on other sites

Is this similar to having an event that does this on loop?

 

Play Bgm: track 1
wait 999 frames
Play Bgm: track 2
wait 999 frames
Play BGM: track 3
...
Or does it dynamically determine when would be a good place to change the music depending on the situation?

Share this post


Link to post
Share on other sites

Is this similar to having an event that does this on loop?

 

Play Bgm: track 1
wait 999 frames
Play Bgm: track 2
wait 999 frames
Play BGM: track 3
...
Or does it dynamically determine when would be a good place to change the music depending on the situation?

 

All it does is switch between tracks you supply it without starting from the beginning (which can't be done without scripting). It's controlled by a variable, so the dynamic determination aspect still needs some kind of input from the developer.

 

It's more like

 

If BGMX is playing
cache pos
 when situation == 0
  play BGMX from current pos
 when situation == 1
  play BGMX_Puzzle from current pos
 when situation == 2
  play BGMX_Tension from current pos
...

The script automatically caches a base BGM and uses the name of that file to create a "BGM group" out of all files with a similar (configurable!) naming scheme. For instance:

 

Your BGM folder has the area BGMs "Forest.ogg", "Factory.ogg", and "Desert.ogg". For each of these, the script makes it possible to have a more immersive experience provided you can supply variations of these. So for each of them, there's a "[Area name]_Combat", "[Area name]_Puzzle", "[Area_Name]_Tension", etc. You'd just need to make sure that the names of these variants of the area BGMs matches up to the array in the script, so you'd change


 VARIATION_EXTENSIONS = ['', '1', '2', '3']

to something more readable, like


 VARIATION_EXTENSIONS = ['', '_Puzzle', '_Tension', '_Combat']

All that's needed to switch between them and create the illusion of more instruments coming in or some fading out (to change the mood, like say from curious to tense) is a "change variable" event command. The script and your musician handles everything else. The demo shows a really simple form of this concept and you can crack it open and see that the music shifts between files when the variable changes.

 

You still need some way to get the actual tracks (as this cannot generate music), but if you have them, this script will make it possible to do something like Soul Reaver, which was the whole point of it.

Share this post


Link to post
Share on other sites

I would really like to use this script but I always get this stupid error... what did I do wrong?

 

Screenshot 2022-07-10 20.47.52.png

 

1944808217_Screenshot2022-07-1014_27_04.thumb.png.730e71e81f3920eaa4f1e7b7e2fd9fa9.png

Edited by stegan

Share this post


Link to post
Share on other sites
19 hours ago, stegan said:

what did I do wrong

You skipped the title screen. That section of code needs to be setup from the title screen method

Perhaps after line 80 add

    $dms = MusicVariations.new if $dms.nil?

You also put code to skip the title screen in the scenemanager section. Custom code should always go into a new slot. DO not ever modify the default scripts.

It makes fixing problems much harder later.

Edited by roninator2
  • Like 1

Share this post


Link to post
Share on other sites

Thank you for your answer! So I can't use the script? Because my game should start without the title screen right into the first map. Is this possible to overcome? 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted