-
-static void
-mnemon_show_challenge (mnemon_t *mnemon,
- challenge_type_t challenge_type,
- const char *challenge)
-{
- const char *program;
- char *command;
-
- if (challenge_type == CHALLENGE_TYPE_TEXT) {
- printf ("%s\n", challenge);
- return;
- }
-
- /* XXX: Yes, shelling out to system is total cheese. The planned
- * fix here is to bring graphical display in process, (or at least
- * have a custom external program that accepts image filenames on
- * stdin.
- */
- switch (challenge_type) {
- case CHALLENGE_TYPE_TEXT:
- ASSERT_NOT_REACHED;
- break;
- case CHALLENGE_TYPE_IMAGE:
- program = "xli -gamma 2.2";
- break;
- case CHALLENGE_TYPE_AUDIO:
- program = "play";
- break;
- case CHALLENGE_TYPE_MIDI:
- program = "timidity -Os";
- break;
- }
-
- xasprintf (&command, "%s %s/%s >/dev/null 2>&1 &",
- program,
- mnemon->dir_name,
- challenge);
- system (command);
- free (command);
-}
-
-static void
-mnemon_hide_challenge (mnemon_t *mnemon, challenge_type_t challenge_type)
-{
- char * command;
-
- if (challenge_type != CHALLENGE_TYPE_IMAGE)
- return;
-
- /* XXX: And this is just embarrassing (obviously wrong in several
- * ways). Hopefully I'll amend away any commit that includes this.
- */
- xasprintf (&command, "killall xli");
- system (command);
- free (command);
-}
-
-static void
-mnemon_do_challenges (mnemon_t *mnemon)
-{
- bin_t *bin;
- int item_index;
- item_t *item;
- category_t *category;
- char *response;
- int i;
-
- /* Count the number of items with negative scores. */
- mnemon->unlearned = 0;
- for (i = 0; i < mnemon->num_bins; i++) {
- bin = &mnemon->bins[i];
- if (bin->score >= 0)
- break;
- mnemon->unlearned += bin->num_items;
- }
-
- mnemon->to_introduce -= mnemon->unlearned;
- if (mnemon->to_introduce < 0)
- mnemon->to_introduce = 0;
-
- /* Get rid of bin with score of 0 if we aren't going to be
- * introducing anything from it. */
- if (mnemon->to_introduce == 0) {
- bin = mnemon_get_bin (mnemon, 0);
- mnemon_remove_bin (mnemon, bin);
- }
-
- if (mnemon->unlearned) {
- printf ("You've got %d items to learn already. ", mnemon->unlearned);
- if (mnemon->to_introduce)
- printf ("I'll introduce %d more as we go.", mnemon->to_introduce);
- printf ("\n");
- } else {
- printf ("Introducing %d new items.\n", mnemon->to_introduce);
- }
- printf ("\n");
-
- do {
- struct timeval start, end;
-
- mnemon_select_item (mnemon, &bin, &item_index, &category);
- item = bin->items[item_index];
-
- while (1) {
- if (category->time_limit > 0.0) {
- response = readline ("The next one is timed. Press enter when ready:");
- free (response);
- }
-
- mnemon_show_challenge (mnemon, category->challenge_type,
- item->challenge);
-
- gettimeofday (&start, NULL);
- response = readline ("> ");
- gettimeofday (&end, NULL);
-
- mnemon_hide_challenge (mnemon, category->challenge_type);
-
- /* Terminate on EOF */
- if (response == NULL) {
- printf ("\n");
- return;
- }
-
- if (response[0] == '/') {
- mnemon_handle_command (mnemon, response + 1);
- free (response);
- } else {
- break;
- }
- }
-
- mnemon_handle_response (mnemon, bin, item_index,
- item, response,
- (end.tv_sec + end.tv_usec / 1e6) -
- (start.tv_sec + start.tv_usec / 1e6),
- category->time_limit);
- free (response);
-
- /* Replay audio challenges for reinforcement. */
- if (category->repeat)
- {
- mnemon_show_challenge (mnemon, category->challenge_type,
- item->challenge);
- printf ("%s\n", item->challenge);
- sleep (2);
- }
- } while (mnemon->to_introduce ||
- mnemon->unlearned ||
- mnemon->to_master > 0);
-}
-
-int
-main (int argc, char *argv[])
-{
- mnemon_t mnemon;
- char *response;
-
- srand (time (NULL));
-
- mnemon_init (&mnemon);
-
- mnemon_load (&mnemon);
-
- mnemon_do_challenges (&mnemon);
-
- mnemon_save (&mnemon);
-
- mnemon_fini (&mnemon);
-
- mnemon_init (&mnemon);
- mnemon_load (&mnemon);
-
- printf ("Great job.\nHere are your current results:\n");
- mnemon_print_histogram (&mnemon, NULL, 0);
- response = readline ("Press enter to quit.\n");
- free (response);
-
- mnemon_fini (&mnemon);
-
- return 0;
-}