HISE Logo Forum
    • Categories
    • Register
    • Login

    Widget of the Day for Y'all

    Scheduled Pinned Locked Moved Presets / Scripts / Ideas
    21 Posts 4 Posters 1.4k 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.
    • d.healeyD
      d.healey
      last edited by

      Looks nice. I noticed two issues.

      You're including a font from the project folder, if the user doesn't have that then the script will fail to compile.

      You're using non-standard parameter names for you LAF function. graphics should be g and widget should be obj. The auto-complete doesn't work with those parameter names (not sure this affects the obj parameter actually). I found this out myself years ago when using e instead of event for mouse callbacks :)

      I've never seen reg variables declared inside a function. I don't know if there are any downsides/benefits to this... @Christoph-Hart ?

      Libre Wave - Freedom respecting instruments and effects
      My Patreon - HISE tutorials
      YouTube Channel - Public HISE tutorials

      clevername27C 2 Replies Last reply Reply Quote 1
      • clevername27C
        clevername27 @d.healey
        last edited by

        @d-healey Hi David, thanks for your feedback. What do you recommend I do for the widest font compatibility?

        d.healeyD ustkU 3 Replies Last reply Reply Quote 0
        • d.healeyD
          d.healey @clevername27
          last edited by

          @clevername27 A snippet should be self contained, so I wouldn't load any fonts inside it.

          Libre Wave - Freedom respecting instruments and effects
          My Patreon - HISE tutorials
          YouTube Channel - Public HISE tutorials

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

            @clevername27 Just a little suggestion
            But of course, I know you wrote this code for beginners. It is good to see how things can be reduced/simplified

            This:

            local componentBlue = colourArray[1];	
            componentBlue += brightnessAdjustment;
            
            if (componentBlue < 0.0)
                componentBlue = 0.0;
            
            if (componentBlue > 1.0) // would benefit from an else if statement here
                componentBlue = 1.0;
            
            colourArray[1] = componentBlue;
            

            could be better written:

            local componentBlue = colourArray[1];	
            componentBlue += brightnessAdjustment;
            
            colourArray[1] = Math.range(componentBlue, 0.0, 1.0);
            

            Or even a one-liner

            colourArray[1] = Math.range(colourArray[1] + brightnessAdjustment, 0.0, 1.0);
            

            Can't help pressing F5 in the forum...

            clevername27C 1 Reply Last reply Reply Quote 1
            • ustkU
              ustk @clevername27
              last edited by ustk

              @clevername27 Like Dave I'm surprised to see the reg declarations inside the function. But if it's not an issue then I'm sure LAF functions in general will largely benefit from this increased variable speed!
              Just a shame we can't nest namespaces because the 32 reg limit will be quickly reached in any small project if they're all in one unique LAF namespace...

              Can't help pressing F5 in the forum...

              Christoph HartC 1 Reply Last reply Reply Quote 0
              • Christoph HartC
                Christoph Hart @ustk
                last edited by

                @ustk the limitation to 32 slots is one of the main reasons why they are so fast :)

                ustkU clevername27C 2 Replies Last reply Reply Quote 1
                • ustkU
                  ustk @Christoph Hart
                  last edited by ustk

                  @Christoph-Hart Sure! I wouldn't need more anyway... When I reach that number I always get back to another design because it means I overdid something... (By the way, it would be cool to have an alert when reaching the limitation because I already struggled multiple times to find the origin of a bug while I was simply having too many regs within a namespace 🙄 )

                  And what about declaring them inside a LAF function like @clevername27 did?

                  Can't help pressing F5 in the forum...

                  Christoph HartC 1 Reply Last reply Reply Quote 1
                  • clevername27C
                    clevername27 @d.healey
                    last edited by

                    @d-healey Thank you - I simply don't know how to do that with fonts, could you please tell me?

                    d.healeyD 1 Reply Last reply Reply Quote 0
                    • clevername27C
                      clevername27 @Christoph Hart
                      last edited by

                      @Christoph-Hart Are these literally register variables?

                      Christoph HartC 1 Reply Last reply Reply Quote 0
                      • Christoph HartC
                        Christoph Hart @ustk
                        last edited by

                        @ustk yes good idea, I‘ll make it throw an error (no idea why I didn‘t do this earlier, lol)

                        1 Reply Last reply Reply Quote 3
                        • Christoph HartC
                          Christoph Hart @clevername27
                          last edited by

                          @clevername27 said in Widget of the Day for Y'all:

                          @Christoph-Hart Are these literally register variables?

                          no, there are about 20 layers of abstraction between these variables and the CPU registers…

                          1 Reply Last reply Reply Quote 1
                          • clevername27C
                            clevername27 @ustk
                            last edited by

                            @ustk I've added your code as a comment - thank you.

                            1 Reply Last reply Reply Quote 0
                            • clevername27C
                              clevername27 @d.healey
                              last edited by

                              @d-healey Thank you for your suggestion - I've revised the code to use 'g' and "obj".

                              1 Reply Last reply Reply Quote 0
                              • d.healeyD
                                d.healey @clevername27
                                last edited by

                                @clevername27 said in Widget of the Day for Y'all:

                                @d-healey Thank you - I simply don't know how to do that with fonts, could you please tell me?

                                You can't, if you load a font in your snippet then the user must have that font. So don't use them in snippets.

                                Libre Wave - Freedom respecting instruments and effects
                                My Patreon - HISE tutorials
                                YouTube Channel - Public HISE tutorials

                                clevername27C 1 Reply Last reply Reply Quote 0
                                • clevername27C
                                  clevername27 @d.healey
                                  last edited by clevername27

                                  @d-healey How do I draw text then - don't I have to specify some font?

                                  ustkU d.healeyD 2 Replies Last reply Reply Quote 0
                                  • ustkU
                                    ustk @clevername27
                                    last edited by ustk

                                    @clevername27 loadFontAs but just give the name of an embedded font (that you can find in the property of a Label)
                                    If you just want to draw a text for an example snippet, just do:

                                    g.setFont("Arial", 14.0); // or whatever embedded font
                                    

                                    inside a paint routine (or LAF function), you don't even need to loadFontAs...
                                    And if you just ignore this line, a default font will be used anyway so you don't even have to bother setting a font (but then you lose the ability to set its size)

                                    Can't help pressing F5 in the forum...

                                    Christoph HartC 1 Reply Last reply Reply Quote 1
                                    • Christoph HartC
                                      Christoph Hart @ustk
                                      last edited by Christoph Hart

                                      How do I draw text then - don't I have to specify some font?

                                      If you don't call g.setFont(), it will default to Arial or whatever is the standard font.

                                      For a "real" project, I would always embed the fonts, but if you want to pass around snippets that need to be self-contained, you can just assume that the user has installed the font on his system and if it isn't found, it will fall back to Arial (or Comic Sans MS on April 1st).

                                      ustkU 1 Reply Last reply Reply Quote 1
                                      • ustkU
                                        ustk @Christoph Hart
                                        last edited by

                                        @Christoph-Hart said in Widget of the Day for Y'all:

                                        (or Comic Sans MS on April 1st).

                                        🤣

                                        Can't help pressing F5 in the forum...

                                        1 Reply Last reply Reply Quote 1
                                        • d.healeyD
                                          d.healey @clevername27
                                          last edited by

                                          @clevername27 said in Widget of the Day for Y'all:

                                          @d-healey How do I draw text then - don't I have to specify some font?

                                          No need to specify a font at all, it will use the default

                                          Libre Wave - Freedom respecting instruments and effects
                                          My Patreon - HISE tutorials
                                          YouTube Channel - Public HISE tutorials

                                          1 Reply Last reply Reply Quote 1
                                          • clevername27C
                                            clevername27
                                            last edited by

                                            Thank you, everyone. Fonts sorted.

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

                                            14

                                            Online

                                            1.7k

                                            Users

                                            11.9k

                                            Topics

                                            103.5k

                                            Posts