HISE Logo Forum
    • Categories
    • Register
    • Login

    addComponentBatch

    Scheduled Pinned Locked Moved Feature Requests
    7 Posts 4 Posters 622 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.
    • CyberGenC
      CyberGen
      last edited by CyberGen

      It would be neat to have addComponentBatch in the API.

      Something like:

      // Chat GPT assisted in writing these functions.
      
      // Batch in Sequence
      const knobs = Content.addKnobBatch(baseName, count, x, y, offsetX, offsetY);
      //Batch With name Array
      const buttons = Content.addButtonBatchWithNames(baseName, nameArray, x, y, offsetX, offsetY)
      

      This will help in creating and referencing components while simplifying scripts.

      You can, of course, create loop functions to do this. Below is an example that I also uploaded to the snippet browser.

      
      // Chat GPT assisted in writing these functions.
      
      Content.makeFrontInterface(600, 600);
      
      // Function to add a batch of knobs
      function addKnobBatch(baseName, count, x, y, offsetX, offsetY) 
      {
          for (var i = 0; i < count; i++) 
          {
              var knobName = baseName + i;
              var knob = Content.addKnob(knobName, x + i * offsetX, y + i * offsetY);
              knob.set("text", knobName);
          }
      }
      
      // Call the function to add 10 knobs with specified positions and offsets
      addKnobBatch("knob_", 10, 10, 10, 0, 50);
      
      // Function to add a batch of knobs using a base name and a name array
      function addKnobBatchWithNames(baseName, nameArray, x, y, offsetX, offsetY) 
      {
          for (var i = 0; i < nameArray.length; i++) 
          {
              var knobName = baseName + nameArray[i];
              var knob = Content.addKnob(knobName, x + i * offsetX, y + i * offsetY);
              knob.set("text", knobName);
          }
      }
      
      // Array of specific names to use
      var names = ["Volume", "Pan", "Reverb", "Chorus", "Delay", "Filter"];
      
      // Call the function to add knobs with the specified names
      addKnobBatchWithNames("knob_", names, 200, 10, 0, 50);
      
      d.healeyD 1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey @CyberGen
        last edited by d.healey

        @CyberGen Yeah use a loop, no need for a new function. Looks like chat gpt wrote your function 😉

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

        CyberGenC 1 Reply Last reply Reply Quote 0
        • CyberGenC
          CyberGen @d.healey
          last edited by

          @d-healey why not? There’s getAllComponents and we use that all the time. I’d much prefer to have one line of code rather than X. Yes, chat GPT helped with it. I suppose the var inside the for loop is a tell. I didn’t claim that I wrote it, But it works so I shared it. No need to shoot it down. I’ll make a note “chat gpt assisted” 😉

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

            No, this is exactly what a for-loop is made for and making this an API method does not make anything clearer, to the contrary:

            • What if you decide that you want to adapt the layouting logic to your needs (eg. make a automatic "line-wrap"). New function or change the signature of the API call breaking backwards compatibility?
            • What if you want a more generic function where you can put in the type of the control? New function or change the signature of the API call breaking backwards compatibility?
            • What if you want it to automatically set the parentComponent so you can put it in a Panel. New function or change the signature of the API call breaking backwards compatibility?
            OrvillainO CyberGenC 2 Replies Last reply Reply Quote 1
            • OrvillainO
              Orvillain @Christoph Hart
              last edited by

              I'm afraid I have to agree. This is not something that time or effort should be spent on. It wouldn't offer the customisation nor the modularity that good API's require.

              1 Reply Last reply Reply Quote 0
              • CyberGenC
                CyberGen @Christoph Hart
                last edited by

                @Christoph-Hart ok. Thanks for the detailed explanation. My thinking was very basic. To use it in much the same way we use getAllComponents by referencing the array that it creates. I was definitely not thinking of backwards compatibility.

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

                  no worries. getAllComponents() has a single parameter with a clear purpose, so it's not comparable to the function you suggested though.

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

                  29

                  Online

                  1.8k

                  Users

                  12.1k

                  Topics

                  104.9k

                  Posts