What is the "value" attribute?
In the Min Devkit docs there is mentioned a "value" attribute. Can anyone share some additional detail on what this attribute is and what it does?

I discovered that it only works if the type is set to "number". Otherwise it returns a funky compiler error.

To my knowledge, pattr can handle all the attributes of an object, including attributes of any type. Not simply number attributes called "value." So I don't understand what this attribute would be used for.
A bit about my usecase:
I am writing a UI object, and I'd like to persist a string between sessions. Save the string with the patch, and recall the saved string on load.
I think the "savestate" message would be ideal for my purpose. But I also discovered that "savestate" doesn't work with UI objects. So I thought maybe persisting the string through pattr using this "Value" attribute might be possible. But I'm not really understanding what this is or how it works.
Ideally the string would be internal to the object, and so not externally represented as an attribute, but at this point I'm willing to consider anything.
Thanks for any input on the mystery!
Hi Joe!
There shouldn't be any issues with your implementation. Rather, the ambiguity seems to arise from how you print m_value
. I assume you're calling cout << m_value << endl
somewhere in your code. If you change this to cout << m_value.get() << endl
, your code should compile.
If you want to hide it from the user, rather than using savestate
you can just pass visiblity::hide
to the attribute:
attribute<symbol> m_value{this, "value", "test", visibility::hide};
This way it's still exposed to pattr/preset/parameter_enable without allowing the user to set it manually
Minimal example (non-hidden):
#include "c74_min.h"
using namespace c74::min;
using namespace c74::min::ui;
class playground : public object<playground>, public ui_operator<100, 20> {
public:
inlet<> inlet_main{this, ""};
outlet<> outlet_main{this, ""};
explicit playground(const atoms& args = {}): ui_operator {this, args} {}
attribute<symbol> m_value{this, "value", "test"};
message<> paint { this, "paint", MIN_FUNCTION {
cout << m_value.get() << endl; // print stored value on mouseover
target t{args};
c74::min::ui::rect<fill>{t, color {color::predefined::gray}};
return {};
}};
};
MIN_EXTERNAL(playground)
Okay! That worked! Thank you! And especially thanks for the quick response.
One followup question if you don't mind:
I know it's possible to use a dict as an attribute. But I'm unclear, in Min, how to initialize a dict when it isn't a message input. Can you give any any input on how to set that up?

One other question has come up:
I noticed that in order for m_value to persist between sessions you have to save the patch. I mean, this makes sense, since it's basically writing the value into the patch json.
So how would this work in a standalone, where the user cannot edit/save changes to the patch? Is there a way for the pattr system provideto persist values between sessions in standalones?
Thanks again for the assistance!
The dict question is tricky. Yes, the pattr system is able to store dicts, but the min-api doesn't provide any proper bindings for attribute<dict>
. It's definitely possible, but it would require digging into the c api (which unfortunately doesn't provide any examples of dict attributes either).
For saving the state between sessions in a standalone: yes it's possible, either by writing pattr/pattrstorage data to a file on exit, or saving it directly into the file through the snapshot API (I don't know the details on how this works in standalones, but the documentation states that it's possible).
Either way, if you go for this solution, it's probably better to search the forum or make a new thread about it (since most of the people who distribute standalones won't read MinAPI questions and vice versa). The behaviour of your external will be identical to any other pattr/snapshot-compatible object
Beautiful!
Thanks so much for the helpful replies. My next steps are clear. Thank you!