//getpitch -- gets two values: the first is an iterator value coming from
// the score file which iterates through the list of chords.
// The second value is either 0, 1, 2, where:
// 0: the root pitch
// 1: the first interval
// 2: the second interval
//---------------------------------------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ugens.h>

extern struct chord curchord[MAXCHORDS];

double getpitch(float *p, short n_args){

int decimalext, newroot, i, step;
int num = p[0];
int interval = (int)p[1];
double newpitch;
float temp;

switch(interval){

case 0:

newpitch = curchord[num].root * 0.01;
break;

case 1:

newroot = curchord[num].root/100;

decimalext = curchord[num].root % 100;

step = curchord[num].triadtype[0];

for(i = 1; i <= step; i++){

if(decimalext % 12 == 0){

newroot++;
decimalext = 1;

}
else

decimalext++;

}

newpitch = (newroot + decimalext * 0.01);
break;

case 2:

newroot = curchord[num].root/100;
decimalext = curchord[num].root % 100;

step = curchord[num].triadtype[0] + curchord[num].triadtype[1];

for(i = 1; i <= step; i++){

if(decimalext % 12 == 0){

newroot++;
decimalext = 1;

}
else

decimalext++;

}
newpitch = (newroot + decimalext * 0.01);
break;

case 3:

newroot = curchord[num].root/100;
decimalext = curchord[num].root % 100;
step = curchord[num].triadtype[0] + curchord[num].triadtype[1] + curchord[num].triadtype[2];

for(i = 1; i <= step; i++){

if(decimalext % 12 == 0){

newroot++;
decimalext = 1;
}

else

decimalext++;

}
newpitch = (newroot + decimalext * 0.01);
break;


}//end switch

return newpitch;

}//end getpitch