OAVp5.clock.phase#
variableoav-p5OAVp5.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
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
}Related
OAVp5.clockWhat 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.infoA snapshot of the external clock:state(none,running,stoppedorlost),bpm, whether the drums follow it, where it came from, and counts.drumPhaseHow far through the current bar the drum machine is, smoothly from 0 up to just below 1, as it is heard.beatPhaseHow far through the current beat the drum machine is, smoothly from 0 up to just below 1, four times per bar.