// // Programmer: Craig Stuart Sapp // Creation Date: Thu Sep 9 21:30:46 PDT 2004 // Last Modified: Thu Sep 9 21:30:48 PDT 2004 // Filename: ...sig/examples/all/rebar.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/rebar.cpp // Syntax: C++; museinfo // // Description: Number, renumber or remove measure numbers from Humdrum files. // #include "humdrum.h" #include #include #ifndef OLDCPP #include #define SSTREAM stringstream #define CSTRING str().c_str() using namespace std; #else #ifdef VISUAL #include /* for windows 95 */ #else #include #endif #define SSTREAM strstream #define CSTRING str() #endif // function declarations void checkOptions (Options& opts, int argc, char* argv[]); void example (void); void usage (const char* command); void processFile (HumdrumFile& file); void removeBarNumbers (HumdrumFile& infile); void printWithoutBarNumbers(HumdrumRecord& humrecord); void printWithBarNumbers(HumdrumRecord& humrecord, int measurenum); void printSingleBarNumber(const char* string, int measurenum); // global variables Options options; // database for command-line arguments int removeQ = 0; // used with -r option int startnum = 1; // used with -s option int allQ = 0; // used with -a option int debugQ = 0; // used with --debug option /////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { HumdrumFile infile, outfile; // process the command-line options checkOptions(options, argc, argv); // if no command-line arguments read data file from standard input int numinputs = options.getArgCount(); if (numinputs < 1) { infile.read(cin); } else { infile.read(options.getArg(1)); } if (removeQ) { removeBarNumbers(infile); } else{ processFile(infile); } return 0; } /////////////////////////////////////////////////////////////////////////// /////////////////////////////// // // removeBarNumbers -- You guessed it. // void removeBarNumbers(HumdrumFile& infile) { int i; for (i=0; i measureline; // line number in the file where measure occur Array measurebeats; // duration of measure Array timesigbeats; // duration according to timesignature Array control; // control = numbered measure Array measurenums; // output measure numbers measureline.setSize(infile.getNumLines()); measureline.setSize(0); measurebeats.setSize(infile.getNumLines()); measurebeats.setSize(0); timesigbeats.setSize(infile.getNumLines()); timesigbeats.setSize(0); int i; double timesigdur = 0.0; double timetop = 4; double timebot = 1; double value = 1; double lastvalue = 1; for (i=0; i 0) { timesigbeats[timesigbeats.getSize()-1] = timesigdur; measurebeats[measurebeats.getSize()-1] = lastvalue * timebot; } } } else if (infile[i].getType() == E_humrec_data_measure) { measureline.append(i); lastvalue = infile[i].getBeat(); // shouldn't use timebot (now analyzing rhythm by "4") // value = lastvalue * timebot; value = lastvalue; measurebeats.append(value); timesigbeats.append(timesigdur); } } if (measurebeats.getSize() == 0) { // no barlines, nothing to do... cout << infile; return; } // Identify controlling/non-controlling barlines // at each measure line determine one of three cases: // // (1) all ok -- the summation of durations in the measure // matches the current time sign // (2) a partial measure -- the measure durations do not // add up to the time signature, but the measure is // at the start/end of a musical section such as the // beginning of a piece, end of a piece, or between // repeat bar dividing a full measure. // (3) the sum of the durations does not match the // time signature because the durations are incorrectly // given. // control.setSize(measureline.getSize()); measurenums.setSize(measureline.getSize()); control.setAll(-1); measurenums.setAll(-1); // if the time signature and the number of beats in a measure // agree, then the bar is worth numbering: for (i=0; i=0; i--) { if ((control[i] == 1) || (control[i+1] == 1)) { continue; } if (timesigbeats[i] != timesigbeats[i+1]) { continue; } if ((measurebeats[i]+measurebeats[i+1]) == timesigbeats[i]) { control[i] = 1; control[i+1] = 0; } } // if two (or more) non-controlling bars occur in a row, then // make them controlling: for (i=0; i 0) && dataq) { offset = 1; } break; } } if (allQ) { control.setAll(1); offset = 0; } // assign the measure numbers; int mnum = startnum + offset; for (i=0; i