home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: SysTools / SysTools.zip / sysba021.zip / SRC.ZIP / sysbar2 / CD_Player / CDengine.h < prev    next >
C/C++ Source or Header  |  2003-01-03  |  6KB  |  192 lines

  1. /*
  2.  
  3.   SysBar/2 Utility Set  version 0.21
  4.  
  5.   CD-player engine for IOCtl -- definitions
  6.  
  7.   ..................................................................
  8.  
  9.   Copyright (c) 1995-1999  Dmitry I. Platonoff <dip@platonoff.com>
  10.   Copyright (c) 2002,03    Max Alekseyev       <relf@os2.ru>
  11.  
  12.                            All rights reserved
  13.  
  14.   ..................................................................
  15.  
  16.   LICENSE
  17.   ~~~~~~~
  18.   Redistribution and use in source and binary forms, with or without
  19.   modification, are permitted provided that the following conditions
  20.   are met:
  21.  
  22.   1. Redistributions of source code must retain the above copyright
  23.      notice, this list of conditions and the following disclaimer.
  24.  
  25.   2. Redistributions in binary form must reproduce the above
  26.      copyright notice, this list of conditions and the following
  27.      disclaimer in the documentation and/or other materials provided
  28.      with the distribution.
  29.  
  30.   3. Redistributions of any form whatsoever, as well as all
  31.      advertising materials mentioning features or use of this
  32.      software (if any), must include the following acknowledgment:
  33.      "This product includes software developed by Dmitry I. Platonoff".
  34.  
  35.   4. The names "SysBar/2" and "Dmitry I. Platonoff" must not be
  36.      used to endorse or promote products derived from this software
  37.      without prior written permission. For such permission, please
  38.      contact dplatonoff@canada.com.
  39.  
  40.   5. Products derived from this software may not be called
  41.      "SysBar/2" nor may "Dmitry I. Platonoff" appear in their
  42.      contributor lists without prior written permission.
  43.  
  44.   ..................................................................
  45.  
  46.   DISCLAIMER
  47.   ~~~~~~~~~~
  48.   THIS SOFTWARE IS PROVIDED BY THE AUTHOR OR CONTRIBUTORS "AS IS"
  49.   AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  50.   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  51.   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  52.   AUTHOR OR THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  53.   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  54.   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  55.   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  56.   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  57.   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  58.   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  59.   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  60.  
  61. */
  62.  
  63. #pragma pack(1)
  64.  
  65. #define INCL_DOSDEVICES
  66. #define INCL_DOSDEVIOCTL
  67. #include <os2.h>
  68.  
  69.  
  70. // CD device finder ----------------------------------------------------------
  71. typedef struct _CDROMDeviceMap
  72. {
  73.   USHORT usDriveCount;
  74.   USHORT usFirstLetter;
  75. } CDROMDeviceMap;
  76.  
  77. // Fills CDROMDeviceMap structure and returns the number of CD-ROMs found.
  78. extern int CDDeviceFinder( CDROMDeviceMap& CDMap );
  79.  
  80.  
  81.  
  82. // CD Drive class ------------------------------------------------------------
  83. typedef struct _CDTrack
  84. {
  85.   short int iTrackNumber;  // "official" track number from TOC (1, 2, ...)
  86.   short int bPlayable;     // TRUE for audio tracks
  87.   ULONG ulStartingTime;    // track starting time (MSF)
  88.   ULONG ulEndingTime;      // track ending time (starting time of next track)
  89. } CDTrack;
  90.  
  91. enum CDStatuses
  92. {
  93.   CDS_TrayOpened,
  94.   CDS_NoMedia,
  95.   CDS_MediaPresent,
  96.   CDS_Playing,
  97.   CDS_Paused
  98. };
  99.  
  100. enum CDStatusChanges
  101. {
  102.   CDS_Unchanged,
  103.   CDS_MediaInserted,
  104.   CDS_MediaRemoved,
  105.   CDS_PlayingStarted,
  106.   CDS_PlayingStopped,
  107.   CDS_PositionChanged,
  108.   CDS_TrackChanged
  109. };
  110.  
  111. class CDDrive
  112. {
  113. protected:
  114.   void FillDevice( void );
  115.   APIRET TrayAction( UCHAR ucCommand );
  116.   int AdjustTrack( void );
  117.  
  118. public:
  119.   HFILE hCD;                // device handle (used only for audio CDs)
  120.   char szDevice[3];         // drive name (e.g. "D:")
  121.  
  122.   USHORT usDrive;           // drive index (0 - A:, 1 - B:, etc.)
  123.   CDStatuses usStatus;      // current device status
  124.   ULONG ulCurrentPosition;  // current head position (MSF)
  125.   USHORT iCurrentTrack;     // current track
  126.   CDTrack *Tracks;          // tracks
  127.   int iTrackCount;          // track count
  128.   int iFirstTrack;          // first track #
  129.  
  130.   // Constructor. Initialized with the drive letter.
  131.   CDDrive( USHORT usDriveLetter );
  132.  
  133.   // Destructor. Calls Close().
  134.   ~CDDrive( void );
  135.  
  136.  
  137.   // Device status checked. To call from parallel independent thread.
  138.   CDStatusChanges CheckStatus( void );
  139.  
  140.  
  141.     // Opens the device, reads the TOC and fills Tracks array of
  142.    //   closes the device if no playable tracks has been detected.
  143.   //    Called by CheckStatus() when a CD insertion detected.
  144.   APIRET Open( void );
  145.  
  146.   // Stops playing and closes the device.
  147.   APIRET Close( void );
  148.  
  149.  
  150.   // Stops playing and ejects disk (or empty tray).
  151.   APIRET EjectTray( void );
  152.  
  153.   // Loads tray
  154.   APIRET LoadTray( void );
  155.  
  156.  
  157.    // Stops playing, positions to the given track and resumes playing.
  158.   //   (if played before).
  159.   APIRET SkipToTrack( int iTrack );
  160.  
  161.   // Calls SkipToTrack() with the next playable track index.
  162.   APIRET NextTrack( void );
  163.  
  164.   // Calls SkipToTrack() with the previous playable track index.
  165.   APIRET PrevTrack( void );
  166.  
  167.  
  168.   // Stops playing.
  169.   APIRET Pause( void );
  170.  
  171.   // Starts playing from the beginning of current track.
  172.   APIRET Play( void );
  173.  
  174.   // Resumes playing from the current position.
  175.   APIRET Resume( void );
  176.  
  177.   // Positions to the given location.
  178.   APIRET Seek( ULONG ulPosition );
  179.  
  180.   // Calls Pause() and then positions to the first playable track.
  181.   APIRET Stop( void );
  182.  
  183.   // if true, shuffle tracks; if false, order them
  184.   void Shuffle( bool );
  185.  
  186.   // MSF calculations.
  187.   static ULONG MSFAdd( ULONG ulValue1, ULONG ulValue2 );
  188.   static ULONG MSFSub( ULONG ulValue1, ULONG ulValue2 );
  189. };
  190.  
  191.  
  192.