The MCI Object
Author: | Kramy
|
Submitted: | 21st September, 2003
|
Views: | 5623
| Rated: |
|
|
Recently I noticed many people asking how to play music over levels in TGF.(4 in the passed month) I actually still have a tutorial on my computer, but it only lists commands, and is somewhat indescriptive...
I'll describe how I believe the MCI object works(correct me if I'm wrong) as I sift through some specific code to help get people started in understanding the object, and how to play their music over different levels.
One thing to note is that the MCI object will keep playing music until you tell it to stop, so it is important that you tell it to stop BEFORE someone exits your game.
So, open TGF. Create 2 levels, and put a distinguishing object in each, so that you know if the frame has flipped. Then go into the first one and put the MCI object in it. You should be faced with 3 edit boxes and some check boxes. Uncheck all the check boxes, and enter sequencer as the device name.
Save your game, and then place your music in the same folder as it.
Note: In this example 3 global values will be used, but alternately 3 counters could be used instead.
Now enter this line:
Start of Level
-send a command: "open .\musicname.mid alias tune"
-send a command: "status tune length"
-set global value 1: Return( "MCI" )
-send a command: "play tune"
-send a command: "status tune tempo
-set global value 2: Return( "MCI" )
There, this will start playing your music at the tune's default rate. It will now even play from level to level after you insert the same MCI object into each level. It will not stop, however, and can not be controlled in any way yet.
These are the commands you just entered:
Open - opens the music in the path specified. .\ means current drive, current directory of game file. If you want to add a music directory for music, just make it play .\Music\musicname.mid. You have to close tunes before starting new ones. Alias probably means what you called the file, instead of what your computer does. The last bit, tune, tells the MCI object to tell the sequencer it refers to the tune.
Status - status gets the status of a specific statistic(tempo, length, etc.) from the current tune.
Return( "MCI" ) and Return string$( "MCI" ) retrieve the information from the MCI object, allowing you to alter some of it(tempo, for example) and then send it back to alter how the midi plays.
Play - "play tune" makes your game start sending the tune information to the sequencer(and your speakers) as it plays it.
Global Value 1: Tune Length
Global Value 2: Tune Tempo
Global Value 3: Tune Position
Now lets make it so your music keeps playing again and again!
Always
-send a command: "status tune position"
-set global value 3: Return( "MCI" )
Global Value 3 = Global Value 1
-send a command: "play tune from 0"
Note: You can also play the tune from any point in the midi. You can leave off somewhere, opening new music after saving the current position, then switch back to that music and position at a later level(if you would want to).
Now we have a problem though. The midi just won't stop! Any commands entered do nothing, the music just keeps on playing! Here is how to solve this.
You must make it so that every event that ends your game sends these commands first.
For example:
Upon Selecting Exit
-send a command: "stop tune"
-send a command: "close tune"
Destroy
Upon Selecting New Game
-send a command: "stop tune"
-send a command: "close tune"
Destroy
Upon Pressing Esc
-send a command: "stop tune"
-send a command: "close tune"
Destroy
Upon Pressing F2
-send a command: "stop tune"
-send a command: "close tune"
Destroy
Upon Pressing F4(alt + F4 is sometimes used to close games)
-send a command: "stop tune"
-send a command: "close tune"
-Destroy
This will stop your music, provided the "End Game" or "Restart Game" command was entered after the send commands. Note that these events are EXTREMELY important, as if they are entered incorrectly the player's computer will freeze solid after the game closes.
Now, how about altering tempo? Global Value 2 was set to the tunes tempo, so instead of picking a different music, lets just alter the current one...
Have an event that does something like this...
Player Colliders with an Enemy
OR
Battle Starts
Then...
-send a command: "set tune tempo " + str$(global value( 2 )*3)
You can also manually alter tempo by having a counter.
Repeat while Left/Right pressed
-Add/Subtract from Global Value 2
-send a command: "set tune tempo " + str$(global value( 2 ))
And finally, one last thing..how to switch the midi playing when you jump from level to level(for example, a horror level to a bright flower-filled meadow)
Start of Level
-send a command: "stop tune"
-send a command: "close tune"
-send a command: "open .\NEWmusic.mid alias tune"
-send a command: "status tune length"
-set global value 1: Return( "MCI" )
-send a command: "play tune"
-send a command: "status tune tempo
-set global value 2: Return( "MCI" )
I hope I provided some insight into how the MCI object works.
|
|
Kramy
Registered 08/06/2002
Points 1888
|