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 13:41:27 2016 +0000
Revision:
24:040cdcb2ff14
Parent:
23:5fe70293e34c
Child:
25:7382bc0a0329
integration testing: UI & Sound

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 21:c4d09aaa52b9 106 volatile uint8_t envMod = 127;
ryood 16:b0419e3c9079 107
ryood 16:b0419e3c9079 108 //------------------------------------------------------------------------
ryood 16:b0419e3c9079 109 // Callback functions
ryood 16:b0419e3c9079 110 //------------------------------------------------------------------------
ryood 16:b0419e3c9079 111 void updateFunction(int ticks)
ryood 8:de409197ff95 112 {
ryood 8:de409197ff95 113 if (ticks == 0) {
ryood 9:3e4e08578e1c 114 envelopeGenerator.init(envelope);
ryood 8:de409197ff95 115 }
ryood 14:c173e03ee3ad 116
ryood 15:9813d8eaf57e 117 if (sequenceSender.getSequences()[sequenceSender.getStep()].isNoteOn()) {
ryood 14:c173e03ee3ad 118 uint16_t level = envelopeGenerator.getModLevel();
ryood 14:c173e03ee3ad 119 ampController.outDca(level);
ryood 14:c173e03ee3ad 120 } else {
ryood 14:c173e03ee3ad 121 ampController.outDca(0);
ryood 14:c173e03ee3ad 122 }
ryood 9:3e4e08578e1c 123 envelopeGenerator.update();
ryood 12:c248781608af 124
ryood 15:9813d8eaf57e 125 filterController.outDcf();
ryood 17:557658db3e81 126
ryood 17:557658db3e81 127 // ToDo: 再生中のLCD表示を検討→SPI1とSPI2の信号のタイミングを調査
ryood 17:557658db3e81 128 //sequencerDisplay.update(SequencerDisplay::stop, sequenceSender.getStep());
ryood 8:de409197ff95 129 }
ryood 8:de409197ff95 130
ryood 16:b0419e3c9079 131 //------------------------------------------------------------------------
ryood 18:309f794eba74 132 // PinDetect ISR
ryood 18:309f794eba74 133 //------------------------------------------------------------------------
ryood 18:309f794eba74 134 void swWaveShapePressed()
ryood 18:309f794eba74 135 {
ryood 18:309f794eba74 136 pinFlag |= bWaveShape;
ryood 18:309f794eba74 137 }
ryood 18:309f794eba74 138
ryood 18:309f794eba74 139 void swModNumberPressed()
ryood 18:309f794eba74 140 {
ryood 18:309f794eba74 141 pinFlag |= bModNumber;
ryood 18:309f794eba74 142 }
ryood 18:309f794eba74 143
ryood 18:309f794eba74 144 void swOctaveUpPressed()
ryood 18:309f794eba74 145 {
ryood 18:309f794eba74 146 pinFlag |= bOctaveUp;
ryood 18:309f794eba74 147 }
ryood 18:309f794eba74 148
ryood 18:309f794eba74 149 void swOctaveDownPressed()
ryood 18:309f794eba74 150 {
ryood 18:309f794eba74 151 pinFlag |= bOctaveDown;
ryood 18:309f794eba74 152 }
ryood 18:309f794eba74 153
ryood 18:309f794eba74 154 void swNoteOnOffPressed()
ryood 18:309f794eba74 155 {
ryood 18:309f794eba74 156 pinFlag |= bNoteOnOff;
ryood 18:309f794eba74 157 }
ryood 18:309f794eba74 158
ryood 18:309f794eba74 159 void swTiePressed()
ryood 18:309f794eba74 160 {
ryood 18:309f794eba74 161 pinFlag |= bTie;
ryood 18:309f794eba74 162 }
ryood 18:309f794eba74 163
ryood 18:309f794eba74 164 void swAccentPressed()
ryood 18:309f794eba74 165 {
ryood 18:309f794eba74 166 pinFlag |= bAccent;
ryood 18:309f794eba74 167 }
ryood 18:309f794eba74 168
ryood 18:309f794eba74 169 void swRunStopPressed()
ryood 18:309f794eba74 170 {
ryood 18:309f794eba74 171 pinFlag |= bRunStop;
ryood 18:309f794eba74 172 }
ryood 18:309f794eba74 173
ryood 18:309f794eba74 174 //------------------------------------------------------------------------
ryood 16:b0419e3c9079 175 // Functions
ryood 16:b0419e3c9079 176 //------------------------------------------------------------------------
ryood 19:241a4b355413 177 void pollingPots()
ryood 19:241a4b355413 178 {
ryood 20:00d3b6ace8c7 179 //pulseWidth = AinPulseWidth.read_u16() >> 8;
ryood 20:00d3b6ace8c7 180
ryood 19:241a4b355413 181 filterController.setCutoff(AinCutOff.read_u16() >> 8);
ryood 19:241a4b355413 182 filterController.setResonance(AinResonance.read_u16() >> 8);
ryood 24:040cdcb2ff14 183 //envMod = AinEnvMod.read_u16() >> 8;
ryood 19:241a4b355413 184
ryood 19:241a4b355413 185 //envelope.setLevel(AinLevel.read_u16() >> 4);
ryood 19:241a4b355413 186 envelope.setLevel(4095);
ryood 19:241a4b355413 187 envelope.setDuration(AinDuration.read() * envelopeLength);
ryood 19:241a4b355413 188 envelope.setDecay(AinDecay.read() * envelopeLength);
ryood 19:241a4b355413 189 envelope.setSustain(AinSustain.read() * 4095);
ryood 20:00d3b6ace8c7 190 }
ryood 20:00d3b6ace8c7 191
ryood 20:00d3b6ace8c7 192 void pollingRotEncs()
ryood 20:00d3b6ace8c7 193 {
ryood 20:00d3b6ace8c7 194 int _bpm = RotEncBpm.getVal();
ryood 20:00d3b6ace8c7 195 if (_bpm != sequenceSender.getBpm()) {
ryood 20:00d3b6ace8c7 196 sequenceSender.setBpm(_bpm);
ryood 20:00d3b6ace8c7 197 isDirty = true;
ryood 20:00d3b6ace8c7 198 }
ryood 20:00d3b6ace8c7 199
ryood 20:00d3b6ace8c7 200 int _step = RotEncStep.getVal();
ryood 20:00d3b6ace8c7 201 if (_step != currentStep) {
ryood 20:00d3b6ace8c7 202 currentStep = _step;
ryood 20:00d3b6ace8c7 203 // syncronize sequence value & Rotary Encoder's value
ryood 20:00d3b6ace8c7 204 RotEncPitch.setVal(sequences[currentStep].getPitch());
ryood 20:00d3b6ace8c7 205 isDirty = true;
ryood 20:00d3b6ace8c7 206 }
ryood 20:00d3b6ace8c7 207
ryood 20:00d3b6ace8c7 208 int _pitch = RotEncPitch.getVal();
ryood 20:00d3b6ace8c7 209 if (_pitch != sequences[currentStep].getPitch()) {
ryood 20:00d3b6ace8c7 210 sequences[currentStep].setPitch(_pitch);
ryood 20:00d3b6ace8c7 211 isDirty = true;
ryood 20:00d3b6ace8c7 212 }
ryood 19:241a4b355413 213 }
ryood 19:241a4b355413 214
ryood 18:309f794eba74 215 void pollingPins()
ryood 18:309f794eba74 216 {
ryood 18:309f794eba74 217 if (pinFlag & bWaveShape) {
ryood 18:309f794eba74 218 #if (UART_TRACE)
ryood 18:309f794eba74 219 printf("PinWaveShape Pushed\r\n");
ryood 18:309f794eba74 220 #endif
ryood 18:309f794eba74 221 uint8_t waveShape = sequenceSender.getWaveShape();
ryood 18:309f794eba74 222 waveShape++;
ryood 18:309f794eba74 223 if (waveShape < SpiSequenceSender::WAVESHAPE_N) {
ryood 18:309f794eba74 224 sequenceSender.setWaveShape(waveShape);
ryood 18:309f794eba74 225 } else {
ryood 18:309f794eba74 226 sequenceSender.setWaveShape(0);
ryood 18:309f794eba74 227 }
ryood 18:309f794eba74 228 pinFlag &= ~bWaveShape;
ryood 18:309f794eba74 229 }
ryood 18:309f794eba74 230
ryood 18:309f794eba74 231 if (pinFlag & bModNumber) {
ryood 18:309f794eba74 232 #if (UART_TRACE)
ryood 18:309f794eba74 233 printf("PinModNumber Pushed\r\n");
ryood 18:309f794eba74 234 #endif
ryood 18:309f794eba74 235 modNumber++;
ryood 18:309f794eba74 236 if (modNumber > MOD_NUMBER_MAX) {
ryood 18:309f794eba74 237 modNumber = 0;
ryood 18:309f794eba74 238 }
ryood 18:309f794eba74 239 pinFlag &= ~bModNumber;
ryood 18:309f794eba74 240 }
ryood 18:309f794eba74 241
ryood 18:309f794eba74 242 if (pinFlag & bOctaveUp) {
ryood 18:309f794eba74 243 #if (UART_TRACE)
ryood 18:309f794eba74 244 printf("PinOctaveUp Pushed\r\n");
ryood 18:309f794eba74 245 #endif
ryood 18:309f794eba74 246 sequences[currentStep].setOctave(sequences[currentStep].getOctave() + 1);
ryood 18:309f794eba74 247 pinFlag &= ~bOctaveUp;
ryood 18:309f794eba74 248 }
ryood 18:309f794eba74 249
ryood 18:309f794eba74 250 if (pinFlag & bOctaveDown) {
ryood 18:309f794eba74 251 #if (UART_TRACE)
ryood 18:309f794eba74 252 printf("PinOctaveDown Pushed\r\n");
ryood 18:309f794eba74 253 #endif
ryood 18:309f794eba74 254 sequences[currentStep].setOctave(sequences[currentStep].getOctave() - 1);
ryood 18:309f794eba74 255 pinFlag &= ~bOctaveDown;
ryood 18:309f794eba74 256 }
ryood 18:309f794eba74 257
ryood 18:309f794eba74 258 if (pinFlag & bNoteOnOff) {
ryood 18:309f794eba74 259 #if (UART_TRACE)
ryood 18:309f794eba74 260 printf("PinNoteOnOff Pushed\r\n");
ryood 18:309f794eba74 261 #endif
ryood 18:309f794eba74 262 sequences[currentStep].setNoteOn(!sequences[currentStep].isNoteOn());
ryood 18:309f794eba74 263 pinFlag &= ~bNoteOnOff;
ryood 18:309f794eba74 264 }
ryood 18:309f794eba74 265
ryood 18:309f794eba74 266 if (pinFlag & bTie) {
ryood 18:309f794eba74 267 #if (UART_TRACE)
ryood 18:309f794eba74 268 printf("PinTie Pushed\r\n");
ryood 18:309f794eba74 269 #endif
ryood 18:309f794eba74 270 sequences[currentStep].setTie(!sequences[currentStep].isTie());
ryood 18:309f794eba74 271 pinFlag &= ~bTie;
ryood 18:309f794eba74 272 }
ryood 18:309f794eba74 273
ryood 18:309f794eba74 274 if (pinFlag & bAccent) {
ryood 18:309f794eba74 275 #if (UART_TRACE)
ryood 18:309f794eba74 276 printf("PinAccent Pushed\r\n");
ryood 18:309f794eba74 277 #endif
ryood 18:309f794eba74 278 sequences[currentStep].setAccent(!sequences[currentStep].isAccent());
ryood 18:309f794eba74 279 pinFlag &= ~bAccent;
ryood 18:309f794eba74 280 }
ryood 18:309f794eba74 281
ryood 18:309f794eba74 282 if (pinFlag & bRunStop) {
ryood 18:309f794eba74 283 #if (UART_TRACE)
ryood 18:309f794eba74 284 printf("PinRunStop Pushed\r\n");
ryood 18:309f794eba74 285 #endif
ryood 18:309f794eba74 286 if (isRunning) {
ryood 22:82f1e7877f9f 287 ampController.outDca(0);
ryood 18:309f794eba74 288 sequenceSender.stop();
ryood 18:309f794eba74 289 isRunning = false;
ryood 18:309f794eba74 290 } else {
ryood 18:309f794eba74 291 sequenceSender.run(currentStep);
ryood 18:309f794eba74 292 isRunning = true;
ryood 18:309f794eba74 293 }
ryood 18:309f794eba74 294 pinFlag &= ~bRunStop;
ryood 18:309f794eba74 295 }
ryood 18:309f794eba74 296 }
ryood 18:309f794eba74 297
ryood 16:b0419e3c9079 298 void dumpToLCD()
ryood 16:b0419e3c9079 299 {
ryood 16:b0419e3c9079 300 char buff[64];
ryood 16:b0419e3c9079 301 int col = 0;
ryood 16:b0419e3c9079 302
ryood 16:b0419e3c9079 303 gLCD.clear();
ryood 16:b0419e3c9079 304
ryood 24:040cdcb2ff14 305 sprintf(buff, "Run:%d BPM:%03d", isRunning, sequenceSender.getBpm());
ryood 16:b0419e3c9079 306 gLCD.drawstring(0, col++, buff);
ryood 24:040cdcb2ff14 307
ryood 24:040cdcb2ff14 308 sprintf(buff, "Stp:%02d Nto:%d Pch:%02d",
ryood 24:040cdcb2ff14 309 currentStep, sequences[currentStep].isNoteOn(), sequences[currentStep].getPitch());
ryood 24:040cdcb2ff14 310 gLCD.drawstring(0, col++, buff);
ryood 24:040cdcb2ff14 311
ryood 24:040cdcb2ff14 312 sprintf(buff, "Oct:%-2d Tie:%d Acc:%d",
ryood 24:040cdcb2ff14 313 sequences[currentStep].getOctave(), sequences[currentStep].isTie(),sequences[currentStep].isAccent());
ryood 16:b0419e3c9079 314 gLCD.drawstring(0, col++, buff);
ryood 16:b0419e3c9079 315
ryood 24:040cdcb2ff14 316 sprintf(buff, "Wsp:%d Mdn:%d", sequenceSender.getWaveShape(), modNumber);
ryood 16:b0419e3c9079 317 gLCD.drawstring(0, col++, buff);
ryood 16:b0419e3c9079 318
ryood 24:040cdcb2ff14 319 sprintf(buff, "PW :%4d CO :%4d", sequenceSender.getPulseWidth(), filterController.getCutoff());
ryood 24:040cdcb2ff14 320 gLCD.drawstring(0, col++, buff);
ryood 24:040cdcb2ff14 321 sprintf(buff, "RSO:%4d ENV:%4d", filterController.getResonance(), envMod);
ryood 24:040cdcb2ff14 322 gLCD.drawstring(0, col++, buff);
ryood 24:040cdcb2ff14 323 sprintf(buff, "LVL:%4d DUR:%4d", envelope.getLevel(), envelope.getDuration());
ryood 24:040cdcb2ff14 324 gLCD.drawstring(0, col++, buff);
ryood 24:040cdcb2ff14 325 sprintf(buff, "DCY:%4d SUS:%4d", envelope.getDecay(), envelope.getSustain());
ryood 24:040cdcb2ff14 326 gLCD.drawstring(0, col++, buff);
ryood 16:b0419e3c9079 327
ryood 16:b0419e3c9079 328 gLCD.display();
ryood 16:b0419e3c9079 329 }
ryood 16:b0419e3c9079 330
ryood 16:b0419e3c9079 331 //------------------------------------------------------------------------
ryood 16:b0419e3c9079 332 // Main routine
ryood 16:b0419e3c9079 333 //------------------------------------------------------------------------
ryood 0:21e39bc75e31 334 int main()
ryood 0:21e39bc75e31 335 {
ryood 18:309f794eba74 336 #if (UART_TRACE)
ryood 18:309f794eba74 337 printf("*** BaseMachine Sequencer ***\r\n");
ryood 18:309f794eba74 338 #endif
ryood 18:309f794eba74 339
ryood 24:040cdcb2ff14 340 //--------------------------------------------------------------------
ryood 16:b0419e3c9079 341 // Setup Devices
ryood 16:b0419e3c9079 342 //
ryood 0:21e39bc75e31 343 spiMaster.format(8, 0);
ryood 0:21e39bc75e31 344 spiMaster.frequency(SPI_RATE);
ryood 0:21e39bc75e31 345
ryood 24:040cdcb2ff14 346 // Mute output
ryood 24:040cdcb2ff14 347 ampController.outDca(0);
ryood 24:040cdcb2ff14 348
ryood 16:b0419e3c9079 349 gLCD.begin(0x12);
ryood 16:b0419e3c9079 350 gLCD.clear();
ryood 16:b0419e3c9079 351 gLCD.drawstring(0, 0, TITLE_STR1);
ryood 16:b0419e3c9079 352 gLCD.drawstring(0, 1, TITLE_STR2);
ryood 16:b0419e3c9079 353 gLCD.display();
ryood 16:b0419e3c9079 354 Thread::wait(1000);
ryood 16:b0419e3c9079 355
ryood 20:00d3b6ace8c7 356 RotEncStep.setInterval(100);
ryood 20:00d3b6ace8c7 357 RotEncPitch.setInterval(100);
ryood 20:00d3b6ace8c7 358 RotEncBpm.setInterval(100);
ryood 17:557658db3e81 359
ryood 18:309f794eba74 360 PinWaveShape.attach_asserted(&swWaveShapePressed);
ryood 18:309f794eba74 361 PinWaveShape.setAssertValue(0);
ryood 18:309f794eba74 362 PinWaveShape.setSampleFrequency();
ryood 18:309f794eba74 363
ryood 18:309f794eba74 364 PinModNumber.attach_asserted(&swModNumberPressed);
ryood 18:309f794eba74 365 PinModNumber.setAssertValue(0);
ryood 18:309f794eba74 366 PinModNumber.setSampleFrequency();
ryood 18:309f794eba74 367
ryood 18:309f794eba74 368 PinOctaveUp.attach_asserted(&swOctaveUpPressed);
ryood 18:309f794eba74 369 PinOctaveUp.setAssertValue(0);
ryood 18:309f794eba74 370 PinOctaveUp.setSampleFrequency();
ryood 18:309f794eba74 371
ryood 18:309f794eba74 372 PinOctaveDown.attach_asserted(&swOctaveDownPressed);
ryood 18:309f794eba74 373 PinOctaveDown.setAssertValue(0);
ryood 18:309f794eba74 374 PinOctaveDown.setSampleFrequency();
ryood 18:309f794eba74 375
ryood 18:309f794eba74 376 PinNoteOnOff.attach_asserted(&swNoteOnOffPressed);
ryood 18:309f794eba74 377 PinNoteOnOff.setAssertValue(0);
ryood 18:309f794eba74 378 PinNoteOnOff.setSampleFrequency();
ryood 18:309f794eba74 379
ryood 18:309f794eba74 380 PinTie.attach_asserted(&swTiePressed);
ryood 18:309f794eba74 381 PinTie.setAssertValue(0);
ryood 18:309f794eba74 382 PinTie.setSampleFrequency();
ryood 18:309f794eba74 383
ryood 18:309f794eba74 384 PinAccent.attach_asserted(&swAccentPressed);
ryood 18:309f794eba74 385 PinAccent.setAssertValue(0);
ryood 18:309f794eba74 386 PinAccent.setSampleFrequency();
ryood 18:309f794eba74 387
ryood 18:309f794eba74 388 PinRunStop.attach_asserted(&swRunStopPressed);
ryood 18:309f794eba74 389 PinRunStop.setAssertValue(0);
ryood 18:309f794eba74 390 PinRunStop.setSampleFrequency();
ryood 18:309f794eba74 391
ryood 24:040cdcb2ff14 392 //--------------------------------------------------------------------
ryood 22:82f1e7877f9f 393 // Initialize objects
ryood 0:21e39bc75e31 394 //
ryood 15:9813d8eaf57e 395 Sequence::setBaseNoteNumber(baseNoteNumber);
ryood 14:c173e03ee3ad 396
ryood 0:21e39bc75e31 397 for (int i = 0; i < SEQUENCE_N; i++) {
ryood 0:21e39bc75e31 398 Sequence& seq = sequenceSender.getSequences()[i];
ryood 14:c173e03ee3ad 399 seq.setPitch(pitch[i]);
ryood 14:c173e03ee3ad 400 seq.setOctave(octave[i]);
ryood 15:9813d8eaf57e 401 seq.setNoteOn(noteOn[i]);
ryood 15:9813d8eaf57e 402 seq.setTie(tie[i]);
ryood 0:21e39bc75e31 403 }
ryood 6:fc10eac60b91 404
ryood 9:3e4e08578e1c 405 envelopeGenerator.init(envelope);
ryood 12:c248781608af 406
ryood 16:b0419e3c9079 407 sequenceSender.attachUpdate(&updateFunction);
ryood 14:c173e03ee3ad 408 sequenceSender.setWaveShape(waveShape);
ryood 18:309f794eba74 409 //sequenceSender.run(0);
ryood 5:4abac408b827 410
ryood 24:040cdcb2ff14 411 //--------------------------------------------------------------------
ryood 24:040cdcb2ff14 412 // Main loop
ryood 24:040cdcb2ff14 413 //
ryood 5:4abac408b827 414 for (;;) {
ryood 20:00d3b6ace8c7 415 pollingPots();
ryood 20:00d3b6ace8c7 416 pollingRotEncs();
ryood 18:309f794eba74 417 pollingPins();
ryood 23:5fe70293e34c 418 if (!isRunning) {
ryood 24:040cdcb2ff14 419 sequencerDisplay.update(SequencerDisplay::stop, currentStep);
ryood 24:040cdcb2ff14 420 //dumpToLCD();
ryood 23:5fe70293e34c 421 }
ryood 5:4abac408b827 422 }
ryood 0:21e39bc75e31 423 }