Dividing screen into x parts and output values and bangs based on mouse location

R_Gol's icon

How can I take the size of my screen (x and y) and output bangs and x and y values of mouse based of the location of the mouse on the screen?

I would like to have the option to decide if the screen will be divide into 4 equal parts, 8 equal parts or any other number.

How(or if) it's possible?

double_UG's icon
Max Patch
Copy patch and select New From Clipboard in Max.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

TFL's icon

Use [mousestate] to get the mouse position, [screensize] to get, well, your screen size and then do the math:

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

R_Gol's icon

But the output should be based on both location of x and y together

Source Audio's icon

is that so difficult to deal with ?

pack x and y dividers and bang when mouse is in both set ranges.

R_Gol's icon

is that so difficult to deal with ?

pack x and y dividers and bang when mouse is in both set ranges.

I don't understand how to decide the ranges in easy way?

what is the math formula I need in here?

double_UG's icon

just scale

scale 0 1919 1 4

R_Gol's icon

just scale

scale 0 1919 1 4

probably there is something I missing but I'm looking for both x and y axis and not only one axis.

I don't understand what math equation is needed?

double_UG's icon
Max Patch
Copy patch and select New From Clipboard in Max.

xxxxxxxxxxxxxxxxxxxxxxxxxx

TFL's icon

Here's Double_UG patcher but a bit neater, and which adapts to your screen resolution.

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

R_Gol's icon

Here's Double_UG patcher but a bit neater, and which adapts to your screen resolution.

Thanks!

This patch divide the screen into 16 parts. If I want it to be divided into only 4 parts or 8 parts? (or other number?)

TFL's icon

Understand the patch and you'll understand how. In that version of the patch, the screen is divided in 4 parts horizontally and 4 parts vertically, which gives the 4x4=16 zones in total.

Search for '4' in the patch and this will be most likely what you want to update to change the number of subdivisions. Double_UG was pretty explicit when they said "just scale"

double_UG's icon
Max Patch
Copy patch and select New From Clipboard in Max.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

R_Gol's icon

Thanks for the explanation! I see it now

Source Audio's icon

there are few details left to deal with.

1~ limit input to 1 screen in case multiple screens are present

works also by using zmap instead of scale.

2~ filter out bottom & right edges of the screen.

if you scale 0 1024 0 4

then when you hit 1024 you will get 4 ... wrong result

Here I pointed my mouse to right-bottom corner :

R_Gol's icon

Thanks! This should work with odd screen divide?

For example I put 3 for x(horizontal) and 2 for y (vertical) but the output seems off.

When I'm with my mouse on the right hand cornel I get 2 which make sense.

When I move the mouse to the bottom left corner I also get 2. I think it should be 3?

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

TFL's icon

Because of this cord. It should be connected to the number of horizontal divisions, like below, instead of number of vertical divisions.


Source Audio's icon

you might also want to divide free ranges , like

1 2 3 4

5 6

7 8 9 10 11 12

13 14

R_Gol's icon

Because of this cord. It should be connected to the number of horizontal divisions, like below, instead of number of vertical divisions.

This did not solved the problem

Edit: It did..!

R_Gol's icon

so I have this patch that taking data from two users - x axis y axis and hand on off.

I would like that if numbers are equal and only if both users are touching the screen the output will be that number. if not - output will be -1.

This is because that if both users are not touching the screen I'm getting position 0 although there is no touch. So I would like to eliminate it

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

R_Gol's icon

I have this version which almost works great:

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

For some reason I have small delay on number displaying

Source Audio's icon

You are not really known for efficient patching...

Joke aside, you can optimise that patch somewhat,

but probably main stress could be data coming through UDP.

Try to reduce or optimise that in first place.

even if you parce/route only a part of the messages in max,

they still get sent/received

one little improvement example :

Can you capture full input from ports 2222 and 101 ?

just to see what is coming in, how fast, if values get repeated without need etc

P.S send/receive should have no spaces !

R_Gol's icon

Can you capture full input from ports 2222 and 101 ?


port 2222:

port 101:

the above two capture is before adding zl.change. I think this will help to reduce stress on capturing data.

I wanted to ask how can I know the delay time when my data is sending from sensor one via computer 1 over udp to computer 2? how can I know I don't have large delays in data transfer?

Source Audio's icon

There is no time stamp on received data, so it is not

visible how fast you get that.

to see how much time elapsed between sending and receiving UDP

data between computers, you could use something that has nothing to do with udp,

for example record short click from both computers into stereo file.

One click when sent, another when received ....

or use round trip like ping or echo through UDP

.....

kill that /channel2 if not in use from the source - that python script

R_Gol's icon

There is no time stamp on received data, so it is not


is there a way I can send data from main computer to the second computer then back to the main and capture the time it takes? and see if there is delays overtime ?

Source Audio's icon

sure, make pairs of udpsend / udpreceive objects.

use different ports

like udpsend <ip addres> 3333 from one

udpsend <ip addres> 4444 to send back.

send short message like shown here.

on local ethernet network message gets received back in no time...

master :

responder:

R_Gol's icon

Yes this what I was thinking, but how can I record this time over a period of lets say 1 minute?

so I can actual see if there is any difference..?

using metro to send bangs at fixed interval?

R_Gol's icon

Maybe sometihng like this?

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

edit: I'm getting wired values such as :-0.8443;

those it make sense?

Source Audio's icon

No that makes no sense to me.

What would make sense is to post that python script

and infos about that touch screens

R_Gol's icon

It try to figure out the time it takes to the data received from secondary computer to main computer and be able to store that data..

What is not make sense in the patch I share?

Source Audio's icon

nothing makes sense, you can't get minus interval ?!??

try this

R_Gol's icon

I'm still getting minus. metro set to 1ms

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

R_Gol's icon

when setting the interval to 10ms I'm no longer getting minus.

so each index is telling me the time it takes to the data received from secondary computer to main computer?

how can I calculate the average time? adding all values together and divide by the number of samples right?

Source Audio's icon

It is not.

ping gets you time of round trip.

send - receive - send back - receive.

That is what you asked for.

Your measurement makes no sense at all to solve your problem.

why should you use 1 ms ping interval ?

R_Gol's icon

why should you use 1 ms ping interval ?


maybe to compare with other data that capture in 1ms intervals?

in any case the interval of pings are make no difference to the fact I want to measure the time is take to the message to arrive?

to measure the average time I can make something like this?

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

Source Audio's icon

I don't understand what you want.

Is it about receiving messages from other computer ?

if you want to send 1000 messages from 1 computer to another

at set interval and measure timing deviations ?

or lost messages ?

You could run counter from source computer and capture numbers together with timing

between received messages into coll on receiving computer.

R_Gol's icon

I don't understand what you want.

Is it about receiving messages from other computer ?

Yes, I want to see what is the delay time between sending the message from 1 computer to the time it receive on the main computer. To see I don't have any large delays..

Source Audio's icon

in that case that ping is enough,

no matter if you send it once or 100 times.

There should be no significant delays unless

something disturbs network, or it is not reliable.

Or software that sends packets is not working properly.

More infos, more help possible ....

Wifi ? Ethernet ?

Local ?

R_Gol's icon

Wifi ? Ethernet ?

Local ?

Both computer are connected to the same local netroc via Ethernet cable

So they are not physically connected between them with eternet cable rather each of them is connected to the local network

R_Gol's icon
There should be no significant delays unless

something disturbs network, or it is not reliable.

I measure around 2ms for every ping to be sent then gets back using the patch you shared. Is this sound reasonable? Is there a 'standard' time for it?

Source Audio's icon

I am having 0.5 - 0.6 ms on a large house network, mixed ethernet and WiFi.

For best result you would use standalone app and not max.

Standalone app would do only what you want it to do.

I measured on Mac computers, maybe I should repeat with few windows laptops as well.

At the end closed local peer to peer connection between 2 computers vith ethernet cable would be best, I mean for your end product, if possible.

it is not 2ms latency that would be critical in any case,

it does not matter if it is even much more,

but important is to get no large deviations and no packet loss.

to measure only one way data flow,

you would send timestamped message from the source,

and compare to arrival times on receiver side.

But I don't think you should waste your time with that...

Why do you need 2 computers ?

Are there other options then to stream fast data ?

capture local and send over as a file ?

if that is only 2 float values, even audio connection could be used ...

and many other ideas could envolve if one considers all factors.

R_Gol's icon

Why do you need 2 computers ?

Are there other options then to stream fast data ?

capture local and send over as a file ?

One screen sensor (ZXY500) is connected to computer. a python script is proccessing the data and this data sent over UDP to a max patch on computer 1. from the Max patch on computer 1 data is sent to Max on computer 2 over UDP.

Computer 2 is receiving the Data from the second screen sensor and all the data recording and processing is happening on that computer.

I will check if I can connect those two sensor to the same Main computer (computer 2) and with that to avoid sending data over UDP.

The way the system is set was done by my colleage that is responsible for the computers and sensors. I don't know why they did not connect both sensors to the same computer. You think this possible even with max?

Another thing is that those sensor before sending the data to Max are pass in python code so the data is sent acctually via python.

Sensor 1 connected to computer 1 over USB --> python code sending data of the sensor over UDP to Max patch on computer 1 --> Data sent to computer 2 over UDP into Main max patch.

Sensor 2 connected to computer 2 over USB --> python code sending data of the sensor 2 over UDP to Main Max patch on computer 2

Source Audio's icon

I see.

Maybe there is a conflict between 2 sensors, or even it is impossible

to connect 2 of them to same computer.

I can't say that, are both same sensors ?

What could immediately get improved is to send UDP directly from python script

on Computer 1 to Computer 2 / Max.

Why that routing via Max on Computer 1 ?

could you post python script and info about computer / OS ?

Also as what do sensors get recognised as hardware - on Windows have a look in

device manager, if it is Mac then system profiler.

R_Gol's icon

I can't say that, are both same sensors ?

Yes they are.

What could immediately get improved is to send UDP directly from python script

on Computer 1 to Computer 2 / Max.

I will ask the computer guy to make it if he can.

Why that routing via Max on Computer 1 ?

I'm not sure. This is was how the system setup when I get there..

could you post python script and info about computer / OS ?

I guess I could but only next week when I get there

Also as what do sensors get recognised as hardware - on Windows have a look in

device manager, if it is Mac then system profiler.

Will check this as well next week