MIDI music file support

Started by Silken Healer, December 20, 2024, 12:15:34 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Silken Healer

Edit Simon: Split from Music in Lix?

Quote from: Simon on October 20, 2017, 08:04:49 AMMp3 won't be supported, it compresses worse than ogg and is patent-encumbered. Midi probably won't be supported because Allegro 5 doesn't offer easy access.
Seeing as you said mp3 definetly won't be supported, and now it is, is there any more updates on whether .midi, which was just probably not could be supported for a future version of Lix?

Simon

#1
In 2021, MP3 has become patent-free. Allegro 5 has some support for it, I don't know for what platforms or with which dependencies. I don't know if MP3 support is compiled into the Windows DLLs that I ship. Yes, since 2023, MP3 support is compiled into the Allegro 5 DLLs that I ship with my Windows releases of Lix.

I haven't looked recently what audio file formats Allegro 5 supports these years. I don't think it offers Midi support.

-- Simon

Silken Healer

What actually is "Allegro." I keep on hearing that word. Why does a file format need to be in Allegro to be in Lix? Can't you get support for it in Lix without using Allegro

Simon

Allegro 5 homepage, read the first section.
Allegro 5 Github repo

When A5 supports a format, the existing infrastructure in Lix can play it without extra hassle.

When A5 doesn't support a format, I'll have to find decoders for the format and then find a way to get the decoded PCM into Allgero 5, or even to write platform-dependent audio playback code.

-- Simon

Silken Healer

I don't want Lix to be overly blotaed with feautres, I remember reading somewhere once that new suggestions should have a strong case, and most suggestions are bad, and obviously as a developer I don't know all the work that goes into it, I don't want to be selfish, obviously there must be some reason why you don't just add all the file formats right away, but considering MIDI was used for a lot of old computer music, it gives off the same sort of vibes as Lix, and it can be harder for less tech-literate people to convert due to the instrument sounds not being stored within the file, and converting loses the file size advantage, I think it would be a good fit for Lix to have it at some point.

namida

And how much of that old music fits with Lix's philosophy of avoiding copyrighted resources?

Pretty much anything used with Lix (outside of customizations to your personal setup, which isn't going to be a particularly high priority) is going to need to be public domain or at least something like Creative Commons licenced. So for the most part, that's going to mean resources specifically made for Lix. I would think it's safe to assume anyone who's creating quality original music can probably figure out how to get it from MIDI to a compatible format - in the unlikely event they're even using MIDI, rather than either a tracker app of some kind or else a full-on production environment like FL Studio that can just directly export an OGG file.

When that is considered, it doesn't really make sense to put a lot of effort into supporting it. Hence - if there were a low-effort way to support it (ie: if Allegro, a library already very central to Lix's code - you can sort of think of it as being what Lix uses instead of an engine like Unity or Godot etc, although there's a lot more DIY involved when working with something like Allegro compared to an engine - has native support for it, then adding support to Lix is pretty much as simple as adding .mid to the list of extensions it looks for on music files), it would happen; but if Simon has to find a seperate library just for MIDI and integrate that, or write his own code to handle MIDI, then it's not going to be worth the effort. And for what it's worth - MIDI is a much trickier format to work with in this regard than most others. To compare it to Lemmings levels; if an OGG file was a level, a MIDI file would be a list of what actions to take in the editor in order to create that level (yes, this is not a perfect analogy, don't try to take it as completely literal). So any DIY midi code is going to be a very large undertaking, and certianly an unnecessary distraction from the more important parts of Lix.
My projects
2D Lemmings: NeoLemmix (engine) | Lemmings Plus Series (level packs) | Doomsday Lemmings (level pack)
3D Lemmings: Loap (engine) | L3DEdit (level / graphics editor) | L3DUtils (replay / etc utility) | Lemmings Plus 3D (level pack)
Non-Lemmings: Commander Keen: Galaxy Reimagined (a Commander Keen fangame)

WillLem

#6
FWIW:

MIDI stands for "Musical Instrument Digital Interface" and isn't so much an audio format as it is a set of digital instructions to the audio for what it should do. It contains data for everything from which notes to play to which instrument should play them, and it necessarily relies on there being something on the receiving end to interpret and ultimately "render" the information into listenable audio.

Pretty much everything nowadays, from pop music to film scores, and certainly video game music, uses MIDI to some extent.

The Lemminas music, for instance, is all MIDI. Once the tunes have been composed, they can be inputted as MIDI information. Even where the tracks are physically played on a keyboard or digital piano, it's recorded in as MIDI (as opposed to raw audio) and then tinkered with in production - it's much easier to work with MIDI than it is to work with raw .wav files when it comes to mixing and editing.

I guess what I'm saying is, there's way more to MIDI than it being a simple audio format. As Silken rightly pointed out, if the MIDI isn't bundled with the necessary instruments and sounds, it generally won't be of any use to any program whose job it is to simply play the audio, as opposed to process it on a deeper level.

I hope this helps to clarify a few things. My advice to anyone who wants to supply MIDI music is to use a DAW to process the MIDI tracks (this may require some basic music production skills, but it's easy enough to learn for just doing a few tracks) and export the resulting piece of music as .ogg - I'd be happy to provide support with this wherever I can.

Silken Healer

#7
Quote from: namida on April 15, 2025, 09:13:31 PMAnd how much of that old music fits with Lix's philosophy of avoiding copyrighted resources?
We could get some in the public domain/specifically created for Lix/CC as you pointed out, but it's a moot point, as I was thinking more for other people downloading MIDIs off the internet, and putting them in their Lix folder, not MIDIs shipping with Lix.



To clarify, I didn't think this was high priority anyway, just that it'd be preferable to have at some point.

Good points though, maybe I overestimated the amount of people who think "Hm, I like the asthetic of the Lix music, I'd like to download some more in that asthetic to add to my folder. I know! I'll download some MIDIs" and underestimated the effort it would take. Maybe I'm probably the only person who exists in that niche :lix-tongue:.

Thanks for your input and for giving me some explanations WillLem and Namida.

namida

Quote from: WillLem on April 16, 2025, 12:09:53 AMMIDI stands for "Musical Instrument Digital Interface" and isn't so much an audio format as it is a set of digital instructions to the audio for what it should do.

It's also a file format as well, which is what Silken is referring to. However - the contents of such a file are indeed along the lines you describe.

To explain this in more depth and contrast it to a WAV / OGG / etc file, in a way that hopefully Silken (and any people with less tech and/or audio knowledge who are reading out of interest) can get:

A typical audio file (like a WAV or OGG) file is made up of "samples". Without getting into too much technical detail about them, you can think of a sample as being the audio equivalent to a pixel - much like how a pixel tells a screen "this is the color that should be at this particular point of an image", a sample tells a speaker "this is the level of sound that should be at this particular time in the sound clip". By extension, you can think of a WAV or OGG etc file as being the audio equivalent of a BMP / PNG / etc file. Most commonly audio files tend to have either 44100 or 48000 samples per second per speaker (ie: if it's a stereo file, there'll be this many samples for the left speaker + this many for the right speaker, per channel). The differences between various formats come down to (a) different header structure and contents; (b) different methods of encoding the samples (in particular, some use integer values ranging from (usually) -32768 to +32767; others use decimal values ranging from -1 to 1); and (c) compression (similar to how BMP is mostly just uncompressed raw pixel data + a header, WAV also stores the audio uncompressed; OGG and MP3 are lossy compression, similar to JPG; FLAC is an example of lossless compression, similar to PNG).

Because of this - if a program / game wants to play a WAV or OGG etc file, it simply needs get the sample data from it (this may involve a decompression step for some formats) and then play that sample data as-is. Perhaps at most it needs to convert between integer and decimal representations, if the audio library it's using expects one, but the format loading code gives the other - this is a simple maths exercise, with almost zero knowledge of the internal workings of audio needed.

MIDI files (and for that matter, module formats like MOD, IT, etc) are more comparable to SVG. I'm not sure how familiar you are with SVG, but basically - SVG files don't contain specific pixel data, instead, they contain instructions like "draw a line from (0, 0) to (120, 120)" that are used to create the image. Any app wanting to render this image would need to be able to actually read and process these instructions - generally speaking, it would be expected they can handle all standard instructions that might be found in an SVG file. MIDI is similar - it doesn't contain actual sample data; it just contains instructions like "play this note for this length of time at this point in the track". It's up to the app trying to play it - or the underlying OS - to generate the actual sample data from these instructions. Module formats are actually kind of "inbetween", in that they do generally contain actual audio clips but these are not the entire song, rather, the audio clips are of single notes, and the module file then contains instructions on when/how to play those notes to produce the overall song. MIDI doesn't even have this - it relies on the app (or the underlying OS) providing the clips that are used to generate the sound. This is also why, especially on older PCs (it's less the case on newer ones), the same MIDI file can sound different on two different PCs - because the two PCs are using a different library of instrument sounds to generate the actual audio.

Obviously, a key difference here is that an image file will be 2D (two axes: horizontal and vertical), and generally have a few thousand pixels on each axis at most (so a few million for the entire image). Whereas an audio file only has a single dimension (time), but will generally have tens of thousands of samples per second. (This is why audio files in formats that contain actual sample data, especially uncompressed formats like WAV, get so big so quickly.)

This is why MIDI often isn't supported in apps that have widespread support for various sound formats - even including ones that may support module formats.
My projects
2D Lemmings: NeoLemmix (engine) | Lemmings Plus Series (level packs) | Doomsday Lemmings (level pack)
3D Lemmings: Loap (engine) | L3DEdit (level / graphics editor) | L3DUtils (replay / etc utility) | Lemmings Plus 3D (level pack)
Non-Lemmings: Commander Keen: Galaxy Reimagined (a Commander Keen fangame)