void VoiceHandler::setPolyphony(size_t polyphony) { while (all_voices_.size() < polyphony) { Voice* new_voice = createVoice(); all_voices_.insert(new_voice); free_voices_.push_back(new_voice); } while (active_voices_.size() > polyphony) { active_voices_.front()->deactivate(); active_voices_.pop_front(); } polyphony_ = polyphony; }
void VoiceHandler::setPolyphony(size_t polyphony) { while (all_voices_.size() < polyphony) { Voice* new_voice = createVoice(); all_voices_.push_back(new_voice); active_voices_.push_back(new_voice); } int num_voices_to_kill = active_voices_.size() - polyphony; for (int i = 0; i < num_voices_to_kill; ++i) { Voice* sacrifice = getVoiceToKill(); if (sacrifice) sacrifice->kill(); } polyphony_ = polyphony; }