# Re:[sc-users] Re: two separate triggers > single counter value

>PulseCount: yes. But problem remains, the sum_counter doesn't add the way I would like it to.
>
> I didn't describe the expected outcome well enough, here again:
> A counter, +1 upon every thresh crossing, -1 every 2", always adds/subtracts
> in steps of 1.
> So for example: -1, -2 , -3, -2 (thresh crossing), -3, -4, -5, -4 (thresh
> crossing), -3 (thresh crossing), -2 (thresh crossing), -3, -4, -5...

When in doubt, simplify as a test. Detecting onsets by comparing the amplitude to a threshold is tricky. I've always gotten a lot of false positives this way. So, one starting point might be to get the difficult amplitude checking out of the picture, temporarily, and use something that generates triggers in a more controlled way.

The behavior of this synth seems to match your description above:

a = {
var mouseTrig = MouseY.kr > 0.5,  // trigger = mouse crosses bottom half --> top half
pulse = Impulse.kr(0.5),
mouseTrigCount = PulseCount.kr(mouseTrig),
pulseCount = PulseCount.kr(pulse),
accumulator = mouseTrigCount - pulseCount,
combinedTrig = Trig1.kr(mouseTrig, ControlDur.ir) + pulse;
accumulator.poll(combinedTrig);
Silent.ar(1)
}.play;

a.free;

Then, if the trigger logic in this synth is OK, try again with the desired source of triggers. If it suddenly stops behaving the way you want (but it was working before), then the problem would be the trigger source rather than the trigger logic.

See also Onsets.kr for a much more reliable way to get onset triggers from incoming audio.

(Sidenote: It might take some time to learn SuperCollider-idiomatic ways to write operations, but bear in mind: "a - b" is simpler, easier to read and easier to maintain than "Mix([a, b * -1]).")

hjh

• References: