Integrated version

Committer:
ryood
Date:
Mon Nov 07 00:32:05 2016 +0000
Revision:
3:f790643458d9
Parent:
2:238127b00dd3
Child:
4:0a55042fa86c
Add: getSequences()

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 0:5bc618f6d862 7
ryood 0:5bc618f6d862 8 #ifndef _UICONTROLLER_H_
ryood 0:5bc618f6d862 9 #define _UICONTROLLER_H_
ryood 0:5bc618f6d862 10
ryood 0:5bc618f6d862 11 #include "mbed.h"
ryood 0:5bc618f6d862 12 #include "rtos.h"
ryood 0:5bc618f6d862 13
ryood 0:5bc618f6d862 14 #include "BaseMachineCommon.h"
ryood 0:5bc618f6d862 15
ryood 0:5bc618f6d862 16 #include "st7565LCD.h"
ryood 0:5bc618f6d862 17 #include "PinDetect.h"
ryood 0:5bc618f6d862 18 #include "RotaryEncoder.h"
ryood 0:5bc618f6d862 19 #include "AverageAnalogIn.h"
ryood 0:5bc618f6d862 20
ryood 0:5bc618f6d862 21 #include "Sequence.h"
ryood 0:5bc618f6d862 22 #include "ST7565_SequencerDisplay.h"
ryood 0:5bc618f6d862 23
ryood 0:5bc618f6d862 24 #define GLCD_SPI_RATE (1000000)
ryood 0:5bc618f6d862 25 #define POT_RESOLUTION (7) // bit
ryood 0:5bc618f6d862 26 #define AIN_AVERAGE (16) // AnalogInを移動平均する要素数
ryood 0:5bc618f6d862 27
ryood 0:5bc618f6d862 28 const int bpmMax = 240;
ryood 0:5bc618f6d862 29 const int bpmMin = 60;
ryood 0:5bc618f6d862 30 const int octaveMax = 2;
ryood 0:5bc618f6d862 31 const int octaveMin = -2;
ryood 0:5bc618f6d862 32 const int waveShapeMax = 1;
ryood 0:5bc618f6d862 33 const int UImodeMax = 2;
ryood 0:5bc618f6d862 34
ryood 0:5bc618f6d862 35 struct OscillatorParam {
ryood 0:5bc618f6d862 36 uint8_t waveShape;
ryood 0:5bc618f6d862 37 uint8_t pulseWidth;
ryood 0:5bc618f6d862 38
ryood 0:5bc618f6d862 39 OscillatorParam() : waveShape(0), pulseWidth(0) {}
ryood 0:5bc618f6d862 40 };
ryood 0:5bc618f6d862 41
ryood 0:5bc618f6d862 42 struct FilterParam {
ryood 0:5bc618f6d862 43 uint8_t cutoff;
ryood 0:5bc618f6d862 44 uint8_t resonance;
ryood 0:5bc618f6d862 45
ryood 0:5bc618f6d862 46 FilterParam() : cutoff(0), resonance(0) {}
ryood 0:5bc618f6d862 47 };
ryood 0:5bc618f6d862 48
ryood 0:5bc618f6d862 49 struct EnvelopeParam {
ryood 0:5bc618f6d862 50 uint8_t level;
ryood 0:5bc618f6d862 51 uint8_t length;
ryood 0:5bc618f6d862 52 uint8_t duration;
ryood 0:5bc618f6d862 53 uint8_t decay;
ryood 0:5bc618f6d862 54 uint8_t sustain;
ryood 0:5bc618f6d862 55
ryood 0:5bc618f6d862 56 EnvelopeParam() : level(0), length(0), duration(0), decay(0), sustain(0) {}
ryood 0:5bc618f6d862 57 };
ryood 0:5bc618f6d862 58
ryood 0:5bc618f6d862 59 class BaseMachineUIController
ryood 0:5bc618f6d862 60 {
ryood 0:5bc618f6d862 61 public:
ryood 0:5bc618f6d862 62 BaseMachineUIController() :
ryood 0:5bc618f6d862 63 bpm(120),
ryood 0:5bc618f6d862 64 accentLevel(127),
ryood 0:5bc618f6d862 65 editingStep(0),
ryood 0:5bc618f6d862 66 playingStep(0),
ryood 0:5bc618f6d862 67 isRunning(false),
ryood 0:5bc618f6d862 68 isDirty(true),
ryood 0:5bc618f6d862 69 UImode(0),
ryood 0:5bc618f6d862 70 isStepChanged(false),
ryood 0:5bc618f6d862 71 errCutoff(0),
ryood 0:5bc618f6d862 72 errDuration(0),
ryood 0:5bc618f6d862 73 errDecay(0),
ryood 0:5bc618f6d862 74 errSustain(0),
ryood 0:5bc618f6d862 75 errResonance(0),
ryood 0:5bc618f6d862 76 errLevel(0),
ryood 0:5bc618f6d862 77 errPulseWidth(0),
ryood 0:5bc618f6d862 78 errAccentLevel(0) {
ryood 0:5bc618f6d862 79 }
ryood 0:5bc618f6d862 80
ryood 0:5bc618f6d862 81 ~BaseMachineUIController() {}
ryood 0:5bc618f6d862 82
ryood 0:5bc618f6d862 83 void init() {
ryood 0:5bc618f6d862 84 //--------------------------------------------------------------------
ryood 0:5bc618f6d862 85 // Create Dvices
ryood 0:5bc618f6d862 86 //
ryood 0:5bc618f6d862 87 //ST7565(PinName mosi, PinName sclk, PinName cs, PinName rst, PinName a0);
ryood 0:5bc618f6d862 88 gLCD = new ST7565(PB_15, PB_13, PB_12, PB_2, PB_1);
ryood 0:5bc618f6d862 89 sequencerDisplay = new ST7565_SequencerDisplay(gLCD, sequences, SEQUENCE_N);
ryood 0:5bc618f6d862 90
ryood 0:5bc618f6d862 91 AinPulseWidth = new AverageAnalogIn(PC_2, AIN_AVERAGE);
ryood 0:5bc618f6d862 92 AinCutOff = new AverageAnalogIn(PB_0, AIN_AVERAGE);
ryood 0:5bc618f6d862 93 AinResonance = new AverageAnalogIn(PC_1, AIN_AVERAGE);
ryood 0:5bc618f6d862 94 AinLevel = new AverageAnalogIn(PC_0, AIN_AVERAGE);
ryood 0:5bc618f6d862 95 AinDuration = new AverageAnalogIn(PA_4, AIN_AVERAGE);
ryood 0:5bc618f6d862 96 AinDecay = new AverageAnalogIn(PA_1, AIN_AVERAGE);
ryood 0:5bc618f6d862 97 AinSustain = new AverageAnalogIn(PA_0, AIN_AVERAGE);
ryood 0:5bc618f6d862 98 AinAccentLevel= new AverageAnalogIn(PC_3, AIN_AVERAGE);
ryood 0:5bc618f6d862 99
ryood 0:5bc618f6d862 100 RotEncStep = new RotaryEncoder(PA_11, PA_12, 0, SEQUENCE_N - 1, 0);
ryood 0:5bc618f6d862 101 RotEncPitch = new RotaryEncoder(PB_5, PB_4, 0, Sequence::getMaxPitch() - 1, 0);
ryood 0:5bc618f6d862 102 RotEncBpm = new RotaryEncoder(PC_12, PC_10, bpmMin, bpmMax, 120);
ryood 0:5bc618f6d862 103
ryood 0:5bc618f6d862 104 PinWaveShape = new PinDetect(PD_2, PullUp);
ryood 0:5bc618f6d862 105 PinUIMode = new PinDetect(PC_11, PullUp);
ryood 0:5bc618f6d862 106 PinOctaveUp = new PinDetect(PB_3, PullUp);
ryood 0:5bc618f6d862 107 PinOctaveDown = new PinDetect(PA_10, PullUp);
ryood 0:5bc618f6d862 108 PinNoteOnOff = new PinDetect(PC_5, PullUp);
ryood 0:5bc618f6d862 109 PinTie = new PinDetect(PC_6, PullUp);
ryood 0:5bc618f6d862 110 PinAccent = new PinDetect(PC_8, PullUp);
ryood 0:5bc618f6d862 111 PinRunStop = new PinDetect(PC_9, PullUp);
ryood 0:5bc618f6d862 112
ryood 0:5bc618f6d862 113 //--------------------------------------------------------------------
ryood 0:5bc618f6d862 114 // Setup Devices
ryood 0:5bc618f6d862 115 //
ryood 0:5bc618f6d862 116 gLCD->set_spi_frequency(GLCD_SPI_RATE);
ryood 0:5bc618f6d862 117 gLCD->begin(0x12);
ryood 0:5bc618f6d862 118 gLCD->clear();
ryood 0:5bc618f6d862 119 gLCD->drawstring(0, 0, TITLE_STR1);
ryood 0:5bc618f6d862 120 gLCD->drawstring(0, 1, TITLE_STR2);
ryood 0:5bc618f6d862 121 gLCD->display();
ryood 0:5bc618f6d862 122 Thread::wait(1000);
ryood 0:5bc618f6d862 123
ryood 0:5bc618f6d862 124 RotEncStep->setInterval(100);
ryood 0:5bc618f6d862 125 RotEncPitch->setInterval(100);
ryood 0:5bc618f6d862 126 RotEncBpm->setInterval(100);
ryood 0:5bc618f6d862 127
ryood 0:5bc618f6d862 128 PinWaveShape->attach_asserted(this, &BaseMachineUIController::swWaveShapePressed);
ryood 0:5bc618f6d862 129 PinWaveShape->setAssertValue(0);
ryood 0:5bc618f6d862 130 PinWaveShape->setSampleFrequency();
ryood 0:5bc618f6d862 131
ryood 0:5bc618f6d862 132 PinUIMode->attach_asserted(this, &BaseMachineUIController::swUIModePressed);
ryood 0:5bc618f6d862 133 PinUIMode->setAssertValue(0);
ryood 0:5bc618f6d862 134 PinUIMode->setSampleFrequency();
ryood 0:5bc618f6d862 135
ryood 0:5bc618f6d862 136 PinOctaveUp->attach_asserted(this, &BaseMachineUIController::swOctaveUpPressed);
ryood 0:5bc618f6d862 137 PinOctaveUp->setAssertValue(0);
ryood 0:5bc618f6d862 138 PinOctaveUp->setSampleFrequency();
ryood 0:5bc618f6d862 139
ryood 0:5bc618f6d862 140 PinOctaveDown->attach_asserted(this, &BaseMachineUIController::swOctaveDownPressed);
ryood 0:5bc618f6d862 141 PinOctaveDown->setAssertValue(0);
ryood 0:5bc618f6d862 142 PinOctaveDown->setSampleFrequency();
ryood 0:5bc618f6d862 143
ryood 0:5bc618f6d862 144 PinNoteOnOff->attach_asserted(this, &BaseMachineUIController::swNoteOnOffPressed);
ryood 0:5bc618f6d862 145 PinNoteOnOff->setAssertValue(0);
ryood 0:5bc618f6d862 146 PinNoteOnOff->setSampleFrequency();
ryood 0:5bc618f6d862 147
ryood 0:5bc618f6d862 148 PinTie->attach_asserted(this, &BaseMachineUIController::swTiePressed);
ryood 0:5bc618f6d862 149 PinTie->setAssertValue(0);
ryood 0:5bc618f6d862 150 PinTie->setSampleFrequency();
ryood 0:5bc618f6d862 151
ryood 0:5bc618f6d862 152 PinAccent->attach_asserted(this, &BaseMachineUIController::swAccentPressed);
ryood 0:5bc618f6d862 153 PinAccent->setAssertValue(0);
ryood 0:5bc618f6d862 154 PinAccent->setSampleFrequency();
ryood 0:5bc618f6d862 155
ryood 0:5bc618f6d862 156 PinRunStop->attach_asserted(this, &BaseMachineUIController::swRunStopPressed);
ryood 0:5bc618f6d862 157 PinRunStop->setAssertValue(0);
ryood 0:5bc618f6d862 158 PinRunStop->setSampleFrequency();
ryood 0:5bc618f6d862 159
ryood 0:5bc618f6d862 160 //--------------------------------------------------------------------
ryood 0:5bc618f6d862 161 // Initialize objects
ryood 0:5bc618f6d862 162 //
ryood 0:5bc618f6d862 163 Sequence::setBaseNoteNumber(baseNoteNumber);
ryood 0:5bc618f6d862 164
ryood 0:5bc618f6d862 165 for (int i = 0; i < SEQUENCE_N; i++) {
ryood 0:5bc618f6d862 166 Sequence& seq = sequences[i];
ryood 0:5bc618f6d862 167 seq.setPitch(pitch[i]);
ryood 0:5bc618f6d862 168 seq.setNoteOn(noteOn[i]);
ryood 0:5bc618f6d862 169 seq.setTie(tie[i]);
ryood 0:5bc618f6d862 170 seq.setAccent(accent[i]);
ryood 0:5bc618f6d862 171 }
ryood 0:5bc618f6d862 172 RotEncPitch->setVal(sequences[0].getPitch());
ryood 0:5bc618f6d862 173 }
ryood 0:5bc618f6d862 174
ryood 0:5bc618f6d862 175 void destract() {
ryood 0:5bc618f6d862 176 //--------------------------------------------------------------------
ryood 0:5bc618f6d862 177 // Destract Devices
ryood 0:5bc618f6d862 178 //
ryood 0:5bc618f6d862 179 delete gLCD;
ryood 0:5bc618f6d862 180
ryood 0:5bc618f6d862 181 delete AinPulseWidth;
ryood 0:5bc618f6d862 182 delete AinCutOff;
ryood 0:5bc618f6d862 183 delete AinResonance;
ryood 0:5bc618f6d862 184 delete AinLevel;
ryood 0:5bc618f6d862 185 delete AinDuration;
ryood 0:5bc618f6d862 186 delete AinDecay;
ryood 0:5bc618f6d862 187 delete AinSustain;
ryood 0:5bc618f6d862 188 delete AinAccentLevel;
ryood 0:5bc618f6d862 189
ryood 0:5bc618f6d862 190 delete RotEncStep;
ryood 0:5bc618f6d862 191 delete RotEncPitch;
ryood 0:5bc618f6d862 192 delete RotEncBpm;
ryood 0:5bc618f6d862 193
ryood 0:5bc618f6d862 194 delete PinWaveShape;
ryood 0:5bc618f6d862 195 delete PinUIMode;
ryood 0:5bc618f6d862 196 delete PinOctaveUp;
ryood 0:5bc618f6d862 197 delete PinOctaveDown;
ryood 0:5bc618f6d862 198 delete PinNoteOnOff;
ryood 0:5bc618f6d862 199 delete PinTie;
ryood 0:5bc618f6d862 200 delete PinAccent;
ryood 0:5bc618f6d862 201 delete PinRunStop;
ryood 0:5bc618f6d862 202 }
ryood 0:5bc618f6d862 203
ryood 3:f790643458d9 204 void getSequences(Sequence (*pSequences)[SEQUENCE_N]) {
ryood 3:f790643458d9 205 memcpy(pSequences, sequences, sizeof(sequences));
ryood 3:f790643458d9 206 }
ryood 3:f790643458d9 207
ryood 0:5bc618f6d862 208 void getOscillatorParam(OscillatorParam* pParam) {
ryood 0:5bc618f6d862 209 memcpy(pParam, &oscillatorParam, sizeof(oscillatorParam));
ryood 0:5bc618f6d862 210 }
ryood 0:5bc618f6d862 211 void getFilterParam(FilterParam* pParam) {
ryood 0:5bc618f6d862 212 memcpy(pParam, &filterParam, sizeof(filterParam));
ryood 0:5bc618f6d862 213 }
ryood 0:5bc618f6d862 214 void getEnvelopeParam(EnvelopeParam* pParam) {
ryood 0:5bc618f6d862 215 memcpy(pParam, &envelopeParam, sizeof(envelopeParam));
ryood 0:5bc618f6d862 216 }
ryood 0:5bc618f6d862 217 uint8_t getBpm() { return bpm; }
ryood 0:5bc618f6d862 218 uint8_t getAccentLevel() { return accentLevel; }
ryood 0:5bc618f6d862 219
ryood 0:5bc618f6d862 220 bool getIsRunning() { return isRunning; }
ryood 0:5bc618f6d862 221
ryood 0:5bc618f6d862 222 void setPlayingStep(int step)
ryood 0:5bc618f6d862 223 {
ryood 0:5bc618f6d862 224 playingStep = step;
ryood 0:5bc618f6d862 225 isDirty = true;
ryood 0:5bc618f6d862 226 }
ryood 0:5bc618f6d862 227
ryood 0:5bc618f6d862 228 void update() {
ryood 0:5bc618f6d862 229 pollingRotEncs();
ryood 0:5bc618f6d862 230 pollingPots();
ryood 0:5bc618f6d862 231
ryood 0:5bc618f6d862 232 switch (UImode) {
ryood 0:5bc618f6d862 233 case 0:
ryood 0:5bc618f6d862 234 if (isDirty) {
ryood 1:ecae97c65943 235 if (isRunning) {
ryood 1:ecae97c65943 236 sequencerDisplay->update(SequencerDisplay::run, editingStep, playingStep);
ryood 1:ecae97c65943 237 } else {
ryood 1:ecae97c65943 238 sequencerDisplay->update(SequencerDisplay::stop, editingStep, playingStep);
ryood 1:ecae97c65943 239 }
ryood 1:ecae97c65943 240 isDirty = false;
ryood 0:5bc618f6d862 241 }
ryood 0:5bc618f6d862 242 break;
ryood 0:5bc618f6d862 243 case 1:
ryood 1:ecae97c65943 244 dumpToLCD00();
ryood 0:5bc618f6d862 245 break;
ryood 0:5bc618f6d862 246 case 2:
ryood 0:5bc618f6d862 247 dumpToLCD01();
ryood 0:5bc618f6d862 248 break;
ryood 0:5bc618f6d862 249 }
ryood 0:5bc618f6d862 250 }
ryood 0:5bc618f6d862 251
ryood 0:5bc618f6d862 252 private:
ryood 0:5bc618f6d862 253 ST7565* gLCD;
ryood 0:5bc618f6d862 254
ryood 0:5bc618f6d862 255 AverageAnalogIn* AinPulseWidth;
ryood 0:5bc618f6d862 256 AverageAnalogIn* AinCutOff;
ryood 0:5bc618f6d862 257 AverageAnalogIn* AinResonance;
ryood 0:5bc618f6d862 258 AverageAnalogIn* AinLevel;
ryood 0:5bc618f6d862 259 AverageAnalogIn* AinDuration;
ryood 0:5bc618f6d862 260 AverageAnalogIn* AinDecay;
ryood 0:5bc618f6d862 261 AverageAnalogIn* AinSustain;
ryood 0:5bc618f6d862 262 AverageAnalogIn* AinAccentLevel;
ryood 0:5bc618f6d862 263
ryood 0:5bc618f6d862 264 RotaryEncoder* RotEncStep;
ryood 0:5bc618f6d862 265 RotaryEncoder* RotEncPitch;
ryood 0:5bc618f6d862 266 RotaryEncoder* RotEncBpm;
ryood 0:5bc618f6d862 267
ryood 0:5bc618f6d862 268 PinDetect* PinWaveShape;
ryood 0:5bc618f6d862 269 PinDetect* PinUIMode;
ryood 0:5bc618f6d862 270 PinDetect* PinOctaveUp;
ryood 0:5bc618f6d862 271 PinDetect* PinOctaveDown;
ryood 0:5bc618f6d862 272 PinDetect* PinNoteOnOff;
ryood 0:5bc618f6d862 273 PinDetect* PinTie;
ryood 0:5bc618f6d862 274 PinDetect* PinAccent;
ryood 0:5bc618f6d862 275 PinDetect* PinRunStop;
ryood 0:5bc618f6d862 276
ryood 0:5bc618f6d862 277 ST7565_SequencerDisplay* sequencerDisplay;
ryood 0:5bc618f6d862 278
ryood 0:5bc618f6d862 279 Sequence sequences[SEQUENCE_N];
ryood 0:5bc618f6d862 280
ryood 0:5bc618f6d862 281 OscillatorParam oscillatorParam;
ryood 0:5bc618f6d862 282 FilterParam filterParam;
ryood 0:5bc618f6d862 283 EnvelopeParam envelopeParam;
ryood 0:5bc618f6d862 284
ryood 0:5bc618f6d862 285 uint8_t bpm;
ryood 0:5bc618f6d862 286 uint8_t accentLevel;
ryood 0:5bc618f6d862 287
ryood 0:5bc618f6d862 288 int editingStep;
ryood 0:5bc618f6d862 289 int playingStep;
ryood 0:5bc618f6d862 290 bool isRunning;
ryood 0:5bc618f6d862 291 bool isDirty;
ryood 0:5bc618f6d862 292 int UImode;
ryood 0:5bc618f6d862 293
ryood 0:5bc618f6d862 294 bool isStepChanged;
ryood 0:5bc618f6d862 295
ryood 0:5bc618f6d862 296 int errCutoff;
ryood 0:5bc618f6d862 297 int errDuration;
ryood 0:5bc618f6d862 298 int errDecay;
ryood 0:5bc618f6d862 299 int errSustain;
ryood 0:5bc618f6d862 300 int errResonance;
ryood 0:5bc618f6d862 301 int errLevel;
ryood 0:5bc618f6d862 302 int errPulseWidth;
ryood 0:5bc618f6d862 303 int errAccentLevel;
ryood 0:5bc618f6d862 304
ryood 0:5bc618f6d862 305 //------------------------------------------------------------------------
ryood 0:5bc618f6d862 306 // PinDetect callback functions
ryood 0:5bc618f6d862 307 //------------------------------------------------------------------------
ryood 0:5bc618f6d862 308 void swWaveShapePressed() {
ryood 0:5bc618f6d862 309 #if (UART_TRACE)
ryood 0:5bc618f6d862 310 printf("PinWaveShape Pushed\r\n");
ryood 0:5bc618f6d862 311 #endif
ryood 0:5bc618f6d862 312 uint8_t _waveShape = oscillatorParam.waveShape;
ryood 0:5bc618f6d862 313 _waveShape++;
ryood 0:5bc618f6d862 314 if (_waveShape > waveShapeMax) {
ryood 0:5bc618f6d862 315 _waveShape = 0;
ryood 0:5bc618f6d862 316 }
ryood 0:5bc618f6d862 317 oscillatorParam.waveShape = _waveShape;
ryood 0:5bc618f6d862 318 sequencerDisplay->setWaveShape(_waveShape);
ryood 0:5bc618f6d862 319 isDirty = true;
ryood 0:5bc618f6d862 320 }
ryood 0:5bc618f6d862 321
ryood 0:5bc618f6d862 322 void swUIModePressed() {
ryood 0:5bc618f6d862 323 #if (UART_TRACE)
ryood 0:5bc618f6d862 324 printf("PinUIMode Pushed\r\n");
ryood 0:5bc618f6d862 325 #endif
ryood 0:5bc618f6d862 326 UImode++;
ryood 0:5bc618f6d862 327 if (UImode > UImodeMax) {
ryood 0:5bc618f6d862 328 UImode = 0;
ryood 0:5bc618f6d862 329 }
ryood 0:5bc618f6d862 330 isDirty = true;
ryood 0:5bc618f6d862 331 }
ryood 0:5bc618f6d862 332
ryood 0:5bc618f6d862 333 void swOctaveUpPressed() {
ryood 0:5bc618f6d862 334 #if (UART_TRACE)
ryood 0:5bc618f6d862 335 printf("PinOctaveUp Pushed\r\n");
ryood 0:5bc618f6d862 336 #endif
ryood 0:5bc618f6d862 337 if (sequencerDisplay->getOctave() < octaveMax) {
ryood 0:5bc618f6d862 338 sequencerDisplay->setOctave(sequencerDisplay->getOctave() + 1);
ryood 0:5bc618f6d862 339 isDirty = true;
ryood 0:5bc618f6d862 340 }
ryood 0:5bc618f6d862 341 }
ryood 0:5bc618f6d862 342
ryood 0:5bc618f6d862 343 void swOctaveDownPressed() {
ryood 0:5bc618f6d862 344 #if (UART_TRACE)
ryood 0:5bc618f6d862 345 printf("PinOctaveDown Pushed\r\n");
ryood 0:5bc618f6d862 346 #endif
ryood 0:5bc618f6d862 347 if (sequencerDisplay->getOctave () > octaveMin) {
ryood 0:5bc618f6d862 348 sequencerDisplay->setOctave(sequencerDisplay->getOctave() - 1);
ryood 0:5bc618f6d862 349 isDirty = true;
ryood 0:5bc618f6d862 350 }
ryood 0:5bc618f6d862 351 }
ryood 0:5bc618f6d862 352
ryood 0:5bc618f6d862 353 void swNoteOnOffPressed() {
ryood 0:5bc618f6d862 354 #if (UART_TRACE)
ryood 0:5bc618f6d862 355 printf("PinNoteOnOff Pushed\r\n");
ryood 0:5bc618f6d862 356 #endif
ryood 0:5bc618f6d862 357 sequences[editingStep].setNoteOn(!sequences[editingStep].isNoteOn());
ryood 0:5bc618f6d862 358 isDirty = true;
ryood 0:5bc618f6d862 359 }
ryood 0:5bc618f6d862 360
ryood 0:5bc618f6d862 361 void swTiePressed() {
ryood 0:5bc618f6d862 362 #if (UART_TRACE)
ryood 0:5bc618f6d862 363 printf("PinTie Pushed\r\n");
ryood 0:5bc618f6d862 364 #endif
ryood 0:5bc618f6d862 365 sequences[editingStep].setTie(!sequences[editingStep].isTie());
ryood 0:5bc618f6d862 366 isDirty = true;
ryood 0:5bc618f6d862 367 }
ryood 0:5bc618f6d862 368
ryood 0:5bc618f6d862 369 void swAccentPressed() {
ryood 0:5bc618f6d862 370 #if (UART_TRACE)
ryood 0:5bc618f6d862 371 printf("PinAccent Pushed\r\n");
ryood 0:5bc618f6d862 372 #endif
ryood 0:5bc618f6d862 373 sequences[editingStep].setAccent(!sequences[editingStep].isAccent());
ryood 0:5bc618f6d862 374 isDirty = true;
ryood 0:5bc618f6d862 375 }
ryood 0:5bc618f6d862 376
ryood 0:5bc618f6d862 377 void swRunStopPressed() {
ryood 0:5bc618f6d862 378 #if (UART_TRACE)
ryood 0:5bc618f6d862 379 printf("PinRunStop Pushed\r\n");
ryood 0:5bc618f6d862 380 #endif
ryood 0:5bc618f6d862 381 if (isRunning) {
ryood 0:5bc618f6d862 382 isRunning = false;
ryood 0:5bc618f6d862 383 } else {
ryood 0:5bc618f6d862 384 isRunning = true;
ryood 0:5bc618f6d862 385 }
ryood 0:5bc618f6d862 386 isDirty = true;
ryood 0:5bc618f6d862 387 }
ryood 0:5bc618f6d862 388
ryood 0:5bc618f6d862 389 //------------------------------------------------------------------------
ryood 0:5bc618f6d862 390 // Functions
ryood 0:5bc618f6d862 391 //------------------------------------------------------------------------
ryood 0:5bc618f6d862 392 void pollingRotEncs() {
ryood 0:5bc618f6d862 393 int _bpm = RotEncBpm->getVal();
ryood 0:5bc618f6d862 394 if (_bpm != bpm) {
ryood 0:5bc618f6d862 395 bpm = _bpm;
ryood 0:5bc618f6d862 396 sequencerDisplay->setBpm(_bpm);
ryood 0:5bc618f6d862 397 isDirty = true;
ryood 0:5bc618f6d862 398 }
ryood 0:5bc618f6d862 399
ryood 0:5bc618f6d862 400 int _step = RotEncStep->getVal();
ryood 0:5bc618f6d862 401 if (_step != editingStep) {
ryood 0:5bc618f6d862 402 editingStep = _step;
ryood 0:5bc618f6d862 403 // syncronize sequence value & Rotary Encoder's value
ryood 0:5bc618f6d862 404 RotEncPitch->setVal(sequences[editingStep].getPitch());
ryood 0:5bc618f6d862 405 isDirty = true;
ryood 0:5bc618f6d862 406 }
ryood 0:5bc618f6d862 407
ryood 0:5bc618f6d862 408 int _pitch = RotEncPitch->getVal();
ryood 0:5bc618f6d862 409 if (_pitch != sequences[editingStep].getPitch()) {
ryood 0:5bc618f6d862 410 sequences[editingStep].setPitch(_pitch);
ryood 0:5bc618f6d862 411 isDirty = true;
ryood 0:5bc618f6d862 412 }
ryood 0:5bc618f6d862 413 }
ryood 0:5bc618f6d862 414
ryood 0:5bc618f6d862 415 void pollingPots() {
ryood 0:5bc618f6d862 416 uint8_t pulseWidth = AinPulseWidth->read_u16() >> (16 - POT_RESOLUTION);
ryood 0:5bc618f6d862 417 if (pulseWidth != oscillatorParam.pulseWidth) {
ryood 0:5bc618f6d862 418 oscillatorParam.pulseWidth = pulseWidth;
ryood 0:5bc618f6d862 419 errPulseWidth++;
ryood 1:ecae97c65943 420 //isDirty = true;
ryood 0:5bc618f6d862 421 }
ryood 0:5bc618f6d862 422
ryood 0:5bc618f6d862 423 uint8_t cutoff = AinCutOff->read_u16() >> (16 - POT_RESOLUTION);
ryood 0:5bc618f6d862 424 if (cutoff != filterParam.cutoff) {
ryood 0:5bc618f6d862 425 filterParam.cutoff = cutoff;
ryood 0:5bc618f6d862 426 errCutoff++;
ryood 1:ecae97c65943 427 //isDirty = true;
ryood 0:5bc618f6d862 428 }
ryood 0:5bc618f6d862 429
ryood 0:5bc618f6d862 430 uint8_t resonance = AinResonance->read_u16() >> (16 - POT_RESOLUTION);
ryood 0:5bc618f6d862 431 if (resonance != filterParam.resonance) {
ryood 0:5bc618f6d862 432 filterParam.resonance = resonance;
ryood 0:5bc618f6d862 433 errResonance++;
ryood 1:ecae97c65943 434 //isDirty = true;
ryood 0:5bc618f6d862 435 }
ryood 0:5bc618f6d862 436
ryood 0:5bc618f6d862 437 uint8_t level = AinLevel->read_u16() >> (16 - POT_RESOLUTION);
ryood 0:5bc618f6d862 438 if (level != envelopeParam.level) {
ryood 0:5bc618f6d862 439 errLevel++;
ryood 0:5bc618f6d862 440 envelopeParam.level = level;
ryood 1:ecae97c65943 441 //isDirty = true;
ryood 0:5bc618f6d862 442 }
ryood 0:5bc618f6d862 443
ryood 0:5bc618f6d862 444 uint8_t duration = AinDuration->read_u16() >> (16 - POT_RESOLUTION);
ryood 0:5bc618f6d862 445 if (duration != envelopeParam.duration) {
ryood 0:5bc618f6d862 446 errDuration++;
ryood 0:5bc618f6d862 447 envelopeParam.duration = duration;
ryood 1:ecae97c65943 448 //isDirty = true;
ryood 0:5bc618f6d862 449 }
ryood 0:5bc618f6d862 450
ryood 0:5bc618f6d862 451 uint8_t decay = AinDecay->read_u16() >> (16 - POT_RESOLUTION);
ryood 0:5bc618f6d862 452 if (decay != envelopeParam.decay) {
ryood 0:5bc618f6d862 453 errDecay++;
ryood 0:5bc618f6d862 454 envelopeParam.decay = decay;
ryood 1:ecae97c65943 455 //isDirty = true;
ryood 0:5bc618f6d862 456 }
ryood 0:5bc618f6d862 457
ryood 0:5bc618f6d862 458 uint8_t sustain = AinSustain->read_u16() >> (16 - POT_RESOLUTION);
ryood 0:5bc618f6d862 459 if (sustain != envelopeParam.sustain) {
ryood 0:5bc618f6d862 460 errSustain++;
ryood 0:5bc618f6d862 461 envelopeParam.sustain = sustain;
ryood 1:ecae97c65943 462 //isDirty = true;
ryood 0:5bc618f6d862 463 }
ryood 0:5bc618f6d862 464
ryood 0:5bc618f6d862 465 uint8_t _accentLevel = AinAccentLevel->read_u16() >> (16 - POT_RESOLUTION);
ryood 0:5bc618f6d862 466 if (_accentLevel != accentLevel) {
ryood 0:5bc618f6d862 467 errAccentLevel++;
ryood 0:5bc618f6d862 468 accentLevel = _accentLevel;
ryood 1:ecae97c65943 469 //isDirty = true;
ryood 0:5bc618f6d862 470 }
ryood 0:5bc618f6d862 471 }
ryood 0:5bc618f6d862 472
ryood 0:5bc618f6d862 473 void dumpToLCD00() {
ryood 0:5bc618f6d862 474 char buff[64];
ryood 0:5bc618f6d862 475 int col = 0;
ryood 0:5bc618f6d862 476
ryood 0:5bc618f6d862 477 gLCD->clear();
ryood 0:5bc618f6d862 478
ryood 0:5bc618f6d862 479 sprintf(buff, "Run:%d BPM:%03d", isRunning, bpm);
ryood 0:5bc618f6d862 480 gLCD->drawstring(0, col++, buff);
ryood 0:5bc618f6d862 481
ryood 0:5bc618f6d862 482 sprintf(buff, "Stp:%02d Nto:%d Pch:%02d",
ryood 0:5bc618f6d862 483 editingStep, sequences[editingStep].isNoteOn(), sequences[editingStep].getPitch());
ryood 0:5bc618f6d862 484 gLCD->drawstring(0, col++, buff);
ryood 0:5bc618f6d862 485
ryood 0:5bc618f6d862 486 sprintf(buff, "Oct:%-2d Tie:%d Acc:%d",
ryood 0:5bc618f6d862 487 sequencerDisplay->getOctave(), sequences[editingStep].isTie(),sequences[editingStep].isAccent());
ryood 0:5bc618f6d862 488 gLCD->drawstring(0, col++, buff);
ryood 0:5bc618f6d862 489
ryood 0:5bc618f6d862 490 sprintf(buff, "Wsp:%d Mod:%d pStp:%d", oscillatorParam.waveShape, UImode, playingStep);
ryood 0:5bc618f6d862 491 gLCD->drawstring(0, col++, buff);
ryood 0:5bc618f6d862 492
ryood 2:238127b00dd3 493 sprintf(buff, "RSO:%4d CO :%4d", filterParam.resonance, filterParam.cutoff);
ryood 0:5bc618f6d862 494 gLCD->drawstring(0, col++, buff);
ryood 0:5bc618f6d862 495 sprintf(buff, "LVL:%4d DUR:%4d", envelopeParam.level, envelopeParam.duration);
ryood 0:5bc618f6d862 496 gLCD->drawstring(0, col++, buff);
ryood 1:ecae97c65943 497 sprintf(buff, "PW :%4d DCY:%4d", oscillatorParam.pulseWidth, envelopeParam.decay);
ryood 1:ecae97c65943 498 gLCD->drawstring(0, col++, buff);
ryood 1:ecae97c65943 499 sprintf(buff, "ACL:%4d SUS:%4d", accentLevel, envelopeParam.sustain);
ryood 0:5bc618f6d862 500 gLCD->drawstring(0, col++, buff);
ryood 0:5bc618f6d862 501
ryood 0:5bc618f6d862 502 gLCD->display();
ryood 0:5bc618f6d862 503 }
ryood 0:5bc618f6d862 504
ryood 0:5bc618f6d862 505 void dumpToLCD01() {
ryood 0:5bc618f6d862 506 char buff[64];
ryood 0:5bc618f6d862 507
ryood 0:5bc618f6d862 508 gLCD->clear();
ryood 0:5bc618f6d862 509
ryood 0:5bc618f6d862 510 sprintf(buff, "Cutoff %3d %5d", filterParam.cutoff, errCutoff);
ryood 0:5bc618f6d862 511 gLCD->drawstring(0, 0, buff);
ryood 0:5bc618f6d862 512 sprintf(buff, "Duration %3d %5d", envelopeParam.duration, errDuration);
ryood 0:5bc618f6d862 513 gLCD->drawstring(0, 1, buff);
ryood 0:5bc618f6d862 514 sprintf(buff, "Decay %3d %5d", envelopeParam.decay, errDecay);
ryood 0:5bc618f6d862 515 gLCD->drawstring(0, 2, buff);
ryood 0:5bc618f6d862 516 sprintf(buff, "Sustain %3d %5d", envelopeParam.sustain, errSustain);
ryood 0:5bc618f6d862 517 gLCD->drawstring(0, 3, buff);
ryood 0:5bc618f6d862 518 sprintf(buff, "Resonance %3d %5d", filterParam.resonance, errResonance);
ryood 0:5bc618f6d862 519 gLCD->drawstring(0, 4, buff);
ryood 0:5bc618f6d862 520 sprintf(buff, "Level %3d %5d", envelopeParam.level, errLevel);
ryood 0:5bc618f6d862 521 gLCD->drawstring(0, 5, buff);
ryood 0:5bc618f6d862 522 sprintf(buff, "PulseWidth %3d %5d", oscillatorParam.pulseWidth, errPulseWidth);
ryood 0:5bc618f6d862 523 gLCD->drawstring(0, 6, buff);
ryood 0:5bc618f6d862 524 sprintf(buff, "AccentLvl %3d %5d", accentLevel, errAccentLevel);
ryood 0:5bc618f6d862 525 gLCD->drawstring(0, 7, buff);
ryood 0:5bc618f6d862 526
ryood 0:5bc618f6d862 527 gLCD->display();
ryood 0:5bc618f6d862 528 }
ryood 0:5bc618f6d862 529 };
ryood 0:5bc618f6d862 530
ryood 0:5bc618f6d862 531 #endif //_UICONTROLLER_H_