home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / libkmid / voiceman.h < prev   
Encoding:
C/C++ Source or Header  |  2007-10-08  |  4.3 KB  |  173 lines

  1. /*  voiceman.h - The VoiceManager class handles a set of voices for synths
  2.     This file is part of LibKMid 0.9.5
  3.     Copyright (C) 1997,98,99,2000  Antonio Larrosa Jimenez
  4.     LibKMid's homepage : http://www.arrakis.es/~rlarrosa/libkmid.html
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.  
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU Library General Public License
  17.     along with this library; see the file COPYING.LIB.  If not, write to
  18.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19.     Boston, MA 02110-1301, USA.                                                  
  20.  
  21.     Send comments and bug fixes to Antonio Larrosa <larrosa@kde.org>
  22.  
  23. ***************************************************************************/
  24. #ifndef _VOICEMAN_H
  25. #define _VOICEMAN_H
  26.  
  27. /**
  28.  * @internal
  29.  * Manages the voices used by synthesizers.
  30.  *
  31.  * @short Manages internally the voices used by synth devices.
  32.  * @version 0.9.5 17/01/2000
  33.  * @author Antonio Larrosa Jimenez <larrosa@kde.org>
  34.  */ 
  35. class VoiceManager
  36. {
  37.   private:
  38.     class VoiceManagerPrivate;
  39.     VoiceManagerPrivate *d;
  40.  
  41.     /**
  42.      * Number of voices managed by this object.
  43.      */
  44.     int nvoices;
  45.  
  46.     /**
  47.      * @internal
  48.      */
  49.     struct voice
  50.     {
  51.       int     id;
  52.       int    channel;
  53.       int    note;
  54.       int    used;
  55.  
  56.       struct voice *prev;
  57.       struct voice *next;
  58.     };
  59.  
  60.     /**
  61.      * Points to the beginning of the voice list, that is, to
  62.      * the older voice which is ready to be used.
  63.      */
  64.     voice *FirstVoice; 
  65.  
  66.     /**
  67.      * Points to the last voice, that is, the latest (most recently) used voice.
  68.      */
  69.     voice *LastVoice; 
  70.  
  71.     /**
  72.      * Points to the latest (list order) not used voice,
  73.      * that is, to where deallocated voices will be moved.
  74.      */
  75.     voice *LastnotusedVoice; 
  76.  
  77.     /**
  78.      * Array with pointers to the voices, arranged by ID for allow faster searches.
  79.      */
  80.     voice **VoiceList; 
  81.  
  82.     /**
  83.      * @internal
  84.      * This variable is used to search channels.
  85.      */
  86.     voice *searcher; 
  87.  
  88.     /**
  89.      * @internal
  90.      * An auxiliary variable for simpler searches.
  91.      */ 
  92.     voice *searcher_aid; 
  93.  
  94.   public:
  95.     /**
  96.      * Cronstructor.
  97.      */
  98.     VoiceManager(int totalvoices);
  99.  
  100.     /**
  101.      * Destructor.
  102.      */
  103.     ~VoiceManager();
  104.  
  105.     /**
  106.      * Allocates a voice used in channel @p chn, and playing key @p key
  107.      * @return the voice that should be used.
  108.      *
  109.      * @see deallocateVoice
  110.      */
  111.  
  112.     int allocateVoice(int chn,int key);
  113.  
  114.     /**
  115.      * Deallocates the voice with ID @p id.
  116.      *
  117.      * @see allocateVoice
  118.      */ 
  119.     void deallocateVoice(int id);
  120.  
  121.     /**
  122.      * initSearch() must be called always before search() to initialize
  123.      * internal variables.
  124.      * 
  125.      * @see search
  126.      */
  127.     void initSearch(void); 
  128.  
  129.     /**
  130.      * Returns -1 if channel chn is not currently used, or a voice using
  131.      * channel @p chn if any.
  132.      *
  133.      * Calling search repeteadly, will return all the voices using channel 
  134.      * @p chn, and a -1 after the last one.
  135.      *
  136.      * @see initSearch
  137.      */
  138.     int search(int chn); 
  139.     //returns -1 if channel chn is not currently used
  140.     // Continue searching for more voices which
  141.     // use the channel chn
  142.  
  143.     /**
  144.      * This is a convenience function that differs from the above in that it also
  145.      * looks for a specific note (the second parameter)
  146.      * 
  147.      * @see initSearch
  148.      */
  149.     int search(int chn,int note);
  150.  
  151.     /**
  152.      * Returns the channel that voice @p v is using.
  153.      */
  154.     int channel(int v) {return VoiceList[v]->channel;}
  155.  
  156.     /**
  157.      * Returns the note that voice @p v is playing.
  158.      */
  159.     int note(int v) {return VoiceList[v]->note;}
  160.  
  161.     /**
  162.      * Returns true or false if the voice @p v is being used or not respectively.
  163.      */
  164.     int used(int v) {return VoiceList[v]->used;}
  165.  
  166.     /**
  167.      * Clears the lists of used voices.
  168.      */
  169.     void clearLists(void);
  170. };
  171.  
  172. #endif
  173.