noteName()#
functionoav-p5noteName(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
| Name | Type | Description |
|---|---|---|
v | Number | String | A MIDI number (or a name, which is normalised). |
o | Object | Options: { 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
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);
}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.noteThe MIDI number (0 to 127) of the last key pressed.