Synth - modify keyboard scanner from 37keys to 49keys keyboard

I’m new to the world of Arduino, and fascinated by the possibilities within audio and synthesis.

My first project is the “How to build a string synth”-project by Jan Östman (, and I’ve run into some problems mainly because I’m not using an 37keys keyboard with 8x5 key matrix.

I’m using an M-Audio keyboard, with 49 keys and an 8x6 keyboard matrix (with one addition, although I haven’t managed to find the 49th key yet - the top C). The code from the project that I need to modify (I think), is:

//—————— Key scanner —————————–
if ((k&0x38)==(0x00<<3)) PORTC&=B11111110;
if ((k&0x38)==(0x01<<3)) PORTC&=B11111101;
if ((k&0x38)==(0x02<<3)) PORTC&=B11111011;
if ((k&0x38)==(0x03<<3)) PORTC&=B11110111;
if ((k&0x38)==(0x04<<3)) PORTC&=B11101111;
if (oldkeytable[k]!=keytable[k]) { //Handle keyevent
if (keytable[k]==0) {
else {
if (k==40) {

I assume the 5 if-statements are the “x5” in the original 8x5 matrix, and I’ve tried to add an additional one, without success. (if ((k&0x38)==(0x05<<3)) PORTC&=B11011111;). I also tried to change the 38 to 50, because I was thinking that 38 was referring to the 37 keys +1.

As you can tell, I’m shooting in darkness, and with only some experience with Visual Basic in Excel, I’m at a loss for modifying the key scanner to suit my keyboard.

Does anyone have any clues to point me in the right direction?