Kodtrolshow control app [alpha]

View on GitHub

Scripting

Helpers

Helpers are useful functions that you can use anywhere in your scripts.


clamp ( value, min, max )

Ensures that an input value is within the range of minimum and maximum values.

Arguments
  • value ( Number )

    The number to clamp

  • min ( Number )

    The minimum value possible

  • max ( Number )

    The maximum value possible

Return value Number

If value is smaller than min, return min. If value is greater than max, return max. Otherwise, returns value.

Example clamp(1, 2, 6) // Returns 2 clamp(10, 2, 6) // Returns 6 clamp(-42, -100, 0) // Return -42
cmykColor ( c, m, y, k )

Creates a color object with keys containing the values of CMYK color components.

Arguments
  • c ( Number )

    The cyan value

  • m ( Number )

    The magenta value

  • y ( Number )

    The yellow value

  • k ( Number )

    The black value

Return value Object

An object containing the matching c, m, y and k keys from the parameters.

counter ( id )

Creates a counter (if it doesn't exist yet) that increments by 1 everytime the function is called.

Arguments
  • id ( String )

    The counter identifier, when using more than one counter per script

Return value Number

The current counter value

Example let myCounter = counter() // myCounter = 0 myCounter = counter() // myCounter = 1
counterLimit ( limit, id )

Creates a counter (if it doesn't exist yet) that increments by 1 everytime the function is called, and returns true when it reaches or exceeds the limit value.

Arguments
  • limit ( Number )

    The limit to reach

  • id ( String )

    The counter identifier, when using more than one counter per script

Return value Boolean

true when the counter value is equal or greater than limit, false otherwise.

Example let result = counterLimit(2) // result = false result = counterLimit(2) // result = false result = counterLimit(2) // result = true
counterReset ( id )

Resets a counter to its initial value of 0.

Arguments
  • id ( String )

    The counter identifier, when using more than one counter per script

counterResetAll ()

Resets all the script's counters to their initial value of 0.

degToRad ( degrees )

Converts a value in degrees to a value in radians.

Arguments
  • degrees ( Number )

    The input value in degrees

Return value Number

The corresponding value in radians

easeInBack ( progress )

Generates a "overshoot" easing at start of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeInBounce ( progress )

Generates a "bouncing" easing at start of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeInCirc ( progress )

Generates a circular easing at start of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeInCubic ( progress )

Generates a cubic (3rd order) easing at start of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeInElastic ( progress )

Generates a "elastic" easing at start of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeInExpo ( progress )

Generates a exponential easing at start of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeInOutBack ( progress )

Generates a "overshoot" easing at both start and end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeInOutBounce ( progress )

Generates a "bouncing" easing at both start and end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeInOutCirc ( progress )

Generates a circular easing at both start and end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeInOutCubic ( progress )

Generates a cubic (3rd order) easing at both start and end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeInOutElastic ( progress )

Generates a "elastic" easing at both start and end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeInOutExpo ( progress )

Generates a exponential easing at both start and end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeInOutQuad ( progress )

Generates a quadratic (2nd order) easing at both start and end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeInOutQuart ( progress )

Generates a quartic (4th order) easing at both start and end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeInOutQuint ( progress )

Generates a quintic (5th order) easing at both start and end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeInOutSine ( progress )

Generates a sine easing at both start and end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeInQuad ( progress )

Generates a quadratic (2nd order) easing at start of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeInQuart ( progress )

Generates a quartic (4th order) easing at start of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeInQuint ( progress )

Generates a quintic (5th order) easing at start of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeInSine ( progress )

Generates a sine easing at start of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeOutBack ( progress )

Generates a "back overshoot" easing at end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeOutBounce ( progress )

Generates a "bouncing" easing at end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeOutCirc ( progress )

Generates a circular easing at end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeOutCubic ( progress )

Generates a cubic (3rd order) easing at end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeOutElastic ( progress )

Generates a "elastic" easing at end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeOutExpo ( progress )

Generates a exponential easing at end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeOutQuad ( progress )

Generates a quadratic (2nd order) easing at end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeOutQuart ( progress )

Generates a quartic (4th order) easing at end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeOutQuint ( progress )

Generates a quintic (5th order) easing at end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

easeOutSine ( progress )

Generates a sine easing at end of period.

Arguments
  • progress ( Number )

    The normalized progress value, from 0 to 1

Return value Number

An eased, normalized value from 0 to 1.

highByte ( value )

Extracts the value of the higher byte of a 16-bit value. Useful for getting the "coarse" value of a 16-bit DMX parameter.

Arguments
  • value ( Number )

    The input value

Return value Number

The higher byte value of the input value

isBeatDivision ( beat, division, allowFirst )

Check if a pulse-per-quarter-note value from Kodtrol's engine is divisible by a value.

Arguments
  • beat ( Number )

    The pulse-per-quarter-note value

  • division ( Number )

    The divider

  • allowFirst ( Boolean )

    Only return true for beat values higher than 0

Return value Boolean

Returns true if the pulse-per-quarter-note is divisible, false otherwise.

isEven ( value )
Arguments
  • value ( Number )

    The number to check

Return value Boolean

Returns true if value is even, false otherwise.

isOdd ( value )
Arguments
  • value ( Number )

    The number to check

Return value Boolean

Returns true if value is odd, false otherwise.

log ( args )

Sends data to Kodtrol's console window.

Arguments
  • args ( * )

    The data to log; each argument will be cast to a string.

Example log("Hello World") // Displays "Hello World" in the console window log(1, 2, 3, "four", 5) // Displays "1 2 3 four 5" in the console window
lowByte ( value )

Extracts the value of the lower byte of a 16-bit value. Useful for getting the "fine" value of a 16-bit DMX parameter.

Arguments
  • value ( Number )

    The input value

Return value Number

The lower byte value of the input value

map ( value, valueMin, valueMax, outMin, outMax )

Using a source value and its known range, re-maps that value to a new target range. Note that the result is not clamped, so you may end up with under or over-shooting output values.

Arguments
  • value ( Number )

    The input value

  • valueMin ( Number )

    The minimum value of the input range

  • valueMax ( Number )

    The maximum value of the input range

  • outMin ( Number )

    The minimum value of the output range

  • outMax ( Number )

    The maximum value of the output range

Return value Number

The mapped value

Example map(75, 50, 100, 0, 1) // Returns 0.5 map(0.5, 0, 1, 0, 100) // Returns 50
mix ( a, b, percent )
Arguments
  • a ( Number )

  • b ( Number )

  • percent ( Number )

Return value Number
noise ( id, seed )
Arguments
  • id ( String )

  • seed ( * )

Return value *
noise2d ( x, y, id, seed )
Arguments
  • x ( Number )

  • y ( Number )

  • id ( String )

  • seed ( * )

Return value Number
noise3d ( x, y, z, id, seed )
Arguments
  • x ( Number )

  • y ( Number )

  • z ( Number )

  • id ( String )

  • seed ( * )

Return value Number
noise4d ( x, y, z, w, id, seed )
Arguments
  • x ( Number )

  • y ( Number )

  • z ( Number )

  • w ( Number )

  • id ( String )

  • seed ( * )

Return value Number
onceWhenFalse ( value, id, callback )

Invokes a callback once for each time that the checked value becomes false.

Arguments
  • value ( * )

    The value to check

  • id ( String )

    The identifier for the check

  • callback ( function )

    The function to be invoked when the check succeeds

onceWhenOne ( value, id, callback )

Invokes a callback once for each time that the checked value becomes exactly 1.

Arguments
  • value ( * )

    The value to check

  • id ( String )

    The identifier for the check

  • callback ( function )

    The function to be invoked when the check succeeds

onceWhenTrue ( value, id, callback )

Invokes a callback once for each time that the checked value becomes true.

Arguments
  • value ( * )

    The value to check

  • id ( String )

    The identifier for the check

  • callback ( function )

    The function to be invoked when the check succeeds

onceWhenZero ( value, id, callback )

Invokes a callback once for each time that the checked value becomes exactly 0.

Arguments
  • value ( * )

    The value to check

  • id ( String )

    The identifier for the check

  • callback ( function )

    The function to be invoked when the check succeeds

radToDeg ( radians )

Converts a value in radians to a value in degrees.

Arguments
  • radians ( Number )

    The input value in radians

Return value Number

The corresponding value in degrees

randomBetween ( min, max )
Arguments
  • min ( Number )

  • max ( Number )

Return value Number
randomIndex ( arr, except )
Arguments
  • arr ( Array )

  • except ( * )

Return value Number
randomIndexWhere ( arr, predicate )
Arguments
  • arr ( Array )

  • predicate ( function )

Return value Number
randomTrueFalse ( bias )
Arguments
  • bias ( Number )

    Adjust probability bias; a value closer to 0 will result in more trues a value close to 1 will result in more falses.

Return value Boolean

A random true or false.

randomValue ( arr, except )
Arguments
  • arr ( Array )

  • except ( * )

Return value *
randomValueWhere ( arr, predicate )
Arguments
  • arr ( Array )

  • predicate ( function )

Return value *
rgbColor ( r, g, b )

Creates a color object with keys containing the values of RGB color components.

Arguments
  • r ( Number )

    The red value

  • g ( Number )

    The green value

  • b ( Number )

    The blue value

Return value Object

An object containing the matching r, g, and b keys from the parameters.

rgbFromHsv ( h, s, v )
Arguments
  • h ( Number )

  • s ( Number )

  • v ( Number )

Return value Object
rgbMix ( color1, color2, percent )
Arguments
  • color1 ( Object )

  • color2 ( Object )

  • percent ( Number )

Return value Object
rgbToCmyk ( rgb )
Arguments
  • rgb ( Object )

    An RGB color object

Return value Object

The CMYK color object of the converted rgb color

sequence ( arr, id )
Arguments
  • arr ( Array )

  • id ( String )

Return value *
sequenceIndex ( id )
Arguments
  • id ( String )

Return value Number
sequenceReset ( id )
Arguments
  • id ( String )

smoothFollow ( device, varName, divider, value, initValue )
Arguments
  • device ( * )

  • varName ( String )

  • divider ( Number )

  • value ( * )

  • initValue ( * )

Return value *
smoothReset ( device, varName, value )
Arguments
  • device ( * )

  • varName ( String )

  • value ( * )

Return value *
smoothValue ( device, varName )
Arguments
  • device ( * )

  • varName ( String )

Return value *
smoothVarName ( device, varName )
Arguments
  • device ( * )

  • varName ( String )

Return value String
square ( x )
Arguments
  • x ( Number )

Return value Number
step ( value, step )
Arguments
  • value ( Number )

  • step ( Number )

Return value Number
timer ( id )
Arguments
  • id ( String )

timerValue ( id )
Arguments
  • id ( String )

Return value Number
timerLimit ( limit, id )
Arguments
  • limit ( Number )

  • id ( String )

Return value Boolean
timerReset ( id )
Arguments
  • id ( String )

timerResetAll ()
tri ( x )
Arguments
  • x ( Number )

Return value Number
wave ( position, percent, frequency, func )
Arguments
  • position ( Number )

  • percent ( Number )

  • frequency ( Number )

  • func ( function )

Return value Number