open-audiovisual
Search GitHub

oav-p5 reference · Drum machine and rhythm

OAVp5.drums.undo()#

functionoav-p5
OAVp5.drums.undo()

Goes back one line of rhythm, like ↶ on the card; returns true if there was an earlier line.

The line before the current one is played again and removed from the history. rhythmChanged() is called with how equal to 'undo'. On the card the same thing is ⌘Z or Ctrl+Z after touching it.

Returns

Boolean true if it went back one line, false if OAVp5.drums.history was empty or the machine is not loaded.

Examples

jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
  startDrums('bd*4, hh*8', 110);
  textAlign(CENTER, CENTER);
}

function mousePressed() {
  OAVp5.drums.edit('bd(3,8), hh*16');
}

function keyPressed() {
  if (key === 'z') OAVp5.drums.undo();
}

function draw() {
  background(20);
  fill(255);
  text(OAVp5.drums.src, width / 2, height / 2 - 10);
  text('click: change the line   z: undo', width / 2, height / 2 + 20);
}
Click to change the line, press z to go back to the one before.

Related

  • 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.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.
  • rhythmChanged() An event you define: it is called with the new line of rhythm every time the rhythm changes.

p5/oav-p5.js, line 1492

↑ Back to top · All names