From: Carl Worth Date: Thu, 2 Apr 2009 15:13:05 +0000 (-0700) Subject: Add a new midi challenge type X-Git-Url: https://git.cworth.org/git?p=mnemon;a=commitdiff_plain;h=4fc1ac21aaa449a2a5c89259079715c2e8319877;hp=31b5189a8145b2b514d69165997e2e443f52dd52 Add a new midi challenge type 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. --- diff --git a/mnemon.c b/mnemon.c index 56a518d..3523ef8 100644 --- 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 ||