forked from klang-modular/synthapp
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.
41 lines
1.2 KiB
41 lines
1.2 KiB
#include <iostream>
|
|
|
|
#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();
|
|
|
|
for(VoiceData& vd : voices) {
|
|
std::cout << "channel=" << vd.channel << " serial=" << vd.serial << " idle=" << vd.voice.isIdle() << " note=" << vd.voice.note << std::endl;
|
|
}
|
|
std::cout << std::endl;
|
|
|
|
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;
|
|
} |