include/SDL_cdrom.h
author Sam Lantinga <slouken@libsdl.org>
Wed, 01 Feb 2006 06:32:25 +0000
changeset 1312 c9b51268668f
parent 1046 f09d5edfc7a3
child 1353 7ba544e2888d
permissions -rw-r--r--
Updated copyright information and removed rcs id lines (problematic in branch merges)
I batch edited these files, so please let me know if I've accidentally removed anybody's
credit here.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 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@0
    23
/* This is the CD-audio control API for Simple DirectMedia Layer */
slouken@0
    24
slouken@0
    25
#ifndef _SDL_cdrom_h
slouken@0
    26
#define _SDL_cdrom_h
slouken@0
    27
slouken@0
    28
#include "SDL_types.h"
slouken@0
    29
slouken@0
    30
#include "begin_code.h"
slouken@0
    31
/* Set up for C function definitions, even when using C++ */
slouken@0
    32
#ifdef __cplusplus
slouken@0
    33
extern "C" {
slouken@0
    34
#endif
slouken@0
    35
slouken@0
    36
/* In order to use these functions, SDL_Init() must have been called
slouken@0
    37
   with the SDL_INIT_CDROM flag.  This causes SDL to scan the system
slouken@0
    38
   for CD-ROM drives, and load appropriate drivers.
slouken@0
    39
*/
slouken@0
    40
slouken@0
    41
/* The maximum number of CD-ROM tracks on a disk */
slouken@0
    42
#define SDL_MAX_TRACKS	99
slouken@0
    43
slouken@0
    44
/* The types of CD-ROM track possible */
slouken@0
    45
#define SDL_AUDIO_TRACK	0x00
slouken@0
    46
#define SDL_DATA_TRACK	0x04
slouken@0
    47
slouken@0
    48
/* The possible states which a CD-ROM drive can be in. */
slouken@0
    49
typedef enum {
slouken@0
    50
	CD_TRAYEMPTY,
slouken@0
    51
	CD_STOPPED,
slouken@0
    52
	CD_PLAYING,
slouken@0
    53
	CD_PAUSED,
slouken@0
    54
	CD_ERROR = -1
slouken@0
    55
} CDstatus;
slouken@0
    56
slouken@0
    57
/* Given a status, returns true if there's a disk in the drive */
icculus@1046
    58
#define CD_INDRIVE(status)	((int)(status) > 0)
slouken@0
    59
slouken@911
    60
typedef struct SDL_CDtrack {
slouken@0
    61
	Uint8 id;		/* Track number */
slouken@0
    62
	Uint8 type;		/* Data or audio track */
slouken@0
    63
	Uint16 unused;
slouken@0
    64
	Uint32 length;		/* Length, in frames, of this track */
slouken@0
    65
	Uint32 offset;		/* Offset, in frames, from start of disk */
slouken@0
    66
} SDL_CDtrack;
slouken@0
    67
slouken@0
    68
/* This structure is only current as of the last call to SDL_CDStatus() */
slouken@0
    69
typedef struct SDL_CD {
slouken@0
    70
	int id;			/* Private drive identifier */
slouken@0
    71
	CDstatus status;	/* Current drive status */
slouken@0
    72
slouken@0
    73
	/* The rest of this structure is only valid if there's a CD in drive */
slouken@0
    74
	int numtracks;		/* Number of tracks on disk */
slouken@0
    75
	int cur_track;		/* Current track position */
slouken@0
    76
	int cur_frame;		/* Current frame offset within current track */
slouken@0
    77
	SDL_CDtrack track[SDL_MAX_TRACKS+1];
slouken@0
    78
} SDL_CD;
slouken@0
    79
slouken@0
    80
/* Conversion functions from frames to Minute/Second/Frames and vice versa */
slouken@0
    81
#define CD_FPS	75
slouken@0
    82
#define FRAMES_TO_MSF(f, M,S,F)	{					\
slouken@0
    83
	int value = f;							\
slouken@0
    84
	*(F) = value%CD_FPS;						\
slouken@0
    85
	value /= CD_FPS;						\
slouken@0
    86
	*(S) = value%60;						\
slouken@0
    87
	value /= 60;							\
slouken@0
    88
	*(M) = value;							\
slouken@0
    89
}
slouken@0
    90
#define MSF_TO_FRAMES(M, S, F)	((M)*60*CD_FPS+(S)*CD_FPS+(F))
slouken@0
    91
slouken@0
    92
/* CD-audio API functions: */
slouken@0
    93
slouken@0
    94
/* Returns the number of CD-ROM drives on the system, or -1 if
slouken@0
    95
   SDL_Init() has not been called with the SDL_INIT_CDROM flag.
slouken@0
    96
 */
slouken@337
    97
extern DECLSPEC int SDLCALL SDL_CDNumDrives(void);
slouken@0
    98
slouken@0
    99
/* Returns a human-readable, system-dependent identifier for the CD-ROM.
slouken@0
   100
   Example:
slouken@0
   101
	"/dev/cdrom"
slouken@0
   102
	"E:"
slouken@0
   103
	"/dev/disk/ide/1/master"
slouken@0
   104
*/
slouken@337
   105
extern DECLSPEC const char * SDLCALL SDL_CDName(int drive);
slouken@0
   106
slouken@0
   107
/* Opens a CD-ROM drive for access.  It returns a drive handle on success,
slouken@0
   108
   or NULL if the drive was invalid or busy.  This newly opened CD-ROM
slouken@0
   109
   becomes the default CD used when other CD functions are passed a NULL
slouken@0
   110
   CD-ROM handle.
slouken@0
   111
   Drives are numbered starting with 0.  Drive 0 is the system default CD-ROM.
slouken@0
   112
*/
slouken@337
   113
extern DECLSPEC SDL_CD * SDLCALL SDL_CDOpen(int drive);
slouken@0
   114
slouken@0
   115
/* This function returns the current status of the given drive.
slouken@0
   116
   If the drive has a CD in it, the table of contents of the CD and current
slouken@0
   117
   play position of the CD will be stored in the SDL_CD structure.
slouken@0
   118
*/
slouken@337
   119
extern DECLSPEC CDstatus SDLCALL SDL_CDStatus(SDL_CD *cdrom);
slouken@0
   120
slouken@0
   121
/* Play the given CD starting at 'start_track' and 'start_frame' for 'ntracks'
slouken@0
   122
   tracks and 'nframes' frames.  If both 'ntrack' and 'nframe' are 0, play 
slouken@0
   123
   until the end of the CD.  This function will skip data tracks.
slouken@0
   124
   This function should only be called after calling SDL_CDStatus() to 
slouken@0
   125
   get track information about the CD.
slouken@0
   126
   For example:
slouken@0
   127
	// Play entire CD:
slouken@0
   128
	if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
slouken@0
   129
		SDL_CDPlayTracks(cdrom, 0, 0, 0, 0);
slouken@0
   130
	// Play last track:
slouken@0
   131
	if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) {
slouken@0
   132
		SDL_CDPlayTracks(cdrom, cdrom->numtracks-1, 0, 0, 0);
slouken@0
   133
	}
slouken@0
   134
	// Play first and second track and 10 seconds of third track:
slouken@0
   135
	if ( CD_INDRIVE(SDL_CDStatus(cdrom)) )
slouken@0
   136
		SDL_CDPlayTracks(cdrom, 0, 0, 2, 10);
slouken@0
   137
slouken@0
   138
   This function returns 0, or -1 if there was an error.
slouken@0
   139
*/
slouken@337
   140
extern DECLSPEC int SDLCALL SDL_CDPlayTracks(SDL_CD *cdrom,
slouken@0
   141
		int start_track, int start_frame, int ntracks, int nframes);
slouken@0
   142
slouken@0
   143
/* Play the given CD starting at 'start' frame for 'length' frames.
slouken@0
   144
   It returns 0, or -1 if there was an error.
slouken@0
   145
*/
slouken@337
   146
extern DECLSPEC int SDLCALL SDL_CDPlay(SDL_CD *cdrom, int start, int length);
slouken@0
   147
slouken@0
   148
/* Pause play -- returns 0, or -1 on error */
slouken@337
   149
extern DECLSPEC int SDLCALL SDL_CDPause(SDL_CD *cdrom);
slouken@0
   150
slouken@0
   151
/* Resume play -- returns 0, or -1 on error */
slouken@337
   152
extern DECLSPEC int SDLCALL SDL_CDResume(SDL_CD *cdrom);
slouken@0
   153
slouken@0
   154
/* Stop play -- returns 0, or -1 on error */
slouken@337
   155
extern DECLSPEC int SDLCALL SDL_CDStop(SDL_CD *cdrom);
slouken@0
   156
slouken@0
   157
/* Eject CD-ROM -- returns 0, or -1 on error */
slouken@337
   158
extern DECLSPEC int SDLCALL SDL_CDEject(SDL_CD *cdrom);
slouken@0
   159
slouken@0
   160
/* Closes the handle for the CD-ROM drive */
slouken@337
   161
extern DECLSPEC void SDLCALL SDL_CDClose(SDL_CD *cdrom);
slouken@0
   162
slouken@0
   163
slouken@0
   164
/* Ends C function definitions when using C++ */
slouken@0
   165
#ifdef __cplusplus
slouken@0
   166
}
slouken@0
   167
#endif
slouken@0
   168
#include "close_code.h"
slouken@0
   169
slouken@0
   170
#endif /* _SDL_video_h */