[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] Regexp with incoming OSC



I don't want to make any assumptions about your goals or workflow, but - encapsulating values in a string to send over OSC is significantly less efficient than just sending key-value pairs with actual numbers. For example, instead of your message:
    [ "/tsharky", "value=200 valueB=300 valueC=400" ]
you could send something like the following:
    [ "/tsharky", "value", 200, "valueB", 300, "valueC", 400 ]
or:
    [ "/tsharky", 200, 300, 400 ]

Again, not sure what your overall workflow is like, but the OSC is heavily optimized for sending packets of values like this - you're missing out on this by packing and unpacking to/from a string yourself.

- Scott C

On Sun, Mar 10, 2019 at 1:27 PM <kv.syntaxerror@xxxxxxxxx> wrote:
Thanks that looks nice I jus had to add .asString, for some reason the message comes in as Symbol apparently. However, although the parsing is done properly and splitting and assigning to key value pairs, there is something strange, my original message looks like this:
26962 17756.256810 162.125.18.133 → 192.168.1.108 TCP 66 443 → 54732 [ACK] Seq=18054 Ack=60158 Win=184320 Len=0 TSval=1286108705 TSecr=421110892

Then parsing with this:
(
OSCdef(\tsharky, {|msg|
    ~dict =  msg.asString.split($=).collect(_.split($ )).flatten(1).asDict;
    ~dict.keysValuesDo{|key, value| [key, value].postln};
}, '/tsharky');
)
-> [ 5296, Ack ] etc. //seems twisted the other way around instead the key is positioned as value.

When I try to get with ~dict.at(\Ack) -> nil

So is there something in the parsing or the iteration function that messes the IdentityDictionary?


K.

On Sun, Mar 10, 2019 at 2:20 PM <alln4tlists@xxxxxxx> wrote:
there are no doubt much more elegant ways of achieving this, but hee are some ideas
 
 
(
var msg = "value=200 valueB=300 valueC=400";
msg.findRegexp("value")
)

(
var msg = "value=200 valueB=300 valueC=400";
msg.split($=)
)
(
var msg = "value=200 valueB=300 valueC=400";
msg.split($=).collect(_.split($ )).flatten(1)
)
(
var msg = "value=200 valueB=300 valueC=400";
msg.split($=).collect(_.split($ )).flatten(1).asDict
)

(
var msg = "value=200 valueB=300 valueC=400";
var dict = msg.split($=).collect(_.split($ )).flatten(1).asDict;
dict.keysValuesDo{|k,v| "%: %\n".postf(k, v.asInteger)}
)
 
cheers,
eddi
 
_______________________________________________ sc-users mailing list info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx archive: https://listarc.bham.ac.uk/marchives/sc-users/ search: https://listarc.bham.ac.uk/lists/sc-users/search/