Plaing MIDI events
[ Follow Ups ] [ The MIDIWORLD Forum ]
Posted by Jerome Siot on March 01, 2001 at 04:47:40:
Hi,
I use the MIDI stream API on Win NT in order to play MIDI events stored in such a buffer:
...
0, 0, 0x007F4390, //note on
48, 0, 0x00004390, //note off
0, 0, 0x007F4390,
48, 0, 0x00004390,
...
with first field as delta-time, second one as reserved and third one as MIDI message.
I want to reproduce such a buffer using relative timestamp, that is to say passing the elapsed time
since the MIDI device was started, instead of deltatime between the current event and the previous one
I think is possible, using the MidiStreamPosition function with an appropriate MMTIME format(TIME_MS or TIME_MIDI)
This solution would allow me to write this kind of buffer:
...
0, 0, 0x007F4390, //note on
48, 0, 0x00004390, //note off
48, 0, 0x007F4390,
996, 0, 0x00004390,
...
Is this really possible ?
Can you give me a short sample code ?
Regards, Jérome SIOT (France)
Here is a piece of my code : (original code was written by J. Glatt, www.borg.com/~jglatt)
//first I declare the buffer
int main(int argc, char **argv)
{
HMIDISTRM handle;
MIDIHDR midiHdr;
unsigned long err, tempo;
MIDIPROPTIMEDIV prop;
MMTIME time;
/* Open default MIDI Out stream device */
err = 0;
if (!(err = midiStreamOpen(&handle, &err, 1, 0, 0, CALLBACK_NULL)))
{
time.wType = TIME_MS; //define the time division type
/* Set the stream device's Time Division to milliseconds*/
prop.cbStruct = sizeof(MIDIPROPTIMEDIV);
prop.dwTimeDiv = 0xE728; //millisecondes : voir midi file spec (key word : E7 28)
midiStreamProperty(handle, (LPBYTE)&prop, MIDIPROP_SET|MIDIPROP_TIMEDIV);
/* Store pointer to our stream (ie, buffer) of messages in MIDIHDR */
midiHdr.lpData = (LPBYTE)&Phrase[0];
/* Store its size in the MIDIHDR */
midiHdr.dwBufferLength = midiHdr.dwBytesRecorded = sizeof(Phrase);
/* Flags must be set to 0 */
midiHdr.dwFlags = 0;
/* Prepare the buffer and MIDIHDR */
midiOutPrepareHeader((HMIDIOUT)handle, &midiHdr, sizeof(MIDIHDR));
midiStreamOut(handle, &midiHdr, sizeof(MIDIHDR));
midiStreamRestart(handle); // actually play MIDIevents
midiOutUnprepareHeader((HMIDIOUT)handle, &midiHdr, sizeof(MIDIHDR));
midiStreamClose(handle);
- Re: Plaing MIDI events Les 3/03/2001
(0)