//
// Programmer:    Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Sun Jul 29 19:52:43 PDT 2012
// Last Modified: Sun Jul 29 19:52:46 PDT 2012
// Filename:      ...sig/examples/all/sworkinfo.cpp
// Web Address:   http://sig.sapp.org/examples/museinfo/score/sworkinfo.cpp
// Syntax:        C++; museinfo
//
// Description:   Display staff information for a SCORE page file.
//

#include "ScorePageSet.h"
#include "Options.h"

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


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

// interface variables:
Options options;
int     verboseQ    = 0;       // used with -v option
int     fullQ       = 0;       // used with -f option
int     debugQ      = 0;       // used with --debug option



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

int main(int argc, char** argv) {
   checkOptions(options, argc, argv);

   ScorePageSet work;
   for (int i=1; i<=options.getArgCount(); i++) {
      cout << "PROCESSING " << options.getArg(i) << endl;
      work.appendRead(options.getArg(i), verboseQ);
   }
   work.analyzeContent();


   if (fullQ) { 
      displayFullWork(work);
   } else {
      cout << "Duration of work: " << work.getDuration() 
           << " quarter notes" << endl;
   
      int i;
      for (i=0; i<work.getPageCount(); i++) {
         cout << "Duration of page " << i+1 << " is " 
              << work[i].getPageDuration() << endl;
      }
   }
   return 0;
}


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

//////////////////////////////
//
// displayFullWork --
//

void displayFullWork(ScorePageSet& work) {
   int i;
   double absbeat;
   int count = work.getItemCount();
   for (i=0; i<count; i++) {
      absbeat = work.getItem(i).getAbsBeat();
      cout << absbeat << "::\t"; 
      work.getItem(i).printAscii(cout);
      cout << endl;
   }
}



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

void checkOptions(Options& opts, int argc, char* argv[]) {
   opts.define("v|verbose=b", "verbose display of information");
   opts.define("f|full=b",    "full view");

   opts.define("debug=b");              // determine bad input line num
   opts.define("author=b");             // author of program
   opts.define("version=b");            // compilation info
   opts.define("example=b");            // example usages
   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, Jul 2012" << endl;
      exit(0);
   } else if (opts.getBoolean("version")) {
      cout << argv[0] << ", version: 29 Jul 2012" << endl;
      cout << "compiled: " << __DATE__ << endl;
      exit(0);
   } else if (opts.getBoolean("help")) {
      usage(opts.getCommand());
      exit(0);
   } else if (opts.getBoolean("example")) {
      example();
      exit(0);
   }

   verboseQ  = opts.getBoolean("verbose");
   debugQ    = opts.getBoolean("debug");
   fullQ     = opts.getBoolean("full");
   
}



//////////////////////////////
//
// example -- example usage of the quality program
//

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



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

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



// md5sum: ba2b7927dc383d3df8d82b5f3f3d3723 sworkinfo.cpp [20120729]