HISE Logo Forum
    • Categories
    • Register
    • Login

    Query multiple TOKENS? || Please advise!

    Scheduled Pinned Locked Moved Unsolved Scripting
    11 Posts 4 Posters 61 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.
    • ChazroxC
      Chazrox
      last edited by

      I have a search function finding all files with this token. "kick".

      What I'd like to do is enter multiple tokens, for instance, if it may be "KICK", "Kick", "kick", "kick", "Bass Drum", "bassdrum" etc....

      Please advise! 🙏

      Screenshot 2025-10-30 at 7.17.12 PM.png

      Oli UllmannO 1 Reply Last reply Reply Quote 0
      • Oli UllmannO
        Oli Ullmann @Chazrox
        last edited by

        @Chazrox
        If you have the same word with different spellings(KICK, Kick...), you could adjust the letters before searching. So, all letters lowercase (String.toLowerCase()) or all letters uppercase (String.toUpperCase()).

        This makes the original spelling irrelevant, and you only have to worry about one case.

        ChazroxC 1 Reply Last reply Reply Quote 1
        • ChazroxC
          Chazrox @Oli Ullmann
          last edited by Chazrox

          @Oli-Ullmann Thanks. What if I want the user to be able to type "kick" but the search results return any variations of the spelling? How do I check for multiple tokens at once? I dont know how I would do that. I can check for one spelling but multiple at once, I havent done that one yet.

          What im workin with now:

              local token1 = "kick";
              
              //local token1 = ["KICK", "Kick", "kick", "kck", "BASS DRUM", "Bass Drum", "bass drum"];
              
              
              if (token1 == "")
              {
          	
          
                  Console.print("No token1 entered.");
                  return;
              }
          
              local txt;
          
              Console.print("Searching in: " + rootFolder.toString(1));
              Console.print("Total files to check: " + allFiles.length);
          	ComboBox1.set("items", "");
          
              for (i = 0; i < allFiles.length; i++)
              {
                  local f = allFiles[i];
          
                  local pathNOW = f.toString(0);
          
                  if (pathNOW.indexOf(token1) != -1)
                  {
                      FoundFiles.push(f);
                      Console.print("MATCH (name/path): " + pathNOW);
                  }
              }
          
          Oli UllmannO 1 Reply Last reply Reply Quote 0
          • Oli UllmannO
            Oli Ullmann @Chazrox
            last edited by Oli Ullmann

            @Chazrox said in Query multiple TOKENS? || Please advise!:

            What if I want the user to be able to type "kick" but the search results return any variations of the spelling?

            I'm not sure what you mean.

            As I said, you can convert the word, e.g., Kick, to lowercase letters only before searching using String.toLowerCase(). Then you only need to search for “kick” and all variants (KICK, Kick, KiCk, etc.) will still be displayed.

            If you want to see all results that contain “kick” (e.g., kick drum), you can use String.contains(). Then all results should be displayed.

            You can also use the functions several times in a row. So

            if(yourVariableName.toLowerCase().contains(“kick”) || yourVariableName.toLowerCase().contains(“drum”))
            

            should give you all results that contain ‘kick’ or “drum.” The original spelling doesn't matter, because you convert all letters to lowercase before searching.

            ChazroxC 2 Replies Last reply Reply Quote 1
            • ChazroxC
              Chazrox @Oli Ullmann
              last edited by

              @Oli-Ullmann ahh, I think the || is what I was looking for. I forgot about that. Thanks! I'll try these. 🙏

              1 Reply Last reply Reply Quote 0
              • ChazroxC
                Chazrox @Oli Ullmann
                last edited by

                @Oli-Ullmann

                Thanks.

                Ended up doing this. Works:

                        if (pathNOW.contains("KICK") || pathNOW.contains("Kick") || pathNOW.contains("kick"))
                        {
                            FoundFiles.push(f);
                            Console.print("MATCH (name/path): " + pathNOW);
                        }
                

                🙏

                Oli UllmannO d.healeyD 2 Replies Last reply Reply Quote 0
                • Oli UllmannO
                  Oli Ullmann @Chazrox
                  last edited by

                  @Chazrox

                  This should also work, no?

                          if (pathNOW.toLowerCase().contains(“kick”))
                          {
                              FoundFiles.push(f);
                              Console.print("MATCH (name/path): " + pathNOW);
                          }
                  
                  
                  ChazroxC 1 Reply Last reply Reply Quote 0
                  • ChazroxC
                    Chazrox @Oli Ullmann
                    last edited by

                    @Oli-Ullmann I think I was not understanding how that works but it just clicked. Yes that should work. *forehead slap. lol. Thanks!

                    Oli UllmannO 1 Reply Last reply Reply Quote 1
                    • Oli UllmannO
                      Oli Ullmann @Chazrox
                      last edited by

                      @Chazrox
                      he he :-)
                      No problem! :-)

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

                        @Chazrox said in Query multiple TOKENS? || Please advise!:

                        Ended up doing this. Works:

                        Use regex. https://docs.hise.dev/scripting/scripting-api/engine/index.html#matchesregex

                        Free HISE Bootcamp Full Course for beginners.
                        YouTube Channel - Public HISE tutorials
                        My Patreon - HISE tutorials

                        1 Reply Last reply Reply Quote 0
                        • dannytaurusD
                          dannytaurus
                          last edited by dannytaurus

                          Yeah, regex is your friend here. The HISE regex seems to be missing a lot of features but you can still condense it down a bit like this:

                          const kickPattern = "kick|kck|kk|bd|bassdrum|bass\sdrum|bassd";
                          const snarePattern = "snare|snar|snr|sn";
                          const hatPattern = "hat|hh|clh|cl|oph|op";
                          
                          inline function stringMatchesPattern(str, pattern) {
                          	return Engine.matchesRegex(str.toLowerCase(), pattern);
                          }
                          
                          Console.print(stringMatchesPattern("Kick".toLowerCase(), kickPattern));
                          Console.print(stringMatchesPattern("Kck".toLowerCase(), kickPattern));
                          Console.print(stringMatchesPattern("Kk".toLowerCase(), kickPattern));
                          Console.print(stringMatchesPattern("kick".toLowerCase(), kickPattern));
                          Console.print(stringMatchesPattern("kk".toLowerCase(), kickPattern));
                          Console.print(stringMatchesPattern("BD".toLowerCase(), kickPattern));
                          Console.print(stringMatchesPattern("Bd".toLowerCase(), kickPattern));
                          Console.print(stringMatchesPattern("bd".toLowerCase(), kickPattern));
                          Console.print(stringMatchesPattern("BassDrum".toLowerCase(), kickPattern));
                          Console.print(stringMatchesPattern("Kick".toLowerCase(), kickPattern));
                          Console.print(stringMatchesPattern("Kick".toLowerCase(), kickPattern));
                          Console.print(stringMatchesPattern("Snare".toLowerCase(), snarePattern));
                          Console.print(stringMatchesPattern("Snr".toLowerCase(), snarePattern));
                          Console.print(stringMatchesPattern("Hat".toLowerCase(), hatPattern));
                          Console.print(stringMatchesPattern("Clh".toLowerCase(), hatPattern));
                          

                          If some of the usual regex tools worked, we could have shorter patterns like this:

                          const kickPattern = "ki?c?k|b(ass)?\s?d(rum)?"
                          

                          Although the longer one might be easier to read and understand I guess.

                          Meat Beats: https://meatbeats.com
                          Klippr Video: https://klippr.video

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

                          19

                          Online

                          2.0k

                          Users

                          12.8k

                          Topics

                          110.8k

                          Posts