HISE Logo Forum
    • Categories
    • Register
    • Login

    Slider getValueNormalized changes output depending on middle position

    Scheduled Pinned Locked Moved Scripting
    10 Posts 2 Posters 507 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 d.healey

      I've been trying to track down an annoying bug in my project which is using getValueNormalized. And I just realised it's returning the normalized visual value and not the actual normalized knob value.

      For example if I have a knob with a range of 0 - 50 and I set the value to 25 I would expect the normalized value to be 0.5. However this is only true if the middle position is set to 25. If I set the middle position to 10 HISE will return 0.74 when the knob's value is at 25.

      Also affects setValueNormalized. In the example above passing in 0.5 will set the knob to the middle position, not 25.

      Is this intentional?

      In the meantime here is are two simple functions to get and set the normalised value.

      inline function getNormalisedValue(component)
      {
          local value = component.getValue();
          local min = component.get("min");
          local max = component.get("max");
          return (value - min) / (max - min);
      }
      
      inline function setNormalisedValue(component, normalisedValue)
      {
          local min = component.get("min");
          local max = component.get("max");
          component.setValue(min + (normalisedValue * (max - min)));
      }
      

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

      A 1 Reply Last reply Reply Quote 0
      • d.healeyD d.healey marked this topic as a question on
      • d.healeyD d.healey marked this topic as a regular topic on
      • A
        aaronventure @d.healey
        last edited by

        @d-healey It's intentional, I think, because the whole point of that is so that you can be manipulating the controls without thinking about skew.

        Don't your functions do the same, as they don't account for middlePosition?

        Use Math.skew().

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

          @aaronventure But you do have to think about the skew because the middle position affects the output. That's the problem.

          My functions don't care about the skew or middle position.

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

          A 1 Reply Last reply Reply Quote 0
          • A
            aaronventure @d.healey
            last edited by

            @d-healey Well, depends on where you use them. As such, you should use these methods in situations where skew can just give you trouble. Like the graphical stuff or animation.

            Can you give me an example where this specifically is an issue for you?

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

              @aaronventure said in Slider getValueNormalized changes output depending on middle position:

              Can you give me an example where this specifically is an issue for you?

              I can't think of an example where I wouldn't want the normalised value to be the normalised value.

              In every situation if I set the knob to the centre value (that is the value half way between the min and max) it should return 0.5 regardless of the middle position or skew.

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

              A 1 Reply Last reply Reply Quote 0
              • A
                aaronventure @d.healey
                last edited by

                @d-healey Ah ok. In that case, did you know you can pass "middlePosition" to Math.to0to1()?

                // prints 0.5
                Console.print(Math.to0To1(80, {"min": 10, "max": 90, "middlePosition": 80})); 
                
                d.healeyD 1 Reply Last reply Reply Quote 0
                • d.healeyD
                  d.healey @aaronventure
                  last edited by

                  @aaronventure I completely forgot about the 0to1 function.

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

                  A 1 Reply Last reply Reply Quote 0
                  • A
                    aaronventure @d.healey
                    last edited by

                    @d-healey Yeah I figured that's why we were running in circles :face_with_tears_of_joy:

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

                      @aaronventure The original function is still bugged though - or misnamed.

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

                      A 1 Reply Last reply Reply Quote 0
                      • A
                        aaronventure @d.healey
                        last edited by

                        @d-healey could be mislabeling - I think it just pulls the same property that you get in LAF (obj.valueNormalized) which has the sole purpose of letting you draw a slider value position without worrying about skew.

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

                        28

                        Online

                        1.8k

                        Users

                        12.1k

                        Topics

                        104.9k

                        Posts