103 lines
3.3 KiB
C++
103 lines
3.3 KiB
C++
/*
|
|
Peacock-8 VA polysynth
|
|
|
|
Copyright 2024 Gordon JC Pearce <gordonjcp@gjcp.net>
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
|
|
#include "ic1.hpp"
|
|
|
|
#include "ic29.hpp"
|
|
#include "peacock.hpp"
|
|
|
|
Assigner ic1;
|
|
|
|
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++) {
|
|
voicemap[i] = 0x80 + i;
|
|
keymap[i] = 0x3c | 0x80;
|
|
}
|
|
}
|
|
|
|
void Assigner::handleMidi(const MidiEvent *ev) {
|
|
//
|
|
uint8_t status = ev->data[0];
|
|
switch (status & 0xf0) {
|
|
case 0x80:
|
|
noteOff(ev->data[1]);
|
|
break;
|
|
case 0x90:
|
|
noteOn(ev->data[1]);
|
|
break;
|
|
case 0xb0:
|
|
break; // nothing to do here except in special cases where we don't expect the host to pass on controls
|
|
default:
|
|
d_debug("unhandled MIDI event, status %02x value %02x\n", ev->data[0], ev->data[1]);
|
|
break;
|
|
}
|
|
}
|
|
void Assigner::noteOff(uint8_t note) {
|
|
// Poly 1 note off
|
|
for (uint8_t i = 0; i < NUM_VOICES; i++) {
|
|
if (keymap[i] == note) {
|
|
uint8_t voice = voicemap[i]; // save the voice
|
|
memmove(voicemap + i, voicemap + i + 1, NUM_VOICES - i - 1);
|
|
memmove(keymap + i, keymap + i + 1, NUM_VOICES - i - 1);
|
|
voicemap[NUM_VOICES - 1] = voice;
|
|
keymap[NUM_VOICES - 1] = note | 0x80;
|
|
ic29.voiceOff(voice);
|
|
}
|
|
}
|
|
}
|
|
|
|
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) {
|
|
// note found, move it to the front of the queue
|
|
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;
|
|
ic29.voiceOn(voice, note);
|
|
return;
|
|
}
|
|
}
|
|
|
|
// note is not in the queue, assign a new voice
|
|
for (uint8_t i = 0; i < NUM_VOICES; i++) {
|
|
if (keymap[i] & 0x80) {
|
|
// voice is free
|
|
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;
|
|
ic29.voiceOn(voice, note);
|
|
return;
|
|
}
|
|
}
|
|
}
|