addComponentBatch
-
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);
-
@CyberGen Yeah use a loop, no need for a new function. Looks like chat gpt wrote your function
-
@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”
-
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?
-
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.
-
@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.
-
no worries. getAllComponents() has a single parameter with a clear purpose, so it's not comparable to the function you suggested though.