// // Programmer: Craig Stuart Sapp // Creation Date: Thu Jul 9 13:20:28 PDT 1998 // Last Modified: Tue Dec 5 15:11:50 PST 2000 (enable polyphonic sampling) // Filename: ...sig/examples/all/sample.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/sample.cpp // Syntax: C++; museinfo // // Description: Samples pitches according to the given pattern // #include "humdrum.h" #include #include // function declarations void checkOptions(Options& opts, int argc, char* argv[]); void example(void); void processRecords(HumdrumFile& infile, HumdrumFile& outfile); void usage(const char* command); // global variables Options options; // database for command-line arguments double* sampleDuration; int sdSize; /////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { HumdrumFile infile, outfile; // 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 sDur; // duration to take note sample at sDur.allowGrowth(1); sDur.setSize(0); char* aDuration; char* aString; aString = new char[strlen(opts.getString("rhythms")) + 1]; strcpy(aString, opts.getString("rhythms")); aDuration = strtok(aString, " ,;\t\n:"); double duration; while (aDuration != NULL) { duration = Convert::kernToDuration(aDuration); sDur.append(duration); aDuration = strtok(NULL, " ,;\t\n:"); } sDur.allowGrowth(0); sdSize = sDur.getSize(); sampleDuration = new double[sDur.getSize()]; for (int i=0; i= currDuration && phraseEnd && doPhraseEnd && phraseToggle == 1) { strcat(outputString, "}"); phraseEnd = 0; doPhraseEnd = 0; phraseToggle = 0; } outfile.appendLine(outputString); } } if (!options.getBoolean("divide")) { strcpy(outputString, ""); if (phraseStart && phraseToggle == 0) { strcat(outputString, "{"); phraseStart = 0; phraseToggle = 1; } strcat(outputString, Convert::durationToKernRhythm(aString, noteDuration)); strcat(outputString, Convert::base40ToKern(aString, pitch)); if (phraseEnd && phraseToggle == 1) { strcat(outputString, "}"); phraseEnd = 0; phraseToggle = 0; } outfile.appendLine(outputString); } } else { if (strchr(currRecord[0], '{') != NULL) { phraseStart = 1; } if (strchr(currRecord[0], '}') != NULL) { phraseEnd = 1; } } break; default: cerr << "Error on line " << (i+1) << " of input" << endl; exit(1); } } } ////////////////////////////// // // usage -- gives the usage statement for the sample program // void usage(const char* command) { cout << " \n" "Analyzes **kern data and generates a rhythmic analysis which gives \n" "the beat location of **kern data records in the measure. Currently, \n" "input spines cannot split or join. \n" " \n" "Usage: " << command << " [-a][-b base-rhythm][-s|-d][input1 [input2 ...]]\n" " \n" "Options: \n" " -b = set the base rhythm for analysis to specified kern rhythm value. \n" " -d = gives the duration of each kern record in beat measurements. \n" " -s = sum the beat count in each measure. \n" " --options = list of all options, aliases and default values \n" " \n" << endl; }