Combobox List Alphabetically
-
Hey Gang,
Ive got a 4 comboboxes scripted to 4 different audio loop players. These comboboxes list audiofiles. This is all working great except, the list is in the order of "Oldest to Newest" and would like it to be in Alphabetical Order. Below is my script, any help is appreciated.
const var SlotSelectors = [Content.getComponent("SampleSelection1"), Content.getComponent("SampleSelection2"), Content.getComponent("SampleSelection3"), Content.getComponent("SampleSelection4")]; const var AudioLoopPlayers = [Synth.getAudioSampleProcessor("LoopPlayer1"), Synth.getAudioSampleProcessor("LoopPlayer2"), Synth.getAudioSampleProcessor("LoopPlayer3"), Synth.getAudioSampleProcessor("LoopPlayer4"),]; const var expHandler = Engine.createExpansionHandler(); const var expansionList = expHandler.getExpansionList(); const var allList = []; const var allIds = []; const var rootList = Engine.loadAudioFilesIntoPool(); allList.push("No Sample Loaded"); allIds.push(""); for(r in rootList) { allList.push(r.split("}")[1]); allIds.push(r); } for(e in expansionList) { for(af in e.getAudioFileList()) { allList.push(af.split("}")[1]); allIds.push(af); } } for(s in SlotSelectors) s.set("items", allList.join("\n")); inline function onSlotSelectorControl(component, value) { local index = SlotSelectors.indexOf(component); if(value != 0) { AudioLoopPlayers[index].setFile(allIds[value-1]); } }; const var numbers = [64, 48]; const var ids = [-1, -1]; for(s in SlotSelectors) s.setControlCallback(onSlotSelectorControl);
-
@trillbilly Try
array.sort();
-
@d-healey Thanks. Does it go within the "rootlist" element? I've tried placing it where I suspected it would go but get the error "Unknown function 'sort'" whenever I try to compile.
-
@trillbilly
allList.sort()
probably. -
@d-healey ahhh, yes, I see now. I added this and it did nothing to effect the list. I also use
allList.sortNatural
which did work, but now it loads the samples out of order (kind of like when you move samplemaps around or add new samplemaps). -
@trillbilly said in Combobox List Alphabetically:
@d-healey ahhh, yes, I see now. I added this and it did nothing to effect the list. I also use
allList.sortNatural
which did work, but now it loads the samples out of order (kind of like when you move samplemaps around or add new samplemaps).-probably because you are not sorting allIds, try sorting e.getAudioFileList instead...
Guessing something like this(not at my machine):
var afl =[]; for(e in expansionList) { afl = e.getAudioFileList(); afl.sortNatural(); for(af in afl) { allList.push(af.split("}")[1]); allIds.push(af); } }
-
@Lindon Thanks, that seemed to do the trick! 2 samples are still out of order but they load the correct audiofile. Ill try deleting and exporting t hem again to see if they fall in place.
-
@trillbilly that may well be a naming issue - lower and upper case etc.
-
@Lindon I dont think its naming. Ive posted a pic of the names below. Its exactly as I named the audiofiles. I just got into the studio and will try the delete method to see if it works.
-
-
@d-healey @Lindon When I add new samples to AudioFiles, they are also at the bottom of the list now, even after recompiling. Here is the new code with @d-healey advice and script. Can you see what Ive done wrong?
const var SlotSelectors = [Content.getComponent("SampleSelection1"), Content.getComponent("SampleSelection2"), Content.getComponent("SampleSelection3"), Content.getComponent("SampleSelection4")]; const var AudioLoopPlayers = [Synth.getAudioSampleProcessor("LoopPlayer1"), Synth.getAudioSampleProcessor("LoopPlayer2"), Synth.getAudioSampleProcessor("LoopPlayer3"), Synth.getAudioSampleProcessor("LoopPlayer4"),]; const var expHandler = Engine.createExpansionHandler(); const var expansionList = expHandler.getExpansionList(); const var allList = []; const var allIds = []; const var rootList = Engine.loadAudioFilesIntoPool(); allList.push("No Sample Loaded"); allIds.push(""); for(r in rootList) { allList.push(r.split("}")[1]); allIds.push(r); } var afl =[]; for(e in expansionList) { afl = e.getAudioFileList(); afl.sortNatural(); for(af in afl) { allList.push(af.split("}")[1]); allIds.push(af); } } for(s in SlotSelectors) s.set("items", allList.join("\n")); inline function onSlotSelectorControl(component, value) { local index = SlotSelectors.indexOf(component); if(value != 0) { AudioLoopPlayers[index].setFile(allIds[value-1]); } }; const var numbers = [64, 48]; const var ids = [-1, -1]; for(s in SlotSelectors) s.setControlCallback(onSlotSelectorControl);
-
@trillbilly Why are you using
sortNatural
instead ofsort
? -
@d-healey I was just trying to see if it made any difference. They both do the same thing in this case. Sorts all previous audiofiles but new audiofiles list at the bottom and out of order.
-
@trillbilly What happens if you sort root list instead? I haven't looked through your code so there might be something obvious but I don't have time at the moment
-
@d-healey Youree right, it is part of my issue, I sorted the
allList.sort
instead ofrootList.sort
. This fixed the issue for the most part. Now my issue is.- I have a repeating sample, and they are not even one above the other. It only repeats one time.
example:
GTR A
GTR B
GTR A
GTR C
GTR D
so on...- If I add a new sample that has a name that would go before my current first sample (GTR A) then that sample doesnt show. Its almost like it replaces that sample with itself?
-
@trillbilly You could just put a number at beginning of each one and then you get the order you want.
-
@d-healey I could, but doesnt look as good from the user end. I was hoping to name them GTR Name, PAD Name, SYN Name, etc so they are easy to view in the dropdown combobox.
I will keep plucking away for the time being. Just strange behavior is all.
-
@trillbilly You don't have to display the numbers to the end user ;) They're just used for sorting. Look up
substring()
-
@d-healey Of course they are lol. I will check it out. Thanks.