Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: convert midi note to note name

  1. #1

    convert midi note to note name

    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.

  2. #2
    Senior Member
    Join Date
    Aug 2013
    Location
    Gothenburg, Sweden
    Posts
    395
    you can use 12 note names and then one digit for the octave.

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

  3. #3

    Quote Originally Posted by mlu View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •