Nucleo Sequencer of my Base Machine
Dependencies: Amp AverageAnalogIn Envelope FilterController Sequence BaseMachineComon mbed-rtos mbed
Fork of SpiSequenceSender_Test by
Diff: main.cpp
- Revision:
- 14:c173e03ee3ad
- Parent:
- 13:b0f988a239df
- Child:
- 15:9813d8eaf57e
--- a/main.cpp Fri Jul 29 09:44:27 2016 +0000 +++ b/main.cpp Tue Aug 02 22:37:09 2016 +0000 @@ -10,9 +10,17 @@ #define SEQUENCE_N (16) #define SPI_RATE (8000000) -const int samplingPeriod = 2; // ms +const int samplingPeriod = 1; // ms const int bpm = 120; const int envelopeLength = (60 * 1000 / (bpm * 4)) / samplingPeriod; +const int waveShape = SpiSequenceSender::WAVESHAPE_SAW; +const int baseNoteNumber = 48; + +// Initial Sequence +const int noteOn[SEQUENCE_N] = { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0 }; +const int octave[SEQUENCE_N] = {-1,-1,-1, 0, 0,-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 }; +const int pitch[SEQUENCE_N] = { 9, 7, 3, 0, 0, 3, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 }; +const int tie[SEQUENCE_N] = { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0 }; //AnalogIn levelIn(A0); AnalogIn durationIn(A2); @@ -37,9 +45,13 @@ if (ticks == 0) { envelopeGenerator.init(envelope); } - uint16_t level = envelopeGenerator.getModLevel(); - //printf("g,%d\r\n", level); - ampController.outDca(level); + + if (sequenceSender.getSequences()[sequenceSender.getStep()].noteOn) { + uint16_t level = envelopeGenerator.getModLevel(); + ampController.outDca(level); + } else { + ampController.outDca(0); + } envelopeGenerator.update(); filterController.outDCF(); @@ -52,23 +64,21 @@ // Test SequencerSender Run // + Sequence::baseNoteNumber = baseNoteNumber; sequenceSender.setBpm(bpm); + for (int i = 0; i < SEQUENCE_N; i++) { Sequence& seq = sequenceSender.getSequences()[i]; - seq.setPitch(i); - seq.setOctave(-1); - seq.tie = true; + seq.setPitch(pitch[i]); + seq.setOctave(octave[i]); + seq.noteOn = noteOn[i]; + seq.tie = tie[i]; } - - sequence[3].setOctave(0); - sequence[7].setOctave(0); - sequence[11].setOctave(0); - sequence[15].setOctave(0); envelopeGenerator.init(envelope); sequenceSender.attachUpdate(&callbackFunction); - sequenceSender.setWaveShape(SpiSequenceSender::WAVESHAPE_SAW); + sequenceSender.setWaveShape(waveShape); sequenceSender.run(0); for (;;) { @@ -88,7 +98,7 @@ filterController.setCutoff(cutoffIn * 255); filterController.setResonance(resonanceIn * 255); - /* + #if(UART_TRACE) printf("%d\t%d\t%d\t%d\t%d\t%d\r\n", filterController.getCutoff(), filterController.getResonance(), @@ -97,6 +107,6 @@ envelope.getDecay(), envelope.getSustain() ); - */ + #endif } }