~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to kmid/player/notearray.cc

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************************
 
2
 
 
3
    notearray.cc  - NoteArray class, which holds an array of notes
 
4
    Copyright (C) 1998  Antonio Larrosa Jimenez
 
5
 
 
6
    This program is free software; you can redistribute it and/or modify
 
7
    it under the terms of the GNU General Public License as published by
 
8
    the Free Software Foundation; either version 2 of the License, or
 
9
    (at your option) any later version.
 
10
 
 
11
    This program 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
 
14
    GNU General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU General Public License
 
17
    along with this program; if not, write to the Free Software
 
18
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 
 
20
    Send comments and bug fixes to antlarr@arrakis.es
 
21
    or to Antonio Larrosa, Rio Arnoya, 10 5B, 29006 Malaga, Spain
 
22
 
 
23
***************************************************************************/
 
24
 
 
25
#include "notearray.h"
 
26
#include <string.h>
 
27
 
 
28
NoteArray::NoteArray(void)
 
29
{
 
30
    totalAllocated=50;
 
31
    data=new noteCmd[totalAllocated];
 
32
    lastAdded=NULL;
 
33
}
 
34
 
 
35
NoteArray::~NoteArray()
 
36
{
 
37
    delete data;
 
38
    totalAllocated=0;
 
39
}
 
40
 
 
41
noteCmd *NoteArray::pointerTo(ulong pos)
 
42
{
 
43
    if (pos<totalAllocated) return &data[pos];
 
44
    while (pos>=totalAllocated)
 
45
    {
 
46
        noteCmd *tmp=new noteCmd[totalAllocated*2];
 
47
        memcpy(tmp,data,sizeof(noteCmd)*totalAllocated);
 
48
        delete data;
 
49
        data=tmp;
 
50
        totalAllocated*=2;
 
51
    }
 
52
    return &data[pos];
 
53
}
 
54
 
 
55
void NoteArray::at(ulong pos, ulong ms,int chn,int cmd,int note)
 
56
{
 
57
    noteCmd *tmp=pointerTo(pos);
 
58
    tmp->ms=ms;
 
59
    tmp->chn=chn;
 
60
    tmp->cmd=cmd;
 
61
    tmp->note=note;
 
62
}
 
63
 
 
64
void NoteArray::at(ulong pos, noteCmd s)
 
65
{
 
66
    noteCmd *tmp=pointerTo(pos);
 
67
    tmp->ms=s.ms;
 
68
    tmp->chn=s.chn;
 
69
    tmp->cmd=s.cmd;
 
70
    tmp->note=s.note;
 
71
}
 
72
 
 
73
noteCmd NoteArray::at(int pos)
 
74
{
 
75
    return *pointerTo(pos);
 
76
}
 
77
 
 
78
void NoteArray::add(ulong ms,int chn,int cmd,int note)
 
79
{
 
80
    if (lastAdded==NULL)
 
81
    {
 
82
        lastAdded=data;
 
83
        last=0;
 
84
    }
 
85
    else
 
86
    {
 
87
        last++;
 
88
        if (last==totalAllocated) lastAdded=pointerTo(totalAllocated);
 
89
        else lastAdded++;
 
90
    }
 
91
    lastAdded->ms=ms;
 
92
    lastAdded->chn=chn;
 
93
    lastAdded->cmd=cmd;
 
94
    lastAdded->note=note;
 
95
}
 
96
 
 
97
void NoteArray::next(void)
 
98
{
 
99
    if (it==lastAdded) {it=NULL;return;};
 
100
    it++;
 
101
}
 
102
 
 
103
void NoteArray::moveIteratorTo(ulong ms,int *pgm)
 
104
{
 
105
    noteCmd *ncmd;
 
106
    iteratorBegin();
 
107
    ncmd=get();
 
108
    int pgm2[16];
 
109
    for (int j=0;j<16;j++) pgm2[j]=0;
 
110
    while ((ncmd!=NULL)&&(ncmd->ms<ms))
 
111
    {
 
112
        if (ncmd->cmd==2) pgm2[ncmd->chn]=ncmd->note;
 
113
        next();
 
114
        ncmd=get();
 
115
    }
 
116
    if (pgm!=NULL)
 
117
    {
 
118
        for (int i=0;i<16;i++) pgm[i]=pgm2[i];
 
119
    }
 
120
}