Parallel sequencers work but go out of sync very quickly
parent
9ce26424a9
commit
b5b4c3bdd3
|
@ -5,9 +5,13 @@
|
|||
Adafruit_MCP4728 mcp;
|
||||
|
||||
|
||||
float tuning[13];
|
||||
int m1[] = { 0, 5, 5, 7, 5, 4, 2, 2, 2, 7, 7, 9, 7, 5, 4, 0, 4, 9, 9, 10, 9, 7, 5, 2, 0, 0, 2, 7, 4, 5, 0, 5, 5, 5, 4, 4, 5, 4, 2, 0, 7, 9, 7, 7, 5, 5, 12, 0, 0, 0, 2, 7, 4, 5 };
|
||||
float tuning[16];
|
||||
// 0 = A, 8 = F (tonic)
|
||||
|
||||
int m1[] = { 3, 8, 8, 10, 8, 7, 5, 5, 5, 10, 10, 12, 10, 8, 7, 3, 7, 12, 12, 13, 12, 10, 8, 5, 3, 3, 5, 10, 7, 8, 3, 8, 8, 8, 7, 7, 8, 7, 5, 3, 10, 12, 10, 10, 8, 8, 15, 3, 3, 3, 5, 10, 7, 8 };
|
||||
float d1[] = { 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 2, 2, 2, 4, 2, 2, 2, 2, 4, 2, 2, 2, 2, 4, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 2, 2, 2, 4 };
|
||||
int m2[] = { -1, 8, 1, 2, 3, 4, 5, 0, 1, 3, 8, 8, 3, 5, 7, 8, 7, 0, 1, 3, 8 };
|
||||
float d2[] = { 2, 6, 6, 6, 6, 6, 4, 2, 4, 2, 6, 6, 6, 6, 6, 6, 4, 2, 4, 2, 4 };
|
||||
float gate = 0.5;
|
||||
int bpm = 240;
|
||||
float beat_s = 60.0 / (float)bpm;
|
||||
|
@ -49,7 +53,7 @@ void setup(void) {
|
|||
mcp.setChannelValue(MCP4728_CHANNEL_B, 0);
|
||||
|
||||
float n0 = 0;
|
||||
for( int i = 0; i < 13; i++ ) {
|
||||
for( int i = 0; i < 16; i++ ) {
|
||||
tuning[i] = round(n0 + octave * (float)i / 12.0);
|
||||
}
|
||||
long now = millis();
|
||||
|
@ -59,12 +63,13 @@ void setup(void) {
|
|||
seq1.melody = m1;
|
||||
seq1.duration = d1;
|
||||
seq1.len = sizeof(m1) / sizeof(m1[0]);
|
||||
Serial.println("length of seq 1 pattern");
|
||||
Serial.println(seq1.len);
|
||||
|
||||
// seq2.last = now;
|
||||
// seq2.pitch = MCP4728_CHANNEL_C;
|
||||
// seq2.gate = MCP4728_CHANNEL_D;
|
||||
seq2.last = now;
|
||||
seq2.pitch = MCP4728_CHANNEL_C;
|
||||
seq2.gate = MCP4728_CHANNEL_D;
|
||||
seq2.melody = m2;
|
||||
seq2.duration = d2;
|
||||
seq2.len = sizeof(m2) / sizeof(m2[0]);
|
||||
|
||||
}
|
||||
|
||||
|
@ -72,12 +77,12 @@ void setup(void) {
|
|||
void loop() {
|
||||
long now = millis();
|
||||
runSequencer(seq1, now);
|
||||
runSequencer(seq2, now);
|
||||
}
|
||||
|
||||
void runSequencer(sequencer& seq, long now) {
|
||||
if( seq.noteOn ) {
|
||||
if( now - seq.last > seq.rel ) {
|
||||
Serial.println("noteOff");
|
||||
noteOff(seq);
|
||||
seq.last = now;
|
||||
seq.play = round(beat_m * seq.duration[seq.s] * (1.0 - gate));
|
||||
|
@ -89,7 +94,6 @@ void runSequencer(sequencer& seq, long now) {
|
|||
}
|
||||
} else {
|
||||
if( now - seq.last > seq.play ) {
|
||||
Serial.println("noteOn");
|
||||
noteOn(seq, seq.melody[seq.s]);
|
||||
seq.last = now;
|
||||
seq.rel = round(beat_m * seq.duration[seq.s] * gate);
|
||||
|
|
Loading…
Reference in New Issue