HISE Logo Forum
    • Categories
    • Register
    • Login

    How to programatically access script attributes?

    Scheduled Pinned Locked Moved Scripting
    scriptattributeloop
    10 Posts 3 Posters 1.0k 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.
    • d.healeyD
      d.healey
      last edited by

      I have a script with 3 knobs. knb1, knb2, knb3. I would like to access these controls from another script in order to set their values. I know I can access them by index, but let's say I don't know the index I just know the name. How could I set the correct control to the correct value?

      Here are somethings I tried that didn't work.

      script.setAttribute("script." + knb1, 50);
      script.setAttribute(exec("script." + knb1), 50);
      script.setAttribute(script["knb1"], 50);

      This is a simplified example of my project. The reason I'd like to do it this way is because I want to set the attributes of several scripts within a loop and I may not always want to set all of the scripts attributes, only some of them, so I can't just iterate through all of the indexes I need to use the attribute's name.

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

      ustkU 1 Reply Last reply Reply Quote 0
      • ustkU
        ustk @d.healey
        last edited by ustk

        @d-healey What if you declare them as global?
        So you could directly access by name:
        script.setAttribute(knb1, 50);

        HiseSnippet 828.3oc0V0saSCCE1tqFncrIlfGfncUmznJcrMPBMst0ePUisUQFSb2jahaq0RrqRbFTg3MjGBdD3M.NNIsIsKZqqBDhdUO+5uy474bbWeoMKHP5ivktX7HFB+Th0XgZXigTt.0oIBuN4TZfh4aDq53winAALGDFux6zJvkJhh98yCOl5RE1rTUHzkRtM68bOtJUa25mvccaScXWv8x38t06XKEMjtxP.OqPLQin1WSGvNipcq.AgeTKGtR5aonJV.BW7XoyXqgxOKh8+Rd.umKSKTCYAIJVcaoqiFwZsnFC4tNcmT2AHHKcS6BqD2EdA4TtCep9ztwyhLXjFQ19AtvcAuZ2O7LyCdEx.uhwvaChksOejJ0hFaqR5HfAUeJLBxBqXeQEN.SZHAODppdzqYs8AgoQTYeSysM1yzbq2tV40JCCh.kwMTei4NoZFGXDwPpNfoloIUYyXWSaN01LNYymhpAL0QJkOuWnhU4DgrWssMLqtm169gBaEWJLjhyjJ14hJaU9qkKU9akMl2T+94ZSWi9RWWletl0bN+6JvJhPudL+sgp2MjM0Qn4O6zc0Ea5ZG2xy3nTzQvUmOhkHmkdNopmX0DMsXypJsFypMpzxwsTU2ldgRnDv+9XmlTEEXb3DcfeiX9JttZwMY2.Wki4ekHMYAWqjifKyKH474jawNxijh+NYfqrG00HhV.jsITVft0P5MRJ.gJaFYMgd8+Cko7eJJy+PZBtPh6fqpnA95IiVKWtCyGwg44iIQCHTT+H8K7+3PzBG7NyG7RxP03Mg1.yi6EweI8.spOdlS+Ajmcxjm5tykmaekA1pHcBcopYW0n2ulX.naybcQ+caQ.WMN692Gv9GyEd83hB2MHc4J6g4i2B4fWMU5uLdS1luFoU+9LaUJXKRZ+okc08C.JePFp3hAmRgcc.gfbVnmE73FaFfDgf4BGDAWPSshkM0xQTOlvIR3WvuDi0zx3Di0lXD4Qs8kWYGesR+dgmDoAvjH5YSkf2uAxFSuLRHlUMQdvp6qrs0shWBXO+X1YIh4UKQL6tDwr2RDy9KQLudIh4M2YL5WMcTnR5EeMATzsUz20v3VBJvxhXjneCZqfhX
        

        Hise made me an F5 dude, browser just suffers...

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

          I never thought of that. For my particular project I don't think it's the best solution because I have a lot of scripts and I don't want to pollute the global namespace with all of the controls, but for a smaller project it's definitely a good option. I think I need a new function, something like getAttributeId(). I'm looking at the HISE source now to see if I can figure out how to add it.

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

          ustkU 1 Reply Last reply Reply Quote 1
          • ustkU
            ustk @d.healey
            last edited by

            @d-healey maybe you can just declare an array per script as global for the moment with const var inside... not sure it works though...
            I also tried with a get("id") like solution but it doesn't work so effectively, having an API for this seems a good solution ;)

            Hise made me an F5 dude, browser just suffers...

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

              I found a solution!

              I added a getAttributeId function to HISE :p

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

              ustkU 1 Reply Last reply Reply Quote 2
              • ustkU
                ustk @d.healey
                last edited by

                @d-healey oh your a boss my man! 😮 😎

                Hise made me an F5 dude, browser just suffers...

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

                  Here's a little snippet to quickly make an organised object containing every attribute ID for every script, indexed by the script's ID.

                      //Get MidiProcessors
                      const var processorIds = Synth.getIdList("Script Processor");
                      const var scriptProcessors = [];
                      for (id in processorIds)
                          scriptProcessors.push(Synth.getMidiProcessor(id));    
                  
                      //Get processor addtribute Ids
                      const var processorAttributes = {};
                      
                      for (s in scriptProcessors) //Each processor
                      {
                          processorAttributes[s.getId()] = []; //Create array to store attribute IDs
                  
                          for (i = 0; i < s.getNumAttributes(); i++) //Each attribute
                              processorAttributes[s.getId()].push(s.getAttributeId(i));
                      }
                  

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

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

                    I found this getAttributeId function so useful that I've added one for every scripting element that has a getAttribute function. :)

                    https://github.com/davidhealey/HISE/tree/develop

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

                    ustkU Casey KolbC 2 Replies Last reply Reply Quote 5
                    • ustkU
                      ustk @d.healey
                      last edited by

                      @d-healey You rock 😎
                      Now we have a new dev, there will be no time between Hise 3 and Hise 4... 🤣

                      Hise made me an F5 dude, browser just suffers...

                      1 Reply Last reply Reply Quote 5
                      • Casey KolbC
                        Casey Kolb @d.healey
                        last edited by

                        @d-healey Wow, this is a game changer for big projects. Super helpful!

                        Casey Kolb
                        Founder & CEO of Lunacy Audio
                        Composer | Producer | Software Developer

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

                        18

                        Online

                        2.0k

                        Users

                        12.6k

                        Topics

                        109.7k

                        Posts