Commit 5f59e634 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Inline poly1 voice stealing

parent c6e35000
......@@ -234,23 +234,6 @@ struct {
.sup = ARRAY_SIZE(poly.in_use_array)},
};
uint8_t poly_acquire(void) {
if (l_empty(&poly.avail)) {
l_pushl(&poly.avail, l_popr(&poly.in_use));
}
uint8_t v = l_popr(&poly.avail);
l_pushl(&poly.in_use, v);
return v;
}
void poly_release(uint8_t v) {
if (l_contains(&poly.in_use, v)) {
l_delete(&poly.in_use, v);
l_pushl(&poly.avail, v);
}
}
void poly_init(void) {
l_flush(&poly.in_use);
l_flush(&poly.avail);
......@@ -265,11 +248,14 @@ void poly_note_on(uint8_t key) {
return;
}
uint8_t v = poly_acquire();
if (v >= NUM_VOICES) {
return;
uint8_t v;
if (!l_empty(&poly.avail)) {
v = l_popr(&poly.avail);
} else {
v = l_popr(&poly.in_use);
}
l_pushl(&poly.in_use, v);
pitch_set_note(v, key, 0);
gate_on(v);
poly.current_note[v] = key;
......@@ -283,7 +269,8 @@ void poly_note_off(uint8_t key) {
for_each_voice (v) {
if (poly.current_note[v] == key) {
poly.current_note[v] = NUM_NOTES;
poly_release(v);
l_delete(&poly.in_use, v);
l_pushl(&poly.avail, v);
gate_off(v);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment