include/SDL_cdrom.h
author Sam Lantinga <slouken@libsdl.org>
Sat, 26 Sep 2009 23:17:08 +0000
branchSDL-1.2
changeset 4246 8b8314cc34a6
parent 4217 4c4113c2162c
child 6137 4720145f848b
permissions -rw-r--r--
Fixed bug #810

Lauri Kenttä 2009-09-26 06:42:23 PDT

Support for disabling stdio redirect with environment variables.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@4159
     3
    Copyright (C) 1997-2009 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@251
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@0
    22
slouken@4217
    23
/**
slouken@4217
    24
 *  @file SDL_cdrom.h
slouken@4217
    25
 *  This is the CD-audio control API for Simple DirectMedia Layer
slouken@4217
    26
 */
slouken@0
    27
slouken@0
    28
#ifndef _SDL_cdrom_h
slouken@0
    29
#define _SDL_cdrom_h
slouken@0
    30
slouken@1353
    31
#include "SDL_stdinc.h"
slouken@1358
    32
#include "SDL_error.h"
slouken@0
    33
slouken@0
    34
#include "begin_code.h"
slouken@0
    35
/* Set up for C function definitions, even when using C++ */
slouken@0
    36
#ifdef __cplusplus
slouken@0
    37
extern "C" {
slouken@0
    38
#endif
slouken@0
    39
slouken@4217
    40
/**
slouken@4217
    41
 *  @file SDL_cdrom.h
slouken@4217
    42
 *  In order to use these functions, SDL_Init() must have been called
slouken@4217
    43
 *  with the SDL_INIT_CDROM flag.  This causes SDL to scan the system
slouken@4217
    44
 *  for CD-ROM drives, and load appropriate drivers.
slouken@4217
    45
 */
slouken@0
    46
slouken@4217
    47
/** The maximum number of CD-ROM tracks on a disk */
slouken@0
    48
#define SDL_MAX_TRACKS	99
slouken@0
    49
slouken@4217
    50
/** @name Track Types
slouken@4217
    51
 *  The types of CD-ROM track possible
slouken@4217
    52
 */
slouken@4217
    53
/*@{*/
slouken@0
    54
#define SDL_AUDIO_TRACK	0x00
slouken@0
    55
#define SDL_DATA_TRACK	0x04
slouken@4217
    56
/*@}*/
slouken@0
    57
slouken@4217
    58
/** The possible states which a CD-ROM drive can be in. */
slouken@0
    59
typedef enum {
slouken@0
    60
	CD_TRAYEMPTY,
slouken@0
    61
	CD_STOPPED,
slouken@0
    62
	CD_PLAYING,
slouken@0
    63
	CD_PAUSED,
slouken@0
    64
	CD_ERROR = -1
slouken@0
    65
} CDstatus;
slouken@0
    66
slouken@4217
    67
/** Given a status, returns true if there's a disk in the drive */
icculus@1046
    68
#define CD_INDRIVE(status)	((int)(status) > 0)
slouken@0
    69
slouken@911
    70
typedef struct SDL_CDtrack {
slouken@4217
    71
	Uint8 id;		/**< Track number */
slouken@4217
    72
	Uint8 type;		/**< Data or audio track */
slouken@0
    73
	Uint16 unused;
slouken@4217
    74
	Uint32 length;		/**< Length, in frames, of this track */
slouken@4217
    75
	Uint32 offset;		/**< Offset, in frames, from start of disk */
slouken@0
    76
} SDL_CDtrack;
slouken@0
    77
slouken@4217
    78
/** This structure is only current as of the last call to SDL_CDStatus() */
slouken@0
    79
typedef struct SDL_CD {
slouken@4217
    80
	int id;			/**< Private drive identifier */
slouken@4217
    81
	CDstatus status;	/**< Current drive status */
slouken@0
    82
slouken@4217
    83
	/** The rest of this structure is only valid if there's a CD in drive */
slouken@4217
    84
        /*@{*/
slouken@4217
    85
	int numtracks;		/**< Number of tracks on disk */
slouken@4217
    86
	int cur_track;		/**< Current track position */
slouken@4217
    87
	int cur_frame;		/**< Current frame offset within current track */
slouken@0
    88
	SDL_CDtrack track[SDL_MAX_TRACKS+1];
slouken@4217
    89
        /*@}*/
slouken@0
    90
} SDL_CD;
slouken@0
    91
slouken@4217
    92
/** @name Frames / MSF Conversion Functions
slouken@4217
    93
 *  Conversion functions from frames to Minute/Second/Frames and vice versa
slouken@4217
    94
 */
slouken@4217
    95
/*@{*/
slouken@0
    96
#define CD_FPS	75
slouken@0
    97
#define FRAMES_TO_MSF(f, M,S,F)	{					\
slouken@0
    98
	int value = f;							\
slouken@0
    99
	*(F) = value%CD_FPS;						\
slouken@0
   100
	value /= CD_FPS;						\
slouken@0
   101
	*(S) = value%60;						\
slouken@0
   102
	value /= 60;							\
slouken@0
   103
	*(M) = value;							\
slouken@0
   104
}
slouken@0
   105
#define MSF_TO_FRAMES(M, S, F)	((M)*60*CD_FPS+(S)*CD_FPS+(F))
slouken@4217
   106
/*@}*/
slouken@0
   107
slouken@0
   108
/* CD-audio API functions: */
slouken@0
   109
slouken@4217
   110
/**
slouken@4217
   111
 *  Returns the number of CD-ROM drives on the system, or -1 if
slouken@4217
   112
 *  SDL_Init() has not been called with the SDL_INIT_CDROM flag.
slouken@0
   113
 */
slouken@337
   114
extern DECLSPEC int SDLCALL SDL_CDNumDrives(void);
slouken@0
   115
slouken@4217
   116
/**
slouken@4217
   117
 *  Returns a human-readable, system-dependent identifier for the CD-ROM.
slouken@4217
   118
 *  Example:
slouken@4217
   119
 *   - "/dev/cdrom"
slouken@4217
   120
 *   - "E:"
slouken@4217
   121
 *   - "/dev/disk/ide/1/master"
slouken@4217
   122
 */
slouken@337
   123
extern DECLSPEC const char * SDLCALL SDL_CDName(int drive);
slouken@0
   124
slouken@4217
   125
/**
slouken@4217
   126
 *  Opens a CD-ROM drive for access.  It returns a drive handle on success,
slouken@4217
   127
 *  or NULL if the drive was invalid or busy.  This newly opened CD-ROM
slouken@4217
   128
 *  becomes the default CD used when other CD functions are passed a NULL
slouken@4217
   129
 *  CD-ROM handle.
slouken@4217
   130
 *  Drives are numbered starting with 0.  Drive 0 is the system default CD-ROM.
slouken@4217
   131
 */
slouken@337
   132
extern DECLSPEC SDL_CD * SDLCALL SDL_CDOpen(int drive);
slouken@0
   133
slouken@4217
   134
/**
slouken@4217
   135
 *  This function returns the current status of the given drive.
slouken@4217
   136
 *  If the drive has a CD in it, the table of contents of the CD and current
slouken@4217
   137
 *  play position of the CD will be stored in the SDL_CD structure.
slouken@4217
   138
 */
slouken@337
   139
extern DECLSPEC CDstatus SDLCALL SDL_CDStatus(SDL_CD *cdrom);
slouken@0
   140
slouken@4217
   141
/**
slouken@4217
   142
 *  Play the given CD starting at 'start_track' and 'start_frame' for 'ntracks'
slouken@4217
   143
 *  tracks and 'nframes' frames.  If both 'ntrack' and 'nframe' are 0, play 
slouken@4217
   144
 *  until the end of the CD.  This function will skip data tracks.
slouken@4217
   145
 *  This function should only be called after calling SDL_CDStatus() to 
slouken@4217
   146
 *  get track information about the CD.
slouken@4217
   147
 *  For example:
slouken@4217
   148
 *      @code
slouken@4217
   149
 *	// Play entire CD:
slouken@4217
   150
 *	if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
slouken@4217
   151
 *		SDL_CDPlayTracks(cdrom, 0, 0, 0, 0);
slouken@4217
   152
 *	// Play last track:
slouken@4217
   153
 *	if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) {
slouken@4217
   154
 *		SDL_CDPlayTracks(cdrom, cdrom->numtracks-1, 0, 0, 0);
slouken@4217
   155
 *	}
slouken@4217
   156
 *	// Play first and second track and 10 seconds of third track:
slouken@4217
   157
 *	if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
slouken@4217
   158
 *		SDL_CDPlayTracks(cdrom, 0, 0, 2, 10);
slouken@4217
   159
 *      @endcode
slouken@4217
   160
 *
slouken@4217
   161
 *  @return This function returns 0, or -1 if there was an error.
slouken@4217
   162
 */
slouken@337
   163
extern DECLSPEC int SDLCALL SDL_CDPlayTracks(SDL_CD *cdrom,
slouken@0
   164
		int start_track, int start_frame, int ntracks, int nframes);
slouken@0
   165
slouken@4217
   166
/**
slouken@4217
   167
 *  Play the given CD starting at 'start' frame for 'length' frames.
slouken@4217
   168
 *  @return It returns 0, or -1 if there was an error.
slouken@4217
   169
 */
slouken@337
   170
extern DECLSPEC int SDLCALL SDL_CDPlay(SDL_CD *cdrom, int start, int length);
slouken@0
   171
slouken@4217
   172
/** Pause play
slouken@4217
   173
 *  @return returns 0, or -1 on error
slouken@4217
   174
 */
slouken@337
   175
extern DECLSPEC int SDLCALL SDL_CDPause(SDL_CD *cdrom);
slouken@0
   176
slouken@4217
   177
/** Resume play
slouken@4217
   178
 *  @return returns 0, or -1 on error
slouken@4217
   179
 */
slouken@337
   180
extern DECLSPEC int SDLCALL SDL_CDResume(SDL_CD *cdrom);
slouken@0
   181
slouken@4217
   182
/** Stop play
slouken@4217
   183
 *  @return returns 0, or -1 on error
slouken@4217
   184
 */
slouken@337
   185
extern DECLSPEC int SDLCALL SDL_CDStop(SDL_CD *cdrom);
slouken@0
   186
slouken@4217
   187
/** Eject CD-ROM
slouken@4217
   188
 *  @return returns 0, or -1 on error
slouken@4217
   189
 */
slouken@337
   190
extern DECLSPEC int SDLCALL SDL_CDEject(SDL_CD *cdrom);
slouken@0
   191
slouken@4217
   192
/** Closes the handle for the CD-ROM drive */
slouken@337
   193
extern DECLSPEC void SDLCALL SDL_CDClose(SDL_CD *cdrom);
slouken@0
   194
slouken@0
   195
slouken@0
   196
/* Ends C function definitions when using C++ */
slouken@0
   197
#ifdef __cplusplus
slouken@0
   198
}
slouken@0
   199
#endif
slouken@0
   200
#include "close_code.h"
slouken@0
   201
slouken@0
   202
#endif /* _SDL_video_h */