HISE Logo Forum
    • Categories
    • Register
    • Login

    value and 1-value

    Scheduled Pinned Locked Moved Scripting
    11 Posts 3 Posters 1.2k 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.
    • Dan KorneffD
      Dan Korneff
      last edited by

      Hey guys,
      Is there a doc that would help me understand the usage of value and 1-value ?
      I can see that when scripting buttons, value is equal to 1 and 1-value is equal to 0. But I'm unable to just use 1 or 0... or even true of false.
      For instance: this works

      inline function onButton5Control(component, value)
      {
          if(value)
              { 
      	// call function here
      	}	
      };
      
      Content.getComponent("Button5").setControlCallback(onButton5Control);
      

      But this doesn't:

      inline function onButton5Control(component, value)
      {
          if(Button5 == 0)
              { 
      	// call function here
      	}	
      };
      
      Content.getComponent("Button5").setControlCallback(onButton5Control);
      

      Dan Korneff - Producer / Mixer / Audio Nerd

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

        @dustbro 1-value is just a bit of maths.

        When you click a button it will change state. So if it was 1 it will become 0, if it was 0 it will become 1.

        You use 1-value when you want to flip the result.

        So if the value of the button is 1 1-value = 0 because it's 1 - 1. If the value of the button is 0 1-value = 1 because 1-0 is 1.

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

        Dan KorneffD 1 Reply Last reply Reply Quote 1
        • Dan KorneffD
          Dan Korneff @d.healey
          last edited by

          @d-healey Ok thanks! that makes sense.
          Can you enlighten me on why if(Button5 == 0) doesn't work?

          Dan Korneff - Producer / Mixer / Audio Nerd

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

            @dustbro Do you have a variable called Button5?

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

            Dan KorneffD 1 Reply Last reply Reply Quote 0
            • Dan KorneffD
              Dan Korneff @d.healey
              last edited by

              @d-healey yes.
              const var Button5 = Content.getComponent("Button5");

              Dan Korneff - Producer / Mixer / Audio Nerd

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

                @dustbro said in value and 1-value:

                Could you share your whole script?

                Also why this Content.getComponent("Button5").setControlCallback(onButton5Control);? If you have it in a variable already, why not Button5.setControlCallback(onButton5Control);?

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

                Dan KorneffD 1 Reply Last reply Reply Quote 0
                • Dan KorneffD
                  Dan Korneff @d.healey
                  last edited by

                  @d-healey said in value and 1-value:

                  @dustbro said in value and 1-value:
                  Also why this Content.getComponent("Button5").setControlCallback(onButton5Control);? If you have it in a variable already, why not Button5.setControlCallback(onButton5Control);?

                  I think that's a better question for @Christoph-Hart. From the Interface Canvas, I select an object, right click and select "Create custom callback for selection", and then paste that into the script editor.
                  For instance: when I right click on Button5 and select "Create custom callback for selection" it copies the following code into clipboard..

                  
                  inline function onButton5Control(component, value)
                  {
                  	//Add your custom logic here...
                  };
                  
                  Content.getComponent("Button5").setControlCallback(onButton5Control);
                  

                  Dan Korneff - Producer / Mixer / Audio Nerd

                  1 Reply Last reply Reply Quote 0
                  • Dan KorneffD
                    Dan Korneff
                    last edited by

                    Here's the full code. It's a simple test I'm using to show/hide objects.

                    Content.makeFrontInterface(600, 500);
                    
                    const var Button1 = Content.getComponent("Button1");
                    const var Knob1 = Content.getComponent("Knob1");
                    const var Button2 = Content.getComponent("Button2");
                    const var Button5 = Content.getComponent("Button5");
                    
                    const var Button3 = Content.getComponent("Button3");
                    const var Knob2 = Content.getComponent("Knob2");
                    const var Button4 = Content.getComponent("Button4");
                    const var Button6 = Content.getComponent("Button6");
                    
                    // Save the controls into arrays
                    
                    const var page1 = [Content.getComponent("Button1"),
                                       Content.getComponent("Knob1"),
                                       Content.getComponent("Button2")];
                    
                                       
                    const var page2 = [Content.getComponent("Button3"),
                                       Content.getComponent("Knob2"),
                                       Content.getComponent("Button4")];
                                       
                    const var page3 = []
                                       
                    inline function showPage(pageIndex)
                    {
                        for(k in page1) 
                        {
                            k.showControl(pageIndex == 0);
                        }
                        
                        for(k in page2) 
                        {
                            k.showControl(pageIndex == 1);
                        }
                        
                        for(k in page3) 
                        {
                            k.showControl(pageIndex == 2);
                        }
                    }
                    
                    showPage(2);
                    
                    inline function onButton5Control(component, value)
                    {
                        Button6.setValue(0);
                        if(value)
                            { 
                    	    showPage(0); // just call the other function here
                    	    }
                        else if(1-value)
                        {
                            showPage(2);
                        }
                    	
                    };
                    
                    Content.getComponent("Button5").setControlCallback(onButton5Control);
                    
                    
                    
                    
                    inline function onButton6Control(component, value)
                    {
                        Button5.setValue(0);
                        if(value)
                    	    showPage(1); // just call the other function here
                    	    else if(1-value)
                        {
                            showPage(2);
                        }
                    };
                    
                    Content.getComponent("Button6").setControlCallback(onButton6Control);
                    

                    Dan Korneff - Producer / Mixer / Audio Nerd

                    1 Reply Last reply Reply Quote 0
                    • Dan KorneffD
                      Dan Korneff
                      last edited by

                      and... the above works just fine. But in some instances, I don't need to check the status of a button. I just wanna set it's value when an action happens.

                      Dan Korneff - Producer / Mixer / Audio Nerd

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

                        inline function onButton5Control(component, value)
                        {
                            if(Button5 == 0)
                                { 
                        	// call function here
                        	}	
                        };
                        

                        You need to check the value not Button5, that's just the variable that stores the control so you need either Button5.getValue() or just value since you get the control's value from the function parameters (component, value).

                        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

                          @dustbro said in value and 1-value:

                          If you have it in a variable already, why not Button5.setControlCallback(onButton5Control);?

                          Because the copy to clipboard function is not smart enough to know whether you defined the variable already so it uses this format to make sure that it works if you paste it like this. There's a minimal overhead because it has to look again for the control but this is only when loading the script and takes about 1-2ms so it shouldn't be too drastic.

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

                          53

                          Online

                          1.7k

                          Users

                          11.7k

                          Topics

                          101.8k

                          Posts