• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libtdemid
 

libtdemid

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

libtdemid

Skip menu "libtdemid"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libtdemid

Skip menu "libtdemid"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for libtdemid by doxygen 1.9.4
This website is maintained by Timothy Pearson.