Spec for pre-defied values?

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 :slight_smile:

1 Like

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

thanks for the hints and example implementations!
And thanks (again) to @Wouter_Snoei for all the really helpful SC extensions :slight_smile:

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])