Commit bb44c64f authored by Jacob Vosmaer's avatar Jacob Vosmaer

Move gate retrigger into gate.c

parent f68f0c42
......@@ -81,11 +81,6 @@ program_change(uint8_t pgm)
}
current_program = pgm;
for_each_voice(v) {
gate_off(v);
}
(*pgm_init[current_program])();
}
......
......@@ -2,10 +2,27 @@
#include "voice.h"
#include "gate.h"
static uint8_t _gate_retrig[NUM_VOICES];
enum {
// RETRIG_DELAY should be as low as possible to reduce MIDI latency, but
// high enough to allow the hardware envelope generators in the CrowBX to
// reset. I know 0x3f to be too low.
RETRIG_DELAY = 0x5f,
};
void
gate_init(void)
{
for_each_voice(v) {
gate_off(v);
}
}
void
gate_on_legato(uint8_t v)
{
if (v > NUM_VOICES) {
if (v >= NUM_VOICES) {
return;
}
......@@ -15,9 +32,39 @@ gate_on_legato(uint8_t v)
void
gate_off(uint8_t v)
{
if (v > NUM_VOICES) {
if (v >= NUM_VOICES) {
return;
}
_gate_retrig[v] = 0;
PORTC &= ~_BV(v);
}
void
gate_on(uint8_t v)
{
if (v >= NUM_VOICES) {
return;
}
gate_off(v);
_gate_retrig[v] = RETRIG_DELAY;
}
void
gate_update(uint8_t delta)
{
for_each_voice(v) {
if (_gate_retrig[v] == 0) {
continue;
}
if (delta < _gate_retrig[v]) {
_gate_retrig[v] -= delta;
continue;
}
_gate_retrig[v] = 0;
gate_on_legato(v);
}
}
......@@ -3,7 +3,10 @@
#include <stdint.h>
void gate_init(void);
void gate_on(uint8_t voice);
void gate_on_legato(uint8_t voice);
void gate_off(uint8_t voice);
void gate_update(uint8_t delta);
#endif
......@@ -14,15 +14,6 @@ INIT_LIST(notes, NUM_NOTES);
static uint16_t current_bend;
static uint8_t current_note;
enum {
// GATE_START should be as low as possible to reduce MIDI latency, but
// high enough to allow the hardware envelope generators in the CrowBX to
// reset. I know 0x3f to be too low.
GATE_START = 0x5f,
};
static uint16_t gate_countdown;
void mono_set_pitch(void);
const float detune_factor[NUM_VOICES] = {
......@@ -39,6 +30,7 @@ mono_init(void)
l_flush(notes);
detune_amount = 0;
current_bend = BEND_CENTER;
gate_init();
}
void
......@@ -51,9 +43,8 @@ mono_note_on(uint8_t n)
l_push(notes, n);
mono_set_pitch();
gate_countdown = GATE_START;
for_each_voice(v) {
gate_off(v);
gate_on(v);
}
}
......@@ -86,17 +77,18 @@ mono_note_off(uint8_t n)
return;
}
for_each_voice(v) {
gate_off(v);
}
if (l_empty(notes)) {
gate_countdown = 0;
for_each_voice(v) {
gate_off(v);
}
return;
}
// Re-trigger previously playing note
gate_countdown = GATE_START;
for_each_voice(v) {
gate_on(v);
}
mono_set_pitch();
}
......@@ -124,29 +116,10 @@ mono_pitch_bend(uint16_t bend)
mono_set_pitch();
}
void
mono_update_gate(uint8_t delta)
{
if (gate_countdown == 0) {
return;
}
if (delta < gate_countdown) {
gate_countdown -= delta;
return;
}
gate_countdown = 0;
for_each_voice(v) {
gate_on_legato(v);
}
}
void
mono_update_clock(uint8_t delta)
{
vibrato_update(delta);
mono_set_pitch();
mono_update_gate(delta);
gate_update(delta);
}
......@@ -12,6 +12,7 @@ static uint16_t current_bend;
void
poly_init(void)
{
gate_init();
voice_init();
current_bend = BEND_CENTER;
}
......@@ -76,4 +77,5 @@ poly_update_clock(uint8_t delta)
for_each_voice(v) {
poly_set_pitch(v, notes[v]);
}
gate_update(delta);
}
......@@ -26,6 +26,7 @@ poly2_init(void)
}
current_bend = BEND_CENTER;
gate_init();
}
void
......@@ -130,4 +131,5 @@ poly2_update_clock(uint8_t delta)
for_each_voice(v) {
poly2_set_pitch(v, playing[v]);
}
gate_update(delta);
}
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