Filter/display sampleMap names by _prefix
-
If you just want a list of numbers that goes from 1 to the number of sample maps why not just use
array.length
in a loop and forget about string manipulation? -
@d-healey said in Filter/display sampleMap names by _prefix:
array.length
No sorry, I should have mentioned/given a better example in terms of the naming. I don't want a list of numbers.
I need the list to display: kick1name,kick2name,etc..
instead of: BD_kick1name, BD_kick2name, I still need to remove the prefix [BD]You mentioned array.length . So the sampleMap List return IS an array?
I can't seem to grasp how to access/edit the sample map list return -
@ten7kur You can either use
String.replace(var substringToLookFor, var replacement)
orString.substring(int startIndex, int endIndex)
since the samplemap list is an array of strings -
@ustk said in Filter/display sampleMap names by _prefix:
@ten7kur You can either use
String.replace(var substringToLookFor, var replacement)
orString.substring(int startIndex, int endIndex)
since the samplemap list is an array of stringsSo?....
sampleMapList.replace(sampleMapList "BD_", sampleMapList " "); SamplemapList.set("items", sampleMapList.join("\n"));
Im puzzled on the 'var's
-
@ten7kur said in Filter/display sampleMap names by _prefix:
So?....
I am not sure it will work if you directly edit the items in the samplemapList, the risk is that it won't be able to locate the samplemaps if the name doesn't correspond to the reality anymore...
If you just want to display the formatted names, fill a second array "formattedSamplemaps" with the applied filter from the original samplemapList -
@ustk said in Filter/display sampleMap names by _prefix:
formattedSamplemaps
I've done this but can't compile successfully:
//! =================== [ Samplemap List ] ================== ! const var SamplemapList = Content.addViewport("SamplemapList", 0, 0); const var Sampler = Synth.getSampler("Sampler"); const var sampleMapList = Sampler.getSampleMapList(); var formattedSamplemaps = []; //String.replace(var substringToLookFor, var replacement) sampleMapList.replace(sampleMapList "BD_", formattedSamplemaps " "); // SamplemapList.set("items", formattedSamplemaps.join("\n")); inline function onViewportControl(component, value) { Sampler.loadSampleMap(sampleMapList[value]); }; SamplemapList.setControlCallback(onViewportControl);
Could you please show me an example?
-
Actually, it's a bit more subtle if you want to make operation in an array, you should do this in FOR loop that iterates each member of the array.
I'll try to find the time to write something today -
@ten7kur That's you ;)
//! =================== [ Samplemap List ] ================== ! const var SamplemapList = Content.addViewport("SamplemapList", 0, 0); // Allow the viewport to list the items SamplemapList.set("useList", true); const var Sampler = Synth.getSampler("Sampler"); const var sampleMapList = Sampler.getSampleMapList(); // Populate the formatted list in a new array const var formattedSamplemaps = []; for (i = 0; i < sampleMapList.length; i++){ var newName = sampleMapList[i]; newName = newName.replace("BD_", ""); formattedSamplemaps.push(newName); } // Update the viewport SamplemapList.set("items", formattedSamplemaps.join("\n"));
-
@ustk
hmm...doesnt seem to work....
Although I can see/partly-understand the logic -
I don't know the solution at present as I haven't looked too much at your code, but I will when I have some free time if somebody else doesn't help you solve it.
However I noticed some things
const var sampleMapListFILTER
sampleMapListFILT.indexOf(sampleMapList, "BD");
The second one should be FILTER not FILT.
In a later post I see this
const var SamplemapList = Content.addViewport("SamplemapList", 0, 0);
const var sampleMapList = Sampler.getSampleMapList();
Those names are going to cause confusion, luckily HISEscript is case sensitive so the code will work, but it's bad practice. For the first one try something like
vpSampleMaps
(vp = viewport).Also stick to one format,
sampleMapListFILTER
is weird - why all caps at the end? andSamplemapList
- why does it start with a capital when your other variable names don't? -
@d-healey said in Filter/display sampleMap names by _prefix:
ar sampleMapListFILTE
Yes, I agree! :)
Some of the code was commented out. I was playing with it before....@ustk 's example looks like it should definitely work , it does ADD text, but does not remove BD_
-
@ten7kur
No sorry, It does work! Brilliant!!!! Big big thanks!How could I also escape directories?
I have sampleMaps inside folders inside my SampleMaps folder in my Project. -
@ten7kur Strange, it effectively removes the
"BD_"
part here...
I am not sure it's a good idea to make subfolders for the samplemaps... -
@ustk
It does work!
But how could I remove the other sounds "SD_", "HH_" from display all together. Just display the BD_ filter.OK. Fair enough on sampleMap subfolders
-
@ten7kur there are two ways:
-
Replace
newName = newName.replace("BD_", "");
withnewName = newName.substring(3, 100);
if you always have 3 characters to remove at the beginning. -
Or use this instead of the loop in my first example:
// String part you don't need const var charsToRemove = ["BD_", "HH_", "SD_"]; for (i = 0; i < sampleMapList.length; i++){ var newName = sampleMapList[i]; for (j = 0; j < charsToRemove.length; j++){ newName = newName.replace(charsToRemove[j], ""); } formattedSamplemaps.push(newName); }
The latter allows you to fill the "forbidden" array with any characters you want to remove
-
-
@ustk
Wouldn't have figured it out my self! Not with my current Javascript knowhow... -
Looking at this further, the filtration of BD_, SD_,etc..works. However, once I click on an item in the list, it does not change it in the sampler. (The sampler name is correct)
Im using this code:inline function onViewportControl(component, value) { Sampler.loadSampleMap(formattedSamplemaps[value]); }; SamplemapList.setControlCallback(onViewportControl);
-
How could I also hide specific sample maps. So only show "BD_", or only "SD_".
How would I 'categorize' them? -
@ten7kur If you think about it, you are trying to load a sample map with a wrong name...
hint: DoesformattedSamplemaps
contains the real .xml samplemap names? ;)For your second question, it will be a bit complicated...
Ok, for loading a samplemap, you need to call its name
But, here, for doing so, you are using a value and look at the table the real name that corresponds to this value in order to load the SM (hidden hint for question one ;) )In YOUR case (because there are different way to do it), you'll need to split the samplemapList list into several subSamplemapList depending on characters they contain in their name
Then you can format these names to remove what you don't like into, let say, FormattedSubSamplemapList
Then you can load them in different viewports
The value of these viewports will correspond to the different subSamplemapLists you can use to load the right SM -
@ustk said in Filter/display sampleMap names by _prefix:
n their
Got ya on the sampleMap loading.!
As for assigning categories,.... still a little puzzled..
const var charsToRemove = ["BD_", "HH_", "SD_"]; const var smCategories = ["BD_", "HH_", "SD_"]; for (i = 0; i < sampleMapList.length; i++) { var newName = sampleMapList[i]; var category = sampleMapList[i]; for (j = 0; j < charsToRemove.length; j++) { newName = newName.replace(charsToRemove[j], ""); category = category.substring(smCategories[j], "SD_"); } formattedSamplemaps.push(newName); formattedSamplemaps.push(category); }
Wouldn't
indexOf
be of help here?
So far I'm thinking ....for (i = 0; i < sampleMapList.length; i++) { var category = sampleMapList[i]; for (j = 0; j == smCategories;) { category = category.indexOf(smCategories["SD_"], "snare"); } formattedSamplemaps.push(category); }
Any help, very much appreciated!!