Commit a3fd3de9 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Inline code and remove repetition

parent 46c6fd9c
......@@ -14,8 +14,6 @@ INIT_LIST(notes, NUM_NOTES);
static uint16_t current_bend;
static uint8_t current_note;
void mono_set_pitch(void);
const float detune_factor[NUM_VOICES] = {
1.2,
-1.2,
......@@ -28,7 +26,6 @@ void
mono_init(void)
{
l_flush(notes);
detune_amount = 0;
current_bend = BEND_CENTER;
}
......@@ -40,27 +37,12 @@ mono_note_on(uint8_t n)
}
l_push(notes, n);
mono_set_pitch();
for_each_voice (v) {
gate_on(v);
}
}
void
mono_set_pitch(void)
{
if (!l_empty(notes)) {
current_note = l_first(notes);
}
for_each_voice (v) {
int16_t detune = detune_factor[v] * detune_amount;
detune += vibrato_detune();
pitch_set_note(v, current_note, detune, current_bend);
}
}
void
mono_note_off(uint8_t n)
{
......@@ -71,23 +53,24 @@ mono_note_off(uint8_t n)
l_delete(notes, n);
if (l_first(notes) == current_note) {
// prevent accidental retrigger
// The note-off we received is for another note than the
// currently playing one. Return now to avoid affecting its
// envelope.
return;
}
if (l_empty(notes)) {
// No key is being pressed, so turn off the gates.
for_each_voice (v) {
gate_off(v);
}
return;
}
// Re-trigger previously playing note
for_each_voice (v) {
gate_on(v);
} else {
// A key is still being pressed. Reset the envelope so that
// note will play now.
for_each_voice (v) {
gate_on(v);
}
}
mono_set_pitch();
}
void
......@@ -96,7 +79,6 @@ mono_control_change(uint8_t ctl, uint8_t val)
switch (ctl) {
case CC_DETUNE:
detune_amount = val;
mono_set_pitch();
break;
case CC_MOD_WHEEL:
vibrato_set_depth(val);
......@@ -116,7 +98,15 @@ mono_pitch_bend(uint16_t bend)
void
mono_update_clock(uint8_t delta)
{
(void)delta;
(void)delta; // unused
mono_set_pitch();
if (!l_empty(notes)) {
current_note = l_first(notes);
}
for_each_voice (v) {
int16_t detune = detune_factor[v] * detune_amount;
detune += vibrato_detune();
pitch_set_note(v, current_note, detune, current_bend);
}
}
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