open-audiovisual
Search GitHub

oav-p5 reference · The OAVp5 object (advanced)

OAVp5.clock.phase#

variableoav-p5
OAVp5.clock.phase

Where the external clock is right now: { pos, bar, beat, bpm, running }, or null while there is no tempo.

A bar is four beats. bar and beat count up from 0 and fall back to 0 at the next downbeat, the same way drumPhase and beatPhase do. After a stop the position holds. A clock with no start message gets its downbeat from the first tick after a silence of half a second, so a phase is there anyway.

Type
Object | null

A new object each time you read it: pos is the number of bars since the start (0 is the downbeat of bar 1), bar and beat are 0..1 through the current bar and beat, bpm the tempo and running whether the transport is moving. null until a tempo is known.

Examples

jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
  OAVp5.input([0xFA]);                          // MIDI start
  setInterval(() => OAVp5.input([0xF8]), 20);   // clock ticks: 24 a beat, here 50 a second (125 BPM)
}

function draw() {
  background(20);
  const p = OAVp5.clock.phase;
  if (!p) return;
  noStroke();
  fill(255, 211, 107);
  circle(40 + p.bar * (width - 80), 100, 30);   // once a bar (four beats)
  fill(120, 190, 255);
  circle(40 + p.beat * (width - 80), 200, 30);  // once a beat
}
Two circles sweep from left to right on the made-up clock: the blue one once per beat, the yellow one once per bar of four beats.

Related

  • OAVp5.clock What oav-p5 hears of an external MIDI clock: its state, tempo and where it is in the bar. Nothing until another program or device starts sending one.
  • OAVp5.clock.info A snapshot of the external clock: state (none, running, stopped or lost), bpm, whether the drums follow it, where it came from, and counts.
  • drumPhase How far through the current bar the drum machine is, smoothly from 0 up to just below 1, as it is heard.
  • beatPhase How far through the current beat the drum machine is, smoothly from 0 up to just below 1, four times per bar.

p5/oav-p5.js, line 746

↑ Back to top · All names