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.