home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / mm / mcdtemp / mcdfuncs.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  11KB  |  240 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /* SOURCE FILE NAME:  MCDFUNCS.C                                            */
  4. /*                                                                          */
  5. /* DESCRIPTIVE NAME:  MCD COMMON FUNCTIONS                                  */
  6. /*                                                                          */
  7. /* COPYRIGHT:  (c) IBM Corp. 1991 - 1993                                    */
  8. /*                                                                          */
  9. /* FUNCTION:  This file contains common functions used by the MCD template. */
  10. /*                                                                          */
  11. /* ENTRY POINTS:                                                            */
  12. /*       QMAudio() - Query master volume settings                           */
  13. /*       GetINIInstallName() - Get the MMPM/2 install name for this device  */
  14. /*       ConvertTime() - Convert time formats                               */
  15. /*       GetDeviceInfo() - Get device info                                  */
  16. /****************************************************************************/
  17. #define INCL_BASE                    // Base OS2 functions
  18. #define INCL_MCIOS2                  // use the OS/2 like MMPM/2 headers
  19.  
  20. #include <os2.h>                     // OS2 defines.
  21. #include <string.h>                  // string prototypes
  22. #include <stdlib.h>                  // standard C functions
  23. #include <os2me.h>                   // MME includes files.
  24. #include "mcdtemp.h"                 // MCD Function Prototypes and typedefs
  25.  
  26.  
  27. /****************************************************************************/
  28. /*                                                                          */
  29. /* SUBROUTINE NAME:  QMAudio                                                */
  30. /*                                                                          */
  31. /* DESCRIPTIVE NAME:  Query Master Audio                                    */
  32. /*                                                                          */
  33. /* FUNCTION:  Query current volume and headphone/speaker settings from      */
  34. /*            Master Audio.                                                 */
  35. /*                                                                          */
  36. /* PARAMETERS:                                                              */
  37. /*      PINSTANCE pInstance - pointer to device instance structure.         */
  38. /*                                                                          */
  39. /* EXIT CODES:   None                                                       */
  40. /*                                                                          */
  41. /****************************************************************************/
  42. VOID QMAudio(PINSTANCE pInstance)
  43. {
  44.    ULONG ulrc;
  45.    MCI_MASTERAUDIO_PARMS recMasterAudio;
  46.  
  47.    /*****************************/
  48.    /* get current master volume */
  49.    /*****************************/
  50.    ulrc = mciSendCommand(pInstance->usDeviceID, MCI_MASTERAUDIO,
  51.                       MCI_WAIT | MCI_QUERYCURRENTSETTING | MCI_MASTERVOL,
  52.                       &recMasterAudio, 0);
  53.    if (ulrc)
  54.       {
  55.       if (pInstance->ulMasterVolume == (ULONG) -1L)
  56.          pInstance->ulMasterVolume = 75L;     //if first time error set to default
  57.       }
  58.    else
  59.       pInstance->ulMasterVolume = recMasterAudio.ulReturn;
  60.  
  61.    /*****************************/
  62.    /* get current speaker status */
  63.    /*****************************/
  64.    ulrc = mciSendCommand(pInstance->usDeviceID, MCI_MASTERAUDIO,
  65.                       MCI_WAIT | MCI_QUERYCURRENTSETTING | MCI_SPEAKERS,
  66.                       &recMasterAudio, 0);
  67.    if (!ulrc)
  68.       if (recMasterAudio.ulReturn)
  69.          pInstance->Speaker = TRUE;      //SPEAKERS are turned on
  70.  
  71.    /*****************************/
  72.    /* get current headphone status */
  73.    /*****************************/
  74.    ulrc = mciSendCommand(pInstance->usDeviceID, MCI_MASTERAUDIO,
  75.                       MCI_WAIT | MCI_QUERYCURRENTSETTING | MCI_HEADPHONES,
  76.                       &recMasterAudio, 0);
  77.  
  78.    if (!ulrc)
  79.       if (recMasterAudio.ulReturn)
  80.          pInstance->Headphone = TRUE;      //Headphones are turned on
  81.  
  82.  
  83. }  /* of QMAudio() */
  84.  
  85.  
  86.  
  87.  
  88. /****************************************************************************/
  89. /*                                                                          */
  90. /* SUBROUTINE NAME:  GetINIInstallName                                      */
  91. /*                                                                          */
  92. /* DESCRIPTIVE NAME:  Get The INI install name for this device              */
  93. /*                                                                          */
  94. /* FUNCTION:  Get the INI install name for this device.  This install name  */
  95. /*            will be used later to get additional information from the     */
  96. /*            INI file about this device.                                   */
  97. /*                                                                          */
  98. /* PARAMETERS:                                                              */
  99. /*      PINSTANCE pInstance -- pointer to instance.                         */
  100. /*                                                                          */
  101. /****************************************************************************/
  102. VOID  GetINIInstallName(PINSTANCE pInstance)
  103. {
  104.    ULONG ulrc;
  105.    MCI_SYSINFO_PARMS      recSysInfo;
  106.    MCI_SYSINFO_QUERY_NAME recQueryName;
  107.  
  108.    /*****************************/
  109.    /* clear input parameters    */
  110.    /*****************************/
  111.    memset(&recQueryName, 0, sizeof(MCI_SYSINFO_QUERY_NAME));
  112.  
  113.    /*********************************************************/
  114.    /* Get install name for this device based on device type */
  115.    /*   Use the MCI_SYSINFO_QUERY_NAMES to get the MMPM/2   */
  116.    /*   INI file install name.                              */
  117.    /*********************************************************/
  118.    recSysInfo.ulItem       = MCI_SYSINFO_QUERY_NAMES;
  119.    recSysInfo.usDeviceType = pInstance->usDeviceType;
  120.    recSysInfo.pSysInfoParm = &recQueryName;
  121.    recQueryName.usDeviceType = pInstance->usDeviceType;
  122.    recQueryName.usDeviceOrd  = pInstance->usDeviceOrd;
  123.  
  124.    ulrc = mciSendCommand(0, MCI_SYSINFO, MCI_SYSINFO_ITEM | MCI_WAIT,
  125.                        &recSysInfo, 0);
  126.  
  127.    if (!ulrc)
  128.       strcpy(pInstance->szInstallName, recQueryName.szInstallName);
  129.  
  130.    return;
  131.  
  132. }  /* end of GetINIInstallName() */
  133.  
  134. /****************************************************************************/
  135. /*                                                                          */
  136. /* SUBROUTINE NAME:  GetDeviceInfo                                          */
  137. /*                                                                          */
  138. /* DESCRIPTIVE NAME:  Get The device info from INI file                     */
  139. /*                                                                          */
  140. /* FUNCTION:  Get the device info from INI file.                            */
  141. /*            Product Info                                                  */
  142. /*                                                                          */
  143. /* PARAMETERS:                                                              */
  144. /*      PINSTANCE pInstance -- pointer to instance.                         */
  145. /*                                                                          */
  146. /****************************************************************************/
  147. VOID  GetDeviceInfo(PINSTANCE pInstance)
  148. {
  149.    ULONG ulrc;
  150.    MCI_SYSINFO_PARMS      recSysInfo;
  151.    MCI_SYSINFO_LOGDEVICE  recLogDevice;
  152.  
  153.    /**************************/
  154.    /* clear input parameters */
  155.    /**************************/
  156.    memset(&recLogDevice, 0, sizeof(MCI_SYSINFO_LOGDEVICE));
  157.  
  158.    /******************************************************/
  159.    /* Get device info for this device                    */
  160.    /*   this assumes that GetINIInstallName was already  */
  161.    /*   called                                           */
  162.    /******************************************************/
  163.    recSysInfo.ulItem       = MCI_SYSINFO_QUERY_DRIVER;
  164.    recSysInfo.usDeviceType = pInstance->usDeviceType;
  165.    recSysInfo.pSysInfoParm = &recLogDevice;
  166.    strcpy(recLogDevice.szInstallName, pInstance->szInstallName);
  167.  
  168.    ulrc = mciSendCommand(0, MCI_SYSINFO, MCI_SYSINFO_ITEM | MCI_WAIT,
  169.                        &recSysInfo, 0);
  170.  
  171.    if (!ulrc)
  172.       strcpy(pInstance->szProductInfo, recLogDevice.szProductInfo);
  173.  
  174.    return;
  175.  
  176. }  /* end of GetDeviceInfo() */
  177.  
  178.  
  179.  
  180. /****************************************************************************/
  181. /*                                                                          */
  182. /* SUBROUTINE NAME:  ConvertTime                                            */
  183. /*                                                                          */
  184. /* DESCRIPTIVE NAME:  Convert time from one format to another.              */
  185. /*                                                                          */
  186. /* PARAMETERS:                                                              */
  187. /*      PINSTANCE pInstance -- pointer to instance.                         */
  188. /*                                                                          */
  189. /* NOTES: This is just the start of a routine to convert from one time      */
  190. /*        format to another.  You should add and delete to this routine     */
  191. /*        as required by your MCD.                                          */
  192. /*                                                                          */
  193. /****************************************************************************/
  194. ULONG  ConvertTime(ULONG ulTime, ULONG ulCurrentFormat, ULONG ulNewFormat)
  195. {
  196.    ULONG ulrc;
  197.    ULONG ulNewTime=0;
  198.  
  199.    switch (ulCurrentFormat)
  200.       {
  201.       case MCI_FORMAT_MILLISECONDS:                // MILLISECONDS
  202.         switch (ulNewFormat)
  203.            {
  204.            case MCI_FORMAT_MMTIME:                 // MMTIME
  205.               ulNewTime = MSECTOMM(ulTime);
  206.               break;
  207.            default :
  208.               ulNewTime = ulTime;
  209.            }  /* on switch */
  210.  
  211.          break;
  212.       case MCI_FORMAT_MMTIME:                      // MMTIME
  213.         switch (ulNewFormat)
  214.            {
  215.            case MCI_FORMAT_MILLISECONDS:           // MILLISECONDS
  216.               ulNewTime = MSECFROMMM(ulTime);
  217.               break;
  218.            }  /* on switch */
  219.          break;
  220.  
  221.       case MCI_FORMAT_MSF:                    // MINUTE, SECONDS, FRAMES
  222.       case MCI_FORMAT_TMSF:                   // TRACKS, MINUTE, SECONDS, FRAMES
  223.       case MCI_FORMAT_CHAPTERS:               // CHAPTERS
  224.       case MCI_FORMAT_FRAMES:                 // FRAMES
  225.       case MCI_FORMAT_HMS:                    // HOURS, MINUTES, SECONDS
  226.       case MCI_FORMAT_HMSF:                   // HOURS, MINUTES, SECONDS, FRAMES
  227.       case MCI_FORMAT_TRACKS:                 // TRACKS
  228.       case MCI_FORMAT_BYTES:                  // BYTES
  229.       case MCI_FORMAT_SAMPLES:                // SAMPLES
  230.       default :
  231.          ulNewTime = ulTime;
  232.       }  /* on switch */
  233.  
  234.    return(ulNewTime);
  235.  
  236. }  /* end of ConvertTime() */
  237.  
  238.  
  239.  
  240.