OAVp5.play()#
functionoav-p5OAVp5.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
| Name | Type | Description |
|---|---|---|
note | Number | String | The key: a MIDI number or a name ('C#4'). |
velocity | Number | How 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
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);
}Related
noteIsDown()True while the keyn(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.