Change/update port tooltip?

I have a param and input for setting either “Min”, “Center” or “Max” for a range, and a push button or menu-item for changing between these 3 modes. When switching mode I want to change/update the tool tip that is shown when hoovering the mouse over the knob/input, and this works fine for my params (knobs):

if (minCntrMax.needsUpdate()) {
	minCntrMax.updateActual();

	std::string mode = "Center";
	if (minCntrMax.act == minCntrMaxType::mcm_Min)
		mode = "Minimum";
	else if (minCntrMax.act == minCntrMaxType::mcm_Max)
		mode = "Maximum";

	ParamQuantity* pq = dynamic_cast<ParamQuantity*>(paramQuantities[MIN_CNTR_MAX_PARAM]);
	if (pq)	pq->name = mode + " (-10V to 10V)";

	pq = dynamic_cast<ParamQuantity*>(paramQuantities[MIN_CNTR_MAX_TRIM_PARAM]);
	if (pq)	pq->name = mode + " CV-trim";

	tooltipNeedsUpdate = true;
}

However I am not sure how I can change the tooltip that is shown for the input-port (“minCntrMaxInputPort”)

void step() override {
	InfNoiseWidget::step();

	RandomCurveModule* module = dynamic_cast<RandomCurveModule*>(this->module);
	if (module && module->tooltipNeedsUpdate) {
		std::string mode = "Center";
		if (module->minCntrMax.act == RandomCurveModule::mcm_Min)
			mode = "Minimum";
		else if (module->minCntrMax.act == RandomCurveModule::mcm_Max)
			mode = "Maximum";

		// minCntrMaxInputPort-> ??? = mode + "-CV";

		module->tooltipNeedsUpdate = false;
	}
}

By “change tooltip”, I assume you mean you want to change the port name that appears in both the tooltip and the port context menu.

It isn’t much different than what you do for the parameters. It’s probably easier within the module instead of the widget, but I will show the code for the widget step method as you have it:

  module->inputInfos[MIN_CNTR_MAX_INPUT]->name = mode + "-CV";

Note - for your parameter changes, you shouldn’t have to do any dynamic_cast() - they are already a ParamQuantity*. For example, you should be able to simply do the following:

  paramQuantities[MIN_CNTR_MAX_PARAM]->name = mode + " (-10V to 10V)";
1 Like

Thanks a lot @DaveVenom for both suggestions. Works like a charm and a lot easier than what I was trying to do, as I can now do all in process, and don’t need the Step() of the widget to do anything.

if (minCntrMax.needsUpdate()) {
	minCntrMax.updateActual();
	lights[MIN_LIGHT].setBrightness(minCntrMax.act == minCntrMaxType::mcm_Min ? 1.f : 0.f);
	lights[CNTR_LIGHT].setBrightness(minCntrMax.act == minCntrMaxType::mcm_Center ? 1.f : 0.f);
	lights[MAX_LIGHT].setBrightness(minCntrMax.act == minCntrMaxType::mcm_Max ? 1.f : 0.f);

	std::string mode = minCntrMaxTooltip[(int)minCntrMax.act];   
	paramQuantities[MIN_CNTR_MAX_PARAM]->name = mode + " (-10V to 10V)";
	paramQuantities[MIN_CNTR_MAX_TRIM_PARAM]->name = mode + " CV-trim";
	inputInfos[MIN_CNTR_MAX_INPUT]->name = mode + "-CV";
}
1 Like