I flunked math(s)

Jan 29, 2010 at 4:41pm

I flunked math(s)

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

– Pasted Max Patch, click to expand. –
#39123
Jan 29, 2010 at 5:51pm

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.

#137334
Jan 29, 2010 at 8:13pm

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

#137335
Jan 29, 2010 at 10:12pm

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.

#137336
Jan 30, 2010 at 5:05am

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

#137337
Jan 30, 2010 at 5:45am

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!

#137338

You must be logged in to reply to this topic.