Looping playback works with a basic two-part phrase
parent
71fd9e319a
commit
56fae7e54d
|
@ -62,7 +62,8 @@ float mod_b = 3.141592653589793 / 4.0;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int s = -1;
|
int s = -1;
|
||||||
int playing = 0;
|
bool playing = false;
|
||||||
|
bool looped = false;
|
||||||
long play = 0;
|
long play = 0;
|
||||||
long rel = 0;
|
long rel = 0;
|
||||||
long last = 0;
|
long last = 0;
|
||||||
|
@ -142,13 +143,33 @@ void loop() {
|
||||||
void runSequencer(sequencer& seq, long now, long beats) {
|
void runSequencer(sequencer& seq, long now, long beats) {
|
||||||
int next = seq.s + 1;
|
int next = seq.s + 1;
|
||||||
int start;
|
int start;
|
||||||
|
|
||||||
|
if( seq.playing ) {
|
||||||
|
if( now > seq.rel ) {
|
||||||
|
mcp.setChannelValue(seq.gate, 0);
|
||||||
|
seq.playing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if( next > seq.len - 1 ) {
|
if( next > seq.len - 1 ) {
|
||||||
seq.s = -1;
|
seq.s = -1;
|
||||||
next = 0;
|
seq.looped = true;
|
||||||
return; // don't start the loop yet
|
return; // don't start the loop yet
|
||||||
} else {
|
} else {
|
||||||
start = seq.start[next];
|
start = seq.start[next];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( seq.looped ) { // reached the end and waiting for the start of the bar
|
||||||
|
if( beats < seq.last ) {
|
||||||
|
seq.looped = false; // bar has restarted, start waiting
|
||||||
|
seq.s = -1;
|
||||||
|
next = 0;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
seq.last = beats;
|
||||||
|
|
||||||
if( beats >= start ) {
|
if( beats >= start ) {
|
||||||
seq.s = next;
|
seq.s = next;
|
||||||
seq.rel = now + seq.duration[seq.s];
|
seq.rel = now + seq.duration[seq.s];
|
||||||
|
@ -156,13 +177,7 @@ void runSequencer(sequencer& seq, long now, long beats) {
|
||||||
mcp.setChannelValue(seq.pitch, tuning[seq.melody[seq.s]]);
|
mcp.setChannelValue(seq.pitch, tuning[seq.melody[seq.s]]);
|
||||||
mcp.setChannelValue(seq.gate, 4095);
|
mcp.setChannelValue(seq.gate, 4095);
|
||||||
}
|
}
|
||||||
seq.playing = 1;
|
seq.playing = true;
|
||||||
}
|
|
||||||
if( seq.playing ) {
|
|
||||||
if( now > seq.rel ) {
|
|
||||||
mcp.setChannelValue(seq.gate, 0);
|
|
||||||
seq.playing = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue