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n70uLP3H4hmyaN+y4y2FhWhxjKPN6XFUbVHgMulSPZ4D5IXUMqf+Sn5H3K0cDjHdHJbvuko90Ejhx46DCs.vc93f6VB7e+3CvBrr0FcEAUYHIRPkBnwAj2B8Ilznik4Aj3KE7PncuYqf.M+ATzWmMkut8zYC9mesMZgxjS9Lw9XxjatL8uWM+LsQRldTZSdxWyTIZCyjMi+vZa82ok1qn9hQy79tosSNaLK9yaSEjwoMVasNBc6sR6YVcxadQ3kSI758KMut8qKkWZyKBubKgWsMVRdcKZ6x3UpYzG1rNbMAt+j.rn3cGjWXR6.1noPC6xlxYwTwz7Wn5+sKT7Po3iM6REdiJmiqTBGgWn+TvQ80vdj4gCFP7DYDbMyi9iOM24B8a7IBJa3IXQDEV7Xd5jw8fG0dDX1YvRJ4F8FqHWFlLtobrTA5QX9pA2BezNaIGanc1J0IZL1Kh+FujsRkWzaCkEfSL0cbsLOQN1d192llM2oIZLbmy234IK+mBmRTNFmk.i6Rf4YKAluaIv77k.y2uDXdQkXjW2+USD7wIuN.F5dn5jLCiCYXXkkZUH5+.d1P0C.
-
@ulrik You're making good use of that
getAllComponents
function again. I need to do that more. -
@d-healey yes it's handy, but it's easy to unintentionally collect wrong components if you're not certain of how you named the components
-
@ulrik brilliant, thank you!
so .getAllComponents will give me an array of all named components? Eg. Panel1, Panel2 etc ?
-
@ulrik Elegant!
@DanHContent.getAllComponents
returns all components whichs name matche the string you pass in the function.I.e.
Content.getAllComponents("pnl_")
will retreive all components which have "pnl_" in their name. Obvisouly you have to be consistent in the naming of your GUI elements but it's quite handy :) -
@Matt_SF said in 3 buttons, 3 panels, and lots of potential scripting...:
@ulrik Elegant!
@DanHContent.getAllComponents
returns all components whichs name matche the string you pass in the function.I.e.
Content.getAllComponents("pnl_")
will retreive all components which have "pnl_" in their name. Obvisouly you have to be consistent in the naming of your GUI elements but it's quite handy :)to be honest I prefer this naming approach;
Button_01
Button_02
Button_03
etc.and then load in a sequenced and ordered way into my array
const var NUM_VOICES = 4; //some number of voices const var myButtonArray = []; myButtonArray.reserve(NUM_VOICES) for(i=0;i<NUM_VOICES; i++) { myButtonArray[i] = Content.getComponent("Button_0" + (i+1)); myButtonArray[i].setControlCallback(onMyButtonControl); }
This gives me everyone in the array in the correct sequenced order....and lets assume these buttons are turning some filter on or off, I can also add the filter itself(again in the right order):
const var NUM_VOICES = 4; //some number of voices const var myButtonArray = []; myButtonArray.reserve(NUM_VOICES) const var myFilterArray = []; myFilterArray.reserve(NUM_VOICES) for(i=0;i<NUM_VOICES; i++) { myButtonArray[i] = Content.getComponent("Button_0" + (i+1)); myButtonArray[i].setControlCallback(onMyButtonControl); myFilterArray[i] = Synth.getEffect("Filter" + (i+1)); }
which means the callback for the button only needs to be this:
inline function onMyButtonControl(component, value) { local pos = myButtonArray.indexOf(component); myFilterArray[pos].setBypassed(1-value); }
always interested in a faster - cleaner- better way if someone has one...
-
@Lindon if your elements are numbered the function will sort them automatically. I usualy don't number them and I also liketo have control on my elements (like the script you wrote) but sometimes it can be useful to get all of typed elements quickly.
-
This post is deleted! -
I rarely put the full type of component in the component id, it seems redundant to call a button button.
I use a prefix to describe the type of component followed by a name that describes the button's function, if the button is part of a group of buttons I follow this with a number, almost always indexed from 0.
So I could have 10 buttons that toggle 10 panels, I might call them
btnToggle0
,btnToggle1
, etc.Then I could use either the loop technique or the
getAllComponents
technique to populate an array of references. I usually use the loop technique because most of the time I will also assign a LAF object and callback to the controls at the same time. From now on I think I'll be using thegetAllComponents
function when I only need a reference.The
getAll...
functions are also useful when you want to loop over a set of components/modules that you haven't stored references to already. For example if I had 5 filter effects and I wanted to change a parameter on all of them but I have no other need to keep references to them:for (x in Synth.getAllEffects("filter")) { // Do the thing }
The
getAll...
functions don't require additional allocation (as far as I know) so they are safe to use at runtime. By contrast you don't want to useContent.getComponent()
at runtime. -
@d-healey said in 3 buttons, 3 panels, and lots of potential scripting...:
The
getAll...
functions don't require additional allocation (as far as I know) so they are safe to use at runtime. By contrast you don't want to useContent.getComponent()
at runtime.Good to know