]> git.cworth.org Git - scherzo/commitdiff
Use a pitch_t rather than a score_note_t for challenge
authorCarl Worth <cworth@cworth.org>
Mon, 30 Sep 2013 00:24:19 +0000 (17:24 -0700)
committerCarl Worth <cworth@cworth.org>
Mon, 30 Sep 2013 00:25:33 +0000 (17:25 -0700)
This continues the recent trend of removing the use of this
score-specific data structure from the scherzo layer above score.

scherzo.c

index b8dd611a0a7e9ae9cff49b08b1a1090e4518acfc..109de6d06b2ccce29e193686f0cd0f9f35059561 100644 (file)
--- a/scherzo.c
+++ b/scherzo.c
 
 typedef struct challenge
 {
 
 typedef struct challenge
 {
+    int active;
     bin_t *bin;
     int item_index;
     score_staff_t *staff;
     bin_t *bin;
     int item_index;
     score_staff_t *staff;
-    score_note_t *note;
+    pitch_t pitch;
 
     int satisfied;
     int mistaken;
 
     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;
 
     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;
 
     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;
 
     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;
 
     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;
     item_t *item;
     challenge_t *challenge = &scherzo->challenge;
     pitch_name_t pitch_name;
-    pitch_t pitch;
     int octave;
     char *s;
 
     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,
     mnemon_select_item (&scherzo->mnemon,
                        &challenge->bin,
                        &challenge->item_index,
@@ -1220,10 +1215,9 @@ _select_challenge (scherzo_t *scherzo)
 
     octave = *s - '0';
 
 
     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;
 }
     challenge->satisfied = 0;
     challenge->mistaken = 0;
 }
@@ -1234,10 +1228,10 @@ _judge_pitch (scherzo_t *scherzo, pitch_t pitch)
 {
     challenge_t *challenge = &scherzo->challenge;
 
 {
     challenge_t *challenge = &scherzo->challenge;
 
-    if (! challenge->note)
+    if (! challenge->active)
        return;
 
        return;
 
-    if (pitch == challenge->note->pitch)
+    if (pitch == challenge->pitch)
        challenge->satisfied = 1;
     else
        challenge->mistaken = 1;
        challenge->satisfied = 1;
     else
        challenge->mistaken = 1;
@@ -1250,7 +1244,7 @@ _score_challenge (scherzo_t *scherzo)
 {
     challenge_t *challenge = &scherzo->challenge;
 
 {
     challenge_t *challenge = &scherzo->challenge;
 
-    if (! challenge->note)
+    if (! challenge->active)
        return;
 
     if (! challenge->satisfied)
        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");
 
     /* 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);
 */
 /*
     _select_challenge (&scherzo);
 */