//
// Programmer:    Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Sun May 13 12:48:03 PDT 2001
// Last Modified: Sun May 13 12:48:06 PDT 2001
// Filename:      ...sig/examples/all/kern2notelist2.cpp
// Web Address: http://sig.sapp.org/examples/museinfo/humdrum/kern2notelist2.cpp
// Syntax:        C++; museinfo
//
// Description:   Generates a list of notes from the input along with their
//		  absolute position in the music, their duration and
//		  the metric level
// 

#include "humdrum.h"

#include <string.h>
#include <math.h>
#include <stdlib.h>

// function declarations
void   checkOptions(Options& opts, int argc, char* argv[]);
void   example(void);
void   usage(const char* command);

// user interface variables
Options      options;            // database for command-line arguments
int          quietQ = 0;         // display only data table or not
int          verboseQ = 1;       // display only data table or not
int          compoundQ  = 1;     // used with the -c option


///////////////////////////////////////////////////////////////////////////

int main(int argc, char* argv[]) {
   HumdrumFile infile;

   // process the command-line options
   checkOptions(options, argc, argv);

   // figure out the number of input files to process
   int numinputs = options.getArgCount();

   Array<double> absbeat;
   Array<int> pitch;
   Array<int> testset;
   Array<double> duration;
   Array<double> level;
   Array<double> coef;

   int i, j;
   for (i=0; i<numinputs || i==0; i++) {
      infile.clear();

      // if no command-line arguments read data file from standard input
      if (numinputs < 1) {
         infile.read(cin);
      } else {
         infile.read(options.getArg(i+1));
      }

      infile.getNoteArray(absbeat, pitch, duration, level);
      cout<<"**absbeat\t**base40\t**duration\t**level\n";
      for (j=0; j<pitch.getSize(); j++) {
         cout << absbeat[j]  << "\t"
              << pitch[j]    << "\t"
              << duration[j] << "\t"
              << level[j]    << "\n";
      }
      cout << "*-\t*-\t*-\t*-\n";
   }

   return 0;
}


///////////////////////////////////////////////////////////////////////////


//////////////////////////////
//
// checkOptions -- validate and process command-line options.
//

void checkOptions(Options& opts, int argc, char* argv[]) {
   opts.define("a|append=b",        "append analysis to data in output");   
   opts.define("q|quiet=b",         "suppress extra information");   
   opts.define("v|noverbose=b",     "suppress extra information");   
   opts.define("C|compound=b",      "don't try to use compound meters");   

   opts.define("debug=b",           "trace input parsing");   
   opts.define("author=b",          "author of the program");   
   opts.define("version=b",         "compilation information"); 
   opts.define("example=b",         "example usage"); 
   opts.define("h|help=b",          "short description"); 
   opts.process(argc, argv);
   
   // handle basic options:
   if (opts.getBoolean("author")) {
      cout << "Written by Craig Stuart Sapp, "
           << "craig@ccrma.stanford.edu, April 2001" << endl;
      exit(0);
   } else if (opts.getBoolean("version")) {
      cout << argv[0] << ", version: 13 April 2001" << endl;
      cout << "compiled: " << __DATE__ << endl;
      cout << MUSEINFO_VERSION << endl;
      exit(0);
   } else if (opts.getBoolean("help")) {
      usage(opts.getCommand());
      exit(0);
   } else if (opts.getBoolean("example")) {
      example();
      exit(0);
   }

   // compound diabled for now
   if (opts.getBoolean("compound")) {
      compoundQ = 0;
   } else {
      compoundQ = 0;
   }

   quietQ   = opts.getBoolean("quiet");
   verboseQ = !opts.getBoolean("noverbose");
}



//////////////////////////////
//
// example -- example usage of the maxent program
//

void example(void) {
   cout <<
   "                                                                        \n"
   << endl;
}



//////////////////////////////
//
// usage -- gives the usage statement for the quality program
//

void usage(const char* command) {
   cout <<
   "                                                                        \n"
   << endl;
}


// md5sum: 49d9f138257161c0484f1496ca21a7b0 kern2notelist2.cpp [20050403]