convert midi note to note name

Status
Not open for further replies.

DanieleFromItaly

Active member
Hi, how to convert mdi note to note name?

0 ->C0
51 -> D#3
..

First thing that comes to my mind is an big array of string: string name[] ={"C0","C#0,"D0"....}

Are there better alternatives ?

Thanks,
Daniele.
 
you can use 12 note names and then one digit for the octave.

note = midinote%12;
octave = midnote/12;
 
you can use 12 note names and then one digit for the octave.

note = midinote%12;
octave = midnote/12;

Great !

Test sketch:

Code:
String nname[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
int mname;
int oc;

void setup() {
Serial.begin(9600);
}

void loop() {
  Serial.println("Start");
  delay(100);
  int i;
  for (i=0; i<=127; i++) {
    oc = i/12;
    mname = i%12;
    Serial.println("Note: "+String(i)+" "+String(nname[mname])+" "+String(nname[mname])+String(oc));
    delay(50);
  }
  delay(200);
}

Thanks,
Daniele.
 
Status
Not open for further replies.
Back
Top