The MCI which stands for Media Control Interface is very easy to use.|
In this tutorial I'll show you how to load a .MID and play it.
Most of the MCI calls are done through the mciSendCommand(...) function,
whenever we use this function we need an ID for the device player,
so if we want to stop the playing for instance we need to pass the
device ID that plays the MIDI and tell it to stop...So we'll save this ID.
Let's start then:
We tell the MCI to load a MIDI off a file and to start playing(once).
// "sequencer" - means we want to play a MIDI.
mciOpenParms.lpstrDeviceType = "sequencer";
// The MIDI file name.
mciOpenParms.lpstrElementName = strFileName;
// We open the MIDI for playing.
mciSendCommand(NULL, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT,
MIDI_Device = mciOpenParms.wDeviceID;
// Getting the Device ID which will play the MIDI.
// This struct is for the playing parameters we want.
// We pass the handle of the window because when the MIDI
// will be finished playing, it will notify us (then we may
// play it again[looped]).
mciPlayParms.dwCallback = (DWORD)hWnd;
mciSendCommand(MIDI_Device, MCI_PLAY, MCI_NOTIFY, (DWORD)&mciPlayParms);
OK that was it for loading and playing, MCI does life easy, HUH? :)
Now let's see how to close the device player(this will free the MIDI too):
// Closing the MIDI.
if (MIDI_Device) mciSendCommand(MIDI_Device, MCI_CLOSE, 0, NULL);
MIDI_Device = NULL;
Well you gotta see the source code, it has a REAL nice GUI,
and you may learn how to use dialog boxes....Check it out!
Visual C++ 6 - MIDI.zip
|User Contributed Comments(1)|
Comments that will hurt anyone in any way will be deleted.
Don't ask for features, advertise or curse.
If you want to leave a message to the author use the contacts,
if you have any question in relation to your comments please use the forum.
Comments which violate any of these requests will be deleted without further
Use the comment system decently.
Post your comment: