open-audiovisual
Search GitHub

oav-p5 reference · MIDI: knobs, faders, pads, keys

OAVp5.play()#

functionoav-p5
OAVp5.play(note, [velocity])

Plays a key as if a controller did: midi.play(60, 0.8) presses middle C, midi.play(60, 0) lets it go.

It sends the same MIDI bytes a keyboard would, with midi.last.source set to 'screen', so everything reacts: notePressed(), noteIsDown(), note, the sound if startSound() is on. midi and OAVp5 are the same object, so OAVp5.play and midi.play are one function.

Parameters

NameTypeDescription
noteNumber | StringThe key: a MIDI number or a name ('C#4').
velocityNumberHow hard, 0..1; 0 releases the key. Leave it out for full force. optional default 1

Notes

  • The key stays down until you play it again with velocity 0.

Examples

jsOpenProcessing ↗
function setup() {
  createCanvas(400, 300);
  textAlign(CENTER, CENTER);
  textSize(32);
}

function mousePressed() { midi.play('C4', 0.8); }
function mouseReleased() { midi.play('C4', 0); }

function draw() {
  background(noteIsDown('C4') ? 90 : 20);
  fill(255);
  text('hold the mouse: C4 is ' + (noteIsDown('C4') ? 'down' : 'up'), width / 2, height / 2);
}
The mouse plays middle C: the sketch hears it the same as a key.

Related

  • noteIsDown() True while the key n (a MIDI number or a name like 'C4') is held down.
  • notePressed() You define this function; oav-p5 calls it each time a key (or a pad) goes down.
  • noteNumber() Turns a note name like 'C4' into its MIDI number, 0 to 127.
  • OAVp5.input() Sends one MIDI message into oav-p5 by hand, as bytes: the whole sketch reacts as if a controller had sent it.

p5/oav-p5.js, line 269

↑ Back to top · All names