Re: MIDI Playback

From: [at]} <Stewart>
Date: Tue, 13 Mar 2001 12:05:25 +0800

Hans,

> I was thinking about adding MIDI playback functionality to one of my
> programs. I understand that this can be accomplished by either calling an
> external application such as the windows media player or by using an midi
> playback dll. I'd prefer the latter; unfortunately I don't know how I would
> go about doing this and/or where to get an appropriate library. Any pointers
> that could help me with either problem would be greatly appreciated.

I think you probably can do it using Windows MCI (media control interface)
functions. Here is a fragment of some C code (sorry!) that uses MCI to play
a sound. Parameter <s> is the name of the file containing the media data
(eg. a MIDI data file). Parameter <wnd> is the handle of a window that will
be sent notification of playback events (eg. end of sound). If you don't
need to handle notification it should be simpler. Once you have a device ID
(eg. wDeviceID in the code), you can use this to control the playback
(position, stop, close, etc).

There are also "string" based versions of these functions (eg.
mciSendString) in which the parameters of the operation are all represented
in a string. This avoids having to pass structures to MCI; Visual Basic
applications would use this interface.

Blackbox includes an MCI interface in WinMM, so it shouldn't be too hard to
do this sort of thing. Note however, that the quality of midi playback
depends on the sound card and can be quite poor on some systems.

Hope this helps.

Cheers,
  Stewart


UINT wDeviceID;
int mciOpened=1;

BOOL MCISound(char * s, HWND wnd) {
        MCI_OPEN_PARMS MciOpenParm;
        MCI_PLAY_PARMS MciPlayParm;
        MCIERROR res;

        // open sound
        MciOpenParm.dwCallback = 0L;
        MciOpenParm.wDeviceID = 0;
#if !defined(__WIN32__)
        MciOpenParm.wReserved0 = 0;
#endif
        MciOpenParm.lpstrDeviceType = NULL;
        MciOpenParm.lpstrElementName = (LPSTR)s;
        MciOpenParm.lpstrAlias = NULL;
        res = mciSendCommand (0, MCI_OPEN, MCI_WAIT| MCI_OPEN_ELEMENT,
                  (DWORD)(LPMCI_OPEN_PARMS)&MciOpenParm);
        if (res != 0) return MCIError(res);
        wDeviceID = MciOpenParm.wDeviceID;
        mciOpened=1;

        // Play sound. Notification will be sent when done.
        MciPlayParm.dwCallback = (DWORD)wnd;
        MciPlayParm.dwFrom = 0;
        MciPlayParm.dwTo = 0;
        res = mciSendCommand (wDeviceID, MCI_PLAY, MCI_NOTIFY,
                  (DWORD)(LPMCI_PLAY_PARMS)&MciPlayParm);
        if (res != 0) {
                MCIError(res); MCIClose(); return FALSE;
        }
        Debug("MCISound: playing sound [%s] (device=%04x)\n", s, wDeviceID);
        return TRUE;
}

--------------------------------------------

To unsubscribe from this mailing list, send a message containing the word "unsubscribe" to:
   blackbox-request{([at]})nowhere.xy

To get a list of valid e-mail commands and instructions on their usage, send a message containing the word "help" to the above address.

Send any problem reports or questions related to this email list to the list owner at
   owner-blackbox{([at]})nowhere.xy
Received on Tue Mar 13 2001 - 04:05:25 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:27:44 UTC