ModPlug Central

OpenMPT => Help and Questions => Topic started by: Reenen on January 26, 2007, 06:19:39

Title: Making one big .IT file with several songs
Post by: Reenen on January 26, 2007, 06:19:39
Hi

In my discussion on this (http://forum.openmpt.org/index.php?msg=10428.0#msg10428) topic.  LPChip gave me a possible solution of my problem (duplicating instruments in several .it files).

The solution basically creating one BIG file with all the music in it, seperated by --- patterns.

Now how, from a programming point of view, would you skip to certain songs?  I'm very interested in this solution, and would like generally to know more on how it would be done.
Title: Making one big .IT file with several songs
Post by: CrazyAznGamer on January 26, 2007, 08:21:27
Most programming APIs offer methods to manipulate the song's position, allowing one to jump around the song. I know FMOD definitely does this.

A lot of engines include scripting controls to use these API's position skipping methods et. al. I would suggest constructing a system where you connect certain keys to certain positions in order to make distinguishing the song in code easier.

The end result is it's a bit more work and that's magnified as one tries to write maintainable code, but it is nevertheless fairly easy to code.
Title: Making one big .IT file with several songs
Post by: LPChip on January 26, 2007, 08:33:19
First, make sure that the .IT file is properly constructed.

This means that the last pattern of each (sub)song has a Bxx command which means: jump to order xx.

This way, playing from a position inside the song will guarantee that only that part of the song is being played. If you make those looped, then its even better (but not required ofcource)

In your program, you need to start playing and then jump to order to change song.

---- [ EXAMPLE ] -----------------------------
Lets say your orderlist looks like this:

00 01 02 03 -- 04 05 06 07 -- 08 09 10 11

3 songs of each 4 patterns.

Lets say you start the main menu on pattern 04, which is the first you will hear when fireing up the game. What you'll need to do is start the song and immediatelly jump to the right order.

Since order 4 has --, you need to take order 5 to start playing from pattern 04.

In pattern 07 you'll have a b05 command on the last row which will loop your song back to pattern 04 without you worrying about it in the code.

You can use this trick on all (sub) songs to get the result you're after.

I can't tell you how to program this, but no doubt there's a function that jumps to an order of choise.
Title: Making one big .IT file with several songs
Post by: Reenen on January 26, 2007, 09:15:51
Must the patterns follow so "closely" to each other?

I was thinking of starting song 1 on pattern 0, and song 2 at say, 500, and so on... Just incase someone adds some length to a song, and then I might be in trouble...
Title: Making one big .IT file with several songs
Post by: LPChip on January 26, 2007, 11:09:37
Quote from: "Reenen"Must the patterns follow so "closely" to each other?

I was thinking of starting song 1 on pattern 0, and song 2 at say, 500, and so on... Just incase someone adds some length to a song, and then I might be in trouble...

There are only 239 orders for .IT files, so good luck with that :P But indeed, you can simply keep many [--] 's in between, and you can always insert a pattern in between too, so its not necessary to keep the space reserved. Only know that if you indeed change the space, you'll need to edit the last patterns and change the Bxx aswell as the game.

Therefor, it might be best to not set the looppoints until the songs has been finished.
Title: Making one big .IT file with several songs
Post by: residentgrey on January 28, 2007, 20:42:10
hey how go you put those -- thingies in the pattern list in mpt anyway, +++ for that matter?
Title: Making one big .IT file with several songs
Post by: LPChip on January 29, 2007, 08:44:05
You can drag a [--] pattern to the left to insert one of those, and you can use num+ and num- to change its number. If you get past the last item, it will show a [++] pattern, and if you + another time, it will show [--]. You can also enter pattern 0, then press - twice (which is what I usually do)

I want to add another tip for this topic.

If you don't want to touch your code ever again, you can begin your song with pattern orders so you can direct your code to a fixed order which will then change the order to the right one.

That means that if you play order 0, you always play song 0, if you play order 4, you always play song 4.

Make several unique empty patterns at the beginning of the song. In each add a Bxx command that will jump to the 1st pattern of that sequence.

This allows you to make song packs where each song pack uses a predefined layout in the song, usefull for any type of game situation.

Eg. You can have it so that you have one beginning tune for a level, several variations dependend on an item you carry and a win and loose song. You can then say: song 0 is always beginning, song 1 is always ending, 2 to 8 are variations.

Keeping all songs identical on the first 8 patterns allows you just link a filename to a level and your script can handle the rest. :)
Title: Making one big .IT file with several songs
Post by: Reenen on January 29, 2007, 09:08:22
If I understand you correctly... Basically have a the first X patterns of you file an "Index"... so 1 would start song 1, 2 would start song 2 and so on.

And then start your first song on pattern 50 or so...

Sounds like a great idea.

The code can then just say "Play(2)" to play song 2.

Or better "Play(Greensleeves)", and in another piece of code have
"Const Greensleeves = 2".
Title: Making one big .IT file with several songs
Post by: LPChip on January 29, 2007, 10:01:57
Yup. :)
Title: Making one big .IT file with several songs
Post by: Reenen on February 02, 2007, 09:45:18
Can I jump to patterns more than 255?  Ie. FF

Because I have a feeling I might need it...
Title: Making one big .IT file with several songs
Post by: LPChip on February 02, 2007, 11:27:14
Quote from: "Reenen"Can I jump to patterns more than 255?  Ie. FF

Because I have a feeling I might need it...

No you can't.

In OpenMPT, you can, but those commands are not being understood outside OpenMPT.

But I believe there's a limit of 239 orders.

You can always make 2 songs even though they have the same samples. Sometimes thats your only option, but I find it strange how you require so many orders per song, cus usually a good gamesong has no more than 20 orders, before it loops.
Title: Making one big .IT file with several songs
Post by: Reenen on February 02, 2007, 11:53:19
(I thought I'll combine all my previous posts, and then delete them... but apparently you can't delete a post except if it was the last one... can admin do it?)

It may be a big game.

I'll maybe try to have songs with drums in one file and files without in the other. Something like that.

I do think that 2 or maybe 3 songs may be enough.

Also, at the moment I opened 50 patterns for "index", and I doubt there'll be 50 songs.

One can also increase the SIZE of the pattern. But that will be a lot of effort with the current way the copy and pasting works. But should be do-able.


Also... the game can directly jump to a pattern...

So maybe I should keep my "index" external (like a text file), and let the program worry about jumping to the right spot.

Can I then jump past 255? Well you'll not know would you... Smile


2 last things...  the [---] pattern seems to cut off my other patterns (or it just does funny things with the scroll bar).  What does the [+++] pattern mean?
Title: Making one big .IT file with several songs
Post by: LPChip on February 02, 2007, 12:18:47
[--] is an empty place in the pattern and most players see that as the end of a song.

[++] is just a space filler. Any player that finds one will skip it and move directly to the next order.
Title: Making one big .IT file with several songs
Post by: Relabsoluness on February 03, 2007, 00:00:31
Quote from: "LPChip"But I believe there's a limit of 239 orders.
The order/pattern limit in MPTm-format in the latest test builds have tentatively been set to 65000 - this should do for a while :)
Title: Making one big .IT file with several songs
Post by: LPChip on February 03, 2007, 00:04:50
Quote from: "Relabsoluness"
Quote from: "LPChip"But I believe there's a limit of 239 orders.
The order/pattern limit in MPTm-format in the latest test builds have tentatively been set to 65000 - this should do for a while :)

Yes, but normal .IT players cannot understand this, now can they? Reenen wants to use this for his game.
Title: Making one big .IT file with several songs
Post by: Reenen on February 05, 2007, 06:41:08
Yeah... It will depend on how "exact" MikMod was written.

My bet is that it would've taken a "byte" type as the parameter which would kinda make it not so useful.  But they may have just specified "integer" or something, which means it should work excellent.

I'll have a look.