HISE Logo Forum
    • Categories
    • Register
    • Login

    .setPosition does not accept float?

    Scheduled Pinned Locked Moved Scripting
    10 Posts 4 Posters 338 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.
    • VirtualVirginV
      VirtualVirgin
      last edited by VirtualVirgin

      It seems that .setPosition is rounding the numbers that go into it, here producing uneven placement of keys on the x axis:

      Screenshot 2024-11-29 at 7.57.08 PM.png

      The x is being calculated by dividing the total keyboard area like so:

      //Loops for positioning the keys
      //White keys
      for (i = 0; i < Math.ceil(keyboard0.length / 12 * 7); i++)
      {
      	//Get keyboard panel area
      	var a = [KeyboardPanel0.get("x"), 
      			KeyboardPanel0.get("y"), 
      			KeyboardPanel0.get("width"), 
      			KeyboardPanel0.get("height")];
      
      	keyboard0[allWhiteKeys[i]].setPosition
      		(a[2] / 128 * (12 / 7) * i + gap, 
      		a[1] - offset,  
      		a[2] / 128 * (12 / 7) - gap, 
      		a[3] + offset * 0.333);	
      }
      

      Every time the x input is multiplied by "i" it gives a float that is getting rounded to the nearest integer, producing values that sometimes round down, and sometimes up, meaning the x interval keeps changing over the course of the loop.
      If I use ceiling or floor on the x input, it evens out the spaces but does not align properly with the total keyboard width , as the little increments add up and top of the keyboard gets wonky.

      Any reason why the inputs are rounding to integers?

      You can listen to my orchestral mockups here:
      https://www.virtualvirgin.net/

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

        @VirtualVirgin Do they show as rounded in the interface designer property editor?

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

        VirtualVirginV 1 Reply Last reply Reply Quote 0
        • VirtualVirginV
          VirtualVirgin @d.healey
          last edited by VirtualVirgin

          @d-healey said in .setPosition does not accept float?:

          @VirtualVirgin Do they show as rounded in the interface designer property editor?

          Yes, those show as rounded.
          When I checked the API it says .setPosition only takes integers so-

          I tried this instead:

          keyboard0[allWhiteKeys[i]].set("x", a[2] / 128 * (12 / 7) * i + gap / 2);
          	keyboard0[allWhiteKeys[i]].set("y", a[1] - offset);
          	keyboard0[allWhiteKeys[i]].set("width", a[2] / 128 * (12 / 7) - gap);	 
          	keyboard0[allWhiteKeys[i]].set("height", (a[3] + offset * 0.333));
          

          It sets the property by string, and shows rounding to 2 decimal points in the property editor for each key button:

          Screenshot 2024-11-29 at 11.48.45 PM.png

          But even with 100x the precision of the input, the appearance is exactly the same, with the jagged gap sizes:

          Screenshot 2024-11-29 at 11.42.18 PM.png

          Trying to set the gap size lower has very low resolution for change and this is the next lowest step it will accept:

          Screenshot 2024-11-29 at 11.42.29 PM.png

          So I can't seem to fix or fine tune the spacing.

          You can listen to my orchestral mockups here:
          https://www.virtualvirgin.net/

          Christoph HartC d.healeyD 2 Replies Last reply Reply Quote 0
          • Christoph HartC
            Christoph Hart @VirtualVirgin
            last edited by

            @VirtualVirgin yes component positions are integers so if you need subpixel stuff you need to render it within a single component.

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

              @VirtualVirgin Time to try again with a panel

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

              1 Reply Last reply Reply Quote 0
              • VirtualVirginV
                VirtualVirgin @Christoph Hart
                last edited by

                @Christoph-Hart said in .setPosition does not accept float?:

                @VirtualVirgin yes component positions are integers so if you need subpixel stuff you need to render it within a single component.

                Can I ask why?

                Maybe I'm wrong, but aren't there many use cases for spacing components the way I am (scaling/transforming multiple adjacent components from a panel area )? It seems odd to me that this then renders the use of any component for this purpose obsolete, meaning any components one has already made cannot be used (say using custom LAF sliders for a slider pack, or buttons for an input/output matrix).

                I would be nice to have a bunch of components on a panel that can just be resized, then scaled as needed on compile without the irregular spacing.

                You can listen to my orchestral mockups here:
                https://www.virtualvirgin.net/

                LindonL 1 Reply Last reply Reply Quote 0
                • LindonL
                  Lindon @VirtualVirgin
                  last edited by

                  @VirtualVirgin no there are exactly no use cases. Think about your screen it has fixed number of pixels, and can only turn them on or off, so all elements on your screen are at an integer position

                  HISE Development for hire.
                  www.channelrobot.com

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

                    Can I ask why?

                    JUCE says so (and perhaps some things in the underlying OS graphics API too but I haven't looked that far).

                    A good example how how to solve that issue is the slider pack though: if the width of the slider pack cannot be divided by numSliders to a integer, then it will calculate the "real" value and then round the position for both width and start position to the next integer:

                    float x = 0.0f;
                    
                    for (int i = 0; i < sliders.size(); i++)
                    {
                    	int thisXPos = std::floor(x);
                    
                    	auto subMod = std::fmod(x, 1.0f);
                    
                    	int thisWidth = std::floor(widthPerSlider + subMod) - 1;
                    
                    	sliders[i]->setBounds(thisXPos, 0, thisWidth, getHeight());
                    
                    	x += widthPerSlider;
                    }
                    

                    This makes the sliders not 100% equal in width (some are 1 px bigger than the others), but it keeps the distance and gap between all sliders the same which is more important.

                    You should be able to apply this trick to your keyboard component as well.

                    VirtualVirginV 1 Reply Last reply Reply Quote 1
                    • VirtualVirginV
                      VirtualVirgin @Christoph Hart
                      last edited by

                      @Christoph-Hart said in .setPosition does not accept float?:

                      You should be able to apply this trick to your keyboard component as well.

                      Ok, this is very cool!

                      I deciphered what you have here in the post and applied to my keyboard and it works!

                      Screenshot 2024-12-01 at 7.34.29 PM.png

                      Screenshot 2024-12-01 at 7.36.29 PM.png

                      You can listen to my orchestral mockups here:
                      https://www.virtualvirgin.net/

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

                        @VirtualVirgin Looking good!

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

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

                        25

                        Online

                        1.8k

                        Users

                        12.0k

                        Topics

                        104.6k

                        Posts