]> git.cworth.org Git - scherzo/blobdiff - scherzo.c
Allow computer-keyboard input of accidentals, and draw accidentals.
[scherzo] / scherzo.c
index b0f2c44ac05d1d96018c12f57874c96eb7bfa8de..b9a463368b86129dd1eee0cdd74cdabcecf7b561 100644 (file)
--- a/scherzo.c
+++ b/scherzo.c
@@ -60,9 +60,11 @@ typedef struct scherzo
     score_staff_t *bass;
     score_chord_t *chord;
 
-    /* This is for a "computer keyboard". Any "piano keyboard" key
-     * knows its own octave. */
+    /* The word "keyboard" here is referring to a "computer
+     * keyboard". Any "piano keyboard" key knows its own octave and
+     * accidental already. */
     int keyboard_octave;
+    score_pitch_accidental_t keyboard_accidental;
 
     int midi_fd;
     snd_midi_event_t *snd_midi_event;
@@ -215,9 +217,17 @@ on_key_press_event (GtkWidget *widget,
     case GDK_KEY_space:
        scherzo_press_pedal (scherzo);
        break;
+    case GDK_KEY_Up:
+       if (scherzo->keyboard_accidental < SCORE_PITCH_ACCIDENTAL_DOUBLE_SHARP)
+           scherzo->keyboard_accidental++;
+       break;
+    case GDK_KEY_Down:
+       if (scherzo->keyboard_accidental > SCORE_PITCH_ACCIDENTAL_DOUBLE_FLAT)
+           scherzo->keyboard_accidental--;
+       break;
     }
 
-    pitch = SCORE_PITCH (pitch_name, SCORE_PITCH_ACCIDENTAL_NATURAL);
+    pitch = SCORE_PITCH (pitch_name, scherzo->keyboard_accidental);
 
     if ((key->keyval >= GDK_KEY_A && key->keyval <= GDK_KEY_G) ||
        (key->keyval >= GDK_KEY_a && key->keyval <= GDK_KEY_g))
@@ -285,7 +295,7 @@ on_key_release_event (unused (GtkWidget *widget),
        break;
     }
 
-    pitch = SCORE_PITCH (pitch_name, SCORE_PITCH_ACCIDENTAL_NATURAL);
+    pitch = SCORE_PITCH (pitch_name, scherzo->keyboard_accidental);
 
     if ((key->keyval >= GDK_KEY_A && key->keyval <= GDK_KEY_G) ||
        (key->keyval >= GDK_KEY_a && key->keyval <= GDK_KEY_g))
@@ -989,8 +999,9 @@ main (int argc, char *argv[])
 
     scherzo.chord = NULL;
 
-    /* Default to octave 4 for computer keyboard keypresses. */
+    /* Default to octave 4 and natural for computer keyboard keypresses. */
     scherzo.keyboard_octave = 4;
+    scherzo.keyboard_accidental = SCORE_PITCH_ACCIDENTAL_NATURAL;
 
     note_group_init (scherzo.ctx, &scherzo.notes_pressed);
     note_group_init (scherzo.ctx, &scherzo.notes_pedaled);