Filter/display sampleMap names by _prefix
-
Hi all,
Im trying to FILTER the SampleMap names on the GUI front[in the Viewport], to display only the ones with a specific PREFIX in their names and also remove that prefix from showing on the GUI front.
I've named my sampleMaps [inside SampleMaps directory in my Project] as
BD_1.xml, BD_2.xml, SD_1.xml, SD_2.xml , etc..
Im want the sampleMap list[viewport] to display "1", "2" etc as a result
I've tried using things like:
const var sampleMapListFILTER = sampleMapList.contains(function(filt) { return filt.BD == " "; }); SamplemapList.set("items", sampleMapListFILTER.join("\n"));
sampleMapListFILT.indexOf(sampleMapList, "BD");
if(Array.from("sampleMapList"))
var FIND = sampleMapList.contains('BD');
I can't seem to be able to put the sampleMap list into another array. Im guessing its a String?
New to Javascript, stuck on this for 3rd day, kinda running out of ideas....
Someone please enlighten me on where I'm going wrong!?HiseSnippet 2791.3oc6ZslaajbDdFIOdWxXsY2E9G4OAnMQ.LIhVJNjRZeXXDYJJaqDqGPT1aBTDLFR1jrWOb5Iyzij0ZHf8.jiPxcHWf.jCR90dB1aPRUcOu4CQQaY37fFVyzUWU20Tc0eU+MjG5w6R884dZ5EN9BWpl9cLZegiX31CsXNZ61RSunQyiN3aauyQMzZdgqkuOsmlt9xOA6Wuvszje9oeSSKaKmtzDQZZufy5ReFaDSjH8vs9cLa6Ga0idLaTJsWeqc6xc1layC.eYYiZZtVcek0.59VnZKYnoe6c5wDbu1BKA0WS+VM48tn8P94NJ8eAym0wlhML0ZCCjR7i418POFkps8PlcuCidl80zzMNLIBrrJBbWi8X8XwxShDeprCRhEoiG5KMK2yLs6Ua9cO8Tt2sTt2mYztqGyUjzC5a+LiccDTu9VvRPZ2Roq1R+zxFayAMbDUGY8J5i8fFwVTtQsZqRpWqVkGrRwUJBKD9BxYVdj1VibsoirbeFCj7PRzPX0q2KXzyc4dhxkxnTIbbv+iCU9AxCFBY1U0ATQnnH68Jk0Beoz8hm5PsRrLrqxnYqsFZhkmm0Efp+11GreUeWaF3bYFlRpmu0VKizGu6yNtJyoG80GzubldVkTpYqXid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2my6e7hLuAoBQSYaFFJ1wANJGGjnhOsn8sBrEQRMyMo6wc3tC4Nrtikr.q8CF.aUy5MSyKejP.YunvMROH1TfKJtczL0X+L3zBVdQaQtFOpyJ59KLTt.AA.He3fJW6C.T4Y48eR3VHBrm2SbyGstigbGMAwpeKlsi3AB.qLBhx.PwTEzSikUWKrUsv2ZJ0oWML.9ElQ8XF9F2gdLC6QqazP.yb38pyLrL0AwgBq1ZC3o14VS8ghGn+fmz3lzEGY00i+xtpC.gN5GKk.Z5HeY2EL1CaSLiN5iA5kZi.nsW1salQYLapu.1zXArY8EvlMV.a1bAr4KW.a9pYZCVU4QAB9HEDAH3vcBOI5NIYU0hOfKjs6R8DL7KKRuE8L3fGpcUE.Lc+WI3txS.GRqRSu305K3AyG0uK3EWDcif9Z7GFfwgxWziu14rdhgffa+2C+FfFRwWpEJ4OGJw0NX.y4PKOHLHnd6GFMhFg.epbtfIPGzVRoTS+OYzr0ZMaU0rn5pUG0M0UWZnt7RSY87vF9AcLStsdw8B7Ycaxecbw+hsasV6VlpK0UWZntr96h5y5KmBaJ4WYwMxuxf2EkczWZB9K9k2cC6uyaMqanefFucLQV3eEMty8uhlLDOhT6erUZJGQR+aakgrQxbMAdFQc9wakijQxiRNFFIcDSuH4YbLtEIcEQrHQRBqhDYYnTn18OFohDs+fhQQgH3ow9F6+n46arGFmCsfm7TZ1jMHdNTRRRiSwjS5Qo9ITociQj48v1uaVf1kmO2U6Fh4j9xo4MkduPLooDeehOPQzkhjb2sh4JEI5WsUZdRKTrvb9iEukTq9OtBjK++7EHWHRgeHtNOEFkuWc04fqmg9RXs0X1dFXYwH9dF5+K3SBgOUQyPJepNmGZo5KERJMIk9ZxH8s1K++LS+uQlo5Kq8uA.4AFN.
-
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