# General Purpose Functions Jack of All Trade

abs(value) Absolute value.

avg(value1, value2, value3, ...) Compute the average of a set of values. Can have any number of values.

bpmCounter(beatInput): Count the number of beats per minute in real-time. The result is in BPM, not percent.

bpmCounter.speed(beatInput): Convert the beats per minute to a percent value usable for speed parameters.

ceil(value): Rounds a number up to the nearest integer.

counter(from, to, incrementNow, [decrementNow], [resetFct]) Increment a counter between the from and to values only when the incrementNow value is true (other than 0). If the resetFct value is > 0, the counter resets.

noLoopCounter(from, to, incrementNow, [decrementNow], [resetFct]) Like the counter function but don't wrap around when reaching the to value.

pingCounter(from, to, incrementNow, [resetFct]) Increment a counter between the from and to values only when the incrementNow value is true (other than 0). When reaching the to value, start counting backward. If the resetFct value is > 0, the counter resets.

delay(time, value) Delay the value of the given time in seconds.

delta(value) Return the difference between the last iteration value and the current value. That's the instantaneous rate of change.

distance(x1, y1, [z1], x2, y2, [z2]) The euclidean distance between two points in 2D or optionnaly, in 3D.

floor(value): Round a number down to the nearest integer.

isBetween(value, min, max) Return 100% if the value is between min and max, inclusively.

latch(updateNow, value, [initialValue]) Store a value that is updated when the updateNow parameter is positive. Optionally provide an initial value, which is returned before the first update trigger is received.

latchDelta(updateNow, value, [min=0], [max=100]) Update the stored value by adding the delta value (difference between the current and first values when starting the update). The update starts when updateNow is > 0.

latestIndex(value0, value1, ...) Return the index of the latest received positive value.

max(value1, value2, value3, ...) Compute the largest value of a set. Can have any number of values.

min(value1, value2, value3, ...) Compute the smallest value of a set. Can have any number of values.

randInt(min, max) Return a random integer value between min and max (inclusive). Never return the same value twice in a row.

record(isRecording, value) Record the values and replay in a loop the recorded values when not recording. The isRecording trigger the start of a new recording when it is true (other than 0).

restrain(value, min, max) Make sure the value is between the specified minimum and maximum values.

round(value) Round the fractional part of a number.

scale(value, toMin, toMax) Scale a percent value to fit the specified toMin and toMax range.

scale(value, min, max, toMin, toMax) Scale a value ranging from min and max to fit the specified toMin and toMax range.

seconds(hours, minutes, seconds) Compute the total number of seconds from the hours, minutes and seconds.

smooth(time, value) Average values over the specified time. This is handy when handling jittering signals like Wiimote accelerometers.

sqrt(value) Square root.

strobe(time) Generate a strobe effect in sync with the DMX output.

sum(value1, value2, value3, ...) Sum all values. Can have any number of values.

tapTempo.bpm(beatInput): Return the number of beats per minute of the detected tempo.

tapTempo.pulse(beatInput): Generate pulses based on the detected tempo.

tapTempo.sawtooth(beatInput): Generate a sawtooth wave in sync with the beat.

tapTempo.speed(beatInput): Convert the beats per minute of the tempo to a percent value usable for speed parameters.

# Examples

counter(0, 10, onbeat(midi.note(1, 40)))

Count from 0 to 10. Increment the counter each time the midi note is pressed.

counter(0, 10, onbeat(midi.note(1, 40)), onbeat(midi.note(1, 41)))

Count from 0 to 10. Increment the counter each time the midi note 40 is pressed and decrement each time the midi note 41 is pressed.

latch(onbeat(midi.note(1, 40)), rand())

Take a new random value each time the midi note is pressed.

tapTempo.pulse(onbeat(midi.note(1, 40)))

Generate pulses based on the tempo made by pressing a midi note.

map.triangle(taptempo.sawtooth(midi.note(1,40)))

Generate a triangle wave in sync with the detected tempo.

tapTempo.speed(onbeat(midi.note(1, 40)))

Return a value suitable to control the speed of a grid or group based on the tempo made by pressing a midi note. If you generate a tempo of 60 BPM, the speed value will be 1x. 120 BPM will be 2x...

strobe(0.1)

Generare a 10 Hz strobe. 0.1 is the time between each pulse in seconds.

isBetween(midi.clock.time(1), seconds(0,10,0), seconds(1,10,0))

Check whether a MIDI time code is between 10 minutes and an hour and 10 minutes.