The pop hits of the future might be written not by human musicians, but by machine-learning algorithms that have learned the rules of catchy music, and apply them to create never-before-heard melodies. Those tunes may not even require human hands to be heard, because a growing army of musical robots, from bagpipes to xylophones, can already play themselves—even improvise too.