Can't you use the generative adversarial networks?
Where the discriminator IA would learn to identify good melodies from real data. After that, the generator would try to make a good melodie to be approve for the discriminator IA. Thus you could play the generator melodie .