how to increment values held inside an array?

Hi all,

I am a total amateur with regards to coding, so please excuse my ignorance.

I am building a midi instrument that can be 'tuned' by the user. In other words, the user will be able to select a scale and key and will then be limited to the notes in that key and scale.

At first I thought my project would require a series of look-up tables containing the midi note numbers for a long series of scales and keys.

However, my brain suddenly started working today and I realized that with regards to selecting a key, all I really need is to increment the values held inside such an array to the amount appropriate for the selected key.

For example, the midi numbers assigned to one octave of the C Major scale looks like this:

[60, 62, 64, 65, 67, 69, 71]

and C# Major looks like this:

[61, 63, 65, 66, 68, 70, 72]

and D Major looks like this:

[62, 64, 66, 67, 69, 71, 73]

... etc ...

I am confident that there must be a way to write a formula that says:

"Here is an array containing all of the notes in the C Major scale. When the user selects C# Major, add 1 to each of the values held in the C Major array. When the user selects D Major, add 2 to each of the values in the C Major array."

... and so on ...

In this fashion I would only need to have arrays for each scale in the key of C as opposed to also having to do so for each of the other keys.

Anyone willing to point me in the right direction? I feel like I have the concept but I struggle with the syntax.

What is the maximum value for the note numbers (60, 62, 64)? How many notes (numbers) in a scale?

the midi note numbers range from 0-127. So the maximum value for the note numbers is 127, and the maximum notes in a scale is 128 (chromatic scale).

I believe that the other scales that I will use will be 72 notes (8 tone scale), 63 (7 tones), 54 (6 tones), and 45 (5 tones).

Thank you.

So what I am trying to do is transpose each of those scales across 12 keys.

Ah, I think I've got it. I won't be able to test it till I get home, though.

I don't need to change the figures in the array. I just need to add 1 or 2 or what-have-you to the note that's being played.

So when the user is in the C major scale and:

note=mapped_note_value[c_maj_scale];

then when they are in C# major:

note=(mapped_note_value[c_maj_scale] +1);

or something to that effect.

I've probably got the syntax wrong there but I think I'm on the right track!

Something like this?

byte keyoffset = 0;
byte transpose(byte note)
{
    return keyoffset + mapped_note_value[note];
}

keyoffset = 1;  //shift keys
note=mapped_note_value[c_maj_scale];