/////////////////////////////////////////////////////// // Chord Root Finder - Created by Daniel White // This documented program will find approximate // weightings of multiple roots for any arbitrary chord /////////////////////////////////////////////////////// #include char* diaNoteName(int i); int mod7(int a); int main(int argc, char *argv[]) { // 1 2 3 4 5 6 7 // c d e f g a b // The note C will be the center of all activity, so other chord notes are related to C=1. When intervals // are mentioned, assume octave equivalence. So 2nd = 9th etc. int chordNote[]={1,3,5,7}; // This is the chord we'll use to test the algorithm - C G B D int numOfNotesInChord = sizeof(chordNote) / sizeof(int); // Find how many notes there are in chordNote[] int degree[7]; for (int n=0; n<7; n++) degree[n]=0; for (int n=0; n0 && degree [mod7(r+3) ] == 1) { // (weight[r]>0 means to affect notes which already have some weighting. One might want to turn this off if is there any merit to negative weightings). Anyway, if the fourth exists for any of the scale degrees, this has a negative effect for the initial note, and maybe a positive effect for the fourth, so... weight [r]-=1; // ... decrement weight of the note which has a fourth interval. // In the case where degree r equals our chord's bass note, the fourth (of degree r) becomes stronger, so increment r fourth's weight. if ( mod7(r)==mod7(chordNote[0]) ) { weight [mod7(r+3)]+=1; } } } // This final section deals with the case where an upper triadic note can form a relationship with the bass. For example, in the chord C E D, the C and E notes form C major, but rather than D forming a D minor triad, it feels more like the upper note of a G triad, due to its relationship with the bass note of C. This could be said to be an extrapolation of the theory of 7th, 9ths, 11ths etc. for (int r=0; r<7 ;r++ ) { if (weight[r]==0) { // This only applies to degrees which currently have no weight // If r's fifth exists, AND (r's second doesn't exist OR r isn't equal to the bass note) if ( degree[mod7(r+4)]==1 && (degree[mod7(r+1)]==0 || mod7(r)!=chordNote[0] ) ) { if ( // ... then if r's interval to the bass note is not a second, or a fourth, or a sixth... (since these notes are too far (in thirds) from C, and will form upper relationships with the bass note, rather than lower. For example, the subdominant is not treated as a thirteenth which although G major is implied in the chord C, E and D (D being the 9th), if we choose C, E, and A, a direct A minor triad is made with the bass note C, and therefore, the note A (possible 13th) possible doesn't imply a D minor triad below it) ... ( mod7(r-chordNote[0]) ) !=1 && // Maybe don't include this one? ( mod7(r-chordNote[0]) ) !=3 && // Probably include this one ( mod7(r-chordNote[0]) ) !=5 // Definitely include this one ) { if ( degree[mod7(r+6)]==0 ) { // ... AND if r's seventh doesn't exist... (because this will push the implied triad up a third (example: C, E, D implies C mixed with G major, but C, E, D *and* F implies C mixed with a B diminished triad) ) weight[r]++; // ... then increment r's weight. } } } } if ( degree[mod7(r+0)]==1 && degree[mod7(r+2)]==1 && degree[mod7(r+4)]==1) { weight[r]++; } // Finally, increment degree's weight if all notes in triad are present } // Simply prints the chord before the main alogirithm calculates the weights for each degree. printf("Chord: "); for (int r=0 ; r=7) { while (a>=7) a-=7; } if (a<0) { while (a<0) a+=7; } return a; }