]> git.cworth.org Git - mnemon/commitdiff
Add a new midi challenge type
authorCarl Worth <cworth@cworth.org>
Thu, 2 Apr 2009 15:13:05 +0000 (08:13 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 2 Apr 2009 15:13:05 +0000 (08:13 -0700)
Doing this instead of the audio type means we can save file size,
(these midi files are much smaller than resulting .wav files), and
also skip once processing step in preparing the files.

Using the -Os option to timidity means that if we have two overlapping
invocations of timidity the second one won't fail due to contention
for /dev/dsp.

mnemon.c

index 56a518d8ed752e63c06023d1c884474089346b76..3523ef822685c33489b64f9e63e619053d4237ed 100644 (file)
--- a/mnemon.c
+++ b/mnemon.c
@@ -64,7 +64,8 @@ typedef enum {
 typedef enum {
     CHALLENGE_TYPE_TEXT,
     CHALLENGE_TYPE_IMAGE,
-    CHALLENGE_TYPE_AUDIO
+    CHALLENGE_TYPE_AUDIO,
+    CHALLENGE_TYPE_MIDI
 } challenge_type_t;
 
 typedef struct _category {
@@ -288,6 +289,9 @@ category_print (category_t  *category,
     case CHALLENGE_TYPE_AUDIO:
        fprintf (file, "audio");
        break;
+    case CHALLENGE_TYPE_MIDI:
+       fprintf (file, "midi");
+       break;
     }
     fprintf (file, "\n\n");
 
@@ -654,6 +658,8 @@ mnemon_load_category (mnemon_t              *mnemon,
                category->challenge_type = CHALLENGE_TYPE_IMAGE;
            } else if (strcmp (value, "audio") == 0) {
                category->challenge_type = CHALLENGE_TYPE_AUDIO;
+           } else if (strcmp (value, "midi") == 0) {
+               category->challenge_type = CHALLENGE_TYPE_MIDI;
            } else {
                fprintf (stderr, "Unknown value for \"challenge\" option \"%s\" at %s:%d\n",
                         value, path, line_count);
@@ -1189,6 +1195,9 @@ mnemon_show_challenge (mnemon_t *mnemon,
     case CHALLENGE_TYPE_AUDIO:
        program = "play";
        break;
+    case CHALLENGE_TYPE_MIDI:
+       program = "timidity -Os";
+       break;
     }
 
     xasprintf (&command, "%s %s/%s >/dev/null 2>&1 &",
@@ -1298,10 +1307,13 @@ mnemon_do_challenges (mnemon_t *mnemon)
        free (response);
 
        /* Replay audio challenges for reinforcement. */
-       if (category->challenge_type == CHALLENGE_TYPE_AUDIO) {
+       if (category->challenge_type == CHALLENGE_TYPE_AUDIO ||
+           category->challenge_type == CHALLENGE_TYPE_MIDI)
+       {
            mnemon_show_challenge (mnemon, category->challenge_type,
                                   item->challenge);
-           sleep (1);
+           printf ("%s\n", item->challenge);
+           sleep (2);
        }
     } while (mnemon->to_introduce ||
             mnemon->unlearned ||