notearray.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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.4.