is it possible to play midi files? i found this lib, hxmidilib, which is a Haxe port of newgonzo's as3midilib for working with MIDI files. If it is possible to play midi with that lib. I need an example because using it is a bit confusing.
bump. need this to work for cpp, neko, etc. any help is appreciated.
What have you tried so far? The Readme states:
Documentation and samples on the original project's page: http://code.google.com/p/as3midilib/
AS3 is generally very close to Haxe, syntax-wise.
This post is deleted!
can hxmidilib play midi?
MIDIFilePlayer();has no help associated with it and I viewed the class and the constructor is empty. those help files at that link has no example about how to play music. the flash swf files do not load and gives errors.
Can you perhaps elaborate a little about what you wish to accomplish with MIDI in Haxe?
Because unless you really do not care too much about quality, or just need some funky 8bit(ish) synthetic sounds, then to be able to play some - decent - MIDI you will need more then just a library. Midi played by just some generic audio device - like your PC sound card - sounds really cheap. To do it right you will need an audio engine that can serve as an VST host. Although this would be very welcome in the Haxe ecosystem. At this point to the best of my knowledge such a thing - natively - does not exist. Also you must check if you may use your virtual instruments - if you have any - in a game and if the virtual instruments are supported by all systems you wish to target.
You can either use (1) a C/C++ engine in Haxe using external code and wrap a Haxe class around it. This would for quality be your best bet. Or you can (2) export all the sounds you are going to need in every pitch you are going to need it in and then export it from your DAW to mp3/ogg. Perhaps then use midi or an own format to play it. The main problem with that is velocity and articulations. For an arithmetic synth sound this would not matter that much and you could just use volume to substitute velocity, but for say an acoustic drum kit it would be important. Some other problems you might run into are EQ, Reverb, Compressors, etc. These do also not exist in the Haxe ecosystem. (Would be extremely appreciated tough!).
You can of course also (3) just pre-record all your audio. This of course then has the big disadvantage of not being dynamic and always static the same. But it does gets the job done!. Perhaps you can (4) make some rhythm figures, groove and some melodies in separate files which you can swap/mix on runtime. Which actually is not that bad of an idea! This would still give you some slight but noticeable variations.
Hopefully this response helps you out a bit, or inspires you to go for a certain solution. I do believe that all my statements about audio in Haxe are accurate., But I am just using Haxe for a month now so please do correct me if I am wrong.
Best of luck!
the game that i am making is a retro style platformer game. therefore, the 8bit(ish) synthetic sounds are fine for me. i like midi because the file size is small. is there an alternative to midi that i can use where the file size is small? what should i do to get this midi working for cpp and flash builds.
Midi is just a data file containing notes. You need an (virtual) instrument to play it. If the library you wish to use does not provide any virtual instruments then the execution environment (example Operating System or Browser) needs to facilitate the instruments used. There is a generic map on most soundcards that can play usual stuff like: Piano, Violin, Harp etc. But those sound really horrible and any real musician would be totally unhappy with these kind of instruments. Normal music uses VSTi's for synthesizing music, which you need a host for. (Haxe does not have this). Also VSTi will not be flash compatible.!
The 8bit(ish) sounds must be made by a synthesizer, which works just like any other instrument., you need an interface to it and it must either be accessible by presets on the library you are using, or, you must program the synthesizer yourself.. I myself dont know of any synths compatible with flash. If you really want that then you must try and google for one written in AS3/Haxe. Only then will it be compatible on both systems. You must also when googling find out if the library has any instruments or if it just uses the ones from the environment (OS, Browser). Because if thats the case the 8bit(ish) sounds will not be facilitated.
Here is an link to a VST that facilitates 8bit(ish) sounds: Kruud (YouTube). Its free but needs a host. OpenFL cannot host this because the interface is C/C++. (Like the majority of these things).
Have you other than the filesize any other reasons of not using pre-recorded samples and swapping/mixing them at runtime? Because the synthesizer/VSTi market is pretty much made of C/C++ and with that incompatible with Flash builds. The changes that you will vind a decent AC3/Haxe 8bit(ish) synthesizer is VERY SLIM.!
Small tip: Google for Synth and not for midi ;-)
thank you for the information. file size was the only reason that I was considering using midi.
Quote: " file size was the only reason that I was considering using midi."
Can you make music? Have you ever written a song? Do you know any music theory? ... These things are important when using MIDI. Because you are just providing a system with notes! Also, have you ever programmed - not with code but just the instrument itself - a synthesizer? These skills are really not that easy either. Learning to program a synthesizer can actually be kind of difficult. Synthesizer theory is really not easy! Just search for a course on YouTube, you might just be overwhelmed with all things you will see. Especially if you have no music/audio theory to go with.
If you have not have any real previous experience with programming synthesizers or coding music. Then - unless you are really eager to learn - just go for solution 3 or 4 from my previous post.!
ty for the information. I will not use midi. Instead, I will use .OGG and MP3 for my music and sound files for my game.
Some last and unmentioned thoughts on this would definitely also be performance. VSTi's can be pretty heavy-duty. Expensive on both ram and CPU. If you have just one simple Synth you probably are still okay... But if you want a complete setup with lots of cool stuff you just might not get it running on say an old/cheap Android with 512mb of ram. Actual music studios use server blades to run their DAW's on. (usually Pro Tools). An other problem in the VSTi scene is bugs. Its al written in unmanaged C/C++. So expect some memory leaks here and there and access violations. The new Cubase release 9 has a sentinel that detects and blacklist these kind of things because their helpdesk/forum is full of sad stories about VSTi's misbehaving and making Cubase unstable.
And also, AFAIK Flash does also not support threads which can also be a potential problem. So even if you find a AS3/Haxe synth you might not get it working in Flash builds while HaxeFlixel - and your game - is running. Because then you probably going to need a separate thread for it because of all the CPU time.
Finally after looking at your provided link https://github.com/OIIOIIOI/hxmidilib I can assure you that this library has no instruments with it. Its a nice and small framework that can be used to play midi files in events loops. For example it can give you a callback on every beat. Which can be used for music because on every callback you can play a mp3/ogg -file, but can also be used for other applications. It will not fully accommodate you desired application though. This will only work with (2) of my previous post.
Good luck with your game!
Here's some inspiration to get you going on the music for your game. Its 8bit synths + heavy metal guitar & drum. You just might have heard it somewhere... And its actually from a game-soundtrack! || For some odd reason I thought it would appreciated for this post :D
# Machinae Supramacy :: Death From Above