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