Transpose notes

Hi, after turning a 49 keys vintage keyboard (6x9 matrix) into a MIDI controller using arduino UNO, i need to transpose all notes for Fl studio, when I play the first note C I can here it playing a C but on FL keys I saw it playing C♯, all notes same problem it shifted to another note . Is it a coding problem ? What can do to transpose the notes by a semi tone?

#include <Keypad.h> // load library "Keypad".
#include <MIDI.h>   // load library "MIDI Library".

MIDI_CREATE_DEFAULT_INSTANCE();

const byte ROWS = 6; //base 6 ROWS (Do,Fa#)(Do#,Sol)(Re,Sol#)(Re#,La)(Mi,La#)(Fa,Si)
const byte COLS = 9; //x 5 columns (Octave_1a)(Octave_1b)(Octave_2a)(Octave_2b)(Octave_3a)

byte keys[ROWS][COLS];

byte rowPins[ROWS] = {A0, A1, A2, A3, A4, A5}; //A0, A1, A2, A3, A4, A5
byte colPins[COLS] = {2, 3, 4, 5, 6, 7, 8, 9, 10,}; //One Pin for every 6 tones

byte pressed_key;

int note = 25;// initial note

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

String msg = "";

void setup() {
    MIDI.begin(); //start transmission Midi.
    Serial.begin(115200);

  //fill matrix of keys with note values
    for (int c=0; c<COLS; c++){
      for (int r=0; r<ROWS; r++){
        keys[r][c]=note;
        note++;
      }
    }   
}

void loop() {
  //search for pressed keys (up to 10 at the same time)
    if (kpd.getKeys())
    {
        for (int i=0; i<LIST_MAX; i++)   // The entire Matrix is ​​scanned.
        {
            if ( kpd.key[i].stateChanged )   // If a key changes state.
            {
                switch (kpd.key[i].kstate) {  // Pressed or Released
                    case PRESSED:
                    msg = " PRESSED.";
                    pressed_key=kpd.key[i].kchar;
                    MIDI.sendNoteOn(pressed_key, 80, 1);
                break;
                    case RELEASED:
                    msg = " RELEASED.";
                    pressed_key=kpd.key[i].kchar;
                    MIDI.sendNoteOff(pressed_key, 20, 1);
                }
            }
        }
    }
}  // End loop

Piano_Midi.ino (1.7 KB)

Code doesn't compile. You declare colPins as 9 long then try to put 11 values in it. Also note is not declared anywhere (should it be 'nota')?

Steve

if you just want to send a midi note which is a semitone lower than it is sending now thenMIDI.sendNoteOn(pressed_key - 1, 80, 1);would suffice, you might want to make sure you don't send a negative value though.

Deva_Rishi:
if you just want to send a midi note which is a semitone lower than it is sending now then

MIDI.sendNoteOn(pressed_key - 1, 80, 1);

would suffice, you might want to make sure you don't send a negative value though.

Oh Yes thanks a lot, I change the code like this and it works !! :wink:

                switch (kpd.key[i].kstate) {  // Pressed or Released
                    case PRESSED:
                    msg = " PRESSED.";
                    pressed_key=kpd.key[i].kchar;
                    MIDI.sendNoteOn(pressed_key +6, 80, 1);
                break;
                    case RELEASED:
                    msg = " RELEASED.";
                    pressed_key=kpd.key[i].kchar;
                    MIDI.sendNoteOff(pressed_key +6, 20, 1);

You have "int note = 25;// initial note" and count up from there. Is the lowest note of your keyboard C-Sharp in Octave 1? If not, you have the wrong starting value for 'note'. Perhaps you meant 24 (C in Octave 1).

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.