Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Squeejee

Playing .mid files in windows.

This topic is 6068 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Something like this.

  
#include <windows.h>
#include <mmsystem.h>

namespace Midi_NS {
bool Loaded = false;
UINT ID;
};

bool LoadMidi(char *FileName)
{
using namespace Midi_NS;
MCI_OPEN_PARMS Params;
CloseMidi();
Params.lpstrDeviceType = "sequencer";
Params.lpstrElementName = FileName;
if(mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD) &Params))
return false;
else
{
ID = Params.wDeviceID;
Loaded = true;
return true;
}
}

void PlayMidi(HWND CallbackWindow)
{
using namespace Midi_NS;
MCI_PLAY_PARMS Params;
Params.dwCallback = (DWORD) CallbackWindow;
Params.dwFrom = 0;
if(Loaded) mciSendCommand(ID, MCI_PLAY, MCI_NOTIFY|MCI_FROM, (DWORD) &Params);
}

void StopMidi(void)
{
using namespace Midi_NS;
DWORD dummy;
if(Loaded) mciSendCommand(ID, MCI_STOP, 0, (DWORD) &dummy);
}

void CloseMidi(void)
{
using namespace Midi_NS;
DWORD dummy;
if(Loaded) mciSendCommand(ID, MCI_CLOSE, MCI_WAIT, (DWORD) &dummy);
Loaded = false;
}


In the window procedure for the callback window, check if the message is MM_MCINOTIFY, and the wParam is MCI_NOTIFY_SUCCESSFUL. If both conditions are met, call PlayMidi again. It's possible to automate that process, but I didn't want that to get in the way of the important code in this example.

Edited by - Beer Hunter on November 12, 2001 1:30:14 AM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
using MCI

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!