HISE Logo Forum
    • Categories
    • Register
    • Login

    Filter/display sampleMap names by _prefix

    Scheduled Pinned Locked Moved Scripting
    24 Posts 4 Posters 1.5k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ustkU
      ustk
      last edited by ustk

      @ten7kur You can either use String.replace(var substringToLookFor, var replacement) or String.substring(int startIndex, int endIndex) since the samplemap list is an array of strings

      Can't help pressing F5 in the forum...

      ten7kurT 1 Reply Last reply Reply Quote 0
      • ten7kurT
        ten7kur @ustk
        last edited by ten7kur

        @ustk said in Filter/display sampleMap names by _prefix:

        @ten7kur You can either use String.replace(var substringToLookFor, var replacement) or String.substring(int startIndex, int endIndex) since the samplemap list is an array of strings

        So?....

        sampleMapList.replace(sampleMapList "BD_", sampleMapList " ");
        SamplemapList.set("items", sampleMapList.join("\n"));
        

        Im puzzled on the 'var's

        1 Reply Last reply Reply Quote 0
        • ustkU
          ustk
          last edited by

          @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

          Can't help pressing F5 in the forum...

          ten7kurT 1 Reply Last reply Reply Quote 0
          • ten7kurT
            ten7kur @ustk
            last edited by

            @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?

            1 Reply Last reply Reply Quote 0
            • ustkU
              ustk
              last edited by

              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

              Can't help pressing F5 in the forum...

              1 Reply Last reply Reply Quote 0
              • ustkU
                ustk
                last edited by

                @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"));
                

                Can't help pressing F5 in the forum...

                ten7kurT 1 Reply Last reply Reply Quote 0
                • ten7kurT
                  ten7kur @ustk
                  last edited by

                  @ustk
                  hmm...doesnt seem to work....
                  Although I can see/partly-understand the logic

                  1 Reply Last reply Reply Quote 0
                  • d.healeyD
                    d.healey
                    last edited by

                    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? and SamplemapList - why does it start with a capital when your other variable names don't?

                    Libre Wave - Freedom respecting instruments and effects
                    My Patreon - HISE tutorials
                    YouTube Channel - Public HISE tutorials

                    ten7kurT 1 Reply Last reply Reply Quote 0
                    • ten7kurT
                      ten7kur @d.healey
                      last edited by ten7kur

                      @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_

                      ten7kurT 1 Reply Last reply Reply Quote 0
                      • ten7kurT
                        ten7kur @ten7kur
                        last edited by ten7kur

                        @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.

                        ustkU 1 Reply Last reply Reply Quote 0
                        • ustkU
                          ustk @ten7kur
                          last edited by

                          @ten7kur Strange, it effectively removes the "BD_" part here...
                          I am not sure it's a good idea to make subfolders for the samplemaps...

                          Can't help pressing F5 in the forum...

                          ten7kurT 1 Reply Last reply Reply Quote 0
                          • ten7kurT
                            ten7kur @ustk
                            last edited by ten7kur

                            @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

                            1 Reply Last reply Reply Quote 0
                            • ustkU
                              ustk
                              last edited by ustk

                              @ten7kur there are two ways:

                              • Replace newName = newName.replace("BD_", ""); with newName = 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

                              Can't help pressing F5 in the forum...

                              ten7kurT 1 Reply Last reply Reply Quote 1
                              • ten7kurT
                                ten7kur @ustk
                                last edited by

                                @ustk
                                👍 👍 👍
                                Wouldn't have figured it out my self! Not with my current Javascript knowhow...

                                ten7kurT 1 Reply Last reply Reply Quote 0
                                • ten7kurT
                                  ten7kur @ten7kur
                                  last edited by

                                  @ten7kur

                                  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);
                                  
                                  ten7kurT 1 Reply Last reply Reply Quote 0
                                  • ten7kurT
                                    ten7kur @ten7kur
                                    last edited by

                                    @ten7kur

                                    How could I also hide specific sample maps. So only show "BD_", or only "SD_".
                                    How would I 'categorize' them?

                                    1 Reply Last reply Reply Quote 0
                                    • ustkU
                                      ustk
                                      last edited by

                                      @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

                                      Can't help pressing F5 in the forum...

                                      ten7kurT 1 Reply Last reply Reply Quote 0
                                      • ten7kurT
                                        ten7kur @ustk
                                        last edited by ten7kur

                                        @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!!🤞😀

                                        1 Reply Last reply Reply Quote 0
                                        • Christoph HartC
                                          Christoph Hart
                                          last edited by

                                          The String.split method is the missing piece:

                                          
                                          const var names = ["SN_One", "BD_One", "BD_Two", "SN_Two"];
                                          
                                          // this will hold the samplenames sorted by category
                                          var obj = {};
                                          
                                          for(n in names)
                                          {
                                              // This splits the string into a list using the given separator
                                              var sp = n.split("_");
                                          
                                              var category = sp[0];
                                              var sampleName = sp[1];
                                          
                                              // We can check if the category is already used
                                              if(isDefined(obj[category]))
                                                  obj[category].push(sampleName); // append to the existing list
                                              else
                                                  obj[category] = [sampleName]; // create a new list at the key
                                          }
                                          
                                          ten7kurT 1 Reply Last reply Reply Quote 1
                                          • ten7kurT
                                            ten7kur @Christoph Hart
                                            last edited by ten7kur

                                            @Christoph-Hart
                                            Thanks for your input. Really appreciate it!
                                            The code is working, but only partly. I don't quite understand what exactly is happening.

                                            At the moment the viewport only is displaying BD and second item xx1. [BD_xx1 was the last item in ''var names'' that I added before pressing compile].

                                            It seems like its listing the category. But I can't see the other categories.... Im somewhat confused...

                                            Im trying to show the categories in a different Viewport to pick from so I could see the sampleMaps[hopefully] but can't quite get it right to display. The category viewport shows items but the items all have the 'undefined' text.

                                            Full code:

                                            Content.makeFrontInterface(600, 500);
                                            
                                            //! =================== [ Samplemap List ] ================== !
                                            const var SamplemapList = Content.getComponent("SamplemapList");
                                            
                                            // Allow the viewport to list the items
                                            SamplemapList.set("useList", true);
                                            
                                            const var Sampler = Synth.getSampler("Sampler");
                                            const var sampleMapList = Sampler.getSampleMapList();
                                            
                                            const var names = ["SD_one", "SD_two", "SD_oi", "BD_one", "BD_Three", "BD_Four", "BDs_one", "BD_xx", "BD_xx1"];//, "SN_Two", "SN_Three", "HH_oneone"];
                                            
                                            // this will hold the samplenames sorted by category
                                            var obj = {};
                                            
                                            for(n in names)
                                            {
                                                // This splits the string into a list using the given separator
                                                var sp = n.split("_");
                                            
                                                var DRUM_category = sp[0];
                                                var DRUM_sampleName = sp[1];
                                            
                                                // We can check if the category is already used
                                                if(isDefined(obj[DRUM_category]))
                                                    obj[DRUM_category].push(sampleName); // append to the existing list
                                                else
                                                    obj[DRUM_category] = [sampleName]; // create a new list at the key
                                            }
                                            // Update the viewport
                                            SamplemapList.set("items", sp.join("\n"));
                                            
                                            // Load samplemap
                                            inline function onViewportControl(component, value)
                                            {
                                                Sampler.loadSampleMap(sampleMapList[value]);	
                                            };
                                            SamplemapList.setControlCallback(onViewportControl);
                                            //! =================== [ /Samplemap List ] ================== !
                                            
                                            
                                            const var cats = Content.getComponent("cats");
                                            // Allow the viewport to list the items
                                            cats.set("useList", true);
                                            // We can check if the category is already used
                                                if( (obj[DRUM_category]));
                                            
                                            // Update the viewport
                                            cats.set("items", obj[DRUM_category].join("\n"));
                                            
                                            HiseSnippet 3220.3oc6Zr1aaibjzNL2IcQWyc3.Z+RA1HTfHi5yVRNw2iff5XYmytW7CXojqstFtqEWIwKjbIHo7iKH.4GR6+g6mP+sb+B526GZmYWtbIodXEm3qosQAHl6r6L6ryL67hb+PdWVTDOzvrTmKBXFl2xp8E9wCZMf53ar8FFl+Bq1Tu.W1Nzfm3DEar9EAznHlsgo47eCtHyR2vP76e76Vm5R86xzfLLdF2oK6INdNwZn6u125359XpMqiiWlUeu01tK2uE2kODXn4spaDP69bZe1t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KnSiffGH+fYZbcxhdztg7i6JS.BYzOT.AVou3EPVxZGbLogJ0GKjKM7.WaG2saNpLBNMuB3rxU.m6cEv49WAbV8JfyWbEv4KmJNXTkGMLl6IcQ..1eyjLQ2TaUUOMAWvZOfEFiuPbSyMXmBIdHuUUB7oG87Xdf309mTwig4G8Z8h+OO8k1SBV6hreyjwrywugRq8EsfOx3LG63AoK3u3s1.F95FRg7imtVf6v9N96SCAwQLKb2DohhBhBn.KTq02n74m2vHorKPNYZBDf55z22SbFtokKqWLJBROVe3r7YHj4zPyeZJrW4OLu5OU7vXb7ZIb6JVPcCxNCUdFeJGeeyY5yeXBL9qdzZIbpk4.XrhKsL+kFuUx2vb9L9Z0eXsWKeXouMBiZN2X3W7CD4Zlem0XvWSeStuYUVck+voCl4Ob5bERoV1eesrkPof9iqkq3I8dMl5lTS9gqUnnI8QoPES5IRKWReFGoVI8TpBkzPzUIogkqDIomjQJRRu52opP51fW2i+VGHu3s3mYeQyQ9.09fY6CTCH29TP.jYkq6zOcqjPzVyYJPUvXY934Mt1pO6mgagWu9ame1XWiqoBBMmOa4fYuRjVKnl2G6ARUEnBxmsVZIfJP+l0xV92URVzX1kEugUL9ecwIm++6iSdkp08cQ87DJT9mUVcFJg0xbNLDaZQrVXzQUYrVl+K3mtNVYryjJYkSNKUaaNWRs1ZS5WyBsei4x2Wv8+KVvs47F+a4jjGWA
                                            

                                            Thanks for any/all help!!

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            46

                                            Online

                                            1.7k

                                            Users

                                            11.7k

                                            Topics

                                            102.1k

                                            Posts