howto: skip specific data values? hard to describe

hey - thanks for taking a look at my problem.

ok: this should be easy. i have a value that i'm controlling via a Parallax PING sonar sensor. i have it configured just the way i want it, with a value of 0-127. you guessed it - i'm using it as a midi controller, with the value of 0-127 determining the note output.

now, my problem is this: 0-127 is a chromatic scale. it contains every possible midi note. instead of a chromatic scale, i want this controller to default to a C major scale*. to do that, i must remove certain values from the 0-127 range. my data must jump smoothly from value to value, as follows:

0 C-1 2 D-1 4 E-1 5 F-1 7 G-1 9 A-1 11 B-1 12 C-0 14 D-0 16 E-0 17 F-0 19 G-0 21 A-0 23 B-0 24 C 1 ... 127 G 9

and so on. so, how does one change a linear value of 0-127 to something that occasionally skips a number?

thanks for your time and ideas.

  • reason for wanting to have this controller default to C major: i use a VST plugin to transpose notes from C major to force the scale into ANY scale, major or minor.

Have a play with that :)

thanks for your suggestion. i use map() a lot, but always just to specify a high and low range for the data. afaik, map() wouldn’t prevent certain values from being outputted while allowing others. perhaps i’m missing something on this page, but it appears to tell me the same thing: a mapped value would still be consecutive 0-127, as opposed to “swiss cheese” 0-127

If you have this variable:


Then you can use that to truncuate the 0...127 range into something like (NUMBER_OF_TONES_IN_SCALE*NUMBER_OF_SCALES) So if you have 7 tones in your scale, across 3 octaves, you need to map the 0...127 to 0...21 When that is done you can simply have a lookup table with the values for the note.


Then use byte send = notes[currentNoteFromMapCalc];


ahhh. yes. that makes way more sense.
lookuptable is an array, & mappedvalue = array’s index number, correct?
i have not yet used an array but it looks straightforward in this application.

so, 0-75 (since there are 75 notes i want to use out of the 0-127 available)
and then a 76 value array used as a lookup table for the actual note values, correct?

You've got it! :)

thank you very much for your time and help.

I don't know much about musical scales (except the 12-tone with a twelth-root of 2 increase in frequency one, not sure what its called, chromatic?).

But did you make a mistake in your list?

0 C-1 2 D-1 4 E-1 5 F-1 7 G-1 9 A-1 11 B-1 12 C-0 14 D-0 16 E-0 17 F-0 19 G-0 21 A-0 23 B-0 24 C 1 ... 127 G 9

I see a pattern of 3 consecutive step-of 2, then +1, and then 3 new steps of +2, etc. Except on your 23rd element here, there are 4 values with a space of 2. If it should be 3 values, then I'm sure some sort of formula or algorithm can be derived.