open-audiovisual
Search GitHub

oav-p5 reference · Drum machine and rhythm

OAVp5.drums#

objectoav-p5
OAVp5.drums

The object behind the drum names: the state of the machine, its counters, the line of rhythm, its history and the loaded machine.

OAVp5.drums (also reachable as midi.drums) is what startDrums(), drumStep and the rest are built on. It holds the numbers (state, step, bar, count, bpm, phase, beatPhase), the rhythm (pattern, src, copyText, strudelUrl, history, edit(), undo()), the cues (cue(), cues, lastCue), a way to listen (on()), what the machine hears right now (now) and handles for the curious (machine, clock).

start, stop and draw are the same as startDrums(), stopDrums() and drawRhythm(). For a sketch the global names are enough. This object is for tools, libraries (Hydra, for one), the console and debugging.

Examples

jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
  startDrums('latin', 110);
  textSize(14);
}

function draw() {
  background(20);
  fill(255);
  const d = OAVp5.drums;
  text('state: ' + d.state, 20, 30);
  text('pattern: ' + d.pattern, 20, 60);
  text('bar ' + d.bar + ', step ' + d.step + ', count ' + d.count, 20, 90);
  text('bpm: ' + d.bpm, 20, 120);
}
Four lines read from the drums object while the machine plays.

Related

  • startDrums() Starts a drum machine: a 16-step grid on the page that plays a preset, your own grid or one line of rhythm, and counts the bars for your sketch.
  • OAVp5.drums.state Where the drum machine is: 'off', 'loading', 'on', 'stopped' or 'error'.
  • OAVp5.drums.on() Listens to the drum machine from anywhere: OAVp5.drums.on('hit', fn) calls fn like drumHit does, and returns a function that stops listening.
  • OAVp5.sound The object behind the sound names: the state, the instrument, the error, the loading progress and the loaded parts of @openav/sound.
  • OAVp5.record The object behind the recording names: the state, the time, the last file, the formats this browser can write and the screenshot function.

p5/oav-p5.js, line 1500

↑ Back to top · All names