Controlling a knob automatically from another knob

Besides it doing the same thing as my code, I believe the value will update the last value as they are always changing when the other knob changes it.

Not too sure how touch interaction works but iirc gestures (multi-touch) is not supported anyway. isHovered just being the name of the method isPressed is probably more descriptive. Even if multi-touch is supported there would be no need to call isWhatever() as you would have the control on as many fingers and knobs you can change at the same time. Plus if you were to use (on a touch device) the invert of the other to control the second there would be no need to use another finger to change that value but if you wanted to do it the other way around you would be stuck on using that first setter knob.

Sorry, I’m unable to help you if you’re just going to ignore all the advice that I give. If you can’t interpret my pseudocode above, I can write a full implementation when I have more time.

So, here it is. Tested and works as requested.

enum ParamIds {
   X,
   Y,
   NUM_PARAMS
};

float lastX;
float lastY;
float deltaX = 0;
float deltaY = 0;

Test() {
   config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);    
   onReset();

   configParam(X, -1.0f, 1.0f, 0.0f, "X");
   configParam(Y, -1.0f, 1.0f, 0.0f, "Y");
}

void process(const ProcessArgs &args) override {
   float x = params[X].getValue();
   float y = params[Y].getValue();
   if (deltaX == 0 && lastX != x) {
      deltaY = y + x;
   } 
   else {
      deltaY = 0;
   }

   if (deltaY == 0 && lastY != y) {
      deltaX = x + y;
   } 
   else {
      deltaX = 0;
   }

   params[X].setValue(x - deltaX);
   params[Y].setValue(y - deltaY);
   lastX = params[X].getValue();
   lastY = params[Y].getValue();
}

Thanks! :+1: Although you could put the setValue() calls inside the if blocks, and you don’t need any of the delta stuff, just lastX/Y.

You’re right :+1: :grinning:

float lastX = 0;
float lastY = 0;

void process(const ProcessArgs &args) override {
   float x = params[X].getValue();
   float y = params[Y].getValue();
   if (lastX != x)
      params[Y].setValue(-x);
   if (lastY != y)
      params[X].setValue(-y);
   lastX = x;
   lastY = y;
}

Thank you, much appreciated! As I said in the previous post I tried the psuedo you posted and it was doing the same as my code:

Only after seeing the solution was I able to spot it myself, There is an error with -x being in both if blocks:

if (x != lastX) {
	y = -x;
	lastX = x;
}
else if (y != lastY) {
	x = -x; //← x = -y
	lastY = y;
}

Also I was using volt1 and volt2 and passing those values to the Display, those values were messing things up as well, declaring 2 separate variables for X and Y fixes that.

@stoermelder, Vortico thanks for the solutions

Here’s what I have and it is working bar a slight glitch with the tooltip value and it gets funky when I reset either params:

///outside scope
float volt1 = 0.f;
float volt2 = 0.f;
float prevVal1, prevVal2;

void process(const ProcessArgs &args) override {
	float prevMax = 0.f, prevMin = 0.f;
		
	prevVal1 = params[MAX_PARAM].getValue();
	prevVal2 = params[MIN_PARAM].getValue();

	volt1 = params[MAX_PARAM].getValue();    //top display
	volt2 = params[MIN_PARAM].getValue();    //bottom display

	//------- one knob controls other, 
	if (params[LINKMINMAX_PARAM].getValue() < 1.f && prevVal1 != prevMax) {
		params[MIN_PARAM].setValue(-prevVal1);		
	} if (params[LINKMINMAX_PARAM].getValue() < 1.f && prevVal2 != prevMin) {
		params[MAX_PARAM].setValue(-prevVal2);
		prevMax = prevVal1;
		prevMin = prevVal2;
	}

I‘m away from computer right now, but are you sure that the last two lines should be inside the if-scope?

Tried them outside also didn’t make a difference, but I’ll double check.

edit:
Same outside

Wait a minute, prevMin and prevMax should be member, prevVal1 and prevVal2 should be local…

Ah indeed, Thanks! It is much less likely to get funky when they are member but still sometimes occurs. I think, but not too sure, it happens when the tooltip is fluctuating and you reset (double click) from the knob you dragged.

Hm, same here. Not sure yet why this happens.

Probably a result of smoothing. You should definitely turn that off for the knobs…

smooth = false; in the constructor?

Tried it there. Makes it much worse.