How to Save a Preset?
-
I realise this may be obvious, but I can't seem to save a preset. I simply have this statement in my code…
Engine.saveUserPreset("Test Preset");
…but no file is written. (I'm expecting a file to be created with component values I've set the save-in-preset flag to, and addModuleStateToUserPreset data.)
What am I missing?



Thank you.
-
@clevername27 This function saves onto a currently loaded file. This means the file has to exist first.
-
@ustk Thank you for your reply. If Engine.saveUserPreset doesn't create a file, then how does it get created?
-
File/FileSystem API
inline function savePresetAs() { FileSystem.browse(FileSystem.getFolder(FileSystem.UserPresets), true, "*.preset", function(f) { var filePath = f.toString(File.FullPath); var parentDirectory = f.getParentDirectory().toString(File.FullPath); var userPresetsDirectory = FileSystem.getFolder(FileSystem.UserPresets).toString(File.FullPath); if (parentDirectory == userPresetsDirectory) return Engine.showMessageBox("Invalid Location", "Please choose a sub folder to store the preset.", 0); if (!filePath.contains(userPresetsDirectory)) return Engine.showMessageBox("Invalid Location", "Please save the preset within the User Presets folder.", 0); Engine.saveUserPreset(f.toString(File.FullPath).replace(".preset")); }); } -
@d-healey I don't care if you are using HISE to make "virtual instruments" (as if that's a real thing). You're alright.
-
C clevername27 has marked this topic as solved on
-
I had to make a slight tweak to the above, to fix some parameter 0 errors in the console:
inline function savePresetAs() { FileSystem.browse(FileSystem.getFolder(FileSystem.UserPresets), true, "*.preset", function (f) { var filePath = f.toString(f.FullPath); var parentDirectory = f.getParentDirectory().toString(f.FullPath); var userPresetsDirectory = FileSystem.getFolder(FileSystem.UserPresets).toString(f.FullPath); if (parentDirectory == userPresetsDirectory) return Engine.showMessageBox("Invalid Location", "Please choose a sub folder to store the preset.", 0); if (!filePath.contains(userPresetsDirectory)) return Engine.showMessageBox("Invalid Location", "Please save the preset within the User Presets folder.", 0); Engine.saveUserPreset(f.toString(f.FullPath).replace(".preset")); }); }This seems to work now. Maybe a HISE version issue, as this thread is quite old now.
-
@Orvillain so what happens if there is no preset file in the directory, like when you first deploy the plugin? Wouldn't the browse function fail, since it wasn't able to get a file?