2 Linked Knobs with 1 Shared Function without doubling the codes



  • Left and Right knobs are linked with a button. These 2 knobs have the same shared function, indexes and equations. Only difference is "Left" and "Right". How can we write a shared function without doubling the codes for Left and Right individually?

    
    inline function sharedFunction()
    {
        
        
        local Node_BoosterValue_Left = 2.288*(Knob_Left.getValue()); 
        
        local Node_BoosterValue_Right = 2.288*(Knob_Right.getValue()); 
        
        
    
        local index_EQ_Gain_Left = EQ_Left.Gain + 0 * EQ_Left.BandOffset;
        
        local index_EQ_Gain_Right = EQ_Right.Gain + 0 * EQ_Right.BandOffset;
        
        
        EQ_Left.setAttribute(index_EQ_Gain_Left, Node_BoosterValue_Left);
        EQ_Right.setAttribute(index_EQ_Gain_Right, Node_BoosterValue_Right);
        
    }
    
    

    I am asking this because I have lot's of equations and controls. Doubling them will be a huge mess. Below is the simple snippet. Any help will be appreciated!

    Note: I know it is about the arrays but I just can't figured it out. 🙂

    HiseSnippet 1500.3oc4X8taaaCDmJNpq1sYncHCneTHnevoKKv1oqs.AC00N1EAM+wKNKc6CCoLRzwDQlzShJqAEEXO.6gXOA6YXOB6QXO.6C8MX6nnjEkqjqpaSwVW9fQ3w6N969wi7NpddbahuO2CYT9vKFSPFW2r+ELwv1CwTFZ6sPFKatyA8Gh8HNVcCX1BJm4iZcwXruOwAYXT5wRMMJuHJ7uW8vVXWLyljHBgNhSsI6PGQEIR607ITW2tXGxgzQZZe2laayYs4t7..UkLqgFisOCeJYOrTsELQFWoiCUv85KvBhOxXwVbmK5Oj+SLk9GQ8om3RjCpi5CNRItK20QhXoTT6gTWmdwQuOBYX1KgKJo3hkM2k5PmHOgStQ3DVIVnyGFKLK3UWGd0JN7Lzf2hJ3cSy91dzwhjYjX6ZlayDDuAXXKPGVJcQK7WWwrMGzfIVeD9LRWOXvDKptwF0VypQiZqt4RUVpBrQ3KrNG6Y04aNdGx.g0WaEldr9oDQmACH1hpqDM0JRSRYvAzSGlmEgyshZURuR6PYmcbq.gfy.aigJXca9nwbFLn5JZ5D4CJ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ve9PURQeBDMN66aCAqj6zSk5E35SdJ0QLrttgIhanKd5Lq25as9O32O4CW4yRECtugOwS4XL1mNZrKoC6bhKz6UHF+LnYqA3.WQrzzGi1ky3iGxYTa8bpCHvo+SOkjJuIy.BdY.7TvDIK27.hKA6Sza6AZZgf8.dhLmbQ8hyEyZ+5VlJ3ZIO6a8wQaOk9HpsmKiSnv0i+KXm98eUUinISpp9gXMFgs83Gaqdsn7n2UCk.wMK7CtW1bW4Xq5wOPzzr150Pv6dnGaaKyN9Rfex1lFygMaLG1b24vluZNr4dygM2eNr4AyzFYsyGEH3iT4+ffdcBentggV+in+AfHDlu3
    


  • You need to plan it from the start. First your EQs should be named something like eq0 and eq1 so that they are loop/array friendly. You should do the same with your controls too, no left/right, always 0/1. Start there and see how you get on, come back when you're stuck again 🙂



  • @d-healey I understand. I did the renaming. Since the scenario is different than I think, for making the situation more realistic, I added high knobs and added a "shared high function" too. But I am stucked more now 🙂

    HiseSnippet 1662.3oc4Y0raaaDDlzxrMRttIovEHmJHL5A4TWCQYGGWXTDEKKkZD+ihkqS6Ik0jqr1ZpcUIW5Dif.jK8RQeP5odou.4QnOBEnm5s7FzNK+QboLojrhcPSpLff2Ymc1u4al8mYUCGlI10k4nnl+fy5gUT+HslmQ4cp1AQnJasoh5bZaueyNHGrkdcOpImvntJabVOjqK1RQUM2CDZpleZE+Ou9dafrQTSbrHEkCYDS71jtDdrzFUdHw1tNxBe.oqj1qTYKSFsJyl4AnJmVIkdHySPGi2EITaJME0OnlEgybZxQbrqh5zavrNqYG1SoA5eHwkbjMVzvPoIXn.w0Y1VBDKjpTsCw1pQj26pnnp0HlKxEvEyosCwhzWdLmbC+NziGgLenN0vfmgL7JM9vSUBdSG.uap0zzgziG2i.aynsEkicZifPfLrBzUYpedFspLPCJeotnSv0cfF8GQwkWtzh5kKWZg0msvrEf.gKW+TjidsGUR+q08SMV5XLuV61XSdw4AwyKTUVQizUzX9.alztaSnmzZCONmQggEALXfUYc6wnPihyKoSnMHT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jsQ85GTih.ZJfRykjRyMdTZJQz8YdbB83cPv0JDqm.NpIyywDCATJEa2mpBaWRzV.olXepSS8efOgcZD0VzY+FJiSjx3MIRou5sN7RORU4g+8+miTyEDolQ6wnSw9uaoer5S8a2l4zU+AXJ1QrQkwPd26+Xbe26di86dumIGfvANHpaOlK1P1xCzWY491Dy8nIUOPTBsDtWcv8LjioQBKKKrAhlvXP6DVZGhzYe+48BRJZhAuwZOWSvYEbmbpTCOaW7iIV7NFxCLVbYYwClYcg2V8cvm6+s2464FO3NheQh7QXrIoaOabM5oXa31v9X7Sfq+1F4YyijlbYzNLJqWGFkXJmSsOFV8e7w3D4Mo5PPghHyShkLWk8w1XjKV99XvsovHGfmvSHWXL9bwvhW2RK.t5h095ueburbuGcurqhUnv1i+GHRe4eppZXmwmp91XN5hLcXsLCpeWrz6Z9R.+l5+6CmWaGQa89U8qoUZoRPIiVjVllhriuD3mzGS4IXLKOAiYkIXL2YBFypSvXt6DLl0F5XDmcdeONqaP9OHnQM+mNQUU59iJ+aPYYqd
    


  • I don't think this does what you think it does

        if (Link_Button.getValue())
    	    LowKnob1.setValue(value);	    
    	    shared_Low_Function();
    

    If statements should be followed by curly braces and the stuff you want to happen inside the statement goes in those curly braces. Like this:

        if (Link_Button.getValue())
        {
    	    LowKnob1.setValue(value);	    
    	    shared_Low_Function();
        }
    

    If you only have one statement within your if statement you can forgo the curly braces, but if you're unsure then use the braces.

    Some comments in your script would be useful.

    You have a crazy amount of empty lines in your script that make it hard to read.

    You should read this.

    Anyway this is how I'd approach it (you can probably reduce some of the repeated code even more, but it's a good start):

    HiseSnippet 1711.3oc4YE0aSbDD9t3b.wPnPUPkmPai3ASAB9bBPpRqvjDaHhDhINMzVTDr4t0wqx4cM2sNPJJR7Rk5C8mRUeo+An+C5OAj5S8s9Onc18ty2dlKAGSBsk5G.1YmYtuY9latYWp4ycHAAbeCyQVcm1DCySYUeGln4bMwTlwByaXNl0hqTuI1m3hp1g4HnbVfwr6zFGDPbMLM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O.dX1NBAmo7vHVQcsRYtZ3XiuZg4wBrbftnLKjsaS7ETIQZNOYaXR4vw6FwZdRvVBdaUpOp4ng4w6qj+ySdnSTdmjEOrbK8o0u3qZg0T8hvtttdjZ7.prTTeFdiCHFr0vvSZnggWt1QLFRUBrWIhod+Ah8LSbHAhg6iBwD29xuUGAjxFu4AKfi2vc63gEoOyirCazFRzne3B4AHX.J2QuV+H4fP8KbOqUMpvoY13cnLvK7J4QMdiNV4nVgmDJArCaU8qGzyPl8QbKl0YHGRCKeTbSl453uMoxSU3vxpxCJlBH2uSqpTOXVF4mYLGBhG4WUKF2U9GbrKKEXGK3m+wuQInT5aDf4NYuBlJQvYTlb8HAu5ml5SUBtQjfW1z8WTBtYrFW36+ckOltWm94IBNQ4pUWsBCCoovTZtzozb8WJMCFcEdGAks4RXX9A38JKHGUm2w2g.DJiQ75lphVWTtVBo5DUpyx7ufeQaZGuVtY2EF8CSY+tvTnab90NzYpx26O9+LSctPl5jVODuMQcsGJt5bp0v.+sP2gvH9xFU16yUn8a86Un0tuuBskcD.DV0GyBZyCH15dtm8Jou27DQGVZ0CEkRKY3UEBOacNMVXIcg0vrTNCVmxSKQ0992quUXQQcBDMtKG3.AqL2oWJUqiW.4gTWQSacCSDWRW7cw9t.u3jpqet2wVsYdccG6e02l36uu4mq+f6a4BOGIFi0osZ6Qpv1l3ASMqv3GCiI2.2wSDKM8qVKwY71M4LZJReEBzQXyMIopkxLffSIhc1JQxXkWg3QvAD84zfQrHXeHOQFvbgc+mK1O957VgvEI6Gf9vXVsbe.Mq1QwanPKy+6vzehEzFuDRQ2n+446C+4CLi1LY9f2GOiVXGe9icBuYBYCiSnj.wMS8eZ1HVKIWi5deFVVEmnnAb7R5icbj0zWExOYaSoAvlIG.alZ.r45CfM2X.r4lCfMSuu1H+h+s6H3sBq+AA0pntXHSSsIgM9a.GXqzIB
    


  • @d-healey Great example and explanation thank you so so so much!

    Just one thing; Knobs are not working when the button is unlinked also.



  • @Steve-Mohican if "sharedFunction" is not active you'll need an "else" statement in your knob CB's

    HiseSnippet 1752.3oc4YEzaSbDEd23rsXCoEPfJmPihnRlBD75DfTkhvjDaHhDhINMzVTDrY2wwix5YL6NafHTj3Ru0+E8duzK8H+D5MtVodp25sdoRsuY1c8NqyFiigj1R8EXdy68lu226My9lI08X1Xeelmld9U2oCVS+DFM1gxaMWKKBUag40zOiwhqznkkG1AUKfZyILpu1r6zwx2G6noqm6NBM0yOpl72ueqYsbsn13DQZZqwH13EIsI7Do0qbOhqaMKG7pj1JZOUkErYz4Xtr..U4LJo0wxdKqMw22Rn1HFZ5ePUGBm40faww9Z5iNKyYmFsXOiFp+ZDexFtXw.SsFfiBEWi45HPrPp1bsHtN0iideMMci5IbQtPt3LFKQbHckmvImTNAJwBU9Pej9AOSU3UZvgmtB7FMDdmxngsGoCOYFA1NtwBTN1qoEjBTgUntZi75iYLGCzfxmns0V3ZdvftVTbxIKcYT4xkt3LiUXrBW8pnpMahs49iU.RJ9bD9o9nahdz5xoax7PEIv3RyfHnu.UF9mKcoKNVAD7CzbhNA9sJJqmlXSLOzUEGu5CFGcID4hcWiM3zEIzshWingfeiAJX7br1cXTXPwwilebg8Q++I7EZP4dL24rbc2.pXJxnQSFMQ3xQntDJF0LpTF0qVEsiWnKi11xM.CgyKBiHRSTwXQhwQhE+1htQ0mtH6YOpz5BnrlPqhcEZttHBBEJi5TlcWxls1qcRo6qg9xMjw6GKFO0tiUX2XRMd0iY03wCP5KJvhsHLMlctHVmjLZJ5frd1YlXE5lZJra1ImdTrOYGWlskKhPcvOGBotXWJX4lIFFiwjbZbMjBU2MAmOU3XdEo6TxUgfXlHE2+zhbGgqOdOUNQv1Q.ZXKyihV.wgp.kVB8YpRm0h5rbylvpqTKnLOLws4bOxFAbbQvmQjD3jxSTd5oAZVBmPxNtFQTokpHQH3.VkHL4MVlHTJi5DYkdeKTDZLXUJJZdvJUjAPl0JGz5jvMtG0EJlGtEJc+xeVbeuACBL3NjswHdKhehZVnMvb36LHJ7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9kuNmQHbQhyCPuezqVt2i5U6vXGJbj4+cxzehAbLdYjLci9mOe+tu+.8nIS5O3nXMZaY6wdrc3KSHNv3XRIPbSk+oDyarjXLp66YXXTZhRZv0KIO11VTSeEfex1lxCgMSND1L0PXy0FBat9PXyMFBaltu1H9h+sC3r1g0+ff5UkOLjttRmvZ+s0EShF
    


  • @ulrik Thanks, I haven't recognized that.

    @d-healey Thank you so much again!!

    👋


Log in to reply
 

14
Online

1.2k
Users

3.8k
Topics

33.5k
Posts