+ pitch = scherzo_key_spell_pitch (&scherzo->key, pitch);
+
+#define NUM_RECENT_PITCHES 7
+ static pitch_t recent_pitches[NUM_RECENT_PITCHES];
+
+ memmove (recent_pitches, recent_pitches + 1,
+ (NUM_RECENT_PITCHES - 1) * sizeof (pitch_t));
+ recent_pitches[NUM_RECENT_PITCHES - 1] = pitch;
+
+ if (pitches_are_diatonic_scale (recent_pitches, NUM_RECENT_PITCHES)) {
+ scherzo_set_key (scherzo, recent_pitches[0]);
+
+ /* Respell pitch according to new key. */
+ pitch = scherzo_key_spell_pitch (&scherzo->key, pitch);
+ }
+