Question about unusedd output ports

Hi, I’m creating random value/melody generator thingy, and I have several output ports.

Do I need to write something into output port if its unconnected? Do I need to do something like this:

    outputs[portId].setChannels(0);
    outputs[portId].setVoltage(0.f);

Or is it automatically initialized as empty.

-k

automatically initialized as empty–you’re all good :slight_smile:

More specifically:

  • in Port.hpp, which defines the Port struct, voltages is created with float[] = {} which as of C++11 zero-initializes the array, and channels is explicitly set to 0.
  • if all cables are disconnected from an output port, output.channels gets set to 0 in Engine.cpp but the voltages aren’t cleared (conceptually correct; if you unplug a cable the voltage is still present at the port, it’s just not being transmitted).

So if that’s what you expect, you’ll get the behavior you want without doing anything extra.

3 Likes

Put another way, it’s pointless to spend valuable cpu cycles to compute data to fill channels on unconnected outputs. That’s why you’ll see many modules that check isConnected before computing values for an output.

You also don’t need to spend cycles setting it to zero, either. There’s nothing to read that information and do somthing with it.

5 Likes

Thank you

1 Like