Integrated version

Revision:
15:646a57eb89f3
Parent:
14:73d3546d92fd
Child:
16:566ddb132ef8
--- a/BaseMachineUIController.h	Sun Nov 27 21:21:38 2016 +0000
+++ b/BaseMachineUIController.h	Sun Nov 27 23:44:13 2016 +0000
@@ -37,6 +37,7 @@
 const int octaveMin = -2;
 const int waveShapeMax = 1;
 const int UImodeMax = 2;
+const int EEPROMSlotMax = 16;
 
 struct OscillatorParam {
     uint8_t waveShape;
@@ -69,8 +70,8 @@
         bpm(120),
         accentLevel(127),
         sequencePattern(0),
-        spareValue(0),
-        spareValue2(0),
+        loadSaveFlag(0),
+        eepromSlot(0),
         editingStep(0),
         playingStep(0),
         isRunning(false),
@@ -138,7 +139,7 @@
             ExioIn[i] = new ExioBufferedDebounceIn(ExioInBufferB, i);
         }
 
-        ExioRotEnc1 = new ExioBufferedRotaryEncoder(ExioInBufferA, 6, 7);
+        ExioRotEnc1 = new ExioBufferedRotaryEncoder(ExioInBufferA, 6, 7, 0, EEPROMSlotMax - 1, 0);
         
         I2c1 = new I2C(PB_9, PB_8);
         At24c1024 = new AT24C1024(*I2c1);
@@ -322,7 +323,7 @@
                 break;
         }
         
-        switch (spareValue) {
+        switch (loadSaveFlag) {
         case 1:
             saveToEEPROM();
             Thread::wait(1000);
@@ -393,8 +394,8 @@
     uint8_t bpm;
     uint8_t accentLevel;
     uint8_t sequencePattern;
-    uint8_t spareValue;
-    uint8_t spareValue2;
+    uint8_t loadSaveFlag;
+    uint8_t eepromSlot;
 
     int editingStep;
     int playingStep;
@@ -598,18 +599,18 @@
             isDirty = true;
         }
         
-        spareValue = 0;
+        loadSaveFlag = 0;
         for (i = 0; i < 5; i++) {
-            spareValue |= ((ExioInA[i]->read()) << i);
+            loadSaveFlag |= ((ExioInA[i]->read()) << i);
         }
         
         #if (UART_TRACE)
-        if (spareValue != 0) {
-            printf("spareValue: %d\r\n", spareValue);
+        if (loadSaveFlag != 0) {
+            printf("loadSaveFlag: %d\r\n", loadSaveFlag);
         }
         #endif
         
-        spareValue2 = ExioRotEnc1->getVal();
+        eepromSlot = ExioRotEnc1->getVal();
     }
     
     void dumpToLCD00() {
@@ -625,13 +626,17 @@
                 editingStep, sequences[sequencePattern][editingStep].isNoteOn(), sequences[sequencePattern][editingStep].getPitch());
         gLCD->drawstring(0, col++, buff);
 
-        sprintf(buff, "Oct:%-2d Tie:%d Acc:%d %d",
-                sequencerDisplay->getOctave(), sequences[sequencePattern][editingStep].isTie(),sequences[sequencePattern][editingStep].isAccent(), spareValue);
+        sprintf(buff, "Oct:%-2d Tie:%d Acc:%d",
+                sequencerDisplay->getOctave(), sequences[sequencePattern][editingStep].isTie(),sequences[sequencePattern][editingStep].isAccent());
         gLCD->drawstring(0, col++, buff);
 
-        sprintf(buff, "Wsp:%d Mod:%d pStp:%d %d", oscillatorParam.waveShape, UImode, playingStep, spareValue2);
+        sprintf(buff, "Wsp:%d Mod:%d pStp:%d", oscillatorParam.waveShape, UImode, playingStep);
         gLCD->drawstring(0, col++, buff);
 
+        sprintf(buff, "LSF:%d SLT:%d", loadSaveFlag, eepromSlot);
+        gLCD->drawstring(0, col++, buff);
+
+        /*
         sprintf(buff, "RSO:%4d   CO :%4d", filterParam.resonance, filterParam.cutoff);
         gLCD->drawstring(0, col++, buff);
         sprintf(buff, "LVL:%4d   DUR:%4d", envelopeParam.level, envelopeParam.duration);
@@ -640,6 +645,7 @@
         gLCD->drawstring(0, col++, buff);
         sprintf(buff, "ACL:%4d   SUS:%4d", accentLevel, envelopeParam.sustain);
         gLCD->drawstring(0, col++, buff);
+        */
 
         gLCD->display();
     }
@@ -688,13 +694,27 @@
 
         gLCD->clear();
 
-        sprintf(buff, "Save to EEPROM");
+        sprintf(buff, "Save to EEPROM?[%02d]", eepromSlot);
         gLCD->drawstring(0, 0, buff);
         gLCD->display();
         
+        while (1) {
+            pollingExio();
+            sprintf(buff, "[%02d]", eepromSlot);
+            gLCD->drawstring(90, 0, buff);
+            gLCD->display();
+            if (loadSaveFlag &= 0x04) {
+                break;
+            }
+        }
+        
+        gLCD->drawstring(0, 1, " Saving...");
+        gLCD->display();    
+        
         #if (UART_TRACE_EEPROM)
         printf("*** Save Sequences to EEPROM ***\r\n");
         for (int j = 0; j < PATTERN_N; j++) {
+            printf("eepromSlot: %d\r\n", eepromSlot);
             printf("sequencePattern: %d\r\n", j);
             for (int i = 0; i < SEQUENCE_N; i++) {
                 printf("%d %d %03d %d %d\r\n",
@@ -726,7 +746,7 @@
                 printf("%d: %d\r\n", i, eep_buff[i]);
             }
             */
-            uint32_t addr_page_top = j << 8;
+            uint32_t addr_page_top = (eepromSlot * PATTERN_N + j) << 8;
             #if (UART_TRACE_EEPROM)
             printf("address: %x\r\n", addr_page_top);
             #endif 
@@ -735,12 +755,14 @@
                 eep_buff,
                 sizeof(eep_buff)
             );
+            Thread::wait(5);
+            
             #if (UART_TRACE_EEPROM)
             printf("status: %d\r\n", status);
             #endif
         }
 
-        gLCD->drawstring(0, 1, " Done");
+        gLCD->drawstring(0, 2, " Done");
         gLCD->display();    
     }
     
@@ -750,10 +772,23 @@
 
         gLCD->clear();
 
-        sprintf(buff, "Load From EEPROM");
+        sprintf(buff, "Load From EEPROM?[%02d]", eepromSlot);
         gLCD->drawstring(0, 0, buff);
         gLCD->display();
         
+        while (1) {
+            pollingExio();
+            sprintf(buff, "[%02d]", eepromSlot);
+            gLCD->drawstring(102, 0, buff);
+            gLCD->display();
+            if (loadSaveFlag &= 0x04) {
+                break;
+            }
+        }
+        
+        gLCD->drawstring(0, 1, " Loading...");
+        gLCD->display();  
+        
         #if (UART_TRACE_EEPROM)
         printf("*** Load Sequences from EEPROM ***\r\n");
         #endif
@@ -761,7 +796,12 @@
         uint8_t eep_buff[258];
         
         for (int j = 0; j < PATTERN_N; j++) {
-            uint32_t addr_page_top = j << 8;
+            uint32_t addr_page_top = (eepromSlot * PATTERN_N + j) << 8;
+
+            #if (UART_TRACE_EEPROM)
+            printf("address: %x\r\n", addr_page_top);
+            #endif
+
             AT24C_STATUS status = At24c1024->read_page(
                 addr_page_top, 
                 eep_buff,
@@ -790,6 +830,7 @@
             
             #if (UART_TRACE_EEPROM)
             printf("size: %d\r\n", cnt);
+            printf("eepromSlot: %d\r\n", eepromSlot);
             printf("sequencePattern: %d\r\n", j);
             #endif
         }
@@ -810,12 +851,17 @@
         }
         #endif
 
-        gLCD->drawstring(0, 1, " Done");
+        gLCD->drawstring(0, 2, " Done");
         gLCD->display();  
     }
     
     void copyToClipBoard()
     {
+        gLCD->clear();
+        gLCD->drawstring(0, 0, "Copy");
+        gLCD->display();
+        isDirty = true;
+
         for (int i = 0; i < SEQUENCE_N; i++) {
             sequenceClipBoard[i].setNoteOn(sequences[sequencePattern][i].isNoteOn());
             sequenceClipBoard[i].setPitch(sequences[sequencePattern][i].getPitch());
@@ -841,6 +887,11 @@
     
     void pasteFromClipBoard()
     {
+        gLCD->clear();
+        gLCD->drawstring(0, 0, "Paste");
+        gLCD->display();  
+        isDirty = true;
+
         #if (UART_TRACE_CLIPBOARD)
         printf("pasteFromClipBoard\r\n");
         printf("isClipBoardEmpty: %d\r\n", isClipBoardEmpty);