lot of computation need optimize

Thomas's icon

Hi, i have a lot of computation with the if object (100)
i think there is certainly a more easy way
in attach is the project reduce to 3 computation.
your help is welcome !
(one word over this project : it's to build a touchscreen with a lot of toggle we can move where we want.
it's ok i built it, it works perfectly but it take a lot of cpu :) )

simple-touch.zip
zip 8.29 KB

Roman Thilenius's icon

if $f1 > $f2 && $f1 < $f2 + $f3 && $f4 > $f5 && $f4 < $f5 + $f6 then 1 else 0

could be replaced by [expr] with the same expression. in overdrive, this might save some CPU.

though i am not sure how much sense $f1 > $f2 && $f1 < $f2 will make, it might output 0 quite often.

MakePatchesNotWar's icon

Dont use Ui-objects to pass through data. Only use them to debug or on the end of a chain but never in between.

<Edit>"never in between"
I mean it's not like the police will come for you but that's the rule i use.

MakePatchesNotWar's icon

"$f1 > $f2 && $f1 < $f2 + $f3"
It's actually this and that could work though

Source Audio's icon

&& means both conditions need to match

Thomas's icon

thank you for your reply,
effectivly expr is working for this computation but the cpu is always a little overload ... the issue is certainly the UI objetc like say @luvulongtime,
i tried to do this with nodes object but again overload
i have to apply this idea with jitter i think

florian1947's icon

A case of the missing brackets?
$f1 > $f2 && $f1 < ($f2 + $f3)

MakePatchesNotWar's icon

"it's to build a touchscreen with a lot of toggle we can move where we want."
"i tried to do this with nodes object but again overload i have to apply this idea with jitter i think"

What are you trying to do? What is "this" because immediately jumping to Jitter maybe unnecessary

Also in your first post you mention "the if object (100)". Does that mean you have 100 if-objects? And we're talking 1 touchscreen here?

You can also replace the if-statement with this (or part of it at least). I don't know if its better or not, it might be cheaper

Max Patch
Copy patch and select New From Clipboard in Max.

<edit> Now that i think about it, 10 fingers? You want to track that by any chance? Then jitter is indeed a better option

Roman Thilenius's icon

ah, i did not see the "+$i3" :)

it works correctly like he wrote it, but of course it is better readable using parentheses.

but whatever, i think it might be a good idea to have a [change] before all these checks, so that you only calculate those conditions when actually all 6 values change.

Thomas's icon

hi luvulongtime, sorry to not be clear
100 is the number of toggle i have on my screen. So 100 computation with if or expr or ..
i'm working with a touchscreen. I would like to use it like the mira.multitouch object with possibility to move the different region (toggle for me)

MakePatchesNotWar's icon

Ok, it's becoming a bit clearer i think. So if i'm not mistaken you have the toggles in a 10x10 grid and you want it to respond to the input from the touchscreen as a visual representation? Does it have to be a toggle then? If it's purely used visually i think i would just use Jitter and if you really need the Ui-aspect i'd probably choose Mtrxctrl over toggle. Having an unpack with 100 outlets for the toggles just doesn't sit right with me...

"to use it like the mira.multitouch object with possibility to move the different region (toggle for me)"
This is still unclear to me. I don't understand what you mean by "moving"

Regardless of all of this, having the data processed individually for each seperate toggle is not advised as you've noticed.

Thomas's icon

hi, i 've limited the mouse data with speedlim, so now the cpu activity is correct
but i understant it 's not the right way.

on video to explain the principle of operation
https://youtu.be/27U8z28HDKs

to answer luvulongtime :
i have the toggles all over my computer screen
and yes they have to be toggle (clic on it)
i wanted to mean by "moving" toggle : move the toggle in the screen wherever i need


Roman Thilenius's icon

so they are only moved by mouse? why has the positionof all the rest to be checked all the time?

and somehow i suspect that either something else is wrong or you got fooled by the CPU meters. 100 if objects are theoretically expensive, but should not cause any trouble.

Thomas's icon

you're right, not to be check all the time, only when i need to move the toggles, or in a different mode (for me) when i want to know what toggles the mouse hovers (like mira.multitouch)

MakePatchesNotWar's icon

After watching your video i'd say Jitter or Jsui/Javascript is much more suited for this and that will definitely show in performance. I'd wager that you can that to run at 60fps without a problem.

I don't know if you're already familiar with tutorials by Federico? Here's a video you could use as a base. Do check out the rest of his channel too btw, it's a goldmine of info...

Thomas's icon

wahhh !!! Federico's tutorials are really a goldmine
thank you !