Ultimate MIDI Animation Starter Kit for iOS
Over the past few months I've been writing a music based game for the iPad. The game reads a MIDI file and this generates a series of notes which the player has to press at the correct time - a bit like this YouTube video but for iPad. The game's going really well and should be ready for release within a month.
|Beat Invasion Screen Shot|
When I first started, I thought the MIDI part of the game would be pretty straight forward - it turned out to be the most difficult part! If you're reading this, you've probably found the same thing. It's hard because there's almost no documentation available for CoreAudio and CoreMidi. During the development of my game, I spent hours searching Google to find every scrap of information there was. In the end there were a lot of things which simply weren't document and I had to work out for myself.
Having acquired all this knowledge, I didn't want it to go to waste so I decided to write the ultimate guide to MIDI on the iOS. This guide has hundreds of hours of research and will prevent you from wanting to throw your computer across the room when your can't access your MIDI messages directly or when your Audio Graph doesn't work.
So you want to use CoreMidi in your App? Huh...
Let me start by saying that CoreAudio is an amazing library. It's very powerful, extremely flexible and consistently written. With a good knowledge of CoreAudio, you can make your audio processing dreams come true. So you've read Apple's blurb and your excited, time to crack open CoreAudio and oh... You find CoreAudio is written in C, it doesn't use object orientation and there's almost no documentation. I forgot to mention it's closed source and very unforgiving if you make a mistake.
When I was starting my game, I tried to find all the information I could about MIDI and CoreMidi. I even took out a $50 monthly subscription to Safari Books Online so I could read a book dedicated to CoreAudio. I got my MIDI file playing in under an hour, now I was ready to start creating my game. All I needed was a callback to give me access to the MIDI messages in real time. After several more hours of searching I found that there isn't a callback. It just doesn't exist. Time to try Plan B. Send the messages to a virtual end point (a callback function). Several days later I've got it working and I even manage to play the messages through an audio graph. Great! Nearly there! I write the graphics side of my game and give it a test. It's ok but the music player tends to skip when there's a CPU spike which sounds horrible. It also doesn't pause automatically. I also want to filter which notes are displayed on the screen. But because I'm using the Music Player I have to do this filtering in real time which makes the frame rate drop.
Damn! Back to the drawing board. Ok so why don't I parse the MIDI file manually and give myself full control? A week later I've managed to parse the file manually and I've written a my own music player. Now I have full control. Oh, the iPhone only includes a mono-timbral MIDI sampler and my MIDI files seem to play too fast :( Que 4 weeks more of frustrating CoreMidi related problems...
Let me finish by saying that CoreAudio and CoreMidi are procedural C libraries with almost no documentation. If you try to go it alone like I did you'll asking for several months of pain.
Welcoming the Ultimate CoreMidi Animation Tutorial!
I've taken all the suffering and pain I experienced and turned it into an amazing tutorial. This tutorial covers a huge amount of information which just isn't available on the internet. It also covers some things which you can find on the internet but just aren't explained well - PPNQ im looking at you...
The tutorial covers the following:
- Loading and parsing a MIDI file using CoreMidi: I'll show you how to load a MIDI file using CoreMidi and then access the MIDI events (Note, Tempo, Time Signature, etc...) individually. This puts you in full control and gives you access to all the information the file contains. I also clearly explain how the MIDI file fits together and what the important MIDI messages mean.
- Lots of background information: In the tutorial I don't just explain how the example project works. I also give lots of background information and useful tips when processing MIDI files. I explain: bitwise operations, hex and binary, General Midi, how the percussion track work and much more! In fact the guide alone is over 5000 words long!
- Writing a fully functional MIDI player: Step by step, I'll explain how to interpret the sequence of messages you retrieved from the MIDI file. The MIDI player uses multi-threading to play the sequence of MIDI messages in real-time. The MIDI clock class ensures that the MIDI file plays smoothly at the correct tempo. The MIDI player provides easy to use callback functions which give you access to all MIDI events in real-time. If you need events which I've aren't included it's easy to extend the framework to support all existing MIDI messages.
- Audio Manager provides multi-timbral playback: CoreAudio on the iPhone only comes with a mono-timbral sampler. This means that you can only play your MIDI notes using one instrument sound. The Audio Manager which is included in the tutorial makes it easy to play your MIDI file using up to 10 instruments using a custom SoundFont. I show step by step how to setup a complex audio graph. I'll also show you how to set up the instruments based on information provided in the MIDI file. Doing this provides a rich sound as demonstrated in the video.
- Putting it all together: In the final part of the tutorial I'll show how you can put all this together to create a rich MIDI based animation. The animation above, visualizes the notes as circles. The position of the circle depends on the value of the note. Notes pulse based on the metronome beat. Sharps and flats are circles with a random fill. This is a simple example but it could easily provide the basis of a cool game or MIDI playing app.
- More than just a tutorial: The sampler project, provided with the tutorial, provides a solid framework for your CoreMidi iOS project. The license allows you to use the framework in any number of your own projects. You can use this project as a learning exercise to learn CoreAudio and CoreMidi or base your whole project on the code.
This tutorial and project took over 100 hours to write and contains information which isn't available anywhere else. This tutorial will save you at least 50 hours of work. If someone came to me today asking for a quote to do the work, I'd charge upwards of $3000. Instead of doing that, I've decided to sell the kit for a fraction of the price in the hope that it will benefit the maximum number of people. If you're not happy with the kit, don't worry - we offer a 14-day money back guarantee. To buy the starter kit visit the link below.