open-audiovisual
Search GitHub

oav-p5 reference · Values over time (CHOP)

trigger()#

functionoav-p5
trigger([name])

Also: OAVp5.chop.trigger

Fires an event of your own, by name, for env() and count() to react to.

Call it where the thing happens: function mousePressed() { trigger('boom'); }. Then read it anywhere in draw() with env('boom', 0.01, 0.6) (a pulse that fades) or count('boom') (how many times so far). It returns nothing.

It works anywhere, not only in draw(), and each call is one event, remembered with the time it happened. You can fire the built-in names by hand as well: trigger('kick') pulses env('kick') as a real kick would.

Parameters

NameTypeDescription
nameStringThe name of the event. Anything is fine except the built-in meanings: 'kick', 'snare', 'hat', 'beat', 'note', 'bar' and 'step' are also fired by the microphone, the keys and the drum machine. Left out: 'trigger'. optional default 'trigger'

Notes

  • OAVp5.chop.trigger(…) is this function under another name.

Examples

jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
}

function mousePressed() {
  trigger('boom');   // an event of our own
}

function draw() {
  background(20);
  const k = env('boom', 0.01, 0.6);
  circle(width / 2, height / 2, 60 + k * 220);
}
Click the canvas: each click fires "boom" and the circle pulses once.
jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
  noStroke();
}

function mousePressed() { trigger('boom'); }
function keyPressed() { trigger('spark'); }

function draw() {
  background(20);
  fill(255, 90, 31);
  circle(120, 150, 40 + env('boom', 0.01, 0.6) * 160);
  fill(120, 190, 255);
  circle(280, 150, 40 + env('spark', 0.005, 0.2) * 160);
}
Click for the orange circle, press any key for the blue one: each reacts only to its own event.

Related

  • env() A 0..1 pulse that jumps up after each event (a kick, a beat, a key, a press) and then fades out: TouchDesigner's Trigger CHOP.
  • count() Counts how often on has turned on, or how many 'kick' (or any other event) have happened; with a limit it loops 0, 1, … limit − 1.
  • OAVp5.chop The CHOP functions under one roof, plus the state of the module behind them: OAVp5.chop.lag(…), .state, .slots(), .reset().

p5/oav-p5.js, line 3061

↑ Back to top · All names