// // Programmer: Craig Stuart Sapp // Creation Date: Mon Apr 12 23:22:19 PDT 2004 // Last Modified: Mon Apr 12 23:22:22 PDT 2004 // Last Modified: Thu Feb 24 22:43:17 PST 2005 (added -k option) // Last Modified: Wed Jun 24 15:39:58 PDT 2009 (updated for GCC 4.4) // Filename: ...sig/examples/all/transpose.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/transpose.cpp // Syntax: C++; museinfo // // Description: Transpose **kern musical data. // #include "humdrum.h" #include #include #ifndef OLDCPP #include #include #else #include #include #endif // function declarations: void checkOptions (Options& opts, int argc, char** argv); void example (void); void usage (const char* command); void printFile (HumdrumFile& infile); int generateFieldList (Array& fieldlist,const char* fieldstring); void processFile (HumdrumFile& infile); void printNewKernString (const char* string); void printHumdrumKernToken (HumdrumRecord& record, int index); void printHumdrumDataRecord(HumdrumRecord& record, Array& spineprocess); int getBase40ValueFromInterval(const char* string); void printNewKeyInterpretation(HumdrumRecord& aRecord, int index); // User interface variables: Options options; int transval = 0; // used with -b option const char* fieldstring = ""; // used with -f option int fieldQ = 0; // used with -f option int ssetkeyQ = 0; // used with -k option int ssetkey = 0; // used with -k option int currentkey = 0; ////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { // process the command-line options checkOptions(options, argc, argv); HumdrumFile infile; if (options.getArgCount() > 0) { infile.read(options.getArg(1)); } else { infile.read(cin); } processFile(infile); return 0; } ////////////////////////////////////////////////////////////////////////// ////////////////////////////// // // processFile -- // void processFile(HumdrumFile& infile) { int i; Array fieldlist; Array spineprocess(infile.getMaxTracks()); if (fieldQ) { spineprocess.setAll(0); generateFieldList(fieldlist, fieldstring); for (i=0; i 4)) { cout << infile[i][j]; if (j= 0 && diatonic <= 6) { printNewKeyInterpretation(infile[i], j); if (j 40) { transval -= 40; } if (transval > 20) { transval = 40 - transval; transval = -transval; } if (transval < -40) { transval += 40; } if (transval < -20) { transval = -40 - transval; transval = -transval; } // cout << "TRANSVAL = "<< transval << endl; } cout << "*" << Convert::base40ToKern(buffer, base40) << ":"; } ////////////////////////////// // // printHumdrumDataRecord -- // void printHumdrumDataRecord(HumdrumRecord& record, Array& spineprocess) { int i; for (i=0; i& fieldlist, const char* fieldstring) { cout << "ENTERING GENERATEFIELD LIST" << endl; int maxfield = 0; int length = strlen(fieldstring); char* buffer = new char[length+1]; strcpy(buffer, fieldstring); int starti, stopi; int temp; int num; char* ptr = strtok(buffer, " ,;:"); while (ptr != NULL) { if (strchr(ptr, '-') != NULL) { sscanf(ptr, "%d-%d", &starti, &stopi); if (starti > stopi) { temp = starti; starti=stopi; stopi = temp; } for (num=starti; num<=stopi; num++) { fieldlist.append(num); } if (num > maxfield) { maxfield = num; } } else { sscanf(ptr, "%d", &num); fieldlist.append(num); if (num > maxfield) { maxfield = num; } } ptr = strtok(NULL, " ,;:"); } cout << "LEAVING GENERATEFIELD LIST" << endl; return maxfield; } /* BRIEF DOCUMENTATION transpose options: -t interval = transpose music by the specified interval, where interval is of the form: P1 = perfect unison (no transposition) m2 = up a minor second -m2 = down a minor second M3 = up a major third -A4 = down an augmented fourth d5 = up a diminished fifth -b interval = transpose by the base-40 equivalent to the -t option interval 0 = perfect unison (no transposition) 6 = up a minor second -6 = down a minor second 12 = up a major third -18 = down an augmented fourth 22 = up a diminished fifth -o octave = transpose (additionally by given octave) transpose -t m3 -o 1 = transpose up by an octave and a minor third. -f fieldstring = transpose only the given list of data spines. example: transpose -f1-2,4 -t P4 fourpart.krn transpose -f3 -t P4 fourpart.krn Note: does not work yet with the -k option ########################################################################## ## ## EXAMPLES ## input: file.krn -- an example with the key being a minor: **kern *a: 4A 4B 4c 4d 4e 4f 4g 4a *- ##################################################################### # # Transpose the file up a minor third (so that it is in C Minor): # tranpose -t m3 file.krn **kern *c: 4c 4d 4e- 4f 4g 4a- 4b- 4cc *- ##################################################################### # # Transpose the file down a minor third (so that it is in F# Minor): # tranpose -t -m3 file.krn **kern *f#: 4F# 4G# 4A 4B 4c# 4d 4e 4f# *- ##################################################################### # # Transpose the file up a perfect octave: # tranpose -t P8 file.krn **kern *a: 4A 4B 4cc 4dd 4ee 4ff 4gg 4aa *- ##################################################################### # # Force the file to a tonic on C rather than a: # transpose -k c file.krn **kern *c: 4c 4d 4e- 4f 4g 4a- 4b- 4cc *- # case -k option value is irrelevant: transpose -k C file.krn **kern *c: 4c 4d 4e- 4f 4g 4a- 4b- 4cc *- # Transpose from A Minor to G# Minor: transpose -k G# file.krn **kern *g#: 4G# 4A# 4B 4c# 4d# 4e 4f# 4g# *- # Changing input files to: **kern *C: 4c 4d 4e 4f *G: 4g 4a 4b 4cc *- # Using -k option will convert all keys to same in output: transpose -k e file.krn **kern *E: 4e 4f# 4g# 4a *E: 4e 4f# 4g# 4a *- ############################## ## ## octave transpositions ## # Back to original data file, transposing up a minor tenth: transpose -o 1 -t m3 file.krn **kern *E-: 8ee- 8ff 8gg 8aa- 8bb- 8ccc 8ddd 8eee- *- # transpose down two octaves: transpose -o -2 file.krn **kern *a: 4AAA 4BBB 4CC 4DD 4EE 4FF 4GG 4AA *- #################### ## ## base 40 -b option instead of -t option ## # Transpose down two octaves: transpose -b -80 file.krn **kern *a: 4AAA 4BBB 4CC 4DD 4EE 4FF 4GG 4AA *- */ // md5sum: 28a5b69adb369d26bcba3835299da2a8 transpose.cpp [20090626]