I'm looking at using UserProperties in a number of scenarios, but have not been able to get them working as I would expect. Specifically I am looking to store and retrieved boolean, integer or doubles from them.
Am I correct in assuming that the property will then be stored as part of any preset?
One of the use cases is to allow tracking of a status so that I can manage changes in the way knobs and sliders work (migrating from custom log scales to the new, more flexible ones coming in the next version) whilst ensuring that presets get automagically converted when used. Another use case is to store additional data about Jacks, such as their previously measured state.
Some example code snippets would be really useful for this.
Understanding Set/GetUserProperty
Re: Understanding Set/GetUserProperty
Looks like the properties are not automatically saved with either full or module presets, so it's just for storing runtime data. Other than that, there's not much to it, it's just a simple way to store and retrieve any object "inside" any GUI object with a string key. A couple of things to keep in mind (that come to my mind right now ) are:
Since the stored object is of the type Object, it usually needs to be cast back to the original type when using GetUserProperty, something like:
guiObject.SetUserProperty( "propertyName", "some string");
String newString = (String)guiObject.GetUserProperty("propertyName");
Another thing is that storing and retrieving objects with SetUserProperty & GetUserProperty seems to be relatively slow (maybe because they are identified with a string, and the need to cast... and also, if you just want to store a primitive value, it needs to be wrapped inside the corresponding object), so I certainly wouldn't use them in any realtime processing, like inside ProcessSample().
Since the stored object is of the type Object, it usually needs to be cast back to the original type when using GetUserProperty, something like:
guiObject.SetUserProperty( "propertyName", "some string");
String newString = (String)guiObject.GetUserProperty("propertyName");
Another thing is that storing and retrieving objects with SetUserProperty & GetUserProperty seems to be relatively slow (maybe because they are identified with a string, and the need to cast... and also, if you just want to store a primitive value, it needs to be wrapped inside the corresponding object), so I certainly wouldn't use them in any realtime processing, like inside ProcessSample().
Re: Understanding Set/GetUserProperty
Ok. Thanks for that. Useful pointers (and warnings) so I'll scrub that approach for what I wanted to do Will have to look at the formal way to store things with presets then!
Re: Understanding Set/GetUserProperty
You are welcome! One ”lazy man’s approach” to store persistent number values is to include/generate hidden knobs or sliders, and just get/set their values. I have used this in my (still very much unfinished) modules, not sure if I’m breaking some conventions here, but it seems to work perfectly.
-
- Site Admin
- Posts: 257
- Joined: Fri Jul 27, 2018 5:36 pm
Re: Understanding Set/GetUserProperty
These functions can be really useful if, for example, you're setting up a large grid of knobs, e.g. for a matrix sequencer, or a lot of buttons, e.g. for a drum sequencer. For example, when a button is pressed or a knob is turned, you can retrieve an object that contains the row & column of the control, which can be a lot easier than searching a 2D table every time a control is changed. But, no, these values are not saved with a preset in any way. They're purely there to make development of complex modules a little easier.
Thanks,
Dan
Thanks,
Dan
Re: Understanding Set/GetUserProperty
I've looked at similar approaches, and (for example) have used a combination of knob + digital display in places where buttons + digital display could have worked. Actually works as a nice UI approach, but does take up a bit more space.Captain wrote: ↑Thu Feb 28, 2019 3:19 pm You are welcome! One ”lazy man’s approach” to store persistent number values is to include/generate hidden knobs or sliders, and just get/set their values. I have used this in my (still very much unfinished) modules, not sure if I’m breaking some conventions here, but it seems to work perfectly.
Re: Understanding Set/GetUserProperty
I wrote a class that uses a text label to show an option from a list of options (like a filter type etc), a hidden knob to store the index value of the currently selected option, and then either a popup menu or click-n-drag to select a different option. Whenever I need to check which option is selected, I just read the value from the hidden knob. Works nicely, the selected option is automatically saved, and once there's a generic class for it, it's easy to add more of these in the GUI.