From: Carl Worth Date: Mon, 30 Sep 2013 00:24:19 +0000 (-0700) Subject: Use a pitch_t rather than a score_note_t for challenge X-Git-Url: https://git.cworth.org/git?p=scherzo;a=commitdiff_plain;h=e5ec7a294da3e46c83d858f711405febbad2651b Use a pitch_t rather than a score_note_t for challenge This continues the recent trend of removing the use of this score-specific data structure from the scherzo layer above score. --- diff --git a/scherzo.c b/scherzo.c index b8dd611..109de6d 100644 --- a/scherzo.c +++ b/scherzo.c @@ -32,10 +32,11 @@ typedef struct challenge { + int active; bin_t *bin; int item_index; score_staff_t *staff; - score_note_t *note; + pitch_t pitch; int satisfied; int mistaken; @@ -152,8 +153,8 @@ on_key_press_event (GtkWidget *widget, pitch_name_t pitch_name = PITCH_NATURAL (C, 0); pitch_t pitch; - if (scherzo->challenge.note) - octave = PITCH_OCTAVE (scherzo->challenge.note->pitch); + if (scherzo->challenge.active) + octave = PITCH_OCTAVE (scherzo->challenge.pitch); else octave = scherzo->keyboard_octave; @@ -257,8 +258,8 @@ on_key_release_event (unused (GtkWidget *widget), pitch_name_t pitch_name = PITCH_NAME_C; pitch_t pitch; - if (scherzo->challenge.note) - octave = PITCH_OCTAVE (scherzo->challenge.note->pitch); + if (scherzo->challenge.active) + octave = PITCH_OCTAVE (scherzo->challenge.pitch); else octave = scherzo->keyboard_octave; @@ -1154,15 +1155,9 @@ _select_challenge (scherzo_t *scherzo) item_t *item; challenge_t *challenge = &scherzo->challenge; pitch_name_t pitch_name; - pitch_t pitch; int octave; char *s; - if (challenge->note) { - score_remove_note (challenge->note); - challenge->note = NULL; - } - mnemon_select_item (&scherzo->mnemon, &challenge->bin, &challenge->item_index, @@ -1220,10 +1215,9 @@ _select_challenge (scherzo_t *scherzo) octave = *s - '0'; - pitch = PITCH (pitch_name, PITCH_ACCIDENTAL_NATURAL, octave); + challenge->pitch = PITCH (pitch_name, PITCH_ACCIDENTAL_NATURAL, octave); - challenge->note = score_staff_add_note (challenge->staff, pitch, - SCORE_DURATION_WHOLE); + challenge->active = 1; challenge->satisfied = 0; challenge->mistaken = 0; } @@ -1234,10 +1228,10 @@ _judge_pitch (scherzo_t *scherzo, pitch_t pitch) { challenge_t *challenge = &scherzo->challenge; - if (! challenge->note) + if (! challenge->active) return; - if (pitch == challenge->note->pitch) + if (pitch == challenge->pitch) challenge->satisfied = 1; else challenge->mistaken = 1; @@ -1250,7 +1244,7 @@ _score_challenge (scherzo_t *scherzo) { challenge_t *challenge = &scherzo->challenge; - if (! challenge->note) + if (! challenge->active) return; if (! challenge->satisfied) @@ -1369,7 +1363,7 @@ main (int argc, char *argv[]) /* XXX: Should create a default file if one cannot be loaded. */ mnemon_load_category (&scherzo.mnemon, "scherzo-notes"); - scherzo.challenge.note = NULL; + scherzo.challenge.active = 0; /* _select_challenge (&scherzo); */