Way to find out number of keys being pressed

Hi all,

I know that if we connect a poly cable to a port we can verify the number of channels on that cable. But, is there a way to know how many “keys” are pressed? Or the number of gates “open” on that cable?

Reason for my question: If I have polyphony set to 8, but I press a 5 key chord, I want to know the number of voices in use at the moment, which is 5 in this case, not 8.

Maybe this is a noob question, sorry.

Thanks, Marcelo.

Something like if (inputs[...]getVoltage(i) != 0.f) {...} You would just need to count the channels who’s voltage is not equal to 0.

1 Like

Yes … this is what I thought … I think I need to count how many of the gate input voltages are not 0. So I am assuming there’s no automatic method like: inputs[GATE].getCount() or something.

To count the number of high gates in a polyphonic cable,

int channels = inputs[...].getChannels();
int count = 0;
for (int c = 0; c < channels; c++) {
	bool gate = inputs[...].getVoltage(c) > 2.f;
	if (gate)

The number of voices in that case would still be 8. 3 of the voices might be decaying or silent, but they are still considered voices.

1 Like

Yes , this brings me a problem. If I release the notes, the gates close, but the voices will still be decaying. And this will give me a wrong number of “active” voices let’s say. Thus messing up with my averaging.

So I would switch my question to:

What is the best way to average a signal? meaning, for example: I want to sum a number of 1vpp voices/waveforms but still keep the result within 1vpp or close to that. I am starting to think I will actually have to count the number of ADSRs that are not in idle state, so I can do: sum(voices) / num(active ADSRs)

Makes sense?


Yes, volts peak to peak. For example: If I have a square wave running between +1/-1 volts (2Vpp), and I sum it with another square wave, similar frequency, same voltage, there will be times when the maximum voltage will reach +2 volts, and the minimum will be sometimes -2 volts, this leads to a 4Vpp signal. I want the signal to be always 2Vpp in this example. So as I know in this case I have two waveforms, then I can just divide by two and get the average, but on multiple voices where not all of them might be active I am not sure how to do. I think what I want is a mixes that mixes dynamically and keeps the resulting signal within the same rage all the time. No idea (yet) how to do it.

As I said, the number of voices is always 8. Playing notes doesn’t change the number of voices.

If you’re trying to apply gain/attenuation dependent on the number of voices, don’t. I’ve explained why 6-8 times in the past year. Hmm, it would be a good interview question for VCV job applicants: “Why shouldn’t a developer automatically apply gain dependent on the number of synthesizer voices?”

Yeah sorry … I keep calling them voices, but let’s say they are “active signals”. I know the number of total voices is the selected polyphony. And sorry again, I only joined the VCV community back in December, so I might have missed the other 6-8 times you explained it … :slight_smile: What I am trying to do is: while mixing an arbitrary number of signals, prevent the amplitude of the mixed signal to go crazy up, for example, of at a certain moment all the mixed waveforms are at the top. I am quite sure there might be a DSP best-practice solution for this, but I really don’t know what it is. (and I don’t know also “Why shouldn’t a developer automatically apply gain dependent on the number of synthesizer voices?”, so I guess I am not getting the job … kkkkkkkkk) :smiley:


1 Like

Another hint:

1 Like

LOL … at least the solution I implemented has the same exact output as SUM.

Can I still get the job? :smiley:

If your solution is knob * \sum channels, then yes.

Yay! I got the job. :slight_smile: