How do i remove numbers and underscore
-
How can i remove 01_, 02_ etc from my SampleMaps (shown in a combobox)
const var displayNames = []; for (var i = 0; i < sampleMapNames.length; i++) { var newName = sampleMapNames[i]; // Remove any numerical prefix followed by an underscore newName = newName.replace(/^\d+_/,''); displayNames.push(newName); } pianos.set("items", displayNames.join("\n"));
HISE does not like:
newName = newName.replace(/^\d+_/,''); -
replace("_");
for (var i = 0; i < sampleMapNames.length; i++) {
The
var
should not be there, I smell ChatGPT.A
for in
loop is probably better here. Gets it down to two linesfor (name in sampleMapNames) displayNames.push(name.replace("_"));
-
@ThinkTank Oh I just saw you want to remove the number as well. One moment...
-
for (name in sampleMapNames) displayNames.push(name.substring(name.indexOf("_") + 1, name.length));
-
I was just about to mention it, thanks a ton for the help.
You are spot on with ChatGPT, im trying to make it my mentor, but it gets a ton of stuff wrong still -
@ThinkTank said in How do i remove numbers and underscore:
im trying to make it my mentor,
It's the other way around, you have to mentor ChatGPT, it doesn't know when it makes a mistake.
Just posted the solution above your response.
-
Thanks a bunch, that's true haha. I'm giving ChatGPT a lot of scolding with these scripts.
-
It never really worked, not sure why. But now im just hiding them with panels
-
@ThinkTank said in How do i remove numbers and underscore:
not sure why.
Try and figure it out. Solving these problems is how you get more proficient at scripting. If you sidestep it now you won't have a solution the next time it happens.
-
True, and i also forgot i can not hide the name when i click the combobox and it drops down
The struggle is real. -
@ThinkTank said in How do i remove numbers and underscore:
The struggle is real.
Every is hard before it is easy. But it doesn't take much practice for things to start getting easier and there is lots of documentation and help available.
-
@d-healey @ThinkTank I haven't used ChatGBT for HISE at all but I can imagine it creates mutant script that kind of works until it causes problems further down the line that you have no idea how to solve.
I'd say ask the forum first for help, as you will benefit from the experienced coders like @d-healey and your code will have a much better chance of working
-
Absolutely correct!
Its a mess to work with, i have to do the research for it and come up with solutions about 90% of the time.However i now got it working.
If anyone else has this problem, here is the code:
// Layer A const var pianos = Content.getComponent("pianos"); const var sampleMapNames = Sampler.getSampleMapList(); // Assuming this is the correct function name // Remove numerical prefixes from sample map names const var displayNames = []; for (name in sampleMapNames) displayNames.push(name.substring(name.indexOf("_") + 1, name.length)); // Sort Array displayNames.sort(); pianos.set("items", displayNames.join("\n")); inline function onpianosControl(component, value) { Sampler1.asSampler().loadSampleMap(sampleMapNames[value - 1]); } pianos.setControlCallback(onpianosControl);
-
@d-healey Sorry for the old topic revival but how about in this case, I need to remove the wildcard {PROJECT_FOLDER} and the ".wav" extension from some audio files. I can do one or the other but don't know how to do both at the same time. Here is what I have so far:
const var Convolutions = Engine.loadAudioFilesIntoPool(); const var IRs = []; for (Convolution in Convolutions) { IRs.push(Convolution.replace("{PROJECT_FOLDER}")); }
-
You can chain it.
IRs.push(Convolution.replace("{PROJECT_FOLDER}").replace("next thing to replace"));
-
@d-healey worked like a charm... Thank you!