//
// Programmer:    Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Mon Feb 25 17:33:53 PST 2002
// Last Modified: Thu Aug  2 14:35:57 PDT 2012 added -e option
// Filename:      ...sig/examples/all/mus2pmx2.cpp
// Web Address:   http://sig.sapp.org/examples/museinfo/score/mus2pmx2.cpp
// Syntax:        C++; museinfo
//
// Description:   Convert SCORE binary files into ASCII using the 
//                ScorePage class.
//

#include "ScorePage.h"
#include "Options.h"

#include <stdlib.h>

#ifndef OLDCPP
   #include <fstream>
#else
   #include <fstream.h>
#endif


// interface variables:
Options options;
int     verboseQ  = 0;    // used with -v option
int     sortQ     = 0;    // used with -s option
int     extraQ    = 0;    // used with -e option
int     analysisQ = 0;    // used with -a option
int     roundQ    = 1;

int main(int argc, char** argv) {
   options.define("v|verbose=b",   "display debugging information in output");
   options.define("s|sort=b",      "sort data by staff in output");
   options.define("e|extra=b",     "add extra parameter analysis data");
   options.define("a|analysis=b",  "generate music analysis of data");
   options.process(argc, argv);
   verboseQ  = options.getBoolean("verbose");
   sortQ     = options.getBoolean("sort");
   analysisQ = options.getBoolean("analysis");
   extraQ    = options.getBoolean("extra");

   if (options.getArgCount() == 0) {
      cout << "Usage: " << argv[0] << " input.mus " << endl;
      exit(1);
   }

   ScorePage page;
   for (int i=1; i<=options.getArgCount(); i++) {
      if (i > 1) {
         cout << "##PAGEBREAK\n";
      }
      if (options.getArgCount() > 1) {
         cout << "##FILE:\t" << options.getArg(i) << "\n";
      }
      page.clear();
      page.readBinary(options.getArg(i), verboseQ); 
      if (sortQ) {
         page.sortByStaff();
      }
      if (analysisQ) {
         page.analyzeSystems();
         page.analyzePitch();
      }
      if (extraQ) {
         page.analyzeContent();
         page.printAsciiWithExtraParameters(cout, roundQ, verboseQ);
      } else {
         page.printAscii(cout, roundQ, verboseQ);
      }
   }

   return 0;
}


// md5sum: daeefb0b33e19f788bdab6fc423efdae mus2pmx2.cpp [20050403]