class MyVoice
{
SqrOsc s => LPF f => ADSR adsr => dac;
fun void setFreq(float freq) { freq => s.freq; }
fun void noteOn() { 1 => adsr.keyOn; }
fun void noteOff() { 1 => adsr.keyOff; }
}
class Poly
{
MyVoice voices[10];
MyVoice @ voiceForNote[127];
0 => int voiceIndex;
fun MyVoice allocateVoiceForNote(int note)
{
voices[voiceIndex] @=> MyVoice v;
v @=> voiceForNote[note];
(voiceIndex+1)%voices.size() => voiceIndex;
return v;
}
fun MyVoice getVoiceForNote(int note)
{
return voiceForNote[note];
}
fun void returnVoiceForNote(int note)
{
null @=> voiceForNote[note];
}
}