/* Music composition assistant */

#include "pitch.h"
#include "noteNode.h"
#include "noteSeq.h"
#include <stdio.h>
#include <ctype.h>  /* for character function isalpha */

/* print composer's operation menu 
   read desired menu option
   returns a lower-case letter
   input line cleared 
*/
char
printAndChooseMenu ();

int
main (void)
{
  /* pointer to first note of the melody */
  noteNode* melodyFirst = NULL;

  printf("Music composition assistant\n");

  int done = 0;
  while (!done)
    {
      char option = printAndChooseMenu();

      switch (option)
        {
        case 'n':
          setNull(&melodyFirst);
          break;
        case 'a':
          addAtEnd(&melodyFirst);
          break;
        case 'p':
          printTuneTable(melodyFirst);
          break;
        case 'q':
          printf ("program completed\n");
          return 0;
        default:
          printf ("unrecognized option\n");
        }
    }

  return 0;
}


/* print composer's operation menu 
   read desired menu option
   returns a lower-case letter
   input line cleared 
*/
char
printAndChooseMenu ()
{
  printf("menu options: \n");
  printf("  n:  set melody to NULL\n");
  printf("  a:  add notes to end of melody\n");
  printf("  p:  print table of current notes in melody\n");
  printf("  q:  quit\n");

  char ch;
  while (!isalpha(ch = getchar())); /* get menu option */
  while (getchar() != '\n');        /* strip remaining characters on line */

  return tolower(ch);
}
