How do we limit selectable samplemaps within a combobox?



  • Hi there,

    Does anybody with a good HISE brain know how to get a Combobox to return a defined range of samplemaps?

    As an example, let's say I have 10 samplemaps in total in my HISE root folder, is there a way to get a combobox to only pull back samplemaps 5-10?

    I'm trying to setup 2 comboxes that are linked to 2 different Sampler modules and I was hoping to find a way to have unique sounds selectable in each.

    eg.
    Combobox1 to return Samplemaps linked to transient wavs
    Combobox2 to return Samplemaps linked to noise wavs

    The code below will pull back all samplemaps, but it would be ace if it could be modified to specify a range etc.
    Any thoughts?

    Cheers ☺

    
    const var sampleList = Sampler.getSampleMapList();
    const var ComboBox1 = Content.getComponent("ComboBox1");
    
    ComboBox1.set("items", sampleList.join("\n"));
    
    
    
    inline function onComboBox1Control(component, value)
    {
    	if(value)
    	    sampler1.loadSampleMap(component.getItemText());
    };
    
    Content.getComponent("ComboBox1").setControlCallback(onComboBox1Control);
    
    
    
    


  • @LeeC Make a new array, loop through the sample map list and add the ones you want to the new array. Use an if statement in the loop as a filter.



  • Ok, so I know I'm being silly with this one but I'm simply trying to create a new array that has been filtered to only return samplemaps that contain 'BD_'
    I'm trying to then display these filtered samplemaps within a view port.

    Can anyone see where I'm going wrong with the code below?

    I probably just need to go to sleep 😴

    Cheers

    const var Sampler = Synth.getSampler("Sampler");
    const var sampleMapList = Sampler.getSampleMapList();
    
    
    // Populate the filtered list in a new array
    const var filteredSamplemaps = [];
    
    for (i = 0; i < sampleMapList.length; i++){
        
        var newName = sampleMapList[i];
        if(sampleMapList.contains(BD_)){
            filteredSamplemaps.push(newName);
            
        }
    }
    
    
    
    Viewport.set("items", filteredSamplemaps.join("\n"));
    
    

    I initially tried to do something in this form but got myself in a tangle implenting it in HISE as 'textContent.startsWith' cannot be used

    function loadFilter() {
        var element = document.getElementById('List');
        var children = element.children;
        var filtered = [];
        for (var i = 0; i < children.length; i++) {
            if (children[i].textContent.startsWith('--')) {
                filtered.push(children[i].textContent);
            }
        }
        return filtered;
    }
    


  • var element = document.getElementById('List')

    No no no no no no no. HISE Script is not Javascript. And there is no DOM. 😄



  • ☺ Cheers @d-healey

    Just going through your 101 now.



  • @LeeC said in How do we limit selectable samplemaps within a combobox?:

    for (i = 0; i < sampleMapList.length; i++){

    var newName = sampleMapList[i];
    if(sampleMapList.contains(BD_)){
        filteredSamplemaps.push(newName);
        
    }
    

    }

    er isnt the string checker

    string.includes("xyz")

    not

    string.contains("xyz")

    .. and dont you need to refer to the element not the whole array, so (guessing) something like:

    for (i = 0; i < sampleMapList.length; i++){
        
        var newName = sampleMapList[i];
        if(newName.includes("BD_")){
            filteredSamplemaps.push(newName);
            
        }
    }
    


  • @Lindon said in How do we limit selectable samplemaps within a combobox?:

    for (i = 0; i < sampleMapList.length; i++){

    var newName = sampleMapList[i];
    if(newName.includes("BD_")){
        filteredSamplemaps.push(newName);
        
    }
    

    }

    Cheers for the response @Lindon...

    Just tried the string.includes("xyz") function but unfortunately it doesn't work in HISE.

    I might have to resort to just specifying an index range to pull back my desired samplemaps - if there isn't an obvious way to filter by name that is.

    Thanks again ☺



  • @LeeC There is documentation built into the script editor

    bbb8c502-9474-4d10-969f-ca2b7c3b0f29-image.png



  • @d-healey Yes this was my initial go to but there's nothing in this list directly related to filtering by name.

    Maybe going down the route of:

    string.substring(int startIndex, int endIndex) equals ("xyz")

    is the way forward?

    Apologies for not seeing anything that is obvious.
    Appreciate the 101 training either way.

    Cheers



  • @LeeC said in How do we limit selectable samplemaps within a combobox?:

    is there a way to get a combobox to only pull back samplemaps 5-10

    To go back to your original question, you wanted to filter by index 5-10, not name. So do you need to filter by name or by index?

    To filter by name you can use indexOf, or you can use regex.
    32c13e50-de86-40b9-8716-c213b3f384d8-image.png

    If you right click on an item in the built in documentation it will give you more info about what the function does and how to use it.



  • @d-healey Yes you're right, my original question was asking to filter by index which your 101 has now taught me how to do.

    However, ideally it would be greate to filter by name which would ultimately harness the power to pull back samplemaps from a list of hundreds (irrespective of their index number).

    So to summarise, a way to filter by name would be ace.

    Sorry for any confusion. ☺



  • Simplest way is to use indexOf

    const var sampleMaps = ["sampleMap1", "sampleMap2", "sampleMap3", "sampleMap4", "sampleMap5"]
    
    Console.print(sampleMaps.indexOf("sampleMap2"));
    


  • You can also use .contains even though that's not in the docs for strings @Christoph-Hart ?

    Console.print(sampleMaps.contains("sampleMap2"));

    This is helpful for a partial search, for example if you wanted to get all of the samplemaps with the word drum you could do .contains("drum") even if the name contains other words too.


Log in to reply
 

8
Online

553
Users

2.1k
Topics

16.4k
Posts