1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/**************************************************************************
notearray.cpp - NoteArray class, which holds an array of notes
This file is part of LibKMid 0.9.5
Copyright (C) 1998,99,2000 Antonio Larrosa Jimenez
LibKMid's homepage : http://www.arrakis.es/~rlarrosa/libtdemid.html
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
Send comments and bug fixes to Antonio Larrosa <larrosa@kde.org>
***************************************************************************/
#include "notearray.h"
#include <string.h>
NoteArray::NoteArray(void)
{
totalAllocated=50;
data=new noteCmd[totalAllocated];
lastAdded=0L;
}
NoteArray::~NoteArray()
{
delete data;
totalAllocated=0;
}
NoteArray::noteCmd *NoteArray::pointerTo(ulong pos)
{
if (pos<totalAllocated) return &data[pos];
while (pos>=totalAllocated)
{
noteCmd *tmp=new noteCmd[totalAllocated*2];
memcpy(tmp,data,sizeof(noteCmd)*totalAllocated);
delete data;
data=tmp;
totalAllocated*=2;
}
return &data[pos];
}
void NoteArray::at(ulong pos, ulong ms,int chn,int cmd,int note)
{
noteCmd *tmp=pointerTo(pos);
tmp->ms=ms;
tmp->chn=chn;
tmp->cmd=cmd;
tmp->note=note;
}
void NoteArray::at(ulong pos, noteCmd s)
{
noteCmd *tmp=pointerTo(pos);
tmp->ms=s.ms;
tmp->chn=s.chn;
tmp->cmd=s.cmd;
tmp->note=s.note;
}
NoteArray::noteCmd NoteArray::at(int pos)
{
return *pointerTo(pos);
}
void NoteArray::add(ulong ms,int chn,int cmd,int note)
{
if (lastAdded==NULL)
{
lastAdded=data;
last=0;
}
else
{
last++;
if (last==totalAllocated) lastAdded=pointerTo(totalAllocated);
else lastAdded++;
}
lastAdded->ms=ms;
lastAdded->chn=chn;
lastAdded->cmd=cmd;
lastAdded->note=note;
}
void NoteArray::next(void)
{
if (it==lastAdded) {it=NULL;return;};
it++;
}
void NoteArray::moveIteratorTo(ulong ms,int *pgm)
{
noteCmd *ncmd;
iteratorBegin();
ncmd=get();
int pgm2[16];
for (int j=0;j<16;j++) pgm2[j]=0;
while ((ncmd!=NULL)&&(ncmd->ms<ms))
{
if (ncmd->cmd==2) pgm2[ncmd->chn]=ncmd->note;
next();
ncmd=get();
}
if (pgm!=NULL)
{
for (int i=0;i<16;i++) pgm[i]=pgm2[i];
}
}
|