Introduction
This script allows you to play music files up to 'designated' points you establish and loop them accordingly. If you have a long intro or fanfare in your piece and don't want the music to repeat the fanfare, you can tell it to loop back to a later start position. You don't want it to go to the end of the file, tell it so.
Included here is a script to create an editor for use with the system.
This addon was created by DerVVulfman to be pasted below the editor. It creates an additional help window which may help first-time users.
Code:
# Help Window Addon for Cogwheel's
# MP3 loop corresponding Editor
#
# By DerVVulfman
#
# ==== Just paste it below his script and it gives you a help window. ====
#==============================================================================
# ** Game_MP3Player
#------------------------------------------------------------------------------
# It is the MP3 player.
#==============================================================================
class Game_MP3Player
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias mp3_initialize initialize
def initialize
# Perform the original call
mp3_initialize
# Create the help window
@mp3help_window = Window_MP3Help.new
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias mp3_update update
def update
# Perform the original call
mp3_update
# If the music type is changed
if @temp_typs != @data_type
# Update and refresh the help
@mp3help_window.type = @data_type
@temp_typs = @data_type
@mp3help_window.refresh
end
# If in the data window
if @data_window.active
# If the data options have changed
if @temp_index != @data_window.index
# Update and refresh the help
@mp3help_window.index = @data_window.index
@mp3help_window.refresh
@temp_index = @data_window.index
end
# Otherwise, if in the music select
else
# Prevent lag, only just entered the option
if @temp_index != -1
# Update and refresh the help
@mp3help_window.index = -1
@mp3help_window.refresh
@temp_index = -1
end
end
end
end
#==============================================================================
# ** Window_MP3 Help
#------------------------------------------------------------------------------
# It is the window which indicates the audio list.
#==============================================================================
class Window_MP3Help < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
attr_accessor :index
attr_accessor :type
def initialize
super(320, 64+224, 256, 128)
self.contents = Bitmap.new(width - 32, height - 32)
self.opacity = 192
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
# Clear
self.contents.clear
# Branch on help option
case @index
when -1 ; text_0
when 0 ; text_1
when 1 ; text_2
when 2 ; text_3
when 3 ; text_4
when 4 ; text_5
when 5 ; text_6
end
end
#--------------------------------------------------------------------------
# * Music Select text
#--------------------------------------------------------------------------
def text_0
self.contents.draw_text(1, 0, 240, 24, "Music File Selection.")
self.contents.draw_text(1, 24, 240, 24, "Up/Down to highlight. ")
self.contents.draw_text(1, 48, 240, 24, "Enter/Select to choose. ")
self.contents.draw_text(1, 72, 240, 24, "ESC saves your custom file. ")
end
#--------------------------------------------------------------------------
# * Audio option text
#--------------------------------------------------------------------------
def text_1
self.contents.draw_text(1, 0, 240, 24, "Choose between 4 types ")
self.contents.draw_text(1, 24, 240, 24, "of audio modes. Normal")
self.contents.draw_text(1, 48, 240, 24, "doesn't loop. Dungeon & ")
self.contents.draw_text(1, 72, 240, 24, "Battle do w/ reduced vol. ")
end
#--------------------------------------------------------------------------
# * Music Start text
#--------------------------------------------------------------------------
def text_2
# Exit if normal type
return if @type == 0
self.contents.draw_text(1, 0, 240, 24, "Sets where the music starts")
self.contents.draw_text(1, 24, 240, 24, "playing." )
self.contents.draw_text(1, 48, 240, 24, "Up/Down sets position by 1 byte." )
self.contents.draw_text(1, 72, 240, 24, "Left/Right sets by 1000 bytes.")
end
#--------------------------------------------------------------------------
# * Music End text
#--------------------------------------------------------------------------
def text_3
# Exit if normal type
return if @type == 0
self.contents.draw_text(1, 0, 240, 24, "Set where the music ends")
self.contents.draw_text(1, 24, 240, 24, "before looping back.")
self.contents.draw_text(1, 48, 240, 24, "Up/Down sets position by 1 byte.")
self.contents.draw_text(1, 72, 240, 24, "Left/Right sets by 1000 bytes.")
end
#--------------------------------------------------------------------------
# * Music Loop text
#--------------------------------------------------------------------------
def text_4
# Exit if normal type
return if @type == 0
self.contents.draw_text(1, 0, 240, 24, "Set where the music returns")
self.contents.draw_text(1, 24, 240, 24, "to after the end is reached.")
self.contents.draw_text(1, 48, 240, 24, "Up/Down sets position by 1 byte." )
self.contents.draw_text(1, 72, 240, 24, "Left/Right sets by 1000 bytes.")
end
#--------------------------------------------------------------------------
# * Play Text
#--------------------------------------------------------------------------
def text_5
self.contents.draw_text(1, 0, 240, 24, "Play or restart the music.")
end
#--------------------------------------------------------------------------
# * Stop Text
#--------------------------------------------------------------------------
def text_6
self.contents.draw_text(1, 0, 240, 24, "Stop music playback.")
end
end
Usage
Well, place the MP3 Loop script (the engine) above MAIN or below SCENE_DEBUG, with the Game_System sample script * directly underneath.
* The Editor script can generate a Game_System sample script for you.
Editing the Game_System sample script
when "satoc-boss09-2"
The name within the quotes is the name of the music file in question. It may be either mp3, ogg, wav and/or mid.
type = "Battle"
This determines the type of music file.
Normally, music is defaulted to 'Normal' indicating no custom looping is involved. However, the values of "Dungeon", "Battle" and "Other" are valid and can permit custom looping that this script allows.
START = 0
loop = 96040
fin = 202680
The START value sets the start position for the music playback rather than having the music start from the beginning of the file. Simple.
The LOOP value sets the position in the 'loop' where the music returns. When looping, the music will restart at this point rather than starting over from the beginning of the music file.
And the FIN (French for 'End') value sets the position in the 'loop' that forces the playback to rebound back to the beginning of the loop. Once the system hits the FIN value, the music will loop back and restart at the LOOP position
All values are measured in milliseconds.
Notes
The system does not like lowercase letters or spaces in the filenames.
When multiple actions are occuring, looping may not be totally accurate. Playback may not be perfect when various activities are occurring in-game.
If the position set in the 'FIN' value exceeds the maximum length of the music file, looping cannot be performed.
Compressed music files may not loop as accurately as uncompressed files. The higher a compression rate, the less accurate the loop.
The music pitch function may not function on music files defined as looping files.
IMPORTANT:
While .Ogg files are usable, PCs may not recognize Ogg Vorbis files as a playable music format. If media player and your Win32API.dll cannot play .ogg files, you may find a need to download a codex (decoder) to play them. Such a codex file may be found (>HERE<). Otherwise, you can always use .mp3 or .wma files.
While you can loop .Mid files with this system, the script will bypass the directX system to accomplish this. When playing files set to 'Dungeon', 'Battle' and/or 'Other', the music played by .mid will use the Windows soundfonts rather than the soundfonts in the DirectX library.
A minor fix was made in the Game_System sample script and the editor that generated Game_System code. This fix prevented (none) audio files from crashing the project.
* * * * *
The Editor System
The 'Editor' script includes both a menu system that takes over your project and includes a copy of the MP3_Loop script. It can generate a Game_System script you can use after you select the start, fin and loop positions for your music files.
Only music files stored within your Audio\BGM folder will show up within the menu. If there are no music files within the Audio\BGM folder, you will receive an error.
Compatability
This will alter systems that play music in your project, rewriting the play_bgm method.
Credits and Thanks
Thanks to Cogwheel for coding this script.
Terms and Conditions
Terms and Conditions
Use code and basic idea
Use code Use ignoring
There is no obligation of use and report
Literary work and indication there is no necessity
About use code
Please use freely regardless of non profit & profit. Also remodelling is free.
There is no necessity of report literary work indication, but when the game completes, when the information you give to with also the bulletin board, it is delightful, is.
However, like whether by his made this script of, please stop the behavior that it distributes with his own HP.
When those which remodelled the script which it is open in this Web page are released, we request the information.
Translation: It's free to post, edit and distribute... even for commercial use. You don't have to inform us if you post them on other sites. If you want to post 'edits', we ask you to let us know what you did.