// // Programmer: Craig Stuart Sapp // Creation Date: Mon Apr 15 20:05:01 PDT 2002 // Last Modified: Mon Apr 15 20:05:04 PDT 2002 // Filename: ...sig/examples/all/addtime.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/addtime.cpp // Syntax: C++; museinfo // // Description: Add a spine indicating the time of performance for // a given line of music. // #include "humdrum.h" #include #include // function declarations void checkOptions (Options& opts, int argc, char* argv[]); void example (void); void printAnalysis (HumdrumFile& infile, vector& timings, vector& tempo); void analyzeTiming (HumdrumFile& infile, vector& timings, vector& tempo); void usage (const string& command); void generateSwing (HumdrumFile& infile, vector& timings, double amount); // global variables Options options; // database for command-line arguments int debugQ = 0; // used with the --debug option double offset = 0.0; // used with the -o option int style = 's'; // used with the -m option double dtempo = 60.0; // used with the -t option double percentage = 60.0; // used with the -p option /////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { HumdrumFile infile; vector timings; vector tempo; // process the command-line options checkOptions(options, argc, argv); // figure out the number of input files to process int numinputs = options.getArgCount(); for (int i=0; i& timings, double amount) { int i; double fraction = amount / 100.0; vector data(timings.size(), 0); vector nextdata(timings.size(), 0); vector lastdata(timings.size(), 0); for (i=0; i= 0; i--) { if (data[i]) { nextdata[i] = next; next = i; } } vector rhylev; infile.analyzeMetricLevel(rhylev); // switch sign for now so that eighth note level is -1. for (i=0; i<(int)rhylev.size(); i++) { rhylev[i] = -rhylev[i]; } double newtime; for (i=0; i= 0 && rhylev[lastdata[i]] >= 0) { // if the eighth note is surrounded by beat levels // then adjust the timing of the note newtime = timings[nextdata[i]] - timings[lastdata[i]]; newtime = newtime * fraction; newtime = newtime + timings[lastdata[i]]; // fix the ending case later: if (newtime >= timings[lastdata[i]]) { timings[i] = newtime; } } } } } ////////////////////////////// // // analyzeTiming -- determing the absolute time position of each // line in the file. // void analyzeTiming(HumdrumFile& infile, vector& timings, vector& tempo) { infile.analyzeRhythm("4"); timings.resize(infile.getNumLines(), 0); tempo.resize(infile.getNumLines(), dtempo); double currtempo = dtempo; double input = 0.0; int count; int i; for (i=1; i 0) { tempo[i-1] = currtempo; } tempo[i] = currtempo; } } tempo[i] = currtempo; timings[i] = timings[i-1] + (infile[i].getAbsBeat() - infile[i-1].getAbsBeat()) * 60.0/currtempo; } } ////////////////////////////// // // checkOptions -- validate and process command-line options. // void checkOptions(Options& opts, int argc, char* argv[]) { opts.define("o|offset=d:0.0", "starting time offset"); opts.define("s|seconds=b", "use seconds as the time unit"); opts.define("t|tempo=d:60.0", "default tempo to use if none in file"); opts.define("p|percent=d:60.0", "swing percentage 0=previous; 100=next"); 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 2002" << endl; exit(0); } else if (opts.getBoolean("version")) { cout << argv[0] << ", version: 15 April 2002" << 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); } debugQ = opts.getBoolean("debug"); offset = opts.getDouble("offset"); if (opts.getBoolean("seconds")) { style = 's'; } else { style = 'm'; } dtempo = opts.getDouble("tempo"); // don't let people set the tempo to slow or negative if (dtempo < 1.0) { dtempo = 60.0; } percentage= opts.getDouble("percent"); if (percentage < 0.0) { percentage = 0.0; } if (percentage > 100.0) { percentage = 100.0; } } ////////////////////////////// // // example -- example usage of the addtime program // void example(void) { cout << " \n" << endl; } ////////////////////////////// // // printAnalysis -- // void printAnalysis(HumdrumFile& infile, vector& timings, vector& tempo) { int tempomark = 0; int i; int m; for (i=0; i