Commit c6e35000 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Invert semantics of unison stacking

parent 3c42989b
......@@ -353,21 +353,13 @@ struct {
struct list held_notes;
const float detune_factor[MAX_VOICES];
uint8_t detune_amount;
uint8_t stacked_voices;
uint8_t disabled_voices;
} mono = {
.held_notes = {.array = mono.held_notes_array,
.sup = ARRAY_SIZE(mono.held_notes_array)},
.detune_factor = {1.2, -1.2, 0.6, -0.6, 0.9, -0.9, 0.3, -0.3},
};
uint8_t mono_active_voices(void) {
if (mono.stacked_voices && mono.stacked_voices < NUM_VOICES) {
return mono.stacked_voices;
} else {
return NUM_VOICES;
}
}
void mono_init(void) { l_flush(&mono.held_notes); }
void mono_set_pitch(void) {
......@@ -376,7 +368,7 @@ void mono_set_pitch(void) {
}
uint8_t current_note = l_last(&mono.held_notes);
for (uint8_t v = 0; v < mono_active_voices(); v++) {
for_each_voice (v) {
int16_t detune = mono.detune_factor[v] * mono.detune_amount;
pitch_set_note(v, current_note, detune);
}
......@@ -391,7 +383,7 @@ void mono_note_on(uint8_t n) {
mono_set_pitch();
for (uint8_t v = 0; v < mono_active_voices(); v++) {
for (uint8_t v = mono.disabled_voices; v < NUM_VOICES; v++) {
gate_on(v);
}
}
......@@ -410,7 +402,7 @@ void mono_note_off(uint8_t n) {
mono_set_pitch();
void (*f)(uint8_t) = l_empty(&mono.held_notes) ? gate_off : gate_on;
for (uint8_t v = 0; v < mono_active_voices(); v++) {
for (uint8_t v = mono.disabled_voices; v < NUM_VOICES; v++) {
f(v);
}
}
......@@ -420,11 +412,17 @@ void mono_control_change(uint8_t ctl, uint8_t val) {
case CC_DETUNE:
mono.detune_amount = val;
break;
case CC_STACKED_VOICES:
mono.stacked_voices = val;
for (uint8_t v = mono_active_voices(); v < NUM_VOICES; v++) {
case CC_MONO_DISABLED_VOICES:
if (val >= NUM_VOICES) {
val = NUM_VOICES - 1;
}
mono.disabled_voices = val;
for (uint8_t v = 0; v < mono.disabled_voices; v++) {
gate_off(v);
}
for (uint8_t v = mono.disabled_voices; v < NUM_VOICES; v++) {
gate_on_legato(v);
}
break;
}
}
......
......@@ -18,7 +18,7 @@ enum _cc {
CC_DETUNE = 14,
CC_PITCH_ENV_DECAY = 15,
CC_PITCH_ENV_AMOUNT = 16,
CC_STACKED_VOICES = 17,
CC_MONO_DISABLED_VOICES = 17,
CC_VIB_RATE = 76,
};
......
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