// // Programmer: Craig Stuart Sapp // Creation Date: Mon Nov 5 11:30:28 PST 2001 // Last Modified: Tue Nov 6 23:25:11 PST 2001 // Filename: ...sig/examples/all/melstep/melstep.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/melstep.cpp // Syntax: C++; museinfo // // Description: Determines the melodic approach or departure of a note. // 0000 = 0 = not approached or left by a 2nd in track // 0001 = 1 = left by a 2nd in track // 0010 = 2 = approached by a 2nd in track // 0011 = 3 = approached and left by a 2nd in track // // Not yet implemented: // 0000 = 0 = note approached or left by a 2nd in another track // 0100 = 4 = note left by a 2nd in another track // 1000 = 8 = note approached by a 2nd in another track // 1100 = 12 = note approached and left by a 2nd in another track // #include "humdrum.h" #include #include #include typedef Array ArrayInt; // function declarations: void checkOptions (Options& opts, int argc, char* argv[]); void getDataLines (HumdrumFile& infile, Array& datalines); void generateAnalysis (HumdrumFile& infile, Array& mstates, Array& datalines); void printAnalysis (HumdrumFile& infile, Array& mstates, Array& datalines); void printState (int state, int style); void printSummary (HumdrumFile& infile, Array& mstates, Array& datalines); void example (void); void usage (const char* command); template void switchvals(type& a, type& b); // option variables: Options options; // database for command-line arguments int debugQ = 0; // for debugging int appendQ = 0; // for appending analysis data to input data int binaryQ = 0; // display analysis in binary format int summaryQ = 0; // display transition statistics only int minstep = 4; // minimum value for step (base40 interval) int maxstep = 8; // maximum value for step (base40 interval) int ridQ = 0; // rid plain **step data of non-data items /////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { HumdrumFile infile; checkOptions(options, argc, argv); // process the command-line options // figure out the number of input files to process int numinputs = options.getArgCount(); Array mstates; Array datalines; for (int i=0; i& datalines) { datalines.setSize(infile.getNumLines()); datalines.setSize(0); datalines.allowGrowth(); int i; for (i=0; i& mstates, Array& datalines) { mstates.setSize(datalines.getSize()); static char buffer[1024] = {0}; static char bufferN[1024] = {0}; static char bufferL[1024] = {0}; Array lastspines; Array nextspines; int i, j; int m; int lindex, nindex; int lspine, nspine; int ltokens, ntokens; int analysis = 0; for (i=0; i= 0 && lspine >= 0) { ltokens = infile[lindex].getTokenCount(lspine); } ntokens = -1; if (nindex >= 0 && nspine >= 0) { ntokens = infile[nindex].getTokenCount(nspine); } if (m < ltokens && lindex >= 0 && lspine >= 0) { infile[lindex].getToken(bufferL, lspine, m); } else { bufferL[0] = '\0'; } if (m < ntokens && nindex >= 0 && nspine >= 0) { infile[nindex].getToken(bufferN, nspine, m); } else { bufferN[0] = '\0'; } ndiff = 0; if (bufferN[0] != '\0' && (strchr(bufferN, 'r') == NULL)) { ndiff = abs(Convert::kernToBase40(bufferN) - Convert::kernToBase40(buffer)); } ldiff = 0; if (bufferL[0] != '\0' && (strchr(bufferL, 'r') == NULL)) { ldiff = abs(Convert::kernToBase40(bufferL) - Convert::kernToBase40(buffer)); } if (ndiff == 0 && ntokens != tokencount) { if (ntokens - m - 1 >= 0 && nindex >= 0 && nspine >= 0) { infile[nindex].getToken(bufferN, nspine, ntokens-m-1); } else { bufferN[0] = '\0'; } if (bufferN[0] != '\0' && (strchr(bufferN, 'r') == NULL)) { ndiff = abs(Convert::kernToBase40(bufferN) - Convert::kernToBase40(buffer)); } } if (ldiff == 0 && ltokens != tokencount) { if (ltokens - m - 1 >= 0 && lindex >= 0 && lspine >= 0) { infile[lindex].getToken(bufferL, lspine, ltokens-m-1); } else { bufferL[0] = '\0'; } if (bufferL[0] != '\0' && (strchr(bufferL, 'r') == NULL)) { ldiff = abs(Convert::kernToBase40(bufferL) - Convert::kernToBase40(buffer)); } } analysis = 0; if (ldiff >= minstep && ldiff <= maxstep) { analysis |= 0x02; } if (ndiff >= minstep && ndiff <= maxstep) { analysis |= 0x01; } mstates[i].append(analysis); } /* token loop */ } /* spine loop */ } /* line loop */ } ////////////////////////////// // // getLastSpines -- check for spine changes // /* void getLastSpines(Array& lastspines, int lindex, int lspine, HumdrumFile& infile, int curindex, int curspine) { } */ ////////////////////////////// // // getNextSpines -- check for spine changes // /* void getNextSpines(nextspines, nspine, infile, lines, datalines[i], spine) { } */ ////////////////////////////// // // printAnalysis -- print melodic state information for each note. // void printAnalysis(HumdrumFile& infile, Array& mstates, Array& datalines) { int i, j, k; if (summaryQ) { printSummary(infile, mstates, datalines); return; } if (!appendQ) { k = 0; for (i=0; i void switchvals(type& a, type& b) { type temp = a; a = b; b = temp; } ///////////////////////////// // // printSummary -- print analysis summary. // void printSummary(HumdrumFile& infile, Array& mstates, Array& datalines) { int c[4] = {0}; int i, j, m; for (i=0; i metpos; metpos.setSize(500); metpos.setSize(0); metpos.allowGrowth(); double pos = 0; int pindex = 0; Array metposb; metposb.setSize(500); metposb.setSize(0); metposb.allowGrowth(); double posb = 0; int pindexb = 0; Array counts(4); Array countsb(4); counts.allowGrowth(0); countsb.allowGrowth(0); for (m=0; m<4; m++) { counts[m].setSize(500); counts[m].setSize(0); counts[0].allowGrowth(); countsb[m].setSize(500); countsb[m].setSize(0); countsb[0].allowGrowth(); } int zero = 0; int pfound = 0; int pfoundb = 0; for (i=0; i metpos[j]) { switchvals(metpos[i], metpos[j]); for (m=0; m<4; m++) { switchvals(counts[m][i], counts[m][j]); } } } } for (i=0; i metposb[j]) { switchvals(metposb[i], metposb[j]); for (m=0; m<4; m++) { switchvals(countsb[m][i], countsb[m][j]); } } } } // print the metric data summary: cout << "\nTransition counts for each metric position:\n\n"; cout << "\ttransitions:\n"; cout << "beat\t"; printState(0, binaryQ); cout << "\t"; printState(1, binaryQ); cout << "\t"; printState(2, binaryQ); cout << "\t"; printState(3, binaryQ); cout << "\tsum\tfraction\n"; cout << "-----------------------------------------------------------\n"; for (i=0; i maxstep) { int temp = minstep; minstep = maxstep; maxstep = temp; } } ////////////////////////////// // // example -- example usage of the melstep program // void example(void) { cout << " \n" << endl; } ////////////////////////////// // // usage -- gives the usage statement for the melstep program // void usage(const char* command) { cout << " \n" << endl; } // md5sum: dae85b0de4324139794b0d7376b9d1a2 melstep.cpp [20050403]