]> git.cworth.org Git - scherzo/blobdiff - scherzo.c
Add support for drawing a key signature
[scherzo] / scherzo.c
index 6a5f2b3176c7f441fdf097714746705a74a91a2c..e8d0d274231e42d0adf1da3d8b3d91ad171c5f7b 100644 (file)
--- a/scherzo.c
+++ b/scherzo.c
@@ -78,6 +78,8 @@ typedef struct scherzo
     pitch_group_t notes_pedaled;
 
     int pedal_pressed;
+
+    pitch_t key;
 } scherzo_t;
 
 /* Forward declarations. */
@@ -561,61 +563,6 @@ _chord_signature_matches (analyzed_pitch_t *pitches,
     return 1;
 }
 
-static const char *
-_pitch_str (pitch_t pitch)
-{
-    static char double_flat[] = "X𝄫";
-    static char flat[] = "X♭";
-    static char natural[] = "X";
-    static char sharp[] = "X♯";
-    static char double_sharp[] = "X𝄪";
-    char *ret;
-
-    switch (PITCH_ACCIDENTAL (pitch)) {
-    case PITCH_ACCIDENTAL_DOUBLE_FLAT:
-       ret = double_flat;
-       break;
-    case PITCH_ACCIDENTAL_FLAT:
-       ret = flat;
-       break;
-    case PITCH_ACCIDENTAL_NATURAL:
-       ret = natural;
-       break;
-    case PITCH_ACCIDENTAL_SHARP:
-       ret = sharp;
-       break;
-    case PITCH_ACCIDENTAL_DOUBLE_SHARP:
-       ret = double_sharp;
-       break;
-    }
-
-    switch (PITCH_NAME(pitch)) {
-    case PITCH_NAME_C:
-       ret[0] = 'C';
-       break;
-    case PITCH_NAME_D:
-       ret[0] = 'D';
-       break;
-    case PITCH_NAME_E:
-       ret[0] = 'E';
-       break;
-    case PITCH_NAME_F:
-       ret[0] = 'F';
-       break;
-    case PITCH_NAME_G:
-       ret[0] = 'G';
-       break;
-    case PITCH_NAME_A:
-       ret[0] = 'A';
-       break;
-    case PITCH_NAME_B:
-       ret[0] = 'B';
-       break;
-    }
-
-    return ret;
-}
-
 typedef struct chord_signature
 {
     int num_degrees;
@@ -1115,7 +1062,7 @@ scherzo_press_note (scherzo_t *scherzo, pitch_t pitch)
                                       signature, *root);
 
            chord_name = talloc_asprintf (local, "%s%s",
-                                         _pitch_str (*root),
+                                         pitch_string (*root),
                                          signature->name);
        }
     } else if (chord->num_pitches > 2) {
@@ -1409,6 +1356,9 @@ main (int argc, char *argv[])
 
     scherzo.pedal_pressed = 0;
 
+    scherzo.key = PITCH_CLASS_LITERAL (C, NATURAL);
+    score_set_key (scherzo.score, scherzo.key);
+
     mnemon_init (&scherzo.mnemon);
     /* XXX: Should create a default file if one cannot be loaded. */
     mnemon_load_category (&scherzo.mnemon, "scherzo-notes");