MPTM file format player outside of OpenMPT

Started by CabbageRoll, July 26, 2021, 08:04:51

Previous topic - Next topic

CabbageRoll

I wonder how can I play tracker files outside of OpenMPT (a custom made MPTM file parser and player in java). It is already possible to find formats such as mod but I wanted some universal and newer one, not because of the features but because it is one and only format that you can convert into inside of OpenMPT before playing it elsewhere... Is mptm the right thing for me? I could not find any detailed information about file structure other than "mptm is upgraded xm". I would appreciate any help, thank you!

Saga Musix

MPTM is in fact an extension of the IT format, not XM. You can use libopenmpt from pretty much any language to have perfect MPTM playback, but I'm not aware of an existing Java wrapper - you'd have to write your own which translates Java calls to either libopenmpt's C or C++ interface or see if there are automated tools to do that. Whether MPTM is the right thing for you really depends on what you want to achieve - based on this single post I cannot judge whether maybe the IT format would be advanced enough for your needs.
» 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.

CabbageRoll

#2
My bad I just remembered it as a 2 letter format, both xm and it have 2 letters. Oops. Anyway what my "current" goal is: I want to read notes and their pitch, the names of samples and a few of the effects that I could use is speed change, and those that move around the track. The name of sample will determine the sound that plays and not the sample itself. I could explain the use case but I don't want to overcomplicate it. I must make it completely in java. I want a format that would make me free of hassle from making support for various formats so I can have just a single one.

Saga Musix

You could probably do all of that with libopenmpt. I'm not aware of any current, maintained module players written in Java, so if using a native library for the "heavy lifting" is not an option, you'd probably have to write most of that code yourself - in which case I'd suggest to stick to IT rather than MPTM files, as there are less features and less corner cases to take care of. It sounds like you will only need the basic parsing of the module format as you want to trigger samples using some other way - that shouldn't be too much work to write in Java. In the end, the amount of effort you should put into this probably also depends on whether you want to work with a fixed set of modules / assets or if they are e.g. supposed to be user-replaceable. In the former case, you only need to implement the absolute minimum amount of features required to get going, otherwise using a more complete implementation like libopenmpt would probably be a good idea.
» 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.

CabbageRoll

#4
I haven't fiddled around very much with converting between different formats, so I don't know about the issues that could happen. Something just suggested me I should go with MPTM because, if I understand correctly it is not a "old or deprecated" format, but I might be completely wrong. Hopefully this little diagram explains everything you need to know.

What concerns me is what if the conversion between some formats goes wrong and something important gets messed up such as timing or pitch? If someone has a module they want to play in this custom parser hopefully the only thing they should to do is download OpenMPT -> open a file -> choose IT format -> save.

Saga Musix

MPTM is not a superset of other formats (except for IT of course), so there's always going to be some inaccuracies if you convert from other formats. As I still don't know about the actual use case this is going to be used in, it's hard to judge if a conversion to IT or MPTM would be acceptable in this scenario, because some of those inaccuracies and lost data may simply not be important to you. Just as an example, there are some effects that exist in both MOD in IT/MPTM but are interpreted differently, so after conversion they will be executed differently. And then there's an effect in MOD that is not supported by IT at all - Invert Loop, which modifies sample data while the sample is playing. As you want to replace the samples anyway, that might not be relevant to you.
» 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.

CabbageRoll

#6
These are all the effects that should convert flawlessly between formats
Axx: Set Speed
Bxx: Position Jump
Cxx: Pattern Break
Mxx: Set Channel Volume
Oxx: Sample Offset (optional)
Qxy: Retrigger (optional)
SBx: Pattern Loop
Txx: Set Tempo
Vxx: Set Global Volume

volume:
vxx: Set Volume

Most if not all of the other pitch-related and speed effects would simply make no sense to use due to the fact that I cannot control the note once it starts to play. I will shortly explain the use case below:

It is for a game called Minecraft, a 3d block building game. One of the features that exists are note blocks that have, for now 16 different instruments. A music generator (Minecraft note block studio, to create and play) and a server-side api (NoteBlockAPI, only to play) have been made to create and play music from a file using custom .nbs format. Note block studio has already built in .mid to .nbs converter and it pretty much varies how the result will sound from perfect to absolutely terrible. Minecraft runs at 20 ticks per second so the note precision is not that great... NoteBlockAPI creator recently pre-released version 2.0 that plays these files outside of main thread, in the future possibly eliminating the 20 ticks per second limit. Native .mid support is about to come, so I thought of helping add a tracker-based format to support even more music (tracker -> mid conversion would end up badly). It is fully made in java and using any sort of native C++ code is not allowed.
Links:
Note Block - https://minecraft.fandom.com/wiki/Note_Block
NBS format - https://opennbs.org/nbs
NoteBlockAPI - https://github.com/koca2000/NoteBlockAPI/tree/2.0

Saga Musix

You will be able to express all of that with with S3M, XM or IT, so picking a format that supports more features that you won't even be able to express in terms of note blocks is probably not going to be very useful. I'd stick to the IT format personally in that case. The complexity of writing a loader for all these formats is roughly the same, some knowledge on reading binary files will be required. But I think of those three IT will have the least amount of surprises.
» 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.

CabbageRoll

I have finally got the parser barely work (it still doesn't recognize any effects but at least it plays the file  :) ). I have followed the instructions from https://github.com/schismtracker/schismtracker/wiki/ITTECH.TXT but it seems like I always have a number of bytes being skipped (that's what the current parser does when it finds something it cannot recognize or not necessarily useful) right after the end of pattern offsets and before song message begins. I am still working to make the parser better, if anyone might need it here it is: https://github.com/Cabbage-Roll/ITPlayer

File in the attachment is here: https://github.com/Cabbage-Roll/ITPlayer/blob/main/src/main/resources/Minecraft.it

Saga Musix

» 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.