commit 0b0b236677c3d2456f8e8200f23fd7f4505a01c5
parent 0319dc6ef8a96d3ae47179632a348031f1ad832a
Author: paulnasca <paulnasca>
Date: Tue, 16 Mar 2004 18:27:34 +0000
*** empty log message ***
Diffstat:
3 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -560,6 +560,7 @@
13 Mar 2004 - Adaugat HarmonicShift la oscilgen
15 Mar 2004 - Inceput sa scriu partea de incarcare MIDI
- Inlaturata partea de recording din Sequencer
+16 Mar 2004 - Inceput sa scriu partea de analiza midi
diff --git a/src/Seq/MIDIFile.C b/src/Seq/MIDIFile.C
@@ -28,6 +28,8 @@
MIDIFile::MIDIFile(){
midifile=NULL;
midifilesize=0;
+ midifilek=0;
+ midieof=false;
};
MIDIFile::~MIDIFile(){
@@ -60,14 +62,24 @@ int MIDIFile::loadfile(char *filename){
fread(midifile,midifilesize,1,file);
fclose(file);
- for (int i=0;i<midifilesize;i++) printf("%2x ",midifile[i]);
- printf("\n");
+// for (int i=0;i<midifilesize;i++) printf("%2x ",midifile[i]);
+// printf("\n");
return(0);
};
int MIDIFile::parsemidifile(){
+
+ //read the header
+ int chunk=getint32();//MThd
+ if (chunk!=0x4d546864) return(-1);
+ int size=getint32();
+ if (size!=6) return(-1);//header is always 6 bytes long
+
+ int format=getint16();
+ printf("format %d\n",format);
+
return(0);
};
@@ -77,6 +89,33 @@ void MIDIFile::clearmidifile(){
if (midifile!=NULL) delete(midifile);
midifile=NULL;
midifilesize=0;
+ midifilek=0;
+ midieof=false;
+};
+
+unsigned char MIDIFile::getbyte(){
+ if (midifilek>=midifilesize) {
+ midieof=true;
+ return(0);
+ };
+ return(midifile[midifilek++]);
};
+unsigned int MIDIFile::getint32(){
+ unsigned int result=0;
+ for (int i=0;i<4;i++) {
+ result=result*256+getbyte();
+ };
+ if (midieof) result=0;
+ return(result);
+};
+
+unsigned short int MIDIFile::getint16(){
+ unsigned short int result=0;
+ for (int i=0;i<2;i++) {
+ result=result*256+getbyte();
+ };
+ if (midieof) result=0;
+ return(result);
+};
diff --git a/src/Seq/MIDIFile.h b/src/Seq/MIDIFile.h
@@ -36,10 +36,20 @@ class MIDIFile{
private:
unsigned char *midifile;
- int midifilesize;
+ int midifilesize,midifilek;
+ bool midieof;
void clearmidifile();
+ //get a byte from the midifile
+ unsigned char getbyte();
+
+ //get a set of 4 bytes from the midifile
+ unsigned int getint32();
+
+ //get a word of 2 bytes from the midifile
+ unsigned short int getint16();
+
};
#endif