]> git.cworth.org Git - scherzo/blobdiff - scherzo.c
Prefer flats rather than sharps when converting from MIDI
[scherzo] / scherzo.c
index 665795977fcf4e2d5c9d397fe3b1579cab9af3ba..bdd1a0fe5c7dbe86e97cf1c2a219e17815b9873e 100644 (file)
--- a/scherzo.c
+++ b/scherzo.c
@@ -280,8 +280,6 @@ on_key_press_event (GtkWidget *widget,
 
     if (pitch != PITCH_NOT_A_PITCH) 
     {
-       pitch = scherzo_key_spell_pitch (&scherzo->key, pitch);
-
        scherzo_press_note (scherzo, pitch);
 
        return TRUE;
@@ -389,8 +387,6 @@ on_key_release_event (unused (GtkWidget *widget),
 
     if (pitch != PITCH_NOT_A_PITCH)
     {
-       pitch = scherzo_key_spell_pitch (&scherzo->key, pitch);
-
        scherzo_release_note (scherzo, pitch);
 
        return TRUE;
@@ -401,17 +397,6 @@ on_key_release_event (unused (GtkWidget *widget),
     return FALSE;
 }
 
-/* Return true if 'a' and 'b' sound identical, (even if spelled differently)
- *
- * This comparison considers octaves as significant. So Bb and A# in
- * the same octave are considered enharmonic, but Bb and A# in
- * different octaves are not. */
-static int
-_pitches_are_enharmonic (pitch_t a, pitch_t b)
-{
-    return pitch_to_midi (a) == pitch_to_midi (b);
-}
-
 /* Determine a chord name (if any) from the current notes pressed */
 
 typedef struct analyzed_pitch {
@@ -875,7 +860,7 @@ pitch_group_remove_pitch_enharmonic (pitch_group_t *group, pitch_t pitch)
     int i;
 
     for (i = 0; i < group->num_pitches; i++)
-       if (_pitches_are_enharmonic (group->pitches[i], pitch))
+       if (pitch_enharmonic_to (group->pitches[i], pitch))
            pitch_group_remove_pitch_at (group, i);
 }
 
@@ -1007,6 +992,8 @@ scherzo_press_note (scherzo_t *scherzo, pitch_t pitch)
 {
     int i;
 
+    pitch = scherzo_key_spell_pitch (&scherzo->key, pitch);
+
 #define NUM_RECENT_PITCHES 7
     static pitch_t recent_pitches[NUM_RECENT_PITCHES];
 
@@ -1033,6 +1020,8 @@ scherzo_press_note (scherzo_t *scherzo, pitch_t pitch)
 static void
 scherzo_release_note (scherzo_t *scherzo, pitch_t pitch)
 {
+    pitch = scherzo_key_spell_pitch (&scherzo->key, pitch);
+
     pitch_group_remove_pitch_enharmonic (&scherzo->notes_pressed, pitch);
 
     scherzo_update_notes_and_chord (scherzo);