OAVp5.clock#
objectoav-p5OAVp5.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.
Some programs keep the time and everyone else follows: Strudel (midicmd("clock*96, <start stop>/8")), a DAW over a virtual cable, a drum machine on a MIDI cable. They send 24 clock messages per beat, plus start, continue, stop and song position. oav-p5 counts them: OAVp5.clock.info says whether a clock is running, OAVp5.clock.bpm its tempo and OAVp5.clock.phase how far through the bar and the beat it is now.
When a clock is moving, drumPhase, beatPhase, drumBar, drumStep and drumBpm read it, and a drum machine that is up follows it. ?oav_clock=off turns all of that off. Clock messages are not delivered to midiMessage(): they belong to the clock.
Notes
- The first clock message loads the counting code (@openav/midi's
MidiClock) from next to oav-p5.js, which takes a few frames. Until then the members readnone,nullandnull. - This is advanced: most sketches only read
drumPhaseand let it follow a clock.
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);
fill(255);
text('clock: ' + OAVp5.clock.info.state, 20, 30);
text('tempo: ' + (OAVp5.clock.bpm ? nf(OAVp5.clock.bpm, 1, 1) : '-') + ' BPM', 20, 60);
const p = OAVp5.clock.phase;
if (p) circle(40 + p.beat * (width - 80), 150, 30); // sweeps across once a beat
}Related
OAVp5.clock.infoA snapshot of the external clock:state(none,running,stoppedorlost),bpm, whether the drums follow it, where it came from, and counts.OAVp5.clock.bpmThe tempo of the external MIDI clock in beats a minute, ornullwhile there is none.OAVp5.clock.phaseWhere the external clock is right now:{ pos, bar, beat, bpm, running }, ornullwhile there is no tempo.clockWhether an external MIDI clock (from a DAW, Strudel or a drum machine) movesdrumPhase,drumBpmand the drum machine:followoroff.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.