Forums > MaxMSP

parseInt

October 12, 2006 | 8:29 am

Hi all,

Does someone know of a way to determine whether a list element is interpretable as an int (like Integer.parseInt() in java)? The patch below does it, but it throws an error if not matched. I’ll be using this functionality a lot so I’d prefer no errors..

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 159 116 26 196617 msg;
#P number 118 181 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 118 116 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 118 141 18 196617 t l;
#P newex 118 161 27 196617 i;
#P connect 4 0 1 0;
#P connect 0 0 3 0;
#P connect 2 0 1 0;
#P connect 1 0 0 0;
#P window clipboard copycount 5;

Thanks,
Mattijs


October 12, 2006 | 8:55 am

On 12 oct. 06, at 10:29, Mattijs Kneppers wrote:

> Does someone know of a way to determine whether a list element is
> interpretable as an int (like Integer.parseInt() in java)?

[route ] ?

Like this:

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 177 172 74 196617 print "not int";
#P message 159 116 26 196617 msg;
#P number 118 181 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 118 116 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 118 141 49 196617 route int;
#P connect 0 1 4 0;
#P connect 0 0 2 0;
#P connect 3 0 0 0;
#P connect 1 0 0 0;
#P window clipboard copycount 5;

_____________________________
Patrick Delges

Centre de Recherches et de Formation Musicales de Wallonie asbl

http://users.skynet.be/crfmw/max


October 12, 2006 | 9:04 am

> Does someone know of a way to determine whether a list element is
> interpretable as an int (like Integer.parseInt() in java)? The
> patch below does it, but it throws an error if not matched. I’ll be
> using this functionality a lot so I’d prefer no errors..

would [route] help ?
not exactly what you asked for, i guess, but maybe you can adjust it
to your needs.
volker.

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 166 78 23 196617 7.7;
#P message 150 78 14 196617 5;
#P message 194 78 52 196617 5 6 7.7 8;
#P flonum 110 78 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 164 148 50 196617 print list;
#P newex 220 147 55 196617 print none;
#P flonum 121 149 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 78 149 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 78 121 141 196617 route int float list;
#P message 78 78 26 196617 msg;
#P number 37 78 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P connect 10 0 2 0;
#P connect 9 0 2 0;
#P connect 8 0 2 0;
#P connect 7 0 2 0;
#P connect 2 2 6 0;
#P connect 2 3 5 0;
#P connect 1 0 2 0;
#P connect 0 0 2 0;
#P connect 2 0 3 0;
#P connect 2 1 4 0;
#P window clipboard copycount 11;


October 12, 2006 | 9:06 am

Hi Patrick, thanks for your reply.

Unfortunately this doesn’t work when the int is in a list format (see the modified patch below).

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 125 147 18 196617 t l;
#P newex 184 189 74 196617 print "not int";
#P message 166 123 26 196617 msg;
#P number 125 189 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 125 123 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 125 166 49 196617 route int;
#P connect 5 0 0 0;
#P connect 1 0 5 0;
#P connect 3 0 5 0;
#P connect 0 0 2 0;
#P connect 0 1 4 0;
#P window clipboard copycount 6;

Cheers,
Mattijs


October 12, 2006 | 9:29 am

Hi Mattijs, your second patch is the same as the first…

but what exactly do you want to check in the list? In max a list is a list
and can ofcourse contain anything and for example if you want to know if all
elements are int, you have to go through each element and check. Probably
the easiest way to do this is to by js or java.

If you want something similar to route maybe tap.typecheck or ej.route can
help?

hth, -thijs

On 10/12/06, Mattijs Kneppers wrote:
>
>
> Hi Patrick, thanks for your reply.
>
> Unfortunately this doesn’t work when the int is in a list format (see the
> modified patch below).
>
> #P window setfont "Sans Serif" 9.;
> #P window linecount 1;
> #P newex 125 147 18 196617 t l;
> #P newex 184 189 74 196617 print "not int";
> #P message 166 123 26 196617 msg;
> #P number 125 189 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P number 125 123 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 125 166 49 196617 route int;
> #P connect 5 0 0 0;
> #P connect 1 0 5 0;
> #P connect 3 0 5 0;
> #P connect 0 0 2 0;
> #P connect 0 1 4 0;
> #P window clipboard copycount 6;
>
> Cheers,
> Mattijs
>
> –
> http://www.samplemadness.nl/smadsteck
> SmadSteck – Interactive audiovisual sampling soft- and hardware
>


October 12, 2006 | 9:40 am

Quote: thijskoerselman@gmail wrote on Thu, 12 October 2006 11:29
—————————————————-
> Hi Mattijs, your second patch is the same as the first…

Hi thijs, ehm, as far as I can see it’s not. Note the [t l] I added and note the different behaviour. This may also be an answer to your next question.

>
> but what exactly do you want to check in the list? In max a list is a list
> and can ofcourse contain anything and for example if you want to know if all
> elements are int, you have to go through each element and check. Probably
> the easiest way to do this is to by js or java.
>
> If you want something similar to route maybe tap.typecheck or ej.route can
> help?
>
> hth, -thijs
>
>
>
>
> On 10/12/06, Mattijs Kneppers wrote:
> >
> >
> > Hi Patrick, thanks for your reply.
> >
> > Unfortunately this doesn’t work when the int is in a list format (see the
> > modified patch below).
> >
> > #P window setfont "Sans Serif" 9.;
> > #P window linecount 1;
> > #P newex 125 147 18 196617 t l;
> > #P newex 184 189 74 196617 print "not int";
> > #P message 166 123 26 196617 msg;
> > #P number 125 189 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> > #P number 125 123 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> > #P newex 125 166 49 196617 route int;
> > #P connect 5 0 0 0;
> > #P connect 1 0 5 0;
> > #P connect 3 0 5 0;
> > #P connect 0 0 2 0;
> > #P connect 0 1 4 0;
> > #P window clipboard copycount 6;
> >
> > Cheers,
> > Mattijs
> >
> > –
> > http://www.samplemadness.nl/smadsteck
> > SmadSteck – Interactive audiovisual sampling soft- and hardware
> >
>
>
>
—————————————————-


October 12, 2006 | 10:19 am

On 12 oct. 06, at 11:06, Mattijs Kneppers wrote:

> Unfortunately this doesn’t work when the int is in a list format (see
> the modified patch below).

If you need to check wether the members of a list are ints, then this
may work for you:

#P window setfont "Sans Serif" 9.;
#P number 312 37 35 9 0 0 0 3 0 0 0 255 227 23 222 222 222 0 0 0;
#P window linecount 1;
#P newex 228 70 18 196617 t l;
#P number 228 39 35 9 0 0 0 3 0 0 0 255 227 23 222 222 222 0 0 0;
#P newex 98 170 68 196617 print "no int";
#P newex 34 170 47 196617 print int;
#P message 73 79 34 196617 1234;
#B color 5;
#P message 34 39 120 196617 i’m sick sick sick of 666;
#B color 5;
#P newex 34 130 74 196617 route int;
#P message 53 59 119 196617 1 2 ach 3 4 5 6 golgotha;
#B color 5;
#P newex 34 108 47 196617 zl iter 1;
#P comment 324 61 100 196617 works too!;
#P fasten 10 0 1 0 317 101 39 101;
#P fasten 9 0 1 0 233 101 39 101;
#P connect 8 0 9 0;
#P connect 3 1 7 0;
#P connect 3 0 6 0;
#P fasten 5 0 1 0 78 101 39 101;
#P connect 4 0 1 0;
#P connect 1 0 3 0;
#P fasten 2 0 1 0 58 91 39 91;
#P window clipboard copycount 11;


October 12, 2006 | 10:35 am

Hey Patrick, thanks! So zl iter interprets list elements, I didn’t know about that! Great, this is wat I am looking for!

In the mean time I even came up with another (much less satisfying) solution:

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#N vpatcher 50 119 352 418;
#N comlet (anything but int) if input is not interpretable;
#P outlet 65 230 15 0;
#N comlet (int) if input is interpretable;
#P outlet 28 230 15 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 28 208 27 196617 i;
#P newex 111 162 21 196617 t 2;
#P newex 65 162 36 196617 zl reg;
#P newex 65 54 53 196617 t b l l 1;
#P newex 28 188 47 196617 gate 2 1;
#P newex 111 142 32 196617 sel 0;
#P newex 111 122 144 196617 expr $i1 >= 48 && $i1 < = 57;
#P newex 111 102 25 196617 iter;
#P newex 111 82 40 196617 atoi;
#N comlet (anything);
#P inlet 65 34 15 0;
#P connect 8 0 5 0;
#P connect 6 3 5 0;
#P connect 5 0 9 0;
#P connect 9 0 10 0;
#P connect 0 0 6 0;
#P connect 6 0 7 0;
#P connect 7 0 5 1;
#P connect 5 1 11 0;
#P connect 6 2 7 1;
#P connect 6 1 1 0;
#P connect 1 0 2 0;
#P connect 2 0 3 0;
#P connect 3 0 4 0;
#P connect 4 0 8 0;
#P pop;
#P newobj 56 74 55 196617 p parseInt;
#P window clipboard copytext "p parseInt" #E;
#P window clipboard copycount 1;

Thanks again!
Mattijs


October 12, 2006 | 12:04 pm

On 10/12/06, Mattijs Kneppers wrote:

>
> Hi thijs, ehm, as far as I can see it’s not. Note the [t l] I added and
> note the different behaviour. This may also be an answer to your next
> question.

ah sorry, I shouldn’t reply to these things when I just wake up;-)

-thijs


October 12, 2006 | 12:27 pm

Quote: thijskoerselman@gmail wrote on Thu, 12 October 2006 14:04
—————————————————-
> ah sorry, I shouldn’t reply to these things when I just wake up;-)

Heh, I know, it’s a difference of only a few pixels ;)
Mattijs


October 16, 2006 | 9:28 am

Mattijs Kneppers wrote:
> Hey Patrick, thanks! So zl iter interprets list elements, I didn’t
> know about that! Great, this is wat I am looking for!

iter does this as well, you can replace [zl iter 1] with [iter].
The main problem in your case is that trigger always changes the type.
This is my ongoing complaint about trigger, as its the most important
structuring object of Max. (I know it won’t change, because it would
likely break old patches)
I always hesitate to use a 3rd party object for that, but one workaround
is a subpatcher which just uses the right to left order to do this. I
still think its ugly, but it works with standard objects.
(There is also my [St] abhaXion which will script this with up to 16
outputs…)

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 264 177 61 196617 print left;
#P newex 200 177 61 196617 print right;
#P number 200 113 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#N vpatcher 20 74 303 326;
#P window setfont "Sans Serif" 9.;
#P newex 124 116 24 196617 t i;
#P outlet 180 144 15 0;
#P outlet 124 144 15 0;
#P outlet 68 144 15 0;
#P inlet 68 80 15 0;
#P connect 0 0 1 0;
#P fasten 0 0 4 0 73 104 129 104;
#P connect 4 0 2 0;
#P fasten 0 0 3 0 73 104 185 104;
#P pop;
#P newobj 200 143 75 196617 p t l i l;
#P newex 155 142 28 196617 t l;
#P number 155 113 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 242 231 15 0;
#P button 213 231 15 0;
#P button 184 231 15 0;
#P button 155 231 15 0;
#P newex 155 201 97 196617 route int float list;
#P connect 7 0 0 0;
#P connect 7 0 10 0;
#P connect 7 2 9 0;
#P connect 8 0 7 0;
#P connect 5 0 6 0;
#P connect 6 0 0 0;
#P connect 0 3 4 0;
#P connect 0 2 3 0;
#P connect 0 1 2 0;
#P connect 0 0 1 0;
#P window clipboard copycount 11;


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


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