From 6d1dd804ce022f0fbc3cebc853edcab5c81d5abc Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 27 Sep 2011 17:12:39 -0700 Subject: [PATCH] Add some color coding of input notes. Red for an incorrect note, and green for correct. (The challenge notes remain black.) --- scherzo.c | 6 ++++-- score.c | 24 +++++++++++++++++++++--- score.h | 12 ++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/scherzo.c b/scherzo.c index 98f70bd..2d43aee 100644 --- 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 26c5a02..db07d5e 100644 --- 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, ¬e_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 5317103..d1f0406 100644 --- 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 * -- 2.43.0