// // Programmer: Craig Stuart Sapp // Creation Date: Sun Oct 31 04:21:10 PDT 2010 // Last Modified: Sun Oct 31 04:21:17 PDT 2010 // Filename: ...sig/examples/all/motive.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/motive.cpp // Syntax: C++; museinfo // // Description: Tool for motive identification in monophonic or single-voice // polyphonic scores. // #include "humdrum.h" #ifndef OLDCPP using namespace std; #endif #define REST -1000 #define INVALID -7000 class Coord { public: int row; int col; Coord(void) { row = col = -1; } }; // function declarations void checkOptions (Options& opts, int argc, char* argv[]); void example (void); void usage (const char* command); void doDiatonicIntervalAnalysis(HumdrumFile& infile); void getDiatonicIntervals(Array >& intervals, Array >& coords, HumdrumFile& infile); void printDiatonicIntervals(Array >& intervals); void printDiatonicData(HumdrumFile& infile, Array >& intervals, Array >& coords); void printDiatonicLine (HumdrumFile& infile, int i, Array >& intervals, const char* strang); // global variables Options options; // database for command-line arguments int debugQ = 0; // used with --debug option int zeroQ = 0; // used with -z option int restQ = 0; // used with -r option int outputonlyQ = 0; // used with -I option int printDiatonicIntervalsQ = 1; // used with -D option /////////////////////////////////////////////////////////////////////////// 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(); for (int i=0; i > intervals; Array > coords; getDiatonicIntervals(intervals, coords, infile); // printDiatonicIntervals(intervals); if (printDiatonicIntervalsQ) { printDiatonicData(infile, intervals, coords); exit(0); } } ////////////////////////////// // // printDiatonicData -- // void printDiatonicData(HumdrumFile& infile, Array >& intervals, Array >& coords) { int i; for (i=0; i >& intervals, const char* strang) { int j; int tcounter = 0; int track; int track2; int value; for (j=0; j= REST) { value = intervals[i][j]; if (restQ && (value == REST)) { cout << "r"; } else { if (!zeroQ) { if (value > 0) { value++; } else if (value < 0) { value--; } } if (value > 0) { cout << "+"; } cout << value; } } else { if ((strcmp(strang, "*") == 0) && (strncmp(infile[i][j], "*staff", strlen("*staff")) == 0)) { cout << infile[i][j]; } else { cout << strang; } } } } if (!outputonlyQ) { if (j < infile[i].getFieldCount()-1) { cout << "\t"; } } } cout << endl; } ////////////////////////////// // // printDiatonicIntervals -- // void printDiatonicIntervals(Array >& intervals) { int i, j; for (i=0; i >& intervals, Array >& coords, HumdrumFile& infile) { int maxtrack = infile.getMaxTracks(); int track; int pitch; Coord coord; intervals.setSize(infile.getNumLines()); coords.setSize(maxtrack); int i, j; // pre-allocate storage space for data: for (i=0; i >& c = coords; int lasti, lastj; // convert absolute diatonic pitch into diatonic interval. if (restQ) { for (i=0; i