open-audiovisual
Search GitHub

oav-p5 reference · Note names and pitch

noteName()#

functionoav-p5
noteName(v, [o])

Turns a MIDI number into a note name: noteName(61) is 'C#4'.

notePressed(note, velocity) hands you the number; noteName(note) writes it back as a name for the screen or a lookup table. The same C4-is-60 convention as noteNumber().

Parameters

NameTypeDescription
vNumber | StringA MIDI number (or a name, which is normalised).
oObjectOptions: { flats: true } writes 'Db4' instead of 'C#4'; { octave: false } drops the octave number ('C#'). optional

Returns

String The name, sharps by default: noteName(60) is 'C4'.

Examples

jsOpenProcessing ↗
let shown = 'play a key';

function setup() {
  createCanvas(400, 300);
  textAlign(CENTER, CENTER);
  textSize(64);
}

function notePressed(note) {
  shown = noteName(note) + '  ' + noteName(note, { flats: true });
}

function draw() {
  background(20);
  fill(255);
  text(shown, width / 2, height / 2);
}
Shows each key twice, with sharps and with flats (they differ on black keys). Open 🎹 and play.

Related

  • noteNumber() Turns a note name like 'C4' into its MIDI number, 0 to 127.
  • noteFreq() Returns the frequency in Hz of a note: noteFreq('A4') is 440.
  • notePressed() You define this function; oav-p5 calls it each time a key (or a pad) goes down.
  • note The MIDI number (0 to 127) of the last key pressed.

p5/oav-p5.js, line 239

↑ Back to top · All names