Forum

    • Register
    • Login
    • Search
    • Categories

    Script to link/unlink knobs, update with callback help

    Scripting Forum
    2
    3
    642
    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.
    • dustbro
      dustbro last edited by

      Hey guys,
      I'm trying to link Gain of 2 SimpleGain effects with one Knob via a Button.

      When Button = 1 , both effects Gain controls are linked to Knob
      When Button = 0 , Gain1 is controlled by Knob, Gain2 is set to -100
      Here's what I got so far, which works... But the gain of Gain2 does not update until the "Level" Knob is turned.
      Do I need to add a callback to my Button?

      // get value of Button
      inline function onButtonControl(component, value)
      {
      	var w = Button.getValue();
      };
      
      Content.getComponent("Button").setControlCallback(onButtonControl);
      
      inline function onLevelControl(component, value)
      {
              if (w == 1)
                  {
                  Gain1.setAttribute(Gain1..Gain, value);
      	        
      	        local g =Gain1.getAttribute(0);
      	        Gain2.setAttribute(Gain2.Gain, g);
                  }
              
             else if (w == 0)
                  {
                  Gain1.setAttribute(Gain1.Gain, value);
      	        Gain2.setAttribute(Gain2.Gain, -100);
                  }
      
      };
      
      Content.getComponent("Level").setControlCallback(onLevelControl);
      
      

      Dan Korneff - Producer / Mixer / Audio Nerd

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

        What you need to do here is to call the same function for both control callbacks. The prettiest way to do this is to reuse the inline function for both controls:

        const var SimpleGain = Synth.getEffect("Simple Gain");
        const var SimpleGain2 = Synth.getEffect("Simple Gain2");
        
        const var Button1 = Content.getComponent("Button1");
        const var Knob1 = Content.getComponent("Knob1");
        
        inline function update(unusedComponentParameter,
                               unusedValueParameter)
        {
            local value = Knob1.getValue();
            local mode = Button1.getValue();
            
            if(mode)
            {
                SimpleGain.setAttribute(SimpleGain.Gain, value);
                SimpleGain2.setAttribute(SimpleGain2.Gain, value);
            }
            else
            {
                SimpleGain.setAttribute(SimpleGain.Gain, value);
                SimpleGain2.setAttribute(SimpleGain2.Gain, -100);
            }
        }
        
        Button1.setControlCallback(update);
        Knob1.setControlCallback(update);
        

        As you can see, we ignore the parameters of the function (it still needs 2 parameters to compile) and grab the actual values directly from the components.

        1 Reply Last reply Reply Quote 2
        • dustbro
          dustbro last edited by

          @Christoph-Hart Super clean solution!

          Dan Korneff - Producer / Mixer / Audio Nerd

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

          23
          Online

          793
          Users

          5.5k
          Topics

          51.6k
          Posts