Indeed. Cope's musical grammar would be a great place to start hacking around. This reminds also of the iMUSE (
http://en.wikipedia.org/wiki/IMUSE) from the SCUMM game engine, which would improvise soundtrack transitions based on motifs and in-game events.