How do we limit selectable samplemaps within a combobox?
-
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; }
-
var element = document.getElementById('List')
No no no no no no no. HISE Script is not Javascript. And there is no DOM. :D
-
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
-
@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.
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.