HISE Logo Forum
    • Categories
    • Register
    • Login

    How do we limit selectable samplemaps within a combobox?

    Scheduled Pinned Locked Moved General Questions
    13 Posts 3 Posters 562 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.
    • L
      LeeC
      last edited by LeeC

      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);
      
      
      
      
      d.healeyD 1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey @LeeC
        last edited by

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

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

        1 Reply Last reply Reply Quote 1
        • L
          LeeC
          last edited by LeeC

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

          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;
          }
          
          LindonL 1 Reply Last reply Reply Quote 0
          • d.healeyD
            d.healey
            last edited by d.healey

            var element = document.getElementById('List')

            No no no no no no no. HISE Script is not Javascript. And there is no DOM. :D

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

            1 Reply Last reply Reply Quote 0
            • L
              LeeC
              last edited by

              ☺ Cheers @d-healey

              Just going through your 101 now.

              1 Reply Last reply Reply Quote 1
              • LindonL
                Lindon @LeeC
                last edited by Lindon

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

                HISE Development for hire.
                www.channelrobot.com

                L 1 Reply Last reply Reply Quote 0
                • L
                  LeeC @Lindon
                  last edited by LeeC

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

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

                    @LeeC There is documentation built into the script editor

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

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

                    L 1 Reply Last reply Reply Quote 0
                    • L
                      LeeC @d.healey
                      last edited by LeeC

                      @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

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

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

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

                        L 1 Reply Last reply Reply Quote 1
                        • L
                          LeeC @d.healey
                          last edited by

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

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

                            Simplest way is to use indexOf

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

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

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

                              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.

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

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

                              49

                              Online

                              1.7k

                              Users

                              11.7k

                              Topics

                              101.9k

                              Posts