HISE Logo Forum
    • Categories
    • Register
    • Login

    Get normalized slider value

    Scheduled Pinned Locked Moved Feature Requests
    9 Posts 2 Posters 1.8k 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

      I'm using a slider to control the volume of a container. The slider is set to dB mode -100 to 0, but the container volume attribute expects a value between 0 and 1. If I change my slider to be between 0 and 1 the value read out will no longer be correct. Could we have a function to normalize the value of the slider to 0-1?

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

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

        Two solutions:

        1. Use the SimpleGain module, which has a dB-Range for the volume. The advantage is that the volume parameter is smoothed there, so you don't get the nasty zipper effects like when controlling the sound generators gain directly.

        2. Use Engine.getGainFactorForDecibels() in your control callback to convert the dB Value of the slider to a gain factor from 0...1.

        For a mixer type control I highly recommend the first solution because of not-zippering.

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

          Aha that's good. Does the simple gain module add much CPU overhead? I'm using simple gains for my main mixer anyway but this container volume control was so I can tweak the volume of individual articulations from the UI.

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

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

            I've just added 10 Containers with 10 SimpleGain modules and it uses 15% - 20% CPU, so you have 0.1% - 0.3% CPU usage per simple gain module. Shouldn't be too problematic :)

            EDIT: However, if you rarely use it and have to write a custom callback anyway (which I think is the case since you are using a dynamic target), the Engine.getGainFactorForDecibel thing might be more practical in this scenario

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

              Is there a handy function to convert a CC value (0-127) to an attack time slider (0-20000)? I've been using v = (Message.getControllerValue() * 20000) / 127; but the resolution is poor.

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

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

                Why is the resolution poor? If you want to make sure it uses floating point precision, use decimal numbers like this:

                v = (Message.getControllerValue() * 20000.0) / 127.0
                

                There's nothing that can be more precise in Javascript :)

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

                  Maybe resolution is the wrong term. Basically if my CC is at 1 (the lowest it can be above 0) then the slider will be at 157ms which is not very good for an attack slider.

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

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

                    Ah, you need a skew factor:

                    // values > 1 will yield more resolution at the lower end
                    var skewFactor = 5.0; 
                    var normalised = Message.getControllerValue() / 127.0;
                    
                    // this will "bend" the line towards the lower end
                    var skewed = Math.pow(normalised, skewFactor);
                    var value = skewed * 20000.0;
                    

                    There are more sophisticated methods, but this is a quick'n dirty formula to give you more resolution on the lower end. Also, exchange var with the suitable variable type (I used var to be as generic as possible in this example).

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

                      Yes that looks like what I'm after. Thank you!

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

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

                      28

                      Online

                      1.7k

                      Users

                      11.8k

                      Topics

                      102.8k

                      Posts