Slimming down a script(for best efficiency)



  • Hi all,

    Im looking to slim down my current script(for better performace!) and better readability!
    The script controls the 'SimpleGain' module.
    If anyone could give some suggestions as to how i could make it more efficient, id really appreciate it!

    As it stands, this is the script::

    Content.makeFrontInterface(560, 500);
    
    var SMP_INDEX;
    
    // Module Wrappers 
    const var SimpleGain_SMP0 = Synth.getEffect("Simple Gain_SMP0");
    const var SimpleGain_SMP1 = Synth.getEffect("Simple Gain_SMP1");
    
    
    //--------------------- SMP Select buttons ----------------------
    var valGain;
    var valPan;
    //SMP 0 button
    inline function onSMP0Control(component, value)
    {
            SMP_INDEX = 0;//Sampler
            
            //Get Volume value
            valGain = (SimpleGain_SMP0.getAttribute(0));
            Content.getComponent("SMP_Gain").setValue(valGain);
            //Get Pan value
            valPan = (SimpleGain_SMP0.getAttribute(3));
            Content.getComponent("SMP_Pan").setValue(valPan);
               
    };
    Content.getComponent("SMP0").setControlCallback(onSMP0Control);
    
    //SMP 1 button
    inline function onSMP1Control(component, value)
    {
            SMP_INDEX = 1;//Sampler
            
            //Get Volume value
            valGain = (SimpleGain_SMP1.getAttribute(0));
            Content.getComponent("SMP_Gain").setValue(valGain);
            //Get Pan value
            valPan = (SimpleGain_SMP1.getAttribute(3));
            Content.getComponent("SMP_Pan").setValue(valPan);
          
    };
    Content.getComponent("SMP1").setControlCallback(onSMP1Control);
    
    
    //--------------------- SMP Module Controls ----------------------
    //Gain
    inline function onSMP_GainControl(component, value)
    {
        if (SMP_INDEX == 0)//Sampler 0
            {
    	    SimpleGain_SMP0.setAttribute(0, (value)); //Gain SMP0
            }
        if (SMP_INDEX == 1)//Sampler 1
            { 
    	    SimpleGain_SMP1.setAttribute(0, (value)); //Gain SMP1
            }    
    };
    Content.getComponent("SMP_Gain").setControlCallback(onSMP_GainControl);
    
    //Pan
    inline function onSMP_PanControl(component, value)
    {
    	if (SMP_INDEX == 0)//Sampler 0
            {   
    	    SimpleGain_SMP0.setAttribute(3, (value)); //Pan SMP0
            }  
        if (SMP_INDEX == 1)//Sampler 1
            {   
    	    SimpleGain_SMP1.setAttribute(3, (value)); //Pan SMP1
            }
    };
    Content.getComponent("SMP_Pan").setControlCallback(onSMP_PanControl);
    
    HiseSnippet 1934.3oc6Z0saSjCEdllN.IPQ.hK1aVoQU8hDo9SlVJrRUqHzzeT.RIJoTXuYKtSbRrXx3HONE5hpDuH66v9Fr8QYeD3MX2i8LSFOSSRmVnrEH4p5i843O+cN19bbmZLpM1yixzzyt6Q8vZ52xnwQt7Nk6fHtZU1PS+5FUq75Mqqs9Q8Pdd3lZ55Y1Vzod1o0j+9ziWG4fbswQhzz1iRrwOmzkvijVqzyHNNagZh2kzUYzOnTEapaYpCsO.jLFE05greKpMdGjXXSYnoesMaR3TVCNhi8zzmdcZyiZzg9NW+wuGwibfCVzvRqAXHewaQcZJPrPpV4NDml0BWvdZZ5F0hV9Y7W922nJoIYf7HZ3NxNLizPkOzmZbvyREdESO7zUf2z9v6tFMrYjd7ndDX6lFUb4XVKD3BTgk+X0l5OyZTlBivkuXWzawawfFCzH+pOr37lqVrXg0lI2L4NDwLaTs19U1YiMesTxRKYVk1ruC17ULTudXlm4L4.+kG2TNXR2dNXQDw9fdEM+USY.zhsw7Ma0BayyOq+PLGLlYKr1HMfUJLf0r9XUfsEF1OwJvrA1AT17f9bNLWlCcfK3ufOD4Hr8ZCZUCIZrzRB6TblbDWGhK1rUeWaNg5ZRcEKCAmxnN4soc6QcA1cdgp8wElI2GlImYvuAjIrvJtFXRjXsvhFPzeszRai4l6Qc52E6apn9BfHXj7IXbAQ8DNmQfUJNewBBtITqP2NLjxgnDnS.RB0msvhdX9dhIJef8UU1GN.ULDrHjdVPYkTBEvVIPBHQUUIIcLHXj1nnuAB7HkQNNG.mfjOlepPPzrvmZMBep042mZcI3Sst53SstT7omg6zZLtSqXtyweDPv4VAZL5y..VAVtiHlPRqmcbAoEPcQwEvl8BCBLDmgDxYvvyJigRr0wKlGedy791uvZl9nSrfTLywiXVsTlUKkY0bnSqUplVE6b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OTZ76pqRco85PcI1w2Q.Q3saiYpXenKHnjUXCoRELkpicvHOrZhmOGxQ.whuQ+bwEVomKFm+5mL7gqo3PNyuOtiLy2Q2QdNRVSenInN3YwBB8S9OMZLWUNWoMvNnXj3q7qWJTvuU5TWlNWoJvtJFuF0AwR5Bx7kJ7d5TGmHer0uYhqEGMAT92R.VFR7sCfuinf9q.vsNsOGRZKLwICH6pFPFk1X0brlRj2le6hguDWCraSYi+E9EzoUXBYhNsB6LsTxsM7ymwDVgL9Ub+2sLjY5YJRL+6Yemcnof0VveKeET8LXWQxjxhAcfzzcTOg0Cp4P.IHg2yYMSVSpYZRMSSpYZRMSorlokmTyzjZl9wrloQdUo7+v5Enlo6exjZllTyzjZllTyzjZl9+slouFn7qwbzEYyn6aG7AZB7wMjR.lvU9s+m0npns4fuVGwW1RQw24.Yeaaw0uK.dwgqyxW.cV4BnyCt.5r5EPmGdAz4QW.c9kwpin3jmzmS65eBKHn1l9Au5aNH3Mi1+A.oJVYK
    

    Based on which button(Sampler) is selected(SMP0,SMP1), the Slider controls the given Module's value/parameter.
    Works as is.. but id like to make it more streamline/efficient.

    Im still very much @-noob stage in terms of Hise/JS.. so im kinda in a vaccum of my own thoughts

    Im thinking Object, variable, varIndex. But im struggling as to how to how to go about it...

    If you have a minute, id love a suggestion!!

    Thanks very much!!



  • var valGain;
    var valPan;
    //SMP 0 button
    inline function onSMP0Control(component, value)
    {
            SMP_INDEX = 0;//Sampler
            
            //Get Volume value
            valGain = (SimpleGain_SMP0.getAttribute(0));
            Content.getComponent("SMP_Gain").setValue(valGain);
            //Get Pan value
            valPan = (SimpleGain_SMP0.getAttribute(3));
            Content.getComponent("SMP_Pan").setValue(valPan);
               
    };
    

    You don't need valGain or valPan, you can just refer to these attributes directly with SimpleGain_SMP0.Gain and SimpleGain_SMP0.Balance.

    //Gain
    inline function onSMP_GainControl(component, value)
    {
        if (SMP_INDEX == 0)//Sampler 0
            {
    	    SimpleGain_SMP0.setAttribute(0, (value)); //Gain SMP0
            }
        if (SMP_INDEX == 1)//Sampler 1
            { 
    	    SimpleGain_SMP1.setAttribute(0, (value)); //Gain SMP1
            }    
    };
    Content.getComponent("SMP_Gain").setControlCallback(onSMP_GainControl);
    

    Here you should do the same thing so you are not using the magic number 0 you should use SimpleGain_SMP0.Gain and SimpleGain_SMP1.Gain. Same goes for the pan parameter.

    You could reduce the lines of code if you put the simple gain effects into an array instead of two separate variables. It won't make it more efficient though, it will just use less lines of code.



  • @ten7kur This is how I would approach it:

    HiseSnippet 1958.3oc6Z0saSbDEd23rzXWREk1K5MUZZTuvVklZyesRoHVxOPSIFrrSApPTX7tyZOhcmwZ2woIEEoJ0mBtiGgdauiGo9FzdlY206rK1NlPfBT6bimeNy467cNyLmyD2Jj6Phh3gFlk28fADCySa04.ln+F8wTlw1aZX9AVM29da01X8CFfihHtFllktgbPyxKZn972WccrOl4Px5xv3NbpCYGZ.Uj0aK6aR88uN1krKMPa1WzdaGNaCtOeH.jRV0MFfcdLtG4VX4zVvxv7Ta4RE7vNBrfDYXt35b2C5zm+qr34eGZDsqOQ1ngQGXgh695beWIhk8ZrQepuaqTCNxvvzpUl4WJ17+TqlTW5n9yngynF.kIgNeXtvzfWCc3Ue1gmoF7VLFderUGmP5.Q1HRr8gVayDjPOL3BzgU7bMVX2kr1fCyfIVM.+Xx0CgFijn5ktb8ygtT850Va4Jx+9luAI8unlb2g9jnkq.9lHAZObHpSv.4PIiftB59pfkU6QDa44QbDUWoCMXfOQsBOrSyV0Wo14VtBZJeNpUnwJ0dvZSeITXd8gBA.zBvsCwGVz0ELEZSYAPaavCFvYPCPgy.LmnjGM7Tn6lLd27XqYqGpn4qL40VMgUj9k7x0BOcwfwWIya9EnNXIiBxpHCJmsbEJymxHHugLUGHNKGYIW6PteUmzE9bfx8GRpsbkmDarTOT03tdRl0m8MvjuaepSeTThtoQnH0xSbylkzfnt6CFSNsuJk4R1+1dYpu1ZSPIcHBjnOA83X9srJhJg4VMhHtiDhUyG2dePkOPRaW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GILJee2ZX.32YLhuLaXSYpi+TDQ5moNMwPd16qOakVpuKV4qWvJtciBsOeg1WnP6KVn8kJz9xEZ+sYsiIzl3AxnB4SrVHc9klsz4gE.R.f3qcT55zdiV73oqeJ5HZVAEMwRpDNRqq4m3NwSbKMav8HdV4xoXL9QW2hsGrSE5QhwyBon5gG5KR6M+M1M4L9f9bF0I+9BHNuWORnN1GqAAUdBaKy54SsaS7I3HhdZn6.YJfCyuc+khKZL6bwz7WelULbQxi5PuebSYo20to7jwMmkZpJj+Fop+rVE+WWLoKIelrl9MI93bD2cyWwzOa+BWidF6sgcRghVbebXQZuzIkst3LGaj8e44cgXY4wQ.k+tDfUgDu6.3yHKk+s.31lOTlHPZJSVPdUcfbIcH5YWsfLis310SemtNDlqpw+.eRFrQZpXxAajN3rRIejUblLHvBCEuk6+NskJGOjLk72m8cNoKEXaIeW89nlkHLYNkpx.8gDz80OgMBp1PBIHU2WxpkZLuZo4UKMuZo4UK8RUsz4mWsz7pk9+S0RS7RRzEtvmXeLpVx34yqVZd0RyqVZd0RyqV5+1pkdSfx2D5H.6DxenS7uEGIerjpGfIXpem4ksZJaix90+XUe05xeaCzG53Hux8qAu33k47GCYtvwPlKdLj4RGCYt7wPlu8XHy2MUYjEjbsgBdP7IrPGs1JN30bqQAukL9WTOlxqD
    

    It might be subtle to grasp for the beginner, but it allows you to add as many modules/samplers as you need with almost no maintenance cost...

    And the simplest solution if your code allows it:

    HiseSnippet 1909.3oc6Zs0aSbDEd23roXCAUn7.OzJsEUUYqllZGtUoTDlbApKDvxldSUzzw6N1dD6NypYGGHEgD+M5a8mPesukeR8eP6YlcWuytw1rDBTRqMBjmyLm47cNmYNWFbaNyAGFx3Flke39AXCyyX0cepX3lCQDpQqsLLeOqcZ8Ca2wXi8CPggXWCSyR2QNoY4EMTe9qatAxCQcvojLL9NFwAeOhOQjRscy6R77tMxE+Phu1puRyVNL5lLO1H.HkrpaDfbdLZ.99H4xVvxvboscIBFuq.IvgFlKtAyc+tCY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i+MCZYUe05xe1Djccbjob+bvKNYdV6HvykOB7bki.OW8Hvy0NB7b8i.Oe4L4Q1PxsFIX9QQXABs2N5vq41iO7Vx3e.WOD.yA
    

    Note that you can still use control callbacks for the knobs instead of the property editor connections...



  • Don‘t call the getComponent method in the control callback, but store it in a variable. The rest is cosmetics.



  • @d-healey said in Slimming down a script(for best efficiency):

    You don't need valGain or valPan, you can just refer to these attributes directly with SimpleGain_SMP0.Gain and SimpleGain_SMP0.Balance.

    Doing this: the Slider is not responding correctly..

    inline function onSMP0Control(component, value)
    {
            SMP_INDEX = 0;//Sampler
            
            //Get Volume value
            //valGain = (SimpleGain_SMP0.getAttribute(0));
            SimpleGain_SMP0.Gain;
            Content.getComponent("SMP_Gain").setValue(SMP0.Gain);
            //Get Pan value
            //valPan = (SimpleGain_SMP0.getAttribute(3));
            SimpleGain_SMP0.Balance;
            Content.getComponent("SMP_Pan").setValue(SMP0.Balance);
               
    };
    Content.getComponent("SMP0").setControlCallback(onSMP0Control);
    
    //SMP 1
    inline function onSMP1Control(component, value)
    {
            SMP_INDEX = 1;//Sampler
            
            //Get Volume value
            SimpleGain_SMP1.Gain;
            Content.getComponent("SMP_Gain").setValue(SMP1.Gain);
            //Get Pan value
            SimpleGain_SMP1.Balance;
            Content.getComponent("SMP_Pan").setValue(SMP1.Balance);
          
    };
    Content.getComponent("SMP1").setControlCallback(onSMP1Control);
    


  • @ustk said in Slimming down a script(for best efficiency):

    @ten7kur This is how I would approach it:

    HiseSnippet 1958.3oc6Z0saSbDEd23rzXWREk1K5MUZZTuvVklZyesRoHVxOPSIFrrSApPTX7tyZOhcmwZ2woIEEoJ0mBtiGgdauiGo9FzdlY206rK1NlPfBT6bimeNy467cNyLmyD2Jj6Phh3gFlk28fADCySa04.ln+F8wTlw1aZX9AVM29da01X8CFfihHtFllktgbPyxKZn972WccrOl4Px5xv3NbpCYGZ.Uj0aK6aR88uN1krKMPa1WzdaGNaCtOeH.jRV0MFfcdLtG4VX4zVvxv7Ta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LpVx34yqVZd0RyqVZd0RyqV5+1pkdSfx2D5H.6DxenS7uEGIerjpGfIXpem4ksZJaix90+XUe05xeaCzG53Hux8qAu33k47GCYtvwPlKdLj4RGCYt7wPlu8XHy2MUYjEjbsgBdP7IrPGs1JN30bqQAukL9WTOlxqD
    

    It might be subtle to grasp for the beginner, but it allows you to add as many modules/samplers as you need with almost no maintenance cost...

    And the simplest solution if your code allows it:

    HiseSnippet 1909.3oc6Zs0aSbDEd23roXCAUn7.OzJsEUUYqllZGtUoTDlbApKDvxldSUzzw6N1dD6NypYGGHEgD+M5a8mPesukeR8eP6YlcWuytw1rDBTRqMBjmyLm47cNmYNWFbaNyAGFx3Flke39AXCyyX0cepX3lCQDpQqsLLeOqcZ8Ca2wXi8CPggXWCSyR2QNoY4EMTe9qatAxCQcvojLL9NFwAeOhOQjRscy6R77tMxE+Phu1puRyVNL5lLO1H.HkrpaDfbdLZ.99H4xVvxvboscIBFuq.IvgFlKtAyc+tCYOgFs9uiDR54gkCZXzE1nHx2l44JQrjpwlCIdtsST3PCCSq1opeoH0+BV6PbIiomZFde0D1obnaOLWXVvqgN7pWb3YpAuEif24r55vIAhzYjX6zVsnBLuOBbA5vJZsFKzeQqMYvJnhU8QOFeaNLXLGUu50puh8UqWu15KWQ9mu3Kr6hEBBcfcaDE6EtbEv6DJr2CwSloM0Kz9F1+Tx1N.K1j4GvnvfpWp6Nsara5JaboZqrbE6o8oP6wkp8n0mwd.eT.eiQBAf0LH1OnK1C6H1PPmMlqOabNKj9RgWho8is6h7C7vRKoDTDFc4JDpGghs6OhpHXynY.sTrblWUmDYtBnXdiv0VtxyhDZeF2tJATt5qaSr+JcuzpdX5.wPf9m8Y0dVJFS+l1h+IxiVMDN1lHw9HuPbs0UK84QbD8u57jAqqRnt3m9f9ofsV1sTvAfC1pmC+UA6d1DZVmTM6dqFJMwJN1D440CBGTcxVknSsZlt6yD3GPqVqxypTtxyqXmep98m3bwaG3Yl3zx.V7YwXU5H+dXdhqAVnzNQ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6APNUwd.DXCT05pEJcCxfwadzx0ihN1LqfhFawEaDpQZdD2oFwsTwf6K4o4Kmfwnx41ltGbSEnHw34gxp6iF4IRnlMi8NLJKXHiRbxdu.NmOX.lqi8IpP2RHfqkoTtPyNXOLJDqWg68fJEP7rW2ekrEMJtsXV9qKZEAWaYnN6+ajorzIsLkGOt4zRSUG4uSh3mPKMSIIYS4qPtE1Ckwv88YaF6GadnznW7fVvMItnMyCwya1KcboqKV3yFRU5jyYYY3HvjeRBvpiDmb.76Kekf2AfaG1HYg.IkLYA0U0EpkzAqWc0BxJ1hFWO4+UjtXpqZveCehmrQRoXxIajLYQMIm0JpRFaPC4h2w8emwRUimsrj7+K66bR1JP2h+t5+PGyRXprlRUafdPA5d5QXCgtMjPBJ08UraoFy6VZd2Ry6VZd2RuRcKs17tkl2sz+e5VZpIIk+lMZdD5VxXd2Ry6VZd2Ry6VZd2R+K2szaCT91PF9HGNaWmne8fR6woTT.KAU8a0ur0Nxw1i+MCZYUe05xe1Djccbjob+bvKNYdV6HvykOB7bki.OW8Hvy0NB7b8i.Oe4L4Q1PxsFIX9QQXABs2N5vq41iO7Vx3e.WOD.yA
    

    Note that you can still use control callbacks for the knobs instead of the property editor connections...

    I like your solution!! Need to sit for a moment and digest it. But Sampler1(on Button SMP1) is not displaying the correct values. Even though the code is the same?!?!



  • @Christoph-Hart said in Slimming down a script(for best efficiency):

    Don‘t call the getComponent method in the control callback, but store it in a variable. The rest is cosmetics.

    Was trying all sorts to get the value before.
    Ok. Variable it is!
    Thanks!



  • @ten7kur And a lot easier than my first solution
    After all, I removed the non-necessary for loops:

    HiseSnippet 1873.3oc6ZszbSbDDdWKu.VAmBHbHWRUSbwAop.iDlGoJJJV7CHNf.UR7JEEAFu6HooX0LplcjAGJph+FbK+Dx0bieR4dNjzyL6pcVYIYgwP3gru34QO8W+08Lc2xptfGPhi4BG2Et6N8HNtG0q4NLYm05foLmMW2w8vd017gazvY0c5giiIgNttEtgZQ2El2Q+yee0UwQXV.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1ZzGCT9wPGcwAB9SBLeaaT7wQzy.LAS+kodAuZpwnAeGe77prbE02ZA5SBBTobOC3EGsLmaeHyJ6CYN+9PlKrOj4h6CYtz9PleZhxnZH4Z8k7tlWXgIpugI30ciAAuEb9O.h9mpl.
    


  • @ten7kur said in Slimming down a script(for best efficiency):

    But Sampler1(on Button SMP1) is not displaying the correct values

    Seems good here when I import the snippet...



  • @ustk said in Slimming down a script(for best efficiency):

    HiseSnippet 1873.3oc6ZszbSbDDdWKu.VAmBHbHWRUSbwAop.iDlGoJJJV7CHNf.UR7JEEAFu6HooX0LplcjAGJph+FbK+Dx0bieR4dNjzyL6pcVYIYgwP3gru34QO8W+08Lc2xptfGPhi4BG2Et6N8HNtG0q4NLYm05foLmMW2w8vd017gazvY0c5giiIgNttEtgZQ2El2Q+yee0UwQXV.IaJGm6yoAjaQ6RkYyV2+lznnqiCI2k10Z2m2ey.NaMdDuO.jBdUb5gCdFtM41X01lyyw8PaDRkbQSIVRhcbmeUd3NM6veNyr+6SioaEQTCp5zDNHyzWmGEpPrZVm05PiBqmZvwNNtd0yL+BFy+jd0ngzAymQCGSu.JSBa9vctIAup1vqxzCOWK3MuAdG2qYff1SlshBaei2lLIQzBCt.aXY1qybO3vdqwgcvjK2E+Lx0EvfART5BWrxoQWnRkxWdwhpeO6YQJ+KpFOreDIdwhfuIVh1FKPM61SsTxJnqfdjNXY41D4FsZQBjkVpIsauHh9DdRyZ0qrT4SuXQzD9YuNgpKU9wWdxGgFyq1WJAfNDbaRhfCcUISi1TV.z1Z7t83LX.nvo.liUx8FdZzcSFeq7XqV8mno4qL9yVugkT9k7xUGOYwf0Wx3MAMuIKj7BDuER1gfh0zAIDEiUjrXwhpyjF9hA99eD0zrDxPcTNawhTVDkQPs5yzSf3rbTqBIBdTofTXbZ.pQ8IkWr3KMTCsEpjYpWlwUY+E.yGzgFzIEVHZ7.nlsK.lfYmSyKSUV2cZko5xWdLJnIQpofmY7DKni8R33kiIx6qfWo7Q3OBT4iUD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VCEqWfm875XedsvzA283iScgTLZ9vF2fsMbsDlQgwS.0i1B2ORlNa9zy03LduNbFMH+k.HntcahvF6izff1Mg6fYybR+FjHBNlXWy4sfxBvh72sem3hpSOWLI+026YfKR8tF5KizhE9bKs3ASHeVcn5P9ajp9S3M7GY+3xH95UV4et55jHbNh6A4aO5W82UNyi4uIbSRHqyivhgo8BGTgzyO0wFY+2M9bHVV8bDP4eNAXcHwmO.9Xp91+D.tM38Uenzo0G4AEQ0DJbLfXWJ0bpxyLiqj9A60jvB0C9W3mjEqlV2kZwpoKNsTx25YJaAAVnP9It+6nd5B5Pp5u+R12EjdTfsk725OTT2BDlp.RcOeQP03Q1uvFCsVnfDTW66XqQUm0ZzrVil0ZzrViFeqQmaVqQyZM5qmViFaFQ8+iy8QqQNucVqQyZMZVqQyZMZVqQ++1ZzGCT9wPGcwAB9SBLeaaT7wQzy.LAS+kodAuZpwnAeGe77prbE02ZA5SBBTobOC3EGsLmaeHyJ6CYN+9PlKrOj4h6CYtz9PleZhxnZH4Z8k7tlWXgIpugI30ciAAuEb9O.h9mpl.

    Just checked. Yea! All working!! yhhh..
    Many Many thanks @ustk ! Need to sit and study this. Im grinning!:))))))
    Thanks all for the inputs!!



  • @ustk

    for (b in SmpSelectBtns) b.setControlCallback(onSmpSelectBtnsControl);
    

    ughhh!
    I understand that "b" is "SmpSelectBtns" array But ive never seen a ControlCallback like this!!
    My digestions struggling at this moment😱 😳



  • @ten7kur That isn't the control callback, that's assigning the function called onSmpSelectBtnsControl as a callback function to each button b.



  • @d-healey said in Slimming down a script(for best efficiency):

    t's assigning the function c

    mhm i see. Its a FOR statment/loop after the function.
    Never seen it like this.
    Though im getting the Logic, the code is still Extra Wings for me. Will digest hopefully 🙃



  • @ten7kur Did you see my HISE Scripting 101 video?


Log in to reply
 

8
Online

647
Users

2.6k
Topics

21.4k
Posts