assigner shunts new notes to the front
This commit is contained in:
parent
e217354146
commit
454051d10c
@ -20,6 +20,14 @@
|
||||
|
||||
#include "peacock.hpp"
|
||||
|
||||
void Assigner::printMap() {
|
||||
printf("note memory:\n");
|
||||
for (uint8_t i = 0; i < NUM_VOICES; i++) printf("%02x ", voicemap[i]);
|
||||
printf("\n");
|
||||
for (uint8_t i = 0; i < NUM_VOICES; i++) printf("%02x ", keymap[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
Assigner::Assigner() {
|
||||
// set up the assigner
|
||||
for (uint8_t i = 0; i < NUM_VOICES; i++) {
|
||||
@ -56,22 +64,22 @@ void Assigner::noteOff(uint8_t note) {
|
||||
keymap[NUM_VOICES - 1] = note | 0x80;
|
||||
}
|
||||
}
|
||||
/*
|
||||
printf("note memory:\n");
|
||||
for (uint8_t i = 0; i < NUM_VOICES; i++) printf("%02x ", voicemap[i]);
|
||||
printf("\n");
|
||||
for (uint8_t i = 0; i < NUM_VOICES; i++) printf("%02x ", keymap[i]);
|
||||
printf("\n");
|
||||
*/
|
||||
printMap();
|
||||
}
|
||||
|
||||
void Assigner::noteOn(uint8_t note) {
|
||||
// Poly 1 assigner
|
||||
|
||||
// scan for the same note
|
||||
for (uint8_t i = 0; i < NUM_VOICES; i++) {
|
||||
if ((keymap[i] & 0x7f) == note) {
|
||||
keymap[i] &= 0x7f; // show note as on
|
||||
// note found, move it to the front of the queue
|
||||
d_debug("voice %02x on in slot %02x, existing note %02x", voicemap[i], i, keymap[i]);
|
||||
uint8_t voice = voicemap[i];
|
||||
memmove(voicemap + 1, voicemap, i);
|
||||
memmove(keymap + 1, keymap, i);
|
||||
keymap[0] = note; // show note as on
|
||||
voicemap[0] = voice;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -80,12 +88,16 @@ void Assigner::noteOn(uint8_t note) {
|
||||
for (uint8_t i = 0; i < NUM_VOICES; i++) {
|
||||
if (keymap[i] & 0x80) {
|
||||
// voice is free
|
||||
keymap[i] = note;
|
||||
d_debug("voice %02x on in slot %02x, setting note %02x", voicemap[i], i, keymap[i]);
|
||||
d_debug("voice %02x on in slot %02x, setting note %02x", voicemap[i], i, note);
|
||||
|
||||
uint8_t voice = voicemap[i];
|
||||
memmove(voicemap + 1, voicemap, i);
|
||||
memmove(keymap + 1, keymap, i);
|
||||
keymap[0] = note; // show note as on
|
||||
voicemap[0] = voice;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
d_debug("unable to allocate a voice for note %02x\n", note);
|
||||
|
||||
d_debug("unable to allocate a voice for note %02x\n", note);
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ class Assigner {
|
||||
private:
|
||||
void noteOn(uint8_t note);
|
||||
void noteOff(uint8_t note);
|
||||
void printMap();
|
||||
|
||||
uint8_t keymap[NUM_VOICES];
|
||||
uint8_t voicemap[NUM_VOICES];
|
||||
|
Loading…
Reference in New Issue
Block a user