[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sc-users] IdentityDictionary possible bug: does not behave correctly after a readArchive WAS Re: [sc-users] Parameter space - saving to disk
With some investigations I concluded that IdentityDictionary's
cannot be loaded with a readArchive.
z = Point(0.5,0.5)
y = Point(0.2,0.5)
a = IdentityDictionary.new;
a.put(z,"the point");
a.put(y,"another point")
a.writeArchive("/test")
b = Object.readArchive("/test")
b[b.keys.asArray[0]]
this gives nil. This seems to me to be a bug, and I wonder if it could
be fixed (devs ?). MultiLevelIdentityDictionary suffers from the same
problem and that's what is keeping ParameterSpace from being saved
correctly.
I made some methods to fix this, they are attached.
so now
b = Object.readArchive("/test")
b[b.keys.asArray[0]] //-> gives nil
b.fixIdentityDictionaries
b[b.keys.asArray[0]] //-> gives "the point"
.fixIdentityDictionaries fixes all IdentityDictionaries recursivly. Off
course it would be much better if the dictiornaries were properly
created in readArchive in the first place...
Finally, wouldn't it make more sense for the collect method to give as
args key,elem instead of elem,key ?
(\key1: \value1, \key2: \value2).collect{ |elem, key| [elem,key].postln }
bye,
Miguel
Martin Vognsen escreveu:
Hi Miguel
So you're writing the identity dictionary to disc and loading it? I
don't know why that wouldn't work, but absent an expert opinion I can
tell you what works for me: I keep all my presets in arrays outside
ParameterSpace and write the arrays to disc. When I load from disc or
change parameters I parameterDict.put the parameter values from the
preset arrays. That may seem backwards, and it get's a little
complicated to keep track of values with no keys this way when you have
a lot of parameters, but it works. So that might suggest that your
explanation is plausible. I actually wanted to clean up my code by
replacing arrays with dictionaries, as it's getting a bit out of hand,
but it seems there is something about identity dictionaries that needs
to be investigate first.
I hope you find a solution.
Martin
Den 30/04/2009 kl. 21.45 skrev Miguel Negrao:
Hi
I'm trying to save a ParameterSpace to disk using writeArchive but I'm
getting some problems. When I do readArchive then I can't access the
members of parameterDict.
After doing a = Object.readArchive doing a.parameterDict I get a nice
list of my points and parameters, but
a.parameterDict.at(a.points[0]) gives me nil...
Could it be related to the fact that "An IdentityDictionary is an
associative collection mapping keys to values.
Keys match only if they are identical objects. (i.e. === returns
true.)" and maybe after reading back the ParameterSpace from file the
objects in points and in the paramDict are no longer the same ?
thanks,
ps: ParaSpace from ixi quark is a great gui for ParameterSpace.
--
Miguel Negrão // ZLB
http://www.friendlyvirus.org/artists/zlb/
_______________________________________________
sc-users mailing list
info (subscription, etc.):
http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
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.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/
--
Miguel Negrão // ZLB
http://www.friendlyvirus.org/artists/zlb/
+IdentityDictionary {
fixID {
var temp = this.collect{ |key,elem| [elem,key] }.values;
this.clear;
temp.do{ |array| this.put(array[0],array[1]) }
}
}
+ Object {
fixIdentityDictionariesÊ{
var objects;
if (this.archiveAsCompileString.not) {
objects = IdentityDictionary.new;
this.fixID(objects);
}
}
fixID { arg objects;
//("Enterd fix. Object is "++this).postln;
if (objects[this].notNil) {^this};
objects[this] = objects.size;
if (this.archiveAsCompileString.not) {
this.slotsDo {|key, slot|
if (slot.archiveAsObject) {
slot.fixID(objects);
};
};
};
}
}