Author Topic: libopenmpt, game dev and effects question  (Read 806 times)

Offline mbbmbbmm

  • Shy artist
  • Posts: 2
libopenmpt, game dev and effects question
« on: December 02, 2020, 21:08:56 »
Hello everybody!

I would like to use IT- or XM- module playback in game development. But I am a little confused.

From what I've read a big advantage of using mod files for game music is that they are kind of interactive, channels can be muted and unmuted etc.

I played around with SharpMik in Unity3D a bit - and muting/unmuting and setting the song position is working fine :)

But I also read that there is this concept of "subsongs", parts of the module that use Bxx Jump-to-order commands. From what I understand the sections are told to loop until further notice and then can jump to a different subsong on demand. This would allow having reactive music via modules in the game which would be super cool!

The looping via Bxx is working fine - but how can I jump to another subsong right on time? Setting the song position from the game code works but is not very tight, since the exact time of the command depends on the current framerate of the game loop. I think the best way would be to set a new jump command on the last beat and leave the timing to the player - if that is possible at all :D

So I am a bit confused: is it possible to change the effects of a module after it has been loaded by the player? With a library like libopenmpt can I set the Bxx-effect on the last step of a subsong to jump to a different order while it is already playing the module?

Maybe I am misunderstanding the concept. Any help or hints are very appreciated!

Offline Saga Musix

  • OpenMPT Developers
  • *****
  • Posts: 7,226
  • aka Jojo
    • Download music, samples, VST plugins: Saga Musix Website
  • Operating System: Windows 10 x64
Re: libopenmpt, game dev and effects question
« Reply #1 on: December 02, 2020, 22:25:38 »
The looping via Bxx is working fine - but how can I jump to another subsong right on time? Setting the song position from the game code works but is not very tight, since the exact time of the command depends on the current framerate of the game loop. I think the best way would be to set a new jump command on the last beat and leave the timing to the player - if that is possible at all :D
Sadly there is no easy way to do this right now but it's planned for the future to make this easier: https://bugs.openmpt.org/view.php?id=1017

If you have complete control over the music being played in your game, you can maybe look at this workaround for now, by computing the expected duration of a row: https://forum.openmpt.org/index.php?topic=6516.0
Let me know if you need any help with the formulas .

So I am a bit confused: is it possible to change the effects of a module after it has been loaded by the player? With a library like libopenmpt can I set the Bxx-effect on the last step of a subsong to jump to a different order while it is already playing the module?
You cannot "edit" the pattern data in the sense you can place Bxx commands after the file has been loaded, but by calculating when a row or pattern is finished playing (see above), you can create smooth transitions between songs. Do note that this is not required if your subsongs are just always supposed to loop back to the same position; this is something the library should already do on its own.
ยป No support, bug reports, feature requests via private messages - they will not be answered. Use the forums and the issue tracker so that everyone can benefit from your post.

Offline mbbmbbmm

  • Shy artist
  • Posts: 2
Re: libopenmpt, game dev and effects question
« Reply #2 on: December 03, 2020, 14:44:08 »
Ok, cool that makes sense. I am going to try this later tonight. Thank you!