• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libtdemid
 

libtdemid

  • libtdemid
voiceman.cpp
1 /**************************************************************************
2 
3  voiceman.cpp - The VoiceManager class handles a set of voices for synths
4  This file is part of LibKMid 0.9.5
5  Copyright (C) 1997,98,99,2000 Antonio Larrosa Jimenez
6  LibKMid's homepage : http://www.arrakis.es/~rlarrosa/libtdemid.html
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 
23  Send comments and bug fixes to Antonio Larrosa <larrosa@kde.org>
24 
25 ***************************************************************************/
26 
27 #include "voiceman.h"
28 #include <stdio.h>
29 #ifdef HAVE_CONFIG_H
30 #include <config.h>
31 #endif
32 
33 VoiceManager::VoiceManager(int totalvoices)
34 {
35  nvoices=totalvoices;
36 
37  FirstVoice=new voice;
38  FirstVoice->id=0;
39  FirstVoice->channel=0;
40  FirstVoice->note=0;
41  FirstVoice->used=0;
42  FirstVoice->prev=NULL;
43 
44  voice *ptrb=FirstVoice;
45  voice *ptr=NULL;
46  int i;
47  for (i=1;i<nvoices;i++)
48  {
49  ptr=new voice;
50  ptrb->next=ptr;
51  ptr->id=i;
52  ptr->channel=0;
53  ptr->note=0;
54  ptr->used=0;
55  ptr->prev=ptrb;
56  ptrb=ptr;
57  }
58  LastVoice=ptr;
59  LastVoice->next=NULL;
60  LastnotusedVoice=LastVoice;
61 
62  VoiceList=new voice *[nvoices];
63  ptr=FirstVoice;
64  for (i=0;i<nvoices;i++)
65  {
66  VoiceList[i]=ptr;
67  ptr=ptr->next;
68  }
69  searcher_aid=new voice;
70 }
71 
72 VoiceManager::~VoiceManager()
73 {
74  voice *ptr=FirstVoice;
75  voice *ptr2;
76  while (ptr!=NULL)
77  {
78  ptr2=ptr->next;
79  delete ptr;
80  ptr=ptr2;
81  }
82  FirstVoice=NULL;
83  LastVoice=NULL;
84  LastnotusedVoice=NULL;
85 
86  delete [] VoiceList;
87  VoiceList=NULL;
88 
89  delete searcher_aid;
90 }
91 
92 void VoiceManager::clearLists(void)
93 {
94 #ifdef VOICEMANDEBUG
95  printf("voicemanager::cleanLists\n");
96 #endif
97  voice *ptr=FirstVoice;
98  voice *ptr2=FirstVoice;
99  while (ptr!=NULL)
100  {
101  ptr->used=0;
102  ptr2=ptr;
103  ptr=ptr->next;
104  }
105  LastVoice=ptr2;
106  LastnotusedVoice=ptr2;
107 
108 }
109 
110 int VoiceManager::allocateVoice(int chn,int key)
111 {
112  // First, we take the allocated voice out of the first place of the list
113  if ((LastnotusedVoice!=NULL)&&(LastnotusedVoice->id==FirstVoice->id))
114  {
115 #ifdef VOICEMANDEBUG
116  printf("Used last voice !\n");
117 #endif
118  LastnotusedVoice=NULL;
119  }
120  voice *newvoice=FirstVoice;
121  FirstVoice=FirstVoice->next;
122  FirstVoice->prev=NULL;
123 
124 #ifdef VOICEMANDEBUG
125  printf("Allocating id :%d\n",newvoice->id);
126 #endif
127  // then we put the allocated voice at the end of the list
128  LastVoice->next=newvoice;
129  newvoice->prev=LastVoice;
130  LastVoice=newvoice;
131  LastVoice->next=NULL;
132 
133  newvoice->channel=chn;
134  newvoice->note=key;
135 
136 #ifdef VOICEMANDEBUG
137  if (newvoice->used==1)
138  {
139  printf("Replacing voice : %d\n",newvoice->id);
140  }
141 #endif
142  newvoice->used=1;
143 
144  //dispStat();
145  return newvoice->id;
146 }
147 
148 void VoiceManager::deallocateVoice(int id)
149 {
150  voice *delvoice=VoiceList[id];
151 #ifdef VOICEMANDEBUG
152  printf("Deallocating id :%d\n",id);
153 #endif
154  if (delvoice->id==LastVoice->id)
155  {
156  LastVoice=delvoice->prev;
157  LastVoice->next=NULL;
158 
159  if (LastnotusedVoice==NULL)
160  {
161  delvoice->next=FirstVoice;
162  FirstVoice->prev=delvoice;
163  FirstVoice=delvoice;
164  FirstVoice->prev=NULL;
165  LastnotusedVoice=FirstVoice;
166  }
167  else
168  {
169  if (LastnotusedVoice->next==NULL)
170  {
171  LastnotusedVoice->next=delvoice;
172  delvoice->prev=LastnotusedVoice;
173  delvoice->next=NULL;
174  LastnotusedVoice=delvoice;
175  LastVoice=delvoice;
176  }
177  else
178  {
179  delvoice->next=LastnotusedVoice->next;
180  delvoice->next->prev=delvoice;
181  delvoice->prev=LastnotusedVoice;
182  LastnotusedVoice->next=delvoice;
183  LastnotusedVoice=delvoice;
184  }
185  }
186  }
187  else
188  {
189  if (delvoice->prev!=NULL)
190  {
191  delvoice->prev->next=delvoice->next;
192  delvoice->next->prev=delvoice->prev;
193  if (LastnotusedVoice==NULL)
194  {
195  delvoice->next=FirstVoice;
196  FirstVoice->prev=delvoice;
197  FirstVoice=delvoice;
198  FirstVoice->prev=NULL;
199  LastnotusedVoice=FirstVoice; }
200  else
201  {
202  if (LastnotusedVoice->next==NULL)
203  {
204  LastnotusedVoice->next=delvoice;
205  delvoice->prev=LastnotusedVoice;
206  delvoice->next=NULL;
207  LastnotusedVoice=delvoice;
208  LastVoice=delvoice;
209  }
210  else
211  {
212  delvoice->next=LastnotusedVoice->next;
213  delvoice->next->prev=delvoice;
214  delvoice->prev=LastnotusedVoice;
215  LastnotusedVoice->next=delvoice;
216  LastnotusedVoice=delvoice;
217  }
218  }
219  }
220  }
221  delvoice->used=0;
222 
223  // dispStat();
224 }
225 
226 void VoiceManager::initSearch(void)
227 {
228  searcher=searcher_aid;
229  searcher_aid->prev=LastVoice;
230 }
231 
232 int VoiceManager::search(int chn)
233 {
234  if (searcher==NULL) return -1;
235  searcher=searcher->prev;
236 
237  while (searcher!=NULL)
238  {
239  if (searcher->used==0) return -1;
240  if (searcher->channel==chn)
241  {
242  return searcher->id;
243  }
244  searcher=searcher->prev;
245  }
246  return -1;
247 }
248 
249 int VoiceManager::search(int chn,int note)
250 {
251  if (searcher==NULL) return -1;
252  searcher=searcher->prev;
253  while ((searcher!=NULL))
254  {
255  if (searcher->used==0) return -1;
256  if ((searcher->channel==chn)&&(searcher->note==note))
257  {
258  return searcher->id;
259  }
260  searcher=searcher->prev;
261  }
262  return -1;
263 }
264 
265 /*
266 void VoiceManager::dispStat(void)
267 {
268 #ifdef VOICEMANDEBUG
269  printf("Stats\n");
270  voice *ptr=FirstVoice;
271  while (ptr!=NULL)
272  {
273  printf("Voice %d is %s\n",ptr->id,(ptr->used==0)?("off"):("on"));
274  ptr=ptr->next;
275  }
276  if (LastnotusedVoice!=NULL) printf("LnuV = %d\n",LastnotusedVoice->id);
277 #endif
278 }
279 */

libtdemid

Skip menu "libtdemid"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libtdemid

Skip menu "libtdemid"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for libtdemid by doxygen 1.8.8
This website is maintained by Timothy Pearson.