src/Convert-pitch.cpp
int Convert::pitchToWbh(int dpc, int acc, int octave, int maxacc) {
	if (dpc > 6) {
		// allow for pitch-classes expressed as ASCII characters:
		dpc = tolower(dpc) - 'a' + 5;
		dpc = dpc % 7;
	}
	int output = -1000;
	switch (dpc) {
		case 0: output = maxacc;            break;
		case 1: output =  3  * maxacc + 2;  break;
		case 2: output =  5  * maxacc + 4;  break;
		case 3: output =  7  * maxacc + 5;  break;
		case 4: output =  9  * maxacc + 7;  break;
		case 5: output =  11 * maxacc + 9;  break;
		case 6: output =  13 * maxacc + 11; break;
	}
	if (output < 0) {
		return output;
	}
	return (output + acc) + (7 * (maxacc * 2 + 1) + 5) * octave;
}
//////////////////////////////
//
// Convert::pitchToWbh -- Convert a given diatonic pitch class and
//   accidental adjustment into an integer.  The diatonic pitch class
//   is C=0, D=1, E=2, F=3, G=4, A=5, B=6. "acc" is the accidental
//   count: -2=double flat, -1=double flat, 0 natural, +1=sharp, etc.
//   "octave" is the octave number, with middle-C being the start of
//   octave 4.  //   "maxacc" is the maximum accidental which defines
//    the base:
//    maxacc = 2 -> Base-40.
//    maxacc = n -> Base (n*2+1)*7 + 5.
//
:pitchToWbh -- Convert a given diatonic pitch class and
accidental adjustment into an integer.
: pitchToWbh -- Convert a given diatonic pitch class and accidental adjustment into an integer .
int Convert::pitchToWbh(int dpc, int acc, int octave, int maxacc) {
	if (dpc > 6) {
		dpc = tolower(dpc) - 'a' + 5;
		dpc = dpc % 7;
	}
	int output = -1000;
	switch (dpc) {
		case 0: output = maxacc;            break;
		case 1: output =  3  * maxacc + 2;  break;
		case 2: output =  5  * maxacc + 4;  break;
		case 3: output =  7  * maxacc + 5;  break;
		case 4: output =  9  * maxacc + 7;  break;
		case 5: output =  11 * maxacc + 9;  break;
		case 6: output =  13 * maxacc + 11; break;
	}
	if (output < 0) {
		return output;
	}
	return (output + acc) + (7 * (maxacc * 2 + 1) + 5) * octave;
}
int Convert :: pitchToWbh ( int dpc , int acc , int octave , int maxacc ) { if ( dpc > 6 ) { dpc = tolower ( dpc ) - ' ' + 5 ; dpc = dpc % 7 ; } int output = -1000 ; switch ( dpc ) { case 0 : output = maxacc ; break ; case 1 : output = 3 * maxacc + 2 ; break ; case 2 : output = 5 * maxacc + 4 ; break ; case 3 : output = 7 * maxacc + 5 ; break ; case 4 : output = 9 * maxacc + 7 ; break ; case 5 : output = 11 * maxacc + 9 ; break ; case 6 : output = 13 * maxacc + 11 ; break ; } if ( output < 0 ) { return output ; } return ( output + acc ) + ( 7 * ( maxacc * 2 + 1 ) + 5 ) * octave ; }
Convert::pitchToWbh -- Convert a given diatonic pitch class and
accidental adjustment into an integer.
Convert :: pitchToWbh -- Convert a given diatonic pitch class and accidental adjustment into an integer .
// allow for pitch-classes expressed as ASCII characters: