Cabbage Logo
Back to Cabbage Site

Code for list of scales

Spent some time putting various scales into step values for cpsmidiin Now I’m just wondering if there’s a more elegant way to do this (selecting the scale from the combobox) other than endless elseif's.

I was thinking of using a 2d array but I think it might use the same amount of code… anyway this is really ugly so looking forward to seeing if anyone has a better suggestion :laughing:

iScaleSelect=chnget("Scale")
if iScaleSelect == 1 then
    giNotes[] fillarray 0, 2, 4, 7, 11, 12, 14, 17 ;Major
 elseif iScaleSelect == 2 then
    giNotes[] fillarray 0, 2, 3, 7, 10, 12, 15, 19 ;minor
 elseif iScaleSelect == 3 then
     giNotes[] fillarray 0, 2, 4, 7, 9, 12, 16, 19 ;Major Pent
 elseif iScaleSelect == 4 then
     giNotes[] fillarray 0, 3, 5, 7, 9, 12, 15, 19  ;minor Pent
 elseif iScaleSelect == 5 then
     giNotes[] fillarray 0, 3, 5, 7, 8, 11, 12, 14  ;Harmonic Minor
 elseif iScaleSelect == 6 then
     giNotes[] fillarray 0, 3, 5, 7, 9, 11, 12, 14  ;Melodic Minor
 elseif iScaleSelect == 7 then
     giNotes[] fillarray 0, 1, 4, 5, 7, 8, 11, 12  ;Hijaz Kar
 elseif iScaleSelect == 8 then
    giNotes[] fillarray 0, 2, 3, 7, 8, 12, 15, 20 ;Hirajoshi
 elseif iScaleSelect == 2 then
    giNotes[] fillarray 0, 2, 5, 7, 9, 12, 2, 14 ;Yo
 elseif iScaleSelect == 9 then
    giNotes[] fillarray 0, 2, 3, 6, 7, 8, 11, 12 ;Hungarian Minor
 elseif iScaleSelect == 10 then
    giNotes[] fillarray 0, 2, 4, 6, 7, 9, 11, 12  ;Lydian
 elseif iScaleSelect == 11 then
    giNotes[] fillarray 0, 2, 4, 5, 7, 9, 10, 12 ;mixolydian
 elseif iScaleSelect == 12 then
    giNotes[] fillarray 0, 2, 3, 5, 7, 9, 10, 12  ;Dorian
 elseif iScaleSelect == 13 then
    giNotes[] fillarray 0, 2, 3, 5, 7, 8, 10, 12 ;Aeolian
 elseif iScaleSelect == 14 then
    giNotes[] fillarray 0, 1, 3, 5, 7, 8, 10, 12  ;Phrygian
 elseif iScaleSelect == 15 then
    giNotes[] fillarray 0, 1, 3, 5, 6, 8, 10, 12 ;Locrian
endif
1 Like

You could define them all in tables using GEN -2 and then uses the the combobox index to select the relevant table:

iScaleSelect=chnget("Scale")
giNotes[] tab2array iScaleSelect

By my rough calculations, that reduce the code by about 50% :thinking:

1 Like

Cool. Thought about that too but the drawback is that the tables have to have fixed numbers so it’s less portable. Hmmm… tradeoffs……

What I often do is set the table to a max size, say 64. Then set the first index of the table to be the number of elements I’m using from the array. You can almost make it seem like you’re working with a list/vector this way.