dict: output only the key that changed
i`m trying to build a preset/cue system with dict across multiple patchers.
but the problem is that i don`t know how i would tell the dict object to output a key (and only that key) as soon as it changes.....
any ideas?
Can you post a reduced example of the patch showing the dict and how it is updated?
Otherwise does this here already help you
...in conjunction with using [dict.route] ?
thx for the reply!
i changed a bit in your patch to make it more clear (hopefully):
Have to think about this. I don't know of a simple object that compares dicts and outputs the difference or which detects changes in a dict. Also I think there is no easy way to use [dict.iter] and [zl] objects that is sufficiently generic. I suppose it will be better to handle such things in javascript.
To summarise your requirements as far as I understood:
a) You have a dict that contains an arbitrary structure eventually with arbitrary nesting of sub dicts and arbitrary named keys.
b) At a time a single key value can change. You need to know the key that has changed.
c) Changes to the dict can also mean that new keys or sub dicts are added to the dict. Right?
Depending on the size of your dict and the speed requirements it may worth to have a look at this here, but the search tree might become too big for a brute force nested loop approach:
javascript...... as i thought, unfortunately i have 0 experience...
a) yes
b) yes. , but it might also possible that more parameters are changing at once.
i already know which key has changed, but beside adding a get message to every set message i have no idea how to tell the dict to stream the key/value pairs that are changing. and this solution seems so unefficient
c) no. the structure stays the same, only values are changing
Can you please clarify what you mean with "adding a get message to every set message i have no idea how to tell the dict to stream that key/value pair that is changing. and this solution seems so unefficient".
Because I think this is already the easiest implementation to your problem and also less time demanding than a brute force search/comparison.
Hey, I don't know how to help you without using javascript for this and also the solution that I propose seems to be far from elegant and efficient.
I attached an example how to retrieve different levels of your dict. Presumably not bug free and more or less for didactic purpose (I think one could also do something like dict.serialize()
).
To achieve the behaviour you are looking for one would have to implement the following:
a) Store the dict which is going to be changed in a separate var referenceDict = new Dict()
;
b) After each access to the dict iterate through both the changed dict and the referenceDict and compare each item by using something like if(variable === referenceVariable)
and report to an outlet outlet(0, variable);
if there is a difference. Copy the changed dict contents to the referenceDict
thx. i will look into this.
Hey, still nobody around who knows a simple solution for this? Get the changed key in a dict?
I investigated the problem a little bit further (js is still my favourite, but no time for this) and I wanted to share this here. It uses [dict. serialize] and [zl compare] and returns the index of the change in the serialised dict (which is text). Don't know if this approach makes sense, if it is possible to extract the corresponding key from the text with the index and if there will be other impassibilities.