Better Approach to Range Values with Uneven steps

Hi,

I'm trying to create a range widget to control the range of an instrument. I want to create it just using the full C-2 to G8, only base notes, and control the sharps/flats later. I'm having trouble creating even steps between each of the pips. I've shared a session to showcase me just coming up with percentages for each step in the range property, but I'm wondering if there is a better approach and if it's possible to achieve even steps between the pips instead of the gaps I've produced.

rangeWidgetExample.json (11.4 KB)

Range property with steps at 75

{
  "0%": { "C-2": "0" },
  "1.3513513513513514%": { "": "0.013513513513513514" },
  "2.702702702702703%": { "": "0.02702702702702703" },
  "4.054054054054054%": { "": "0.04054054054054054" },
  "5.405405405405405%": { "": "0.05405405405405406" },
  "6.756756756756757%": { "": "0.06756756756756757" },
  "8.108108108108109%": { "": "0.08108108108108109" },
  "9.45945945945946%": { "C-1": "0.0945945945945946" },
  "10.81081081081081%": { "": "0.10810810810810811" },
  "12.162162162162163%": { "": "0.12162162162162163" },
  "13.513513513513514%": { "": "0.13513513513513514" },
  "14.864864864864865%": { "": "0.14864864864864866" },
  "16.216216216216217%": { "": "0.16216216216216217" },
  "17.567567567567569%": { "": "0.17567567567567569" },
  "18.91891891891892%": { "C0": "0.1891891891891892" },
  "20.27027027027027%": { "": "0.20270270270270271" },
  "21.621621621621623%": { "": "0.21621621621621623" },
  "22.972972972972973%": { "": "0.22972972972972974" },
  "24.324324324324326%": { "": "0.24324324324324326" },
  "25.675675675675677%": { "": "0.25675675675675674" },
  "27.02702702702703%": { "": "0.2702702702702703" },
  "28.378378378378377%": { "C1": "0.28378378378378377" },
  "29.72972972972973%": { "": "0.2972972972972973" },
  "31.081081081081083%": { "": "0.3108108108108108" },
  "32.432432432432435%": { "": "0.32432432432432434" },
  "33.783783783783785%": { "": "0.33783783783783783" },
  "35.13513513513514%": { "": "0.35135135135135137" },
  "36.48648648648649%": { "": "0.36486486486486486" },
  "37.83783783783784%": { "C2": "0.3783783783783784" },
  "39.18918918918919%": { "": "0.3918918918918919" },
  "40.54054054054054%": { "": "0.40540540540540543" },
  "41.891891891891894%": { "": "0.4189189189189189" },
  "43.24324324324325%": { "": "0.43243243243243246" },
  "44.594594594594594%": { "": "0.44594594594594594" },
  "45.94594594594595%": { "": "0.4594594594594595" },
  "47.2972972972973%": { "C3": "0.47297297297297297" },
  "48.64864864864865%": { "": "0.4864864864864865" },
  "50%": { "": "0.5" },
  "51.35135135135135%": { "": "0.5135135135135135" },
  "52.702702702702705%": { "": "0.527027027027027" },
  "54.054054054054056%": { "": "0.5405405405405406" },
  "55.40540540540541%": { "": "0.5540540540540541" },
  "56.75675675675676%": { "C4": "0.5675675675675675" },
  "58.10810810810811%": { "": "0.581081081081081" },
  "59.45945945945946%": { "": "0.5945945945945946" },
  "60.810810810810814%": { "": "0.6081081081081081" },
  "62.16216216216216%": { "": "0.6216216216216216" },
  "63.51351351351352%": { "": "0.6351351351351351" },
  "64.86486486486487%": { "": "0.6486486486486487" },
  "66.21621621621622%": { "C5": "0.6621621621621622" },
  "67.56756756756757%": { "": "0.6756756756756757" },
  "68.91891891891892%": { "": "0.6891891891891891" },
  "70.27027027027027%": { "": "0.7027027027027027" },
  "71.62162162162163%": { "": "0.7162162162162162" },
  "72.97297297297297%": { "": "0.7297297297297297" },
  "74.32432432432433%": { "": "0.7432432432432432" },
  "75.67567567567568%": { "C6": "0.7567567567567568" },
  "77.02702702702703%": { "": "0.7702702702702703" },
  "78.37837837837838%": { "": "0.7837837837837838" },
  "79.72972972972973%": { "": "0.7972972972972973" },
  "81.08108108108108%": { "": "0.8108108108108109" },
  "82.43243243243244%": { "": "0.8243243243243243" },
  "83.78378378378379%": { "": "0.8378378378378378" },
  "85.13513513513513%": { "C7": "0.8513513513513513" },
  "86.48648648648649%": { "": "0.8648648648648649" },
  "87.83783783783784%": { "": "0.8783783783783784" },
  "89.18918918918919%": { "": "0.8918918918918919" },
  "90.54054054054054%": { "": "0.9054054054054054" },
  "91.8918918918919%": { "": "0.918918918918919" },
  "93.24324324324325%": { "": "0.9324324324324325" },
  "94.5945945945946%": { "C8": "0.9459459459459459" },
  "95.94594594594595%": { "": "0.9594594594594594" },
  "97.2972972972973%": { "": "0.972972972972973" },
  "98.64864864864865%": { "": "0.9864864864864865" },
  "100%": { "": "1" }
}

Cheers,
DMDComposer

There's a actually a bug there (pips should be evenly spaced in this case) , to be fixed in next release.

2 Likes

Many thanks for your range widget, @DMDComposer. I learned a lot studying it.

I noticed that your range is tied to a whole note scale. Was this by necessity? I noted that you only had quotes around your negative octaves ("C-2"...C0) and that sharps seem to cause an error when they are not in quotes. Any rationale for not having quotes around all entries?

I tried to adapt your widget into one with a 12 note-octave resolution and I have been struggling to get it working. Some of the notes show up correctly in the console, which makes me suspect that it is a value accuracy issue. However, Math.round doesn't seem to be working inside a range widget.

You've been immensely helpful to me in the past. I appreciate all your help past and future and I hope I don't burden you with too many questions!

RangeTest.json (31.1 KB)

PS. You probably don't need these, but here are two python scripts I wrote to quickly generate these datasets

def generate_dataset():.txt (1.3 KB)
def generate_midi_scale_notes():.txt (908 Bytes)

1 Like

Hi Samson,

I'm glad my posts have been useful!

I noticed that your range is tied to a whole note scale. Was this by necessity?

If I recall, originally was making this range for a harp scale which is why I didn't have the full 12 note octave.

I noted that you only had quotes around your negative octaves ("C-2"...C0) and that sharps seem to cause an error when they are not in quotes. Any rationale for not having quotes around all entries?

Hmmm... I'm assuming I did that because of JS rules. Since it's a key value object, if there is a hyphen in the key then you need to encase it with quotations. I believe so anyway. Sometimes I forget little things like this because VS Code handles it for me. :upside_down_face:

I tried to adapt your widget into one with a 12 note-octave resolution and I have been struggling to get it working. Some of the notes show up correctly in the console, which makes me suspect that it is a value accuracy issue. However, Math.round doesn't seem to be working inside a range widget.

I actually use a JS function inside the range value (with steps set to 128), to handle this. Something like this below should work which you can adapt to your specific needs.

JS{
    let step = 0
    let steps = @{this.steps}
    let maxSteps = steps - 1
    let range = {}

    const labelNames = {
        120: "C8",
        108: "C7",
        96: "C6",
        84: "C5",
        72: "C4",
        60: "C3",
        48: "C2",
        36: "C1",
        24: "C0",
        12: "C-1",
        0: "C-2",
    }
    

    for (let i = 0; i <= steps; i++) {
        // Handle the situation where the loop exceeds the maximum allowed
        // iterations, exit the loop.
        if (i > steps) break

        // ensure 100% is always 100%
        step >= maxSteps ? (step = maxSteps) : step
        

        range[`${step}%`] = {"": i}
        
        if (Object.keys(labelNames).includes(i.toString())) {
            let label = {}
            label[labelNames[i]] = i
            range[`${step}%`] = label
        }

        step += 100 / maxSteps
    }
    
    return range
}

Cheers!