Forum
    • Categories
    • Register
    • Login

    How to Save a Preset?

    Scheduled Pinned Locked Moved Solved Scripting
    7 Posts 5 Posters 816 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      clevername27
      last edited by

      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.

      ustkU 1 Reply Last reply Reply Quote 0
      • ustkU
        ustk @clevername27
        last edited by

        @clevername27 This function saves onto a currently loaded file. This means the file has to exist first.

        Hise made me an F5 dude, any other app just suffers...

        C 1 Reply Last reply Reply Quote 1
        • C
          clevername27 @ustk
          last edited by

          @ustk Thank you for your reply. If Engine.saveUserPreset doesn't create a file, then how does it get created?

          1 Reply Last reply Reply Quote 0
          • David HealeyD
            David Healey
            last edited by

            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"));
            		});
            	}
            

            Free HISE Bootcamp Full Course for beginners.
            YouTube Channel - Public HISE tutorials
            My Patreon - HISE tutorials

            C 1 Reply Last reply Reply Quote 5
            • C
              clevername27 @David Healey
              last edited by

              @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.

              1 Reply Last reply Reply Quote 1
              • C clevername27 has marked this topic as solved on
              • OrvillainO
                Orvillain
                last edited by

                @David-Healey

                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.

                Musician - Instrument Designer - Sonic Architect - Creative Product Owner
                Crafting sound at every level. From strings to signal paths, samples to systems.

                P 1 Reply Last reply Reply Quote 0
                • P
                  pgroslou @Orvillain
                  last edited by

                  @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?

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post

                  22

                  Online

                  2.2k

                  Users

                  13.3k

                  Topics

                  116.0k

                  Posts