We help IT Professionals succeed at work.

playing a .mod or a .mid file

markyvt
markyvt asked
on
i want to play a .mod or a .mid file in my C programm  (dos based) how can i set this up ?
Comment
Watch Question

CERTIFIED EXPERT
Commented:
Try the below which works for mid file.

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
CERTIFIED EXPERT

Commented:
Ignore my previous comment!!!

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

Author

Commented:
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?

Author

Commented:
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?

Commented:
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;
}

Explore More ContentExplore courses, solutions, and other research materials related to this topic.