BaseMachine UI Controllerに分離

Dependencies:   AverageAnalogIn PinDetect RotaryEncoder Sequence SequencerDisplay mbed-rtos mbed st7567LCD BaseMachineComon

Fork of BaseMachine_Sequencer by Ryo Od

Revision:
45:3c7143da38d1
Parent:
44:b1bdccdbf67e
Child:
46:0fb579ecdd77
--- a/main.cpp	Fri Oct 07 09:02:29 2016 +0000
+++ b/main.cpp	Fri Oct 07 09:56:34 2016 +0000
@@ -202,53 +202,73 @@
     return recievedVal;
 }
 
+uint8_t getNoteData(uint8_t step)
+{
+    uint8_t noteData = 0;
+    
+    noteData |= (step << 4);
+    noteData |= (sequences[step].isAccent() ? 4 : 0);
+    noteData |= (sequences[step].isTie()    ? 2 : 0);
+    noteData |= (sequences[step].isNoteOn() ? 1 : 0);
+    
+    return noteData;
+}
+
 void pollingPots()
 {
     uint8_t pulseWidth = AinPulseWidth.read_u16() >> (16 - POT_RESOLUTION);
     if (pulseWidth != oscillatorParam.pulseWidth) {
         oscillatorParam.pulseWidth = pulseWidth;
+        SpiSendParams(CMD_PULSE_WIDTH, pulseWidth);
         isDirty = true;
     }
    
     uint8_t cutoff = AinCutOff.read_u16() >> (16 - POT_RESOLUTION);
     if (cutoff != filterParam.cutoff) {
         filterParam.cutoff = cutoff;
+        SpiSendParams(CMD_CUTOFF, cutoff);
         isDirty = true;
     }
 
     uint8_t resonance = AinResonance.read_u16() >> (16 - POT_RESOLUTION);
     if (resonance != filterParam.resonance) {
         filterParam.resonance = resonance;
+        SpiSendParams(CMD_RESONANCE, resonance);
         isDirty = true;
     }
     
     uint8_t level = AinLevel.read_u16() >> (16 - POT_RESOLUTION);
     if (level != envelopeParam.level) {
         envelopeParam.level = level;
+        SpiSendParams(CMD_LEVEL, level);
         isDirty = true;
     }
 
     uint8_t duration = AinDuration.read_u16() >> (16 - POT_RESOLUTION);
-    if (duration != envelopeParam.level) {
+    if (duration != envelopeParam.duration) {
         envelopeParam.duration = duration;
+        SpiSendParams(CMD_DURATION, duration);
         isDirty = true;
     }
 
     uint8_t decay = AinDecay.read_u16() >> (16 - POT_RESOLUTION);
     if (decay != envelopeParam.decay) {
         envelopeParam.decay = decay;
+        SpiSendParams(CMD_DECAY, decay);
         isDirty = true;
     }
     
     uint8_t sustain = AinSustain.read_u16() >> (16 - POT_RESOLUTION);
     if (sustain != envelopeParam.sustain) {
         envelopeParam.sustain = sustain;
+        SpiSendParams(CMD_SUSTAIN, sustain);
         isDirty = true;
     }
     
     uint8_t _accentLevel = AinAccentLevel.read_u16() >> (16 - POT_RESOLUTION);
     if (_accentLevel != accentLevel) {
         accentLevel = _accentLevel;
+        SpiSendParams(CMD_ACCENT_LEVEL, accentLevel);
         isDirty = true;
     }
 }
@@ -291,6 +311,7 @@
         oscillatorParam.waveShape = _waveShape;
         sequencerDisplay.setWaveShape(_waveShape);
         pinFlag &= ~bWaveShape;
+        SpiSendParams(CMD_WAVE_SHAPE, _waveShape);
         isDirty = true;
     }
     
@@ -334,6 +355,7 @@
         #endif
         sequences[currentStep].setNoteOn(!sequences[currentStep].isNoteOn());
         pinFlag &= ~bNoteOnOff;
+        SpiSendParams(CMD_NOTE, getNoteData(currentStep));
         isDirty = true;
     }
     
@@ -343,6 +365,7 @@
         #endif
         sequences[currentStep].setTie(!sequences[currentStep].isTie());
         pinFlag &= ~bTie;
+        SpiSendParams(CMD_NOTE, getNoteData(currentStep));
         isDirty = true;
     }
     
@@ -352,6 +375,7 @@
         #endif
         sequences[currentStep].setAccent(!sequences[currentStep].isAccent());
         pinFlag &= ~bAccent;
+        SpiSendParams(CMD_NOTE, getNoteData(currentStep));
         isDirty = true;
     }
     
@@ -365,6 +389,7 @@
             isRunning = true;
         }
         pinFlag &= ~bRunStop;
+        SpiSendParams(CMD_RUN, isRunning);
         isDirty = true;
     }
 }