HISE Logo Forum
    • Categories
    • Register
    • Login

    onControl nested functions?

    Scheduled Pinned Locked Moved Scripting
    6 Posts 3 Posters 1.0k 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.
    • ulrikU
      ulrik
      last edited by

      I have some problems with my setup, I'll explain.
      I have 5 buttons (B1,B2,B3,B4 and B5), connected to same radiogrupp so that only one button has value 1
      I have 4 Samplers (S1,S2,S3 and S4)
      This is what I want to accomplish:

      if B1 = S1 enabled
      if B2 = S2 enabled
      if B3 = S2, S3 and S4 enabled
      if B4 = S1 and S2 enabled
      if B5 = S2 and S4 enabled
      I'm trying to set this up in "OnControl" callback but I can't get B3 - B5 to work, do I have to have some "nested" functions? I'm lost or tired or both.... :)

      Hise Develop branch
      MacOs 15.3.1, Xcode 16.2
      http://musikboden.se

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

        Put all of your samplers in an array. Put all of your buttons in an array. Create a callback function and apply it to all of the buttons. In the callback get the array index of the button that triggered the callback, this will give you the number of the currently selected radio button and you can use this as the index of the samplers array to enabled the correct sampler.

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

        ulrikU 1 Reply Last reply Reply Quote 1
        • ulrikU
          ulrik @d.healey
          last edited by

          @d-healey My god, it took you 6 minutes to answer that, you're fast!!I :)
          Thank you, I'll learn the array stuff after some sleep.
          Great forum!!

          Hise Develop branch
          MacOs 15.3.1, Xcode 16.2
          http://musikboden.se

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

            // Use a 2-dimensional array to store the configuration
            const var samplerStates = [[1, 0, 0, 0],
                                       [0, 1, 0, 0],
                                       [0, 1, 1, 1],
                                       [1, 1, 0, 0],
                                       [0, 1, 0, 1]];
            
                                       
            // Store all samplers in an array
            const var Samplers = [Synth.getChildSynth("Sampler1"),
                                  Synth.getChildSynth("Sampler2"),
                                  Synth.getChildSynth("Sampler3"),
                                  Synth.getChildSynth("Sampler4")];
                                       
            // Store all buttons in an array
            const var Buttons = [Content.getComponent("Button1"),
                                 Content.getComponent("Button2"),
                                 Content.getComponent("Button3"),
                                 Content.getComponent("Button4"),
                                 Content.getComponent("Button5")];
            
            inline function buttonCallback(component, value)
            {
                // If buttons are in a radio group, the callback will
                // be triggered for every button so this makes sure
                // that we only handle the pressed button
                if(value)
                {
                    // get the index from the Button array
                    // this allows us to only write one callback for all buttons
                    local index = Buttons.indexOf(component);
                    
                    for(i = 0; i < 4; i++)
                    {
                        // Enable each sampler based on the configuration
                        Samplers[i].setBypassed(1 - samplerStates[index][i]);
                    }
                }
            }
            
            // give every button the same callback
            for(b in Buttons)
                b.setControlCallback(buttonCallback);
            
            ulrikU 2 Replies Last reply Reply Quote 2
            • ulrikU
              ulrik @Christoph Hart
              last edited by

              @christoph-hart Yes. as I said before, what a great forum !!
              Thank you Christoph! I am grateful for the code, I will study it and learn :)
              Cheers!

              Hise Develop branch
              MacOs 15.3.1, Xcode 16.2
              http://musikboden.se

              1 Reply Last reply Reply Quote 0
              • ulrikU
                ulrik @Christoph Hart
                last edited by

                @christoph-hart This works beautiful, I even made a compliment to this using 5 leds that lights up for each button, however I than had to make the ledStates with 5 columns instead of 4, and use:
                "for(i = 0; i <5; i++)
                {
                Lamps[i].setValue(!value == 1 - lampStates[index][i]);
                }
                and it works fine.

                Now to another question, I have 3 different states of the keyboard as well, and I want to set them with the same buttons as the samplers (I have key switches on some keys with coloured keys, and I want to show them and also the key range for that instrument, only in one of the buttons states.
                Is there some tutorial or document around that I can study for this matter?

                Hise Develop branch
                MacOs 15.3.1, Xcode 16.2
                http://musikboden.se

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

                11

                Online

                1.8k

                Users

                11.9k

                Topics

                103.8k

                Posts