After connecting a cable, first voltage value is zero?

I found out that after a cable is connected, the first value on the input read by getVoltage() is zero.

I’m on Windows and I ask myself: is this also true on Mac and on Linux?

Does anyone know why the first value after connecting is zero?

I’m intrigued and will take a look when I get a chance (also on Windows, but I’d be surprised if that makes a difference).

Do you mean that if you have a module with an input port and a button, and the button tells the module to call getVoltage() once and DEBUG() the voltage, that:

  1. You connect a cable from a DC source (say 1V);
  2. You push the button and see 0V;
  3. You push the button again and see 1V?

It’s especially odd because Port::process calls getVoltage() to set the port light brightness, so you’d think that would ‘flush’ the apparent initial zero value as soon as the cable was connected.

I found a workaround for this unexpected behaviour, but I question myself: Is this also true on Mac and on Linux? Does anyone know why the first value after connecting is zero?

I want to get the value exactly when a cable is connected. Everything happens in the module in process().

void FlyingFader::process(const ProcessArgs& args) {
	if (!faderDragged && inputs[CV_INPUT].isConnected()) {
		if (inputs[CV_INPUT].getVoltage() && !params[CV_INPUT_WAS_CONNECTED].getValue()) {
			params[FADER_VALUE_BEFORE_CONNECTED].setValue(params[FADER_VALUE_BEFORE_CONNECTED].getValue() / (inputs[CV_INPUT].getVoltage() / 10.f));
			params[CV_INPUT_WAS_CONNECTED].setValue(1);
		}
		params[FADER_PARAM].setValue(clamp(params[FADER_VALUE_BEFORE_CONNECTED].getValue() * inputs[CV_INPUT].getVoltage() / 10.f, 0.f, PLUS_6_DB));
	} else {
		params[CV_INPUT_WAS_CONNECTED].setValue(0);
		params[FADER_VALUE_BEFORE_CONNECTED].setValue(params[FADER_PARAM].getValue());
	}
	
	if (outputs[CV_OUTPUT].isConnected()) {
		outputs[CV_OUTPUT].setVoltage(params[FADER_PARAM].getValue() * 10.f);
	}
}

My workaround is to check if getVoltage() is not zero (see line 3 in the code example above).

Heres’s what the code does:

These look cool!

On your zero-voltage question: I wrote a little test module that logs to DEBUG every time it sees a connection status or voltage change. (Code is trivial but included below).

When I connect it to a 1V DC signal (from Frank Buss Formula), the connection and the voltage update immediately–it doesn’t see a connected cable with 0V. (In other words, it just prints Conn 1 Volt 1.000000.

However, when I save that patch with the connection and reload it, it does what I think you’re seeing: Conn 1 Volt 0.000000 and then, immediately, Conn 1 Volt 1.000000. I know why that happens; it’s because of the one-cycle delay in cables. The cable is connected from the beginning; at the end of the first time step, there’s 1V at the output port; at the end of the second time step, that 1V has been moved to the input port.

But I think you’re seeing this whenever you make a connection, not just on startup, right?


#include "plugin.hpp"

struct ConnectTest : Module {
	enum ParamIds  { NUM_PARAMS };
	enum InputIds  { CV_INPUT, NUM_INPUTS };
	enum OutputIds { NUM_OUTPUTS };
	enum LightIds  { NUM_LIGHTS };

	bool last_is_connected = false;
	float last_input_voltage = 0.f;

	void process(const ProcessArgs& args) override {
		bool is_connected = inputs[CV_INPUT].isConnected();
		float input_voltage = inputs[CV_INPUT].getVoltage();

		if (is_connected != last_is_connected || input_voltage != last_input_voltage)
		{
			DEBUG("Conn %d Volt %f", is_connected, input_voltage);
			last_is_connected = is_connected;
			last_input_voltage = input_voltage;
		}
	};

	ConnectTest() {
		config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
	};
};

struct ConnectTestWidget : ModuleWidget {
	ConnectTestWidget(ConnectTest* module) {
		setModule(module);
		setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/Blank.svg")));
		addInput(createInputCentered<PJ301MPort>(mm2px(Vec(6, 120)), module, ConnectTest::CV_INPUT));
	}
};

Model* modelConnectTest = createModel<ConnectTest, ConnectTestWidget>("ConnectTest");

I did some more tests and I found out that it depends on how many cables are connected on the port that sends the 1 Volts value.

If only one cable is connected, then the zero value on connecting appears.

If more than one cables are connected, then the zero value on connecting does not appear.

Interesting!

I can’t reproduce this using my little test module above. It looks like Flying Fader is up on your main branch so I’ll get it running in application and try to repro (and, if I can, chase it through the engine).