BaseMachine UI Controllerに分離
Dependencies: AverageAnalogIn PinDetect RotaryEncoder Sequence SequencerDisplay mbed-rtos mbed st7567LCD BaseMachineComon
Fork of BaseMachine_Sequencer by
Diff: main.cpp
- Revision:
- 28:d8614d2b82f9
- Parent:
- 27:c382689e652b
- Child:
- 30:0f652280d6ee
--- a/main.cpp Fri Aug 26 07:39:02 2016 +0000 +++ b/main.cpp Tue Aug 30 11:58:08 2016 +0000 @@ -21,10 +21,10 @@ #include "ST7565_SequencerDisplay.h" #define TITLE_STR1 ("BaseMachine Sequencer") -#define TITLE_STR2 ("20160826") +#define TITLE_STR2 ("20160830") #define SEQUENCE_N (16) -#define SPI_RATE (8000000) +#define SPI_RATE (16000000) // Actual frequency about 5MHz const int samplingPeriod = 1; // ms const int bpm = 120; @@ -33,6 +33,7 @@ const int baseNoteNumber = 36; const int bpmMax = 240; const int bpmMin = 60; +const int UImodeMax = 2; // Initial Sequence const int noteOn[SEQUENCE_N] = { 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0 }; @@ -62,7 +63,7 @@ RotaryEncoder RotEncBpm(PB_9, PB_8, bpmMin, bpmMax, 120); PinDetect PinWaveShape(PD_2, PullUp); -PinDetect PinModNumber(PC_11, PullUp); +PinDetect PinUIMode(PC_11, PullUp); PinDetect PinOctaveUp(PC_10, PullUp); PinDetect PinOctaveDown(PC_12, PullUp); PinDetect PinNoteOnOff(PA_13, PullUp); @@ -87,10 +88,11 @@ volatile bool isRunning = false; volatile bool isDirty = true; volatile uint8_t pinFlag = 0x00; +volatile int UImode = 0; enum PinBit { bWaveShape = 0x01, - bModNumber = 0x02, + bUIMode = 0x02, bOctaveUp = 0x04, bOctaveDown = 0x08, bNoteOnOff = 0x10, @@ -100,8 +102,6 @@ }; // とりあえずの変数(後でClassのメンバ変数に格納) -#define MOD_NUMBER_MAX 1 -volatile int modNumber = 0; volatile uint8_t envMod = 127; //------------------------------------------------------------------------ @@ -127,7 +127,7 @@ filterController.outDcf(); // ToDo: 再生中のLCD表示を検討→SPI1とSPI2の信号のタイミングを調査 - //sequencerDisplay.update(SequencerDisplay::stop, sequenceSender.getStep()); + //sequencerDisplay.update(SequencerDisplay::run, sequenceSender.getStep()); } //------------------------------------------------------------------------ @@ -138,9 +138,9 @@ pinFlag |= bWaveShape; } -void swModNumberPressed() +void swUIModePressed() { - pinFlag |= bModNumber; + pinFlag |= bUIMode; } void swOctaveUpPressed() @@ -229,18 +229,19 @@ sequenceSender.setWaveShape(waveShape); sequencerDisplay.setWaveShape(waveShape); pinFlag &= ~bWaveShape; + isDirty = true; } - if (pinFlag & bModNumber) { + if (pinFlag & bUIMode) { #if (UART_TRACE) - printf("PinModNumber Pushed\r\n"); + printf("PinUIMode Pushed\r\n"); #endif - modNumber++; - if (modNumber > MOD_NUMBER_MAX) { - modNumber = 0; + UImode++; + if (UImode > UImodeMax) { + UImode = 0; } - sequencerDisplay.setModNumber(modNumber); - pinFlag &= ~bModNumber; + pinFlag &= ~bUIMode; + isDirty = true; } if (pinFlag & bOctaveUp) { @@ -250,6 +251,7 @@ //sequences[currentStep].setOctave(sequences[currentStep].getOctave() + 1); sequencerDisplay.setOctave(sequencerDisplay.getOctave() + 1); pinFlag &= ~bOctaveUp; + isDirty = true; } if (pinFlag & bOctaveDown) { @@ -259,6 +261,7 @@ //sequences[currentStep].setOctave(sequences[currentStep].getOctave() - 1); sequencerDisplay.setOctave(sequencerDisplay.getOctave() - 1); pinFlag &= ~bOctaveDown; + isDirty = true; } if (pinFlag & bNoteOnOff) { @@ -267,6 +270,7 @@ #endif sequences[currentStep].setNoteOn(!sequences[currentStep].isNoteOn()); pinFlag &= ~bNoteOnOff; + isDirty = true; } if (pinFlag & bTie) { @@ -275,6 +279,7 @@ #endif sequences[currentStep].setTie(!sequences[currentStep].isTie()); pinFlag &= ~bTie; + isDirty = true; } if (pinFlag & bAccent) { @@ -283,6 +288,7 @@ #endif sequences[currentStep].setAccent(!sequences[currentStep].isAccent()); pinFlag &= ~bAccent; + isDirty = true; } if (pinFlag & bRunStop) { @@ -298,10 +304,11 @@ isRunning = true; } pinFlag &= ~bRunStop; + isDirty = true; } } -void dumpToLCD() +void dumpToLCD00() { char buff[64]; int col = 0; @@ -319,7 +326,7 @@ sequencerDisplay.getOctave(), sequences[currentStep].isTie(),sequences[currentStep].isAccent()); gLCD.drawstring(0, col++, buff); - sprintf(buff, "Wsp:%d Mdn:%d", sequenceSender.getWaveShape(), modNumber); + sprintf(buff, "Wsp:%d Mod:%d", sequenceSender.getWaveShape(), UImode); gLCD.drawstring(0, col++, buff); sprintf(buff, "PW :%4d CO :%4d", sequenceSender.getPulseWidth(), filterController.getCutoff()); @@ -334,6 +341,35 @@ gLCD.display(); } +void dumpToLCD01() +{ + char buff[64]; + int col = 0; + + gLCD.clear(); + + sprintf(buff, "Cutoff %5d", AinCutOff.read_u16() >> 8); + gLCD.drawstring(0, col++, buff); + sprintf(buff, "Duration %5d", AinDuration.read_u16() >> 8); + gLCD.drawstring(0, col++, buff); + sprintf(buff, "Decay %5d", AinDecay.read_u16() >> 8); + gLCD.drawstring(0, col++, buff); + sprintf(buff, "Sustain %5d", AinSustain.read_u16() >> 8); + gLCD.drawstring(0, col++, buff); + + + sprintf(buff, "Resonance %5d", AinResonance.read_u16() >> 8); + gLCD.drawstring(0, col++, buff); + sprintf(buff, "Level %5d", AinLevel.read_u16() >> 8); + gLCD.drawstring(0, col++, buff); + sprintf(buff, "EnvMod %5d", AinEnvMod.read_u16() >> 8); + gLCD.drawstring(0, col++, buff); + sprintf(buff, "PulseWidth %5d", AinPulseWidth.read_u16() >> 8); + gLCD.drawstring(0, col++, buff); + + gLCD.display(); +} + //------------------------------------------------------------------------ // Main routine //------------------------------------------------------------------------ @@ -352,6 +388,7 @@ // Mute output ampController.outDca(0); + gLCD.set_spi_frequency(SPI_RATE); gLCD.begin(0x12); gLCD.clear(); gLCD.drawstring(0, 0, TITLE_STR1); @@ -367,9 +404,9 @@ PinWaveShape.setAssertValue(0); PinWaveShape.setSampleFrequency(); - PinModNumber.attach_asserted(&swModNumberPressed); - PinModNumber.setAssertValue(0); - PinModNumber.setSampleFrequency(); + PinUIMode.attach_asserted(&swUIModePressed); + PinUIMode.setAssertValue(0); + PinUIMode.setSampleFrequency(); PinOctaveUp.attach_asserted(&swOctaveUpPressed); PinOctaveUp.setAssertValue(0); @@ -423,8 +460,30 @@ pollingPins(); if (!isRunning) { if (isDirty) { - sequencerDisplay.update(SequencerDisplay::stop, currentStep); - //dumpToLCD(); + switch (UImode) { + case 0: + sequencerDisplay.update(SequencerDisplay::stop, currentStep); + break; + case 1: + dumpToLCD00(); + break; + } + isDirty = false; + } + if (UImode == 2) { + dumpToLCD01(); + } + } else { + if (isDirty) { + //sequencerDisplay.update(SequencerDisplay::run, currentStep); + static int cnt = 0; + char buffer[32]; + sprintf(buffer, "%d", cnt); + cnt++; + gLCD.clear(); + gLCD.drawstring(0, 0, buffer); + gLCD.display(); + isDirty = false; } } }