The rational and social foundations of music