Music is about sound. The interplay of consonance and dissonance is central to musical sound.
What is consonance? What is dissonance?
Our ears evolved to aid us in survival - to help us to find food and mates, avoid predators, and such. Music as we know it today had no role in the evolution of how we perceive sound - it is too recent in our genetic history. Reduced to fundamentals, I submit that consonant sounds are those which tend in nature to come from single natural sources: prey, mate, predator. Dissonant sounds tend to come from multiple sources. Recognition of the difference is built into our neural sound processing at all levels. The world in which we evolved was complex, and so are consonance and dissonance.
Numerous musical scales (organised collections of defined pitches) have been used over the years by various human cultures. All are designed to maximise consonance among their members in some way. (These ways are artificial and extremely limited - string ensembles ignore them!) The 12-note scale now used for Western music has itself been optimised in several different ways with the aim of maximizing the quality and musical flexibility of sound produced by fixed-pitch instruments such as the harpsichord.
These optimisations are of two main types: open and circular. In open tunings, such as those based on the meantone system, A flat is not the same pitch as its enharmonic G sharp; in circular tunings they are the same. An open tuning requires that a fixed-pitch instrument be retuned for each key; any use of enharmonics requires a keyboard with more than 12 keys. I believe that William Byrd was the first composer to write successfully for a keyboard with only 12 keys.
A primary interval in all musical traditions is the octave, which is defined as a factor of two in frequency (but can differ slightly from this with non-harmonic sounds). It sounds more consonant to our ears than any other interval. (Any single object, mouse or tiger, that interacts with a non-linear source of sound produces a harmonic series of partials, which begins with the octave.) Other "pure" intervals are defined as those formed by small integer ratios. Such intervals have maximum overlap of harmonic partials in the same way as the octave and also tend to sound consonant. Even in cases where non-harmonic partials are produced by an instrument (gongs, bells and drums, for example), musicians invariably select and use them so that their sounds resolve in our ears as closely to pure intervals as possible.
Given that octaves are to sound exactly in tune as our ears demand, only a few of the other intervals can be pure in any circular tuning. The modern preference is to make all intervals somewhat impure by using 12 equal semitones. There is then no difference between various musical keys and there are no restrictions on modulation. Unfortunately, this also removes key tonality as a significant structure in music. In Scarlatti's world this was not the case.
Until the late 1800's, the European preference was to tune keyboard instruments so that commonly used intervals were purer than those less used. The resulting slightly non-equal semitones gave a different harmonic character to each musical key. These harmonic colours were part of the musical language of the time, philosophically and practically. In particular, the variations in consonance of intervals were used by composers to shape phrases. When a musical phrase is repeated in a descending or ascending sequence, each one sounded different, nothing like modern equal-temperament where such sequences sound repetitive and boring. Scarlatti is full of them, and he was incapable of saying anything boring!
So, if one wishes to understand the musical language of early keyboard composers, the tuning in which their music was conceived and heard is important. Much early music relies on the strong consonance patterns of quarter-comma meantone tuning to shape phrases, and becomes dull and lifeless without it. Use of the tuning known today as Werkmeister III for J.S.Bach reveals many patterns in the Well Tempered Klavier that are hidden by modern equal temperament.
However, few composers documented the tunings used in their music. Although there is sufficient historical evidence that the period and nationality of a composer can narrow the choice considerably, there are often significant variances between historically-justifiable tunings for any specific piece of music. The tuning preferences of Domenico Scarlatti are particularly uncertain, since he was born and trained in Italy, but spent most of his career in Portugal and Spain, and did all of his significant composing while under strong Spanish influence.
My JASA paper referenced below discusses a quantitative method to approximate human judgements of consonance. It is based on a measure of the perceived consonance of each interval in a tuning and its frequency of occurrence in the compositions of Scarlatti. The presumption of all consonance methods is that Scarlatti would avoid passages using intervals that were markedly out-of-tune or dissonant in his tuning (such as wolf fifths) except in passing, and would tend on average to emphasize those intervals and keys which were relatively pure. Unlike traditional approaches to this question (cf. Barnes), which are based upon the same assumption but rely upon culture-dependent interval selection and classification, the JASA method is based directly upon experimentally-determined psychoacoustic properties of human hearing.
The method used in this paper cannot be used blindly. Although it gets many things right, it does not correspond with human perception in one important respect - "background" dissonance. The difference between the consonance numbers for a good and a poor tuning are much smaller than what our ear judges. One reason is that the method is linear, and our neural perception is very non-linear. Our perception involves successive pattern optimisations that evolved to maximise the likelihood of identifying the source of a sound. Temporal consistency patterns, the consistency of the sound of a lion's cough over the period of its utterance, are at least as important to our ears as harmonic overlap. And, the consonance number gain from making the most commonly used interval of a piece perfectly pure is often greater than that from balancing consonance across a piece of music, so the method favours over-specialized tunings with short samples of music.
Nonetheless, the method worked for Domenico Scarlatti. It alerted me to a match between French tunings of the period and his music that no one had suspected, and that stood up to musical judgement. And, with the large volume of Scarlatti's music available for analysis, it successfully optimised that tuning within the constraints set by French tuning instructions of the time.
The test of music is in the listening. My MIDI recordings use only one tuning for all the Scarlatti solo sonatas. (Technical limits of the MIDI specification prevented me from tuning the 2-player sonatas.) The consonance phrasing matches the musical phrasing - the strings talk to each other throughout. In fact the match is so good that you may not even be aware that a non-equal tuning is being used, just that the music sounds well. That's what good harpsichord sound is about.
References
The format used for my MIDI files is type 0 (single block). Each of the 12 notes of the scale is placed in its own channel, then a pitch bend applied for that channel appropriate for the tuning by a computer program. This format plays correctly on all General MIDI-compatible players of which I am aware. However, many sequencer programs insist on modifying it on file output. You are welcome to modify my files as you wish for your personal use, but I require that solely my originals be posted or distributed to others.
The tuning used for my Scarlatti recordings is C=0, 85.6, 193.4, 291.4, 386.3, 498.0, 584.7, 696.8, 787.5, 888.7, 994.9, 1086.5 cents, a tuning described by a number of French documents of the period, I believe first by d'Alembert. For Bach, I use C=0, 90.2, 192.3, 294.1, 390.2, 498.1, 588.3, 696.2, 792.2, 888.3, 996.1, 1092.2 cents (Werckmeister III); for Wm.Byrd C=0, 76.2, 193.2, 310.2, 386.4, 503.4, 579.6, 696.6, 772.8, 889.8, 1006.8, 1083.0 cents (quarter-comma meantone).