Playing MIDIs in VC++ with MCI
Hello,
I''m teaching myself VC++ by programming a simple Space War game and would like to play MIDI music in the background. I''ve been having problems with the DX libraries and the compiler, so I''m doing this one without DX. I remember back in the good ol'' VB days I would use the MCI API commands to play MIDI files. Of course, the tutorial in VC++ that shows how to do this is overwhelmingly large. Is there anywhere I might find a tutorial on playing MIDIs using MCI or a source code snippet? Surely someone out there has asked themselves why MCI has to be so damned complicated? Oh. Right. 16bit. Go figure.
Telamon
-----------------------------
Let be be finale of seem, seems to me.
Shedletsky's Bits: A Blog | ROBLOX | Twitter
Time held me green and dying
Though I sang in my chains like the sea...
Here''s some old functions I pulled out from my archives.
I suggest adding ''wait'' to every command to force them to wait until they can be processed. Sometimes this doesn''t work though.
eg.
mciSendString("open sequencer wait", NULL, 0, NULL);
mciSendString("play song from 0 wait", NULL, 0, NULL);
and so on.
BOOL midi_init()
{
if(mciSendString("open sequencer", NULL, 0, NULL))
return FALSE;
return TRUE;
}
BOOL midi_shutdown()
{
midi_stop();
midi_free();
mciSendString("close sequencer", NULL, 0, NULL);
return TRUE;
}
BOOL midi_load(char *filename)
{
char command[256];
sprintf(command, "open %s type sequencer alias song", filename);
if(mciSendString(command, NULL, 0, NULL))
return FALSE;
return TRUE;
}
BOOL midi_free()
{
if(mciSendString("close song", NULL, 0, NULL))
return FALSE;
return TRUE;
}
BOOL midi_play()
{
if(mciSendString("play song from 0", NULL, 0, NULL))
return FALSE;
return TRUE;
}
BOOL midi_stop()
{
if(mciSendString("stop song", NULL, 0, NULL))
return FALSE;
return TRUE;
}
BOOL midi_pause()
{
if(mciSendString("stop song", NULL, 0, NULL))
return FALSE;
return TRUE;
}
BOOL midi_unpause()
{
if(mciSendString("play song", NULL, 0, NULL))
return FALSE;
return TRUE;
}
Jim Adams
I suggest adding ''wait'' to every command to force them to wait until they can be processed. Sometimes this doesn''t work though.
eg.
mciSendString("open sequencer wait", NULL, 0, NULL);
mciSendString("play song from 0 wait", NULL, 0, NULL);
and so on.
BOOL midi_init()
{
if(mciSendString("open sequencer", NULL, 0, NULL))
return FALSE;
return TRUE;
}
BOOL midi_shutdown()
{
midi_stop();
midi_free();
mciSendString("close sequencer", NULL, 0, NULL);
return TRUE;
}
BOOL midi_load(char *filename)
{
char command[256];
sprintf(command, "open %s type sequencer alias song", filename);
if(mciSendString(command, NULL, 0, NULL))
return FALSE;
return TRUE;
}
BOOL midi_free()
{
if(mciSendString("close song", NULL, 0, NULL))
return FALSE;
return TRUE;
}
BOOL midi_play()
{
if(mciSendString("play song from 0", NULL, 0, NULL))
return FALSE;
return TRUE;
}
BOOL midi_stop()
{
if(mciSendString("stop song", NULL, 0, NULL))
return FALSE;
return TRUE;
}
BOOL midi_pause()
{
if(mciSendString("stop song", NULL, 0, NULL))
return FALSE;
return TRUE;
}
BOOL midi_unpause()
{
if(mciSendString("play song", NULL, 0, NULL))
return FALSE;
return TRUE;
}
Jim Adams
Jim Adams, Author"Programming Role-Playing Games with DirectX""Advanced Animation with DirectX""Programming Role-Playing Games with DirectX, 2nd Edition"
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement