/*====================================================/ / Name: genmus.h / / Author: Joy Schoenberger / / Date: April 2002 / / Purpose: Header file containing data structures for / / CS710 Masters research project: Genetic / / Algorithms for Musical Composition with / / Coherency Through Genotype / /====================================================*/ #include #include #include "bitFunctions.h" #include #define numChords 8 #define numIntervals 25 #define numPhrasePatterns 8 #define numSemiTones 12 #define numBeats 32 #define convert "CdDeEFgGaAbBCdDeEFgGaAbBCdDeEFgGaAbBCdDeEFgGaAbBCdDeEFgGaAbBC" #define bitKey 3418u #define numPhrases 4 struct Chord{ int numNotes; unsigned int semitones; void initialize(){ semitones = clearAll(); } void setTone(int n){ semitones = setBit(semitones,n); } bool isOn(int n){ return (isSet(semitones,n)); } bool adj(int a, int b){ char aLet, bLet; aLet = toupper(convert[a]); bLet = toupper(convert[b]); if(aLet == bLet) return true; if( ((aLet-1) == bLet)||((aLet+1) == bLet) ) return true; if((aLet == 'A') && (bLet == 'G')) return true; if((aLet == 'G') && (bLet == 'A')) return true; return false; } bool dissonant(){ // if any two pitches in the chord share the same // conversion letter, the chord is dissonant for(int i = 0;i<11;i++){ for(int j = i+1;j<12;j++){ if(isSet(semitones,i) && isSet(semitones,j) && adj(i,j)) return true; } } return false; } void display(){ for(int i = 0;i30) while(!isSet(played2,index-31))index++; } return index; } bool isEmpty(){ for(int i = 0;i<31;i++) if(isSet(played1,i))return false; for(int i = 31;i<61;i++) if(isSet(played2,i-31))return false; return true; } void display(){ for(int k = 0;k<31;k++) if(isSet(played1,k)) cout << k << "(" << convert[k] << ") "; for(int k = 31;k<61;k++) if(isSet(played2,k-31)) cout << k << "(" << convert[k] << ") "; cout << endl; } int min(){ int k = 61; while((!isSet(played2,k-31))&&(k>30)) k--; if(k == 30) while((!isSet(played1,k))&&(k>-1)) k--; return k; } int max(){ int k = 0; while((!isSet(played1,k))&&(k<31)) k++; if(k == 31) while((!isSet(played2,k-31))&&(k<62)) k++; return k; } Chord compress(){ // compress note into one octave Chord retChord; retChord.initialize(); int sounded; for(int n = 0; n<12; n++){ for(int octave = 0;octave < 5; octave++){ sounded = n + octave * 12; if((sounded < 31)&&(isSet(played1,sounded))) retChord.setTone(n); else if((sounded >30)&&(isSet(played2,sounded-31))) retChord.setTone(n); } } return retChord; } int numInCommon(Note compare){ int ret = 0; for(int i = 0;i<31;i++) if(compare.isPlayed(i) && isSet(played1,i)) ret++; for(int i = 31;i<61;i++) if(compare.isPlayed(i) && isSet(played2,i-31)) ret++; return ret; } int numVoices(){ int ret = 0; for(int i = 0;i<31;i++){ if(isSet(played1,i)) ret++; if(isSet(played2,i)) ret++; } return ret; } }; struct Phrase { Note notes[numBeats]; void initialize(){ for(int i = 0; i < numBeats; i++) notes[i].initialize(); } void display(){ for(int i = 0;i