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

Dependencies:   EFM32_SegmentLCD IOFuncLib mbed

Files at this revision

API Documentation at this revision

Comitter:
MaxScorda
Date:
Sun Jun 28 12:57:01 2015 +0000
Commit message:
Music Keys. First try

Changed in this revision

EFM32_SegmentLCD.lib Show annotated file Show diff for this revision Revisions of this file
Functions.h Show annotated file Show diff for this revision Revisions of this file
IOFuncLib.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
midiFunctions.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EFM32_SegmentLCD.lib	Sun Jun 28 12:57:01 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/SiliconLabs/code/EFM32_SegmentLCD/#114aa75da77b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Functions.h	Sun Jun 28 12:57:01 2015 +0000
@@ -0,0 +1,17 @@
+#include <string>
+
+
+//************************ FUNZIONI MODIFICATE
+void in0_handler()
+{
+    kcount++;
+    kcount=(kcount+24)%24;
+    printKey(kcount);
+}
+
+void in1_handler()
+{
+    kcount--;
+    kcount=(kcount+24)%24;
+    printKey(kcount);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IOFuncLib.lib	Sun Jun 28 12:57:01 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/MaxScorda/code/IOFuncLib/#33987903895c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Jun 28 12:57:01 2015 +0000
@@ -0,0 +1,44 @@
+#include "mbed.h"
+#include "EFM32_SegmentLCD.h"
+
+/******************** Define I/O *****************************/
+InterruptIn in0(PB9);
+InterruptIn in1(PB10);
+
+silabs::EFM32_SegmentLCD segmentDisplay;
+
+
+DigitalOut myled1(LED1);
+DigitalOut myled0(LED0);
+
+/***************** Define callback handlers *********************/
+void in0_handler();
+void in1_handler();
+
+
+//------------- variabili
+int kcount = 0;
+
+
+
+
+//------------ Funzioni -------------
+#include "midiFunctions.h"
+#include "Functions.h"
+
+
+
+int main()
+{
+    // Initialize pushbutton handler
+    in0.rise(NULL);
+    in0.fall(in0_handler);
+
+    in1.rise(NULL);
+    in1.fall(in1_handler);
+
+    printKey(kcount);
+    while(1) {
+        sleep();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Jun 28 12:57:01 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7cff1c4259d7
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/midiFunctions.h	Sun Jun 28 12:57:01 2015 +0000
@@ -0,0 +1,48 @@
+#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);
+    
+
+}
+
+
+
+
+