Historically, it was the troubadours who brought up the question with their contrast between difficult poetry for connoisseurs and clear poetry for immediate pleasure: trobar clus and trobar clar. Here is music by one of the leading troubadours, Bernart de Ventadorn:
Troubadour music had both high and low styles; the high style has, as we hear in the piece above, affinities with the chant of the church. The low style tended to have an affinity with the dance as in the balada or dance-song:
The performers are trying to re-create what a performance in the late 12th century might have sounded like, but you should bear in mind that the rhythms and instruments are all conjectural. All we actually have is the melodic contour and the text.
The first European writer on the social function of music was Johannes de Grocheio or "John the Grouchy" (if we translate literally from the French version of his name). He wrote a book around 1300 that classified music in Paris according to how it was used (or rather, how it ought to be used). For him, as for Plato before him, music was a means of organizing and controlling society. As long as music was largely supported by the aristocracy, this was certainly an important function. The glorious music of the French Baroque, for example, was certainly at least partly about gilding the Bourbon lily:
But with the fall of the ancien régime it was the newly prosperous and numerous middle class that bought concert tickets, pianos and sheet music thereby supporting the growth of the symphony orchestra, concert hall, instrument builders and publishers--not to mention performers and their agents! So music in the 19th century became the expression of the inner life and outer aspirations of the middle class. Romantic music and all its progressive followers exemplify this.
The question of the social function of music became particularly keen for some composers in the 20th century--Shostakovich in particular. After he was severely criticized for his opera Lady MacBeth of the Mtsensk District in 1936 he withdrew from performance the newly written 4th Symphony and composed his 5th Symphony. This was certainly a work that had a social function--a rather desperate one as, if Shostakovich did not successfully demonstrate his adherence to the 'social realist' ideals of the regime, headed at the time by Joseph Stalin, then he might get that knock on the door at 3 am followed by a quick trip to Siberia. So the music had to have a surface ambiguous enough that it could be interpreted as an optimistic tribute to the Soviet system. But at the same time, he wanted to reach out to those people who were suffering under that system. The half hour ovation at the premiere and the restoration of Shostakovich's fortunes by the government testify that he succeeded. Here is the first movement which comes in two parts because of the length:
The 5th Symphony of Shostakovich and, indeed, all his symphonies, have a number of complex social functions that have yet to be explored in much depth.
So one is led inevitably to wonder, what is the social function of music now? Some of it certainly seems to be about selling product:
Popular music, the trobar clar of the troubadours, seems to have taken over. The trobar clus, music designed for connoisseurs and the learned, which seems to be predominant in earlier ages (if only because it was the only music written down), seems now to be vanishing away, found only in music departments at universities, the occasional festival and the ever-struggling symphony orchestra concert. But note that "pops" concerts are common and new and difficult music is programmed less and less except at specialized festivals. Pop music rules the airwaves and public spaces. I'm not sure what the frenetic, mechanical nature of it is designed to serve. Any ideas?
UPDATE: It occurs to me that both the Shostakovich symphony and the song by Rihanna operate on two levels. In the Shostakovich, one level is that of an acceptable 'social realist' symphony, one that ends with rejoicing and rejects Western 'formalism' (i.e. the kind of atonality that was being used in the decadent West). The other level is an expression of the bleak oppression of the system and the toll it was taking on the humanity of everyone. Similarly, we might see two levels in the song by Rihanna. On the one hand, it is a girl trying to come to terms with her unfaithfulness to her boyfriend--this is the surface level. On the other hand, it seems to be an advertisement for make-up, clothing, restaurants and the good life generally.