Forum

    • Register
    • Login
    • Search
    • Categories

    How do you use onControl(number,value)?

    Scripting Forum
    5
    6
    577
    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.
    • E
      elanhickler last edited by

      function onControl(number, value)
      {
      	v = Knob.getValue();
      
      	if (v < third)
      	{
      		changeKeyColor(red);
      	}
      	else if(inRange(v,third,third*2))
      	{
      		changeKeyColor(yellow);
      	}
      	else
      	{
      		changeKeyColor(blue);
      	}
      }
      
      

      What's up with the (number, value)? What do you do when you have multiple controls? I would have guessed that number is the control ID and value is the control value, but it doesn't seem to work like that.

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

        Sorry, 'number' is a bit outdated as parameter name - it is the actual interface as variable and 'value' is the current value (so you don't need Knob.getValue()). So multiple controls can be used like this:

        	if(number == Button)
        	{
        		// Do something with button
        	}
        	else if(number == Knob)
        	{
        		// Do something with Knob
        		// Also: Knob.getValue() == value
        		Console.print(value);
        	}
        
        

        I'll probably change that parameter name to "control" or something…

        1 Reply Last reply Reply Quote 0
        • Frankbeat
          Frankbeat last edited by

          Can somebody please help me with this? I'd like to control the Amp Decay of 2 samplers simultaneously by turning one single knob. From what I understand, this must be scripted in the onControl callback. So I tried:

          const var SAMPLER1env = Synth.getModulator("SAMPLER1env");
          const var SAMPLER2env = Synth.getModulator("SAMPLER2env");
          
          function onControl(number, value) {
          
          	switch(number)	{
          		case decayKnob:	{
          			SAMPLER1env.setAttribute(Decay,	value);
          			SAMPLER2env.setAttribute(Decay,	value);
          			break;}
          		case sustainKnob //… and other parameters the same way
          	};
          }
          

          But it is giving me the error:

          ! onControl() - Line, column: API call with undefined parameter 0
          

          Am I using the wrong handler by .setAttribute() or is my syntax wrong?

          I'm not a developer

          d.healey Lindon 2 Replies Last reply Reply Quote 0
          • d.healey
            d.healey @Frankbeat last edited by d.healey

            @Frankbeat Hi don't use onControl. It's a left over from early versions of HISE. Use a dedicated control callback for your controls instead, I demonstrate this in most videos.

            The error could be because you haven't defined Decay. But you probably should use a built in constant here, e.g. myModule.Decay

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

            1 Reply Last reply Reply Quote 1
            • Lindon
              Lindon @Frankbeat last edited by Lindon

              @Frankbeat - so as David says - like this:

              SAMPLER1env.setAttribute(SAMPLER1env.Decay,value);
              

              But really a giant onControl function is probably a bad way to divide up your code - whats wrong with using the custom callback for each control?

              
              inline function onDecayControl(component, value)
              {
              	SAMPLER1env.setAttribute(SAMPLER1env.Decay, value);
              	SAMPLER2env.setAttribute(SAMPLER2env.Decay, value);
              };
              Content.getComponent("Decay").setControlCallback(onDecayControl);
              
              
              inline function onReleaseControl(component, value)
              {
              	SAMPLER1env.setAttribute(SAMPLER1env.Release, value);
              	SAMPLER2env.setAttribute(SAMPLER2env.Release, value);
              };
              Content.getComponent("Release").setControlCallback(onReleaseControl);
              
              // etc. etc..
              

              HISE Development for hire.
              www.channelrobot.com

              Frankbeat 1 Reply Last reply Reply Quote 1
              • Frankbeat
                Frankbeat @Lindon last edited by

                @Lindon Thanks, Lindon! That's the way I ended up doing it now after watching David's video Playing with Knobs.

                I'm not a developer

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

                10
                Online

                1.1k
                Users

                6.8k
                Topics

                62.3k
                Posts