ramon (15) [Avatar] Offline
#1
I wrote some code, that reads an smf and returns the events.

The file has three tracks.

The status byte returns 0x90 for a note_event in track 1.

Is it correct, that the status byte for note_events in track 2 are 0x91? Track 3 0x92?

This seems rather strange.

Output:

read_smf Version 0.3 The Midi File contains 4 Tracks. Number of events in track 0 = 1 time= 0:status= 0:tdata4= 500000 Number of events in track 1 = 8 time= 0:status= B0:tdata1= 7:tdata2= 127:tdata3= 0 time= 0:status= B0:tdata1= 10:tdata2= 64:tdata3= 0 time= 0:status= 90:tdata1= 65:tdata2= 110:tdata3= 0 time= 0:status= 90:tdata1= 76:tdata2= 110:tdata3= 0 time= 160:status= 90:tdata1= 65:tdata2= 0:tdata3= 0 time= 0:status= 90:tdata1= 76:tdata2= 0:tdata3= 0 time= 32:status= 90:tdata1= 65:tdata2= 110:tdata3= 0 time= 160:status= 90:tdata1= 65:tdata2= 0:tdata3= 0 Number of events in track 2 = 6 time= 0:status= B1:tdata1= 7:tdata2= 127:tdata3= 0 time= 0:status= B1:tdata1= 10:tdata2= 64:tdata3= 0 time= 0:status= 91:tdata1= 72:tdata2= 110:tdata3= 0 time= 160:status= 91:tdata1= 72:tdata2= 0:tdata3= 0 time= 32:status= 91:tdata1= 71:tdata2= 110:tdata3= 0 time= 160:status= 91:tdata1= 71:tdata2= 0:tdata3= 0 Number of events in track 3 = 6 time= 0:status= B2:tdata1= 7:tdata2= 127:tdata3= 0 time= 0:status= B2:tdata1= 10:tdata2= 64:tdata3= 0 time= 0:status= 92:tdata1= 50:tdata2= 110:tdata3= 0 time= 160:status= 92:tdata1= 50:tdata2= 0:tdata3= 0 time= 32:status= 92:tdata1= 50:tdata2= 110:tdata3= 0 time= 160:status= 92:tdata1= 50:tdata2= 0:tdata3= 0

Code:
#include <stdio.h>
#include <windows.h>
#include <MaxMidi.h>
#include <IOSTREAM.H>

int main(void) {
int NumOfTracks;
HSMF hSmf;
int format;
DWORD NumOfEvents;
int wTrack;
int x;
LPMIDIEVENT lpMidiBuff;
DWORD dwBuffLen;
DWORD eventCount;
HMOUT hMidiOut;


printf("read_smf Version 0.3
");

hSmf = OpenSMF("C:\midis\b.mid", &format, 'r', &NumOfTracks);
printf("The Midi File contains %d Tracks.
", NumOfTracks);
if (!hSmf)
return;

//read an event from track
//pTrackList[1]->GetEvent(1);

// read the first track



for (wTrack=0;wTrack<NumOfTracks;wTrack++){ >


// use a 512 event buffer
dwBuffLen = 512L;
// allocate memory for the buffer
lpMidiBuff = (LPMIDIEVENT)GlobalAlloc(GPTR, dwBuffLen * sizeof(MidiEvent));

NumOfEvents = ReadSMF(hSmf, wTrack, lpMidiBuff, dwBuffLen);
printf("Number of events in track %d = %d
", wTrack, NumOfEvents );

eventCount = 0;
while (eventCount < NumOfEvents) {
int tstatus = (lpMidiBuff + eventCount)->status;
int ttime = (lpMidiBuff + eventCount)->time;
int tdata1 = (lpMidiBuff + eventCount)->data1;
int tdata2 = (lpMidiBuff + eventCount)->data2;
int tdata3 = (lpMidiBuff + eventCount)->data3;
if (tstatus==0){

int tdata4 = (tdata1*256+tdata2)*256+tdata3 ; // calculate microseconds per beat
printf("time= %3d:status= %3X:tdata4=%10d
",ttime,tstatus,tdata4);
//printf("time= %3d:status= %3d:tdata1=%4d:tdata2=%4d:tdata3=%4d
",ttime,tstatus,tdata1,tdata2,tdata3);
} else
{printf("time= %3d:status= %3X:tdata1=%4d:tdata2=%4d:tdata3=%4d
",ttime,tstatus,tdata1,tdata2,tdata3);}


//printf("Event = %3d: time=%4d, status =%4s; %4d %4d %4d
", eventCount,
/*(lpMidiBuff + eventCount)->time,
(LPSTR)((lpMidiBuff + eventCount)->status),
(UINT)((lpMidiBuff + eventCount)->data1),
(UINT)((lpMidiBuff + eventCount)->data2),
(UINT)((lpMidiBuff + eventCount)->data3));*/
eventCount++;
}

}
CloseSMF(hSmf);
hSmf=0;

}
KUMA (56) [Avatar] Offline
#2
Re: Meaning of status bytes of smf
0x9n means that the Midi-channel of the event is n + 1.
ramon (15) [Avatar] Offline
#3
Re: Meaning of status bytes of smf
Hi,

thank you. Yes, I think that is correct.

Have you checked out the miditoolbox for matlab?
KUMA (56) [Avatar] Offline
#4
Re: Meaning of status bytes of smf
No, what is that?
ramon (15) [Avatar] Offline
#5
Re: Meaning of status bytes of smf
A midi programming environment for Matlab.

It reads Midi files and converts it to a Matrix.