// // Programmer: Craig Stuart Sapp // Creation Date: Sat Apr 28 04:46:58 PDT 2001 // Last Modified: Sat Apr 28 04:47:03 PDT 2001 // Filename: ...sig/examples/all/kern2notelist.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/kern2notelist.cpp // Syntax: C++; museinfo // // Description: Converts kern data into the format used in // Director Musices, a program that genrates // computer-based performances of musical scores. // #include "humdrum.h" #include #include #include #include #include // function declarations void checkOptions (Options& opts, int argc, char* argv[]); void example (void); void usage (const char* command); void convertToDM(HumdrumFile& infile); void processTrack(HumdrumFile& infile, int track); void convertKernNoteToDM(HumdrumFile& infile, int line, int spine, int track); void printNote(int base40); void printFractionDuration(double duration); int parseInterpretation(HumdrumFile& infile, int line, int track); void addExtraStuff(void); void printPitchClass(int note); void getNoteArray(Array& notes, HumdrumFile& infile, int line, int spine); // user interface variables Options options; // database for command-line arguments // other variables: int key = -1; // for storing the key (base 40 number) int nameinit = 0; char name[128] = {0}; int bar = 0; // bar number int mode = -1; // for storing the mode (0 = major, 1 = minor) float metronome = -1.0; int metertop = -1; int meterbottom = -1; int start = -1; int terminus = -1; /////////////////////////////////////////////////////////////////////////// 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 absbeat; Array pitch; Array testset; Array duration; Array level; Array coef; for (int i=0; i= 0; i--) { // set global state variables to uninitialized key = -1; nameinit = 0; name[0] = '\0'; mode = -1; metronome = -1; metertop = -1; meterbottom = -1; bar = 0; processTrack(infile, i+1); } } ////////////////////////////// // // processTrack -- print out the specified track // void processTrack(HumdrumFile& infile, int track) { int status; int i, j; if (infile.getPickupDuration() > 0) { bar = 0; } else { bar = 1; } for (i=0; i i && track != infile.getMaxTracks()) { // skip over global comments after the first time: i = start; } if (terminus < i && terminus != -1 && track != 1) { // skip over global comments after the first time: break; } switch (infile[i].getType()) { case E_humrec_data: for (j=0; j notes; if (strcmp(element, ".") == 0) { return; } if (infile[line].getExInterpNum(spine) != E_KERN_EXINT) { return; } if (nameinit == 0 && name[0] == '\0') { cout << " :trackname \"track " << track << "\"\n"; nameinit = 1; } else if (nameinit == 0) { cout << " :trackname \"" << name << "\"\n"; nameinit = 1; } cout << " ("; if (infile[line].getBeat() == 1.0) { cout << "bar " << bar << " "; bar++; } duration = Convert::kernToDuration(infile[line][spine]); if (strchr(element, 'r') != NULL) { cout << "n (nil "; printFractionDuration(duration); cout << ") rest t"; addExtraStuff(); cout << ")\n"; return; } getNoteArray(notes, infile, line, spine); int notecount = notes.getSize(); cout << "n ("; if (notecount > 1) { cout << "("; } for (int i=0; i 1) { cout << ")"; } cout << " "; printFractionDuration(duration); cout << ")"; if (strchr(infile[line][spine], '[') != NULL) { cout << " tie t"; } else if (strchr(infile[line][spine], '_') != NULL) { cout << " tie t"; } addExtraStuff(); cout << ")\n"; } ////////////////////////////// // // getNoteArray -- // void getNoteArray(Array& notes, HumdrumFile& infile, int line, int spine){ int notecount = infile[line].getTokenCount(spine); char buffer[128] = {0}; notes.setSize(0); int note; notes.allowGrowth(1); for (int i=0; i 0) { cout << " mm " << metronome; } if (metertop != -1) { cout << " meter (" << metertop << " " << meterbottom << ")"; } metertop = -1; meterbottom = -1; mode = -1; metronome = -1; key = -1; } ////////////////////////////// // // printFractionDuration -- // void printFractionDuration(double duration) { duration = duration/4.0; double tolerance = 0.001; double frac = duration - (int)duration; int whole = (int)(duration - frac); if (fabs(whole - duration) < tolerance) { cout << whole; return; } int top = 1; int bottom; while (top<257) { for (bottom=2; bottom<257; bottom++) { if (fabs((double)top/bottom - frac) < tolerance) { cout << top + whole * bottom; cout << "/"; cout << bottom; return; } } top++; } } ////////////////////////////// // // printPitchClass -- // void printPitchClass(int base40) { switch ((base40 % 40) - 2) { case -2: cout << "Cbb"; break; case -1: cout << "Cb"; break; case 0: cout << "C"; break; case 1: cout << "C#"; break; case 2: cout << "C##"; break; case 3: cout << "X"; break; case 4: cout << "Dbb"; break; case 5: cout << "Db"; break; case 6: cout << "D"; break; case 7: cout << "D#"; break; case 8: cout << "D##"; break; case 9: cout << "X"; break; case 10: cout << "Ebb"; break; case 11: cout << "Eb"; break; case 12: cout << "E"; break; case 13: cout << "E#"; break; case 14: cout << "E##"; break; case 15: cout << "Fbb"; break; case 16: cout << "Fb"; break; case 17: cout << "F"; break; case 18: cout << "F#"; break; case 19: cout << "F##"; break; case 20: cout << "X"; break; case 21: cout << "Gbb"; break; case 22: cout << "Gb"; break; case 23: cout << "G"; break; case 24: cout << "G#"; break; case 25: cout << "G##"; break; case 26: cout << "X"; break; case 27: cout << "Abb"; break; case 28: cout << "Ab"; break; case 29: cout << "A"; break; case 30: cout << "A#"; break; case 31: cout << "A##"; break; case 32: cout << "X"; break; case 33: cout << "Bbb"; break; case 34: cout << "Bb"; break; case 35: cout << "B"; break; case 36: cout << "B#"; break; case 37: cout << "B##"; break; default: cout << "X"; } } ////////////////////////////// // // printNote -- // void printNote(int base40) { cout << "\""; printPitchClass(base40); cout << base40/40; // the octave number cout << "\""; } ////////////////////////////// // // checkOptions -- validate and process command-line options. // void checkOptions(Options& opts, int argc, char* argv[]) { 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: 28 April 2001" << endl; cout << "compiled: " << __DATE__ << endl; cout << MUSEINFO_VERSION << endl; exit(0); } else if (opts.getBoolean("help")) { usage(opts.getCommand().data()); exit(0); } else if (opts.getBoolean("example")) { example(); exit(0); } } ////////////////////////////// // // example -- example usage of the kern2dm 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: 003059a8835ba4cd400ed9c9fdeaa679 kern2dm.cpp [20151120]