I flunked math(s)

brendan mccloskey's icon

I've built a little pentatonic chord/melody generator (for performers with limited physical capabilities); the pitch-sets fixate on a certain ambit or span, until the user transposes that ambit (via one cc#); as the transposition increases, so does the ambit, until the max transposition is reached, while the ambit shrinks, so you get: very few lowest notes, more mid-range notes, lots of notes, fewer higher notes, very few highest notes. Not explained very clearly, but the patch (below) is dead simple. Here's my question: I've used a coll ([coll log] in the patch) to generate this curve of small ambit-large ambit-small ambit, cos i suck at math(s); there must be a more elegant math function to do this? [!/] or some such.
Thanks everyone

Max Patch
Copy patch and select New From Clipboard in Max.

Brian Gruber's icon

your coll is equivalent to "expr 12 - 2 * abs($i1 - 6)". I wouldn't make any bets on which was faster though, if that's what you're after.

brendan mccloskey's icon

I wouldn't have got that in an eternity of math-revision. Thanks; I wasn't concerned with the speed of the computation, just that the [coll] was a little clunky and inelegant. If you've got another 5 mins i'd love to know how you arrived at the [expr] function;
thanks again

Brian Gruber's icon

Imagine your function plotted on coordinate axes. You have 2 lines: from 0 to 6, it has a slope of 2, and from 6 to 12 it has a slope of -2.

Let's slide the whole thing over to the left so that the 'peak' is at 0 instead of 6. We can find the equation for the line on the positive side using formula y = mx + b, where m is the slope and b is the "y intercept"--where the line hits the y axis. So we get y = -2x + 12.

The line on the negative side is just the mirror image, so to get its equation we negate x. y = (-2)*(-x) + 12. One way of defining the absolute value function is that it negates negative numbers and leaves positive numbers alone, so we can combine the equations for the two lines by saying y = -2|x| + 12, where |x| means the absolute value of x.

Finally, we have to slide the whole thing back to the right by 6. In order to do that, we subtract 6 from x. y = -2|x-6| + 12

If that sounded really complicated, it's only because I tried to be as explicit as possible in my explanation.

brendan mccloskey's icon

thanks very much for this; it couldn't be any clearer - i'm off to play with [expr] for a few days now...

seejayjames's icon

also check out the "a few math functions" in the jit.displays help file, might give some ideas for curves.

You can plot a ton of points in a hurry with [uzi] and [expr], provided you use [scale] at the right places to set your X and/or Y values to appropriate ranges...

the modulo [%] is often very helpful when dealing with pitches, as they repeat at the octave [% 12]. same goes for the "everything else" outlets of [select] and [route].

also jit.bfg will give you some *really* nice curves and stepping functions, and looks incredibly cool when plugged into a jit.gl.mesh @polymode 1 1 (wireframe). rolling hills of math!