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 / notearray.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-10-08  |  3.4 KB  |  146 lines

  1. /*  notearray.h  - NoteArray class, which holds an array of notes
  2.     This file is part of LibKMid 0.9.5
  3.     Copyright (C) 1998,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 NOTEARRAY_H
  25. #define NOTEARRAY_H
  26.  
  27. #include <libkmid/dattypes.h>
  28. #include <kdelibs_export.h>
  29.  
  30. /**
  31.  * Holds a resizeable array of note on/off and patch change events. It can
  32.  * increase it size, but it doesn't decreases (until destruction :-) )
  33.  *
  34.  * @short Stores an array of note on/off events
  35.  * @version 0.9.5 17/01/2000
  36.  * @author Antonio Larrosa Jimenez <larrosa@kde.org>
  37.  */
  38. class KMID_EXPORT NoteArray
  39. {
  40.   private:
  41.     class NoteArrayPrivate;
  42.     NoteArrayPrivate *d;
  43.  
  44.   public:
  45.   struct noteCmd {
  46.     /**
  47.      * ms from beginning of song 
  48.      */
  49.     ulong ms; 
  50.  
  51.     /**
  52.      * The channel
  53.      */
  54.     int chn;
  55.  
  56.     /**
  57.      * 0 note off, 1 note on, 2 change patch
  58.      */
  59.     int cmd; 
  60.  
  61.     /**
  62.      * The note.
  63.      *
  64.      * If cmd==2, then the patch is stored in "note"
  65.      */
  66.     int note; 
  67.   };
  68.   
  69.   private:
  70.   noteCmd *data;
  71.   ulong totalAllocated;
  72.  
  73.   ulong last;
  74.   noteCmd *lastAdded;
  75.  
  76.   /**
  77.    * @internal
  78.    * The iterator
  79.    */
  80.   noteCmd *it;
  81.  
  82.   noteCmd *pointerTo(ulong pos);
  83.  
  84.   public:
  85.   /**
  86.    * Constructor. Initializes internal variables.
  87.    */
  88.   NoteArray(void);
  89.   /**
  90.    * Destructor.
  91.    */
  92.   ~NoteArray();
  93.  
  94.   /**
  95.    * Adds (or modifies) an event in the given position . 
  96.    *
  97.    * Note that this has nothing to do with what is being played, this just
  98.    * modifies an internal array.
  99.    */
  100.   void at(ulong pos, ulong ms,int chn,int cmd,int note);
  101.  
  102.   /**
  103.    * A convenience function, which differs from the above in the parameters
  104.    * it accepts.
  105.    */
  106.   void at(ulong pos, noteCmd s);
  107.  
  108.   /**
  109.    * Returns the note event at a given position.
  110.    */ 
  111.   noteCmd at(int pos);
  112.  
  113.   /**
  114.    * Adds a note/patch event at a given millisecond.
  115.    * 
  116.    * Note: This method always appends at the end of the list.
  117.    */ 
  118.   void add(ulong ms,int chn,int cmd,int note);
  119.  
  120.   /**
  121.    * Initializes the iterator.
  122.    *
  123.    * @see get()
  124.    * @see next()
  125.    */ 
  126.   void iteratorBegin(void) { it=data; }
  127.  
  128.   /**
  129.    * Get the command currently pointed to by the iterator.
  130.    */
  131.   noteCmd *get(void)       { return it; }
  132.  
  133.   /**
  134.    * Advances the iterator to the next position.
  135.    */ 
  136.   void next(void);
  137.  
  138.   /**
  139.    * Calls next() until the next event is over ms milliseconds
  140.    * and puts in @p pgm[16] the instruments used at this moment.
  141.    */
  142.   void moveIteratorTo(ulong ms,int *pgm=NULL);
  143. };
  144.  
  145. #endif
  146.