# Generating music notes on the fly, that play over one another

I'm attempting to use Mathematica to generate music on the fly. I know that I can take a list of notes (which have lengths associated with them) and create a sound object, and play that sound object. But what I want, again, is to generate the notes ON THE FLY and play them as they are generated. In my mind this doesn't work the same way as having the notes specified ahead of time. I've tried using the EmitSound function to do this, but the issue seems to be that if say, I set it to emit one note for 10 seconds, and then use EmitSound again to play a second note one second later, the second note stops the first one. I want it to play over the first. I'll give some examples.

EmitSound[Sound[SoundNote[1, 10, "Trumpet"]]]; Pause[1]; EmitSound[Sound[SoundNote[1, 1, "Piano"]]]


The piano stops the trumpet from playing for the full 10 seconds. Granted I could get around this by putting the sounds together then playing them, but what say I want to do something LIKE the following:

While[True, EmitSound[Sound[SoundNote[RandomInteger[8], {0, RandomInteger[7]}, "Trumpet"]]]; Pause[1]]


This, in my mind, is SUPPOSED to endlessly choose a note between 1 and 8, and play the note for a random amount of time between 1 and 7 seconds, and the notes are SUPPOSED to overlap with each other due to the different note lengths. What it does though is just play each randomly selected tone for one second, after which it is cut off by the next note without getting to play its full duration. One can see that this is the same problem as previous, and in this case it's supposed to play endlessly, so there's no "compiling" the notes beforehand.

I definitely want the notes to play for their full duration, and there's no cutting the notes into shorter notes because that's not one constant tone with such musical instruments as they are.

Granted this code is NOT the final form of what I'm trying to accomplish, playing gibberish random notes, but getting this to work is the issue I need to get through... thanks.