]> git.cworth.org Git - scherzo/commitdiff
Add some color coding of input notes.
authorCarl Worth <cworth@cworth.org>
Wed, 28 Sep 2011 00:12:39 +0000 (17:12 -0700)
committerCarl Worth <cworth@cworth.org>
Wed, 28 Sep 2011 00:12:39 +0000 (17:12 -0700)
Red for an incorrect note, and green for correct. (The challenge notes
remain black.)

scherzo.c
score.c
score.h

index 98f70bd99ff2485e0cf3e0b4ad542341353f41f5..2d43aee0bd5d8aacdc6e0fe43910735b2a8331d6 100644 (file)
--- a/scherzo.c
+++ b/scherzo.c
@@ -325,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 */
     }
 }
 
@@ -420,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);
@@ -457,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);
diff --git a/score.c b/score.c
index 26c5a02818e6ba60ad6f77c7e00141719ff16ddb..db07d5e9d57f33436688db8741d2a4442d519760 100644 (file)
--- a/score.c
+++ b/score.c
@@ -75,10 +75,10 @@ score_create (void *ctx)
        return NULL;
 
     /* Also sets space_height and line_width */
-    score_set_staff_height (score, 24);
+    score_set_staff_height (score, 76);
 
     /* Just to have some nominal width. */
-    score->width = 800;
+    score->width = 1000;
 
     score->braces = NULL;
     score->num_braces = 0;
@@ -243,7 +243,10 @@ _draw_note (score_t *score, cairo_t *cr,
        }
     }
 
-    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
+    cairo_set_source_rgb (cr,
+                         note->color.r,
+                         note->color.g,
+                         note->color.b);
     cairo_show_glyphs (cr, &note_glyph, 1);
 
     cairo_restore (cr);
@@ -442,6 +445,10 @@ score_add_note (score_staff_t *staff,
     note->octave = octave;
     note->duration = duration;
 
+    note->color.r = 0.0;
+    note->color.g = 0.0;
+    note->color.b = 0.0;
+
     line = _score_note_to_line (staff, note);
     if (line < 0) {
        int lines = (int) (- line);
@@ -496,6 +503,17 @@ score_remove_note (score_note_t *note)
     }
 }
 
+void
+score_set_note_color_rgb (score_note_t *note,
+                         double r,
+                         double g,
+                         double b)
+{
+    note->color.r = r;
+    note->color.g = g;
+    note->color.b = b;
+}
+
 score_note_t *
 score_staff_find_note (score_staff_t *staff,
                       score_pitch_t pitch,
diff --git a/score.h b/score.h
index 531710348a6a2caad7b1222e622fc8b8d8146cb6..d1f0406725944e2c66e3132b169bc3541bf8e1a9 100644 (file)
--- a/score.h
+++ b/score.h
@@ -132,6 +132,12 @@ typedef struct score_note
     score_pitch_t pitch;
     int octave;
     score_duration_t duration;
+
+    struct {
+       double r;
+       double g;
+       double b;
+    } color;
 } score_note_t;
 
 typedef enum score_clef
@@ -189,6 +195,12 @@ score_add_note (score_staff_t *staff,
 void
 score_remove_note (score_note_t *note);
 
+void
+score_set_note_color_rgb (score_note_t *note,
+                         double r,
+                         double g,
+                         double b);
+
 /* Return the first note on the given staff with the given pitch,
  * octave, and durations. Returns NULL if no match is found. */
 score_note_t *