open-audiovisual
Search GitHub

oav-p5 reference · Note names and pitch

noteNumber()#

functionoav-p5
noteNumber(v)

Turns a note name like 'C4' into its MIDI number, 0 to 127.

A name is a letter A to G (either case), an optional # or b (♯ and ♭ too), and the octave: C4, c#4, Db3, C-1 (0) up to G9 (127). C4 is 60. Anything else, such as 'H4' or 'C-2', throws an error, and a card beside the 🎹 says how to write a note.

You rarely call it yourself: every place that takes a note number also takes a name, such as noteIsDown() and midi.play().

Parameters

NameTypeDescription
vString | NumberA note name ('C4', 'c#4', 'Db3', 'F♯2') or a number. A number comes back rounded and held to 0..127.

Returns

Number The MIDI number: noteNumber('C4') is 60, noteNumber('A4') is 69.

Examples

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

function draw() {
  background(20);
  fill(255);
  text('C4 = ' + noteNumber('C4') + '\nA4 = ' + noteNumber('A4') + '\nF#2 = ' + noteNumber('F#2'), width / 2, height / 2);
}
Prints 60, 69 and 42.

Related

  • noteName() Turns a MIDI number into a note name: noteName(61) is 'C#4'.
  • noteFreq() Returns the frequency in Hz of a note: noteFreq('A4') is 440.
  • noteIsDown() True while the key n (a MIDI number or a name like 'C4') is held down.

p5/oav-p5.js, line 225

↑ Back to top · All names