<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Author" CONTENT="Zafir Anjum">
<TITLE>MFC Programmer's SourceBook : Static Controls</TITLE>
<META Name="description" Content="Source code for various windows controls">
<META Name="keywords" Content="">
</HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--
var adcategory = "controls";
// -->
</SCRIPT>
<body background="../fancyhome/back.gif" bgcolor="#FFFFFF" >
<!-- Spidersoft WebZIP Ad Banner Insert -->
<TABLE width=100% border="0" cellpadding="0" cellspacing="0">
<TR>
<TD>
<ILAYER id=ad1 visibility=hidden height=60></ILAYER>
<NOLAYER>
<IFRAME SRC="http://www.spidersoft.com/ads/bwz468_60.htm" width="100%" height="60" marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no></IFRAME>
</NOLAYER>
</TD>
</TR>
</TABLE>
<!-- End of Spidersoft WebZIP Ad Banner Insert-->
<SCRIPT LANGUAGE="JavaScript"><!--
var nfrm = location.href.indexOf("_nfrm_");
var validframes = (top.frames.length > 0 && top.frames['ad'] && top.frames['logo'] );
var random = Math.random();
if( !validframes && nfrm == -1 )
{
var dclkPage = "www.codeguru.com/";
if( self.adcategory )
dclkPage += adcategory;
else
dclkPage += "mfc";
document.write('<nolayer><center>');
document.write('<iframe src="http://ad.doubleclick.net/adi/' + dclkPage + ';ord='
+ random + '" width=470 height=62 marginwidth=0 marginheight=0 hspace=0 vspace=0 '
+ 'frameborder=0 scrolling=no bordercolor="#000000">');
document.write('<a href="http://ad.doubleclick.net/jump/' + dclkPage + ';ord='
+ random + '">');
document.write('<img src="http://ad.doubleclick.net/ad/' + dclkPage + ';ord='
+ random + '" height=60 width=468>' + '</a>');
document.write('</iframe>');
document.write('</center></nolayer>');
document.write('<layer src="http://ad.doubleclick.net/adl/' + dclkPage +
';ord=' + random + '"></layer>');
document.write('<ilayer visibility=hide width=468 height=83></ilayer>');
}
// top.location = "/show.cgi?" + adcategory + "=" + location.pathname;
// -->
</SCRIPT>
<noscript>
<p align="center">
<a href="http://ad.doubleclick.net/jump/www.codeguru.com/controls;ord=No6iONFCY35kNQAAvpg">
<img src="http://ad.doubleclick.net/ad/www.codeguru.com/controls;ord=No6iONFCY35kNQAAvpg"></a>
</p>
</noscript>
<CENTER><H3><FONT COLOR="#AOAO99">
Playing MIDI Files Directly From The Resource
</FONT></H3></CENTER><HR>
<!-- Author and contact details -->
This article was contributed by <A HREF="mailto:
[email protected]">Joerg Koenig</A>.
<A NAME="ToTheTop"></A>
<P><A HREF="#intro">Introduction</A>
<BR><A HREF="#publics">Public Interface</A>
<BR><A HREF="#virtuals">Overridables</A>
<BR><A HREF="#usage">Usage</A>
<BR><A HREF="#download">Download</A>
<BR><A HREF="#comments">Comments</A>
<BR>
<H4><A NAME="intro"></A>Introduction (<A HREF="#ToTheTop">back to top</A>)</H4>
This class is a slightly modified "spin off" from the <A HREF="http://www.codeguru.com/samples/CGTetris.shtml">CGTetris</A>
application. It is based on a sample in the DirectX sdk (called <B>mstream</B>).
The conversion into a C++ class makes it much easier to use. The CMIDI
class makes it easy to play a MIDI file directly from the resource (without
copying it into a temporary file). One can use the class to play MIDI <I>files</I>,
too. In this case you have to load the entire file into memory and to pass
the pointer to the beginning of the buffer to the Create() method.
<H4><A NAME="publics"></A>Public Interface (<A HREF="#ToTheTop">back to top</A>)</H4>
<TT><FONT COLOR="#006600">// create the MIDI object. You cannot use a MIDI
object before</FONT></TT>
<BR><TT><FONT COLOR="#006600">// you've "Create()"ed one!</FONT></TT>
<BR><TT><FONT COLOR="#990000">BOOL Create(LPVOID pSoundData, DWORD dwSize,
CWnd * pParent = 0);</FONT></TT>
<BR><TT><FONT COLOR="#990000">BOOL Create(LPCTSTR pszResID, CWnd * pParent
= 0);</FONT></TT>
<BR><TT><FONT COLOR="#990000">BOOL Create(UINT uResID, CWnd * pParent =
0);</FONT></TT>
<P><TT><FONT COLOR="#006600">// Play the MIDI file. Normally the playback
will stop after</FONT></TT>
<BR><TT><FONT COLOR="#006600">// the MIDI played off.</FONT></TT>
<BR><TT><FONT COLOR="#990000">BOOL Play(BOOL bInfinite = FALSE);</FONT></TT>
<P><TT><FONT COLOR="#006600">// usually you should never set "bReOpen"
to FALSE</FONT></TT>
<BR><TT><FONT COLOR="#006600">// unless you're absolutly sure you will</FONT></TT>
<BR><TT><FONT COLOR="#006600">// not reuse the MIDI object. Normally only
the</FONT></TT>
<BR><TT><FONT COLOR="#006600">// destructor of the class should set this
flag</FONT></TT>
<BR><TT><FONT COLOR="#990000">BOOL Stop(BOOL bReOpen = TRUE);</FONT></TT>
<P><TT><FONT COLOR="#990000">BOOL IsPlaying() const;</FONT></TT>
<P><TT><FONT COLOR="#990000">BOOL Pause();</FONT></TT>
<BR><TT><FONT COLOR="#990000">BOOL Continue();</FONT></TT>
<BR><TT><FONT COLOR="#990000">BOOL IsPaused() const;</FONT></TT>
<P><TT><FONT COLOR="#006600">// Set playback position back to the start</FONT></TT>
<BR><TT><FONT COLOR="#006600">// normally there is no need to call this
method directly.</FONT></TT>
<BR><TT><FONT COLOR="#990000">BOOL Rewind();</FONT></TT>
<P><TT><FONT COLOR="#006600">// Get the number of volume channels</FONT></TT>
<BR><TT><FONT COLOR="#990000">DWORD GetChannelCount() const;</FONT></TT>
<P><TT><FONT COLOR="#006600">// Set the volume of a channel in percentage.
(default 100%)</FONT></TT>
<BR><TT><FONT COLOR="#006600">// Channels can be addressed from 0 to (GetChannelCount()-1)</FONT></TT>
<BR><TT><FONT COLOR="#990000">void SetChannelVolume(DWORD channel, DWORD
percent);</FONT></TT>
<P><TT><FONT COLOR="#006600">// Get the volume of a channel (in percentage)</FONT></TT>
<BR><TT><FONT COLOR="#990000">DWORD GetChannelVolume(DWORD channel) const;</FONT></TT>
<BR><TT><FONT COLOR="#990000"> </FONT></TT>
<BR><TT><FONT COLOR="#006600">// Set the volume for all channels in percentage</FONT></TT>
<BR><TT><FONT COLOR="#990000">void SetVolume(DWORD percent);</FONT></TT>
<P><TT><FONT COLOR="#006600">// Get the average volume for all channels
(in percentage)</FONT></TT>
<BR><TT><FONT COLOR="#990000">DWORD GetVolume() const;</FONT></TT>
<P><TT><FONT COLOR="#006600">// Set the tempo of the playback. (default
100%)</FONT></TT>
<BR><TT><FONT COLOR="#990000">void SetTempo(DWORD percent);</FONT></TT>
<P><TT><FONT COLOR="#006600">// Get the current tempo (in percentage)</FONT></TT>
<BR><TT><FONT COLOR="#990000">DWORD GetTempo() const;</FONT></TT>
<P><TT><FONT COLOR="#006600">// You can (un)set an infinite loop during
playback.</FONT></TT>
<BR><TT><FONT COLOR="#006600">// Note that "Play()" overrides this setting!</FONT></TT>
<BR><TT><FONT COLOR="#990000">void SetInfinitePlay(BOOL bSet = TRUE);</FONT></TT>
<P>The CMIDI class sends the message WM_MIDI_VOLUMECHANGED to its owner
window (if one is set via <I>Create()</I>), if the volume changed during
playback in another way than explicitly set by the class (a MIDI stream
can control its volume by itself). The WPARAM parameter of the message
is a pointer to the CMIDI object that sent the message. The LOWORD of the
LPARAM parameter describes the channel that changed volume and the HIWORD
is the new volume in percentage. The WM_MIDI_VOLUMECHANGED message is #define'd
as WM_USER+23.
<H4><A NAME="virtuals"></A>Overridables (<A HREF="#ToTheTop">back to top</A>)</H4>
<TT><FONT COLOR="#006600">// NOTE THAT, IF YOU OVERRIDE ONE OF THESE METHODS,
YOU MUST CALL</FONT></TT>
<BR><TT><FONT COLOR="#006600">// THE BASE CLASS IMPLEMENTATION, TOO!</FONT></TT>
<P><TT><FONT COLOR="#006600">// called when a MIDI output device is opened</FONT></TT>
<BR><TT><FONT COLOR="#990000">virtual void OnMidiOutOpen();</FONT></TT>
<BR><TT><FONT COLOR="#006600"> </FONT></TT>
<BR
评论0