Custom Mini Preset Browser Example using FileSystem API



  • Hey folks!

    This seems to be a hot topic with the new FileSystem API, so for those who need a starting place for building a custom mini-preset browser in HiseScript, here's a simple snippet showing how to achieve the most basic steps for:

    • Loading presets from the user preset directory
    • Saving a set of controls to a file in the user preset directory with user input for the preset name
    • Fetching all preset names in a given directory and displaying them in a viewport
    • Showing the preset directory
    HiseSnippet 2295.3ocsZ0ziaabFd3tKCrjsRrcC5odfXOoscqhVWmzFajZ48q1MwqWUK6Ew0wMlhbzpIhhi.GpcsRvhZfdnWxk.zS8TAxgh.TTTzeAEnsW5ugV.+SH28A224CRNbHor1EwBvFly7Ny6y6Gyy7Ny3tQTOLiQiPV0t+rIXj0kr6MKLd3VCcIgn81FYcA6tQXFNFs4rItLF1GYYs7uf2qUsUPhee6s1zMvMzCm0DBcHk3guCYLINq0tc9HRPvtt936SFqI806rmGMbKZ.cJfjksail35Mx8H7cc4hsjMx5M1wmDSi5E6FiYHqU1j5Oq2P5IgR4OjvH8Cv7O1.0ClHYy6RC74Hl2JZqgj.+tIVLCAyR2L6eYo8+116S7Iosm4GtrnCmrQn6OrVZdvaCc30dwgmkF7VQBuqX2yKhLINqGN1tn8dgw3nAtPHPGVRYQKc5aYuEEjHLt0X2Q3cifORGQy2qc60cd21sW6lMp2n967NNbYinALmXpSerCy8XruCIzYhHQnQcHVwhcN1MxoW.waD7W93HmOvIQGGgi2hNdBMD9n4pZxrJWEYidSr6zXxfoAaNMNlFV4LXH2pRfJf513AjPLywMHvwKA1tg9NdPK8gjHly.ZjB4N8inmvvQMpGB4ULHGC6HSt2T1gyWzntC7KChxtuCA9rJzkIh.X7wm0TKFWVAt1Rgnlzvr9U8kLPS0ySgjBKRUliS1PvTnX1Q4.xTpWErfLBo3UCnTQxfRZSU.hz9WX0evjXBz7BfBkjoforY69j3.7BLWB4JYlj8x4rtOkK8qHkISvUmmkdvn4BoCFkyAevnpctGLRywVlp1hShGLW0IEImJkMUsZk8WZLcBcxz.fxLaAQy7B.Kw6p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cGww2sr1IjWomHiD8+gi7rcn
    

    Hope this is helpful! 😀

    A few extra things to consider:

    • This example saves the preset files in a certain format (key-value pairs), but it's up to you to choose how you'll save your controls and load them from your custom preset files.
    • This is completely separate from the built-in preset browser, so proceed with caution. The actual HISE user presets are formatted differently.
    • This doesn't include any protections for overwriting files or checks for invalid files / objects loaded.


  • @Lunacy-Audio Great. It will help me to learn.



  • @Lunacy-Audio "beautiful button" and "slick slider" 😁
    Love it!



  • @Lunacy-Audio
    Nice work! Im still having an issue with exporting midi using

    MIDIPlayer.saveAsMidiFile("{PROJECT_FOLDER}FileMIDI.mid", 0);
    

    Been trying to figure it out for over a year now 😕



  • @Lunacy-Audio i wonder if this can be used/modified to make a preset system for an arpeggiator part of the synth, in paralel to default preset browser?



  • @BWSounds Have you tried this:

    FileSystem.browse(FileSystem.Desktop, true, "*.mid", function(f)
    {
        MIDIPlayer1.saveAsMidiFile(f.toString(0), 1);
    });
    

    Track indexes are not zero-based (super confusing, but it's the MIDI standard) and you need to convert the file object that is passed into the result function to a String containing the full path.



  • @musictop I think that would be precisely the use case for this kinda thing! This will work best for smaller sub-presets within a larger plugin.





  • @Lunacy-Audio great! Thank you.



  • Nice one, this will be useful. thanks for sharing. 🙂



  • @Christoph-Hart said in Custom Mini Preset Browser Example using FileSystem API:

    @BWSounds Have you tried this:

    FileSystem.browse(FileSystem.Desktop, true, "*.mid", function(f)
    {
        MIDIPlayer1.saveAsMidiFile(f.toString(0), 1);
    });
    

    Track indexes are not zero-based (super confusing, but it's the MIDI standard) and you need to convert the file object that is passed into the result function to a String containing the full path.

    @Christoph-Hart I have a project that allows users to drag/drop midi files onto the interface and the plugin plays the files. This looks like what I need to actually save those MIDI files so that when the user saves their project in the DAW and re-opens the project, those MIDI files are still available. Currently, the files disappear on reload of the plugin unless they were compiled with the plugin.

    Could this be used to save and recall multiple user MIDI files? Then, to recall multiple midi files on init, could setFile be used?



  • No if you want a midi player to be restored with the user preset you will have to connect it like a EQ with this:

    https://docs.hise.audio/scripting/scripting-api/engine/index.html#addmodulestatetouserpreset



  • @Christoph-Hart So I've built two mini-preset browsers (thanks @Lunacy-Audio!) within the same plug in. I'm basically trying to save an LFO shape using one of the browsers, and then load it into a second LFO using the second browser.

    Everything works, except that when I save a new .preset file in one browser, and then go into the second browser to load it into the other LFO table, the preset list has not updated to include the new .preset file.

    So basically I'm looking for a callback function that will fetch all the relevant preset names to populate the list. I'm pretty sure its all in this script, but when I try and load bits into a button callback, I get errors.



  • You'll need a timer for this sort of thing where it repopulates the list every so often, like every 2000 ms or something. You could also add a refresh button like the one you describe for which you'll just need to add a button callback and then add the function populatePresetList() to that callback from the original snippet above.

    The timer approach will require some more testing. I tried this in one of my projects and it would occasionally crash the plugin, but worth a shot!



  • @Lunacy-Audio Yeah I looked at a timer but then realised a callback would be perfect. I tried to use populatePresetList() but kept getting errors.... said it wasn't a function.

    inline function onLOAD_LFO1Control(component, value)
    {
    	TABLEBROWSER1.showControl(1);
    	LFOCLOSE1.showControl(1);
    	populatePresetList();
    		
    };
    
    Content.getComponent("LOAD_LFO1").setControlCallback(onLOAD_LFO1Control);
    
    

    This is the callback on the button which brings up one of the browsers. If it refreshes the list at the same time that solves my problem. It felt a bit crude just sticking in populatePresetList(); and looks like it was 😂

    Interface:! Line 386, column 20: This expression is not a function! {SW50ZXJmYWNlfHwxMjQwOXwzODZ8MjA=}
    


  • Ah, I forgot to mention you just need to include the namespace that encapsulates the function, so PresetBrowser.populatePresetList();. Anything outside the PresetBrowser namespace doesn't know what that function is.



  • @Lunacy-Audio Brilliant thank you!


Log in to reply
 

13
Online

1.1k
Users

3.8k
Topics

33.4k
Posts