Forums > MaxMSP

Probably Newbie Question (logarithmic sliders)

August 4, 2008 | 7:05 am

So I’ve got a slider controlling the center frequency of a filtergraph object, only the slider isn’t logarthmic, and the filtergraph display is. How do I get the slider to output logarthmically, ideally without using an MSP slider?

IE, what equation do I put between the filter’s output and the filtergraph input to make it function correctly? (lower values should be more precise than higher values, 0-200 should take up almost half the graph, and 200-22000 should take up the other half, but with a smooth curve).

I’m sure this is easy, I just haven’t figured it out. :/


August 4, 2008 | 7:27 am

You can use the scale object with a fifth argument. The fifth argument needs to be a floating-point number greater than one otherwise it will be a linear mapping(see help-file for scale).

Example:

– Pasted Max Patch, click to expand. –

August 4, 2008 | 7:29 am

oh
…uh… alter the slider in that example so the range is actually 128 otherwise, you won’t go all the way up to 20k(with range 127 and minimum 0, you only get up to 126 and scale is scaling 0 through 127 between 0 and 20000…. well, you know, you can tweak it out how you like it…).


August 4, 2008 | 8:28 am

Posted by Luke a few days ago (look for logarithmic in title of message…)

– Pasted Max Patch, click to expand. –

August 4, 2008 | 8:51 am

On Aug 4, 2008, at 12:05 AM, mushoo wrote:

> IE, what equation do I put between the filter’s output and the
> filtergraph input to make it function correctly? (lower values
> should be more precise than higher values, 0-200 should take up
> almost half the graph, and 200-22000 should take up the other half,
> but with a smooth curve).

mtof would work.

-C

Chris Muir
cbm@well.com

http://www.xfade.com


August 4, 2008 | 1:52 pm

Ah! Thanks for all the replies, guys.

Also, thanks for making me finally figure out what to do with the new max5 text chunks! I like that you can just copy/paste now. (Is that ever explained anywhere?)


August 4, 2008 | 3:39 pm

Ooookay, got a slightly harder problem for you all this time.

I need to do it in reverse.

the included patch is something you’ve probably seen before, I’m using it to allow the user to set a number box, or the slider, without a feedback loop. (I also take the [float] output and use it for a settings-save system).

The problem is that I need a second scale object for getting the numbers from the float back into the slider’s 1-128 range, but scaling with the right curve. As it is right now, the slider is functioning… oddly. The ‘set $1′ command is slamming the slider around to the edges.

– Pasted Max Patch, click to expand. –

August 4, 2008 | 5:42 pm

The patch below is the closest I can get, it makes the slider less jumpy, but now the slider "feels" logarithmic instead of linear. If you want it to keep the linear "feel" while having logarithmic output, you might need to use some fancy math within the object over the output again
(like the math from this post:
http://www.cycling74.com/forums/index.php?t=msg&th=34937&start=0&rid=6532&S=8105738c365ba48d24ca9519543a3561
)
(and just to let you know, if you give scale floating-point arguments it will output floats properly)

without delving into all the advanced math required for the "expr" object or similar stuff, this is the quickest, easiest thing I could come up with:

– Pasted Max Patch, click to expand. –

August 4, 2008 | 5:44 pm

oh wait, this one allows you to change number-boxes better along with the slider:

– Pasted Max Patch, click to expand. –

August 4, 2008 | 7:55 pm

I can’t open your Max 5 patch but I’m guessing you want the equation in reverse. You can use a combination of [mtof] or [ftom] with [scale] or you can use these [expr] equations.

I hope this is helpful. I’ve explained most of workings in the thread linked to above.

lh

max v2;
#N vpatcher 10 59 771 434;
#P window setfont "Sans Serif" 9.;
#P flonum 455 142 71 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 455 123 201 196617 scale 8.1758 12543.853516 20. 20000.;
#P flonum 455 106 71 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 455 87 31 196617 mtof;
#P user hslider 486 223 18 128 128 1 0 0;
#P number 486 206 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 2;
#P newex 486 175 204 196617 expr (((((log10(($f1/440.)))/(log10(2)))*12.)+69)-15.48682)/119.589417*127.;
#P number 378 195 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 378 231 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 378 212 99 196617 scale 15 135 0 127;
#P newex 378 176 31 196617 ftom;
#P flonum 234 118 71 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 2;
#P newex 234 87 209 196617 expr (pow(2.\,((($i1/127.*119.589417+15.48682)-69.)/12.)))*440.;
#P number 234 67 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P user hslider 234 47 18 128 128 1 0 0;
#P window setfont Helvetica 9.;
#P user filtergraph~ 59 178 256 128 21 9 20. 20000. 0.0625 16. 0 1 1 0 0 1 1;
#X frgb 170 170 170;
#X brgb 209 209 209;
#X rgb2 0 0 0;
#X rgb3 130 130 130;
#X rgb4 0 0 0;
#X rgb5 76 108 172;
#X rgb6 210 74 54;
#X rgb7 255 22 22;
#X linmarkers 20. 50. 100. 250. 500. 1000. 2500. 5000. 10000. 20000.;
#X logmarkers 20. 50. 100. 250. 500. 1000. 2500. 5000. 10000. 20000.;
#X nfilters 1;
#X setfilter 0 5 1 0 0 20000.001953 1.048069 2.5 0. 0. 0. 0. 0. 0.;
#X done;
#P connect 1 0 2 0;
#P connect 2 0 3 0;
#P connect 3 0 4 0;
#P connect 4 0 0 5;
#P fasten 4 0 5 0 239 172 383 172;
#P connect 5 0 8 0;
#P connect 8 0 6 0;
#P connect 6 0 7 0;
#P fasten 2 0 12 0 239 84 460 84;
#P connect 12 0 13 0;
#P connect 13 0 14 0;
#P connect 14 0 15 0;
#P fasten 4 0 9 0 239 172 491 172;
#P connect 9 0 10 0;
#P connect 10 0 11 0;
#P pop;


August 5, 2008 | 12:27 am

holy crap that mtof/ftom example works perfectly!

thereIShopeforus!


August 5, 2008 | 12:56 am

I knew there was a reason I did a maths A-level. It wasn’t a completely useless waste of time after all!

lh


August 6, 2008 | 2:36 pm

raja schrieb:
> without delving into all the advanced math required for the "expr"
> object or similar stuff, this is the quickest, easiest thing I could
> come up with:

The problem is your 0 HZ point, can’t really work with a logarithmic
curve if you think about it…
(I know why I never touch that fifth argument to scale, nobody knows
what it does exactly anyway… ;-)

My version:

– Pasted Max Patch, click to expand. –


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com


Viewing 13 posts - 1 through 13 (of 13 total)