AudioBus state saving: converting ValueTree to NSDictionary

Hi All

I've got an iOS app that I'm trying to make compatible with AudioBus' state saving feature.  In my app I keep track of all my parameters with a handy Juce ValueTree. AudioBus wants me to give it an NSDictionary to save. 

Can someone recommend an easy way to spit out an NSDictionary or maybe a Plist from a ValueTree so that I can easily pass that data to AudioBus and reload it later?

-nick

I don't think we have a way to export to NSDictionary. However if all you want is a PList (which is essentially just an XML file), maybe you could write the ValueTree out as an XML? You could then try to read it back in with NSDictionary.

Good point. I'll try that first and see if it works. I think Plists have to be formatted a certain way though, so not sure if it will fly.  

I think you can just use plain XML like this:

<plist>
  <dict>
    <key>name</key>
    <string>value</string>
    ...

  </dict>
</plist>

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/PropertyLists/UnderstandXMLPlist/UnderstandXMLPlist.html

Or you could save the ValueTree as a JSON string and use that to create the NSDictionary object. I've successfully used this method to convert NSDictionary objects to ValueTree objects, I'm sure it can be done the other way round. The set up is a little tricky though (I'm in the process of setting up an example project that does this...!)

interesting. yes please do share if you can find time :)

For now I managed to do something pretty simple to get this working. To save, I create an NSMutableDictionary, then just iterate through the ValueTree and create dictionary entries using the Identifiers and vars from the ValueTree (reading them as UTF8 strings). Then on the way back in, iterate through the Dictionary and update the current state from the Dictionary entries. With a little conversion you can use UTF8 strings when checking a ValueTree's Identifiers or setting its Vars and it deals with them just fine, so everything seems to work for what I'm doing. But then again all of my parameters are represented by numbers and I don't have anything nested in my ValueTree, so my case is pretty simple -- I haven't done any testing for more general uses of ValueTree.