Forum
    • Categories
    • Register
    • Login

    Code feedback on this custom envelope panel

    Scheduled Pinned Locked Moved Scripting
    15 Posts 5 Posters 82 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • dannytaurusD
      dannytaurus @David Healey
      last edited by dannytaurus

      @David-Healey said in Code feedback on this custom envelope panel:

      I'd draw the labels on the panel rather than using individual label components.

      The labels aren't set in stone yet. I tihnk eventually I'd like the user to be able to drag the label values up/down to change the values too, as well as the handles.

      Why a function and not an inline function? Doesn't Math.range do the same thing?

      I was getting some errors calling it when it was an inline function. I'll look at Math.range too 👍

      You don't need the else in statements like this. The first return will exit the function anyway.

      Yep, good point 👍

      I think it's cleaner to declare n outside of the if statement rather than have two declarations for it

      That's just me squeezing a couple of line out of the code, but yeah probably best to define outside 👍

      I didn't know you could declare a function within a paint routine. Somehow that feels wrong to me :) I'd declare it outside, but if it works it works.

      Yep, new to me too but it works. But yeah, might move it outside for clarity. Especially since it's multiple lines. It was a one-liner until I added the handle highlight colour.

      This is a perfect place for a switch statement instead of the else ifs

      I read you shouldn't declare vars in a switch statement, so I stuck with if/else. I can move the x and n vars outside I guess 👍

      Thanks for all the tips! 🙌

      Meat Beats: https://meatbeats.com
      Klippr Video: https://klippr.video

      1 Reply Last reply Reply Quote 0
      • Oli UllmannO
        Oli Ullmann @dannytaurus
        last edited by

        @dannytaurus
        That looks great!

        @Christoph-Hart I also created my own panel because I had performance issues with theFlexEnvelope FloatingTile. It caused significant lag in the user interface and the interface of my DAW (Cubase).

        1 Reply Last reply Reply Quote 1
        • ustkU
          ustk @David Healey
          last edited by ustk

          @David-Healey said in Code feedback on this custom envelope panel:

          I didn't know you could declare a function within a paint routine. Somehow that feels wrong to me :) I'd declare it outside, but if it works it works.

          I tend to do it this way nowadays, inlining as many functions as I can for paintRoutines, mouseCB... And sub functions can be used elsewhere when necessary

          MainPanel.setPaintRoutine(drawMainPanel);
          
          inline function drawMainPanel(g)
          {
          	subFunction1();
          	subFunction2();
          }
          
          
          inline function subFunction1()
          {
          	
          }
          
          inline function subFunction2()
          {
          	
          }
          

          Hise made me an F5 dude, any other app just suffers...

          David HealeyD dannytaurusD 2 Replies Last reply Reply Quote 1
          • David HealeyD
            David Healey @ustk
            last edited by

            @ustk Yes that's my approach too.

            A few things in my mind when writing code:

            • Don't indent more than 2 levels - there are exceptions, for example when using nested loops.
            • Make the code readable, even if it ends up a little more verbose.
            • The code should be self documenting as much as possible, no need for comments
            • Be consistent with naming, use of brackets, etc.

            Basically the stuff I put in the style guide.

            I also use type-safety for all my functions now, except in a few instances where I want to allow for undefined return types.

            Free HISE Bootcamp Full Course for beginners.
            YouTube Channel - Public HISE tutorials
            My Patreon - HISE tutorials

            ustkU 1 Reply Last reply Reply Quote 1
            • ustkU
              ustk @David Healey
              last edited by

              @David-Healey all the same except for type-safety which I didn't really see the gain for me now as I am very careful on the caller side... But I understand where it can help 👍

              Hise made me an F5 dude, any other app just suffers...

              1 Reply Last reply Reply Quote 0
              • dannytaurusD
                dannytaurus @ustk
                last edited by

                @ustk said in Code feedback on this custom envelope panel:

                I tend to do it this way nowadays, inlining as many functions as I can for paintRoutines, mouseCB...

                Is this mainly for readability and reusability? Or is there a performance improvement too?

                Meat Beats: https://meatbeats.com
                Klippr Video: https://klippr.video

                ustkU 1 Reply Last reply Reply Quote 0
                • ustkU
                  ustk @dannytaurus
                  last edited by

                  @dannytaurus inline functions tend to perform better

                  Hise made me an F5 dude, any other app just suffers...

                  dannytaurusD David HealeyD 2 Replies Last reply Reply Quote 0
                  • dannytaurusD
                    dannytaurus @ustk
                    last edited by

                    @ustk I thought inline functions were placed inline at their call spot during compilation, hence the name? Which would end up putting them all back where they were refactored out from.

                    Although I now think I remember Christoph saying recently that wasn't the case? 🤔

                    Meat Beats: https://meatbeats.com
                    Klippr Video: https://klippr.video

                    1 Reply Last reply Reply Quote 0
                    • David HealeyD
                      David Healey @ustk
                      last edited by

                      @ustk said in Code feedback on this custom envelope panel:

                      @dannytaurus inline functions tend to perform better

                      For paint routines and mouse callbacks I'm not sure it makes a difference since the paint routine or mouse callback is still a regular function.

                      @dannytaurus said in Code feedback on this custom envelope panel:

                      Although I now think I remember Christoph saying recently that wasn't the case?

                      You remember correctly, he was lying to us this whole time :p

                      Free HISE Bootcamp Full Course for beginners.
                      YouTube Channel - Public HISE tutorials
                      My Patreon - HISE tutorials

                      dannytaurusD ustkU 2 Replies Last reply Reply Quote 1
                      • dannytaurusD
                        dannytaurus @David Healey
                        last edited by dannytaurus

                        @David-Healey @ustk I'm not against the concept of refactoring stuff out to inline functions at all, it's a very common pattern in Ruby. Lots of small well-named methods can make the code a lot easier to reason about.

                        Also helps with the self-documenting code idea.

                        @David-Healey 😂

                        Meat Beats: https://meatbeats.com
                        Klippr Video: https://klippr.video

                        1 Reply Last reply Reply Quote 0
                        • ustkU
                          ustk @David Healey
                          last edited by

                          @David-Healey said in Code feedback on this custom envelope panel:

                          For paint routines and mouse callbacks I'm not sure it makes a difference since the paint routine or mouse callback is still a regular function.

                          Yes but the way I understand it (might be wrong though) is that it's faster to execute even if the outside part isn't inlined. The inline part containing locals, the code execution inside it seems faster especially for long paint routines or mouseCB. Then what happens after this isn't affected but at least the script part might be improved.

                          Hise made me an F5 dude, any other app just suffers...

                          1 Reply Last reply Reply Quote 2
                          • First post
                            Last post

                          15

                          Online

                          2.1k

                          Users

                          13.2k

                          Topics

                          114.5k

                          Posts