Embedded midis

Blitz3D Forums/Blitz3D Beginners Area/Embedded midis

fox95871(Posted 2016) [#1]
Hello, I've been thinking about how much I like Blitz3d programs that use no outside media, because of all the cool stuff you can do with CreateMesh and other such commands. But is there a way to do that kind of thing with midis, so you don't have to rely on a midi file? In the past, I've used long lines of code that go way off the page - I think the maximum was 50 scrolls over - so I was thinking, maybe since midis are so small, I could do the same thing with the music, accessing each instrument to play at set times, and using colons to make it all as "off the page" as possible, so in the end it just looks like a few lines of code. Please don't hesitate to post anything that might help me with this... I guess probably unheard of request ;P


Midimaster(Posted 2016) [#2]
hi fox95871

You found my topic here: http://www.blitzbasic.com/Community/post.php?topic=100066&post=1179878 and asked to aswer here.

No outside media means, that you don't want to use files? My tool does the opposite. it builds a audio file of each midi tone. At the end you work with dozends of "piano.ogg" instead of calling the piano via midi commands. So that is not what you are looking for...

There are some tools that can includ files into your compiled Exe. I don't remember the name, but I used it years ago successfully. That is very comfortable and easy to use.

The official way is to build an install file with installers like "inno setup". where you build a exe with all files you need. The installer unpacks the game files once at the users computer into a folder.

MIDI

Instead of using big midi files you can also fire single MIDI events. This is what I'm doing in all my software. It is super-small. To send a tone you only need a sequence of 3 bytes. To stop it another 3 bytes. You can define your own "song-format" where it may be possible to need 1 byte for one tone.

You need a MIDI userlib or build a wrapper to call the MCI or MIDI SERVICE: https://msdn.microsoft.com/de-de/library/windows/desktop/dd742875(v=vs.85).aspx

Blitz3D library:
http://www.abrexxes.huntingsoftware.de/blitz/midi.zip

steps:
1.You check what MIDI devices are on the computer
2.You open a MIDI-OUT device.
3. Send 3 bytes strings
4. jump to 3. for each tone
5. You close the device

A three byte string contains:

<action+channel>, <midi note>, <midi velocity>

action is what you want to do f.e. 143 mean "play a tone",

channel is a free number between 0 to 15 added to action, (use 0 for notes
10 for drums)

midi note is the tone f.e. 60=C, 61=c#

volume=1-127, 0=note off

there are complete list of all command in the internet

I have no idea, how good this is working on Blitz3D, because I only work with BlitzMax. So good luck.


fox95871(Posted 2016) [#3]
Thanks for taking the time to write all that :) The program that combines media with an exe is called Blitz media linker. I have it, and I think I'll go that way instead, using midis turned into oggs.


Midimaster(Posted 2016) [#4]
ah! then my tool will be very comfortable for you. It plays a complete set (chromatic scales) of single tones on a MIDI instrument and saves each single tone into an audio file.

In your game you will be possible to combine this single audio sounds to create whole songs. The advantage is, that you can use a high quality MIDI instrument (ROLAND GS...), which often has a high latency of more than 200msec, to create the OGGs. But later the converted OGGs sounds will have 0 latency in your game.

If you use MIDI channel 10 and scan every note from 1 to 127, you will get 127 OGGs of a complete drum set.

Here is the correct link: http://www.blitzbasic.com/toolbox/toolbox.php?tool=264


fox95871(Posted 2016) [#5]
I have over 30,000 midis, so any instrument Roland has, I probably run into at some point. Could I turn all the instruments into oggs, then write code that does the same thing as a midi, playing each instrument at a set time using PlaySound, or would Blitz3d blow up or something? By the way, I'm not trying to detract from what you made, I'd just rather do it myself. Having more control like that might also solve a problem I had a while ago, where I'd made it so the music in my games could be intro>loop>loop like in most games, but it always had delays, even though I used oggs, and they were properly loaded beforehand, and so on. Someone even posted something like "Please perfect this, it's beautiful!", but I was never able to. Anyway, I have a zillion and one questions about music coding, so I'll leave it at that for now.


Midimaster(Posted 2016) [#6]
to run complete MIDI files you would need to many OGGs. That's the reason microsoft uses a virtual "sythesizer" like "ROLAND GS". There are 128 Instruments with each 80 scale notes + 80 drum sound=10.000 OGGs.

But if you only use f.e. a piano within 4 octaves you will need max 60 OGGs or less. For a drum machine a dozend OGGs are often enough. This is the point where I prefer my converted sounds. Latency shrinks to 0 and files size is often below 4kB per OGG. So no delays any more.

Good luck