range(x,min, max) where min>max

Send us your feedback or ask for features.
Post Reply
Softcore
Regular
Posts:1639
Joined:04 Nov 2012 08:34
range(x,min, max) where min>max

Post by Softcore » 27 Feb 2015 14:10

Try this with Fader and a monitor:

Montitor.value = range(Fader.x, 127,0);

It WOULD be cool if this would give us an inverted 0 - 127 range so that:

When Fader.x = 0 -> Monitor.value=127;
When Fader.x = 1 -> Monitor.value=0;

Joe Soap
Regular
Posts:475
Joined:07 Jul 2012 15:04

Re: range(x,min, max) where min>max

Post by Joe Soap » 27 Feb 2015 19:21

Monitor.value = 127 - Fader.x * 127

Softcore
Regular
Posts:1639
Joined:04 Nov 2012 08:34

Re: range(x,min, max) where min>max

Post by Softcore » 28 Feb 2015 11:04

Yeah I know bro....Its just an example. I have a specific usage case scenario where I need to "invert" a couple of generated values which go through a range object....Being able to use the function as I describe would save me some (many) lines of coding.

Aaaanyways.....

ndivuyo
Regular
Posts:279
Joined:23 May 2014 00:24

Re: range(x,min, max) where min>max

Post by ndivuyo » 28 Feb 2015 11:13

on a slightly related note, it would be cool to come up with a user defined function that works a lot like the scale object in max. args: (x, low in, hi in, low out, hi out) and maybe even the sixth argument for an exponential slope. Having it work for a single value and vector would be ideal. Anyone interested and got the know how?
It should accomplish also what you are saying, but not as specific.

anyway..

Softcore
Regular
Posts:1639
Joined:04 Nov 2012 08:34

Re: range(x,min, max) where min>max

Post by Softcore » 01 Mar 2015 11:02

Ah this is easy in fact! I just always thought that built in functions must be less ram-cpu hungry than custom ones.

The maths behind it is:

NewValue = (((OldValue - OldMin) * NewRange) / OldRange) + NewMin
where
OldRange = (OldMax - OldMin)
NewRange = (NewMax - NewMin)

So, I made two custom functions:

ranged(x,oldmin,oldmax,min,max) converts a variable x of ANY range (including negative ones) to a new range. Min>max works too!

Specifically in the case that the input is in our familiar 0 to 1 range a simplified function, I made:
rangednorm(x,min,max)
Attachments
convertranges.jzml
(7.43KiB)Downloaded 257 times


Post Reply