BaseMachine UI Controllerに分離

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

Fork of BaseMachine_Sequencer by Ryo Od

Committer:
ryood
Date:
Tue Aug 23 11:47:44 2016 +0000
Revision:
20:00d3b6ace8c7
Parent:
19:241a4b355413
Child:
21:c4d09aaa52b9
Add: RotaryEncoder Library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ryood 15:9813d8eaf57e 1 /*
ryood 15:9813d8eaf57e 2 * main.cpp
ryood 15:9813d8eaf57e 3 * SpiSequencerSender_test
ryood 15:9813d8eaf57e 4 *
ryood 15:9813d8eaf57e 5 * 2016.08.20 mbed Rev 121 / mbed-rtos Rev 117で動作確認
ryood 15:9813d8eaf57e 6 *
ryood 15:9813d8eaf57e 7 */
ryood 15:9813d8eaf57e 8
ryood 0:21e39bc75e31 9 #include "mbed.h"
ryood 5:4abac408b827 10 #include "rtos.h"
ryood 16:b0419e3c9079 11 #include "st7565LCD.h"
ryood 18:309f794eba74 12 #include "PinDetect.h"
ryood 20:00d3b6ace8c7 13 #include "RotaryEncoder.h"
ryood 19:241a4b355413 14 #include "AverageAnalogIn.h"
ryood 0:21e39bc75e31 15
ryood 6:fc10eac60b91 16 #define UART_TRACE (0)
ryood 6:fc10eac60b91 17 #include "SpiSequenceSender.h"
ryood 9:3e4e08578e1c 18 #include "EnvelopeGenerator.h"
ryood 9:3e4e08578e1c 19 #include "SpiAmpController.h"
ryood 12:c248781608af 20 #include "SpiFilterController.h"
ryood 17:557658db3e81 21 #include "ST7565_SequencerDisplay.h"
ryood 0:21e39bc75e31 22
ryood 16:b0419e3c9079 23 #define TITLE_STR1 ("BaseMachine Sequencer")
ryood 16:b0419e3c9079 24 #define TITLE_STR2 ("20160823")
ryood 16:b0419e3c9079 25
ryood 6:fc10eac60b91 26 #define SEQUENCE_N (16)
ryood 6:fc10eac60b91 27 #define SPI_RATE (8000000)
ryood 0:21e39bc75e31 28
ryood 14:c173e03ee3ad 29 const int samplingPeriod = 1; // ms
ryood 10:fb04f9959fd9 30 const int bpm = 120;
ryood 10:fb04f9959fd9 31 const int envelopeLength = (60 * 1000 / (bpm * 4)) / samplingPeriod;
ryood 20:00d3b6ace8c7 32 const int waveShape = SpiSequenceSender::WAVESHAPE_SQUARE;
ryood 20:00d3b6ace8c7 33 const int baseNoteNumber = 36;
ryood 20:00d3b6ace8c7 34 const int pitchMax = 12;
ryood 20:00d3b6ace8c7 35 const int bpmMax = 240;
ryood 20:00d3b6ace8c7 36 const int bpmMin = 60;
ryood 14:c173e03ee3ad 37
ryood 14:c173e03ee3ad 38 // Initial Sequence
ryood 14:c173e03ee3ad 39 const int noteOn[SEQUENCE_N] = { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0 };
ryood 14:c173e03ee3ad 40 const int octave[SEQUENCE_N] = {-1,-1,-1, 0, 0,-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 };
ryood 14:c173e03ee3ad 41 const int pitch[SEQUENCE_N] = { 9, 7, 3, 0, 0, 3, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 };
ryood 14:c173e03ee3ad 42 const int tie[SEQUENCE_N] = { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0 };
ryood 10:fb04f9959fd9 43
ryood 16:b0419e3c9079 44 // Devices
ryood 16:b0419e3c9079 45 //
ryood 16:b0419e3c9079 46 //SPI (PinName mosi, PinName miso, PinName sclk, PinName ssel=NC)
ryood 19:241a4b355413 47 SPI spiMaster(PA_7, PA_6, PA_5);
ryood 16:b0419e3c9079 48
ryood 16:b0419e3c9079 49 //ST7565(PinName mosi, PinName sclk, PinName cs, PinName rst, PinName a0);
ryood 16:b0419e3c9079 50 ST7565 gLCD(PB_15, PB_13, PB_12, PB_2, PB_1);
ryood 16:b0419e3c9079 51
ryood 19:241a4b355413 52 AverageAnalogIn AinPulseWidth(PC_2);
ryood 19:241a4b355413 53 AverageAnalogIn AinCutOff(PB_0);
ryood 19:241a4b355413 54 AverageAnalogIn AinResonance(PC_1);
ryood 19:241a4b355413 55 AverageAnalogIn AinEnvMod(PC_3);
ryood 19:241a4b355413 56 AverageAnalogIn AinLevel(PC_0);
ryood 19:241a4b355413 57 AverageAnalogIn AinDuration(PA_4);
ryood 19:241a4b355413 58 AverageAnalogIn AinDecay(PA_1);
ryood 19:241a4b355413 59 AverageAnalogIn AinSustain(PA_0);
ryood 10:fb04f9959fd9 60
ryood 20:00d3b6ace8c7 61 RotaryEncoder RotEncStep(D2, D3, 0, SEQUENCE_N - 1, 0);
ryood 20:00d3b6ace8c7 62 RotaryEncoder RotEncPitch(D4, D5, 0, pitchMax, 0);
ryood 20:00d3b6ace8c7 63 RotaryEncoder RotEncBpm(D14, D15, bpmMin, bpmMax, 120);
ryood 20:00d3b6ace8c7 64
ryood 18:309f794eba74 65 PinDetect PinWaveShape(PD_2, PullUp);
ryood 18:309f794eba74 66 PinDetect PinModNumber(PC_11, PullUp);
ryood 18:309f794eba74 67 PinDetect PinOctaveUp(PC_10, PullUp);
ryood 18:309f794eba74 68 PinDetect PinOctaveDown(PC_12, PullUp);
ryood 18:309f794eba74 69 PinDetect PinNoteOnOff(PA_13, PullUp);
ryood 18:309f794eba74 70 PinDetect PinTie(PA_14, PullUp);
ryood 18:309f794eba74 71 PinDetect PinAccent(PA_15, PullUp);
ryood 18:309f794eba74 72 PinDetect PinRunStop(PB_7, PullUp);
ryood 18:309f794eba74 73
ryood 16:b0419e3c9079 74 // Grobal Variables
ryood 16:b0419e3c9079 75 //
ryood 16:b0419e3c9079 76 Sequence sequences[SEQUENCE_N];
ryood 16:b0419e3c9079 77 SpiSequenceSender sequenceSender(&spiMaster, D9, sequences, SEQUENCE_N, samplingPeriod, bpm);
ryood 6:fc10eac60b91 78
ryood 10:fb04f9959fd9 79 Envelope envelope(4095, envelopeLength, envelopeLength*3/4, envelopeLength/2, 2047);
ryood 9:3e4e08578e1c 80 EnvelopeGenerator envelopeGenerator;
ryood 9:3e4e08578e1c 81 SpiAmpController ampController(&spiMaster, D8, D7);
ryood 6:fc10eac60b91 82
ryood 12:c248781608af 83 SpiFilterController filterController(&spiMaster, D10);
ryood 0:21e39bc75e31 84
ryood 17:557658db3e81 85 ST7565_SequencerDisplay sequencerDisplay(&gLCD, sequences, SEQUENCE_N);
ryood 17:557658db3e81 86
ryood 16:b0419e3c9079 87 volatile int currentStep = 0;
ryood 16:b0419e3c9079 88 volatile bool isRunning = false;
ryood 16:b0419e3c9079 89 volatile bool isDirty = false;
ryood 16:b0419e3c9079 90 volatile uint8_t pinFlag = 0x00;
ryood 16:b0419e3c9079 91
ryood 16:b0419e3c9079 92 enum PinBit {
ryood 16:b0419e3c9079 93 bWaveShape = 0x01,
ryood 16:b0419e3c9079 94 bModNumber = 0x02,
ryood 16:b0419e3c9079 95 bOctaveUp = 0x04,
ryood 16:b0419e3c9079 96 bOctaveDown = 0x08,
ryood 16:b0419e3c9079 97 bNoteOnOff = 0x10,
ryood 16:b0419e3c9079 98 bTie = 0x20,
ryood 16:b0419e3c9079 99 bAccent = 0x40,
ryood 16:b0419e3c9079 100 bRunStop = 0x80
ryood 16:b0419e3c9079 101 };
ryood 16:b0419e3c9079 102
ryood 16:b0419e3c9079 103 // とりあえずの変数(後でClassのメンバ変数に格納)
ryood 16:b0419e3c9079 104 #define MOD_NUMBER_MAX 1
ryood 16:b0419e3c9079 105 volatile int modNumber = 0;
ryood 19:241a4b355413 106 /*
ryood 16:b0419e3c9079 107 volatile uint8_t cutOff;
ryood 16:b0419e3c9079 108 volatile uint8_t resonance;
ryood 19:241a4b355413 109 */
ryood 16:b0419e3c9079 110 volatile uint8_t envMod;
ryood 19:241a4b355413 111 /*
ryood 16:b0419e3c9079 112 volatile uint8_t level;
ryood 16:b0419e3c9079 113 volatile uint8_t duration;
ryood 16:b0419e3c9079 114 volatile uint8_t decay;
ryood 16:b0419e3c9079 115 volatile uint8_t sustain;
ryood 19:241a4b355413 116 */
ryood 16:b0419e3c9079 117
ryood 16:b0419e3c9079 118 //------------------------------------------------------------------------
ryood 16:b0419e3c9079 119 // Callback functions
ryood 16:b0419e3c9079 120 //------------------------------------------------------------------------
ryood 16:b0419e3c9079 121 void updateFunction(int ticks)
ryood 8:de409197ff95 122 {
ryood 8:de409197ff95 123 if (ticks == 0) {
ryood 9:3e4e08578e1c 124 envelopeGenerator.init(envelope);
ryood 8:de409197ff95 125 }
ryood 14:c173e03ee3ad 126
ryood 15:9813d8eaf57e 127 if (sequenceSender.getSequences()[sequenceSender.getStep()].isNoteOn()) {
ryood 14:c173e03ee3ad 128 uint16_t level = envelopeGenerator.getModLevel();
ryood 14:c173e03ee3ad 129 ampController.outDca(level);
ryood 14:c173e03ee3ad 130 } else {
ryood 14:c173e03ee3ad 131 ampController.outDca(0);
ryood 14:c173e03ee3ad 132 }
ryood 9:3e4e08578e1c 133 envelopeGenerator.update();
ryood 12:c248781608af 134
ryood 15:9813d8eaf57e 135 filterController.outDcf();
ryood 17:557658db3e81 136
ryood 17:557658db3e81 137 // ToDo: 再生中のLCD表示を検討→SPI1とSPI2の信号のタイミングを調査
ryood 17:557658db3e81 138 //sequencerDisplay.update(SequencerDisplay::stop, sequenceSender.getStep());
ryood 8:de409197ff95 139 }
ryood 8:de409197ff95 140
ryood 16:b0419e3c9079 141 //------------------------------------------------------------------------
ryood 18:309f794eba74 142 // PinDetect ISR
ryood 18:309f794eba74 143 //------------------------------------------------------------------------
ryood 18:309f794eba74 144 void swWaveShapePressed()
ryood 18:309f794eba74 145 {
ryood 18:309f794eba74 146 pinFlag |= bWaveShape;
ryood 18:309f794eba74 147 }
ryood 18:309f794eba74 148
ryood 18:309f794eba74 149 void swModNumberPressed()
ryood 18:309f794eba74 150 {
ryood 18:309f794eba74 151 pinFlag |= bModNumber;
ryood 18:309f794eba74 152 }
ryood 18:309f794eba74 153
ryood 18:309f794eba74 154 void swOctaveUpPressed()
ryood 18:309f794eba74 155 {
ryood 18:309f794eba74 156 pinFlag |= bOctaveUp;
ryood 18:309f794eba74 157 }
ryood 18:309f794eba74 158
ryood 18:309f794eba74 159 void swOctaveDownPressed()
ryood 18:309f794eba74 160 {
ryood 18:309f794eba74 161 pinFlag |= bOctaveDown;
ryood 18:309f794eba74 162 }
ryood 18:309f794eba74 163
ryood 18:309f794eba74 164 void swNoteOnOffPressed()
ryood 18:309f794eba74 165 {
ryood 18:309f794eba74 166 pinFlag |= bNoteOnOff;
ryood 18:309f794eba74 167 }
ryood 18:309f794eba74 168
ryood 18:309f794eba74 169 void swTiePressed()
ryood 18:309f794eba74 170 {
ryood 18:309f794eba74 171 pinFlag |= bTie;
ryood 18:309f794eba74 172 }
ryood 18:309f794eba74 173
ryood 18:309f794eba74 174 void swAccentPressed()
ryood 18:309f794eba74 175 {
ryood 18:309f794eba74 176 pinFlag |= bAccent;
ryood 18:309f794eba74 177 }
ryood 18:309f794eba74 178
ryood 18:309f794eba74 179 void swRunStopPressed()
ryood 18:309f794eba74 180 {
ryood 18:309f794eba74 181 pinFlag |= bRunStop;
ryood 18:309f794eba74 182 }
ryood 18:309f794eba74 183
ryood 18:309f794eba74 184 //------------------------------------------------------------------------
ryood 16:b0419e3c9079 185 // Functions
ryood 16:b0419e3c9079 186 //------------------------------------------------------------------------
ryood 19:241a4b355413 187 void pollingPots()
ryood 19:241a4b355413 188 {
ryood 20:00d3b6ace8c7 189 //pulseWidth = AinPulseWidth.read_u16() >> 8;
ryood 20:00d3b6ace8c7 190
ryood 19:241a4b355413 191 filterController.setCutoff(AinCutOff.read_u16() >> 8);
ryood 19:241a4b355413 192 filterController.setResonance(AinResonance.read_u16() >> 8);
ryood 20:00d3b6ace8c7 193 //envMod = AinEnvMod.read_u16() >> 8;
ryood 19:241a4b355413 194
ryood 19:241a4b355413 195 //envelope.setLevel(AinLevel.read_u16() >> 4);
ryood 19:241a4b355413 196 envelope.setLevel(4095);
ryood 19:241a4b355413 197 envelope.setDuration(AinDuration.read() * envelopeLength);
ryood 19:241a4b355413 198 envelope.setDecay(AinDecay.read() * envelopeLength);
ryood 19:241a4b355413 199 envelope.setSustain(AinSustain.read() * 4095);
ryood 20:00d3b6ace8c7 200 }
ryood 20:00d3b6ace8c7 201
ryood 20:00d3b6ace8c7 202 void pollingRotEncs()
ryood 20:00d3b6ace8c7 203 {
ryood 20:00d3b6ace8c7 204 int _bpm = RotEncBpm.getVal();
ryood 20:00d3b6ace8c7 205 if (_bpm != sequenceSender.getBpm()) {
ryood 20:00d3b6ace8c7 206 sequenceSender.setBpm(_bpm);
ryood 20:00d3b6ace8c7 207 isDirty = true;
ryood 20:00d3b6ace8c7 208 }
ryood 20:00d3b6ace8c7 209
ryood 20:00d3b6ace8c7 210 int _step = RotEncStep.getVal();
ryood 20:00d3b6ace8c7 211 if (_step != currentStep) {
ryood 20:00d3b6ace8c7 212 currentStep = _step;
ryood 20:00d3b6ace8c7 213 // syncronize sequence value & Rotary Encoder's value
ryood 20:00d3b6ace8c7 214 RotEncPitch.setVal(sequences[currentStep].getPitch());
ryood 20:00d3b6ace8c7 215 isDirty = true;
ryood 20:00d3b6ace8c7 216 }
ryood 20:00d3b6ace8c7 217
ryood 20:00d3b6ace8c7 218 int _pitch = RotEncPitch.getVal();
ryood 20:00d3b6ace8c7 219 if (_pitch != sequences[currentStep].getPitch()) {
ryood 20:00d3b6ace8c7 220 sequences[currentStep].setPitch(_pitch);
ryood 20:00d3b6ace8c7 221 isDirty = true;
ryood 20:00d3b6ace8c7 222 }
ryood 19:241a4b355413 223 }
ryood 19:241a4b355413 224
ryood 18:309f794eba74 225 void pollingPins()
ryood 18:309f794eba74 226 {
ryood 18:309f794eba74 227 if (pinFlag & bWaveShape) {
ryood 18:309f794eba74 228 #if (UART_TRACE)
ryood 18:309f794eba74 229 printf("PinWaveShape Pushed\r\n");
ryood 18:309f794eba74 230 #endif
ryood 18:309f794eba74 231 uint8_t waveShape = sequenceSender.getWaveShape();
ryood 18:309f794eba74 232 waveShape++;
ryood 18:309f794eba74 233 if (waveShape < SpiSequenceSender::WAVESHAPE_N) {
ryood 18:309f794eba74 234 sequenceSender.setWaveShape(waveShape);
ryood 18:309f794eba74 235 } else {
ryood 18:309f794eba74 236 sequenceSender.setWaveShape(0);
ryood 18:309f794eba74 237 }
ryood 18:309f794eba74 238 pinFlag &= ~bWaveShape;
ryood 18:309f794eba74 239 }
ryood 18:309f794eba74 240
ryood 18:309f794eba74 241 if (pinFlag & bModNumber) {
ryood 18:309f794eba74 242 #if (UART_TRACE)
ryood 18:309f794eba74 243 printf("PinModNumber Pushed\r\n");
ryood 18:309f794eba74 244 #endif
ryood 18:309f794eba74 245 modNumber++;
ryood 18:309f794eba74 246 if (modNumber > MOD_NUMBER_MAX) {
ryood 18:309f794eba74 247 modNumber = 0;
ryood 18:309f794eba74 248 }
ryood 18:309f794eba74 249 pinFlag &= ~bModNumber;
ryood 18:309f794eba74 250 }
ryood 18:309f794eba74 251
ryood 18:309f794eba74 252 if (pinFlag & bOctaveUp) {
ryood 18:309f794eba74 253 #if (UART_TRACE)
ryood 18:309f794eba74 254 printf("PinOctaveUp Pushed\r\n");
ryood 18:309f794eba74 255 #endif
ryood 18:309f794eba74 256 sequences[currentStep].setOctave(sequences[currentStep].getOctave() + 1);
ryood 18:309f794eba74 257 pinFlag &= ~bOctaveUp;
ryood 18:309f794eba74 258 }
ryood 18:309f794eba74 259
ryood 18:309f794eba74 260 if (pinFlag & bOctaveDown) {
ryood 18:309f794eba74 261 #if (UART_TRACE)
ryood 18:309f794eba74 262 printf("PinOctaveDown Pushed\r\n");
ryood 18:309f794eba74 263 #endif
ryood 18:309f794eba74 264 sequences[currentStep].setOctave(sequences[currentStep].getOctave() - 1);
ryood 18:309f794eba74 265 pinFlag &= ~bOctaveDown;
ryood 18:309f794eba74 266 }
ryood 18:309f794eba74 267
ryood 18:309f794eba74 268 if (pinFlag & bNoteOnOff) {
ryood 18:309f794eba74 269 #if (UART_TRACE)
ryood 18:309f794eba74 270 printf("PinNoteOnOff Pushed\r\n");
ryood 18:309f794eba74 271 #endif
ryood 18:309f794eba74 272 sequences[currentStep].setNoteOn(!sequences[currentStep].isNoteOn());
ryood 18:309f794eba74 273 pinFlag &= ~bNoteOnOff;
ryood 18:309f794eba74 274 }
ryood 18:309f794eba74 275
ryood 18:309f794eba74 276 if (pinFlag & bTie) {
ryood 18:309f794eba74 277 #if (UART_TRACE)
ryood 18:309f794eba74 278 printf("PinTie Pushed\r\n");
ryood 18:309f794eba74 279 #endif
ryood 18:309f794eba74 280 sequences[currentStep].setTie(!sequences[currentStep].isTie());
ryood 18:309f794eba74 281 pinFlag &= ~bTie;
ryood 18:309f794eba74 282 }
ryood 18:309f794eba74 283
ryood 18:309f794eba74 284 if (pinFlag & bAccent) {
ryood 18:309f794eba74 285 #if (UART_TRACE)
ryood 18:309f794eba74 286 printf("PinAccent Pushed\r\n");
ryood 18:309f794eba74 287 #endif
ryood 18:309f794eba74 288 sequences[currentStep].setAccent(!sequences[currentStep].isAccent());
ryood 18:309f794eba74 289 pinFlag &= ~bAccent;
ryood 18:309f794eba74 290 }
ryood 18:309f794eba74 291
ryood 18:309f794eba74 292 if (pinFlag & bRunStop) {
ryood 18:309f794eba74 293 #if (UART_TRACE)
ryood 18:309f794eba74 294 printf("PinRunStop Pushed\r\n");
ryood 18:309f794eba74 295 #endif
ryood 18:309f794eba74 296 if (isRunning) {
ryood 18:309f794eba74 297 sequenceSender.stop();
ryood 18:309f794eba74 298 isRunning = false;
ryood 18:309f794eba74 299 } else {
ryood 18:309f794eba74 300 sequenceSender.run(currentStep);
ryood 18:309f794eba74 301 isRunning = true;
ryood 18:309f794eba74 302 }
ryood 18:309f794eba74 303 pinFlag &= ~bRunStop;
ryood 18:309f794eba74 304 }
ryood 18:309f794eba74 305 }
ryood 18:309f794eba74 306
ryood 16:b0419e3c9079 307 void dumpToLCD()
ryood 16:b0419e3c9079 308 {
ryood 16:b0419e3c9079 309 char buff[64];
ryood 16:b0419e3c9079 310 int col = 0;
ryood 16:b0419e3c9079 311
ryood 16:b0419e3c9079 312 gLCD.clear();
ryood 16:b0419e3c9079 313
ryood 16:b0419e3c9079 314 sprintf(buff, "Run: %d", isRunning);
ryood 16:b0419e3c9079 315 gLCD.drawstring(0, col++, buff);
ryood 16:b0419e3c9079 316 sprintf(buff, "BPM: %d", sequenceSender.getBpm());
ryood 16:b0419e3c9079 317 gLCD.drawstring(0, col++, buff);
ryood 16:b0419e3c9079 318
ryood 16:b0419e3c9079 319 sprintf(buff, "Step: %d", currentStep);
ryood 16:b0419e3c9079 320 gLCD.drawstring(0, col++, buff);
ryood 16:b0419e3c9079 321 sprintf(buff, "NoteOn: %d", sequences[currentStep].isNoteOn());
ryood 16:b0419e3c9079 322 gLCD.drawstring(0, col++, buff);
ryood 16:b0419e3c9079 323 sprintf(buff, "Pitch: %d", sequences[currentStep].getPitch());
ryood 16:b0419e3c9079 324 gLCD.drawstring(0, col++, buff);
ryood 16:b0419e3c9079 325 sprintf(buff, "Octave: %d", sequences[currentStep].getOctave());
ryood 16:b0419e3c9079 326 gLCD.drawstring(0, col++, buff);
ryood 16:b0419e3c9079 327 sprintf(buff, "Tie: %d", sequences[currentStep].isTie());
ryood 16:b0419e3c9079 328 gLCD.drawstring(0, col++, buff);
ryood 16:b0419e3c9079 329 sprintf(buff, "Accent: %d", sequences[currentStep].isAccent());
ryood 16:b0419e3c9079 330 gLCD.drawstring(0, col++, buff);
ryood 16:b0419e3c9079 331
ryood 16:b0419e3c9079 332 col = 0;
ryood 16:b0419e3c9079 333 sprintf(buff, "WavS: %d", sequenceSender.getWaveShape());
ryood 16:b0419e3c9079 334 gLCD.drawstring(64, col++, buff);
ryood 16:b0419e3c9079 335 sprintf(buff, "ModN: %d", modNumber);
ryood 16:b0419e3c9079 336 gLCD.drawstring(64, col++, buff);
ryood 16:b0419e3c9079 337
ryood 16:b0419e3c9079 338 col = 2;
ryood 19:241a4b355413 339 sprintf(buff, "PW%3d CO%3d", sequenceSender.getPulseWidth(), filterController.getCutoff());
ryood 16:b0419e3c9079 340 gLCD.drawstring(60, col++, buff);
ryood 19:241a4b355413 341 sprintf(buff, "RS%3d EV%3d", filterController.getResonance(), envMod);
ryood 16:b0419e3c9079 342 gLCD.drawstring(60, col++, buff);
ryood 19:241a4b355413 343 sprintf(buff, "LV%3d DR%3d", envelope.getLevel(), envelope.getDuration());
ryood 16:b0419e3c9079 344 gLCD.drawstring(60, col++, buff);
ryood 19:241a4b355413 345 sprintf(buff, "DC%3d ST%3d", envelope.getDecay(), envelope.getSustain());
ryood 16:b0419e3c9079 346 gLCD.drawstring(60, col++, buff);
ryood 16:b0419e3c9079 347
ryood 16:b0419e3c9079 348 gLCD.display();
ryood 16:b0419e3c9079 349 }
ryood 16:b0419e3c9079 350
ryood 16:b0419e3c9079 351 //------------------------------------------------------------------------
ryood 16:b0419e3c9079 352 // Main routine
ryood 16:b0419e3c9079 353 //------------------------------------------------------------------------
ryood 0:21e39bc75e31 354 int main()
ryood 0:21e39bc75e31 355 {
ryood 18:309f794eba74 356 #if (UART_TRACE)
ryood 18:309f794eba74 357 printf("*** BaseMachine Sequencer ***\r\n");
ryood 18:309f794eba74 358 #endif
ryood 18:309f794eba74 359
ryood 16:b0419e3c9079 360 // Setup Devices
ryood 16:b0419e3c9079 361 //
ryood 0:21e39bc75e31 362 spiMaster.format(8, 0);
ryood 0:21e39bc75e31 363 spiMaster.frequency(SPI_RATE);
ryood 0:21e39bc75e31 364
ryood 16:b0419e3c9079 365 gLCD.begin(0x12);
ryood 16:b0419e3c9079 366 gLCD.clear();
ryood 16:b0419e3c9079 367 gLCD.drawstring(0, 0, TITLE_STR1);
ryood 16:b0419e3c9079 368 gLCD.drawstring(0, 1, TITLE_STR2);
ryood 16:b0419e3c9079 369 gLCD.display();
ryood 16:b0419e3c9079 370 Thread::wait(1000);
ryood 16:b0419e3c9079 371
ryood 17:557658db3e81 372 dumpToLCD();
ryood 17:557658db3e81 373 Thread::wait(1000);
ryood 17:557658db3e81 374
ryood 20:00d3b6ace8c7 375 RotEncStep.setInterval(100);
ryood 20:00d3b6ace8c7 376 RotEncPitch.setInterval(100);
ryood 20:00d3b6ace8c7 377 RotEncBpm.setInterval(100);
ryood 17:557658db3e81 378
ryood 18:309f794eba74 379 PinWaveShape.attach_asserted(&swWaveShapePressed);
ryood 18:309f794eba74 380 PinWaveShape.setAssertValue(0);
ryood 18:309f794eba74 381 PinWaveShape.setSampleFrequency();
ryood 18:309f794eba74 382
ryood 18:309f794eba74 383 PinModNumber.attach_asserted(&swModNumberPressed);
ryood 18:309f794eba74 384 PinModNumber.setAssertValue(0);
ryood 18:309f794eba74 385 PinModNumber.setSampleFrequency();
ryood 18:309f794eba74 386
ryood 18:309f794eba74 387 PinOctaveUp.attach_asserted(&swOctaveUpPressed);
ryood 18:309f794eba74 388 PinOctaveUp.setAssertValue(0);
ryood 18:309f794eba74 389 PinOctaveUp.setSampleFrequency();
ryood 18:309f794eba74 390
ryood 18:309f794eba74 391 PinOctaveDown.attach_asserted(&swOctaveDownPressed);
ryood 18:309f794eba74 392 PinOctaveDown.setAssertValue(0);
ryood 18:309f794eba74 393 PinOctaveDown.setSampleFrequency();
ryood 18:309f794eba74 394
ryood 18:309f794eba74 395 PinNoteOnOff.attach_asserted(&swNoteOnOffPressed);
ryood 18:309f794eba74 396 PinNoteOnOff.setAssertValue(0);
ryood 18:309f794eba74 397 PinNoteOnOff.setSampleFrequency();
ryood 18:309f794eba74 398
ryood 18:309f794eba74 399 PinTie.attach_asserted(&swTiePressed);
ryood 18:309f794eba74 400 PinTie.setAssertValue(0);
ryood 18:309f794eba74 401 PinTie.setSampleFrequency();
ryood 18:309f794eba74 402
ryood 18:309f794eba74 403 PinAccent.attach_asserted(&swAccentPressed);
ryood 18:309f794eba74 404 PinAccent.setAssertValue(0);
ryood 18:309f794eba74 405 PinAccent.setSampleFrequency();
ryood 18:309f794eba74 406
ryood 18:309f794eba74 407 PinRunStop.attach_asserted(&swRunStopPressed);
ryood 18:309f794eba74 408 PinRunStop.setAssertValue(0);
ryood 18:309f794eba74 409 PinRunStop.setSampleFrequency();
ryood 18:309f794eba74 410
ryood 0:21e39bc75e31 411 // Test SequencerSender Run
ryood 0:21e39bc75e31 412 //
ryood 15:9813d8eaf57e 413 Sequence::setBaseNoteNumber(baseNoteNumber);
ryood 10:fb04f9959fd9 414 sequenceSender.setBpm(bpm);
ryood 14:c173e03ee3ad 415
ryood 19:241a4b355413 416 // Initialize sequences
ryood 0:21e39bc75e31 417 for (int i = 0; i < SEQUENCE_N; i++) {
ryood 0:21e39bc75e31 418 Sequence& seq = sequenceSender.getSequences()[i];
ryood 14:c173e03ee3ad 419 seq.setPitch(pitch[i]);
ryood 14:c173e03ee3ad 420 seq.setOctave(octave[i]);
ryood 15:9813d8eaf57e 421 seq.setNoteOn(noteOn[i]);
ryood 15:9813d8eaf57e 422 seq.setTie(tie[i]);
ryood 0:21e39bc75e31 423 }
ryood 6:fc10eac60b91 424
ryood 9:3e4e08578e1c 425 envelopeGenerator.init(envelope);
ryood 12:c248781608af 426
ryood 16:b0419e3c9079 427 sequenceSender.attachUpdate(&updateFunction);
ryood 14:c173e03ee3ad 428 sequenceSender.setWaveShape(waveShape);
ryood 18:309f794eba74 429 //sequenceSender.run(0);
ryood 5:4abac408b827 430
ryood 5:4abac408b827 431 for (;;) {
ryood 20:00d3b6ace8c7 432 pollingPots();
ryood 20:00d3b6ace8c7 433 pollingRotEncs();
ryood 18:309f794eba74 434 pollingPins();
ryood 18:309f794eba74 435 #if 0
ryood 10:fb04f9959fd9 436 /*
ryood 5:4abac408b827 437 sequenceSender.setPulseWidth(sequenceSender.getPulseWidth() + 4);
ryood 6:fc10eac60b91 438 Thread::wait(500);
ryood 6:fc10eac60b91 439 sequenceSender.setWaveShape(SpiSequenceSender::WAVESHAPE_SAW);
ryood 6:fc10eac60b91 440 Thread::wait(500);
ryood 6:fc10eac60b91 441 sequenceSender.setWaveShape(SpiSequenceSender::WAVESHAPE_SQUARE);
ryood 10:fb04f9959fd9 442 */
ryood 13:b0f988a239df 443 //envelope.setLevel(levelIn * 4095);
ryood 13:b0f988a239df 444 envelope.setLevel(4095);
ryood 10:fb04f9959fd9 445 envelope.setDuration(durationIn * envelopeLength);
ryood 10:fb04f9959fd9 446 envelope.setDecay(decayIn * envelopeLength);
ryood 10:fb04f9959fd9 447 envelope.setSustain(sustainIn * 4095);
ryood 12:c248781608af 448
ryood 12:c248781608af 449 filterController.setCutoff(cutoffIn * 255);
ryood 12:c248781608af 450 filterController.setResonance(resonanceIn * 255);
ryood 12:c248781608af 451
ryood 14:c173e03ee3ad 452 #if(UART_TRACE)
ryood 12:c248781608af 453 printf("%d\t%d\t%d\t%d\t%d\t%d\r\n",
ryood 12:c248781608af 454 filterController.getCutoff(),
ryood 12:c248781608af 455 filterController.getResonance(),
ryood 12:c248781608af 456 envelope.getLevel(),
ryood 12:c248781608af 457 envelope.getDuration(),
ryood 12:c248781608af 458 envelope.getDecay(),
ryood 12:c248781608af 459 envelope.getSustain()
ryood 12:c248781608af 460 );
ryood 14:c173e03ee3ad 461 #endif
ryood 18:309f794eba74 462 #endif
ryood 5:4abac408b827 463 }
ryood 0:21e39bc75e31 464 }