## ftm simplification using 'expr'

Jun 23, 2008 at 6:13am

# ftm simplification using 'expr'

hey all,

I’m trying to implement an equation and have a few questions:

[1] why does max add parenthesis????? i can’t delete un-wanted/needed
parenthesis. These added parenthesis are giving me a syntax error.

[2] how can i use variable within an equation?

here’s the patch:
#P origin 0 1;
#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P comment 132 205 804 196617 why are the parenthesis impossible to remove? … like the top equation , there should be two left parenthesis at the beginning and three right parenthesis at the end;
#P user ftm.mess 406 259 747 15 3 9 255 255 255 0 0 0 1 2 0 0 0 –> 0;
#T _#ftm version 2 3;
#T _#scope begin;
#T _#absargs \$0_ \$1_ \$2_ \$3_ \$4_ \$5_ \$6_ \$7_ \$8_ \$9_;
#T _#line “_(((floor (12 * ((log (((\$col + 1) / 1024) * 44100 / 440)) / (log 2)))) – ((floor (floor (12 * ((log (((\$col + 1) / 1024) * 44100 / 440)) / (log 2)))) / 12)) * 12))”;
#P user ftm.mess 14 177 1299 21 3 14 255 255 255 0 0 0 1 2 0 0 0 –> 0;
#T _#line “_((((((\$pcp fill (new expr ‘(((floor (12 * ((log (((\$col + 1) / 1024) * 44100 / 440)) / (log 2)))) – ((floor (floor (12 * ((log (((\$col + 1) / 1024) * 44100 / 440)) / (log 2)))) / 12)) * 12))’)))”;
#P user ftm.mess 47 128 822 27 3 18 255 255 255 0 0 0 1 2 0 0 0 –> 0;
#T _#line “_((\$pcp fill (new expr ‘(floor (12 * ((log (((\$col + 1) / 1024) * 44100 / 440)) / (log 2))))’)))”;
#N ftm.print –> 0;
#P newobj 193 325 51 196617 ftm.print;
#P user ftm.object 49 423 33 18 3 9 –> 0;
#T _#def 0 _440 ref local;
#P user ftm.object 49 400 45 18 3 9 –> 0;
#T _#def 0 _44100 sr local;
#P user ftm.object 49 377 39 18 3 9 –> 0;
#T _#def 0 _1024 N local;
#P user ftm.object 33 42 62 18 3 9 –> 0;
#T _#obj 1 mat;
#T _#def 0 “_mat 1 513″ pcp local;
#P flonum 191 240 35 9 1. 20. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P user ftm.mess 193 277 151 15 3 9 255 255 255 0 0 0 1 2 0 0 0 –> 0;
#T _#line “_(\$1 – ((floor (\$1 / 12)) * 12))”;
#T _#scope end;
#P comment 429 278 347 196617 this equation should like within the ” marks above.;
#P window linecount 5;
#P comment 115 379 100 196617 is there a way to express this equatino using variables rather than values?;
#P window linecount 1;
#P comment 275 364 331 196617 p(k) = (floor (12 * log2 (k/N * sr/ref))) mod 12;
#P connect 4 0 3 0;
#P fasten 3 0 9 0 198 292;
#P pop;

many many thanks.

#38542
Jun 23, 2008 at 6:25pm

You can’t write an equation in a message box (well, you can, but it won’t do anything).

In general, you need the expr object to write general mathematical expressions. Something like

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P newex 165 115 183 196617 expr \$f1 – ((floor (\$f1 / 12)) * 12);
#P window clipboard copytext “expr \$f1 – ((floor (\$f1 / 12)) * 12)” #E;
#P window clipboard copycount 1;

However, Max 4 expr doesn’t grok floor(). But that’s not a problem, just build a patch. Conversion from float to int automatically does a floor(). Writing the expression as a patch is an excellent exercise in learning to use Max idiomatically (and, no offense, but I think the idiomatic bit may need some work, guy)

But, hey, I was about to implement your formula as a patch, and I realized all you want is a bloody % operator. What language are you coming from that doesn’t have a modulo operator or function?

#P window setfont “Sans Serif” 9.;
#P number 166 146 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 166 91 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 166 115 35 196617 % 12;
#P connect 0 0 2 0;
#P connect 1 0 0 0;
#P window clipboard copycount 3;

#134532
Jun 23, 2008 at 10:11pm

Hi v1025kernel,

Here is a variation of your patch that uses an expression to fill an
FTM fmat.
In fact, the FTM message box supports % as a (floating-point) modulo
operator.
FTM message box.

**NOS

P.S.: Yes, the parenthesis completion seems to be messed up…

#P user ftm.mess 182 215 213 21 3 14 255 255 255 0 0 0 1 2 0 0 0 –> 0;
#T _#ftm version 2 3;
#T _#scope begin;
#T _#absargs \$0_ \$1_ \$2_ \$3_ \$4_ \$5_ \$6_ \$7_ \$8_ \$9_;
#T _#line “_(print (\$m set (\$pcp fill \$e)))”;
#P user ftm.object 182 246 62 18 3 9 –> 0;
#T _#obj 1 mat;
#T _#def 0 “_mat 1 513″ m local;
#P user ftm.object 51 527 45 18 3 9 –> 0;
#T _#def 0 “_(log 2)” log2 global;
#P user ftm.object 51 506 71 18 3 9 –> 0;
#T _#def 0 “_(\$sr / \$ref)” sroverref global;
#P window setfont “Sans Serif” 9.;
#P flonum 52 282 75 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 52 344 75 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P message 52 223 32 196617 print;
#P user ftm.object 52 150 374 18 3 9 –> 0;
#T _#obj 2 expr “((floor (12 * ((log (((\$col + 1) / \$N) * (\$sr /
\$ref))) / (log 2)))) % 12)”;
#T _#def 0 “_expr ‘((floor (12 * ((log (((\$col + 1) / \$N) * (\$sr /
\$ref))) / (log 2)))) % 12)’” e local;
#P user ftm.mess 52 180 99 21 3 14 255 255 255 0 0 0 1 2 0 0 0 –> 0;
#T _#line “_(\$pcp fill \$e)”;
#P user ftm.mess 52 310 475 21 3 14 255 255 255 0 0 0 1 2 0 0 0 –> 0;
#T _#line “_((floor (12 * ((log (((\$1 + 1) / \$N) * \$sroverref)) /
\$log2))) % 12)”;
#P user ftm.object 52 472 33 18 3 9 –> 0;
#T _#def 0 _440 ref global;
#P user ftm.object 52 449 87 18 3 9 –> 0;
#T _#def 0 _(\$FTM.audio.sr) sr global;
#P user ftm.object 52 426 39 18 3 9 –> 0;
#T _#def 0 _1024 N global;
#P user ftm.object 52 245 66 18 3 9 –> 0;
#T _#obj 3 fmat;
#T _#def 0 “_fmat 1 513″ pcp local;
#T _#scope end;
#P comment 129 480 261 196617 named constants have to be global in
expression objects;
#P window setfont “Sans Serif” 18.;
#P comment 52 77 448 196626 p(k) = (floor (12 * log2 (k/N * sr/ref)))
mod 12;
#P window setfont “Sans Serif” 9.;
#P comment 268 240 108 196617 if you need it in a mat;
#P connect 7 0 11 0;
#P connect 12 0 7 0;
#P connect 10 0 3 0;
#P window clipboard copycount 17;

On 23 juin 08, at 08:13, v1025kernel wrote:
> hey all,
>
> I’m trying to implement an equation and have a few questions:
>
> [1] why does max add parenthesis????? i can’t delete un-wanted/
> needed
> parenthesis. These added parenthesis are giving me a syntax error.
>
> [2] how can i use variable within an equation?
>
> here’s the patch:
> #P origin 0 1;
> #P window setfont “Sans Serif” 9.;
> #P window linecount 1;
> #P comment 132 205 804 196617 why are the parenthesis impossible to
> remove? … like the top equation , there should be two left
> parenthesis at the beginning and three right parenthesis at the end;
> #P user ftm.mess 406 259 747 15 3 9 255 255 255 0 0 0 1 2 0 0 0 –> 0;
> #T _#ftm version 2 3;
> #T _#scope begin;
> #T _#absargs \$0_ \$1_ \$2_ \$3_ \$4_ \$5_ \$6_ \$7_ \$8_ \$9_;
> #T _#line “_(((floor (12 * ((log (((\$col + 1) / 1024) * 44100 /
> 440)) / (log 2)))) – ((floor (floor (12 * ((log (((\$col + 1) / 1024)
> * 44100 / 440)) / (log 2)))) / 12)) * 12))”;
> #P user ftm.mess 14 177 1299 21 3 14 255 255 255 0 0 0 1 2 0 0 0 –>
> 0;
> #T _#line “_((((((\$pcp fill (new expr ‘(((floor (12 * ((log (((\$col
> + 1) / 1024) * 44100 / 440)) / (log 2)))) – ((floor (floor (12 *
> ((log (((\$col + 1) / 1024) * 44100 / 440)) / (log 2)))) / 12)) *
> 12))’)))”;
> #P user ftm.mess 47 128 822 27 3 18 255 255 255 0 0 0 1 2 0 0 0 –> 0;
> #T _#line “_((\$pcp fill (new expr ‘(floor (12 * ((log (((\$col + 1) /
> 1024) * 44100 / 440)) / (log 2))))’)))”;
> #N ftm.print –> 0;
> #P newobj 193 325 51 196617 ftm.print;
> #P user ftm.object 49 423 33 18 3 9 –> 0;
> #T _#def 0 _440 ref local;
> #P user ftm.object 49 400 45 18 3 9 –> 0;
> #T _#def 0 _44100 sr local;
> #P user ftm.object 49 377 39 18 3 9 –> 0;
> #T _#def 0 _1024 N local;
> #P user ftm.object 33 42 62 18 3 9 –> 0;
> #T _#obj 1 mat;
> #T _#def 0 “_mat 1 513″ pcp local;
> #P flonum 191 240 35 9 1. 20. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P user ftm.mess 193 277 151 15 3 9 255 255 255 0 0 0 1 2 0 0 0 –> 0;
> #T _#line “_(\$1 – ((floor (\$1 / 12)) * 12))”;
> #T _#scope end;
> #P comment 429 278 347 196617 this equation should like within the
> ” marks above.;
> #P window linecount 5;
> #P comment 115 379 100 196617 is there a way to express this
> equatino using variables rather than values?;
> #P window linecount 1;
> #P comment 275 364 331 196617 p(k) = (floor (12 * log2 (k/N * sr/
> ref))) mod 12;
> #P connect 4 0 3 0;
> #P fasten 3 0 9 0 198 292;
> #P pop;
>
>
> many many thanks.
>

#134534

You must be logged in to reply to this topic.