include/SDL_cdrom.h
changeset 0 74212992fb08
child 251 b8688cfdc232
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/include/SDL_cdrom.h	Thu Apr 26 16:45:43 2001 +0000
     1.3 @@ -0,0 +1,175 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@devolution.com
    1.24 +*/
    1.25 +
    1.26 +#ifdef SAVE_RCSID
    1.27 +static char rcsid =
    1.28 + "@(#) $Id$";
    1.29 +#endif
    1.30 +
    1.31 +/* This is the CD-audio control API for Simple DirectMedia Layer */
    1.32 +
    1.33 +#ifndef _SDL_cdrom_h
    1.34 +#define _SDL_cdrom_h
    1.35 +
    1.36 +#include "SDL_types.h"
    1.37 +
    1.38 +#include "begin_code.h"
    1.39 +/* Set up for C function definitions, even when using C++ */
    1.40 +#ifdef __cplusplus
    1.41 +extern "C" {
    1.42 +#endif
    1.43 +
    1.44 +/* In order to use these functions, SDL_Init() must have been called
    1.45 +   with the SDL_INIT_CDROM flag.  This causes SDL to scan the system
    1.46 +   for CD-ROM drives, and load appropriate drivers.
    1.47 +*/
    1.48 +
    1.49 +/* The maximum number of CD-ROM tracks on a disk */
    1.50 +#define SDL_MAX_TRACKS	99
    1.51 +
    1.52 +/* The types of CD-ROM track possible */
    1.53 +#define SDL_AUDIO_TRACK	0x00
    1.54 +#define SDL_DATA_TRACK	0x04
    1.55 +
    1.56 +/* The possible states which a CD-ROM drive can be in. */
    1.57 +typedef enum {
    1.58 +	CD_TRAYEMPTY,
    1.59 +	CD_STOPPED,
    1.60 +	CD_PLAYING,
    1.61 +	CD_PAUSED,
    1.62 +	CD_ERROR = -1
    1.63 +} CDstatus;
    1.64 +
    1.65 +/* Given a status, returns true if there's a disk in the drive */
    1.66 +#define CD_INDRIVE(status)	((int)status > 0)
    1.67 +
    1.68 +typedef struct {
    1.69 +	Uint8 id;		/* Track number */
    1.70 +	Uint8 type;		/* Data or audio track */
    1.71 +	Uint16 unused;
    1.72 +	Uint32 length;		/* Length, in frames, of this track */
    1.73 +	Uint32 offset;		/* Offset, in frames, from start of disk */
    1.74 +} SDL_CDtrack;
    1.75 +
    1.76 +/* This structure is only current as of the last call to SDL_CDStatus() */
    1.77 +typedef struct SDL_CD {
    1.78 +	int id;			/* Private drive identifier */
    1.79 +	CDstatus status;	/* Current drive status */
    1.80 +
    1.81 +	/* The rest of this structure is only valid if there's a CD in drive */
    1.82 +	int numtracks;		/* Number of tracks on disk */
    1.83 +	int cur_track;		/* Current track position */
    1.84 +	int cur_frame;		/* Current frame offset within current track */
    1.85 +	SDL_CDtrack track[SDL_MAX_TRACKS+1];
    1.86 +} SDL_CD;
    1.87 +
    1.88 +/* Conversion functions from frames to Minute/Second/Frames and vice versa */
    1.89 +#define CD_FPS	75
    1.90 +#define FRAMES_TO_MSF(f, M,S,F)	{					\
    1.91 +	int value = f;							\
    1.92 +	*(F) = value%CD_FPS;						\
    1.93 +	value /= CD_FPS;						\
    1.94 +	*(S) = value%60;						\
    1.95 +	value /= 60;							\
    1.96 +	*(M) = value;							\
    1.97 +}
    1.98 +#define MSF_TO_FRAMES(M, S, F)	((M)*60*CD_FPS+(S)*CD_FPS+(F))
    1.99 +
   1.100 +/* CD-audio API functions: */
   1.101 +
   1.102 +/* Returns the number of CD-ROM drives on the system, or -1 if
   1.103 +   SDL_Init() has not been called with the SDL_INIT_CDROM flag.
   1.104 + */
   1.105 +extern DECLSPEC int SDL_CDNumDrives(void);
   1.106 +
   1.107 +/* Returns a human-readable, system-dependent identifier for the CD-ROM.
   1.108 +   Example:
   1.109 +	"/dev/cdrom"
   1.110 +	"E:"
   1.111 +	"/dev/disk/ide/1/master"
   1.112 +*/
   1.113 +extern DECLSPEC const char * SDL_CDName(int drive);
   1.114 +
   1.115 +/* Opens a CD-ROM drive for access.  It returns a drive handle on success,
   1.116 +   or NULL if the drive was invalid or busy.  This newly opened CD-ROM
   1.117 +   becomes the default CD used when other CD functions are passed a NULL
   1.118 +   CD-ROM handle.
   1.119 +   Drives are numbered starting with 0.  Drive 0 is the system default CD-ROM.
   1.120 +*/
   1.121 +extern DECLSPEC SDL_CD * SDL_CDOpen(int drive);
   1.122 +
   1.123 +/* This function returns the current status of the given drive.
   1.124 +   If the drive has a CD in it, the table of contents of the CD and current
   1.125 +   play position of the CD will be stored in the SDL_CD structure.
   1.126 +*/
   1.127 +extern DECLSPEC CDstatus SDL_CDStatus(SDL_CD *cdrom);
   1.128 +
   1.129 +/* Play the given CD starting at 'start_track' and 'start_frame' for 'ntracks'
   1.130 +   tracks and 'nframes' frames.  If both 'ntrack' and 'nframe' are 0, play 
   1.131 +   until the end of the CD.  This function will skip data tracks.
   1.132 +   This function should only be called after calling SDL_CDStatus() to 
   1.133 +   get track information about the CD.
   1.134 +   For example:
   1.135 +	// Play entire CD:
   1.136 +	if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
   1.137 +		SDL_CDPlayTracks(cdrom, 0, 0, 0, 0);
   1.138 +	// Play last track:
   1.139 +	if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) {
   1.140 +		SDL_CDPlayTracks(cdrom, cdrom->numtracks-1, 0, 0, 0);
   1.141 +	}
   1.142 +	// Play first and second track and 10 seconds of third track:
   1.143 +	if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
   1.144 +		SDL_CDPlayTracks(cdrom, 0, 0, 2, 10);
   1.145 +
   1.146 +   This function returns 0, or -1 if there was an error.
   1.147 +*/
   1.148 +extern DECLSPEC int SDL_CDPlayTracks(SDL_CD *cdrom,
   1.149 +		int start_track, int start_frame, int ntracks, int nframes);
   1.150 +
   1.151 +/* Play the given CD starting at 'start' frame for 'length' frames.
   1.152 +   It returns 0, or -1 if there was an error.
   1.153 +*/
   1.154 +extern DECLSPEC int SDL_CDPlay(SDL_CD *cdrom, int start, int length);
   1.155 +
   1.156 +/* Pause play -- returns 0, or -1 on error */
   1.157 +extern DECLSPEC int SDL_CDPause(SDL_CD *cdrom);
   1.158 +
   1.159 +/* Resume play -- returns 0, or -1 on error */
   1.160 +extern DECLSPEC int SDL_CDResume(SDL_CD *cdrom);
   1.161 +
   1.162 +/* Stop play -- returns 0, or -1 on error */
   1.163 +extern DECLSPEC int SDL_CDStop(SDL_CD *cdrom);
   1.164 +
   1.165 +/* Eject CD-ROM -- returns 0, or -1 on error */
   1.166 +extern DECLSPEC int SDL_CDEject(SDL_CD *cdrom);
   1.167 +
   1.168 +/* Closes the handle for the CD-ROM drive */
   1.169 +extern DECLSPEC void SDL_CDClose(SDL_CD *cdrom);
   1.170 +
   1.171 +
   1.172 +/* Ends C function definitions when using C++ */
   1.173 +#ifdef __cplusplus
   1.174 +}
   1.175 +#endif
   1.176 +#include "close_code.h"
   1.177 +
   1.178 +#endif /* _SDL_video_h */