// // Programmer: Craig Stuart Sapp // Creation Date: Wed Oct 24 10:08:24 PDT 2001 // Last Modified: Fri Mar 29 09:37:12 PST 2002 (fixed bib recs at end of data) // Last Modified: Wed Jun 24 15:37:46 PDT 2009 (updated for GCC 4.4) // Filename: ...sig/examples/all/hum2gmn.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/hum2gmn.cpp // Syntax: C++; museinfo // // Description: Converts a Humdrum file into Guido Music Notation. // // Reference: http://www.salieri.org/GUIDO // Reference: http://guidolib.sourceforge.net // // Status: Initial stages of development // // Things todo: beams // articulations (except staccatos) // ties // lyrics // multiple voices on a staff // stem direction markers // double barline encodings? // tempo markings? // etc. // // Things done: systems, notes, rhythms, slurs, clefs, time sigs, key sigs, // grace notes, staccatos. // // #include "humdrum.h" #include #include #include #ifndef OLDCPP #include #else #include #endif #ifndef VISUAL #include #endif // function declarations: void checkOptions (Options& opts, int argc, char** argv); void example (void); void convertToGMN (HumdrumFile& hfile); void convertPartToGMN (HumdrumFile& hfile, int part, int startline); void convertMeasureToGMN (HumdrumFile& hfile, int part, int line); int convertInterpretationToGMN(HumdrumFile& hfile, int part, int line); void convertNoteDataToGMN (HumdrumFile& hfile, int part, int line); void convertNoteToGMN (const char* note, int graceQ); void convertGlobalComment (HumdrumRecord& globalcomment); void convertBibliography (HumdrumRecord& bibrec); void processHeader (HumdrumFile& hfile); void processFooter (HumdrumFile& hfile); void print (const char* data); void usage (const char* command); int getPartSpine (HumdrumFile& hfile, int part, int line); void resetGlobals (void); void printTitleComposer (HumdrumFile& hfile); // User interface variables: Options options; int debugQ = 0; // used with the --debug option int cautionaryQ = 1; // used with the --nocaution option int reverseQ = 0; // reverse the ordering of the parts int quietQ = 0; // don't add extra information // Global state information int Goctave = -99; // for displaying octave after a note double Gduration = -99.0; // for sticky rhythms int Gnoteinit = 0; // for marking when the first note is written char lastchar = '\0'; // last printed character in print stream int Gline =0; // for error warnings int Gpartinit = 0; // for identifying the first part in the file. ////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { checkOptions(options, argc, argv); // process the command-line options HumdrumFile hfile(options.getArg(1).c_str()); hfile.analyzeRhythm(); convertToGMN(hfile); return 0; } ////////////////////////////////////////////////////////////////////////// ////////////////////////////// // // checkOptions -- // void checkOptions(Options& opts, int argc, char* argv[]) { opts.define("debug=b", "print debug information"); opts.define("nocaution=b", "print cautionary accidentals"); opts.define("r|reverse=b", "reverse the order of the parts"); 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, Oct 2001" << endl; exit(0); } else if (opts.getBoolean("version")) { cout << argv[0] << ", version: 24 Oct 2001" << endl; cout << "compiled: " << __DATE__ << endl; cout << MUSEINFO_VERSION << endl; exit(0); } else if (opts.getBoolean("help")) { usage(opts.getCommand().c_str()); exit(0); } else if (opts.getBoolean("example")) { example(); exit(0); } debugQ = opts.getBoolean("debug"); cautionaryQ = !opts.getBoolean("nocaution"); reverseQ = opts.getBoolean("reverse"); } ////////////////////////////// // // example -- // void example(void) { } ////////////////////////////// // // convertToGMN -- // void convertToGMN(HumdrumFile& hfile) { // find the start of the data and count how many parts there are int i, j; int parts = 0; Array partspines; partspines.setSize(100); partspines.setSize(0); partspines.allowGrowth(); int startline = 0; for (i=0; i"); #endif print("\n"); } } ////////////////////////////// // // convertPartToGMN -- // void convertPartToGMN(HumdrumFile& hfile, int part, int startline) { static int staffno = 1; static char buffer[1024] = {0}; print("[ "); // beginning of part marker sprintf(buffer, "\\staff<%d> ", staffno++); print(buffer); if (Gpartinit == 0) { printTitleComposer(hfile); print("\n\t\\systemFormat "); print("\n\t\\barFormat "); print("\n\t\\set "); } int i; int done = 0; for (i=startline+1; i"); } if (strncmp(hfile[i][0], "!!!COM", 6) == 0) { cptr = strchr(hfile[i][0], ','); if (cptr == NULL) { cptr = strchr(hfile[i][0], ':'); } if (cptr == NULL) { continue; } cptr++; while (cptr[0] == ' ') { cptr++; } if (cptr[0] != '\0') { print("\n\t\\composer<\""); } else { continue; } while (cptr[0] != '\0') { if (cptr[0] == '\"') { print("\\\'"); } else { buffer[0] = cptr[0]; buffer[1] = '\0'; print(buffer); } cptr++; } cptr = strchr(hfile[i][0], ':'); if (cptr != NULL) { cptr++; while (cptr[0] == ' ') { cptr++; } if (cptr[0] == '\0') { print("\">"); continue; } print(" "); while (cptr[0] != ',' && cptr[0] != '\0') { if (cptr[0] == '\"') { print("\\\'"); } else { buffer[0] = cptr[0]; buffer[1] = '\0'; print(buffer); } cptr++; } } print("\">"); } } } } ////////////////////////////// // // getPartSpine -- get the spine number for the first // occurance of the part in the given line. // int getPartSpine(HumdrumFile& hfile, int part, int line) { int i; int output = -1; for (i=0; i