This might a bit of an overkill, but if you want to do something more than generating a piano note, and work with musical generation you might want to have a look at this :
http://chuck.cs.princeton.edu/
It's a programming language that allows (among other things) to synthesise audio.
It has been the base for some music applications published on iOs, namely the ones by Smule.