The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX Ace => VXA Scripts Database => Topic started by: Mishka on February 16, 2015, 03:39:05 PM

Title: [VXA] Dynamic Music System
Post by: Mishka on February 16, 2015, 03:39:05 PM
Noyemi K's Dynamic Music System
Version: 1.0
Author: Noyemi K/Mishka
Date: February 16, 2015

Version History



Planned Future Versions


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


Instructions

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

Script

Code: [Select]
#---------------------------------------------------
# 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 (https://www.mediafire.com/?eml79hiqxhaai66)

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!