As a musician myself and a major software developer, I can say that I can shed some cool light here: P I have done a lot of work on this issue and plan to do something big based on this in the future.
When you write an algorithm, your goal is to come up with an example of a solution; when sorting problems, it should have a sorted list. In an algorithmic musical composition, the solution (usually) is to have a song, or a pleasant melody, structure, etc.
The problem with the solution (hah) is that it is not only objective, but the solution is completely open. With the sorting algorithm, you have only one way to sort the list. With a musical composition, you have millions of enjoyable songs / whatevr, your goal.
Thus, you will need an algorithm that is good in order not to find the final solutions, but OPTIMAL. My suggestion is a genetic algorithm or similar. Genetic algorithms are great because they can create a pool of various optimal solutions.
You need to break the composition into pieces - have GA for the melody, GA for the rhythm, GA for the structure, etc. And design your fitness function according to your needs.
Of course, this is only one solution to the problem; there are many, and the wikipedia link listed above is a great start.
I recommend checking: GenJam: an improvisational jazz genetic algorithm designed to trade solo- http://www.it.rit.edu/~jab/GenJam.html
And this book is very instructive: http://www.springer.com/computer/information+systems/book/978-1-84628-599-8
I guess another interesting way would be with neural networks ... but providing them with sets will be a bit of a problem, maybe ... it works a lot more.
In any case, good luck with your projects: P