ModPlug Central

Community => General Chatter => Topic started by: rchrdcrg on August 16, 2019, 13:00:30

Title: Utilizing libopenmpt in Games for Dynamic/Interactive Music?
Post by: rchrdcrg on August 16, 2019, 13:00:30
Hello folks! So I've got a bit of a question!

I see there's a library that can be used for playback, but I'm no programmer, and lately I've been curious just what is libopenmpt capable of? Is it merely for playback, or could it be tied into variables in a game that would allow for more precise control such as:
-Volume/mute of channels
-Jumping to different patterns on cue
-Changing volume/effect/vst commands based on data from the game

If any of that is possible, let's just say I can dream up some truly amazing things you could do with that!
Title: Re: Utilizing libopenmpt in Games for Dynamic/Interactive Music?
Post by: Saga Musix on August 17, 2019, 01:15:47
Most of that is possible with the library, except for manipulating pattern data (which I guess your third point refers to). libopenmpt does not handle plugins and that would certainly not be a very useful feature for games anyway, as redistributing VST plugins is often not trivial (and more importantly you typically don't have the permission to do so with many plugins).
If you're seriously interested in what is possible and how it can be done, the documentation for each API function can be found at https://lib.openmpt.org/doc/
Title: Re: Utilizing libopenmpt in Games for Dynamic/Interactive Music?
Post by: rchrdcrg on August 17, 2019, 15:37:58
Awesome, thanks! Yeah, I didn't even really think about VST in depth before blurting it out... makes sense! I'm interested in exploring dynamic soundtracks for games in more detail than what most games do. Usually a dynamic soundtrack is just different prerecorded tracks that are faded in and out based on something simple like location/action, or maybe certain notes and effects are tied to actions and correspond to a beat, such as Rez, but I wanted to take it a step further and basically hand over some of the "composition" to the game itself with the objective that the music would be unique to every playthrough. Perhaps the game design could even be worked around this so that better skill equals better music, as if the player feels like a musician but by playing something unrelated like a Geometry Wars clone or something.
Title: Re: Utilizing libopenmpt in Games for Dynamic/Interactive Music?
Post by: LPChip on August 17, 2019, 22:30:28
If you are interested in procedural generated music (music that interacts with what happens in game), you should check out an indie game developer called Nifflas.

He uses Unity nowadays, and he created his own synthesizer in Unity, so he can have the music interact with what happens in-game. For example, in his latest game Knytt Underground, there is a section that is rhythm based, where you hear and see the music interact with the game very clearly.

Here's one of the examples of his earlier implementations: https://youtu.be/HLA3AekhB3U?t=98 The character is forced to transform every beat. In later puzzles, the puzzles themselves transform their state based on the beat or musical events.

Here is an example of the synth he build for his upcoming project Ondskan: https://www.youtube.com/watch?v=bU8HEQm0zX0. Everything you hear is generated by his synth and as you can see that he presses some buttons, those button presses could be an event in a game just as easily. For example, entering a room could add a synth section or change a parameter. For example, entering a cave could add a delay section to simulate reverb.
Title: Re: Utilizing libopenmpt in Games for Dynamic/Interactive Music?
Post by: violgamba on January 09, 2023, 08:19:19
Sorry for necroposting, but for the record, and the sake of others interested in this: interaction options are currently limited.
- You can not interactively manipulate channels (mute/volume/etc).
- You can not interactively jump to patterns.

You CAN set the tempo, pitch and volume of the song, but that's about it, for now.

I'm also interested in this kind of interaction.  I read a similar post to this one and got libopenmpt working before realizing that it isn't actually interactive.

If I'm mistaken about this, then I apologize.  I'd love to be wrong, but I haven't seen anything in the documentation about channels or patterns except for getter functions.
Title: Re: Utilizing libopenmpt in Games for Dynamic/Interactive Music?
Post by: Saga Musix on January 09, 2023, 09:17:59
That's not quite right.

Quote from: violgamba on January 09, 2023, 08:19:19- You can not interactively manipulate channels (mute/volume/etc).
set_channel_volume and set_channel_mute_status from the interactive (https://lib.openmpt.org/doc/classopenmpt_1_1ext_1_1interactive.html) interface.

Quote from: violgamba on January 09, 2023, 08:19:19- You can not interactively jump to patterns.
There is both set_position_seconds and set_position_order_row for jumping to a specific position.
Title: Re: Utilizing libopenmpt in Games for Dynamic/Interactive Music?
Post by: violgamba on January 09, 2023, 12:10:18
Oooh boy, that's exciting.  But, how did I miss these?  I guess I wasn't as thorough as I thought.

Thanks for setting the record straight.