//
// Programmer:    Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Mon Feb 25 18:06:08 PST 2002
// Last Modified: Mon Feb 25 18:06:11 PST 2002
// Filename:      ...sig/examples/all/pmx2mus2.cpp
// Web Address:   http://sig.sapp.org/examples/museinfo/score/pmx2mus2.cpp
// Syntax:        C++; museinfo
//
// Description:   Convert SCORE PMX file into binary format.
//

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

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


// interface variables:
Options options;
int     verboseQ = 0;             // used with the -v option
const char* outputfilename = "";  // used with the -o option


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

int main(int argc, char** argv) {
   options.define("verbose=b", "display debugging information in output");
   options.define("v|version|ver=d:3.0", "for 2 or 4 byte counter");
   options.define("o|output=s:", "output filename if specified");
   options.process(argc, argv);
   verboseQ = options.getBoolean("verbose");
   outputfilename = options.getString("output");
   char namebuffer[1024] = {0};

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

   ScorePage scorepage;
   for (int i=1; i<=options.getArgCount(); i++) {
      scorepage.readAscii(options.getArg(i));
      scorepage.setVersion(options.getDouble("version"));

      if (strcmp(outputfilename, "") != 0) {
         strcpy(namebuffer, outputfilename);
      } else {
         strcpy(namebuffer, options.getArg(i));
         char* ptr = strrchr(namebuffer, '.');
         if (ptr != NULL) {
            ptr[0] = '\0';
            strcat(namebuffer, ".mus");
         } else {
            strcat(namebuffer, ".mus");
         }
      }
      scorepage.writeBinary(namebuffer);
   }

   return 0;
}



// md5sum: 1e3829ca309118291de36706b4400e82 pmx2mus2.cpp [20090406]