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