You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

42 lines
1.2 KiB

#include <cstdio>
#include "synth/voicemanager.h"
VoiceManager::VoiceManager() : serial(0) {
for(VoiceData& vd : voices) {
vd.channel = 0;
vd.serial = 0;
}
}
Voice * VoiceManager::get(channel_t channel) {
// Sort idle voices first, then by highest channel and lowest serial
std::sort(std::begin(voices), std::end(voices), [](VoiceData& a, VoiceData& b) {
return (a.voice.isIdle() && !b.voice.isIdle()) || a.channel > b.channel || a.serial < b.serial;
});
VoiceData& voiceData = voices[0];
voiceData.channel = channel;
voiceData.serial = serial++;
voiceData.voice.reset();
putchar('\n');
for(VoiceData& vd : voices) {
printf("channel=%d serial=%d idle=%d note=%d\n", vd.channel, vd.serial, vd.voice.isIdle(), vd.voice.note);
}
putchar('\n');
return &voiceData.voice;
}
Voice** VoiceManager::getChannelVoices(channel_t channel) {
static Voice* result[NUM_VOICES + 1];
Voice** voice = result;
for(VoiceData& voiceData : voices) {
if(voiceData.channel == channel && !voiceData.voice.isIdle()) {
*voice++ = &voiceData.voice;
}
}
*voice = NULL;
return result;
}