Commit 1d19907a authored by Jacob Vosmaer's avatar Jacob Vosmaer

Move clock update logic to crowbx.c

parent ba4749c8
......@@ -8,6 +8,7 @@
#include "poly.h"
#include "poly2.h"
#include "mono.h"
#include "vibrato.h"
enum _programs {
PGM_POLY,
......@@ -81,9 +82,27 @@ program_change(uint8_t pgm)
}
current_program = pgm;
vibrato_init();
gate_init();
(*pgm_init[current_program])();
}
void
do_clock_update(void)
{
static uint8_t prev_clock = 0;
uint8_t clock = TCNT0;
uint8_t delta = clock - prev_clock;
vibrato_update(delta);
gate_update(delta);
(*update_clock[current_program])(delta);
prev_clock = clock;
}
int
main(void)
{
......@@ -93,12 +112,9 @@ main(void)
clock_init();
program_change(PGM_POLY);
uint8_t prev_clock = 0;
for (;;) {
uint8_t clock = TCNT0;
(*update_clock[current_program])(clock - prev_clock);
prev_clock = clock;
do_clock_update();
uint8_t status, data1, data2;
if (midi_read(&status, &data1, &data2) != MIDI_READ_OK) {
......
......@@ -30,7 +30,6 @@ mono_init(void)
l_flush(notes);
detune_amount = 0;
current_bend = BEND_CENTER;
gate_init();
}
void
......@@ -119,7 +118,5 @@ mono_pitch_bend(uint16_t bend)
void
mono_update_clock(uint8_t delta)
{
vibrato_update(delta);
mono_set_pitch();
gate_update(delta);
}
......@@ -13,7 +13,6 @@ static uint16_t current_bend;
void
poly_init(void)
{
gate_init();
voice_init();
current_bend = BEND_CENTER;
for_each_voice(v) {
......@@ -78,9 +77,7 @@ poly_pitch_bend(uint16_t bend)
void
poly_update_clock(uint8_t delta)
{
vibrato_update(delta);
for_each_voice(v) {
poly_set_pitch(v, notes[v]);
}
gate_update(delta);
}
......@@ -26,7 +26,6 @@ poly2_init(void)
}
current_bend = BEND_CENTER;
gate_init();
}
void
......@@ -127,9 +126,7 @@ poly2_pitch_bend(uint16_t bend)
void
poly2_update_clock(uint8_t delta)
{
vibrato_update(delta);
for_each_voice(v) {
poly2_set_pitch(v, playing[v]);
}
gate_update(delta);
}
......@@ -18,6 +18,12 @@ vibrato_set_depth(uint8_t val)
depth = val;
}
void
vibrato_init(void)
{
vibrato_set_depth(0);
}
int16_t
vibrato_detune(void)
{
......
......@@ -4,6 +4,7 @@
#include <stdint.h>
int16_t vibrato_detune(void);
void vibrato_init(void);
void vibrato_update(uint8_t delta);
void vibrato_set_rate(uint8_t val);
void vibrato_set_depth(uint8_t val);
......
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