open-audiovisual
Search GitHub

oav-p5 reference · Drum machine and rhythm

OAVp5.drums.history#

variableoav-p5
OAVp5.drums.history

The earlier lines of rhythm, oldest first: every click on a cell, typed line or menu pick leaves the line before it here.

OAVp5.drums.undo() takes the last line off this list and plays it. Changes made by startDrums() are not recorded here, only the ones made on the card or with OAVp5.drums.edit(). The array is the machine's own, so treat it as read-only.

Type
Array<String>

Empty at the start, and at most 50 lines long. The line that plays now is not in it: that is OAVp5.drums.src.

Examples

jsOpenProcessing ↗
const LINES = ['bd*4, hh*8', 'bd(3,8), hh*8', 'bd ~ ~ bd, [~ sd]*2, hh*16'];
let n = 0;

function setup() {
  createCanvas(400, 300);
  startDrums(LINES[0], 110);
  textSize(14);
}

function mousePressed() {
  n = (n + 1) % LINES.length;
  OAVp5.drums.edit(LINES[n]);
}

function draw() {
  background(20);
  fill(255);
  text('click to edit the line', 20, 30);
  text('history: ' + OAVp5.drums.history.length + ' earlier lines', 20, 60);
  text(OAVp5.drums.history.join('\n'), 20, 90);
}
Each click edits the line and adds the one before it to the history list.

Related

  • OAVp5.drums.undo() Goes back one line of rhythm, like ↶ on the card; returns true if there was an earlier line.
  • OAVp5.drums.edit() Plays a line of rhythm as if it was typed on the card, and returns whether it worked and, if not, what is wrong with it.
  • OAVp5.drums.src The line of rhythm that plays now, such as 'bd*4, [~ sd]*2, hh*8'; an empty string until the machine has loaded.
  • rhythmChanged() An event you define: it is called with the new line of rhythm every time the rhythm changes.

p5/oav-p5.js, line 1490

↑ Back to top · All names