Build Application and JSON files?

FriFlo's icon

I have successfully built an application from a Max project. Everything seems to work, including loading all dependent JSON files within the project. However, when I press the GUI-button save, which triggers those JSON files to get saved (works just fine within max!), the console shows me an error for every JSON file to be saved. Is saving presets not supposed to work within an application? Loading seems to work, because I don't get any errors there ...

Nikolas K's icon

Hi Friflo,

It would be easier to identify the problem it you could post some details about it, like what is the error and where do you try to save the json?

Nick

FriFlo's icon

Hi Nick,

it is a more complex project with a lot of midi processing and I cannot explain every detail about it, but this is what doesn't work:
There are six pattrstorage objects within sub patchers and patchers of the projects main patcher. All those get saved to JSON files manually or when closing max. At startup of the main patcher, the JSON files get read into the pattrstorage objects, so all parameters/presets are available. Both of those work fine within the main patcher! The JSON objects are included in the project and are therefore saved to the subfolder "Data". To save one of the pattrstorage current content to disk, I send it the order "write", which asks me where to save the JSON file and with which file name. As I do not want to go through all of those manually, I send "write ", but within the project, max knows where the file is located, so it works automatically without a specifying the location on disk. I suppose, when building a standalone application from a project, those dependencies will get solved and the content of those JSON files gets somehow saved within the app itself, this is what I don't know anything about and what could be a misunderstanding of how these work ...
Anyway, it seems to work so far, that I can open the built application with everything doing its thing as it is supposed to! The content of those JSON files must somehow be within the app itself, unless the app reads them from the project's subfolder, which would be odd for a standalone app. All I can say is: the data for the pattrstorage objects is exactly as it was last saved, before I built the application, so somehow it must have been read by the app.
Now, what doesn't work within the app is saving the pattrstorage content! Within max, created a button, that bangs the message "write " to all pattrstorage objects. This correctly saves all changes of this content within max, but within the app, I get an error message for each of those write messages. I hope, this makes my question easier!? Thanks for listening!

Fritz.

Nikolas K's icon

It does make it more understandable, but still, its not the complexity of the patches or the values, but the steps you do to read and write the json files. That is, how do your read them, from where, what messages? are they indeed included in your project (I assume a Max project)?

Well, if your .json files are included in the project, they get included in the .mxf that gets created when you build the standalone. You can read them with a "read json-name.json" but cannot "write" them.

The JSON objects are included in the project and are therefore saved to the subfolder "Data"

The "Data" folder, is created by you I suppose, but how do you conclude that the json are saved there?
I would suggest, using full paths when saving and reading files.

Sorry for the many questions, but the more info, the easier it will be to solve.

Nick

FriFlo's icon

Yes, the JSONs are in the max project subfolder "Data", which is where every max project automatically saves data files like JSON when prompted to save. I did not create the folder. That is why I suppose every pattrstorage object within this project also understands the the message "read "( or respectively write). I can verify this by looking into the content of those JSON files by text edit. No directory path has to be added to the message read or write! That is why I assumed, the JSONS would be somehow saved within the application as well, if it was to represent the project.
So, will I have to specify a location for those JSON files to be saved, when it is an application? There is no way, the app can store those changed settings within itself?
If that is the case, how can I provide the same app for another PC or Mac, where it will remember the location of those files after the first start? That would be the whole point of making an application, wouldn't it? :-)

Nikolas K's icon

What I usually do, is to use the locations that the OS expects me to write stuff like that.
On Mac the location is "~/Library/Application Support/name-of-your-app".
On Windows it is the "C:/Users/your-user-name/AppData/Roaming/name-of-your-app"

The Mac folder is created by the OS the first time you launch your standalone, but on Windows you have to create it by yourself and given that max doesn't let you create folders, you should make and installer that does that.

Then, when the app launches, I check, do the json exist in the appropriate folder? If yes, read them (using the full path).
if not, read them from the max mxf (simple "read name-of-json"), and write them at the appropriate position, then check again to be sure that they get read from there.

I know its a bit of work, but its the expected behavior.
Hope this heps,
Nick.

FriFlo's icon

Yes, that helps! It is a good idea, as those folders exist at every computer - I just didn't think of it in the right way! ;-)
And the subfolder named after my app name will be created by max, if it doesn't exist I suppose. So, that problem is solved! Thank you!

Nikolas K's icon

Well, not exactly. Mac and Win need different approaches.
First of all, you must include the [standalone] object in your main patch, then open the [standalone]'s inspector, and at the "preferences folder" attribute , change the value to your app's name.

Then, a Mac, yes, when the app first launches,it will create the folder "~/Library/Application Support/your-app-name". Max also stores some stuff there.
A Windows machine, I think will not create any folder. You have to make an installer for your application, that does that for you (not Max).
I think the Advanced Installer has a free license, and can do that, or if you like a bit of a scripting, you could try the NSIS installer.

Good luck with the project! Cheers!

Nick