Key finding algorithms, designed to determine the local key of segments in a piece of music, usually have difficulties at the locations where modulations occur. A specifically designed program to indicate modulations in a piece of music is presented in this paper. It was previously shown that the major and minor diatonic scale, as well as the diatonic chords, form convex sets when represented in the Euler lattice (Honingh and Bod 2005). Therefore, a non-convex set within a piece of music may indicate that this specific set is not part of a diatonic scale, which could indicate a modulation in the music. A program has been developed that finds modulations in a piece of music by localizing nonconvex sets. The program was tested on the first five preludes and fugues in a major key from the first book of Bach's Well-tempered Clavier. It has been shown that the algorithm works best for modulations that involve many chromatic notes.