Saving a Dict as part of a Live Set with Dict not being updated from C++ min API
I am getting strange behaviour when trying to save a Dict as part of a live set - the difference in this case is that I am updating the Dict from inside a Max package I have written in C++ using the min api.
I define the Dict as a named dict object in the patcher and have enabled parameter saving on it:
dict channelNames @parameter_enable 1
Then inside the C++ package I connect to the same dict by defining it like this:
dict channelNames {symbol("channelNames")};
I can then update the Dict by writing to it and the touching it to make sure it is updated everywhere:
channelNames["channel1"] = "One";
channelNames.touch();
Inside the max editor window this all works fine and any changes I make to the Dict are persisted when I save the Live Set.
But when I try running this properly just inside Live any updates to the Dict do not get saved - it always reloads the last set of data I updated when inside the max editor window.
Do I need to be doing something extra to mark the Dict as dirty so it gets saved with the Set? I had assumed this is what touch() is doing but perhaps I need an extra call?
Any help much appreciated.
Hi did you find a solution ?
I didn't I'm afraid - gave up in the end and used a pattr object linked to the package I am writing in C++
Hi Simon, thanks for your answer. I am really struggling hard.
And i also tried the pattr directly connected to the external solution but no success to correctly bind the attribute special "Value" to the pattr.
I don't understand well how to write this part :
attribute<dict> m_value { this, "value", atoms{dict()},
// setter {
// MIN_FUNCTION {
// using namespace c74::max;
... and so on
if you have any working code about how to store a dict inside the "value" attribute, only this portion of code, i would really appreciate.
all the best
pierre
Pierre,
So to save stored state I created an output:
outlet<> outputStoredData { this, "(symbol) stored data" };
and then when I want to persist the data I create a JSON string of the data (you could encode in however you want though) and send that to this output - so something like:
atoms message(1);
message[0] = jsonData.stringify(false); // you might want to encode it a different way
outputStoredData.send(message);
Then to read the persisted data I have a second input:
inlet<> inputMessage { this, "(list) commands" }; // this is used for other things
inlet<> inputStoredData { this, "(symbol) stored data" };
And I read the incoming data like this:
message<> commandList { this, "anything", "commands",
MIN_FUNCTION {
if(inlet == 1)
{
std::string jsonString = args[0];
JSON json;
json.parse(jsonString); // you might have encoded it in another format
// do things with the parsed JSON here
return {};
}
// I process the messages on the first input
}
};
Hope that helps a bit?
Simon.
Hi Simon, thanks, it is a good workaround solution.
This works for me.
I tried first with the official mindev solution, using the argument method, and setvalueof and getvalueof but with min devkit, but no luck to make it work well.
If somebody knows...
All the best
Pierre
OK good - glad that worked