Music key reference. From C to B, major and minor

Dependencies:   EFM32_SegmentLCD IOFuncLib mbed

midiFunctions.h

Committer:
MaxScorda
Date:
2015-06-28
Revision:
0:45c4e9ef5b03

File content as of revision 0:45c4e9ef5b03:

#include <string>
#include "IOFuncLib.h"
genFunctions fnz;


int getScala(char notaf, bool tiposcala)
{
    //idx= nota da calcolare NB 0-6
    //tiposcala true=maggiore, flase=minore
    int idx = kcount;
    int scalamaggiore[] = {0,2,2,1,2,2,2 };
    int scalaminore[] = {0,2,1,2,2,1,2 };
    notaf = fnz.constrain(notaf, 0, 6);
    for (int i = 0; i < notaf + 1; i++)  {
        if (tiposcala) idx = idx +  scalamaggiore[i];
        else idx = idx +  scalaminore[i];
    }
    return idx;
}


void printKey(int valk)
{
    char score[] = {'C', 'c', 'D', 'd',
                    'E', 'F', 'f', 'G',
                    'g', 'A', 'a', 'B'
                   };
    char posidxs = 0;
    string strnota;

    for (int i = 0; i < 7; i++)  {
        //scala anglosassone
        if ((valk%2) == 0) strnota = strnota+score[getScala(i, true) % 12]; //se maggiore
        else strnota = strnota+score[getScala(i, false) % 12];               //se minore
        posidxs = posidxs + 8 + 3;
    }
    segmentDisplay.Number(valk);
    segmentDisplay.Write(fnz.string2char(strnota));
     if ((valk%2)==0) segmentDisplay.Symbol(LCD_SYMBOL_MINUS, false);
     else segmentDisplay.Symbol(LCD_SYMBOL_MINUS, true);
    

}