home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v6.zip / MMPM2TK / TK / RECORDER / OPTIONS.C < prev    next >
C/C++ Source or Header  |  1993-03-07  |  19KB  |  543 lines

  1. /******************************************************************************
  2.  * File Name    :  OPTIONS.C
  3.  *
  4.  * Description  :  This file contains the C source code required for the
  5.  *                 Recorder sample program.
  6.  *
  7.  * MMPM/2 API's :  List of all MMPM/2 API's that are used in
  8.  *                 this module
  9.  *
  10.  *                 mmioOpen
  11.  *                 mmioGetHeader
  12.  *                 mmioClose
  13.  *
  14.  * Copyright (C) IBM 1993
  15.  ******************************************************************************/
  16.  
  17. #define  INCL_WIN                      /* required to use Win APIs.           */
  18. #define  INCL_PM                       /* required to use PM APIs.            */
  19. #define  INCL_OS2MM                 /* required for MCI and MMIO headers   */
  20.  
  21. #include <os2.h>
  22. #include <os2me.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25.  
  26. #include "recorder.h"
  27.  
  28. /*
  29.  * Procedure/Function Prototypes
  30.  */
  31. VOID    EnableTheOption( USHORT idOption );
  32. VOID    DisableTheOption( HWND hwndMenu, USHORT idOption );
  33.  
  34. extern  HWND hwndMenu;
  35. extern  HWND hwndFrame;
  36. extern  HAB  hab;
  37. /******************************************************************************
  38.  * Name         : SelectTheOption
  39.  *
  40.  * Description  : This procedure will select the menu pulldown option.
  41.  *
  42.  * Concepts     : None.
  43.  *
  44.  * MMPM/2 API's : None.
  45.  *
  46.  * Parameters   : idOption - Id for the selected menu pulldown option.
  47.  *
  48.  * Return       : None.
  49.  *
  50.  ******************************************************************************/
  51. VOID  SelectTheOption( USHORT idOption )
  52. {
  53.    USHORT   usAttrib;
  54.  
  55.    /*
  56.     * Query the selected menu pulldown to get their current state...
  57.     */
  58.    usAttrib = (USHORT) WinSendMsg( hwndMenu,
  59.                                    MM_QUERYITEMATTR,
  60.                                    MPFROM2SHORT(idOption, TRUE),
  61.                                    MPFROMSHORT(MIA_CHECKED));
  62.    if (!(usAttrib & MIA_CHECKED))
  63.    {
  64.       /*
  65.        * Selected option was not in selected state, set the attribute and
  66.        * select it.
  67.        */
  68.       usAttrib ^= MIA_CHECKED;
  69.       WinSendMsg( hwndMenu,
  70.                   MM_SETITEMATTR,
  71.                   MPFROM2SHORT( idOption, TRUE),
  72.                   MPFROM2SHORT( MIA_CHECKED, usAttrib ) );
  73.    }
  74.    return;
  75. }
  76.  
  77. /******************************************************************************
  78.  * Name         : DeselectTheOption
  79.  *
  80.  * Description  : This procedure will deselect the menu pulldown option.
  81.  *
  82.  * Concepts     : None.
  83.  *
  84.  * MMPM/2 API's : None.
  85.  *
  86.  * Parameters   : idOption - Id for the selected menu pulldown option.
  87.  *
  88.  * Return       : None.
  89.  *
  90.  ******************************************************************************/
  91. VOID  DeselectTheOption( USHORT idOption )
  92. {
  93.    USHORT   usAttrib;
  94.  
  95.    /*
  96.     * Query the selected menu pulldown to get their current state...
  97.     */
  98.    usAttrib = (USHORT) WinSendMsg( hwndMenu,
  99.                                    MM_QUERYITEMATTR,
  100.                                    MPFROM2SHORT(idOption, TRUE),
  101.                                    MPFROMSHORT(MIA_CHECKED));
  102.    if (usAttrib & MIA_CHECKED)
  103.    {
  104.       /*
  105.        * Selected option was in selected state, set the attribute and
  106.        * deselect it.
  107.        */
  108.       usAttrib ^= MIA_CHECKED;
  109.       WinSendMsg( hwndMenu,
  110.                   MM_SETITEMATTR,
  111.                   MPFROM2SHORT( idOption, TRUE),
  112.                   MPFROM2SHORT( MIA_CHECKED, usAttrib ) );
  113.    }
  114.    return;
  115. }
  116.  
  117.  
  118. /******************************************************************************
  119.  * Name         : DisableTheOption
  120.  *
  121.  * Description  : This procedure will disable the menu pulldown option.
  122.  *
  123.  * Concepts     : None.
  124.  *
  125.  * MMPM/2 API's : None.
  126.  *
  127.  * Parameters   : hwndMenu - handle for the menu.
  128.  *                idOption - Id for the selected menu pulldown option.
  129.  *
  130.  * Return       : None.
  131.  *
  132.  ******************************************************************************/
  133. VOID  DisableTheOption( HWND hwndMenu, USHORT idOption )
  134. {
  135.    USHORT   usAttrib;
  136.  
  137.    /*
  138.     * Query the selected menu pulldown to get their current state...
  139.     */
  140.    usAttrib = (USHORT) WinSendMsg( hwndMenu,
  141.                                    MM_QUERYITEMATTR,
  142.                                    MPFROM2SHORT(idOption, TRUE),
  143.                                    MPFROMSHORT(MIA_DISABLED));
  144.    if (!(usAttrib & MIA_DISABLED))
  145.    {
  146.       /*
  147.        * Selected option was in enable state, set the attribute and
  148.        * disable it.
  149.        */
  150.       usAttrib ^= MIA_DISABLED;
  151.       WinSendMsg( hwndMenu,
  152.                   MM_SETITEMATTR,
  153.                   MPFROM2SHORT( idOption, TRUE ),
  154.                   MPFROM2SHORT( MIA_DISABLED, usAttrib));
  155.    }
  156.    return;
  157. }
  158.  
  159.  
  160. /******************************************************************************
  161.  * Name         : EnableTheOption
  162.  *
  163.  * Description  : This procedure will enable the menu pulldown option.
  164.  *
  165.  * Concepts     : None.
  166.  *
  167.  * MMPM/2 API's : None.
  168.  *
  169.  * Parameters   : idOption - Id for the selected menu pulldown option.
  170.  *
  171.  * Return       : None.
  172.  *
  173.  ******************************************************************************/
  174. VOID  EnableTheOption( USHORT idOption )
  175. {
  176.    USHORT   usAttrib;
  177.  
  178.    /*
  179.     * Query the selected menu pulldown to get their current state...
  180.     */
  181.    usAttrib = (USHORT) WinSendMsg( hwndMenu,
  182.                                    MM_QUERYITEMATTR,
  183.                                    MPFROM2SHORT(idOption, TRUE),
  184.                                    MPFROMSHORT(MIA_DISABLED));
  185.    if (usAttrib & MIA_DISABLED)
  186.    {
  187.       /*
  188.        * Selected option was in disable state, set the attribute and
  189.        * enable it.
  190.        */
  191.       usAttrib ^= MIA_DISABLED;
  192.       WinSendMsg( hwndMenu,
  193.                   MM_SETITEMATTR,
  194.                   MPFROM2SHORT( idOption, TRUE ),
  195.                   MPFROM2SHORT( MIA_DISABLED, usAttrib));
  196.    }
  197.    return;
  198. }
  199.  
  200.  
  201. /******************************************************************************
  202.  *  Name          : SetTheOptions
  203.  *
  204.  *  Description   : If the user selected an existing file, this procedure
  205.  *                  will do the following:
  206.  *                    -  get the file header information.
  207.  *                    -  sets checkmarks on the appropriate type menu options.
  208.  *                    -  disable the other type menu options.
  209.  *
  210.  *                  If the user selected a new file, this procedure will do
  211.  *                  the following:
  212.  *                    -  Enable the disabled type menu options.
  213.  *                    -  Deselect the selected type menu options.
  214.  *                    -  Select the default type menu options.
  215.  *
  216.  *  MMPM/2 API's : mmioOpen
  217.  *                 mmioGetHeader
  218.  *
  219.  *  Parameters   : fSelectedFileType :  Selected file type - new/existing.
  220.  *
  221.  * Return        :  TRUE  -  if there is no error
  222.  *                  FALSE -  if there is an error
  223.  *
  224. \******************************************************************************/
  225. BOOL SetTheOptions( BOOL fSelectedFileType )
  226. {
  227.     ULONG         rc;                   /* for return code                    */
  228.     HMMIO         hmmio;                /* Handle to the currently loaded file*/
  229.     ULONG         lHeaderLength;        /* for header length                  */
  230.     LONG          lBytes;               /* used for mmioGetheader api         */
  231.     MMAUDIOHEADER mmAudioHeader;        /* WAVE header structure              */
  232.  
  233.     extern CHAR szFileName[FILE_NAME_SIZE];/* for fully qualified file name   */
  234.     extern BOOL    fMonoSupported;                /* Dev supports mono files   */
  235.     extern BOOL    fStereoSupported;              /* Dev supports stereo files */
  236.     extern BOOL    fVoiceSupported;               /* Dev supports 11 kHz files */
  237.     extern BOOL    fMusicSupported;               /* Dev supports 22 kHz files */
  238.     extern BOOL    fHiFiSupported;                /* Dev supports 44 kHz files */
  239.     extern BOOL    fHighQualitySupported;         /* Dev supports 16 bps files */
  240.     extern BOOL    fLoQualitySupported;           /* Dev supports 8 bps files  */
  241.  
  242.  
  243.     if (fSelectedFileType != NEW_FILE)
  244.     {
  245.        /*
  246.         * Selected file is an EXISTING file. Open the file get the header
  247.         * information.
  248.         */
  249.        hmmio = mmioOpen( szFileName, (PMMIOINFO)NULL, MMIO_READWRITE );
  250.        if (!hmmio)
  251.        {
  252.           MessageBox( IDS_CANNOT_OPEN_INPUT_FILE,   /* ID of the message          */
  253.                       MB_OK | MB_INFORMATION  | MB_MOVEABLE);    /* style         */
  254.           return( FALSE );
  255.        }
  256.  
  257.        /*
  258.         * Get the header information from the selected file.
  259.         */
  260.        lHeaderLength = sizeof(MMAUDIOHEADER);
  261.        rc = mmioGetHeader( hmmio,
  262.                            (PVOID)&mmAudioHeader,
  263.                            lHeaderLength,
  264.                            (PLONG)&lBytes,
  265.                            (ULONG) NULL,
  266.                            (ULONG) NULL );
  267.        if (rc)
  268.        {
  269.           MessageBox( IDS_MMIO_GET_HEADER_FAIL,     /* ID of the message          */
  270.                       MB_OK | MB_INFORMATION  | MB_MOVEABLE);    /* style         */
  271.           return( FALSE );
  272.        }
  273.     }
  274.  
  275.     /*
  276.      * Before setting the correct selctions, enable the disbled items
  277.      * in the menu pulldown and deselect the selected items.
  278.      */
  279.     if (fMonoSupported)           EnableTheOption( IDM_MONO );
  280.     if (fStereoSupported)         EnableTheOption( IDM_STEREO );
  281.     if (fVoiceSupported)          EnableTheOption( IDM_VOICE );
  282.     if (fMusicSupported)          EnableTheOption( IDM_MUSIC );
  283.     if (fHiFiSupported)           EnableTheOption( IDM_HIGH_FIDELITY );
  284.     if (fLoQualitySupported)      EnableTheOption( IDM_LOW_QUALITY );
  285.     if (fHighQualitySupported)    EnableTheOption( IDM_HIGH_QUALITY );
  286.     DeselectTheOption( IDM_MONO );
  287.     DeselectTheOption( IDM_VOICE );
  288.     DeselectTheOption( IDM_MUSIC );
  289.     DeselectTheOption( IDM_HIGH_FIDELITY );
  290.     DeselectTheOption( IDM_LOW_QUALITY );
  291.     DeselectTheOption( IDM_STEREO );
  292.     DeselectTheOption( IDM_HIGH_QUALITY );
  293.  
  294.     if (fSelectedFileType != NEW_FILE)
  295.     {
  296.        /*
  297.         * Selected file is an EXISTING file. Check the header information
  298.         * and check the appropriate item.
  299.         */
  300.        if ( mmAudioHeader.mmXWAVHeader.WAVEHeader.usChannels == 1 )
  301.        {
  302.           /*
  303.            * Selected file is using only channel. Select the "Mono" menu option.
  304.            * Disable the "Stereo" menu option.
  305.            */
  306.           SelectTheOption( IDM_MONO );
  307.           DisableTheOption( hwndMenu, IDM_STEREO );
  308.        }
  309.        else
  310.        if ( mmAudioHeader.mmXWAVHeader.WAVEHeader.usChannels == 2 )
  311.        {
  312.           /*
  313.            * Selected file is using both the channel. Select the "Stereo" menu
  314.            * option. Disable the "Mono" menu option.
  315.            */
  316.           SelectTheOption( IDM_STEREO );
  317.           DisableTheOption( hwndMenu, IDM_MONO );
  318.        }
  319.  
  320.        if (mmAudioHeader.mmXWAVHeader.WAVEHeader.ulSamplesPerSec == 11025)
  321.        {
  322.           /*
  323.            * Selected file sampling rate is 11.025 kHz. Select "Voice (11 khz)"
  324.            * menu option. Disable the "Music (22 khz)" and
  325.            * "High fidelity (44 khz)" menu options.
  326.            */
  327.           SelectTheOption( IDM_VOICE );
  328.           DisableTheOption( hwndMenu, IDM_MUSIC );
  329.           DisableTheOption( hwndMenu, IDM_HIGH_FIDELITY );
  330.        }
  331.        else
  332.        if (mmAudioHeader.mmXWAVHeader.WAVEHeader.ulSamplesPerSec == 22050)
  333.        {
  334.           /*
  335.            * Selected file sampling rate is 22.050 kHz. Select "Music (22 khz)"
  336.            * menu option. Disable the "Voice (11 khz)" and
  337.            * "High fidelity (44 khz)" menu options.
  338.            */
  339.           SelectTheOption( IDM_MUSIC );
  340.           DisableTheOption( hwndMenu, IDM_VOICE );
  341.           DisableTheOption( hwndMenu, IDM_HIGH_FIDELITY );
  342.        }
  343.        else
  344.        if (mmAudioHeader.mmXWAVHeader.WAVEHeader.ulSamplesPerSec == 44100)
  345.        {
  346.           /*
  347.            * Selected file sampling rate is 44.100 kHz. Select "High fidelity
  348.            * 44 khz" menu option. Disable the "Voice (11 khz)" and
  349.            * "Music (22 khz)" menu options.
  350.            */
  351.           SelectTheOption( IDM_HIGH_FIDELITY );
  352.           DisableTheOption( hwndMenu, IDM_VOICE );
  353.           DisableTheOption( hwndMenu, IDM_MUSIC );
  354.        }
  355.  
  356.        if (mmAudioHeader.mmXWAVHeader.WAVEHeader.usBitsPerSample == 8)
  357.        {
  358.           /*
  359.            * Selected file bits per sample is 8. Select "Low quality (8-bit)"
  360.            * menu option. Disable the "High quality (16-bit)" menu option.
  361.            */
  362.           SelectTheOption( IDM_LOW_QUALITY );
  363.           DisableTheOption( hwndMenu, IDM_HIGH_QUALITY );
  364.        }
  365.        else
  366.        if (mmAudioHeader.mmXWAVHeader.WAVEHeader.usBitsPerSample == 16)
  367.        {
  368.           /*
  369.            * Selected file bits per sample is 16. Select "High quality (16-bit)"
  370.            * menu option. Disable the "Low quality (8-bit)" menu option.
  371.            */
  372.           SelectTheOption( IDM_HIGH_QUALITY );
  373.           DisableTheOption( hwndMenu, IDM_LOW_QUALITY );
  374.        }
  375.     }
  376.     else
  377.     {
  378.        /*
  379.         * Selected file is a NEW file. Select all the default menu options.
  380.         */
  381.        SelectTheOption( IDM_STEREO );
  382.        SelectTheOption( IDM_MUSIC );
  383.        SelectTheOption( IDM_LOW_QUALITY );
  384.     }
  385.     mmioClose( hmmio, 0 );
  386.     return( TRUE );
  387.  
  388. }   /* end GetHeader() */
  389.  
  390. /******************************************************************************
  391.  * Name         :  AdjustTheDlg
  392.  *
  393.  * Description  :  This fuction adjusts the main dialog window whenever the
  394.  *                 status line is added or deleted.
  395.  *
  396.  * Concepts     :
  397.  *
  398.  * MMPM/2 API's :  none
  399.  *
  400.  * Parameters   :  fShow - flag for selection/deselection of the Status line.
  401.  *
  402.  * Return       :  none
  403.  *
  404.  ******************************************************************************/
  405. VOID AdjustTheDlg( HWND hwnd, BOOL fShow )
  406. {
  407.    SWP    swpFrame;                /* frame window positioning.               */
  408.    SWP    swpDefault;              /* default window positioning.             */
  409.    SWP    swpDialog;               /* dialog window positioning.              */
  410.    SWP    swpStatus;               /* status line window positioning.         */
  411.    static ULONG ulcyDialog = 0 ;   /* height of the dialog window.            */
  412.    BOOL   fAtDefaultSize = FALSE ; /* flag to determine the size of the window*/
  413.  
  414.  
  415.    /*
  416.     * Get the current frame window and the default frame window sizes.
  417.     */
  418.    WinQueryWindowPos( hwndFrame, &swpFrame ) ;
  419.    WinQueryDefaultSize( hwndFrame, &swpDefault ) ;
  420.  
  421.    /*
  422.     * Set the flag to determine whether we were at the default size.
  423.     */
  424.    if (swpFrame.cx==swpDefault.cx && swpFrame.cy==swpDefault.cy)
  425.    {
  426.       fAtDefaultSize = TRUE ;
  427.    }
  428.  
  429.    /*
  430.     * Query the window size and position of the Dialog window.
  431.     */
  432.    WinQueryWindowPos( hwnd, &swpDialog ) ;
  433.  
  434.    /*
  435.     * Save the current height of the Dialog window for further use.
  436.     */
  437.    if (!ulcyDialog)
  438.    {
  439.       ulcyDialog = swpDialog.cy ;
  440.    }
  441.  
  442.    /*
  443.     * Check to see the user selecting or deselecting the "Show status line"
  444.     * option.
  445.     */
  446.    if (fShow)
  447.    {
  448.       /*
  449.        * Status line is desired, raise dialog window height to ensure status
  450.        * is visible
  451.        */
  452.       swpDialog.cy = ulcyDialog ;
  453.    }
  454.    else
  455.    {
  456.       /*
  457.        * Status line is not desired, query the size and position of the
  458.        * "status text line" and lower dialog height to hide status line.
  459.        */
  460.       WinQueryWindowPos(
  461.          WinWindowFromID(
  462.             hwnd,                                 /* Dialog window handle     */
  463.             ID_STATUSTXT),                        /* Status text ID           */
  464.          &swpStatus );                            /* Return status text data  */
  465.       swpDialog.cy = swpStatus.y ;
  466.    }
  467.    /*
  468.     * Set the positioning of the Dialog window.
  469.     */
  470.    WinSetWindowPos(
  471.          hwnd,                           /* Dialog window handle              */
  472.          0L,                             /* Place hwnd on top of all siblings */
  473.          0L,                             /* Window position, x coordinate     */
  474.          0L,                             /* Window position, y coordinate     */
  475.          swpDialog.cx,                   /* New window size                   */
  476.          swpDialog.cy,                   /* New window size                   */
  477.          SWP_SIZE ) ;                    /* Window positioning options        */
  478.  
  479.    if (fAtDefaultSize)
  480.    {
  481.       /*
  482.        * Current window is at default size. Repaint the window with new
  483.        * window size.
  484.        */
  485.       WinDefaultSize(hwnd) ;
  486.    }
  487.    else
  488.    {
  489.       /*
  490.        * Current window is NOT at default size. Just update the window to
  491.        * hide the status line.
  492.        */
  493.       WinUpdateWindow(hwnd);
  494.    }
  495. }  /* End AdjustTheDlg() */
  496.  
  497. /******************************************************************************
  498.  * Name         :  UpdateTheStatusLine
  499.  *
  500.  * Description  :  This function update the status line text.
  501.  *
  502.  * Concepts     :  none
  503.  *
  504.  * MMPM/2 API's :  none
  505.  *
  506.  * Parameters   :  hwnd     -  Handle for the dialog window.
  507.  *                 usStatus -  Status line text to display.
  508.  *
  509.  * Return       :  none
  510.  *
  511.  ******************************************************************************/
  512. VOID UpdateTheStatusLine( HWND hwnd, USHORT usStatus )
  513. {
  514.    CHAR szStatus[50];                   /* to store string from the resource. */
  515.    CHAR szTemp[50];                     /* to store string from the resource. */
  516.    extern BOOL fPassedDevice;           /* for MCI_ACQUIRE to play the file.  */
  517.  
  518.    /*
  519.     * Get the appropriate string from the Resource string table.
  520.     */
  521.    WinLoadString( hab, (HMODULE)NULL, usStatus, sizeof(szStatus), szStatus );
  522.  
  523.    /*
  524.     * If lost the device, inform the user by appending "Suspended" to the
  525.     * current string.
  526.     */
  527.    if ( fPassedDevice )
  528.    {
  529.       /*
  530.        * Get the "Suspended" string from the Resource string table.
  531.        */
  532.       WinLoadString( hab, (HMODULE)NULL, IDS_PASSED, sizeof(szTemp), szTemp );
  533.  
  534.       strcat( szStatus, ", ");              /* append ", " to the status      */
  535.       strcat( szStatus, szTemp );           /* Append "Suspended" at the end. */
  536.    }
  537.    /*
  538.     * Update the status line.
  539.     */
  540.    WinSetWindowText (WinWindowFromID (hwnd, ID_STATUSTXT), szStatus);
  541.  
  542. }  /* End if status line should be shown */
  543.