HISE Logo Forum
    • Categories
    • Register
    • Login

    Master Bypass Button

    Scheduled Pinned Locked Moved General Questions
    38 Posts 5 Posters 1.7k 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

      bypassArray[0] = Content.getComponent("Button1");
      bypassArray[1] = Content.getComponent("Button2");
      bypassArray[2] = Content.getComponent("Button3");
      bypassArray[0] = value;
      bypassArray[1] = value;
      bypassArray[2] = value;
      

      More crazy code :p

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

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

        as @d-healey says. Use your variables, not strings.

        const var moduleArray = [SINE1, SINE2, SINE3];

        Dan Korneff - Producer / Mixer / Audio Nerd

        1 Reply Last reply Reply Quote 0
        • ustkU
          ustk @DanH
          last edited by ustk

          @DanH Ok so many things going on here

          First, the error you get is because what you stored in moduleArray are strings, not the variables you declared at the top

          Then another error, why are you declaring the buttons a second time in bypassArray, and why are you overwriting it again with value?

          bypassArray should be at the top too (like all declarations actually) and kept empty until the buttons callback are feeding it

          So this is better:

          const var SINE1 = Synth.getChildSynth("SINE1");
          const var SINE2 = Synth.getChildSynth("SINE2");
          const var SINE3 = Synth.getChildSynth("SINE3");
          
          const var moduleArray  = [SINE1, SINE2, SINE3];
          

          Even better so you declare directly the array of modules

          const var moduleArray = [Synth.getChildSynth("SINE1"),
                                   Synth.getChildSynth("SINE2"),
                                   Synth.getChildSynth("SINE3")];
          

          and then the buttons have the same treatment:

          const var buttonsArray = [Content.getComponent("Button1"),
                                    Content.getComponent("Button2"),
                                    Content.getComponent("Button3")];
          
          const var moduleArray = [Synth.getChildSynth("SINE1"),
                                   Synth.getChildSynth("SINE2"),
                                   Synth.getChildSynth("SINE3")];
          
          const var bypassArray  = [];
          

          Now we are going to feed bypassArray
          Before, you would have done this (temporarily, to show the progress):

          inline function onButton1Control(component, value)
          {
          	SINE1.setBypassed(1- value);
          	bypassArray[0] = value;
          };
          Content.getComponent("Button1").setControlCallback(onButton1Control);
          
          
          inline function onButton2Control(component, value)
          {
          	SINE2.setBypassed(1- value);
          	bypassArray[1] = value;
          };
          Content.getComponent("Button2").setControlCallback(onButton2Control);
          
          
          inline function onButton3Control(component, value)
          {
          	SINE3.setBypassed(1- value);
          	bypassArray[2] = value;
          };
          Content.getComponent("Button3").setControlCallback(onButton3Control);
          

          But instead, you can use only one callback for all the buttons

          inline function onBypassButtonsControl(component, value)
          {
              var btnIdx = buttonsArray.indexOf(component);
              
              moduleArray[btnIdx].setBypassed(value);
              bypassArray[btnIdx] = value;
          };
          for (b in buttonsArray) b.setControlCallback(onBypassButtonsControl);
          

          So we put altogether:

          const var buttonsArray = [Content.getComponent("Button1"),
                                    Content.getComponent("Button2"),
                                    Content.getComponent("Button3")];
          
          const var moduleArray = [Synth.getChildSynth("SINE1"),
                                   Synth.getChildSynth("SINE2"),
                                   Synth.getChildSynth("SINE3")];
          
          const var bypassArray  = [];    // The array that stores the buttons states (bypass)
          
          // INDIVIDUAL BYPASSES
          inline function onBypassButtonsControl(component, value)
          {
              var btnIdx = buttonsArray.indexOf(component);   // Which button has been clicked
              
              moduleArray[btnIdx].setBypassed(value);         // Set the corresponding module bypass
              bypassArray[btnIdx] = value;                    // Store the individual states
          };
          for (b in buttonsArray) b.setControlCallback(onBypassButtonsControl);
          
          
          // MASTER BYPASS
          inline function onmasterControl(component, value)
          {
              for (i=0; i<buttonsArray.length; i++)
              {
                  if (value)                                      // If Master bypass ON
                      moduleArray[i].setBypassed(true);           // Set all to bypass
                  else
                      moduleArray[i].setBypassed(bypassArray[i]); // Or restore their original state from the array
              }
          };
          Content.getComponent("master").setControlCallback(onmasterControl);
          

          And the final snippet:

          HiseSnippet 1461.3oc6Y0saaaCEVJNps1ctXcnWrKIB1E1ncoNNscCvqn1wwdvX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qCiJ6NlvtHYKqXhDDvxEiJ3WRs70shkuLaGrnfJUdmXEDKMjSVUg0Uv7puq4w.YIMe2Ld6Oqy9XIVoCGuhfU4XhPRUDn89jyfBbLpx4c1mDcpjOF3444NvuWhE84yek+Z85SWznUcqqjmplvS0II7j0U0S6lvSuUbwdx4B8zMbL6KRBovDN52NsdD9LRGVOXGJQppTw5uVpCTvkZGOVltJLUomwC.Y9oJ2QURCKhJmlLL9AozrkEt21oGU5MJa7tQF3Ex19Pi23BcK5zZ3PhmbAX2zo8O8gup1jP4VFnbSGWPzSWpjFHW2QWeVJtJ8MN98k8FGiW5abz0SB4jGIvLnfhnTN1kDROBx5iR14yhf5nI+beUXMY+M4XQlC81mzFVkYZiKVNQnyOZDxmvjoxGxszAgqvMe17e0274i2oA4VN39dtbV9YXzkFNNfzhcFI.jJzX7K.sgg3IAxY8lJuN2AbFe7HNi5kLn2mHEzSNgHRh8LWPMjRnTjE8bm58IADbxD3up9SgDOr.3IxJxE6r7bwkEu9RGCbQpMinOMNEO2+OOEuOehDtz0AXHQEj4cNbRnKbVpGAPBiAEuC8Yug57PS6Jp1lCSY95F+A7DO3Np11wCtyrAWZkhpWx2lZsRwZkh+qpTTcsRwZkh0JE+CpTr656TrVo3SPkhcWqTrVoXsRwRnT7w3cDh8D7W4Y95ypb4an6AV2L8+O67NGnZil+IucbprcEqP3DwW44on6uF3mrso5JXytqfMOXEr4gqfMOZEr4aVAa91K0FkXTiIRdnYqHzQuV5O9uscKFFxj0Y8V+I7haMR
          

          Can't help pressing F5 in the forum...

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

            @ustk You missed an opportunity, you could use a single callback for all the buttons ;)

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

            ustkU 1 Reply Last reply Reply Quote 0
            • ustkU
              ustk @d.healey
              last edited by

              @d-healey That is what I did, except for the master bypass, but I don't want to complicate it more for @DanH
              Or I don't get what you mean?

              Can't help pressing F5 in the forum...

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

                @ustk Oh so you did! I read through it too quickly :D

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

                DanHD 1 Reply Last reply Reply Quote 1
                • DanHD
                  DanH @d.healey
                  last edited by

                  @d-healey @ustk @dustbro Thanks guys, I told you I find it confusing! this is going to really help me learn :)

                  DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
                  https://dhplugins.com/ | https://dcbreaks.com/
                  London, UK

                  ustkU 1 Reply Last reply Reply Quote 1
                  • ustkU
                    ustk @DanH
                    last edited by ustk

                    @DanH I just updated the snippet above with some comments ;)

                    Can't help pressing F5 in the forum...

                    DanHD 1 Reply Last reply Reply Quote 1
                    • DanHD
                      DanH @ustk
                      last edited by

                      @ustk :folded_hands: on Daddy duty until tomorrow afternoon so look forward to learning it all then :)

                      DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
                      https://dhplugins.com/ | https://dcbreaks.com/
                      London, UK

                      DanHD 1 Reply Last reply Reply Quote 0
                      • DanHD
                        DanH @DanH
                        last edited by DanH

                        @ustk Thanks again for doing this, super helpful I have a few questions if that's ok?! Feel free to answer whatever you feel like by the way!

                        • Declarations: So I'm declaring the modules and buttons outside of Arrays because I'll most likely need to refer to them in other parts of the script. As far as I can work out, only declaring them inside of an array prevents me from referring to them in other functions - is that correct? Otherwise this is a very neat solution :)

                        • bypassArray: In the first example of the bypassArray, the line inside the callback 'bypassArray[0/1/2/3etc] = value;' will load the '= value' value into the index of the array, is that right? So if the value was say, 59, and the index number is 0, then the first value in the array is 59?

                        • bypassArray example 2: 'var btnIdx = buttonsArray.indexOf(component); - nice, I haven't seen this before, I assume I can use this in the same way for other Arrays? However the last line 'for (b in buttonsArray) b.setControlCallback(onBypassButtonsControl);' is confusing to me... I've not seen a callback like that before. What does the 'for' do, and likewise. what is the 'b' for?

                        • Lastly, I'd like the buttons to all switch off as well, and then return to their previous state like the modules do. I've tried adding buttonsArray.setValue(1); but can see that's probably not going to work (and doesn't!). Make a second array for the buttons? Have a duplicate set of buttons which are linked?

                        Like I said, thanks so much for this, even just typing these questions is helping me get a grasp of it all.

                        DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
                        https://dhplugins.com/ | https://dcbreaks.com/
                        London, UK

                        d.healeyD LindonL ustkU 3 Replies Last reply Reply Quote 0
                        • d.healeyD
                          d.healey @DanH
                          last edited by d.healey

                          @DanH said in Master Bypass Button:

                          As far as I can work out, only declaring them inside of an array prevents me from referring to them in other functions - is that correct?

                          An array is just another type of variable, you can refer to your modules from the array variables or from individual variables. You don't need to use both.

                          'var btnIdx = buttonsArray.indexOf(component); - nice, I haven't seen this before

                          You should watch more of my videos ;)

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

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

                            @DanH said in Master Bypass Button:

                            the last line 'for (b in buttonsArray) b.setControlCallback(onBypassButtonsControl);' is confusing to me... I've not seen a callback like that before. What does the 'for' do, and likewise. what is the 'b' for?

                            Please go read up about Javascript - this is standard notation....

                            This interwebs is full of explanation for this sort of thing:

                            Link Preview Image
                            W3Schools.com

                            Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.

                            favicon

                            (www.w3schools.com)

                            HISE Development for hire.
                            www.channelrobot.com

                            DanHD 1 Reply Last reply Reply Quote 1
                            • DanHD
                              DanH @d.healey
                              last edited by

                              @d-healey ha I do... but there's a lot to take in when learning for the first time. I have to rewatch them from time to time when I've learned more, and they make more sense to me.

                              DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
                              https://dhplugins.com/ | https://dcbreaks.com/
                              London, UK

                              1 Reply Last reply Reply Quote 1
                              • DanHD
                                DanH @Lindon
                                last edited by

                                @Lindon good site thanks

                                DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
                                https://dhplugins.com/ | https://dcbreaks.com/
                                London, UK

                                1 Reply Last reply Reply Quote 0
                                • ustkU
                                  ustk @DanH
                                  last edited by

                                  @DanH said in Master Bypass Button:

                                  • Declarations: So I'm declaring the modules and buttons outside of Arrays because I'll most likely need to refer to them in other parts of the script. As far as I can work out, only declaring them inside of an array prevents me from referring to them in other functions - is that correct? Otherwise this is a very neat solution :)

                                  As Dave said, you don't need to use both, but you can if it's better for your implementation. You can also just keep the array style and refer to them later in the script with moduleArray[x]

                                  • bypassArray: In the first example of the bypassArray, the line inside the callback 'bypassArray[0/1/2/3etc] = value;' will load the '= value' value into the index of the array, is that right? So if the value was say, 59, and the index number is 0, then the first value in the array is 59?

                                  I'm not sure of what you ask. value is the value of the button you pressed. it will be stored in bypassArray at the index btnIdx, so the one corresponding of the button pressed. Play with the buttons and watch the bypassArray content changing in the ScriptWatchTable tile, it'll make sense to you...

                                  • bypassArray example 2: 'var btnIdx = buttonsArray.indexOf(component); - nice, I haven't seen this before, I assume I can use this in the same way for other Arrays? However the last line 'for (b in buttonsArray) b.setControlCallback(onBypassButtonsControl);' is confusing to me... I've not seen a callback like that before. What does the 'for' do, and likewise. what is the 'b' for?

                                  Like @Lindon said, go learn more javascript related stuff, try to find exercises online, it helps a lot...
                                  for the moment I can just tell you that this is equivalent to:

                                  buttonsArray[0].setControlCallback(onBypassButtonsControl);
                                  buttonsArray[1].setControlCallback(onBypassButtonsControl);
                                  buttonsArray[1].setControlCallback(onBypassButtonsControl);
                                  

                                  Or,

                                  for (i=0; i< buttonsArray.length)
                                      buttonsArray[i].setControlCallback(onBypassButtonsControl);
                                  

                                  but for/in is better isn't it? ;)

                                  • Lastly, I'd like the buttons to all switch off as well, and then return to their previous state like the modules do. I've tried adding buttonsArray.setValue(1); but can see that's probably not going to work (and doesn't!). Make a second array for the buttons? Have a duplicate set of buttons which are linked?

                                  So you mean the opposite of Master Bypass? In this case, just do the same thing using moduleArray[i].setBypassed(false); instead of true
                                  With all of this, you can now even make a single callback for the Master Bypass/unbypass buttons, since the only difference is true/false. Just use the indexOf magic trick to determine which button has been clicked, and then if you should use true or false (there's even something shorter but I'll let you find your way with a simple IF statement first ;) )

                                  Can't help pressing F5 in the forum...

                                  DanHD 1 Reply Last reply Reply Quote 0
                                  • DanHD
                                    DanH @ustk
                                    last edited by

                                    @ustk Thanks mate! Making a lot more sense now :)

                                    So my last question: I just want the buttons to do the same as the modules - they all turn off when you press the master button, and then they return to the state they were in before you pressed. So doing exactly the same as the modules.

                                    This is because the buttons are on the ui, and need to show that the modules are off (otherwise the user can't see it). Does that make sense? Becasue buttonsArray is already in the callback I don't think it can be used again...

                                    And I will try to figure out the quicker method, give me a few weeks :face_with_tears_of_joy:

                                    DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
                                    https://dhplugins.com/ | https://dcbreaks.com/
                                    London, UK

                                    ustkU 1 Reply Last reply Reply Quote 0
                                    • ustkU
                                      ustk @DanH
                                      last edited by ustk

                                      @DanH so just add them to the Master callback

                                      inline function onmasterControl(component, value)
                                      {
                                          for (i=0; i<buttonsArray.length; i++)
                                          {
                                              if (value)                                      // If Master bypass ON
                                              {
                                                  moduleArray[i].setBypassed(true);           // Set all to bypass
                                                  buttonsArray[i].setValue(true);
                                              }
                                              else
                                              {
                                                  moduleArray[i].setBypassed(bypassArray[i]); // Or restore their state from the array
                                                  buttonsArray[i].setValue(bypassArray[i]);
                                              }
                                          }
                                      };
                                      Content.getComponent("master").setControlCallback(onmasterControl);
                                      

                                      But this is weird because then the user can change individual bypasses while the master is still enabled, so the Master doesn't reflect what it should anymore and you just transferred the problem... I would prefer to hide the individual bypasses when the master is on. Another solution is to add a safety in the individual bypass callback so when you click a button, the master automatically switches off

                                      Can't help pressing F5 in the forum...

                                      DanHD 2 Replies Last reply Reply Quote 0
                                      • DanHD
                                        DanH @ustk
                                        last edited by

                                        @ustk Ah, I was trying to add buttonsArray[i].setValue(true); etc to the callback but I didn't have the extra {} - why do you have to put these in, if you don't mind my asking?

                                        Yes could be a bit weird but I think it will work for its purpose (It's an audition tool, to let the user hear what the sound is like without all the fx and modulation on it).

                                        Legend :)

                                        DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
                                        https://dhplugins.com/ | https://dcbreaks.com/
                                        London, UK

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

                                          @DanH https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/block
                                          https://github.com/davidhealey/hise_documentation/blob/master/scripting/scripting-in-hise/hise-script-coding-standards.md

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

                                          1 Reply Last reply Reply Quote 0
                                          • DanHD
                                            DanH @ustk
                                            last edited by DanH

                                            @ustk Hi mate, one last question on this! So it would be really neat if the buttons could execute whatever their functions are with this script. So then we may not need the modules array, and can add extra functionality to each button from separate callbacks. (I'm saying this because the project I'm working on is way more complicated than this snippet!)

                                            I've been trying to put in .changed(); but it changes the state of the buttons permanently, rather than referring to the bypassArray, perhaps because the values have now changed within that Array?

                                            inline function onmasterControl(component, value)
                                            {
                                                for (i=0; i<buttonsArray.length; i++)
                                                {
                                                    if (value)                                      // If Master bypass ON
                                                    {
                                                        buttonsArray[i].setValue(true);         // Set all to bypass
                                                        //buttonsArray[i].changed();
                                                    }
                                                    else
                                                    {
                                                        buttonsArray[i].setValue(bypassArray[i]);     // Or restore their state from the array
                                                        //buttonsArray[i].changed();
                                                        
                                                    }
                                                      //buttonsArray[i].changed();
                                                }
                                            };
                                            Content.getComponent("master").setControlCallback(onmasterControl);
                                            

                                            DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
                                            https://dhplugins.com/ | https://dcbreaks.com/
                                            London, UK

                                            d.healeyD 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            35

                                            Online

                                            1.7k

                                            Users

                                            11.9k

                                            Topics

                                            103.5k

                                            Posts