HISE Logo Forum
    • Categories
    • Register
    • Login

    How to Invert a Set of Button Values with a Single Click?

    Scheduled Pinned Locked Moved Scripting
    6 Posts 2 Posters 477 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.
    • ILIAMI
      ILIAM
      last edited by

      I aim to create a button that flips the values of a series of associated buttons. So, a 0 state will become 1, and a 1 state will become 0.

      Content.makeFrontInterface(200, 300);
      
      
      
      const var Buttons = Content.getAllComponents("Button");
      const var FlipMode = Content.getComponent("FlipMode");
      
      inline function onFlipModeControl(component, value)
      {
      
          if (value == 1)
          {
              for (i = 0; i < Buttons.length; i++)
              {
                  
              }
          }
      };
      
      Content.getComponent("FlipMode").setControlCallback(onFlipModeControl);
      
      
      
      HiseSnippet 968.3ocsVstaaaCElxIpXVcoXEXO.B4WJqEAx2pSPWPciSbqQqSMl6JV+UAsDkEQnHEjnRmQQd+5iSeC5NTWrjqctXuM9GoykOd93gGdHGGIbHwwhHjlw6mGRPZ+r9j4boeeeLkiFdFR6Q5ivwRRjYlpSmGhiiItHMscdkRgV8cQoiu8hSwLL2gTpBg9ff5PdKMfJK0Nt2anL1.rK48zfJd2t2PGAuufIR.9ritMJD6bIdF4BrxsZ5nWii8QZ+ldW6isaQNtiKA25nVcZXiOtqW6Vt1tSwccOposWmmMsKwCo8fycoRQzDIVRhgI8Tg67I9hOyyBvGnwzoLhRnAZBD4L0n99Tl63hjSLBos63xT0NYopeUeD0ktPeYJ6WRMXVhnZRSq1sQoFa.kzpPocynzi0m3DQCkkVT74g5C4vNnGF1apRkLeQ0NrldeA3AWdX.9RxfHPXABql11O0rks8AO2.FvNTrz7Jbj4oIRIHXdhYA3YD4KYr9hfPAGjis1Oym8Ank3FvngiDtjkAt.k09ENnfYP4LJmX5kvcjTA2TvKLq.GIXVNEHeJL8rDxAFeYOi8LLgA0yzJUm4ImX13fLkeI6iZ3IhLsn.QretI072KVRGxH7YReP2SdxAkdWAnZTJcc1uWabMP36ZMcXrxPJ06iYroPIt0JKJ0JuxR9Bgj7NtErxLpabsg4OZxyas1xmLFIZslUm9htMfV7jfojnx7ZliP01xkvO39UB6jkYp3nfOjSkuKjjKOPvbUklp+WsfGkmZUmFyYH3pLsv+Q4E9Y6fHJLI00yDZfRoe0tRnM.dy+cva+iv+1K1D3cVC7+b3YXIV0.HOg.IoPRjjp1KzNibEzxMqcPc8yHwWJEgHM8EEiv908Hm82UWvyqJ7YpqD5Bqq4BB9D5LeYgDZiBRypA4i81lfT+FChgdwQpaboP6sHJecknDiuhLjONh.GWU8JIbLTRq5q+VBNhqTQiGIB.ZfifIUq1ls3aeiz5i89OKC24Fyv2dPV8hE3JMgaBCKW9dN0K.xM.cNV5xE0EH7Xpbd0Z2M3xO6a8xu6KEer9Xpzwe8br1Z3Hbr5+CNl+jg8zO2yi3HKI3t5C9qs88A2Q3+CQhjxmMBKinPcf9EIASfmV4Pfny4DVrZ+tlplJS1VIqx.SHb2TguCibiMTxZ4FaTXDEfchDexIqgl5QI+TpFfS7zGsUGd8HHatllvAvYoO43r7TsBvlaKvVaKv1aKvNaKvmss.6ts.O5tApZ08xDoHH6XCBMZ74o26nocdZuvzpUz+z4hCoB
      
      1 Reply Last reply Reply Quote 0
      • ILIAMI
        ILIAM
        last edited by

        Is this Good:

        inline function onFlipModeControl(component, value)
        {
        	local invVal = 1-value;
        	
            if (value == 1)
            {
                for (i = 0; i < Buttons.length; i++)
                {
                    Buttons[i].setValue(Buttons[i].getValue() == invVal);
                    Buttons[i].changed();
                }
            }
        };
        
        Content.getComponent("FlipMode").setControlCallback(onFlipModeControl);
        
        d.healeyD 1 Reply Last reply Reply Quote 0
        • d.healeyD
          d.healey @ILIAM
          last edited by

          @ILIAM said in How to Invert a Set of Button Values with a Single Click?:

          Is this Good:

          That's only going to apply if the button is 1 (because of your if statement).

          inline function onFlipModeControl(component, value)
          {
              for (x in buttons)
              {
                  x.setValue(!x.getValue());
                  x.changed();
              }
          };
          

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

          ILIAMI 1 Reply Last reply Reply Quote 1
          • ILIAMI
            ILIAM @d.healey
            last edited by

            @d-healey said in How to Invert a Set of Button Values with a Single Click?:

            t's only going to apply if the button is 1 (because of your if statement).

            Very nice :) Thank you
            Yeah, I want this to act as a momentary

            so :

            	if(value)
            	{
            		for (x in Buttons)
            		{
            		    x.setValue(!x.getValue());
            		    x.changed();
            		}	
            	}
            
            d.healeyD 1 Reply Last reply Reply Quote 1
            • d.healeyD
              d.healey @ILIAM
              last edited by

              @ILIAM

              I'd do it like this, same thing but less nesting

              inline function onFlipModeControl(component, value)
              {
                  if (!value)
                      return;
              
                  for (x in buttons)
                  {
                      x.setValue(!x.getValue());
                      x.changed();
                  }
              };
              

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

              ILIAMI 1 Reply Last reply Reply Quote 1
              • ILIAMI
                ILIAM @d.healey
                last edited by

                @d-healey Very Nice, thank you so much

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

                21

                Online

                1.8k

                Users

                11.9k

                Topics

                104.0k

                Posts