code repetitions are ugly

Home Forums General Programming code repetitions are ugly

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #71354
    proton
    Participant
    • Topics: 19
    • Replies: 94
    • Total: 113
    • ★★

    Hi good souls of this great forum!

    I need to ask for some help since I’m pretty sure there are people out there that are great in this game.

    While writing methods for many things in my panels I see the amount of lines of code growing and growing. Since I use many buttons and labels I tend to reuse the code by just changing the button numbers etc. I know this can be done in much more elegant way and without generating such a long script. Due to this the programs starts to run slower and autosaving takes muuuch too long.

    So for example if I do the exact same thing on all the 12 buttons in question I write something like this:

    pres1xtra_label1_1 = panel:getComponent(“XtraLblBut1-1”):getProperty(“uiLabelText”)
    pres1xtra_label1_2 = panel:getComponent(“XtraLblBut1-2”):getProperty(“uiLabelText”)
    pres1xtra_label1_3 = panel:getComponent(“XtraLblBut1-3”):getProperty(“uiLabelText”)
    pres1xtra_label1_4 = panel:getComponent(“XtraLblBut1-4”):getProperty(“uiLabelText”)
    pres1xtra_label1_5 = panel:getComponent(“XtraLblBut1-5”):getProperty(“uiLabelText”)
    pres1xtra_label1_6 = panel:getComponent(“XtraLblBut1-6”):getProperty(“uiLabelText”)
    pres1xtra_label1_7 = panel:getComponent(“XtraLblBut1-7”):getProperty(“uiLabelText”)
    pres1xtra_label1_8 = panel:getComponent(“XtraLblBut1-8”):getProperty(“uiLabelText”)
    pres1xtra_label1_9 = panel:getComponent(“XtraLblBut1-9”):getProperty(“uiLabelText”)
    pres1xtra_label1_10 = panel:getComponent(“XtraLblBut1-10”):getProperty(“uiLabelText”)
    pres1xtra_label1_11 = panel:getComponent(“XtraLblBut1-11”):getProperty(“uiLabelText”)
    pres1xtra_label1_12 = panel:getComponent(“XtraLblBut1-12”):getProperty(“uiLabelText”)

    As you can see only the numbers grows, the rest stays same. And this is only for preset1 of buttons 1-12 of the first row. With 16 rows, 12 buttons in each row and 16 presets for all of them I generate 3.072 lines of code just for getProperty(“uiLabelText”). Not to mention all the others. For the second row it will look like this:

    pres1xtra_label2_1 = panel:getComponent(“XtraLblBut2-1”):getProperty(“uiLabelText”)
    pres1xtra_label2_2 = panel:getComponent(“XtraLblBut2-2”):getProperty(“uiLabelText”)
    pres1xtra_label2_3 = panel:getComponent(“XtraLblBut2-3”):getProperty(“uiLabelText”)
    pres1xtra_label2_4 = panel:getComponent(“XtraLblBut2-4”):getProperty(“uiLabelText”)
    pres1xtra_label2_5 = panel:getComponent(“XtraLblBut2-5”):getProperty(“uiLabelText”)
    pres1xtra_label2_6 = panel:getComponent(“XtraLblBut2-6”):getProperty(“uiLabelText”)
    pres1xtra_label2_7 = panel:getComponent(“XtraLblBut2-7”):getProperty(“uiLabelText”)
    pres1xtra_label2_8 = panel:getComponent(“XtraLblBut2-8”):getProperty(“uiLabelText”)
    pres1xtra_label2_9 = panel:getComponent(“XtraLblBut2-9”):getProperty(“uiLabelText”)
    pres1xtra_label2_10 = panel:getComponent(“XtraLblBut2-10”):getProperty(“uiLabelText”)
    pres1xtra_label2_11 = panel:getComponent(“XtraLblBut2-11”):getProperty(“uiLabelText”)
    pres1xtra_label2_12 = panel:getComponent(“XtraLblBut2-12”):getProperty(“uiLabelText”)

    i hope you can see the pattern here.

    Any tips or examples on how to make all this shorter by using iteration or variables?
    Let me help make my methods great again and help me to grab them by the code 😉

    Thanx!!!

    #71355
    dasfaker
    Keymaster
    • Topics: 80
    • Replies: 793
    • Total: 873
    • ★★★

    If this is only done once on the panel, I see no problem.
    I think longer saving times are due to the amount of modulators rather than because of a single script. How many mods do you have on the panel? Each mod has a great amount of lines, the more mods, bigger panel size.

    #71360
    proton
    Participant
    • Topics: 19
    • Replies: 94
    • Total: 113
    • ★★

    In this particular panel I have 12×20 buttons, so 240 buttons in total and on each button there are 2 or 3 labels and an one extra modulator that isn’t visible but changes its value depending on what function of a button is selected, each button has also a PNG attached to it and it changes depending on the selection. There are also 60 buttons that I use to fire LUA methods that I wrote to save the current state and assignments of all the buttons, labels, PNGs etc – I use them to store and recall my “presets” so to speak.
    Having so many moving parts to store and recall by a press of a button seems to work the way I do it now but it takes some time and feels laggy, especially on the OSX, much slower reaction compared to the PC version.
    I just thought making the script slicker would improve the performance greatly.

    Thanks for any input!

    #71361
    dasfaker
    Keymaster
    • Topics: 80
    • Replies: 793
    • Total: 873
    • ★★★

    What you call labels on each button, are components, modulators? What’s the size in Mb of the panel?
    Could you replace all 60 buttons with a combo with 60 options? Sure there could be room for improvement, but it’s hard to tell without seeing the panel.

    • This reply was modified 5 years, 3 months ago by dasfaker.
    #71363
    proton
    Participant
    • Topics: 19
    • Replies: 94
    • Total: 113
    • ★★

    Hi dasfaker,
    by label I meant uiLabels. I can’t replace the preset buttons with a combo since everything needs to be visible on the screen all the time. The panel size as of now is 15MB. I can’t share the panel since this is a commissioned job for a potential client of mine but it kinda mimics the behavior of a Lounchpad or Ableton Push.

    Going thru the code today I realized that maybe all would be much easier with different naming convention for my buttons. Instead of naming them “XtraLblBut1-1”, “XtraLblBut1-2”, …, “XtraLblBut1-12”, “XtraLblBut2-1”, “XtraLblBut2-2″,…,”XtraLblBut2-12” etc I should just name them “XtraLblBut_1″…”XtraLblBut_240” and the iteration in code would be easier to achieve.

    Still looking for any helpful tips! Thanks in advance!

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Programming’ is closed to new topics and replies.
There is currently 0 users and 57 guests online
No users are currently active
Forum Statistics
Threads: 2,495, Posts: 17,374, Members: 77,605
Most users ever online was 12 on January 22, 2019 3:47 pm
Ctrlr