LFSaw
August 22, 2025, 12:55pm
1
Heya,
I was wondering: is there a Spec for pre-defined values?
Something along the lines of
v = ValuesSpec([100, 200, 413, 1.02456]) // spec with 4 values
v.map(0); // 100
v.map(0.25); // vals >= 0.25 >> 200
v.map(0.5); // vals >= 0.5 >> 413
v.map(0.75); // vals >= 0.75 >> 1.02456
v.unmap(100); // 0
v.unmap(200); // 0.25
v.unmap(1.02456); // 0.75
v.unmap(413); // 0.5
thanks for any hint
1 Like
TXMod
August 22, 2025, 6:57pm
2
Maybe make your own - something like this?:
(
v = ();
v.vals = [100, 200, 413, 1.02456]; // spec with 4 values
v.map = {arg event, val; v.vals[val.linlin(0, 1,0, v.vals.size).asInteger]};
v.unmap = {arg event, val;
var outVal;
var ind = v.vals.indexOfEqual(val);
if (ind.notNil, {
outVal = ind / v.vals.size;
});
outVal;
};
)
v.map(0); // -> 100
v.map(0.25); // -> 200
v.map(0.5); // -> 413
v.map(0.75); // -> 1.02456
v.map(33); // -> nil
v.unmap(100); // -> 0
v.unmap(200); // -> 0.25
v.unmap(1.02456); // -> 0.75
v.unmap(413); // -> 0.5
v.unmap(999999); // -> nil
Hope that helps,
Paul
2 Likes
Thereโs SegWarp in wslib quark, Iโve never used it but maybe it does what you need?
1 Like
LFSaw
August 23, 2025, 10:34am
4
thanks for the hints and example implementations!
And thanks (again) to @Wouter_Snoei for all the really helpful SC extensions
This is doing exactly what I want:
// SegWarp by Wouter (WSLib)
l = [100, 200, 413, 1.02456]; // the elements to
a = SegWarp(Env.step(l, (1!l.size).normalizeSum))
a.map([0, 0.25, 0.5, 0.75])