markyvt
asked on
playing a .mod or a .mid file
i want to play a .mod or a .mid file in my C programm (dos based) how can i set this up ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
im new to C programming, i'm more a VB/Pascal/Delphi coder, you see?
how do i define the file what needs to be opened?
how do i define the file what needs to be opened?
ASKER
im new to C programming, i'm more a VB/Pascal/Delphi coder, you see?
how do i define the file what needs to be opened?
how do i define the file what needs to be opened?
If you don't need to have a control over play you may use Shellexecuite which will fork another process:
#include <windows.h>
#include <shellapi.h>
#pragma comment(lib,"shell32.lib")
int main()
{
ShellExecute(NULL, "open", "c:\\temp\\canyon.mid", NULL, NULL, SW_HIDE);
return 0;
}
#include <windows.h>
#include <shellapi.h>
#pragma comment(lib,"shell32.lib")
int main()
{
ShellExecute(NULL, "open", "c:\\temp\\canyon.mid", NULL, NULL, SW_HIDE);
return 0;
}
Below will play midi.
If you are using Visual C++ 6.0, do the following:
Click Projects - Settings - Link Tab and then enter "winmm.lib" in the library modules to include
#include <windows.h>
#include <mmsystem.h>
....
void main()
{
char* ReturnString = (char*)malloc(30 *sizeof(char));
LPTSTR lpszReturnString = ReturnString;
....
/* play midi */
mciSendString("open name.mid type sequencer alias finch", lpszReturnString, 30, NULL);
mciSendString("set finch time format samples", lpszReturnString, 30, NULL);
mciSendString("play finch", lpszReturnString, 30, NULL);
/* pause midi */
mciSendString("pause finch", lpszReturnString, 30, NULL);
/* resume midi */
mciSendString("resume finch", lpszReturnString, 30, NULL);
/* stop midi */
mciSendString("close finch", lpszReturnString, 30, NULL);
/* restart midi */
mciSendString("close finch", lpszReturnString, 30, NULL);
mciSendString("open name.mid type sequencer alias finch", lpszReturnString, 30, NULL);
mciSendString("set finch time format samples", lpszReturnString, 30, NULL);
mciSendString("play finch", lpszReturnString, 30, NULL);
....
}
hongjun