Ryo Od / Mbed 2 deprecated BaseMachine_Sequencer

Dependencies:   Amp AverageAnalogIn Envelope FilterController Sequence BaseMachineComon mbed-rtos mbed

Fork of SpiSequenceSender_Test by Ryo Od

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