Author Topic: How to load all sub songs in an mo3 file?  (Read 10563 times)

scvegetable

  • Posts: 7
How to load all sub songs in an mo3 file?
« on: 13 Sep '11 - 08:14 »
How to load all sub songs in an mo3 file?

Ian @ un4seen

  • Administrator
  • Posts: 20152
Re: How to load all sub songs in an mo3 file?
« Reply #1 on: 13 Sep '11 - 14:21 »
Can you confirm how you're loading/playing the MO3 file? The sub-songs will all be loaded, but to play the 2nd/3rd/etc, you need to seek to the appropriate start position. If you're using XMPlay, that is done by right-clicking the next/previous buttons.

scvegetable

  • Posts: 7
Re: How to load all sub songs in an mo3 file?
« Reply #2 on: 13 Sep '11 - 16:43 »
Can you confirm how you're loading/playing the MO3 file? The sub-songs will all be loaded, but to play the 2nd/3rd/etc, you need to seek to the appropriate start position. If you're using XMPlay, that is done by right-clicking the next/previous buttons.

I'm loading the MO3 file with BASS_MusicLoad function in my program, but the 1st has been played looped. How can I know how many sub-songs in the MO3 file and the start position of each song?

scvegetable

  • Posts: 7
Re: How to load all sub songs in an mo3 file?
« Reply #3 on: 14 Sep '11 - 07:41 »
I`m so sorry for my poor english!

The following is my code.

HMUSIC hMusic = BASS_MusicLoad(FALSE, "music.mo3", 0, 0, BASS_MUSIC_RAMPS | BASS_MUSIC_PRESCAN);

QWORD len = BASS_ChannelGetLength(hMusic, BASS_POS_BYTE); // len == 33467352

BASS_ChannelPlay(hMusic, FALSE);


But after the completion of playback, it plays the song from the start again. And the return value of the BASS_ChannelGetLength function is greater than 33467352?

Can anyone help me? Thanks

saga

  • Posts: 2148
Re: How to load all sub songs in an mo3 file?
« Reply #4 on: 14 Sep '11 - 15:18 »
BASS doesn't have built-in support for playing sub-tunes. To achieve your goal, there are several ways, some are more complicated than others. To make a good suggestion what you want to do, we need to know what you have in mind, though - do you just want background music for a game (easy if the module is prepared properly), or do you want to write a music player (a lot more complicated) or whatever?

scvegetable

  • Posts: 7
Re: How to load all sub songs in an mo3 file?
« Reply #5 on: 14 Sep '11 - 15:27 »
BASS doesn't have built-in support for playing sub-tunes. To achieve your goal, there are several ways, some are more complicated than others. To make a good suggestion what you want to do, we need to know what you have in mind, though - do you just want background music for a game (easy if the module is prepared properly), or do you want to write a music player (a lot more complicated) or whatever?

I just want background music in my game. There are 14 sub-songs in the mo3 file, but it just play the 1st. What should I do if I want to play the 2nd/3rd song?

scvegetable

  • Posts: 7
Re: How to load all sub songs in an mo3 file?
« Reply #6 on: 14 Sep '11 - 15:31 »
BASS doesn't have built-in support for playing sub-tunes. To achieve your goal, there are several ways, some are more complicated than others. To make a good suggestion what you want to do, we need to know what you have in mind, though - do you just want background music for a game (easy if the module is prepared properly), or do you want to write a music player (a lot more complicated) or whatever?

The details will be displayed in the XMPlayer window after an mo3 file being loaded. How does it work?

Ian @ un4seen

  • Administrator
  • Posts: 20152
Re: How to load all sub songs in an mo3 file?
« Reply #7 on: 14 Sep '11 - 16:03 »
I just want background music in my game. There are 14 sub-songs in the mo3 file, but it just play the 1st. What should I do if I want to play the 2nd/3rd song?

In that case, I would recommend that you just hardcode the start position of each sub-song in the game, and use BASS_ChannelSetPosition (with BASS_POS_MUSIC_ORDER) when you want to jump to a new one.

As saga mentions, if you want to arbitrarily detect sub-songs, it can get pretty complicated. In tracker formats (like MO3), there is a single "pattern" sequence containing all of the sub-songs. There isn't an index to tell the number/position/length of sub-songs, so the pattern data needs to be processed to get that information. When the BASS_MUSIC_PRESCAN flag is used, BASS_MusicLoad will process the pattern data to get the length but it won't look for sub-songs. Here is an old post with a description of how sub-songs could be detected...

   www.un4seen.com/forum/?topic=2650.msg17705#msg17705

Note that post is pretty old, and some things have since changed: BASS_MusicGetLength would be replaced by BASS_ChannelGetLength (with BASS_POS_MUSIC_ORDER) and BASS_SYNC_POS would be replaced by BASS_SYNC_MUSIC_POS. If wanted, it could also be expanded to get the lengths of the sub-songs, by checking how much sample data was produced by a sub-song.

The details will be displayed in the XMPlayer window after an mo3 file being loaded. How does it work?

XMPlay basically does what I described above :)

scvegetable

  • Posts: 7
Re: How to load all sub songs in an mo3 file?
« Reply #8 on: 14 Sep '11 - 17:11 »
But how to do it? Can you give me an example?

I just want background music in my game. There are 14 sub-songs in the mo3 file, but it just play the 1st. What should I do if I want to play the 2nd/3rd song?

In that case, I would recommend that you just hardcode the start position of each sub-song in the game, and use BASS_ChannelSetPosition (with BASS_POS_MUSIC_ORDER) when you want to jump to a new one.

As saga mentions, if you want to arbitrarily detect sub-songs, it can get pretty complicated. In tracker formats (like MO3), there is a single "pattern" sequence containing all of the sub-songs. There isn't an index to tell the number/position/length of sub-songs, so the pattern data needs to be processed to get that information. When the BASS_MUSIC_PRESCAN flag is used, BASS_MusicLoad will process the pattern data to get the length but it won't look for sub-songs. Here is an old post with a description of how sub-songs could be detected...

   www.un4seen.com/forum/?topic=2650.msg17705#msg17705

Note that post is pretty old, and some things have since changed: BASS_MusicGetLength would be replaced by BASS_ChannelGetLength (with BASS_POS_MUSIC_ORDER) and BASS_SYNC_POS would be replaced by BASS_SYNC_MUSIC_POS. If wanted, it could also be expanded to get the lengths of the sub-songs, by checking how much sample data was produced by a sub-song.

The details will be displayed in the XMPlayer window after an mo3 file being loaded. How does it work?

XMPlay basically does what I described above :)

saga

  • Posts: 2148
Re: How to load all sub songs in an mo3 file?
« Reply #9 on: 14 Sep '11 - 20:39 »
For a game, I personally would use (and have actually used) this approach:

- In the module file, separate sub songs by a "---" pattern (in IT/S3M, in MOD/XM there is no such thing, so you'd have to put some arbitrary empty pattern between sub songs, f.e. pattern 99).

- In the game, use ChannelGetTags(handle, BASS_TAG_MUSIC_ORDERS) to retrieve the order list byte array. The byte array's length can be retrieved by using ChannelGetLength(handle, BASS_POS_MUSIC_ORDER). Scan this byte array for the value 255 (if you put "---" between the sub songs) or 99 (if you did use an empty pattern as described above). Save the positions of those numbers + 1 into a new array. Then you can use those positions together with BASS_ChannelSetPosition to start the music from that position.

scvegetable

  • Posts: 7
Re: How to load all sub songs in an mo3 file?
« Reply #10 on: 15 Sep '11 - 13:20 »
I see, thanks a lot