agree with scott :-)
here is a minimal example with comments:
/// make a dict once for the sharky values
~valdict = ();
// the OSC listener
OSCdef(\tsharky, { |msg|
////// uncomment to see that strings are already symbols when arriving by OSC
/// msg.postcs;
// for efficiency, put in values in existing dict by key, value
(1, 3 .. msg.size).do { |i|
~valdict.put(msg[i], msg[i+1]);
};
// use a function to trigger whatever action on incoming
~sharkfunc.value;
}, \tsharky);
// example update function:
~sharkfunc = {
// debug info
"- ~sharkfunc runs - ".postln;
("~valdict is now: " + ~valdict.cs).postln;
// other code here ....
};
// now test from SC:
n = NetAddr.localAddr;
// test message format
n.sendMsg( "/tsharky", "value", 200, "valueB", 300, "valueC", 400);
n.sendMsg( "/tsharky", "value", 500.rand, "valueB", 500.rand, "valueC", 500.rand);
best adc
> On 10/03/2019, at 13:54 , scott@xxxxxxxxxxxxx wrote:
>
> 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
> __
> https://soundcloud.com/all-n4tural
> https://alln4tural.bandcamp.com/album/mix-root-gumbo
>
> _______________________________________________ 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/
_______________________________________________
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/