HISE Logo Forum
    • Categories
    • Register
    • Login

    Presets displayed in a combobox issues

    Scheduled Pinned Locked Moved Scripting
    5 Posts 3 Posters 123 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.
    • D
      drey
      last edited by

      Hi everyone. I'm newbie here.

      I got a combobox displaying the presets in presets folder, its working fine, but there are two problems:

      1 - The whole directory name + preset name is shown in the combobox instead of just the preset name.

      2 - When I save a new preset, It will only be shown in the combobox if I hit 'Compile' again.

      Does anyone have a clue of how can I fix this behavior?

      Code I have for this Combobox so far:

      const var Presets = Content.getComponent("Presets");
      var menuItems = [];

      const var x = Engine.getUserPresetList();
      for (i in x)
      menuItems.insert(-1, i);

      menuItems = menuItems.join("\n");
      Presets.set("items", menuItems);

      inline function onPresetsControl(component, value)
      {
      Engine.loadUserPreset(Presets.getItemText() + ".preset");
      };

      Content.getComponent("Presets").setControlCallback(onPresetsControl);

      ulrikU 2 Replies Last reply Reply Quote 0
      • ulrikU
        ulrik @drey
        last edited by

        @drey
        I wrote like this

        //   The Engine.loadUserPreset need a "relative path" or "file object"
        //   I used the relative path for loading the presets
        const var Presets = Content.getComponent("Presets");
        reg presetPaths = [];
        reg presetNames = [];
        
        const presetList = Engine.getUserPresetList();
        for (p in presetList)
        {
        	presetPaths.push(p); // here I save the relative path to the preset
        	presetNames.push(p.substring(p.lastIndexOf("/")+1, p.length));  // and here the preset name
        }
        
        //    Here I take only the names of the presets and put them in the combobox
        Presets.set("items", presetNames.join("\n"));
        
        inline function onPresetsControl(component, value)
        {
        	// since the combobox value range starts with 1, not 0, I need to subtract the value with 1
               Engine.loadUserPreset(presetPaths[value-1]+".preset");
        };
        
        Content.getComponent("Presets").setControlCallback(onPresetsControl);
        

        Hise Develop branch
        MacOs 15.3.1, Xcode 16.2
        http://musikboden.se

        D MorphoiceM 2 Replies Last reply Reply Quote 0
        • ulrikU
          ulrik @drey
          last edited by

          @drey said in Presets displayed in a combobox issues:

          2 - When I save a new preset, It will only be shown in the combobox if I hit 'Compile' again.

          If you have the name of the saved preset, you can just find the indexOf that name in the presetName list and use it for setting the value to the combobox
          Oh and when you have saved a new preset, you have to update the presetList so it will be present in the list

          Hise Develop branch
          MacOs 15.3.1, Xcode 16.2
          http://musikboden.se

          1 Reply Last reply Reply Quote 0
          • D
            drey @ulrik
            last edited by

            @ulrik Thanks a lot man, I really appreciate it! Super helpful, it works now

            1 Reply Last reply Reply Quote 0
            • MorphoiceM
              Morphoice @ulrik
              last edited by

              @ulrik This is super useful! Thanks.

              Anyone please note the combo box will have to have "saveInPreset" switched OFF,
              otherwise there's a loop loading the preset as onPresetsControl fires every time a preset is loaded.

              https://instagram.com/morphoice - 80s inspired Synthwave Music, Arcade & Gameboy homebrew!

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

              30

              Online

              1.7k

              Users

              11.7k

              Topics

              102.0k

              Posts