Best way to send markers over udp?

F_Dos's icon

I need to send over UDP few markers when tempo in change, metro is ON, sound is on/off and so on. some markers are sent every few millisecond, some only one time in running.

Should I use prepend for every item I want to send?

Rei Kurosawa's icon

For unlabelled values sent to another Max patch, prepend tempo adds a tag: 120 becomes tempo 120. The receiver can use route tempo to get 120 from its first outlet. Use a different tag for each stream.

Wil's icon

Here ere 3 ways may help

one is to prepend before you prepend /name send - so that the tag and value comes out at the other end - I use that one for sending groups of params directly into jit.bl.pix

second is to use single prepend = that routes just the number - I stopped using this one , now using double prepending so my receiver side is clean.

third one with a list unpacks at the other end - I use this into matrix to set cell , this one will works best for packing tempo, on/off and others in the same list and send ,, then unpacking at the other end.

***I havnt found a work around for spat5.unslashify, but that little [forward] gizmo I made work really well for having just ONE [forward] to send all those different stuff

TFL's icon

Instead of [spat5.osc.unslashify], you can use [regexp / @substitute " "], but you can also not use slash notation at all, if you're sending from Max to Max and don't care about sending "compliant" OSC messages.

Should I use prepend for every item I want to send?

All in one list, one dict, or each message with a word as identifier set with [prepend], with or without slash, it's up to you really, any approach will work. You will see later on if you tend to send more stuff over OSC that maybe you would prefer one method over another one.

F_Dos's icon

Thanks for the answers

Is there any difference in timing or performance between the approaches? If I pack everything into one list with [pak], every time a single value changes the whole list gets sent again. Whereas if I use [prepend] for each value, only that value is sent, right when it changes, correct?

Is sending the full list on every change a problem in practice (bandwidth, latency, or unnecessary triggering on the receiving side), or is it negligible over a local network?

Rei Kurosawa's icon

Your reading is right: pak outputs the entire list whenever input is received in any inlet, so one changed value re-sends the whole list. With a separate prepend per value only the changed value produces a message, so only that one goes out over UDP. On the receiving side a packed list is usually split with unpack, which sends each item out a separate outlet on every arrival, even for values that did not change. With per-value tags route selects the outlet by matching the first element, so only the matching path reacts. For a few small markers on a local network the extra packets of the one-list version are rarely a problem, but since some of your markers go out every few milliseconds, the per-value shape you described avoids constant full re-sends and needless receiver work.