Hey all,
What I am trying to achieve:
Turn my OSC messages to Dictionaries with unique IDs tapped out from the first message in this array.
[ /wfiRwJaZy3wktE2MAAAX, {"0":"455.00","1":"211.00","2":"455.00"} ]
Final goal:
Access the data in the rest of the program by calling the ID of the Dictionary
Long explanation of the objective is below.
I am trying to create incoming osc messages to dictionaries so I can access the in rest of the program later on. The idea is that something like an incoming message (below) will be clamped into a new dictionary if this doesn’t exist by checking its first message from inside the osc array. If it exists obviously will update its values and carry on. Then I can have access to the data from inside the dictionary array or collection by selecting the ID which is the string of the first osc message. I am aware of parseYaml
and 'parseJSON` will create a dictionary, and I have also managed to split the osc array into the id to assign the dictionary and key, and values but that is how far I have gone, and I am getting “nil” every time I am calling my dictionary.
Here is the draft of my code thus far:
//incoming osc formated message as object
[ /wfiRwJaZy3wktE2MAAAX, {"0":"455.00","1":"211.00","2":"455.00"} ]
(
var oldUserID, oldData, d = ();
~listener = { |msg, time, replyAddr, recvPort|
var oscArray, checkBadVals, userID;
if(msg[0] != '/status.reply') {
//"At time %s received message % from % on port%\n".postf( time, msg, replyAddr, recvPort );
msg.postln;
userID = msg[0].asString.drop(1);
oscArray = msg[1].asString.parseJSON;
checkBadVals = oscArray.collect(_.notNil).reject(_.isNil);
if(checkBadVals != false && oldUserID != userID && oldData != oscArray) { //proceed on assigning values after check for nils in osc array.
"User with ID: % sent message % at time %\n".postf(userID, oscArray, time);
oscArray = oscArray.keysValuesDo({|index, value|
value = value.interpret;
//{\notifier.changed(index.asSymbol, userID, value.max(0.01))}.defer; //safely ignored.
d.add(userID -> oscArray); // d = () -> "Nil"
});
};
oldUserID = userID;
oldData = oscArray;
[oldUserID, oldData].postln;
}
};
thisProcess.addOSCRecvFunc(~listener);
)
Thanks for the time reading this.
K.