// // Programmer: Craig Stuart Sapp // Creation Date: Fri Jan 7 17:32:52 PST 2011 // Last Modified: Fri Jan 7 19:33:31 PST 2011 (added -o and -a options) // Filename: ...sig/examples/all/rscale.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/rscale.cpp // Syntax: C++; museinfo // // Description: Scale the duration of all **kern rhythms by a constant // factor. // // #include #include #include #include #include "PerlRegularExpression.h" #include "humdrum.h" using namespace std; // function declarations void checkOptions (Options& opts, int argc, char* argv[]); void example (void); void usage (const string& command); void printOutput (HumdrumFile& infile, RationalNumber& rnum); void printKernToken (HumdrumFile& infile, int row, int col, RationalNumber& factor); void printSingleKernSubtoken(const string& buff, RationalNumber& factor); void printSpecialRational(RationalNumber& value); void processTimeSignature(HumdrumFile& infile, int row, RationalNumber& factor); void handleBibliographic(HumdrumFile& infile, int row, RationalNumber& num); void getOriginalFactor (HumdrumFile& infile, RationalNumber& factor); void getAlternateFactor (HumdrumFile& infile, RationalNumber& factor); void cleanUpBeams (string& prebuffer, string& postbuffer, int level); // global variables Options options; // database for command-line arguments int debugQ = 0; // used with --debug RationalNumber factor; // used with -f option int meterQ = 1; // used with -M option int FoundRef = 0; // used with !!!rscale: reference record int originalQ = 0; // used with --original int alternateQ = 0; // used with --alternate int longQ = 0; // used with -r option int rebeamQ = 0; // used with -B option int autoQ = 0; // used with -F option /////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { checkOptions(options, argc, argv); HumdrumFileSet infiles; infiles.read(options); for (int i=0; i 0)) { pre.sar(prestring, "L", ""); level--; } else if ((level == 1) && (Jcount1 > 0)) { pre.sar(prestring, "J", ""); level--; } else if ((level == 1) && (Lcount2 > 0)) { pre.sar(prestring, "L", ""); level--; } else if ((level == 1) && (Jcount2 > 0)) { pre.sar(prestring, "J", ""); level--; } else if ((level == 2) && (Lcount1 > 1)) { pre.sar(prestring, "L", ""); pre.sar(prestring, "L", ""); level -= 2; } else if ((level == 2) && (Jcount1 > 1)) { pre.sar(prestring, "J", ""); pre.sar(prestring, "J", ""); level -= 2; } else if ((level == 2) && (Lcount2 > 1)) { pre.sar(prestring, "L", ""); pre.sar(prestring, "L", ""); level -= 2; } else if ((level == 2) && (Jcount2 > 1)) { pre.sar(prestring, "J", ""); pre.sar(prestring, "J", ""); level -= 2; } // deal with k and K later... prebuffer = prestring; postbuffer = poststring; } ////////////////////////////// // // printSpecialRational -- print rational number rhythm, but use 0 // for 1/2 (breve), 00 for 1/4 (long), or 000 for 1/8 (maxima). // void printSpecialRational(RationalNumber& value) { static RationalNumber half(1,2); // breve static RationalNumber quarter(1,4); // long static RationalNumber eighth(1,8); // maxima if (longQ) { // don't print 0 for breve, 00 for long or 000 for maxima. cout << value.getNumerator(); if (value.getDenominator() != 1) { cout << '%' << value.getDenominator(); } } else { if (value == half) { // breve alternate cout << "0"; } else if (value == quarter) { // long alternate cout << "00"; } else if (value == eighth) { // maxima alternate cout << "000"; } else { cout << value.getNumerator(); if (value.getDenominator() != 1) { cout << '%' << value.getDenominator(); } } } } ////////////////////////////// // // checkOptions -- validate and process command-line options. // void checkOptions(Options& opts, int argc, char* argv[]) { opts.define("d|f|factor=s:1/1", "Factor to multiply durations by"); opts.define("F=b", "Read rscale factors from !!!RSCALE: lines"); opts.define("M|T|nometer=b", "Do not alter time signatures"); opts.define("o|original=b", "Revert to original rhythms"); opts.define("a|alternate=b", "Change to alternate rhythm set"); opts.define("r|long=b", "Do not use short form for breve,long,maxima"); opts.define("B|adjust-beams=b", "Adjust beaming for powers of 2 rscaling"); 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, Jan 2011" << endl; exit(0); } else if (opts.getBoolean("version")) { cout << argv[0] << ", version: 6 Jan 2011" << 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); } PerlRegularExpression pre; if (pre.search(opts.getString("factor").data(), "(\\d+)\\/?(\\d*)", "")) { int top = 1; int bot = 1; top = atoi(pre.getSubmatch(1)); if (strlen(pre.getSubmatch(2)) != 0) { bot = atoi(pre.getSubmatch()); if (bot == 0) { bot = 1; } } else { bot = 1; } factor.setValue(top, bot); } else { factor.setValue(1,1); cerr << "Scaling factor set to " << factor << endl; } debugQ = opts.getBoolean("debug"); if (debugQ) { cerr << "Scaling factor set to " << factor << endl; } autoQ = opts.getBoolean("F"); meterQ = !opts.getBoolean("nometer"); originalQ = opts.getBoolean("original"); alternateQ = opts.getBoolean("alternate"); longQ = opts.getBoolean("long"); rebeamQ = opts.getBoolean("adjust-beams"); } ////////////////////////////// // // 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 string& command) { cout << " \n" << endl; }