]> git.cworth.org Git - scherzo/blobdiff - scherzo.c
Add some color coding of input notes.
[scherzo] / scherzo.c
index c285891f0a43d00167f4beb5d164189c227ccfa5..2d43aee0bd5d8aacdc6e0fe43910735b2a8331d6 100644 (file)
--- a/scherzo.c
+++ b/scherzo.c
@@ -92,7 +92,7 @@ on_expose_event_draw (GtkWidget *widget,
     cairo_paint (cr);
 
     /* Add some padding on the sides and top */
-    cairo_translate (cr, pad, 2 * scherzo->staff_height);
+    cairo_translate (cr, pad, scherzo->staff_height);
     score_set_staff_height (score, scherzo->staff_height);
     score_set_width (score, widget_width - 2 * pad);
 
@@ -194,7 +194,7 @@ scherzo_add_note_midi (scherzo_t *scherzo, unsigned char midi_note)
 
     _midi_to_score_pitch_and_octave (midi_note, &pitch, &octave);
 
-    note = score_staff_add_note (staff, pitch, octave, SCORE_DURATION_WHOLE);
+    note = score_add_note (staff, pitch, octave, SCORE_DURATION_WHOLE);
 
     scherzo->num_notes_pressed++;
     scherzo->notes_pressed = talloc_realloc (scherzo->ctx,
@@ -214,20 +214,17 @@ scherzo_add_note_midi (scherzo_t *scherzo, unsigned char midi_note)
 static void
 scherzo_remove_note_midi (scherzo_t *scherzo, unsigned char midi_note)
 {
-    score_staff_t *staff;
     score_pitch_t pitch;
     int octave;
     score_note_t *note;
     int i;
 
-    staff = scherzo->challenge.staff;
-
     _midi_to_score_pitch_and_octave (midi_note, &pitch, &octave);
 
     for (i = 0; i < scherzo->num_notes_pressed; i++) {
        note = scherzo->notes_pressed[i];
        if (note->pitch == pitch && note->octave == octave) {
-           score_staff_remove_note (staff, note);
+           score_remove_note (note);
            if (i < scherzo->num_notes_pressed - 1) {
                memmove (scherzo->notes_pressed + i,
                         scherzo->notes_pressed + i + 1,
@@ -251,7 +248,7 @@ _select_challenge (scherzo_t *scherzo)
     char *s;
 
     if (challenge->note) {
-       score_staff_remove_note (challenge->staff, challenge->note);
+       score_remove_note (challenge->note);
        challenge->note = NULL;
     }
 
@@ -312,8 +309,8 @@ _select_challenge (scherzo_t *scherzo)
 
     octave = *s - '0';
 
-    challenge->note = score_staff_add_note (challenge->staff, pitch, octave,
-                                           SCORE_DURATION_WHOLE);
+    challenge->note = score_add_note (challenge->staff, pitch, octave,
+                                     SCORE_DURATION_WHOLE);
     challenge->satisfied = 0;
     challenge->mistaken = 0;
 }
@@ -328,10 +325,12 @@ _judge_note (scherzo_t *scherzo, score_note_t *note)
        note->octave == challenge->note->octave)
     {
        challenge->satisfied = 1;
+       score_set_note_color_rgb (note, 18/256., 130/256., 28/256.); /* green */
     }
     else
     {
        challenge->mistaken = 1;
+       score_set_note_color_rgb (note, 184/256., 4/256., 22/256.); /* red */
     }
 }
 
@@ -361,6 +360,7 @@ on_midi_input (unused (GIOChannel *channel),
     ssize_t remaining;
     snd_seq_event_t event;
     score_note_t *note;
+    int need_redraw = FALSE;
 
     remaining = read (scherzo->midi_fd, buf, MIDI_BUF_SIZE);
 
@@ -372,6 +372,7 @@ on_midi_input (unused (GIOChannel *channel),
                                          next, remaining, &event);
 
        remaining -= consumed;
+       next += consumed;
 
        switch (event.type) {
        case SND_SEQ_EVENT_NONE:
@@ -380,12 +381,12 @@ on_midi_input (unused (GIOChannel *channel),
        case SND_SEQ_EVENT_NOTEON:
            note = scherzo_add_note_midi (scherzo, event.data.note.note);
            _judge_note (scherzo, note);
-           gtk_widget_queue_draw (scherzo->window);
+           need_redraw = TRUE;
            break;
        case SND_SEQ_EVENT_NOTEOFF:
            scherzo_remove_note_midi (scherzo, event.data.note.note);
            _score_challenge (scherzo);
-           gtk_widget_queue_draw (scherzo->window);
+           need_redraw = TRUE;
            break;
        case SND_SEQ_EVENT_CLOCK:
            /* Ignore for now as my piano sends a constant stream of these. */
@@ -399,7 +400,10 @@ on_midi_input (unused (GIOChannel *channel),
            break;
        }
     }
-    
+
+    if (need_redraw)
+       gtk_widget_queue_draw (scherzo->window);
+
     /* Return TRUE to continue to get called in the future. */
     return TRUE;
 }
@@ -418,7 +422,7 @@ main (int argc, char *argv[])
     scherzo.ctx = talloc_new (NULL);
 
     scherzo.score = score_create (scherzo.ctx);
-    scherzo.staff_height = 48;
+    scherzo.staff_height = 100;
     score_set_staff_height (scherzo.score, scherzo.staff_height);
 
     score_add_brace (scherzo.score, 2);
@@ -455,7 +459,7 @@ main (int argc, char *argv[])
 
     scherzo.window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 
-    gtk_window_set_default_size (GTK_WINDOW (scherzo.window), 600, 400);
+    gtk_window_set_default_size (GTK_WINDOW (scherzo.window), 1000, 600);
 
     g_signal_connect (scherzo.window, "delete-event",
                      G_CALLBACK (on_delete_event_quit), NULL);