Forums > MaxMSP

extract a number from a message

June 11, 2010 | 9:55 pm

Hi guys,

Pulling my hair out trying to work out how to do something that I assume there is a simple answer to, so I’m throwing it out there to you.

Does anyone know how to extract a number from a message?

I’m using a umenu which is pointed to a folder with audio samples to load samples into a buffer. What I want to do is put a number after the file name that I can extract whenever the file is loaded. This number will tell my patch how many bars long the sample is. So for example introguitar4.wav is sent to an object which looks at this message sees that there is a number 4, when it does it sends the number, or a bang, or whatever out of an outlet.

I’ve looked at the zl object, which would do the job perfectly accept for the fact that I have to label the files in a particular way to get it to see the numbers. So if the file is named introguitar 4 .wav it works fine, it sees the four and sends a bang out of the left outlet. The problem is that when using umenu, if there are spaces in the file name, for some reason it puts brackets around the text, which causes the zl object not to see the number.

Thank’s for any help you may be able to offer…



Ad.
June 11, 2010 | 10:26 pm

regexp can do that:
max v2;
#N vpatcher 0 44 1680 1046;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 719 416 90 196617 introguitar 2.wav;
#P number 568 511 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 568 416 87 196617 introguitar4.wav;
#P newex 568 480 96 196617 regexp \\W*(\\d);
#P connect 3 0 0 0;
#P connect 1 0 0 0;
#P connect 0 1 2 0;
#P pop;

Ask if the regexp help is not enough for understanding.
Ad.


June 12, 2010 | 2:58 pm

Thanks Ad. I haven’t had a chance to look at how it works yet, but it works.


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