Integrated version

Committer:
ryood
Date:
Mon Nov 28 00:37:40 2016 +0000
Revision:
16:566ddb132ef8
Parent:
15:646a57eb89f3
Child:
17:5c8c173008cf
impl. Load/Save Cancel.;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ryood 0:5bc618f6d862 1 /*
ryood 0:5bc618f6d862 2 * BaseMachineUIController.h
ryood 0:5bc618f6d862 3 *
ryood 0:5bc618f6d862 4 * 2016.11.06 created
ryood 0:5bc618f6d862 5 *
ryood 0:5bc618f6d862 6 */
ryood 10:a8ec7391a066 7
ryood 12:d4e5feab3a2d 8 #define UART_TRACE_EEPROM (0)
ryood 16:566ddb132ef8 9 #define UART_TRACE_CLIPBOARD (1)
ryood 0:5bc618f6d862 10
ryood 0:5bc618f6d862 11 #ifndef _UICONTROLLER_H_
ryood 0:5bc618f6d862 12 #define _UICONTROLLER_H_
ryood 0:5bc618f6d862 13
ryood 0:5bc618f6d862 14 #include "mbed.h"
ryood 0:5bc618f6d862 15 #include "rtos.h"
ryood 0:5bc618f6d862 16
ryood 0:5bc618f6d862 17 #include "BaseMachineCommon.h"
ryood 0:5bc618f6d862 18
ryood 0:5bc618f6d862 19 #include "st7565LCD.h"
ryood 10:a8ec7391a066 20 #include "AT24C1024.h"
ryood 0:5bc618f6d862 21 #include "PinDetect.h"
ryood 0:5bc618f6d862 22 #include "RotaryEncoder.h"
ryood 0:5bc618f6d862 23 #include "AverageAnalogIn.h"
ryood 5:c3ed523c0330 24 #include "ExioBufferedDebounceIn.h"
ryood 9:70b8f9935ef7 25 #include "ExioBufferedRotaryEncoder.h"
ryood 0:5bc618f6d862 26
ryood 0:5bc618f6d862 27 #include "Sequence.h"
ryood 0:5bc618f6d862 28 #include "ST7565_SequencerDisplay.h"
ryood 0:5bc618f6d862 29
ryood 0:5bc618f6d862 30 #define GLCD_SPI_RATE (1000000)
ryood 0:5bc618f6d862 31 #define POT_RESOLUTION (7) // bit
ryood 0:5bc618f6d862 32 #define AIN_AVERAGE (16) // AnalogInを移動平均する要素数
ryood 0:5bc618f6d862 33
ryood 0:5bc618f6d862 34 const int bpmMax = 240;
ryood 0:5bc618f6d862 35 const int bpmMin = 60;
ryood 0:5bc618f6d862 36 const int octaveMax = 2;
ryood 0:5bc618f6d862 37 const int octaveMin = -2;
ryood 0:5bc618f6d862 38 const int waveShapeMax = 1;
ryood 6:5ef23727ce6a 39 const int UImodeMax = 2;
ryood 15:646a57eb89f3 40 const int EEPROMSlotMax = 16;
ryood 0:5bc618f6d862 41
ryood 16:566ddb132ef8 42
ryood 16:566ddb132ef8 43 //flagEepromCancel スイッチを増やして割り当てる
ryood 16:566ddb132ef8 44 typedef enum {
ryood 16:566ddb132ef8 45 flagSaveToEeprom = 0x01,
ryood 16:566ddb132ef8 46 flagLoadFromEeprom = 0x02,
ryood 16:566ddb132ef8 47 flagEepromOK = 0x04,
ryood 16:566ddb132ef8 48 flagCopyToClipBoard = 0x08,
ryood 16:566ddb132ef8 49 flagPasteFromClipBoard = 0x10
ryood 16:566ddb132ef8 50 } LoadSaveFlagT;
ryood 16:566ddb132ef8 51
ryood 0:5bc618f6d862 52 struct OscillatorParam {
ryood 0:5bc618f6d862 53 uint8_t waveShape;
ryood 0:5bc618f6d862 54 uint8_t pulseWidth;
ryood 0:5bc618f6d862 55
ryood 0:5bc618f6d862 56 OscillatorParam() : waveShape(0), pulseWidth(0) {}
ryood 0:5bc618f6d862 57 };
ryood 0:5bc618f6d862 58
ryood 0:5bc618f6d862 59 struct FilterParam {
ryood 0:5bc618f6d862 60 uint8_t cutoff;
ryood 0:5bc618f6d862 61 uint8_t resonance;
ryood 0:5bc618f6d862 62
ryood 0:5bc618f6d862 63 FilterParam() : cutoff(0), resonance(0) {}
ryood 0:5bc618f6d862 64 };
ryood 0:5bc618f6d862 65
ryood 0:5bc618f6d862 66 struct EnvelopeParam {
ryood 0:5bc618f6d862 67 uint8_t level;
ryood 0:5bc618f6d862 68 uint8_t length;
ryood 0:5bc618f6d862 69 uint8_t duration;
ryood 0:5bc618f6d862 70 uint8_t decay;
ryood 0:5bc618f6d862 71 uint8_t sustain;
ryood 0:5bc618f6d862 72
ryood 0:5bc618f6d862 73 EnvelopeParam() : level(0), length(0), duration(0), decay(0), sustain(0) {}
ryood 0:5bc618f6d862 74 };
ryood 0:5bc618f6d862 75
ryood 0:5bc618f6d862 76 class BaseMachineUIController
ryood 0:5bc618f6d862 77 {
ryood 0:5bc618f6d862 78 public:
ryood 0:5bc618f6d862 79 BaseMachineUIController() :
ryood 0:5bc618f6d862 80 bpm(120),
ryood 0:5bc618f6d862 81 accentLevel(127),
ryood 7:0f8efe0e1e3f 82 sequencePattern(0),
ryood 15:646a57eb89f3 83 loadSaveFlag(0),
ryood 15:646a57eb89f3 84 eepromSlot(0),
ryood 0:5bc618f6d862 85 editingStep(0),
ryood 0:5bc618f6d862 86 playingStep(0),
ryood 0:5bc618f6d862 87 isRunning(false),
ryood 0:5bc618f6d862 88 isDirty(true),
ryood 12:d4e5feab3a2d 89 isClipBoardEmpty(true),
ryood 0:5bc618f6d862 90 UImode(0),
ryood 0:5bc618f6d862 91 isStepChanged(false),
ryood 0:5bc618f6d862 92 errCutoff(0),
ryood 0:5bc618f6d862 93 errDuration(0),
ryood 0:5bc618f6d862 94 errDecay(0),
ryood 0:5bc618f6d862 95 errSustain(0),
ryood 0:5bc618f6d862 96 errResonance(0),
ryood 0:5bc618f6d862 97 errLevel(0),
ryood 0:5bc618f6d862 98 errPulseWidth(0),
ryood 0:5bc618f6d862 99 errAccentLevel(0) {
ryood 0:5bc618f6d862 100 }
ryood 0:5bc618f6d862 101
ryood 0:5bc618f6d862 102 ~BaseMachineUIController() {}
ryood 0:5bc618f6d862 103
ryood 0:5bc618f6d862 104 void init() {
ryood 0:5bc618f6d862 105 //--------------------------------------------------------------------
ryood 0:5bc618f6d862 106 // Create Dvices
ryood 0:5bc618f6d862 107 //
ryood 0:5bc618f6d862 108 //ST7565(PinName mosi, PinName sclk, PinName cs, PinName rst, PinName a0);
ryood 0:5bc618f6d862 109 gLCD = new ST7565(PB_15, PB_13, PB_12, PB_2, PB_1);
ryood 8:62a65664a2fb 110 sequencerDisplay = new ST7565_SequencerDisplay(gLCD, sequences[sequencePattern], SEQUENCE_N);
ryood 0:5bc618f6d862 111
ryood 0:5bc618f6d862 112 AinPulseWidth = new AverageAnalogIn(PC_2, AIN_AVERAGE);
ryood 0:5bc618f6d862 113 AinCutOff = new AverageAnalogIn(PB_0, AIN_AVERAGE);
ryood 0:5bc618f6d862 114 AinResonance = new AverageAnalogIn(PC_1, AIN_AVERAGE);
ryood 0:5bc618f6d862 115 AinLevel = new AverageAnalogIn(PC_0, AIN_AVERAGE);
ryood 0:5bc618f6d862 116 AinDuration = new AverageAnalogIn(PA_4, AIN_AVERAGE);
ryood 0:5bc618f6d862 117 AinDecay = new AverageAnalogIn(PA_1, AIN_AVERAGE);
ryood 0:5bc618f6d862 118 AinSustain = new AverageAnalogIn(PA_0, AIN_AVERAGE);
ryood 0:5bc618f6d862 119 AinAccentLevel= new AverageAnalogIn(PC_3, AIN_AVERAGE);
ryood 0:5bc618f6d862 120
ryood 0:5bc618f6d862 121 RotEncStep = new RotaryEncoder(PA_11, PA_12, 0, SEQUENCE_N - 1, 0);
ryood 0:5bc618f6d862 122 RotEncPitch = new RotaryEncoder(PB_5, PB_4, 0, Sequence::getMaxPitch() - 1, 0);
ryood 4:0a55042fa86c 123 //RotEncBpm = new RotaryEncoder(PC_12, PC_10, bpmMin, bpmMax, 120);
ryood 4:0a55042fa86c 124 RotEncBpm = new RotaryEncoder(PA_14, PA_15, bpmMin, bpmMax, 120);
ryood 0:5bc618f6d862 125
ryood 4:0a55042fa86c 126 //PinWaveShape = new PinDetect(PD_2, PullUp);
ryood 4:0a55042fa86c 127 PinWaveShape = new PinDetect(PB_7, PullUp);
ryood 4:0a55042fa86c 128 //PinUIMode = new PinDetect(PC_11, PullUp);
ryood 4:0a55042fa86c 129 PinUIMode = new PinDetect(PC_13, PullUp);
ryood 0:5bc618f6d862 130 PinOctaveUp = new PinDetect(PB_3, PullUp);
ryood 0:5bc618f6d862 131 PinOctaveDown = new PinDetect(PA_10, PullUp);
ryood 0:5bc618f6d862 132 PinNoteOnOff = new PinDetect(PC_5, PullUp);
ryood 0:5bc618f6d862 133 PinTie = new PinDetect(PC_6, PullUp);
ryood 0:5bc618f6d862 134 PinAccent = new PinDetect(PC_8, PullUp);
ryood 0:5bc618f6d862 135 PinRunStop = new PinDetect(PC_9, PullUp);
ryood 5:c3ed523c0330 136
ryood 5:c3ed523c0330 137 Spi3 = new SPI(PC_12, PC_11, PC_10); // SPI3 mosi, miso, sclk;
ryood 5:c3ed523c0330 138 // ExioMcp23s17(int hardwareaddress, SPI& spi, PinName nCs, PinName nReset);
ryood 5:c3ed523c0330 139 Exio = new ExioMcp23s17(0x00, *Spi3, PD_2, PA_13);
ryood 5:c3ed523c0330 140 Exio->reset();
ryood 9:70b8f9935ef7 141
ryood 9:70b8f9935ef7 142 ExioInBufferA = new ExioInBuffer(Exio, ExioPortA);
ryood 9:70b8f9935ef7 143 for (int i = 0; i < 5; i++) {
ryood 9:70b8f9935ef7 144 ExioInA[i] = new ExioBufferedDebounceIn(ExioInBufferA, i);
ryood 9:70b8f9935ef7 145 }
ryood 5:c3ed523c0330 146
ryood 5:c3ed523c0330 147 ExioInBufferB = new ExioInBuffer(Exio, ExioPortB);
ryood 5:c3ed523c0330 148 for (int i = 0; i < 8; i++) {
ryood 5:c3ed523c0330 149 ExioIn[i] = new ExioBufferedDebounceIn(ExioInBufferB, i);
ryood 5:c3ed523c0330 150 }
ryood 0:5bc618f6d862 151
ryood 15:646a57eb89f3 152 ExioRotEnc1 = new ExioBufferedRotaryEncoder(ExioInBufferA, 6, 7, 0, EEPROMSlotMax - 1, 0);
ryood 9:70b8f9935ef7 153
ryood 10:a8ec7391a066 154 I2c1 = new I2C(PB_9, PB_8);
ryood 10:a8ec7391a066 155 At24c1024 = new AT24C1024(*I2c1);
ryood 10:a8ec7391a066 156
ryood 0:5bc618f6d862 157 //--------------------------------------------------------------------
ryood 0:5bc618f6d862 158 // Setup Devices
ryood 0:5bc618f6d862 159 //
ryood 0:5bc618f6d862 160 gLCD->set_spi_frequency(GLCD_SPI_RATE);
ryood 0:5bc618f6d862 161 gLCD->begin(0x12);
ryood 0:5bc618f6d862 162 gLCD->clear();
ryood 0:5bc618f6d862 163 gLCD->drawstring(0, 0, TITLE_STR1);
ryood 0:5bc618f6d862 164 gLCD->drawstring(0, 1, TITLE_STR2);
ryood 0:5bc618f6d862 165 gLCD->display();
ryood 0:5bc618f6d862 166 Thread::wait(1000);
ryood 0:5bc618f6d862 167
ryood 0:5bc618f6d862 168 RotEncStep->setInterval(100);
ryood 0:5bc618f6d862 169 RotEncPitch->setInterval(100);
ryood 0:5bc618f6d862 170 RotEncBpm->setInterval(100);
ryood 0:5bc618f6d862 171
ryood 0:5bc618f6d862 172 PinWaveShape->attach_asserted(this, &BaseMachineUIController::swWaveShapePressed);
ryood 0:5bc618f6d862 173 PinWaveShape->setAssertValue(0);
ryood 0:5bc618f6d862 174 PinWaveShape->setSampleFrequency();
ryood 0:5bc618f6d862 175
ryood 0:5bc618f6d862 176 PinUIMode->attach_asserted(this, &BaseMachineUIController::swUIModePressed);
ryood 0:5bc618f6d862 177 PinUIMode->setAssertValue(0);
ryood 0:5bc618f6d862 178 PinUIMode->setSampleFrequency();
ryood 0:5bc618f6d862 179
ryood 0:5bc618f6d862 180 PinOctaveUp->attach_asserted(this, &BaseMachineUIController::swOctaveUpPressed);
ryood 0:5bc618f6d862 181 PinOctaveUp->setAssertValue(0);
ryood 0:5bc618f6d862 182 PinOctaveUp->setSampleFrequency();
ryood 0:5bc618f6d862 183
ryood 0:5bc618f6d862 184 PinOctaveDown->attach_asserted(this, &BaseMachineUIController::swOctaveDownPressed);
ryood 0:5bc618f6d862 185 PinOctaveDown->setAssertValue(0);
ryood 0:5bc618f6d862 186 PinOctaveDown->setSampleFrequency();
ryood 0:5bc618f6d862 187
ryood 0:5bc618f6d862 188 PinNoteOnOff->attach_asserted(this, &BaseMachineUIController::swNoteOnOffPressed);
ryood 0:5bc618f6d862 189 PinNoteOnOff->setAssertValue(0);
ryood 0:5bc618f6d862 190 PinNoteOnOff->setSampleFrequency();
ryood 0:5bc618f6d862 191
ryood 0:5bc618f6d862 192 PinTie->attach_asserted(this, &BaseMachineUIController::swTiePressed);
ryood 0:5bc618f6d862 193 PinTie->setAssertValue(0);
ryood 0:5bc618f6d862 194 PinTie->setSampleFrequency();
ryood 0:5bc618f6d862 195
ryood 0:5bc618f6d862 196 PinAccent->attach_asserted(this, &BaseMachineUIController::swAccentPressed);
ryood 0:5bc618f6d862 197 PinAccent->setAssertValue(0);
ryood 0:5bc618f6d862 198 PinAccent->setSampleFrequency();
ryood 0:5bc618f6d862 199
ryood 0:5bc618f6d862 200 PinRunStop->attach_asserted(this, &BaseMachineUIController::swRunStopPressed);
ryood 0:5bc618f6d862 201 PinRunStop->setAssertValue(0);
ryood 0:5bc618f6d862 202 PinRunStop->setSampleFrequency();
ryood 5:c3ed523c0330 203
ryood 9:70b8f9935ef7 204 ExioInBufferA->run(10);
ryood 9:70b8f9935ef7 205 for (int i = 0; i < 5; i++) {
ryood 9:70b8f9935ef7 206 ExioInA[i]->set_debounce_us(5000);
ryood 9:70b8f9935ef7 207 }
ryood 9:70b8f9935ef7 208
ryood 5:c3ed523c0330 209 ExioInBufferB->run(10);
ryood 5:c3ed523c0330 210 for (int i = 0; i < 8; i++) {
ryood 6:5ef23727ce6a 211 ExioIn[i]->set_debounce_us(5000);
ryood 5:c3ed523c0330 212 }
ryood 0:5bc618f6d862 213
ryood 9:70b8f9935ef7 214 ExioRotEnc1->setInterval(1000);
ryood 9:70b8f9935ef7 215
ryood 0:5bc618f6d862 216 //--------------------------------------------------------------------
ryood 0:5bc618f6d862 217 // Initialize objects
ryood 0:5bc618f6d862 218 //
ryood 0:5bc618f6d862 219 Sequence::setBaseNoteNumber(baseNoteNumber);
ryood 0:5bc618f6d862 220
ryood 8:62a65664a2fb 221 for (int j = 0; j < PATTERN_N; j++) {
ryood 8:62a65664a2fb 222 for (int i = 0; i < SEQUENCE_N; i++) {
ryood 8:62a65664a2fb 223 sequences[j][i].setPitch(pitch[i]);
ryood 8:62a65664a2fb 224 sequences[j][i].setNoteOn(noteOn[i]);
ryood 8:62a65664a2fb 225 sequences[j][i].setTie(tie[i]);
ryood 8:62a65664a2fb 226 sequences[j][i].setAccent(accent[i]);
ryood 8:62a65664a2fb 227 }
ryood 0:5bc618f6d862 228 }
ryood 8:62a65664a2fb 229 RotEncPitch->setVal(sequences[sequencePattern][0].getPitch());
ryood 12:d4e5feab3a2d 230
ryood 12:d4e5feab3a2d 231 for (int i = 0; i < SEQUENCE_N; i++) {
ryood 12:d4e5feab3a2d 232 sequenceClipBoard[i].setPitch(pitch[i]);
ryood 12:d4e5feab3a2d 233 sequenceClipBoard[i].setNoteOn(noteOn[i]);
ryood 12:d4e5feab3a2d 234 sequenceClipBoard[i].setTie(tie[i]);
ryood 12:d4e5feab3a2d 235 sequenceClipBoard[i].setAccent(accent[i]);
ryood 12:d4e5feab3a2d 236 }
ryood 0:5bc618f6d862 237 }
ryood 0:5bc618f6d862 238
ryood 0:5bc618f6d862 239 void destract() {
ryood 0:5bc618f6d862 240 //--------------------------------------------------------------------
ryood 0:5bc618f6d862 241 // Destract Devices
ryood 0:5bc618f6d862 242 //
ryood 0:5bc618f6d862 243 delete gLCD;
ryood 0:5bc618f6d862 244
ryood 0:5bc618f6d862 245 delete AinPulseWidth;
ryood 0:5bc618f6d862 246 delete AinCutOff;
ryood 0:5bc618f6d862 247 delete AinResonance;
ryood 0:5bc618f6d862 248 delete AinLevel;
ryood 0:5bc618f6d862 249 delete AinDuration;
ryood 0:5bc618f6d862 250 delete AinDecay;
ryood 0:5bc618f6d862 251 delete AinSustain;
ryood 0:5bc618f6d862 252 delete AinAccentLevel;
ryood 0:5bc618f6d862 253
ryood 0:5bc618f6d862 254 delete RotEncStep;
ryood 0:5bc618f6d862 255 delete RotEncPitch;
ryood 0:5bc618f6d862 256 delete RotEncBpm;
ryood 0:5bc618f6d862 257
ryood 0:5bc618f6d862 258 delete PinWaveShape;
ryood 0:5bc618f6d862 259 delete PinUIMode;
ryood 0:5bc618f6d862 260 delete PinOctaveUp;
ryood 0:5bc618f6d862 261 delete PinOctaveDown;
ryood 0:5bc618f6d862 262 delete PinNoteOnOff;
ryood 0:5bc618f6d862 263 delete PinTie;
ryood 0:5bc618f6d862 264 delete PinAccent;
ryood 0:5bc618f6d862 265 delete PinRunStop;
ryood 5:c3ed523c0330 266
ryood 9:70b8f9935ef7 267 delete[] ExioInA;
ryood 9:70b8f9935ef7 268 delete ExioRotEnc1;
ryood 5:c3ed523c0330 269 delete[] ExioIn;
ryood 9:70b8f9935ef7 270 delete ExioInBufferA;
ryood 5:c3ed523c0330 271 delete ExioInBufferB;
ryood 5:c3ed523c0330 272 delete Exio;
ryood 5:c3ed523c0330 273 delete Spi3;
ryood 10:a8ec7391a066 274
ryood 10:a8ec7391a066 275 delete At24c1024;
ryood 10:a8ec7391a066 276 delete I2c1;
ryood 0:5bc618f6d862 277 }
ryood 0:5bc618f6d862 278
ryood 3:f790643458d9 279 void getSequences(Sequence (*pSequences)[SEQUENCE_N]) {
ryood 8:62a65664a2fb 280 memcpy(pSequences, sequences[sequencePattern], sizeof(sequences[sequencePattern]));
ryood 3:f790643458d9 281 }
ryood 8:62a65664a2fb 282 /*
ryood 8:62a65664a2fb 283 void setSequences(Sequence* pSequence) {
ryood 8:62a65664a2fb 284 memcpy(sequences[sequencePattern], pSequence, sizeof(sequences[sequencePattern]));
ryood 8:62a65664a2fb 285 }
ryood 8:62a65664a2fb 286 */
ryood 3:f790643458d9 287
ryood 0:5bc618f6d862 288 void getOscillatorParam(OscillatorParam* pParam) {
ryood 0:5bc618f6d862 289 memcpy(pParam, &oscillatorParam, sizeof(oscillatorParam));
ryood 0:5bc618f6d862 290 }
ryood 0:5bc618f6d862 291 void getFilterParam(FilterParam* pParam) {
ryood 0:5bc618f6d862 292 memcpy(pParam, &filterParam, sizeof(filterParam));
ryood 0:5bc618f6d862 293 }
ryood 0:5bc618f6d862 294 void getEnvelopeParam(EnvelopeParam* pParam) {
ryood 0:5bc618f6d862 295 memcpy(pParam, &envelopeParam, sizeof(envelopeParam));
ryood 0:5bc618f6d862 296 }
ryood 0:5bc618f6d862 297 uint8_t getBpm() { return bpm; }
ryood 0:5bc618f6d862 298 uint8_t getAccentLevel() { return accentLevel; }
ryood 7:0f8efe0e1e3f 299 uint8_t getSequencePattern() { return sequencePattern; }
ryood 0:5bc618f6d862 300
ryood 0:5bc618f6d862 301 bool getIsRunning() { return isRunning; }
ryood 0:5bc618f6d862 302
ryood 0:5bc618f6d862 303 void setPlayingStep(int step)
ryood 0:5bc618f6d862 304 {
ryood 0:5bc618f6d862 305 playingStep = step;
ryood 0:5bc618f6d862 306 isDirty = true;
ryood 0:5bc618f6d862 307 }
ryood 0:5bc618f6d862 308
ryood 0:5bc618f6d862 309 void update() {
ryood 0:5bc618f6d862 310 pollingRotEncs();
ryood 0:5bc618f6d862 311 pollingPots();
ryood 5:c3ed523c0330 312 pollingExio();
ryood 0:5bc618f6d862 313
ryood 0:5bc618f6d862 314 switch (UImode) {
ryood 0:5bc618f6d862 315 case 0:
ryood 0:5bc618f6d862 316 if (isDirty) {
ryood 1:ecae97c65943 317 if (isRunning) {
ryood 1:ecae97c65943 318 sequencerDisplay->update(SequencerDisplay::run, editingStep, playingStep);
ryood 1:ecae97c65943 319 } else {
ryood 1:ecae97c65943 320 sequencerDisplay->update(SequencerDisplay::stop, editingStep, playingStep);
ryood 1:ecae97c65943 321 }
ryood 1:ecae97c65943 322 isDirty = false;
ryood 0:5bc618f6d862 323 }
ryood 0:5bc618f6d862 324 break;
ryood 0:5bc618f6d862 325 case 1:
ryood 1:ecae97c65943 326 dumpToLCD00();
ryood 0:5bc618f6d862 327 break;
ryood 0:5bc618f6d862 328 case 2:
ryood 0:5bc618f6d862 329 dumpToLCD01();
ryood 0:5bc618f6d862 330 break;
ryood 5:c3ed523c0330 331 case 3:
ryood 5:c3ed523c0330 332 dumpToLCD02();
ryood 5:c3ed523c0330 333 break;
ryood 0:5bc618f6d862 334 }
ryood 10:a8ec7391a066 335
ryood 15:646a57eb89f3 336 switch (loadSaveFlag) {
ryood 16:566ddb132ef8 337 case flagSaveToEeprom:
ryood 16:566ddb132ef8 338 saveToEeprom();
ryood 16:566ddb132ef8 339 Thread::wait(500);
ryood 10:a8ec7391a066 340 isDirty = true;
ryood 10:a8ec7391a066 341 break;
ryood 16:566ddb132ef8 342 case flagLoadFromEeprom:
ryood 16:566ddb132ef8 343 loadFromEeprom();
ryood 16:566ddb132ef8 344 Thread::wait(500);
ryood 10:a8ec7391a066 345 isDirty = true;
ryood 10:a8ec7391a066 346 break;
ryood 16:566ddb132ef8 347 case flagCopyToClipBoard:
ryood 12:d4e5feab3a2d 348 copyToClipBoard();
ryood 16:566ddb132ef8 349 Thread::wait(10);
ryood 16:566ddb132ef8 350 isDirty = true;
ryood 12:d4e5feab3a2d 351 break;
ryood 16:566ddb132ef8 352 case flagPasteFromClipBoard:
ryood 12:d4e5feab3a2d 353 pasteFromClipBoard();
ryood 16:566ddb132ef8 354 Thread::wait(10);
ryood 12:d4e5feab3a2d 355 isDirty = true;
ryood 12:d4e5feab3a2d 356 break;
ryood 10:a8ec7391a066 357 }
ryood 0:5bc618f6d862 358 }
ryood 0:5bc618f6d862 359
ryood 0:5bc618f6d862 360 private:
ryood 0:5bc618f6d862 361 ST7565* gLCD;
ryood 5:c3ed523c0330 362
ryood 5:c3ed523c0330 363 SPI* Spi3;
ryood 5:c3ed523c0330 364 ExioMcp23s17* Exio;
ryood 9:70b8f9935ef7 365 ExioInBuffer* ExioInBufferA;
ryood 5:c3ed523c0330 366 ExioInBuffer* ExioInBufferB;
ryood 9:70b8f9935ef7 367 ExioBufferedDebounceIn* ExioInA[5];
ryood 5:c3ed523c0330 368 ExioBufferedDebounceIn* ExioIn[8];
ryood 9:70b8f9935ef7 369 ExioBufferedRotaryEncoder* ExioRotEnc1;
ryood 10:a8ec7391a066 370
ryood 10:a8ec7391a066 371 I2C* I2c1;
ryood 10:a8ec7391a066 372 AT24C1024* At24c1024;
ryood 0:5bc618f6d862 373
ryood 0:5bc618f6d862 374 AverageAnalogIn* AinPulseWidth;
ryood 0:5bc618f6d862 375 AverageAnalogIn* AinCutOff;
ryood 0:5bc618f6d862 376 AverageAnalogIn* AinResonance;
ryood 0:5bc618f6d862 377 AverageAnalogIn* AinLevel;
ryood 0:5bc618f6d862 378 AverageAnalogIn* AinDuration;
ryood 0:5bc618f6d862 379 AverageAnalogIn* AinDecay;
ryood 0:5bc618f6d862 380 AverageAnalogIn* AinSustain;
ryood 0:5bc618f6d862 381 AverageAnalogIn* AinAccentLevel;
ryood 0:5bc618f6d862 382
ryood 0:5bc618f6d862 383 RotaryEncoder* RotEncStep;
ryood 0:5bc618f6d862 384 RotaryEncoder* RotEncPitch;
ryood 0:5bc618f6d862 385 RotaryEncoder* RotEncBpm;
ryood 0:5bc618f6d862 386
ryood 0:5bc618f6d862 387 PinDetect* PinWaveShape;
ryood 0:5bc618f6d862 388 PinDetect* PinUIMode;
ryood 0:5bc618f6d862 389 PinDetect* PinOctaveUp;
ryood 0:5bc618f6d862 390 PinDetect* PinOctaveDown;
ryood 0:5bc618f6d862 391 PinDetect* PinNoteOnOff;
ryood 0:5bc618f6d862 392 PinDetect* PinTie;
ryood 0:5bc618f6d862 393 PinDetect* PinAccent;
ryood 0:5bc618f6d862 394 PinDetect* PinRunStop;
ryood 0:5bc618f6d862 395
ryood 0:5bc618f6d862 396 ST7565_SequencerDisplay* sequencerDisplay;
ryood 0:5bc618f6d862 397
ryood 8:62a65664a2fb 398 Sequence sequences[PATTERN_N][SEQUENCE_N];
ryood 12:d4e5feab3a2d 399 Sequence sequenceClipBoard[SEQUENCE_N];
ryood 0:5bc618f6d862 400
ryood 0:5bc618f6d862 401 OscillatorParam oscillatorParam;
ryood 0:5bc618f6d862 402 FilterParam filterParam;
ryood 0:5bc618f6d862 403 EnvelopeParam envelopeParam;
ryood 0:5bc618f6d862 404
ryood 0:5bc618f6d862 405 uint8_t bpm;
ryood 0:5bc618f6d862 406 uint8_t accentLevel;
ryood 6:5ef23727ce6a 407 uint8_t sequencePattern;
ryood 15:646a57eb89f3 408 uint8_t loadSaveFlag;
ryood 15:646a57eb89f3 409 uint8_t eepromSlot;
ryood 0:5bc618f6d862 410
ryood 0:5bc618f6d862 411 int editingStep;
ryood 0:5bc618f6d862 412 int playingStep;
ryood 0:5bc618f6d862 413 bool isRunning;
ryood 0:5bc618f6d862 414 bool isDirty;
ryood 12:d4e5feab3a2d 415 bool isClipBoardEmpty;
ryood 0:5bc618f6d862 416 int UImode;
ryood 0:5bc618f6d862 417
ryood 0:5bc618f6d862 418 bool isStepChanged;
ryood 0:5bc618f6d862 419
ryood 0:5bc618f6d862 420 int errCutoff;
ryood 0:5bc618f6d862 421 int errDuration;
ryood 0:5bc618f6d862 422 int errDecay;
ryood 0:5bc618f6d862 423 int errSustain;
ryood 0:5bc618f6d862 424 int errResonance;
ryood 0:5bc618f6d862 425 int errLevel;
ryood 0:5bc618f6d862 426 int errPulseWidth;
ryood 0:5bc618f6d862 427 int errAccentLevel;
ryood 0:5bc618f6d862 428
ryood 0:5bc618f6d862 429 //------------------------------------------------------------------------
ryood 0:5bc618f6d862 430 // PinDetect callback functions
ryood 0:5bc618f6d862 431 //------------------------------------------------------------------------
ryood 0:5bc618f6d862 432 void swWaveShapePressed() {
ryood 0:5bc618f6d862 433 #if (UART_TRACE)
ryood 0:5bc618f6d862 434 printf("PinWaveShape Pushed\r\n");
ryood 0:5bc618f6d862 435 #endif
ryood 0:5bc618f6d862 436 uint8_t _waveShape = oscillatorParam.waveShape;
ryood 0:5bc618f6d862 437 _waveShape++;
ryood 0:5bc618f6d862 438 if (_waveShape > waveShapeMax) {
ryood 0:5bc618f6d862 439 _waveShape = 0;
ryood 0:5bc618f6d862 440 }
ryood 0:5bc618f6d862 441 oscillatorParam.waveShape = _waveShape;
ryood 0:5bc618f6d862 442 sequencerDisplay->setWaveShape(_waveShape);
ryood 0:5bc618f6d862 443 isDirty = true;
ryood 0:5bc618f6d862 444 }
ryood 0:5bc618f6d862 445
ryood 0:5bc618f6d862 446 void swUIModePressed() {
ryood 0:5bc618f6d862 447 #if (UART_TRACE)
ryood 0:5bc618f6d862 448 printf("PinUIMode Pushed\r\n");
ryood 0:5bc618f6d862 449 #endif
ryood 0:5bc618f6d862 450 UImode++;
ryood 0:5bc618f6d862 451 if (UImode > UImodeMax) {
ryood 0:5bc618f6d862 452 UImode = 0;
ryood 0:5bc618f6d862 453 }
ryood 0:5bc618f6d862 454 isDirty = true;
ryood 0:5bc618f6d862 455 }
ryood 0:5bc618f6d862 456
ryood 0:5bc618f6d862 457 void swOctaveUpPressed() {
ryood 0:5bc618f6d862 458 #if (UART_TRACE)
ryood 0:5bc618f6d862 459 printf("PinOctaveUp Pushed\r\n");
ryood 0:5bc618f6d862 460 #endif
ryood 0:5bc618f6d862 461 if (sequencerDisplay->getOctave() < octaveMax) {
ryood 0:5bc618f6d862 462 sequencerDisplay->setOctave(sequencerDisplay->getOctave() + 1);
ryood 0:5bc618f6d862 463 isDirty = true;
ryood 0:5bc618f6d862 464 }
ryood 0:5bc618f6d862 465 }
ryood 0:5bc618f6d862 466
ryood 0:5bc618f6d862 467 void swOctaveDownPressed() {
ryood 0:5bc618f6d862 468 #if (UART_TRACE)
ryood 0:5bc618f6d862 469 printf("PinOctaveDown Pushed\r\n");
ryood 0:5bc618f6d862 470 #endif
ryood 0:5bc618f6d862 471 if (sequencerDisplay->getOctave () > octaveMin) {
ryood 0:5bc618f6d862 472 sequencerDisplay->setOctave(sequencerDisplay->getOctave() - 1);
ryood 0:5bc618f6d862 473 isDirty = true;
ryood 0:5bc618f6d862 474 }
ryood 0:5bc618f6d862 475 }
ryood 0:5bc618f6d862 476
ryood 0:5bc618f6d862 477 void swNoteOnOffPressed() {
ryood 0:5bc618f6d862 478 #if (UART_TRACE)
ryood 0:5bc618f6d862 479 printf("PinNoteOnOff Pushed\r\n");
ryood 0:5bc618f6d862 480 #endif
ryood 8:62a65664a2fb 481 sequences[sequencePattern][editingStep].setNoteOn(!sequences[sequencePattern][editingStep].isNoteOn());
ryood 0:5bc618f6d862 482 isDirty = true;
ryood 0:5bc618f6d862 483 }
ryood 0:5bc618f6d862 484
ryood 0:5bc618f6d862 485 void swTiePressed() {
ryood 0:5bc618f6d862 486 #if (UART_TRACE)
ryood 0:5bc618f6d862 487 printf("PinTie Pushed\r\n");
ryood 0:5bc618f6d862 488 #endif
ryood 8:62a65664a2fb 489 sequences[sequencePattern][editingStep].setTie(!sequences[sequencePattern][editingStep].isTie());
ryood 0:5bc618f6d862 490 isDirty = true;
ryood 0:5bc618f6d862 491 }
ryood 0:5bc618f6d862 492
ryood 0:5bc618f6d862 493 void swAccentPressed() {
ryood 0:5bc618f6d862 494 #if (UART_TRACE)
ryood 0:5bc618f6d862 495 printf("PinAccent Pushed\r\n");
ryood 0:5bc618f6d862 496 #endif
ryood 8:62a65664a2fb 497 sequences[sequencePattern][editingStep].setAccent(!sequences[sequencePattern][editingStep].isAccent());
ryood 0:5bc618f6d862 498 isDirty = true;
ryood 0:5bc618f6d862 499 }
ryood 0:5bc618f6d862 500
ryood 0:5bc618f6d862 501 void swRunStopPressed() {
ryood 0:5bc618f6d862 502 #if (UART_TRACE)
ryood 0:5bc618f6d862 503 printf("PinRunStop Pushed\r\n");
ryood 0:5bc618f6d862 504 #endif
ryood 0:5bc618f6d862 505 if (isRunning) {
ryood 0:5bc618f6d862 506 isRunning = false;
ryood 0:5bc618f6d862 507 } else {
ryood 0:5bc618f6d862 508 isRunning = true;
ryood 0:5bc618f6d862 509 }
ryood 0:5bc618f6d862 510 isDirty = true;
ryood 0:5bc618f6d862 511 }
ryood 0:5bc618f6d862 512
ryood 0:5bc618f6d862 513 //------------------------------------------------------------------------
ryood 0:5bc618f6d862 514 // Functions
ryood 0:5bc618f6d862 515 //------------------------------------------------------------------------
ryood 0:5bc618f6d862 516 void pollingRotEncs() {
ryood 0:5bc618f6d862 517 int _bpm = RotEncBpm->getVal();
ryood 0:5bc618f6d862 518 if (_bpm != bpm) {
ryood 0:5bc618f6d862 519 bpm = _bpm;
ryood 0:5bc618f6d862 520 sequencerDisplay->setBpm(_bpm);
ryood 0:5bc618f6d862 521 isDirty = true;
ryood 0:5bc618f6d862 522 }
ryood 0:5bc618f6d862 523
ryood 0:5bc618f6d862 524 int _step = RotEncStep->getVal();
ryood 0:5bc618f6d862 525 if (_step != editingStep) {
ryood 0:5bc618f6d862 526 editingStep = _step;
ryood 0:5bc618f6d862 527 // syncronize sequence value & Rotary Encoder's value
ryood 8:62a65664a2fb 528 RotEncPitch->setVal(sequences[sequencePattern][editingStep].getPitch());
ryood 0:5bc618f6d862 529 isDirty = true;
ryood 0:5bc618f6d862 530 }
ryood 0:5bc618f6d862 531
ryood 0:5bc618f6d862 532 int _pitch = RotEncPitch->getVal();
ryood 8:62a65664a2fb 533 if (_pitch != sequences[sequencePattern][editingStep].getPitch()) {
ryood 8:62a65664a2fb 534 sequences[sequencePattern][editingStep].setPitch(_pitch);
ryood 0:5bc618f6d862 535 isDirty = true;
ryood 0:5bc618f6d862 536 }
ryood 0:5bc618f6d862 537 }
ryood 0:5bc618f6d862 538
ryood 0:5bc618f6d862 539 void pollingPots() {
ryood 0:5bc618f6d862 540 uint8_t pulseWidth = AinPulseWidth->read_u16() >> (16 - POT_RESOLUTION);
ryood 0:5bc618f6d862 541 if (pulseWidth != oscillatorParam.pulseWidth) {
ryood 0:5bc618f6d862 542 oscillatorParam.pulseWidth = pulseWidth;
ryood 0:5bc618f6d862 543 errPulseWidth++;
ryood 1:ecae97c65943 544 //isDirty = true;
ryood 0:5bc618f6d862 545 }
ryood 0:5bc618f6d862 546
ryood 0:5bc618f6d862 547 uint8_t cutoff = AinCutOff->read_u16() >> (16 - POT_RESOLUTION);
ryood 0:5bc618f6d862 548 if (cutoff != filterParam.cutoff) {
ryood 0:5bc618f6d862 549 filterParam.cutoff = cutoff;
ryood 0:5bc618f6d862 550 errCutoff++;
ryood 1:ecae97c65943 551 //isDirty = true;
ryood 0:5bc618f6d862 552 }
ryood 0:5bc618f6d862 553
ryood 0:5bc618f6d862 554 uint8_t resonance = AinResonance->read_u16() >> (16 - POT_RESOLUTION);
ryood 0:5bc618f6d862 555 if (resonance != filterParam.resonance) {
ryood 0:5bc618f6d862 556 filterParam.resonance = resonance;
ryood 0:5bc618f6d862 557 errResonance++;
ryood 1:ecae97c65943 558 //isDirty = true;
ryood 0:5bc618f6d862 559 }
ryood 0:5bc618f6d862 560
ryood 0:5bc618f6d862 561 uint8_t level = AinLevel->read_u16() >> (16 - POT_RESOLUTION);
ryood 0:5bc618f6d862 562 if (level != envelopeParam.level) {
ryood 0:5bc618f6d862 563 errLevel++;
ryood 0:5bc618f6d862 564 envelopeParam.level = level;
ryood 1:ecae97c65943 565 //isDirty = true;
ryood 0:5bc618f6d862 566 }
ryood 0:5bc618f6d862 567
ryood 0:5bc618f6d862 568 uint8_t duration = AinDuration->read_u16() >> (16 - POT_RESOLUTION);
ryood 0:5bc618f6d862 569 if (duration != envelopeParam.duration) {
ryood 0:5bc618f6d862 570 errDuration++;
ryood 0:5bc618f6d862 571 envelopeParam.duration = duration;
ryood 1:ecae97c65943 572 //isDirty = true;
ryood 0:5bc618f6d862 573 }
ryood 0:5bc618f6d862 574
ryood 0:5bc618f6d862 575 uint8_t decay = AinDecay->read_u16() >> (16 - POT_RESOLUTION);
ryood 0:5bc618f6d862 576 if (decay != envelopeParam.decay) {
ryood 0:5bc618f6d862 577 errDecay++;
ryood 0:5bc618f6d862 578 envelopeParam.decay = decay;
ryood 1:ecae97c65943 579 //isDirty = true;
ryood 0:5bc618f6d862 580 }
ryood 0:5bc618f6d862 581
ryood 0:5bc618f6d862 582 uint8_t sustain = AinSustain->read_u16() >> (16 - POT_RESOLUTION);
ryood 0:5bc618f6d862 583 if (sustain != envelopeParam.sustain) {
ryood 0:5bc618f6d862 584 errSustain++;
ryood 0:5bc618f6d862 585 envelopeParam.sustain = sustain;
ryood 1:ecae97c65943 586 //isDirty = true;
ryood 0:5bc618f6d862 587 }
ryood 0:5bc618f6d862 588
ryood 0:5bc618f6d862 589 uint8_t _accentLevel = AinAccentLevel->read_u16() >> (16 - POT_RESOLUTION);
ryood 0:5bc618f6d862 590 if (_accentLevel != accentLevel) {
ryood 0:5bc618f6d862 591 errAccentLevel++;
ryood 0:5bc618f6d862 592 accentLevel = _accentLevel;
ryood 1:ecae97c65943 593 //isDirty = true;
ryood 0:5bc618f6d862 594 }
ryood 0:5bc618f6d862 595 }
ryood 0:5bc618f6d862 596
ryood 5:c3ed523c0330 597 void pollingExio()
ryood 5:c3ed523c0330 598 {
ryood 6:5ef23727ce6a 599 int i;
ryood 6:5ef23727ce6a 600 for (i = 0; i < 8; i++) {
ryood 6:5ef23727ce6a 601 if (ExioIn[i]->read()) break;
ryood 6:5ef23727ce6a 602 }
ryood 7:0f8efe0e1e3f 603 if (i != 8 && sequencePattern != i) {
ryood 7:0f8efe0e1e3f 604 sequencePattern = i;
ryood 8:62a65664a2fb 605 // syncronize sequence value & Rotary Encoder's value
ryood 8:62a65664a2fb 606 RotEncPitch->setVal(sequences[sequencePattern][editingStep].getPitch());
ryood 8:62a65664a2fb 607
ryood 8:62a65664a2fb 608 sequencerDisplay->setSequences(sequences[sequencePattern]);
ryood 10:a8ec7391a066 609 sequencerDisplay->setSequencePattern(sequencePattern);
ryood 6:5ef23727ce6a 610 isDirty = true;
ryood 5:c3ed523c0330 611 }
ryood 9:70b8f9935ef7 612
ryood 15:646a57eb89f3 613 loadSaveFlag = 0;
ryood 9:70b8f9935ef7 614 for (i = 0; i < 5; i++) {
ryood 15:646a57eb89f3 615 loadSaveFlag |= ((ExioInA[i]->read()) << i);
ryood 9:70b8f9935ef7 616 }
ryood 13:d3ee2ba4efaf 617
ryood 13:d3ee2ba4efaf 618 #if (UART_TRACE)
ryood 15:646a57eb89f3 619 if (loadSaveFlag != 0) {
ryood 15:646a57eb89f3 620 printf("loadSaveFlag: %d\r\n", loadSaveFlag);
ryood 12:d4e5feab3a2d 621 }
ryood 13:d3ee2ba4efaf 622 #endif
ryood 9:70b8f9935ef7 623
ryood 15:646a57eb89f3 624 eepromSlot = ExioRotEnc1->getVal();
ryood 5:c3ed523c0330 625 }
ryood 5:c3ed523c0330 626
ryood 0:5bc618f6d862 627 void dumpToLCD00() {
ryood 0:5bc618f6d862 628 char buff[64];
ryood 0:5bc618f6d862 629 int col = 0;
ryood 0:5bc618f6d862 630
ryood 0:5bc618f6d862 631 gLCD->clear();
ryood 0:5bc618f6d862 632
ryood 8:62a65664a2fb 633 sprintf(buff, "Run:%d BPM:%03d Ptn:%02d", isRunning, bpm, sequencePattern + 1);
ryood 0:5bc618f6d862 634 gLCD->drawstring(0, col++, buff);
ryood 0:5bc618f6d862 635
ryood 0:5bc618f6d862 636 sprintf(buff, "Stp:%02d Nto:%d Pch:%02d",
ryood 8:62a65664a2fb 637 editingStep, sequences[sequencePattern][editingStep].isNoteOn(), sequences[sequencePattern][editingStep].getPitch());
ryood 0:5bc618f6d862 638 gLCD->drawstring(0, col++, buff);
ryood 0:5bc618f6d862 639
ryood 15:646a57eb89f3 640 sprintf(buff, "Oct:%-2d Tie:%d Acc:%d",
ryood 15:646a57eb89f3 641 sequencerDisplay->getOctave(), sequences[sequencePattern][editingStep].isTie(),sequences[sequencePattern][editingStep].isAccent());
ryood 0:5bc618f6d862 642 gLCD->drawstring(0, col++, buff);
ryood 0:5bc618f6d862 643
ryood 15:646a57eb89f3 644 sprintf(buff, "Wsp:%d Mod:%d pStp:%d", oscillatorParam.waveShape, UImode, playingStep);
ryood 0:5bc618f6d862 645 gLCD->drawstring(0, col++, buff);
ryood 0:5bc618f6d862 646
ryood 15:646a57eb89f3 647 sprintf(buff, "LSF:%d SLT:%d", loadSaveFlag, eepromSlot);
ryood 15:646a57eb89f3 648 gLCD->drawstring(0, col++, buff);
ryood 15:646a57eb89f3 649
ryood 15:646a57eb89f3 650 /*
ryood 2:238127b00dd3 651 sprintf(buff, "RSO:%4d CO :%4d", filterParam.resonance, filterParam.cutoff);
ryood 0:5bc618f6d862 652 gLCD->drawstring(0, col++, buff);
ryood 0:5bc618f6d862 653 sprintf(buff, "LVL:%4d DUR:%4d", envelopeParam.level, envelopeParam.duration);
ryood 0:5bc618f6d862 654 gLCD->drawstring(0, col++, buff);
ryood 1:ecae97c65943 655 sprintf(buff, "PW :%4d DCY:%4d", oscillatorParam.pulseWidth, envelopeParam.decay);
ryood 1:ecae97c65943 656 gLCD->drawstring(0, col++, buff);
ryood 1:ecae97c65943 657 sprintf(buff, "ACL:%4d SUS:%4d", accentLevel, envelopeParam.sustain);
ryood 0:5bc618f6d862 658 gLCD->drawstring(0, col++, buff);
ryood 15:646a57eb89f3 659 */
ryood 0:5bc618f6d862 660
ryood 0:5bc618f6d862 661 gLCD->display();
ryood 0:5bc618f6d862 662 }
ryood 0:5bc618f6d862 663
ryood 5:c3ed523c0330 664 void dumpToLCD01()
ryood 5:c3ed523c0330 665 {
ryood 0:5bc618f6d862 666 char buff[64];
ryood 0:5bc618f6d862 667
ryood 0:5bc618f6d862 668 gLCD->clear();
ryood 0:5bc618f6d862 669
ryood 0:5bc618f6d862 670 sprintf(buff, "Cutoff %3d %5d", filterParam.cutoff, errCutoff);
ryood 0:5bc618f6d862 671 gLCD->drawstring(0, 0, buff);
ryood 0:5bc618f6d862 672 sprintf(buff, "Duration %3d %5d", envelopeParam.duration, errDuration);
ryood 0:5bc618f6d862 673 gLCD->drawstring(0, 1, buff);
ryood 0:5bc618f6d862 674 sprintf(buff, "Decay %3d %5d", envelopeParam.decay, errDecay);
ryood 0:5bc618f6d862 675 gLCD->drawstring(0, 2, buff);
ryood 0:5bc618f6d862 676 sprintf(buff, "Sustain %3d %5d", envelopeParam.sustain, errSustain);
ryood 0:5bc618f6d862 677 gLCD->drawstring(0, 3, buff);
ryood 0:5bc618f6d862 678 sprintf(buff, "Resonance %3d %5d", filterParam.resonance, errResonance);
ryood 0:5bc618f6d862 679 gLCD->drawstring(0, 4, buff);
ryood 0:5bc618f6d862 680 sprintf(buff, "Level %3d %5d", envelopeParam.level, errLevel);
ryood 0:5bc618f6d862 681 gLCD->drawstring(0, 5, buff);
ryood 0:5bc618f6d862 682 sprintf(buff, "PulseWidth %3d %5d", oscillatorParam.pulseWidth, errPulseWidth);
ryood 0:5bc618f6d862 683 gLCD->drawstring(0, 6, buff);
ryood 0:5bc618f6d862 684 sprintf(buff, "AccentLvl %3d %5d", accentLevel, errAccentLevel);
ryood 0:5bc618f6d862 685 gLCD->drawstring(0, 7, buff);
ryood 0:5bc618f6d862 686
ryood 0:5bc618f6d862 687 gLCD->display();
ryood 0:5bc618f6d862 688 }
ryood 5:c3ed523c0330 689
ryood 5:c3ed523c0330 690 void dumpToLCD02()
ryood 5:c3ed523c0330 691 {
ryood 5:c3ed523c0330 692 char buff[64];
ryood 5:c3ed523c0330 693
ryood 5:c3ed523c0330 694 gLCD->clear();
ryood 5:c3ed523c0330 695
ryood 6:5ef23727ce6a 696 sprintf(buff, "sequencePattern %d", sequencePattern);
ryood 5:c3ed523c0330 697 gLCD->drawstring(0, 0, buff);
ryood 5:c3ed523c0330 698
ryood 5:c3ed523c0330 699 gLCD->display();
ryood 5:c3ed523c0330 700 }
ryood 10:a8ec7391a066 701
ryood 16:566ddb132ef8 702 void saveToEeprom()
ryood 10:a8ec7391a066 703 {
ryood 10:a8ec7391a066 704 char buff[64];
ryood 10:a8ec7391a066 705
ryood 10:a8ec7391a066 706 gLCD->clear();
ryood 10:a8ec7391a066 707
ryood 15:646a57eb89f3 708 sprintf(buff, "Save to EEPROM?[%02d]", eepromSlot);
ryood 10:a8ec7391a066 709 gLCD->drawstring(0, 0, buff);
ryood 10:a8ec7391a066 710 gLCD->display();
ryood 10:a8ec7391a066 711
ryood 15:646a57eb89f3 712 while (1) {
ryood 15:646a57eb89f3 713 pollingExio();
ryood 15:646a57eb89f3 714 sprintf(buff, "[%02d]", eepromSlot);
ryood 15:646a57eb89f3 715 gLCD->drawstring(90, 0, buff);
ryood 15:646a57eb89f3 716 gLCD->display();
ryood 16:566ddb132ef8 717 //ToDo: flagEepromCancel スイッチを増やして割り当てる
ryood 16:566ddb132ef8 718 if (loadSaveFlag & flagLoadFromEeprom) {
ryood 16:566ddb132ef8 719 gLCD->drawstring(0, 1, " Cancel");
ryood 16:566ddb132ef8 720 gLCD->display();
ryood 16:566ddb132ef8 721 return;
ryood 16:566ddb132ef8 722 }
ryood 16:566ddb132ef8 723 printf("loadSaveFlag: %2d\r\n", loadSaveFlag);
ryood 16:566ddb132ef8 724 if (loadSaveFlag & flagEepromOK) {
ryood 15:646a57eb89f3 725 break;
ryood 15:646a57eb89f3 726 }
ryood 15:646a57eb89f3 727 }
ryood 15:646a57eb89f3 728
ryood 15:646a57eb89f3 729 gLCD->drawstring(0, 1, " Saving...");
ryood 15:646a57eb89f3 730 gLCD->display();
ryood 15:646a57eb89f3 731
ryood 10:a8ec7391a066 732 #if (UART_TRACE_EEPROM)
ryood 10:a8ec7391a066 733 printf("*** Save Sequences to EEPROM ***\r\n");
ryood 11:a2a51191ebe4 734 for (int j = 0; j < PATTERN_N; j++) {
ryood 15:646a57eb89f3 735 printf("eepromSlot: %d\r\n", eepromSlot);
ryood 11:a2a51191ebe4 736 printf("sequencePattern: %d\r\n", j);
ryood 11:a2a51191ebe4 737 for (int i = 0; i < SEQUENCE_N; i++) {
ryood 11:a2a51191ebe4 738 printf("%d %d %03d %d %d\r\n",
ryood 11:a2a51191ebe4 739 i,
ryood 11:a2a51191ebe4 740 sequences[j][i].isNoteOn(),
ryood 11:a2a51191ebe4 741 sequences[j][i].getPitch(),
ryood 11:a2a51191ebe4 742 sequences[j][i].isTie(),
ryood 11:a2a51191ebe4 743 sequences[j][i].isAccent()
ryood 11:a2a51191ebe4 744 );
ryood 11:a2a51191ebe4 745 }
ryood 10:a8ec7391a066 746 }
ryood 10:a8ec7391a066 747 #endif
ryood 10:a8ec7391a066 748
ryood 10:a8ec7391a066 749 uint8_t eep_buff[258];
ryood 11:a2a51191ebe4 750 for (int j = 0; j < PATTERN_N; j++) {
ryood 11:a2a51191ebe4 751 uint8_t cnt = 0;
ryood 11:a2a51191ebe4 752 for (int i = 0; i < SEQUENCE_N; i++) {
ryood 11:a2a51191ebe4 753 eep_buff[cnt++] = sequences[j][i].isNoteOn();
ryood 11:a2a51191ebe4 754 eep_buff[cnt++] = ((sequences[j][i].getPitch() & 0xff00) >> 8); // MSB
ryood 11:a2a51191ebe4 755 eep_buff[cnt++] = sequences[j][i].getPitch() & 0xff; // LSB
ryood 11:a2a51191ebe4 756 eep_buff[cnt++] = sequences[j][i].isTie();
ryood 11:a2a51191ebe4 757 eep_buff[cnt++] = sequences[j][i].isAccent();
ryood 11:a2a51191ebe4 758 }
ryood 11:a2a51191ebe4 759 #if (UART_TRACE_EEPROM)
ryood 11:a2a51191ebe4 760 printf("size: %d\r\n", cnt);
ryood 11:a2a51191ebe4 761 #endif
ryood 11:a2a51191ebe4 762 /*
ryood 11:a2a51191ebe4 763 for (int i = 0; i < cnt; i++) {
ryood 11:a2a51191ebe4 764 printf("%d: %d\r\n", i, eep_buff[i]);
ryood 11:a2a51191ebe4 765 }
ryood 11:a2a51191ebe4 766 */
ryood 15:646a57eb89f3 767 uint32_t addr_page_top = (eepromSlot * PATTERN_N + j) << 8;
ryood 12:d4e5feab3a2d 768 #if (UART_TRACE_EEPROM)
ryood 12:d4e5feab3a2d 769 printf("address: %x\r\n", addr_page_top);
ryood 12:d4e5feab3a2d 770 #endif
ryood 11:a2a51191ebe4 771 AT24C_STATUS status = At24c1024->write_page(
ryood 11:a2a51191ebe4 772 addr_page_top,
ryood 11:a2a51191ebe4 773 eep_buff,
ryood 11:a2a51191ebe4 774 sizeof(eep_buff)
ryood 11:a2a51191ebe4 775 );
ryood 15:646a57eb89f3 776 Thread::wait(5);
ryood 15:646a57eb89f3 777
ryood 11:a2a51191ebe4 778 #if (UART_TRACE_EEPROM)
ryood 11:a2a51191ebe4 779 printf("status: %d\r\n", status);
ryood 11:a2a51191ebe4 780 #endif
ryood 10:a8ec7391a066 781 }
ryood 10:a8ec7391a066 782
ryood 15:646a57eb89f3 783 gLCD->drawstring(0, 2, " Done");
ryood 10:a8ec7391a066 784 gLCD->display();
ryood 10:a8ec7391a066 785 }
ryood 10:a8ec7391a066 786
ryood 16:566ddb132ef8 787 void loadFromEeprom()
ryood 10:a8ec7391a066 788 {
ryood 10:a8ec7391a066 789 char buff[64];
ryood 10:a8ec7391a066 790
ryood 10:a8ec7391a066 791 gLCD->clear();
ryood 10:a8ec7391a066 792
ryood 15:646a57eb89f3 793 sprintf(buff, "Load From EEPROM?[%02d]", eepromSlot);
ryood 10:a8ec7391a066 794 gLCD->drawstring(0, 0, buff);
ryood 10:a8ec7391a066 795 gLCD->display();
ryood 10:a8ec7391a066 796
ryood 15:646a57eb89f3 797 while (1) {
ryood 15:646a57eb89f3 798 pollingExio();
ryood 15:646a57eb89f3 799 sprintf(buff, "[%02d]", eepromSlot);
ryood 15:646a57eb89f3 800 gLCD->drawstring(102, 0, buff);
ryood 15:646a57eb89f3 801 gLCD->display();
ryood 16:566ddb132ef8 802 //ToDo: flagEepromCancel スイッチを増やして割り当てる
ryood 16:566ddb132ef8 803 if (loadSaveFlag & flagSaveToEeprom) {
ryood 16:566ddb132ef8 804 gLCD->drawstring(0, 1, " Cancel");
ryood 16:566ddb132ef8 805 gLCD->display();
ryood 16:566ddb132ef8 806 return;
ryood 16:566ddb132ef8 807 }
ryood 16:566ddb132ef8 808 if (loadSaveFlag &= flagEepromOK) {
ryood 15:646a57eb89f3 809 break;
ryood 15:646a57eb89f3 810 }
ryood 15:646a57eb89f3 811 }
ryood 15:646a57eb89f3 812
ryood 15:646a57eb89f3 813 gLCD->drawstring(0, 1, " Loading...");
ryood 15:646a57eb89f3 814 gLCD->display();
ryood 15:646a57eb89f3 815
ryood 10:a8ec7391a066 816 #if (UART_TRACE_EEPROM)
ryood 10:a8ec7391a066 817 printf("*** Load Sequences from EEPROM ***\r\n");
ryood 10:a8ec7391a066 818 #endif
ryood 10:a8ec7391a066 819
ryood 10:a8ec7391a066 820 uint8_t eep_buff[258];
ryood 10:a8ec7391a066 821
ryood 11:a2a51191ebe4 822 for (int j = 0; j < PATTERN_N; j++) {
ryood 15:646a57eb89f3 823 uint32_t addr_page_top = (eepromSlot * PATTERN_N + j) << 8;
ryood 15:646a57eb89f3 824
ryood 15:646a57eb89f3 825 #if (UART_TRACE_EEPROM)
ryood 15:646a57eb89f3 826 printf("address: %x\r\n", addr_page_top);
ryood 15:646a57eb89f3 827 #endif
ryood 15:646a57eb89f3 828
ryood 11:a2a51191ebe4 829 AT24C_STATUS status = At24c1024->read_page(
ryood 11:a2a51191ebe4 830 addr_page_top,
ryood 11:a2a51191ebe4 831 eep_buff,
ryood 11:a2a51191ebe4 832 sizeof(eep_buff)
ryood 11:a2a51191ebe4 833 );
ryood 11:a2a51191ebe4 834
ryood 11:a2a51191ebe4 835 #if (UART_TRACE_EEPROM)
ryood 11:a2a51191ebe4 836 printf("status: %d\r\n", status);
ryood 11:a2a51191ebe4 837 #endif
ryood 10:a8ec7391a066 838
ryood 11:a2a51191ebe4 839 /*
ryood 11:a2a51191ebe4 840 for (int i = 0; i < 80; i++) {
ryood 11:a2a51191ebe4 841 printf("%d: %d\r\n", i, eep_buff[i]);
ryood 11:a2a51191ebe4 842 }
ryood 11:a2a51191ebe4 843 */
ryood 10:a8ec7391a066 844
ryood 11:a2a51191ebe4 845 uint8_t cnt = 0;
ryood 11:a2a51191ebe4 846 for (int i = 0; i < SEQUENCE_N; i++) {
ryood 11:a2a51191ebe4 847 sequences[j][i].setNoteOn(eep_buff[cnt++]);
ryood 11:a2a51191ebe4 848 int pitch = eep_buff[cnt++] << 8; // MSB
ryood 11:a2a51191ebe4 849 pitch |= eep_buff[cnt++]; // LSB
ryood 11:a2a51191ebe4 850 sequences[j][i].setPitch(pitch);
ryood 11:a2a51191ebe4 851 sequences[j][i].setTie(eep_buff[cnt++]);
ryood 11:a2a51191ebe4 852 sequences[j][i].setAccent(eep_buff[cnt++]);
ryood 11:a2a51191ebe4 853 }
ryood 11:a2a51191ebe4 854
ryood 11:a2a51191ebe4 855 #if (UART_TRACE_EEPROM)
ryood 11:a2a51191ebe4 856 printf("size: %d\r\n", cnt);
ryood 15:646a57eb89f3 857 printf("eepromSlot: %d\r\n", eepromSlot);
ryood 11:a2a51191ebe4 858 printf("sequencePattern: %d\r\n", j);
ryood 11:a2a51191ebe4 859 #endif
ryood 10:a8ec7391a066 860 }
ryood 10:a8ec7391a066 861 // syncronize sequence value & Rotary Encoder's value
ryood 10:a8ec7391a066 862 RotEncPitch->setVal(sequences[sequencePattern][editingStep].getPitch());
ryood 10:a8ec7391a066 863
ryood 10:a8ec7391a066 864 #if (UART_TRACE_EEPROM)
ryood 11:a2a51191ebe4 865 for (int j = 0; j < PATTERN_N; j++) {
ryood 11:a2a51191ebe4 866 for (int i = 0; i < SEQUENCE_N; i++) {
ryood 11:a2a51191ebe4 867 printf("%d %d %03d %d %d\r\n",
ryood 11:a2a51191ebe4 868 i,
ryood 11:a2a51191ebe4 869 sequences[j][i].isNoteOn(),
ryood 11:a2a51191ebe4 870 sequences[j][i].getPitch(),
ryood 11:a2a51191ebe4 871 sequences[j][i].isTie(),
ryood 11:a2a51191ebe4 872 sequences[j][i].isAccent()
ryood 11:a2a51191ebe4 873 );
ryood 11:a2a51191ebe4 874 }
ryood 10:a8ec7391a066 875 }
ryood 10:a8ec7391a066 876 #endif
ryood 10:a8ec7391a066 877
ryood 15:646a57eb89f3 878 gLCD->drawstring(0, 2, " Done");
ryood 10:a8ec7391a066 879 gLCD->display();
ryood 10:a8ec7391a066 880 }
ryood 12:d4e5feab3a2d 881
ryood 12:d4e5feab3a2d 882 void copyToClipBoard()
ryood 12:d4e5feab3a2d 883 {
ryood 15:646a57eb89f3 884 gLCD->clear();
ryood 15:646a57eb89f3 885 gLCD->drawstring(0, 0, "Copy");
ryood 15:646a57eb89f3 886 gLCD->display();
ryood 15:646a57eb89f3 887
ryood 12:d4e5feab3a2d 888 for (int i = 0; i < SEQUENCE_N; i++) {
ryood 12:d4e5feab3a2d 889 sequenceClipBoard[i].setNoteOn(sequences[sequencePattern][i].isNoteOn());
ryood 12:d4e5feab3a2d 890 sequenceClipBoard[i].setPitch(sequences[sequencePattern][i].getPitch());
ryood 12:d4e5feab3a2d 891 sequenceClipBoard[i].setTie(sequences[sequencePattern][i].isTie());
ryood 12:d4e5feab3a2d 892 sequenceClipBoard[i].setAccent(sequences[sequencePattern][i].isAccent());
ryood 12:d4e5feab3a2d 893 }
ryood 12:d4e5feab3a2d 894 isClipBoardEmpty = false;
ryood 12:d4e5feab3a2d 895
ryood 12:d4e5feab3a2d 896 #if (UART_TRACE_CLIPBOARD)
ryood 12:d4e5feab3a2d 897 printf("copyToClipBoard\r\n");
ryood 12:d4e5feab3a2d 898 printf("sequencePattern: %d\r\n", sequencePattern);
ryood 12:d4e5feab3a2d 899 for (int i = 0; i < SEQUENCE_N; i++) {
ryood 12:d4e5feab3a2d 900 printf("%d %d %03d %d %d\r\n",
ryood 12:d4e5feab3a2d 901 i,
ryood 12:d4e5feab3a2d 902 sequenceClipBoard[i].isNoteOn(),
ryood 12:d4e5feab3a2d 903 sequenceClipBoard[i].getPitch(),
ryood 12:d4e5feab3a2d 904 sequenceClipBoard[i].isTie(),
ryood 12:d4e5feab3a2d 905 sequenceClipBoard[i].isAccent()
ryood 12:d4e5feab3a2d 906 );
ryood 12:d4e5feab3a2d 907 }
ryood 12:d4e5feab3a2d 908 #endif
ryood 12:d4e5feab3a2d 909 }
ryood 12:d4e5feab3a2d 910
ryood 12:d4e5feab3a2d 911 void pasteFromClipBoard()
ryood 12:d4e5feab3a2d 912 {
ryood 15:646a57eb89f3 913 gLCD->clear();
ryood 15:646a57eb89f3 914 gLCD->drawstring(0, 0, "Paste");
ryood 15:646a57eb89f3 915 gLCD->display();
ryood 15:646a57eb89f3 916
ryood 12:d4e5feab3a2d 917 #if (UART_TRACE_CLIPBOARD)
ryood 12:d4e5feab3a2d 918 printf("pasteFromClipBoard\r\n");
ryood 12:d4e5feab3a2d 919 printf("isClipBoardEmpty: %d\r\n", isClipBoardEmpty);
ryood 12:d4e5feab3a2d 920 printf("sequencePattern: %d\r\n", sequencePattern);
ryood 12:d4e5feab3a2d 921 for (int i = 0; i < SEQUENCE_N; i++) {
ryood 12:d4e5feab3a2d 922 printf("%d %d %03d %d %d\r\n",
ryood 12:d4e5feab3a2d 923 i,
ryood 12:d4e5feab3a2d 924 sequenceClipBoard[i].isNoteOn(),
ryood 12:d4e5feab3a2d 925 sequenceClipBoard[i].getPitch(),
ryood 12:d4e5feab3a2d 926 sequenceClipBoard[i].isTie(),
ryood 12:d4e5feab3a2d 927 sequenceClipBoard[i].isAccent()
ryood 12:d4e5feab3a2d 928 );
ryood 12:d4e5feab3a2d 929 }
ryood 12:d4e5feab3a2d 930 #endif
ryood 12:d4e5feab3a2d 931
ryood 12:d4e5feab3a2d 932 for (int i = 0; i < SEQUENCE_N; i++) {
ryood 12:d4e5feab3a2d 933 if (!isClipBoardEmpty) {
ryood 12:d4e5feab3a2d 934 sequences[sequencePattern][i].setNoteOn(sequenceClipBoard[i].isNoteOn());
ryood 12:d4e5feab3a2d 935 sequences[sequencePattern][i].setPitch(sequenceClipBoard[i].getPitch());
ryood 12:d4e5feab3a2d 936 sequences[sequencePattern][i].setTie(sequenceClipBoard[i].isTie());
ryood 12:d4e5feab3a2d 937 sequences[sequencePattern][i].setAccent(sequenceClipBoard[i].isAccent());
ryood 12:d4e5feab3a2d 938 }
ryood 12:d4e5feab3a2d 939 }
ryood 12:d4e5feab3a2d 940 // syncronize sequence value & Rotary Encoder's value
ryood 12:d4e5feab3a2d 941 RotEncPitch->setVal(sequences[sequencePattern][editingStep].getPitch());
ryood 12:d4e5feab3a2d 942 }
ryood 0:5bc618f6d862 943 };
ryood 0:5bc618f6d862 944
ryood 0:5bc618f6d862 945 #endif //_UICONTROLLER_H_