Apart from highly artistic work, commercial pop could be written and sung entirely by computers within two to four years.
At the moment, in order to make this feasible, a computer has to have an expert knowledge database that is essentially so large that it becomes practical to make. the problem changes from "how to write the algorithm to generate a song" to "how to get a comprehensive expert knowledge database and how to apply it".
The technology's already there, but is is worthwhile. But would a computer own the copyright to a song it wrote?
Well that's the easiest part. The copyright would belong to whoever owned/used the system to create that particular piece.
What if a computer generated every possibly song sequence based on pattern analysis?
Impossible because this is a problem with an infinite solution. You could certainly generate a lot, but not the infinite amount required.