This only works for western music
Now, you're correct if you're saying that not all music has melodies. Or that things like Indian ragas would be difficult to run through exhaustive permutation. But, as far as I know all music in the world has native notation or can be notated and reproduced.