onControl nested functions?

  • 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.... 🙂

  • 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.

  • @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!!

  • // 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"),
    // Store all buttons in an array
    const var Buttons = [Content.getComponent("Button1"),
    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
            // 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)

  • @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 🙂

  • @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?

Log in to reply