home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Source / ORiffPlay.cpp < prev    next >
C/C++ Source or Header  |  1996-08-12  |  5KB  |  182 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // ORiffPlay.cpp
  5.  
  6.  
  7. /*
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  14.  *    endorse or promote products derived from this software
  15.  *    without specific prior written permission.
  16.  * 3. See OCL.INF for a detailed copyright notice.
  17.  *
  18.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  19.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  22.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28.  * SUCH DAMAGE.
  29.  */
  30.  
  31.  
  32. // $Header: W:/Projects/OCL/Source/rcs/ORiffPlay.cpp 1.50 1996/08/11 23:49:30 B.STEIN Release $
  33.  
  34. #define __OCL_SOURCE__
  35.  
  36. #define OINCL_OSTRING
  37. #define OINCL_BASE
  38.  
  39. #include <ocl.hpp>
  40. #include <ORiffPlay.hpp>
  41.  
  42.  
  43. mci_play_file     ORiffPlay::mci_pf  = NULL;
  44. mci_play_resource ORiffPlay::mci_pr  = NULL;
  45. mci_get_error     ORiffPlay::mci_err = NULL;
  46. pODynamicLib      ORiffPlay::mciapi  = NULL;
  47. pODynamicLib      ORiffPlay::mdmapi  = NULL;
  48.  
  49.  
  50. ORiffPlay::ORiffPlay()
  51.   : waveID       (0),
  52.     waveType     (0)
  53. {
  54.  if (!OApp::currentOApp)
  55.    throw OPMException(OCL::error(250), OException::unrecoverable);
  56.  resolve();
  57. }
  58.  
  59.    
  60. ORiffPlay::ORiffPlay(PSZ soundLibrary)
  61.   : waveID       (0),
  62.     waveType     (0),
  63.     waveLibrary  (soundLibrary)
  64. {
  65.  if (!OApp::currentOApp)
  66.    throw OPMException(OCL::error(250), OException::unrecoverable);
  67.  resolve();
  68. }
  69.  
  70.  
  71. ORiffPlay::ORiffPlay(ODynamicLib& soundLibrary)
  72.   : waveID       (0),
  73.     waveType     (0),
  74.     waveLibrary  (soundLibrary.getLibHandle())
  75. {
  76.  if (!OApp::currentOApp)
  77.    throw OPMException(OCL::error(250), OException::unrecoverable);
  78.  resolve();
  79. }
  80.  
  81.  
  82. ORiffPlay::~ORiffPlay()
  83. {
  84.  stop();
  85. }
  86.   
  87.  
  88. PSZ ORiffPlay::isOfType() const
  89. {
  90.  return("ORiffPlay");
  91. }
  92.  
  93.  
  94. void ORiffPlay::play(PSZ waveFileName,
  95.                      ORiffPlay::PlayType playType)
  96. {
  97.  waveFile << waveFileName;
  98.  
  99.  playWave(playType);
  100. }
  101.  
  102.  
  103. void ORiffPlay::play(ULONG soundID,
  104.                      ORiffPlay::RiffType resType,
  105.                      ORiffPlay::PlayType playType)
  106. {
  107.  waveID   = soundID;
  108.  waveType = resType;
  109.  
  110.  playWave(playType);
  111. }
  112.  
  113.  
  114. void ORiffPlay::playWave(ORiffPlay::PlayType playType)
  115. {
  116.  APIRET            rc = 0;
  117.  
  118.  stop();
  119.  
  120.  if (!waveFile)
  121.    rc = ORiffPlay::mci_pr(NULLHANDLE,
  122.                           waveLibrary.getLibHandle(),
  123.                           waveType,
  124.                           waveID,
  125.                           playType,
  126.                           NULL,
  127.                           NULLHANDLE);
  128.  else
  129.    rc = ORiffPlay::mci_pf(NULLHANDLE,
  130.                           waveFile,
  131.                           playType,
  132.                           0, 0);
  133.  
  134.  if (rc != 0)
  135.   {
  136.    OString Buffer(CCHMAXPATH);
  137.  
  138.    ORiffPlay::mci_err(rc, Buffer, CCHMAXPATH);
  139.    throw OPMException(OMessage(252, OCL::MSGFILE, Buffer), rc, OException::recoverable); 
  140.   }
  141. }
  142.  
  143.  
  144. void ORiffPlay::stop()
  145. {
  146.  ORiffPlay::mci_pf(NULLHANDLE,
  147.                    NULL,
  148.                    ORiffPlay::stopActive, 0, 0);
  149. }
  150.  
  151. // This member loads MCIAPI.DLL and MDM.DLL
  152. // and resolves the entry points for the desired functions.
  153. // This is because the OCL should not be linked against
  154. // MMPM2.LIB.
  155.  
  156.  
  157. void ORiffPlay::resolve()
  158. {
  159.  if (ORiffPlay::mciapi && ORiffPlay::mdmapi) // initialize only once!
  160.    return;
  161.  
  162.  try
  163.    {
  164.     ORiffPlay::mciapi  = new ODynamicLib("MCIAPI");   
  165.     ORiffPlay::mdmapi  = new ODynamicLib("MDM");   
  166.     ORiffPlay::mci_pf  = (mci_play_file)
  167.                          ORiffPlay::mciapi->queryFn("mciPlayFile");
  168.     ORiffPlay::mci_pr  = (mci_play_resource)
  169.                          ORiffPlay::mciapi->queryFn("mciPlayResource");
  170.     ORiffPlay::mci_err = (mci_get_error)
  171.                          ORiffPlay::mdmapi->queryFn("mciGetErrorString");
  172.    }
  173.  catch(OVioException &ex)
  174.    {
  175.     throw OPMException(OCL::error(251), OException::unrecoverable);
  176.    } 
  177. }
  178.  
  179.  
  180. // end of source
  181.  
  182.