teenageengineering / videolab

MIT License
737 stars 65 forks source link

Threshold node update #43

Closed sdhuys closed 4 years ago

sdhuys commented 4 years ago

Update Klak Threshold node with “discrete” checkbox to switch between Kejiro’s original threshold’s behaviour and a new “discrete mode”. Remove “delay to off” functionality.

“Discrete mode” is intended for cases where consecutive input values >= _threshold (or < threshold) should keep invoking the _onEvent (or _offEvent). It probably shouldn’t be used when the threshold input is continuously being sent in, for instance from a Knob Input node, as that would result in the On/OffEvent being invoked constantly and might cause unwanted results. A good use for the “discrete mode” would be for instance to randomly trigger one of three events every time a certain button is pressed with a patch like this: https://drive.google.com/file/d/1HtbE6EJZzD6CWeM50Ddf2KH_0R-ba5iy/view Regarding this patch: if two consecutive button presses both result in the Random Value 1 node generating a value > Threshold 1’s, then the original threshold’s behaviour results in Random Value 2 only generating a value once and subsequently only triggering an Event Out node once, only on the first button press. In “discrete mode” the Random Value 2 node will generate a value both times and guarantees an Event Out node will get triggered with each button press.

To make this work properly I removed the “delay to off” functionality, as invoking the Off Event happened in the Update() function because of this delay functionality, which would cause the Off Event to be invoked constantly once a single value < _threshold is reached (until a value >= _threshold is reached). The benefit of having the “discrete mode” seems to outweigh the losing of the “delay to off”, since simply hooking up a Delay node to the Off-outlet of the threshold node has the same result, so no functionality is really lost.

I’m not sure of “discrete” is the best name for the new checkbox though.

sdhuys commented 4 years ago

I just realised it’s incorrect that using a delay node has the same result as the “delay to off” functionality (as this prevents the Off Event from being invoked if a value < _threshold comes in, followed by a value > _threshold in a time interval < _delayToOff, whereas simply a Delay node after the Off outlet does not). One way to keep the delay to off combined with the new “discrete mode” could be to make it so that the same input value cannot invoke the Off Event more than once consecutively, to prevent the Update() function to invoke the Off Event constantly once a value < _threshold comes in.