Commit 5cc1110b by Jacob Vosmaer

Implement last note priority

parent df0624e0
......@@ -4,40 +4,80 @@
#include "voice.h"
uint8_t current_note;
#define NO_NOTE 255;
#define NUM_NOTES 128
uint8_t notes[NUM_NOTES];
uint8_t playing_note;
void set_pitch(uint8_t n);
void
mono_init(void)
{
current_note = NO_NOTE;
playing_note = NUM_NOTES;
}
void
push_note(uint8_t n)
{
notes[n] = playing_note;
playing_note = n;
}
void
mono_note_on(uint8_t note)
mono_note_on(uint8_t n)
{
if (note > 127) {
if (n >= NUM_NOTES) {
return;
}
current_note = note;
push_note(n);
set_pitch(n);
for (uint8_t v = 0; v < NUM_VOICES; v++) {
dac_set_note(v, note);
gate_on(v);
}
}
void
mono_note_off(uint8_t note)
drop_note(uint8_t n)
{
if (note > 127) {
if (playing_note == n) {
playing_note = notes[playing_note];
return;
}
if (current_note != note) {
return;
for (uint8_t i = playing_note; notes[i] != NUM_NOTES; i = notes[i]) {
if (notes[i] == n) {
notes[i] = notes[n];
return;
}
}
}
void
set_pitch(uint8_t n)
{
for (uint8_t v = 0; v < NUM_VOICES; v++) {
gate_off(v);
dac_set_note(v, n);
}
}
void
mono_note_off(uint8_t n)
{
if (n >= NUM_NOTES) {
return;
}
drop_note(n);
if (playing_note == NUM_NOTES) {
for (uint8_t v = 0; v < NUM_VOICES; v++) {
gate_off(v);
}
return;
}
set_pitch(playing_note);
}
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