Anybody here speak GREP?

usefuldesign.au's picture

I wanted a simple patch to add a certain number of zero's after the decimal point in a float when its value is zero (so the text layout doesn't jump when it starts to change).

While there are a few of ways that come to mind of doing this without grep I got started down that path, probably b/c I have a bad habit of making work for myself if it means learning another technique that's new to me.

If found a great online set of video tutes for GREP but after the first tute no clue as to how to accomplish this despite a few different angles of attack.

Tutes: http://blog.themeforest.net/screencasts/regular-expressions-for-dummies/ Testbed: http://gskinner.com/RegExr/

This is an academic kind of "how is this done exactly?" with GREP b/c I know it's powerful and I want to learn it one of these days.

PreviewAttachmentSize
GREP Q&A.qtz11.78 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

cwright's picture
Re: Anybody here speak GREP?

grep is not the right tool for this job -- grep is essentially a string search on steroids. It's not really intended to do complex manipulation of string (in command-line land, that tool is called "sed", for "String EDitor" iirc).

Anyway, what you're wanting to do can be easily accomplished with a line of javascript.

PreviewAttachmentSize
nice numbers.qtz3.67 KB

usefuldesign.au's picture
Re: Anybody here speak GREP?

Thanks cwright, I didn't think of string methods.

I ended up using the string truncate patch a second time on a string of "00000000000" by the fixed amount.

I thought with GREP I could search for a token ("0") then replace it with itself n times but couldn't quiet get there... got me distracted I guess.

Lango's picture
Re: Anybody here speak GREP?

Hey

There is already a patch that does what you want. It is called the Number Formatter putting something in like '0.###' will always give three decimal places.

Regards

Lango

cwright's picture
Re: Anybody here speak GREP?

Oh, good point -- I forgot about the number formatter. Thanks for noting that!

usefuldesign.au's picture
Re: Anybody here speak GREP?

Thanks Lango,

I just discovered that patch in the Dynamic Slider.qtz comp offonoll just uploaded as it happens. In this case I wanted programatic control over decimal places and being in the settings panel it's locked up. Even if setting was in the accessible part of patch I'd still be constructing a string of ".####" by truncating an oversized one so back to sq 1. : )

I've made a string printer for outputting [1-10] nodes on screen and it nicely recognises booleans and truncates the decimal and has option for fixed length for the rest. When I'm really looking for distraction I'll substitute fake-LEDs for booleans with smooth lag to catch signal pulses ; ). It buys a performance hit but can always be disabled when ya done. Not sure if unrolling the iterator would speed it up, no time to check.

I spend too much time with debuging. With so many noodles flying around a change on one part often throws something else I wasn't aware of at time – hence my debugging string printer. Hope it's useful to somebody else too. Helped me hammer out an ADSR envelope macro today.

Really interested to see how your movement detection works BTW can see some good applications for that in the future.

PreviewAttachmentSize
string printer.qtz34.88 KB

usefuldesign.au's picture
Re: Anybody here speak GREP?

'c' key

PreviewAttachmentSize
string printer 'c' to see printer-1.qtz34.71 KB

dust's picture
Re: Anybody here speak GREP?

i don't really speak command line grep 2 much im more of a spotlight person. grep is very specific search. im not exactly sure what you are trying to do to tell you the truth i feel kind of stupid because you have got all kinds of answers here but i don't understand are you trying to format or truncate a string to a particular decimal place with grep or just replace.

you can use 2 greps. lets say your string is counting between 0.0 1.0. in the grep you can type search "0" replace "0000" that will make .5123 => 000.5123 but will also change 0.0 => 0000.0000123 so you need to use another grep to take out the ".0000" and replace with "0000.0123" or something like that so you don't get a jump in the animation. if you use the number formatter before the first grep you should be able to retain some sort of smooth animation that way.

usefuldesign.au's picture
Re: Anybody here speak GREP?

If you look at the string printer part of the comp dust (the iterator that draws it) there is a keyed value in the data structure for the number of decimal places to display. I wanted a patch that could take that value and truncate the data string to that number of places which truncate patch does but not when string is 0 or 1 (booleans for example get cast to single character string) etc etc.

Got it sorted – can't even remember how. Another way to have done it would be to have appended "0000000000" to the string prior to the truncate patch so there was always enough digits to truncate.

dust's picture
Re: Anybody here speak GREP?

yeah thats what i thought you where doing. interesting approach.