The earliest Western dance music that we know are some of the medieval dances such as caroles and the Estampie. Composers started to write their music down on music staves. Dance music had to have a regular beat so that the dancers could dance in time. This is why barlines were invented. The music was divided into bars with a particular number of beats in each bar. This was different from church music which was based on plainchant which was very free in the way it was sung.