Many of you know how I like to use sound to make the old computer box more interesting. The midi file packs a lot of neat instrumental music. It is very simple to play, even in a console application, using the winmm.lib file that comes with just about any Windows based compiler. Here is the code. Turn up the speakers and blast the dust off the rafters!
Ze MIDI music file player
// use mciSendString() to play a midi music file
// you can also play from pos1 to pos2, stop, pause and resume
// you have to link with the winmm.lib file, or
// in the case of Dev-C++ link with libwinmm.a via
// Project>>Project Options>>Parameters>>Add Lib>>libwinmm.a
// a Dev-C++ tested console application by vegaseat 19dec2004
#include <iostream>
#include <windows.h>
#include <mmsystem.h> // mciSendString()
using namespace std; // std::cout, std::cin
int main()
{
cout << "Looking for onestop.mid midi music file in" << endl;
cout << "the windows media directory, wait just a second ...";
// this midi file comes with Windows XP
// you might have to change it to something you have
mciSendString("play C:/Windows/Media/onestop.mid",NULL,0,NULL);
// pause the play
//mciSendString("pause C:/Windows/Media/onestop.mid",NULL,0,NULL);
// resume play from paused position
//mciSendString("resume C:/Windows/Media/onestop.mid",NULL,0,NULL);
cout << "\n\nPress Enter to stop ...";
cin.get();
// stop play, if you play again it will play from beginning
mciSendString("stop C:/Windows/Media/onestop.mid",NULL,0,NULL);
// play the midi file from sequence 10 to sequence 50
//mciSendString("play C:/Windows/Media/onestop.mid from 10 to 50 notify",NULL,0,NULL);
// almost forgot, of course you can play a .wav file too
mciSendString("play C:/Windows/Media/ding.wav",NULL,0,NULL);
return 0;
}
evilsilver 0 Junior Poster in Training
eagleeye 0 Junior Poster in Training
eagleeye 0 Junior Poster in Training
eagleeye 0 Junior Poster in Training
Dani 4,329 The Queen of DaniWeb Administrator Featured Poster Premium Member
evilsilver 0 Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.