Thank @genekogan, but it doesn’t work for me because my input source is a microphone (which goes from 0 to 1), and I’d like to trig something, every time it goes over 0.5.
For exemple, if I say :
if (sound>0.5)
{
y = y+1;
}
If my sound is equal 0.6 then 0.61 then 0.65 my effect is always triggered.
I just want to trig my effect if my sound passes over 0.5, not if it is over 0.5…
EDIT: @bakercp, just tried, but my Y variable is still incrementing even if my sound > 0.5.
I’ve tried if sound=0.5, but as it’s sound, and depending on my fps, sometimes my app doesn’t get 0.5 but 0.51 for exemple so Y doesn’t increment…
@Cyril, I take it you are looking for something that triggers when a value exceeds a threshold, but that then the value must drop below the threshold before another event can be triggered?
You need to add a little extra to the if statements to get that behavior. You need to track whether or not the threshold has been exceeded/reset. That would look something like this:
bool hasThresholdBeenExceeded = false;
float threshold = 0.5;
float value;
void update() {
// Grab the mic level from OSC and store it in the variable called value
if (!hasThresholdBeenExceeded && value >= threshold) {
hasThresholdBeenExceeded = true;
cout << "Threshold exceeded. It needs to be reset before it can be triggered again" << endl;
}
else if (hasThresholdBeenExceeded && value < threshold) {
hasThresholdBeenExceeded = false;
cout << "Threshold is now reset and ready to be triggered again" << endl;
}
}
A little by the way remark that may or may not be useful. Sometimes it’s good to have two slightly different threshold values (one for triggering the increment and one for resetting the hasThresholdbeenExceeded) so that if whatever you are thresholding is just on the edge of the threshold, it won’t keep triggering the increment.
For instance if your signal is more or less constant at 0.5 but actually oscillating between 0.499 and 0.5001 you may have tons of unwanted increment that could be avoided if your reset threshold was at 0.4 rather than 0.5.
(of course you actually pick values that are making sense for your situation)
@silverbahamut,
Yep, in this situation i just take a snare drum via a “physic” trigger on it.
Then the sound is routed to my OF project and I’ve assigned a Mackie CC to the Threshold, so I can modify the amount of my visual effect. (If my threshold is low, everything is reacting via the kick drum etc… otherwise, if it high, the effect is really “jerky”. It’s now more like a DJ which controls the tension of the sound… but for the visuals