33VoiceManager::VoiceManager(
int totalvoices)
39 FirstVoice->channel=0;
42 FirstVoice->prev=
nullptr;
44 voice *ptrb=FirstVoice;
47 for (i=1;i<nvoices;i++)
59 LastVoice->next=
nullptr;
60 LastnotusedVoice=LastVoice;
62 VoiceList=
new voice *[nvoices];
64 for (i=0;i<nvoices;i++)
69 searcher_aid=
new voice;
72VoiceManager::~VoiceManager()
74 voice *ptr=FirstVoice;
84 LastnotusedVoice=
nullptr;
92void VoiceManager::clearLists(
void)
95 printf(
"voicemanager::cleanLists\n");
97 voice *ptr=FirstVoice;
98 voice *ptr2=FirstVoice;
106 LastnotusedVoice=ptr2;
110int VoiceManager::allocateVoice(
int chn,
int key)
113 if (LastnotusedVoice && LastnotusedVoice->id == FirstVoice->id)
116 printf(
"Used last voice !\n");
118 LastnotusedVoice=
nullptr;
120 voice *newvoice=FirstVoice;
121 FirstVoice=FirstVoice->next;
122 FirstVoice->prev=
nullptr;
125 printf(
"Allocating id :%d\n",newvoice->id);
128 LastVoice->next=newvoice;
129 newvoice->prev=LastVoice;
131 LastVoice->next=
nullptr;
133 newvoice->channel=chn;
137 if (newvoice->used==1)
139 printf(
"Replacing voice : %d\n",newvoice->id);
148void VoiceManager::deallocateVoice(
int id)
150 voice *delvoice=VoiceList[id];
152 printf(
"Deallocating id :%d\n",
id);
154 if (delvoice->id==LastVoice->id)
156 LastVoice=delvoice->prev;
157 LastVoice->next=
nullptr;
159 if (!LastnotusedVoice)
161 delvoice->next=FirstVoice;
162 FirstVoice->prev=delvoice;
164 FirstVoice->prev=
nullptr;
165 LastnotusedVoice=FirstVoice;
169 if (!LastnotusedVoice->next)
171 LastnotusedVoice->next=delvoice;
172 delvoice->prev=LastnotusedVoice;
173 delvoice->next=
nullptr;
174 LastnotusedVoice=delvoice;
179 delvoice->next=LastnotusedVoice->next;
180 delvoice->next->prev=delvoice;
181 delvoice->prev=LastnotusedVoice;
182 LastnotusedVoice->next=delvoice;
183 LastnotusedVoice=delvoice;
191 delvoice->prev->next=delvoice->next;
192 delvoice->next->prev=delvoice->prev;
193 if (!LastnotusedVoice)
195 delvoice->next=FirstVoice;
196 FirstVoice->prev=delvoice;
198 FirstVoice->prev=
nullptr;
199 LastnotusedVoice=FirstVoice; }
202 if (!LastnotusedVoice->next)
204 LastnotusedVoice->next=delvoice;
205 delvoice->prev=LastnotusedVoice;
206 delvoice->next=
nullptr;
207 LastnotusedVoice=delvoice;
212 delvoice->next=LastnotusedVoice->next;
213 delvoice->next->prev=delvoice;
214 delvoice->prev=LastnotusedVoice;
215 LastnotusedVoice->next=delvoice;
216 LastnotusedVoice=delvoice;
226void VoiceManager::initSearch(
void)
228 searcher=searcher_aid;
229 searcher_aid->prev=LastVoice;
232int VoiceManager::search(
int chn)
234 if (!searcher)
return -1;
235 searcher=searcher->prev;
239 if (searcher->used==0)
return -1;
240 if (searcher->channel==chn)
244 searcher=searcher->prev;
249int VoiceManager::search(
int chn,
int note)
251 if (!searcher)
return -1;
252 searcher=searcher->prev;
255 if (searcher->used==0)
return -1;
256 if ((searcher->channel==chn)&&(searcher->note==note))
260 searcher=searcher->prev;