00001 /* 00002 SDL - Simple DirectMedia Layer 00003 Copyright (C) 1997-2009 Sam Lantinga 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 00019 Sam Lantinga 00020 slouken@libsdl.org 00021 */ 00022 00029 #ifndef _SDL_cdrom_h 00030 #define _SDL_cdrom_h 00031 00032 #include "SDL_stdinc.h" 00033 #include "SDL_error.h" 00034 00035 #include "begin_code.h" 00036 /* Set up for C function definitions, even when using C++ */ 00037 #ifdef __cplusplus 00038 /* *INDENT-OFF* */ 00039 extern "C" { 00040 /* *INDENT-ON* */ 00041 #endif 00042 00043 /* In order to use these functions, SDL_Init() must have been called 00044 with the SDL_INIT_CDROM flag. This causes SDL to scan the system 00045 for CD-ROM drives, and load appropriate drivers. 00046 */ 00047 00048 /* The maximum number of CD-ROM tracks on a disk */ 00049 #define SDL_MAX_TRACKS 99 00050 00051 /* The types of CD-ROM track possible */ 00052 #define SDL_AUDIO_TRACK 0x00 00053 #define SDL_DATA_TRACK 0x04 00054 00055 /* The possible states which a CD-ROM drive can be in. */ 00056 typedef enum 00057 { 00058 CD_TRAYEMPTY, 00059 CD_STOPPED, 00060 CD_PLAYING, 00061 CD_PAUSED, 00062 CD_ERROR = -1 00063 } CDstatus; 00064 00065 /* Given a status, returns true if there's a disk in the drive */ 00066 #define CD_INDRIVE(status) ((int)(status) > 0) 00067 00068 typedef struct SDL_CDtrack 00069 { 00070 Uint8 id; /* Track number */ 00071 Uint8 type; /* Data or audio track */ 00072 Uint16 unused; 00073 Uint32 length; /* Length, in frames, of this track */ 00074 Uint32 offset; /* Offset, in frames, from start of disk */ 00075 } SDL_CDtrack; 00076 00077 /* This structure is only current as of the last call to SDL_CDStatus() */ 00078 typedef struct SDL_CD 00079 { 00080 int id; /* Private drive identifier */ 00081 CDstatus status; /* Current drive status */ 00082 00083 /* The rest of this structure is only valid if there's a CD in drive */ 00084 int numtracks; /* Number of tracks on disk */ 00085 int cur_track; /* Current track position */ 00086 int cur_frame; /* Current frame offset within current track */ 00087 SDL_CDtrack track[SDL_MAX_TRACKS + 1]; 00088 } SDL_CD; 00089 00090 /* Conversion functions from frames to Minute/Second/Frames and vice versa */ 00091 #define CD_FPS 75 00092 #define FRAMES_TO_MSF(f, M,S,F) { \ 00093 int value = f; \ 00094 *(F) = value%CD_FPS; \ 00095 value /= CD_FPS; \ 00096 *(S) = value%60; \ 00097 value /= 60; \ 00098 *(M) = value; \ 00099 } 00100 #define MSF_TO_FRAMES(M, S, F) ((M)*60*CD_FPS+(S)*CD_FPS+(F)) 00101 00102 /* CD-audio API functions: */ 00103 00104 /* Returns the number of CD-ROM drives on the system, or -1 if 00105 SDL_Init() has not been called with the SDL_INIT_CDROM flag. 00106 */ 00107 extern DECLSPEC int SDLCALL SDL_CDNumDrives(void); 00108 00109 /* Returns a human-readable, system-dependent identifier for the CD-ROM. 00110 Example: 00111 "/dev/cdrom" 00112 "E:" 00113 "/dev/disk/ide/1/master" 00114 */ 00115 extern DECLSPEC const char *SDLCALL SDL_CDName(int drive); 00116 00117 /* Opens a CD-ROM drive for access. It returns a drive handle on success, 00118 or NULL if the drive was invalid or busy. This newly opened CD-ROM 00119 becomes the default CD used when other CD functions are passed a NULL 00120 CD-ROM handle. 00121 Drives are numbered starting with 0. Drive 0 is the system default CD-ROM. 00122 */ 00123 extern DECLSPEC SDL_CD *SDLCALL SDL_CDOpen(int drive); 00124 00125 /* This function returns the current status of the given drive. 00126 If the drive has a CD in it, the table of contents of the CD and current 00127 play position of the CD will be stored in the SDL_CD structure. 00128 */ 00129 extern DECLSPEC CDstatus SDLCALL SDL_CDStatus(SDL_CD * cdrom); 00130 00131 /* Play the given CD starting at 'start_track' and 'start_frame' for 'ntracks' 00132 tracks and 'nframes' frames. If both 'ntrack' and 'nframe' are 0, play 00133 until the end of the CD. This function will skip data tracks. 00134 This function should only be called after calling SDL_CDStatus() to 00135 get track information about the CD. 00136 For example: 00137 // Play entire CD: 00138 if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) 00139 SDL_CDPlayTracks(cdrom, 0, 0, 0, 0); 00140 // Play last track: 00141 if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) { 00142 SDL_CDPlayTracks(cdrom, cdrom->numtracks-1, 0, 0, 0); 00143 } 00144 // Play first and second track and 10 seconds of third track: 00145 if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) 00146 SDL_CDPlayTracks(cdrom, 0, 0, 2, 10); 00147 00148 This function returns 0, or -1 if there was an error. 00149 */ 00150 extern DECLSPEC int SDLCALL SDL_CDPlayTracks(SDL_CD * cdrom, 00151 int start_track, 00152 int start_frame, int ntracks, 00153 int nframes); 00154 00155 /* Play the given CD starting at 'start' frame for 'length' frames. 00156 It returns 0, or -1 if there was an error. 00157 */ 00158 extern DECLSPEC int SDLCALL SDL_CDPlay(SDL_CD * cdrom, int start, int length); 00159 00160 /* Pause play -- returns 0, or -1 on error */ 00161 extern DECLSPEC int SDLCALL SDL_CDPause(SDL_CD * cdrom); 00162 00163 /* Resume play -- returns 0, or -1 on error */ 00164 extern DECLSPEC int SDLCALL SDL_CDResume(SDL_CD * cdrom); 00165 00166 /* Stop play -- returns 0, or -1 on error */ 00167 extern DECLSPEC int SDLCALL SDL_CDStop(SDL_CD * cdrom); 00168 00169 /* Eject CD-ROM -- returns 0, or -1 on error */ 00170 extern DECLSPEC int SDLCALL SDL_CDEject(SDL_CD * cdrom); 00171 00172 /* Closes the handle for the CD-ROM drive */ 00173 extern DECLSPEC void SDLCALL SDL_CDClose(SDL_CD * cdrom); 00174 00175 00176 /* Ends C function definitions when using C++ */ 00177 #ifdef __cplusplus 00178 /* *INDENT-OFF* */ 00179 } 00180 /* *INDENT-ON* */ 00181 #endif 00182 #include "close_code.h" 00183 00184 #endif /* _SDL_video_h */ 00185 00186 /* vi: set ts=4 sw=4 expandtab: */
1.5.8