This is Bach's chorale R.80. I want to know if the music has modulated to a particular key in certain, or is it only passing through different keys (and hence not a fixed modulation to only one key)?
Well, the score tells a story of modulation I would say.
Anyway, this melody appears 5 times during Bach's St. Matthew Passion with 4 different harmonizations. The melody, the soprano voice, is written by Hans Leo Hassler. Bach often took known melodies and harmonized them.
Try out playing the soprano voice, the melody, without the harmonies and you will hear a melody in the Phrygian mode, in this case F♯ Phrygian . The melody has a strong minor feeling. Now instead of treating F♯ as tonic Bach uses a D major chord at the start and the end, and suddenly it appears as if the chorale is in D major. It is an amazing harmonization created by a master.
The first section is D major ending with a fermata on a D major chord.
Then it immediatly modulates to B minor and the second fermata is a B minor chord.
Then it is repeated.
After the repetition sign the choral continues in B minor but modulates back to D major almost immediatly, and the next fermata is D major.
In the following section it modulates to E minor and the fermata is a B major chord which is the dominant chord in E minor. Notice that the melodic line ends this section with a Phrygian leading tone from G to F♯.
Anyway, the chord is B major, the dominant chord in E. Now you would think we are in E minor, but the next chord is E major instead of minor and it is even an E7 chord, so it works as a secondary dominant pointing to A major. And this section clearly is A major ending with a fermata on A major.
And since A major is the dominant in D major the last section starts right away in D major and ends in D major.
It is so fascinating.