Struct to/from File

jersmi's picture

Probably a simple solution -- how do I get the Kineme Struct To File patch to record a succession of structure values over time, like with the Value Historian?

smokris's picture
Re: Struct to/from File

Use the Queue patch to collect per-frame data, then write the entire queue structure using Struct To File.

jersmi's picture
Re: Struct to/from File

Can the queue size be dynamic or does it require a set size? Say I want to draw on the viewer for a few secs, save to file 1, then draw again for a different length of time, save to file 2, etc.

EDIT: found this, which I think answers my question: http://kineme.net/forum/Discussion/DevelopingCompositions/QuestionaboutS...

jersmi's picture
Re: Struct to/from File

Confused. I can capture a .plist from a queue, size = 300 (10 secs at 30fps?). But I cannot get it to play back with Struct From File. To capture I am using a Kineme Named Structure Maker connected to a queue to Struct To File. One thing -- all the structure members in the .plist are out of order? I tried iterating the queue structure to try and see any/all members in the .plist at once. I tried exposing Struct From File patch time and starting from 0 as "read" is selected. I cannot get any .plist data to show up. My comp is a bit of a spaghetti mess right now, otherwise I'd post it. Help?

gtoledo3's picture
Re: Struct to/from File

You have to use the keyed structure maker for it to return an array and not a dictionary....which will read back in the correct order.

dust's picture
Re: Struct to/from File

check out the repository. there is a file i made that does this. "value recorder"

jersmi's picture
Re: Struct to/from File

Thanks and thanks.

jersmi's picture
Re: Struct to/from File

Still don't have this one -- not sure what else to try to get the data from the queue to the .plist as an array, or whatever it takes to read back the structure.

I am using a Named Structure Maker before the Queue (with 3 keys, "x", "y" and "b", for mouse X position, Y position and left button). The .plist file gets written as a dictionary (root) with a dictionary for each queue member (and gets read out of order, it appears). GT, does your workaround involve some way of converting the queue output before it gets written to .plist file to make the .plist think it's an array, or after it gets read from Structure From File?

Dust's (excellent) example saves a separate .plist file for each param, which I guess gets around the problem I'm having with a structure within a structure.

jersmi's picture
Re: Struct to/from File

Here's the comp in progress. The write setup is inside the Struct To File macro.

Could javascript be used instead of the Named Struct Maker patch?

Also, re: http://kineme.net/BugReports/BugStructureToFromFilepatches

I am using Structure Key Member patches when reading .plist file, with a Struct Index Member patch feeding them (needed for playback, right?). I also tried index member patches after the key member patches.

In the pic, playing directly from the Queue plays fine, it's writing to / reading from file that gets wacky.

jersmi's picture
Re: Struct to/from File

So I'm looking around for info on keeping arrays of arrays in order in this case. It seems a known issue, maybe... I see several posts mentioning the issue of structures out of order, but it's muddy waters. Since I am a novice at JS (I am trying, reading and learning, though, slowly), I can't quite get a grip on this...

Is there a technique in javascript for keeping arrays of arrays in order that could apply to this case (saving to .plist)?

dust solved the problem by saving to file only as a one dimensional array. i could do this, iguess, since i only have 3 variables in the structure (mouse values -- X position, Y position, Left Button saved as a number 0 or 1).

usefuldesign.au's picture
Re: Struct to/from File

To clarify, keys are associated with dictionaries (key and data pairs) while arrays are indexed structures, which are lists of items (usually of a particular type of data but not necessarily). When you hover the cursor and preview a structure, the item number is the first bit of info in brackets (item#) and the key if there is one is in quotes "Key Value".

For more explanation see comment below

usefuldesign.au's picture
Re: Struct to/from File

gtoledo3 wrote:
You have to use the keyed structure maker for it to return an array and not a dictionary....which will read back in the correct order.

How can we tell what the underlying NSObject carrying a structure insde QC is, ie. is it a dictionary or an array. To me any structure using keys even empty ones (ie. "") must be a dictionary.

usefuldesign.au's picture
Re: Struct to/from File

Quote:
To clarify, keys are associated with dictionaries (key and data pairs) while arrays are indexed structures, which are lists of items (usually of a particular type of data but not necessarily). When you hover the cursor and preview a structure, the item number is the first bit of info in brackets (item#) and the key if there is one is in quotes "Key Value".

Sometimes the key may be a number rather than an assigned text/token. Using the Kineme Structure Maker patch, you get the number in the item and the key. If you tick "Skip Empty Inputs" node you get a miss-match between the auto-generated Keys and Item numbers with unplugged value ports.

What these patches output is a dictionaries as far as I can tell because there is always a "key value" assigned. A key for data is the fundamental difference between dictionaries and arrays. However Dictionaries can be treated as arrays and iterated through as every keyed vale also has an index. Also the key for the Structure Maker patch is auto-assigned an incrementing-by-1 number which is what George is referring to, it looks like an array and can be treated like one. Worth bearing in mind the item and key numbers might not always match for reason of unplugged ports.

.plists are dictionaries but as I just said they can be treated as arrays if you are aware of numbering issues that can send you a cropper. Usually there is a way to remidy the situation easily like just a sort patch or iterating through the items in a Javascript patch.

The comp I'm posting has four different ways to make a simple 1D structure, 2 JS methods , Kineme Struct Maker patch and Queue patch. You'll notice if you set the published to top level settings "Find Key member by" to "Key" and "Input" to "Queue" that the Queue patch method is the only one which generates a genuine Array structure that fails to get displayed when iterated by "key" member not index. I think this demonstrates that all the other methods are actually creating dictionary structures that can be treated as arrays.

usefuldesign.au's picture
Re: Struct to/from File

Demo comp

This comp illustrates nested structures with key and item number mis-matches when using the structure item and key patches to iterate through a structure.