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.
A correction has been made to the system. As of now, it DOES accept spaces and lowercase letters. For some reason, this also fixed (dunno why) the .ogg looping.
When it cycles back to the start of a loop, the .ogg music file may suffer a 0.5 delay, but it's streaming audio now.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)
Sorry if this counts as a bump, I don't suppose you know why there is a rather audible (or maybe it's just me being a perfectionist) gap when a loop restarts in mp3s?
This is kinda frustrating. I started off with a combination of MEs and BGMs to create a looping section and would (depending on my luck) have a slight jump at the start, but be good from then on. With this system it's the other way around, the jump is at the end of the loop.
Enterbraaaaaaaaain, why did you have to make Audio and Graphics hidden.
An audible gap in .mp3? There is one for .ogg that I'm aware and was even noted by others. Yours is the first statement of an audible mp3 format gap.
A few questions. Is it your music that you've done? Was it music in the demo? I really looked to time the gaps in Mark II from IronMan. Yep the movie soundtrack. Perhaps it's a different PC Operating system? I still sport Windows XP and I'm aware of some audio issues with Win7. Have you tried .wma?
And yeah.... I wish you could cache music and SEs lke graphics.
BTW: Hey, Jirby.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)
Oh, I thought you were aware of it? In the help file it talks about a slight jump before the looping section restarts. This is what happens with me. This is why I asked if you knew why it happened.
I tried to time the looping segments with parts that would sound okay with it, but it's still jarring. The example you mentioned - I think that was constructed in a way that made the jump unnoticeable.
On another note, I've found that the jump in my ME-BGM technique is noticeable after I've started something like Photoshop. Even closing it, even with 50FPS (what I've got my game set to), that jump will remain until a restart. Before that it is absolutely seamless.
(03-20-2011, 04:33 AM)DerVVulfman Wrote: An audible gap in .mp3? There is one for .ogg that I'm aware and was even noted by others. Yours is the first statement of an audible mp3 format gap.
A few questions. Is it your music that you've done? Was it music in the demo? I really looked to time the gaps in Mark II from IronMan. Yep the movie soundtrack. Perhaps it's a different PC Operating system? I still sport Windows XP and I'm aware of some audio issues with Win7. Have you tried .wma?
And yeah.... I wish you could cache music and SEs lke graphics.
BTW: Hey, Jirby.
Since you're bringing it up, I want to point out that .wma files don't play with this system.
At least not on my PC.
Friendship is born at that moment when one person says to another: "What! You, too? Thought I was the only one." (C.S. Lewis) For the time you're laughing, there's nothing wrong in the world. (Colin Mochrie) If it's funny, make sure people laugh. If it's not funny, make it funny (unless it's actually really serious). (silvercheers)
Please don't spell my name "Yamina-chan". It's all small. Thank you =D
Just an comment... why use .mp3? Midis *well made* can sound great, can be easly loopable, and aren't heavy as hell.
The "good quality" of MP3 don't make it for their high size and bad looping.
Also it's really disapointing download an 100MB game, and see that 80MBs are only for 10-25 musics.