HISE Logo Forum
    • Categories
    • Register
    • Login

    Making a Viewport List Folders in UserPresets

    Scheduled Pinned Locked Moved Scripting
    8 Posts 2 Posters 349 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.
    • CasmatC
      Casmat
      last edited by Casmat

      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!

      i make music

      d.healeyD 1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey @Casmat
        last edited by

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

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        CasmatC 2 Replies Last reply Reply Quote 0
        • CasmatC
          Casmat @d.healey
          last edited by

          @d-healey Thanks David! Will take a look!

          i make music

          1 Reply Last reply Reply Quote 0
          • CasmatC
            Casmat @d.healey
            last edited by Casmat

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

            1. 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?

            2. 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?

            3. 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!

            i make music

            d.healeyD 1 Reply Last reply Reply Quote 0
            • d.healeyD
              d.healey @Casmat
              last edited by

              @Casmat

              1. FileSystem.getFolder(FileSystem.UserPresets)

              2. Would need a timer, this would eat up a bit of CPU

              3. FindFiles I think only returns files, but try "*" wildcard.

              Libre Wave - Freedom respecting instruments and effects
              My Patreon - HISE tutorials
              YouTube Channel - Public HISE tutorials

              CasmatC 1 Reply Last reply Reply Quote 0
              • CasmatC
                Casmat @d.healey
                last edited by Casmat

                @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 a db.json file that is in the user presets folder, which I don't know if I can remove...

                i make music

                d.healeyD 1 Reply Last reply Reply Quote 0
                • d.healeyD
                  d.healey @Casmat
                  last edited by d.healey

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

                  Libre Wave - Freedom respecting instruments and effects
                  My Patreon - HISE tutorials
                  YouTube Channel - Public HISE tutorials

                  CasmatC 1 Reply Last reply Reply Quote 0
                  • CasmatC
                    Casmat @d.healey
                    last edited by

                    @d-healey What a simple, but effective solution 😁

                    i make music

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

                    32

                    Online

                    1.8k

                    Users

                    12.0k

                    Topics

                    104.5k

                    Posts