# libkmid Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# notearray.cc

    00001 /**************************************************************************
    00002
    00003     notearray.cc  - NoteArray class, which holds an array of notes
    00004     This file is part of LibKMid 0.9.5
    00005     Copyright (C) 1998,99,2000  Antonio Larrosa Jimenez
    00006     LibKMid's homepage : http://www.arrakis.es/~rlarrosa/libkmid.html
    00007
    00008     This library is free software; you can redistribute it and/or
    00009     modify it under the terms of the GNU Library General Public
    00010     License as published by the Free Software Foundation; either
    00011     version 2 of the License, or (at your option) any later version.
    00012
    00013     This library is distributed in the hope that it will be useful,
    00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00016     Library General Public License for more details.
    00017
    00018     You should have received a copy of the GNU Library General Public License
    00019     along with this library; see the file COPYING.LIB.  If not, write to
    00020     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00021     Boston, MA 02111-1307, USA.
    00022
    00023     Send comments and bug fixes to Antonio Larrosa <larrosa@kde.org>
    00024
    00025 ***************************************************************************/
    00026
    00027 #include "notearray.h"
    00028 #include <string.h>
    00029
    00030 NoteArray::NoteArray(void)
    00031 {
    00032   totalAllocated=50;
    00033   data=new noteCmd[totalAllocated];
    00034   lastAdded=0L;
    00035 }
    00036
    00037 NoteArray::~NoteArray()
    00038 {
    00039   delete data;
    00040   totalAllocated=0;
    00041 }
    00042
    00043 NoteArray::noteCmd *NoteArray::pointerTo(ulong pos)
    00044 {
    00045   if (pos<totalAllocated) return &data[pos];
    00046   while (pos>=totalAllocated)
    00047   {
    00048     noteCmd *tmp=new noteCmd[totalAllocated*2];
    00049     memcpy(tmp,data,sizeof(noteCmd)*totalAllocated);
    00050     delete data;
    00051     data=tmp;
    00052     totalAllocated*=2;
    00053   }
    00054   return &data[pos];
    00055 }
    00056
    00057 void NoteArray::at(ulong pos, ulong ms,int chn,int cmd,int note)
    00058 {
    00059   noteCmd *tmp=pointerTo(pos);
    00060   tmp->ms=ms;
    00061   tmp->chn=chn;
    00062   tmp->cmd=cmd;
    00063   tmp->note=note;
    00064 }
    00065
    00066 void NoteArray::at(ulong pos, noteCmd s)
    00067 {
    00068   noteCmd *tmp=pointerTo(pos);
    00069   tmp->ms=s.ms;
    00070   tmp->chn=s.chn;
    00071   tmp->cmd=s.cmd;
    00072   tmp->note=s.note;
    00073 }
    00074
    00075 NoteArray::noteCmd NoteArray::at(int pos)
    00076 {
    00077   return *pointerTo(pos);
    00078 }
    00079
    00080 void NoteArray::add(ulong ms,int chn,int cmd,int note)
    00081 {
    00082   if (lastAdded==NULL)
    00083   {
    00084     lastAdded=data;
    00085     last=0;
    00086   }
    00087   else
    00088   {
    00089     last++;
    00090     if (last==totalAllocated) lastAdded=pointerTo(totalAllocated);
    00091     else lastAdded++;
    00092   }
    00093   lastAdded->ms=ms;
    00094   lastAdded->chn=chn;
    00095   lastAdded->cmd=cmd;
    00096   lastAdded->note=note;
    00097 }
    00098
    00099 void NoteArray::next(void)
    00100 {
    00101   if (it==lastAdded) {it=NULL;return;};
    00102   it++;
    00103 }
    00104
    00105 void NoteArray::moveIteratorTo(ulong ms,int *pgm)
    00106 {
    00107   noteCmd *ncmd;
    00108   iteratorBegin();
    00109   ncmd=get();
    00110   int pgm2[16];
    00111   for (int j=0;j<16;j++) pgm2[j]=0;
    00112   while ((ncmd!=NULL)&&(ncmd->ms<ms))
    00113   {
    00114     if (ncmd->cmd==2) pgm2[ncmd->chn]=ncmd->note;
    00115     next();
    00116     ncmd=get();
    00117   }
    00118   if (pgm!=NULL)
    00119   {
    00120     for (int i=0;i<16;i++) pgm[i]=pgm2[i];
    00121   }
    00122 }

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:28:29 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001