Making a Viewport List Folders in UserPresets
-
Hey!
I’m on my custom preset browser adventure and thought of a way to go about it, like the default preset browser, let’s make it present the folders in the UserPresets folder! Anyways, how do I get the contents of the UserPresets folder, specifically folders and not the Db.json file? And will this transfer nicely over to the final product, since I’ve heard the “UserPresets” folder becomes “User Presets” after compiling. Side question as well, what’s the difference between the presets and userpresets folder, the auto saves seem to go in the presets and actual presets in the user presets? Is the “presets” one read only or something?
Thanks!
-
@Casmat Presets is for HISE project presets (.hip). User Presets is for what you want.
You can use the File and File System APIs to do all the file handling you're interested in.
To get a list of files in a folder you can use the
findFiles()
function. -
@d-healey Thanks David! Will take a look!
-
@d-healey I got a button to work on my interface which updates a viewport, when clicked it browses for directory and finds the files in that directory and converts it to strings and displays it on the viewport:
inline function onbtnFindUserPresetsControl(component, value) { FileSystem.browseForDirectory(FileSystem.Downloads, function(folder) { if(isDefined(folder) && folder.isDirectory()) { var folderArray = FileSystem.findFiles(folder, "*.txt", false); for(file in folderArray) { file = file.toString(1); }; vptBrowser0.set("items", folderArray.join("\n")); } }); }; Content.getComponent("btnFindUserPresets").setControlCallback(onbtnFindUserPresetsControl);
Couple questions however:
-
Is there a way for the plugin to find the userpresets folder automatically instead of having to open up a browser each time. I thought about having a setup prompt which asks for the folder upon first load and save it in a variable, but there may be a more seamless way as I saw in the docs of filesystem that there were "special locations" with a "AppData" location which may be able to locate the userpresets folder automatically? In that case how would I get the userpresets folder from the appdata?
-
The viewport only shows the files at the time of button pressing, how do I make it show a continuous view of the directory with real-time updates, so that whenever a file is updated in the folder manually, it updates the viewport, like in the default preset browser?
-
I could only get test "*.txt" files to work to be viewed, how do I make it so the wildcard is only folders in the findFiles() function?
Thanks for your help!
-
-
-
FileSystem.getFolder(FileSystem.UserPresets)
-
Would need a timer, this would eat up a bit of CPU
-
FindFiles I think only returns files, but try
"*"
wildcard.
-
-
@d-healey Thanks! Now everything fits into this!
reg folderUserPresets = FileSystem.getFolder(FileSystem.UserPresets); if(isDefined(folderUserPresets) && folderUserPresets.isDirectory()) { var folderArray = FileSystem.findFiles(folderUserPresets, "*", false); for(file in folderArray) { file = file.toString(1); }; vptBrowser0.set("items", folderArray.join("\n")); };
The
"*"
shows the folders in userpresets, but also the files, is there another function or method that I'm not seeing that only gets folders? I could use"*"
, but there is adb.json
file that is in the user presets folder, which I don't know if I can remove... -
@Casmat Run through the file objects in a loop and filter out the directories using the
isDirectory
function.const filesAndDirectories = FileSystem.findFiles(FileSystem.getFolder(FileSystem.UserPresets), "*", false); const directories = []; for (f in filesAndDirectories) { if (f.isDirectory()) directories.push(f); }
-
@d-healey What a simple, but effective solution